Ejemplo n.º 1
0
static int
irange_parse(const struct sol_flow_node_options_member_description *member,
    const char *value,
    struct sol_irange *ret)
{
    char *buf;
    int field_cnt = 0;
    bool keys_schema = false;
    char *min, *max, *step, *val;
    bool min_done = false, max_done = false,
         step_done = false, val_done = false;
    static const char INT_MAX_STR[] = "INT32_MAX";
    static const char INT_MIN_STR[] = "INT32_MIN";
    static const size_t INT_LIMIT_STR_LEN = sizeof(INT_MAX_STR) - 1;
    int32_t *store_vals[] = { &ret->val, &ret->min, &ret->max, &ret->step };

    buf = strdup(value);

    ASSIGN_KEY_VAL(int32_t, min, STRTOL_DECIMAL, false,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, max, STRTOL_DECIMAL, false,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, step, STRTOL_DECIMAL, false,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, val, STRTOL_DECIMAL, false,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);

    KEY_VALUES_RECAP(INT32_MAX, INT32_MIN);

    ASSIGN_LINEAR_VALUES(STRTOL_DECIMAL,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);

    LINEAR_VALUES_RECAP(INT32_MAX, INT32_MIN);

    SOL_DBG("irange opt ends up as min=%d, max=%d, step=%d, val=%d\n",
        ret->min, ret->max, ret->step, ret->val);

