EC_LOG_TYPE_REGISTER(node_many);
struct ec_node_many {
- struct ec_node gen;
unsigned int min;
unsigned int max;
struct ec_node *child;
};
-static int ec_node_many_parse(const struct ec_node *gen_node,
+static int ec_node_many_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_many *node = (struct ec_node_many *)gen_node;
+ struct ec_node_many *priv = ec_node_priv(node);
struct ec_parse *child_parse;
struct ec_strvec *childvec = NULL;
size_t off = 0, count;
int ret;
- for (count = 0; node->max == 0 || count < node->max; count++) {
+ for (count = 0; priv->max == 0 || count < priv->max; count++) {
childvec = ec_strvec_ndup(strvec, off,
ec_strvec_len(strvec) - off);
if (childvec == NULL)
goto fail;
- ret = ec_node_parse_child(node->child, state, childvec);
+ ret = ec_node_parse_child(priv->child, state, childvec);
if (ret < 0)
goto fail;
off += ret;
}
- if (count < node->min) {
+ if (count < priv->min) {
ec_parse_free_children(state);
return EC_PARSE_NOMATCH;
}
}
static int
-__ec_node_many_complete(struct ec_node_many *node, unsigned int max,
+__ec_node_many_complete(struct ec_node_many *priv, unsigned int max,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
int ret;
/* first, try to complete with the child node */
- ret = ec_node_complete_child(node->child, comp, strvec);
+ ret = ec_node_complete_child(priv->child, comp, strvec);
if (ret < 0)
goto fail;
if (childvec == NULL)
goto fail;
- ret = ec_node_parse_child(node->child, parse, childvec);
+ ret = ec_node_parse_child(priv->child, parse, childvec);
if (ret < 0)
goto fail;
goto fail;
}
- ret = __ec_node_many_complete(node, max, comp, childvec);
+ ret = __ec_node_many_complete(priv, max, comp, childvec);
ec_parse_del_last_child(parse);
ec_strvec_free(childvec);
childvec = NULL;
}
static int
-ec_node_many_complete(const struct ec_node *gen_node,
+ec_node_many_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_many *node = (struct ec_node_many *)gen_node;
+ struct ec_node_many *priv = ec_node_priv(node);
- return __ec_node_many_complete(node, node->max, comp,
+ return __ec_node_many_complete(priv, priv->max, comp,
strvec);
}
-static void ec_node_many_free_priv(struct ec_node *gen_node)
+static void ec_node_many_free_priv(struct ec_node *node)
{
- struct ec_node_many *node = (struct ec_node_many *)gen_node;
+ struct ec_node_many *priv = ec_node_priv(node);
- ec_node_free(node->child);
+ ec_node_free(priv->child);
}
static size_t
-ec_node_many_get_children_count(const struct ec_node *gen_node)
+ec_node_many_get_children_count(const struct ec_node *node)
{
- struct ec_node_many *node = (struct ec_node_many *)gen_node;
+ struct ec_node_many *priv = ec_node_priv(node);
- if (node->child)
+ if (priv->child)
return 1;
return 0;
}
static int
-ec_node_many_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_many_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_many *node = (struct ec_node_many *)gen_node;
+ struct ec_node_many *priv = ec_node_priv(node);
if (i >= 1)
return -1;
- *child = node->child;
+ *child = priv->child;
*refs = 2;
return 0;
}
},
};
-static int ec_node_many_set_config(struct ec_node *gen_node,
+static int ec_node_many_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_many *node = (struct ec_node_many *)gen_node;
+ struct ec_node_many *priv = ec_node_priv(node);
const struct ec_config *child, *min, *max;
child = ec_config_dict_get(config, "child");
goto fail;
}
- if (node->child != NULL)
- ec_node_free(node->child);
- node->child = ec_node_clone(child->node);
+ if (priv->child != NULL)
+ ec_node_free(priv->child);
+ priv->child = ec_node_clone(child->node);
if (min == NULL)
- node->min = 0;
+ priv->min = 0;
else
- node->min = min->u64;
+ priv->min = min->u64;
if (max == NULL)
- node->max = 0;
+ priv->max = 0;
else
- node->max = max->u64;
+ priv->max = max->u64;
return 0;
EC_NODE_TYPE_REGISTER(ec_node_many_type);
int
-ec_node_many_set_params(struct ec_node *gen_node, struct ec_node *child,
+ec_node_many_set_params(struct ec_node *node, struct ec_node *child,
unsigned int min, unsigned int max)
{
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL;
int ret;
- if (ec_node_check_type(gen_node, &ec_node_many_type) < 0)
+ if (ec_node_check_type(node, &ec_node_many_type) < 0)
goto fail;
- cur_config = ec_node_get_config(gen_node);
+ cur_config = ec_node_get_config(node);
if (cur_config == NULL)
config = ec_config_dict();
else
if (ec_config_dict_set(config, "max", ec_config_u64(max)) < 0)
goto fail;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL; /* freed */
if (ret < 0)
goto fail;
struct ec_node *ec_node_many(const char *id, struct ec_node *child,
unsigned int min, unsigned int max)
{
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
if (child == NULL)
return NULL;
- gen_node = ec_node_from_type(&ec_node_many_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_many_type, id);
+ if (node == NULL)
goto fail;
- if (ec_node_many_set_params(gen_node, child, min, max) < 0) {
+ if (ec_node_many_set_params(node, child, min, max) < 0) {
child = NULL;
goto fail;
}
child = NULL;
- return gen_node;
+ return node;
fail:
- ec_node_free(gen_node);
+ ec_node_free(node);
ec_node_free(child);
return NULL;
}