コード例 #1
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;
}
コード例 #2
0
static int
drange_parse(const struct sol_flow_node_options_member_description *member,
    const char *value,
    struct sol_drange *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 DBL_MAX_STR[] = "DBL_MAX";
    static const char DBL_MIN_STR[] = "-DBL_MAX";
    static const size_t DBL_MAX_STR_LEN = sizeof(DBL_MAX_STR) - 1;
    static const size_t DBL_MIN_STR_LEN = sizeof(DBL_MIN_STR) - 1;
    double *store_vals[] = { &ret->val, &ret->min, &ret->max, &ret->step };

    buf = strdup(value);

    ASSIGN_KEY_VAL(double, min, strtod, false,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, max, strtod, false,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, step, strtod, false,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, val, strtod, false,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);

    KEY_VALUES_RECAP(DBL_MAX, -DBL_MAX);

    ASSIGN_LINEAR_VALUES(strtod,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);

    LINEAR_VALUES_RECAP(DBL_MAX, -DBL_MAX);

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

    free(buf);
    return 0;

err:
    SOL_DBG("Invalid drange 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 DBL_MAX and -DBL_MAX. Don't use commas "
        "on the numbers",
        member->name, value);
    free(buf);
    return -EINVAL;
}
コード例 #3
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;
}
コード例 #4
0
static int
direction_vector_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, *x, *y, *z;
    struct sol_direction_vector *ret = &m->direction_vector;
    double *store_vals[] = { &ret->x, &ret->y, &ret->z, &ret->min, &ret->max };

    buf = strdup(value);

    ASSIGN_KEY_VAL(double, x, strtod_no_locale, false,
                   DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
                   -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, y, strtod_no_locale, false,
                   DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
                   -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, z, strtod_no_locale, false,
                   DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
                   -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, min, strtod_no_locale, false,
                   DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
                   -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, max, strtod_no_locale, false,
                   DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
                   -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);

    ASSIGN_LINEAR_VALUES(strtod_no_locale,
                         DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
                         -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);

    SOL_DBG("direction_vector opt ends up as "
            "x=%lf, y=%lf, z=%lf, min=%lf, max=%lf\n",
            ret->x, ret->y, ret->z, ret->min, ret->max);

    free(buf);
    return 0;

err:
    SOL_DBG("Invalid direction_vector value for option name=\"%s\": \"%s\"."
            " Please use the formats"
            " \"<x_value>|<y_value>|<z_value>|<min_value>|<max_value>\","
            " in that order, or \"<key>:<value>|<...>\", for keys in "
            "[x, y, z, min, max], in any order. Values may be the "
            "special strings DBL_MAX and -DBL_MAX. Don't use commas "
            "on the numbers",
            m->name, value);
    free(buf);
    return -EINVAL;
}
コード例 #5
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;
}
コード例 #6
0
static int
drange_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_drange_spec *ret = &m->drange_spec;
    double *store_vals[] = { &ret->min, &ret->max, &ret->step };

    buf = strdup(value);

    ASSIGN_KEY_VAL(double, min, strtod_no_locale, false,
                   DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
                   -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, max, strtod_no_locale, false,
                   DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
                   -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, step, strtod_no_locale, false,
                   DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
                   -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);

    ASSIGN_LINEAR_VALUES(strtod_no_locale,
                         DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
                         -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);

    SOL_DBG("drange opt ends up as min=%lf, max=%lf, step=%lf",
            ret->min, ret->max, ret->step);

    free(buf);
    return 0;

err:
    SOL_DBG("Invalid drange 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 DBL_MAX and -DBL_MAX. Don't use commas "
            "on the numbers",
            m->name, value);
    free(buf);
    return -EINVAL;
}
コード例 #7
0
static int
direction_vector_parse(const struct sol_flow_node_options_member_description *member,
    const char *value,
    struct sol_direction_vector *ret)
{
    char *buf;
    int field_cnt = 0;
    bool keys_schema = false;
    char *min, *max, *x, *y, *z;
    bool min_done = false, max_done = false,
         x_done = false, y_done = false, z_done = false;
    static const char DBL_MAX_STR[] = "DBL_MAX";
    static const char DBL_MIN_STR[] = "-DBL_MAX";
    static const size_t DBL_MAX_STR_LEN = sizeof(DBL_MAX_STR) - 1;
    static const size_t DBL_MIN_STR_LEN = sizeof(DBL_MIN_STR) - 1;
    double *store_vals[] = { &ret->x, &ret->y, &ret->z, &ret->min, &ret->max };

    buf = strdup(value);

    ASSIGN_KEY_VAL(double, x, strtod, false,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, y, strtod, false,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, z, strtod, false,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, min, strtod, false,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);
    ASSIGN_KEY_VAL(double, max, strtod, false,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);

    if (keys_schema) {
        if (!x_done) ret->x = 0;
        if (!y_done) ret->y = 0;
        if (!z_done) ret->z = 0;
        if (!min_done) ret->min = -DBL_MAX;
        if (!max_done) ret->max = DBL_MAX;
    }

    ASSIGN_LINEAR_VALUES(strtod,
        DBL_MAX, DBL_MAX_STR, DBL_MAX_STR_LEN,
        -DBL_MAX, DBL_MIN_STR, DBL_MIN_STR_LEN);

    switch (field_cnt) {
    case 1:
        ret->y = 0;
    case 2:
        ret->z = 0;
    case 3:
        ret->min = -DBL_MAX;
    case 4:
        ret->max = DBL_MAX;
    default:
        break;
    }

    SOL_DBG("direction_vector opt ends up as x=%lf, y=%lf, z=%lf, min=%lf, max=%lf\n",
        ret->x, ret->y, ret->z, ret->min, ret->max);

    free(buf);
    return 0;

err:
    SOL_ERR("Invalid direction_vector value for option name=\"%s\": \"%s\"."
        " Please use the formats"
        " \"<x_value>|<y_value>|<z_value>|<min_value>|<max_value>\","
        " in that order, or \"<key>:<value>|<...>\", for keys in "
        "[x, y, z, min, max], in any order. Values may be the "
        "special strings DBL_MAX and -DBL_MAX. Don't use commas "
        "on the numbers",
        member->name, value);
    free(buf);
    return -EINVAL;
}
コード例 #8
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;
}