    free(buf);
    return 0;

err:
    SOL_DBG("Invalid irange value for option name=\"%s\": \"%s\"."
        " Please use the formats"
        " \"<val_value>|<min_value>|<max_value>|<step_value>\","
        " in that order, or \"<key>:<value>|<...>\", for keys in "
        "[val, min, max, step], in any order. Values may be the "
        "special strings INT32_MAX and INT32_MIN.",
        member->name, value);
    free(buf);
    return -EINVAL;
}
Ejemplo n.º 2
0
static int
irange_spec_parse(const char *value, struct sol_flow_node_named_options_member *m)
{
    char *buf;
    int field_cnt = 0;
    bool keys_schema = false;
    char *min, *max, *step;
    struct sol_irange_spec *ret = &m->irange_spec;
    int32_t *store_vals[] = { &ret->min, &ret->max, &ret->step };

    buf = strdup(value);

    ASSIGN_KEY_VAL(int32_t, min, STRTOL_DECIMAL, false,
                   INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                   INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, max, STRTOL_DECIMAL, false,
                   INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                   INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, step, STRTOL_DECIMAL, false,
                   INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                   INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);

    ASSIGN_LINEAR_VALUES(STRTOL_DECIMAL,
                         INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                         INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);


    SOL_DBG("irange spec opt ends up as min=%" PRId32 ", max=%" PRId32
            ", step=%" PRId32 "\n", ret->min, ret->max, ret->step);

    free(buf);
    return 0;

err:
    SOL_DBG("Invalid irange value for option name=\"%s\": \"%s\"."
            " Please use the formats"
            " \"<min_value>|<max_value>|<step_value>\","
            " in that order, or \"<key>:<value>|<...>\", for keys in "
            "[min, max, step], in any order. Values may be the "
            "special strings INT32_MIN and INT32_MAX.",
            m->name, value);
    free(buf);
    return -EINVAL;
}
Ejemplo n.º 3
0
static int
rgb_parse(const char *value, struct sol_flow_node_named_options_member *m)
{
    char *buf;
    int field_cnt = 0;
    bool keys_schema = false;
    char *red, *green, *blue, *red_max, *green_max, *blue_max;
    struct sol_rgb *ret = &m->rgb;
    uint32_t *store_vals[] = { &ret->red, &ret->green, &ret->blue,
                               &ret->red_max, &ret->green_max, &ret->blue_max
                             };

    buf = strdup(value);

    ASSIGN_KEY_VAL(int32_t, red, STRTOL_DECIMAL, true,
                   INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                   INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, green, STRTOL_DECIMAL, true,
                   INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                   INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, blue, STRTOL_DECIMAL, true,
                   INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                   INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, red_max, STRTOL_DECIMAL, true,
                   INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                   INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, green_max, STRTOL_DECIMAL, true,
                   INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                   INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, blue_max, STRTOL_DECIMAL, true,
                   INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                   INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);

    ASSIGN_LINEAR_VALUES(STRTOL_DECIMAL,
                         INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
                         INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);

    SOL_DBG("rgb opt ends up as red=%" PRIu32 ", green=%" PRIu32
            ", blue=%" PRIu32 " red_max=%" PRIu32 ", green_max=%" PRIu32
            ", blue_max=%" PRIu32 "\n",
            ret->red, ret->green, ret->blue,
            ret->red_max, ret->green_max, ret->blue_max);

    free(buf);
    return 0;

err:
    SOL_DBG("Invalid rgb value for option name=\"%s\": \"%s\"."
            " Please use the formats"
            " \"<red_value>|<green_value>|<blue_value>|"
            "<red_max_value>|<green_max_value>|<blue_max_value>\","
            " in that order, or \"<key>:<value>|<...>\", for keys in "
            "[red, green, blue, red_max, green_max, blue_max], in any order. "
            "Values may be the special strings INT32_MAX. All of them must be "
            "not negative int values.",
            m->name, value);
    free(buf);
    return -EINVAL;
}
Ejemplo n.º 4
0
static int
rgb_parse(const struct sol_flow_node_options_member_description *member,
    const char *value, struct sol_rgb *ret)
{
    char *buf;
    int field_cnt = 0;
    bool keys_schema = false;
    char *red, *green, *blue, *red_max, *green_max, *blue_max;
    bool red_done = false, green_done = false, blue_done = false,
         red_max_done = false, green_max_done = false, blue_max_done = false;
    static const char INT_MAX_STR[] = "INT32_MAX";
    static const char INT_MIN_STR[] = "INT32_MIN";
    static const size_t INT_LIMIT_STR_LEN = sizeof(INT_MAX_STR) - 1;
    uint32_t *store_vals[] = { &ret->red, &ret->green, &ret->blue,
                               &ret->red_max, &ret->green_max, &ret->blue_max };

    buf = strdup(value);

    ASSIGN_KEY_VAL(int32_t, red, STRTOL_DECIMAL, true,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, green, STRTOL_DECIMAL, true,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, blue, STRTOL_DECIMAL, true,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, red_max, STRTOL_DECIMAL, true,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, green_max, STRTOL_DECIMAL, true,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);
    ASSIGN_KEY_VAL(int32_t, blue_max, STRTOL_DECIMAL, true,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);

    if (keys_schema) {
        if (!red_done) ret->red = 0;
        if (!red_max_done) ret->red_max = 255;
        if (!green_done) ret->green = 0;
        if (!green_max_done) ret->green_max = 255;
        if (!blue_done) ret->blue = 0;
        if (!blue_max_done) ret->blue_max = 255;
    }

    ASSIGN_LINEAR_VALUES(STRTOL_DECIMAL,
        INT32_MAX, INT_MAX_STR, INT_LIMIT_STR_LEN,
        INT32_MIN, INT_MIN_STR, INT_LIMIT_STR_LEN);

    /* field_cnt shouldn't start from 0 in switch,
     * since if no value was declared, it doesn't make
     * sense to declare the option. Also, if values were
     * assigned by ASSIGN_KEY_VAL field_cnt would stay 0, and the whole
     * option would be set to default values */
    switch (field_cnt) {
    case 1:
        ret->green = 0;
    case 2:
        ret->blue = 0;
    case 3:
        ret->red_max = 255;
    case 4:
        ret->green_max = 255;
    case 5:
        ret->blue_max = 255;
    default:
        break;
    }

    SOL_DBG("rgb opt ends up as red=%d, green=%d, blue=%d "
        "red_max=%d, green_max=%d, blue_max=%d\n",
        ret->red, ret->green, ret->blue,
        ret->red_max, ret->green_max, ret->blue_max);

    free(buf);
    return 0;

err:
    SOL_DBG("Invalid rgb value for option name=\"%s\": \"%s\"."
        " Please use the formats"
        " \"<red_value>|<green_value>|<blue_value>|"
        "<red_max_value>|<green_max_value>|<blue_max_value>\","
        " in that order, or \"<key>:<value>|<...>\", for keys in "
        "[red, green, blue, red_max, green_max, blue_max], in any order. "
        "Values may be the special strings INT32_MAX. All of them must be "
        "not negative int values.",
        member->name, value);
    free(buf);
    return -EINVAL;
}