EC_NODE_FREE_STATE_FREEING,
};
-struct ec_node {
- const struct ec_node_type *type;
- struct ec_config *config; /**< Generic configuration. */
- char *id;
- char *desc;
- struct ec_dict *attrs;
- unsigned int refcnt;
- struct {
- enum ec_node_free_state state; /**< State of loop detection */
- unsigned int refcnt; /**< Number of reachable references
- * starting from node beeing freed */
- } free; /**< Freeing state: used for loop detection */
-};
-
/* create a new node when the type is known, typically called from the node
* code */
struct ec_node *ec_node_from_type(const struct ec_node_type *type, const char *id);
int ec_node_check_type(const struct ec_node *node,
const struct ec_node_type *type);
+const char *ec_node_get_type_name(const struct ec_node *node);
+
+/**
+ * Get the pointer to the node private area.
+ *
+ * @param node
+ * The grammar node.
+ * @return
+ * The pointer to the node private area.
+ */
+void *ec_node_priv(const struct ec_node *node);
+
#endif
/** @} */
EC_LOG_TYPE_REGISTER(node);
+struct ec_node {
+ const struct ec_node_type *type;
+ struct ec_config *config; /**< Generic configuration. */
+ char *id;
+ char *desc;
+ struct ec_dict *attrs;
+ unsigned int refcnt;
+ struct {
+ enum ec_node_free_state state; /**< State of loop detection */
+ unsigned int refcnt; /**< Number of reachable references
+ * starting from node beeing freed */
+ } free; /**< Freeing state: used for loop detection */
+};
+
static struct ec_node_type_list node_type_list =
TAILQ_HEAD_INITIALIZER(node_type_list);
int ec_node_type_register(struct ec_node_type *type)
{
- EC_CHECK_ARG(type->size >= sizeof(struct ec_node), -1, EINVAL);
-
if (ec_node_type_lookup(type->name) != NULL) {
errno = EEXIST;
return -1;
goto fail;
}
- node = ec_calloc(1, type->size);
+ node = ec_calloc(1, sizeof(*node) + type->size);
if (node == NULL)
goto fail;
return 0;
}
+const char *ec_node_get_type_name(const struct ec_node *node)
+{
+ return node->type->name;
+}
+
+void *ec_node_priv(const struct ec_node *node)
+{
+ if (node == NULL)
+ return NULL;
+ return (void *)(node + 1);
+}
+
/* LCOV_EXCL_START */
static int ec_node_testcase(void)
{
EC_LOG_TYPE_REGISTER(node_any);
struct ec_node_any {
- struct ec_node gen;
char *attr_name;
};
-static int ec_node_any_parse(const struct ec_node *gen_node,
+static int ec_node_any_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_any *node = (struct ec_node_any *)gen_node;
+ struct ec_node_any *priv = ec_node_priv(node);
const struct ec_dict *attrs;
(void)state;
if (ec_strvec_len(strvec) == 0)
return EC_PARSE_NOMATCH;
- if (node->attr_name != NULL) {
+ if (priv->attr_name != NULL) {
attrs = ec_strvec_get_attrs(strvec, 0);
- if (attrs == NULL || !ec_dict_has_key(attrs, node->attr_name))
+ if (attrs == NULL || !ec_dict_has_key(attrs, priv->attr_name))
return EC_PARSE_NOMATCH;
}
return 1;
}
-static void ec_node_any_free_priv(struct ec_node *gen_node)
+static void ec_node_any_free_priv(struct ec_node *node)
{
- struct ec_node_any *node = (struct ec_node_any *)gen_node;
+ struct ec_node_any *priv = ec_node_priv(node);
- ec_free(node->attr_name);
+ ec_free(priv->attr_name);
}
static const struct ec_config_schema ec_node_any_schema[] = {
},
};
-static int ec_node_any_set_config(struct ec_node *gen_node,
+static int ec_node_any_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_any *node = (struct ec_node_any *)gen_node;
+ struct ec_node_any *priv = ec_node_priv(node);
const struct ec_config *value = NULL;
char *s = NULL;
goto fail;
}
- ec_free(node->attr_name);
- node->attr_name = s;
+ ec_free(priv->attr_name);
+ priv->attr_name = s;
return 0;
ec_node_any(const char *id, const char *attr)
{
struct ec_config *config = NULL;
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
int ret;
- gen_node = ec_node_from_type(&ec_node_any_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_any_type, id);
+ if (node == NULL)
return NULL;
config = ec_config_dict();
if (ret < 0)
goto fail;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL;
if (ret < 0)
goto fail;
- return gen_node;
+ return node;
fail:
ec_config_free(config);
- ec_node_free(gen_node);
+ ec_node_free(node);
return NULL;
}
EC_LOG_TYPE_REGISTER(node_bypass);
struct ec_node_bypass {
- struct ec_node gen;
struct ec_node *child;
};
static int
-ec_node_bypass_parse(const struct ec_node *gen_node,
+ec_node_bypass_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+ struct ec_node_bypass *priv = ec_node_priv(node);
- return ec_node_parse_child(node->child, state, strvec);
+ return ec_node_parse_child(priv->child, state, strvec);
}
static int
-ec_node_bypass_complete(const struct ec_node *gen_node,
+ec_node_bypass_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+ struct ec_node_bypass *priv = ec_node_priv(node);
- return ec_node_complete_child(node->child, comp, strvec);
+ return ec_node_complete_child(priv->child, comp, strvec);
}
-static void ec_node_bypass_free_priv(struct ec_node *gen_node)
+static void ec_node_bypass_free_priv(struct ec_node *node)
{
- struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+ struct ec_node_bypass *priv = ec_node_priv(node);
- ec_node_free(node->child);
+ ec_node_free(priv->child);
}
static size_t
-ec_node_bypass_get_children_count(const struct ec_node *gen_node)
+ec_node_bypass_get_children_count(const struct ec_node *node)
{
- struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+ struct ec_node_bypass *priv = ec_node_priv(node);
- if (node->child)
+ if (priv->child)
return 1;
return 0;
}
static int
-ec_node_bypass_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_bypass_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+ struct ec_node_bypass *priv = ec_node_priv(node);
if (i >= 1)
return -1;
- *child = node->child;
+ *child = priv->child;
*refs = 2;
return 0;
}
},
};
-static int ec_node_bypass_set_config(struct ec_node *gen_node,
+static int ec_node_bypass_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+ struct ec_node_bypass *priv = ec_node_priv(node);
const struct ec_config *child;
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);
return 0;
EC_NODE_TYPE_REGISTER(ec_node_bypass_type);
int
-ec_node_bypass_set_child(struct ec_node *gen_node, struct ec_node *child)
+ec_node_bypass_set_child(struct ec_node *node, struct ec_node *child)
{
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL;
int ret;
- if (ec_node_check_type(gen_node, &ec_node_bypass_type) < 0)
+ if (ec_node_check_type(node, &ec_node_bypass_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
}
child = NULL; /* freed */
- 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_bypass(const char *id, struct ec_node *child)
{
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
if (child == NULL)
goto fail;
- gen_node = ec_node_from_type(&ec_node_bypass_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_bypass_type, id);
+ if (node == NULL)
goto fail;
- ec_node_bypass_set_child(gen_node, child);
+ ec_node_bypass_set_child(node, child);
child = NULL;
- return gen_node;
+ return node;
fail:
ec_node_free(child);
static struct ec_node *ec_node_cmd_expr; /* the expr parser without lexer. */
struct ec_node_cmd {
- struct ec_node gen;
char *cmd_str; /* the command string. */
struct ec_node *cmd; /* the command node. */
struct ec_node **table; /* table of node referenced in command. */
}
if (ec_strvec_len(vec) == 0) {
- if (!strcmp(in1->type->name, "seq")) {
+ if (!strcmp(ec_node_get_type_name(in1), "seq")) {
if (ec_node_seq_add(in1, ec_node_clone(in2)) < 0)
return -1;
ec_node_free(in2);
*result = out;
}
} else if (!strcmp(ec_strvec_val(vec, 0), "|")) {
- if (!strcmp(in2->type->name, "or")) {
+ if (!strcmp(ec_node_get_type_name(in2), "or")) {
if (ec_node_or_add(in2, ec_node_clone(in1)) < 0)
return -1;
ec_node_free(in1);
*result = in2;
- } else if (!strcmp(in1->type->name, "or")) {
+ } else if (!strcmp(ec_node_get_type_name(in1), "or")) {
if (ec_node_or_add(in1, ec_node_clone(in2)) < 0)
return -1;
ec_node_free(in2);
*result = out;
}
} else if (!strcmp(ec_strvec_val(vec, 0), ",")) {
- if (!strcmp(in2->type->name, "subset")) {
+ if (!strcmp(ec_node_get_type_name(in2), "subset")) {
if (ec_node_subset_add(in2, ec_node_clone(in1)) < 0)
return -1;
ec_node_free(in1);
*result = in2;
- } else if (!strcmp(in1->type->name, "subset")) {
+ } else if (!strcmp(ec_node_get_type_name(in1), "subset")) {
if (ec_node_subset_add(in1, ec_node_clone(in2)) < 0)
return -1;
ec_node_free(in2);
}
static int
-ec_node_cmd_parse(const struct ec_node *gen_node, struct ec_parse *state,
+ec_node_cmd_parse(const struct ec_node *node, struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+ struct ec_node_cmd *priv = ec_node_priv(node);
- return ec_node_parse_child(node->cmd, state, strvec);
+ return ec_node_parse_child(priv->cmd, state, strvec);
}
static int
-ec_node_cmd_complete(const struct ec_node *gen_node,
+ec_node_cmd_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+ struct ec_node_cmd *priv = ec_node_priv(node);
- return ec_node_complete_child(node->cmd, comp, strvec);
+ return ec_node_complete_child(priv->cmd, comp, strvec);
}
-static void ec_node_cmd_free_priv(struct ec_node *gen_node)
+static void ec_node_cmd_free_priv(struct ec_node *node)
{
- struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+ struct ec_node_cmd *priv = ec_node_priv(node);
size_t i;
- ec_free(node->cmd_str);
- node->cmd_str = NULL;
- ec_node_free(node->cmd);
- node->cmd = NULL;
- for (i = 0; i < node->len; i++)
- ec_node_free(node->table[i]);
- ec_free(node->table);
- node->table = NULL;
- node->len = 0;
+ ec_free(priv->cmd_str);
+ priv->cmd_str = NULL;
+ ec_node_free(priv->cmd);
+ priv->cmd = NULL;
+ for (i = 0; i < priv->len; i++)
+ ec_node_free(priv->table[i]);
+ ec_free(priv->table);
+ priv->table = NULL;
+ priv->len = 0;
}
static const struct ec_config_schema ec_node_cmd_subschema[] = {
},
};
-static int ec_node_cmd_set_config(struct ec_node *gen_node,
+static int ec_node_cmd_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+ struct ec_node_cmd *priv = ec_node_priv(node);
const struct ec_config *expr = NULL;
struct ec_node *cmd = NULL;
struct ec_node **table = NULL;
goto fail;
/* ok, store the config */
- ec_node_free(node->cmd);
- node->cmd = cmd;
- ec_free(node->cmd_str);
- node->cmd_str = cmd_str;
- for (i = 0; i < node->len; i++)
- ec_node_free(node->table[i]);
- ec_free(node->table);
- node->table = table;
- node->len = len;
+ ec_node_free(priv->cmd);
+ priv->cmd = cmd;
+ ec_free(priv->cmd_str);
+ priv->cmd_str = cmd_str;
+ for (i = 0; i < priv->len; i++)
+ ec_node_free(priv->table[i]);
+ ec_free(priv->table);
+ priv->table = table;
+ priv->len = len;
return 0;
}
static size_t
-ec_node_cmd_get_children_count(const struct ec_node *gen_node)
+ec_node_cmd_get_children_count(const struct ec_node *node)
{
- struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+ struct ec_node_cmd *priv = ec_node_priv(node);
- if (node->cmd == NULL)
+ if (priv->cmd == NULL)
return 0;
return 1;
}
static int
-ec_node_cmd_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_cmd_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+ struct ec_node_cmd *priv = ec_node_priv(node);
if (i > 0)
return -1;
- *child = node->cmd;
+ *child = priv->cmd;
*refs = 1;
return 0;
}
struct ec_node *__ec_node_cmd(const char *id, const char *cmd, ...)
{
struct ec_config *config = NULL, *children = NULL;
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
va_list ap;
int ret;
if (children == NULL)
goto fail;
- gen_node = ec_node_from_type(&ec_node_cmd_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_cmd_type, id);
+ if (node == NULL)
goto fail;
config = ec_config_dict();
}
children = NULL;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL; /* freed */
if (ret < 0)
goto fail;
- return gen_node;
+ return node;
fail:
- ec_node_free(gen_node); /* will also free added children */
+ ec_node_free(node); /* will also free added children */
ec_config_free(children);
ec_config_free(config);
static struct ec_dict *ec_node_cond_functions; /* functions dictionary */
struct ec_node_cond {
- struct ec_node gen;
char *cond_str; /* the condition string. */
struct ec_parse *parsed_cond; /* the parsed condition. */
struct ec_node *child; /* the child node. */
}
static int
-ec_node_cond_parse(const struct ec_node *gen_node, struct ec_parse *state,
+ec_node_cond_parse(const struct ec_node *node, struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+ struct ec_node_cond *priv = ec_node_priv(node);
struct ec_parse *child;
int ret, valid;
- ret = ec_node_parse_child(node->child, state, strvec);
+ ret = ec_node_parse_child(priv->child, state, strvec);
if (ret <= 0)
return ret;
- valid = validate_condition(node->parsed_cond, state);
+ valid = validate_condition(priv->parsed_cond, state);
if (valid < 0)
return valid;
}
static int
-ec_node_cond_complete(const struct ec_node *gen_node,
+ec_node_cond_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+ struct ec_node_cond *priv = ec_node_priv(node);
// XXX eval condition
// XXX before or after completing ? configurable ?
- return ec_node_complete_child(node->child, comp, strvec);
+ return ec_node_complete_child(priv->child, comp, strvec);
}
-static void ec_node_cond_free_priv(struct ec_node *gen_node)
+static void ec_node_cond_free_priv(struct ec_node *node)
{
- struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+ struct ec_node_cond *priv = ec_node_priv(node);
- ec_free(node->cond_str);
- node->cond_str = NULL;
- ec_parse_free(node->parsed_cond);
- node->parsed_cond = NULL;
- ec_node_free(node->child);
+ ec_free(priv->cond_str);
+ priv->cond_str = NULL;
+ ec_parse_free(priv->parsed_cond);
+ priv->parsed_cond = NULL;
+ ec_node_free(priv->child);
}
static const struct ec_config_schema ec_node_cond_schema[] = {
},
};
-static int ec_node_cond_set_config(struct ec_node *gen_node,
+static int ec_node_cond_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+ struct ec_node_cond *priv = ec_node_priv(node);
const struct ec_config *cond = NULL;
struct ec_parse *parsed_cond = NULL;
const struct ec_config *child;
goto fail;
/* ok, store the config */
- ec_parse_free(node->parsed_cond);
- node->parsed_cond = parsed_cond;
- ec_free(node->cond_str);
- node->cond_str = cond_str;
- ec_node_free(node->child);
- node->child = ec_node_clone(child->node);
+ ec_parse_free(priv->parsed_cond);
+ priv->parsed_cond = parsed_cond;
+ ec_free(priv->cond_str);
+ priv->cond_str = cond_str;
+ ec_node_free(priv->child);
+ priv->child = ec_node_clone(child->node);
return 0;
}
static size_t
-ec_node_cond_get_children_count(const struct ec_node *gen_node)
+ec_node_cond_get_children_count(const struct ec_node *node)
{
- struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+ struct ec_node_cond *priv = ec_node_priv(node);
- if (node->child == NULL)
+ if (priv->child == NULL)
return 0;
return 1;
}
static int
-ec_node_cond_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_cond_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+ struct ec_node_cond *priv = ec_node_priv(node);
if (i > 0)
return -1;
- *child = node->child;
+ *child = priv->child;
*refs = 1;
return 0;
}
struct ec_node *child)
{
struct ec_config *config = NULL;
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
int ret;
if (child == NULL)
return NULL;
- gen_node = ec_node_from_type(&ec_node_cond_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_cond_type, id);
+ if (node == NULL)
goto fail;
config = ec_config_dict();
}
child = NULL;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL; /* freed */
if (ret < 0)
goto fail;
- return gen_node;
+ return node;
fail:
- ec_node_free(gen_node);
+ ec_node_free(node);
ec_node_free(child);
ec_config_free(config);
EC_LOG_TYPE_REGISTER(node_dynamic);
struct ec_node_dynamic {
- struct ec_node gen;
ec_node_dynamic_build_t build;
void *opaque;
};
static int
-ec_node_dynamic_parse(const struct ec_node *gen_node,
+ec_node_dynamic_parse(const struct ec_node *node,
struct ec_parse *parse,
const struct ec_strvec *strvec)
{
- struct ec_node_dynamic *node = (struct ec_node_dynamic *)gen_node;
+ struct ec_node_dynamic *priv = ec_node_priv(node);
struct ec_node *child = NULL;
void (*node_free)(struct ec_node *) = ec_node_free;
char key[64];
int ret = -1;
- child = node->build(parse, node->opaque);
+ child = priv->build(parse, priv->opaque);
if (child == NULL)
goto fail;
}
static int
-ec_node_dynamic_complete(const struct ec_node *gen_node,
+ec_node_dynamic_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_dynamic *node = (struct ec_node_dynamic *)gen_node;
+ struct ec_node_dynamic *priv = ec_node_priv(node);
struct ec_parse *parse;
struct ec_node *child = NULL;
void (*node_free)(struct ec_node *) = ec_node_free;
int ret = -1;
parse = ec_comp_get_state(comp);
- child = node->build(parse, node->opaque);
+ child = priv->build(parse, priv->opaque);
if (child == NULL)
goto fail;
struct ec_node *
ec_node_dynamic(const char *id, ec_node_dynamic_build_t build, void *opaque)
{
- struct ec_node *gen_node = NULL;
- struct ec_node_dynamic *node;
+ struct ec_node *node = NULL;
+ struct ec_node_dynamic *priv;
if (build == NULL) {
errno = EINVAL;
goto fail;
}
- gen_node = ec_node_from_type(&ec_node_dynamic_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_dynamic_type, id);
+ if (node == NULL)
goto fail;
- node = (struct ec_node_dynamic *)gen_node;
- node->build = build;
- node->opaque = opaque;
+ priv = ec_node_priv(node);
+ priv->build = build;
+ priv->opaque = opaque;
- return gen_node;
+ return node;
fail:
- ec_node_free(gen_node);
+ ec_node_free(node);
return NULL;
}
for (iter = root; iter != NULL;
iter = EC_PARSE_ITER_NEXT(root, iter, 1)) {
node = ec_parse_get_node(iter);
- if (node->id && !strcmp(node->id, "my-id"))
+ if (!strcmp(ec_node_id(node), "my-id"))
count++;
}
snprintf(buf, sizeof(buf), "count-%u", count);
EC_LOG_TYPE_REGISTER(node_empty);
struct ec_node_empty {
- struct ec_node gen;
};
-static int ec_node_empty_parse(const struct ec_node *gen_node,
+static int ec_node_empty_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- (void)gen_node;
+ (void)node;
(void)state;
(void)strvec;
return 0;
EC_LOG_TYPE_REGISTER(node_expr);
struct ec_node_expr {
- struct ec_node gen;
-
/* the built node */
struct ec_node *child;
unsigned int paren_len;
};
-static int ec_node_expr_parse(const struct ec_node *gen_node,
+static int ec_node_expr_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+ struct ec_node_expr *priv = ec_node_priv(node);
- if (node->child == NULL) {
+ if (priv->child == NULL) {
errno = ENOENT;
return -1;
}
- return ec_node_parse_child(node->child, state, strvec);
+ return ec_node_parse_child(priv->child, state, strvec);
}
static int
-ec_node_expr_complete(const struct ec_node *gen_node,
+ec_node_expr_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+ struct ec_node_expr *priv = ec_node_priv(node);
- if (node->child == NULL) {
+ if (priv->child == NULL) {
errno = ENOENT;
return -1;
}
- return ec_node_complete_child(node->child, comp, strvec);
+ return ec_node_complete_child(priv->child, comp, strvec);
}
-static void ec_node_expr_free_priv(struct ec_node *gen_node)
+static void ec_node_expr_free_priv(struct ec_node *node)
{
- struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+ struct ec_node_expr *priv = ec_node_priv(node);
unsigned int i;
- ec_node_free(node->child);
- ec_node_free(node->val_node);
-
- for (i = 0; i < node->bin_ops_len; i++)
- ec_node_free(node->bin_ops[i]);
- ec_free(node->bin_ops);
- for (i = 0; i < node->pre_ops_len; i++)
- ec_node_free(node->pre_ops[i]);
- ec_free(node->pre_ops);
- for (i = 0; i < node->post_ops_len; i++)
- ec_node_free(node->post_ops[i]);
- ec_free(node->post_ops);
- for (i = 0; i < node->paren_len; i++) {
- ec_node_free(node->open_ops[i]);
- ec_node_free(node->close_ops[i]);
+ ec_node_free(priv->child);
+ ec_node_free(priv->val_node);
+
+ for (i = 0; i < priv->bin_ops_len; i++)
+ ec_node_free(priv->bin_ops[i]);
+ ec_free(priv->bin_ops);
+ for (i = 0; i < priv->pre_ops_len; i++)
+ ec_node_free(priv->pre_ops[i]);
+ ec_free(priv->pre_ops);
+ for (i = 0; i < priv->post_ops_len; i++)
+ ec_node_free(priv->post_ops[i]);
+ ec_free(priv->post_ops);
+ for (i = 0; i < priv->paren_len; i++) {
+ ec_node_free(priv->open_ops[i]);
+ ec_node_free(priv->close_ops[i]);
}
- ec_free(node->open_ops);
- ec_free(node->close_ops);
+ ec_free(priv->open_ops);
+ ec_free(priv->close_ops);
}
-static int ec_node_expr_build(struct ec_node_expr *node)
+static int ec_node_expr_build(struct ec_node_expr *priv)
{
struct ec_node *term = NULL, *expr = NULL, *next = NULL,
*pre_op = NULL, *post_op = NULL, *ref = NULL,
*post = NULL;
unsigned int i;
- ec_node_free(node->child);
- node->child = NULL;
+ ec_node_free(priv->child);
+ priv->child = NULL;
- if (node->val_node == NULL) {
+ if (priv->val_node == NULL) {
errno = EINVAL;
return -1;
}
- if (node->bin_ops_len == 0 && node->pre_ops_len == 0 &&
- node->post_ops_len == 0) {
+ if (priv->bin_ops_len == 0 && priv->pre_ops_len == 0 &&
+ priv->post_ops_len == 0) {
errno = EINVAL;
return -1;
}
pre_op = ec_node("or", "pre-op");
if (pre_op == NULL)
goto fail;
- for (i = 0; i < node->pre_ops_len; i++) {
- if (ec_node_or_add(pre_op, ec_node_clone(node->pre_ops[i])) < 0)
+ for (i = 0; i < priv->pre_ops_len; i++) {
+ if (ec_node_or_add(pre_op, ec_node_clone(priv->pre_ops[i])) < 0)
goto fail;
}
post_op = ec_node("or", "post-op");
if (post_op == NULL)
goto fail;
- for (i = 0; i < node->post_ops_len; i++) {
- if (ec_node_or_add(post_op, ec_node_clone(node->post_ops[i])) < 0)
+ for (i = 0; i < priv->post_ops_len; i++) {
+ if (ec_node_or_add(post_op, ec_node_clone(priv->post_ops[i])) < 0)
goto fail;
}
post = ec_node("or", "post");
if (post == NULL)
goto fail;
- if (ec_node_or_add(post, ec_node_clone(node->val_node)) < 0)
+ if (ec_node_or_add(post, ec_node_clone(priv->val_node)) < 0)
goto fail;
if (ec_node_or_add(post,
EC_NODE_SEQ(EC_NO_ID,
ec_node_clone(pre_op),
ec_node_clone(ref))) < 0)
goto fail;
- for (i = 0; i < node->paren_len; i++) {
+ for (i = 0; i < priv->paren_len; i++) {
if (ec_node_or_add(post, EC_NODE_SEQ(EC_NO_ID,
- ec_node_clone(node->open_ops[i]),
+ ec_node_clone(priv->open_ops[i]),
ec_node_clone(ref),
- ec_node_clone(node->close_ops[i]))) < 0)
+ ec_node_clone(priv->close_ops[i]))) < 0)
goto fail;
}
term = EC_NODE_SEQ("term",
if (term == NULL)
goto fail;
- for (i = 0; i < node->bin_ops_len; i++) {
+ for (i = 0; i < priv->bin_ops_len; i++) {
next = EC_NODE_SEQ("next",
ec_node_clone(term),
ec_node_many(EC_NO_ID,
EC_NODE_SEQ(EC_NO_ID,
- ec_node_clone(node->bin_ops[i]),
+ ec_node_clone(priv->bin_ops[i]),
ec_node_clone(term)
),
0, 0
ec_node_free(ref);
ref = NULL;
- node->child = expr;
+ priv->child = expr;
return 0;
}
static size_t
-ec_node_expr_get_children_count(const struct ec_node *gen_node)
+ec_node_expr_get_children_count(const struct ec_node *node)
{
- struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+ struct ec_node_expr *priv = ec_node_priv(node);
- if (node->child)
+ if (priv->child)
return 1;
return 0;
}
static int
-ec_node_expr_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_expr_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+ struct ec_node_expr *priv = ec_node_priv(node);
if (i >= 1)
return -1;
- *child = node->child;
+ *child = priv->child;
*refs = 1;
return 0;
}
EC_NODE_TYPE_REGISTER(ec_node_expr_type);
-int ec_node_expr_set_val_node(struct ec_node *gen_node, struct ec_node *val_node)
+int ec_node_expr_set_val_node(struct ec_node *node, struct ec_node *val_node)
{
- struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+ struct ec_node_expr *priv = ec_node_priv(node);
- if (ec_node_check_type(gen_node, &ec_node_expr_type) < 0)
+ if (ec_node_check_type(node, &ec_node_expr_type) < 0)
goto fail;
if (val_node == NULL) {
goto fail;
}
- ec_node_free(node->val_node);
- node->val_node = val_node;
- ec_node_expr_build(node);
+ ec_node_free(priv->val_node);
+ priv->val_node = val_node;
+ ec_node_expr_build(priv);
return 0;
}
/* add a binary operator */
-int ec_node_expr_add_bin_op(struct ec_node *gen_node, struct ec_node *op)
+int ec_node_expr_add_bin_op(struct ec_node *node, struct ec_node *op)
{
- struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+ struct ec_node_expr *priv = ec_node_priv(node);
struct ec_node **bin_ops;
- if (ec_node_check_type(gen_node, &ec_node_expr_type) < 0)
+ if (ec_node_check_type(node, &ec_node_expr_type) < 0)
goto fail;
if (node == NULL || op == NULL) {
goto fail;
}
- bin_ops = ec_realloc(node->bin_ops,
- (node->bin_ops_len + 1) * sizeof(*node->bin_ops));
+ bin_ops = ec_realloc(priv->bin_ops,
+ (priv->bin_ops_len + 1) * sizeof(*priv->bin_ops));
if (bin_ops == NULL)
goto fail;;
- node->bin_ops = bin_ops;
- bin_ops[node->bin_ops_len] = op;
- node->bin_ops_len++;
- ec_node_expr_build(node);
+ priv->bin_ops = bin_ops;
+ bin_ops[priv->bin_ops_len] = op;
+ priv->bin_ops_len++;
+ ec_node_expr_build(priv);
return 0;
}
/* add a unary pre-operator */
-int ec_node_expr_add_pre_op(struct ec_node *gen_node, struct ec_node *op)
+int ec_node_expr_add_pre_op(struct ec_node *node, struct ec_node *op)
{
- struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+ struct ec_node_expr *priv = ec_node_priv(node);
struct ec_node **pre_ops;
- if (ec_node_check_type(gen_node, &ec_node_expr_type) < 0)
+ if (ec_node_check_type(node, &ec_node_expr_type) < 0)
goto fail;
if (node == NULL || op == NULL) {
goto fail;
}
- pre_ops = ec_realloc(node->pre_ops,
- (node->pre_ops_len + 1) * sizeof(*node->pre_ops));
+ pre_ops = ec_realloc(priv->pre_ops,
+ (priv->pre_ops_len + 1) * sizeof(*priv->pre_ops));
if (pre_ops == NULL)
goto fail;
- node->pre_ops = pre_ops;
- pre_ops[node->pre_ops_len] = op;
- node->pre_ops_len++;
- ec_node_expr_build(node);
+ priv->pre_ops = pre_ops;
+ pre_ops[priv->pre_ops_len] = op;
+ priv->pre_ops_len++;
+ ec_node_expr_build(priv);
return 0;
}
/* add a unary post-operator */
-int ec_node_expr_add_post_op(struct ec_node *gen_node, struct ec_node *op)
+int ec_node_expr_add_post_op(struct ec_node *node, struct ec_node *op)
{
- struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+ struct ec_node_expr *priv = ec_node_priv(node);
struct ec_node **post_ops;
- if (ec_node_check_type(gen_node, &ec_node_expr_type) < 0)
+ if (ec_node_check_type(node, &ec_node_expr_type) < 0)
goto fail;
if (node == NULL || op == NULL) {
goto fail;
}
- post_ops = ec_realloc(node->post_ops,
- (node->post_ops_len + 1) * sizeof(*node->post_ops));
+ post_ops = ec_realloc(priv->post_ops,
+ (priv->post_ops_len + 1) * sizeof(*priv->post_ops));
if (post_ops == NULL)
goto fail;
- node->post_ops = post_ops;
- post_ops[node->post_ops_len] = op;
- node->post_ops_len++;
- ec_node_expr_build(node);
+ priv->post_ops = post_ops;
+ post_ops[priv->post_ops_len] = op;
+ priv->post_ops_len++;
+ ec_node_expr_build(priv);
return 0;
}
/* add parenthesis symbols */
-int ec_node_expr_add_parenthesis(struct ec_node *gen_node,
+int ec_node_expr_add_parenthesis(struct ec_node *node,
struct ec_node *open, struct ec_node *close)
{
- struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+ struct ec_node_expr *priv = ec_node_priv(node);
struct ec_node **open_ops, **close_ops;
- if (ec_node_check_type(gen_node, &ec_node_expr_type) < 0)
+ if (ec_node_check_type(node, &ec_node_expr_type) < 0)
goto fail;
if (node == NULL || open == NULL || close == NULL) {
goto fail;
}
- open_ops = ec_realloc(node->open_ops,
- (node->paren_len + 1) * sizeof(*node->open_ops));
+ open_ops = ec_realloc(priv->open_ops,
+ (priv->paren_len + 1) * sizeof(*priv->open_ops));
if (open_ops == NULL)
goto fail;
- close_ops = ec_realloc(node->close_ops,
- (node->paren_len + 1) * sizeof(*node->close_ops));
+ close_ops = ec_realloc(priv->close_ops,
+ (priv->paren_len + 1) * sizeof(*priv->close_ops));
if (close_ops == NULL)
goto fail;
- node->open_ops = open_ops;
- node->close_ops = close_ops;
- open_ops[node->paren_len] = open;
- close_ops[node->paren_len] = close;
- node->paren_len++;
- ec_node_expr_build(node);
+ priv->open_ops = open_ops;
+ priv->close_ops = close_ops;
+ open_ops[priv->paren_len] = open;
+ close_ops[priv->paren_len] = close;
+ priv->paren_len++;
+ ec_node_expr_build(priv);
return 0;
PAREN_CLOSE,
};
-static enum expr_node_type get_node_type(const struct ec_node *expr_gen_node,
+static enum expr_node_type get_node_type(const struct ec_node *expr_node,
const struct ec_node *check)
{
- struct ec_node_expr *expr_node = (struct ec_node_expr *)expr_gen_node;
+ struct ec_node_expr *expr_priv = ec_node_priv(expr_node);
size_t i;
- if (check == expr_node->val_node)
+ if (check == expr_priv->val_node)
return VAL;
- for (i = 0; i < expr_node->bin_ops_len; i++) {
- if (check == expr_node->bin_ops[i])
+ for (i = 0; i < expr_priv->bin_ops_len; i++) {
+ if (check == expr_priv->bin_ops[i])
return BIN_OP;
}
- for (i = 0; i < expr_node->pre_ops_len; i++) {
- if (check == expr_node->pre_ops[i])
+ for (i = 0; i < expr_priv->pre_ops_len; i++) {
+ if (check == expr_priv->pre_ops[i])
return PRE_OP;
}
- for (i = 0; i < expr_node->post_ops_len; i++) {
- if (check == expr_node->post_ops[i])
+ for (i = 0; i < expr_priv->post_ops_len; i++) {
+ if (check == expr_priv->post_ops[i])
return POST_OP;
}
- for (i = 0; i < expr_node->paren_len; i++) {
- if (check == expr_node->open_ops[i])
+ for (i = 0; i < expr_priv->paren_len; i++) {
+ if (check == expr_priv->open_ops[i])
return PAREN_OPEN;
}
- for (i = 0; i < expr_node->paren_len; i++) {
- if (check == expr_node->close_ops[i])
+ for (i = 0; i < expr_priv->paren_len; i++) {
+ if (check == expr_priv->close_ops[i])
return PAREN_CLOSE;
}
static int eval_expression(struct result *result,
void *userctx,
const struct ec_node_expr_eval_ops *ops,
- const struct ec_node *expr_gen_node,
+ const struct ec_node *expr_node,
const struct ec_parse *parse)
{
memset(result, 0, sizeof(*result));
memset(&child_result, 0, sizeof(child_result));
- type = get_node_type(expr_gen_node, ec_parse_get_node(parse));
+ type = get_node_type(expr_node, ec_parse_get_node(parse));
if (type == VAL) {
if (ops->eval_var(&result->val, userctx, parse) < 0)
goto fail;
EC_PARSE_FOREACH_CHILD(child, parse) {
- type = get_node_type(expr_gen_node, ec_parse_get_node(child));
+ type = get_node_type(expr_node, ec_parse_get_node(child));
if (type == PAREN_OPEN) {
open = child;
continue;
}
if (eval_expression(&child_result, userctx, ops,
- expr_gen_node, child) < 0)
+ expr_node, child) < 0)
goto fail;
if (merge_results(userctx, ops, result, &child_result) < 0)
EC_LOG_TYPE_REGISTER(node_file);
struct ec_node_file {
- struct ec_node gen;
-
/* below functions pointers are only useful for test */
int (*lstat)(const char *pathname, struct stat *buf);
DIR *(*opendir)(const char *name);
};
static int
-ec_node_file_parse(const struct ec_node *gen_node,
+ec_node_file_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- (void)gen_node;
+ (void)node;
(void)state;
if (ec_strvec_len(strvec) == 0)
}
static int
-ec_node_file_complete(const struct ec_node *gen_node,
+ec_node_file_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_file *node = (struct ec_node_file *)gen_node;
+ struct ec_node_file *priv = ec_node_priv(node);
char *dname = NULL, *bname = NULL, *effective_dir;
struct ec_comp_item *item = NULL;
enum ec_comp_type type;
else
effective_dir = dname;
- if (node->lstat(effective_dir, &st) < 0)
+ if (priv->lstat(effective_dir, &st) < 0)
goto fail;
if (!S_ISDIR(st.st_mode))
goto out;
- dir = node->opendir(effective_dir);
+ dir = priv->opendir(effective_dir);
if (dir == NULL)
goto fail;
int save_errno = errno;
errno = 0;
- de = node->readdir(dir);
+ de = priv->readdir(dir);
if (de == NULL) {
if (errno == 0) {
errno = save_errno;
if (de->d_type == DT_DIR) {
is_dir = 1;
} else if (de->d_type == DT_UNKNOWN) {
- int dir_fd = node->dirfd(dir);
+ int dir_fd = priv->dirfd(dir);
if (dir_fd < 0)
goto fail;
- if (node->fstatat(dir_fd, de->d_name, &st2, 0) < 0)
+ if (priv->fstatat(dir_fd, de->d_name, &st2, 0) < 0)
goto fail;
if (S_ISDIR(st2.st_mode))
is_dir = 1;
if (ec_asprintf(&disp_str, "%s", de->d_name) < 0)
goto fail;
}
- if (ec_comp_add_item(comp, gen_node, &item,
+ if (ec_comp_add_item(comp, node, &item,
type, input, comp_str) < 0)
goto out;
ec_free(dname);
ec_free(bname);
if (dir != NULL)
- node->closedir(dir);
+ priv->closedir(dir);
return 0;
ec_free(dname);
ec_free(bname);
if (dir != NULL)
- node->closedir(dir);
+ priv->closedir(dir);
return -1;
}
static int
-ec_node_file_init_priv(struct ec_node *gen_node)
+ec_node_file_init_priv(struct ec_node *node)
{
- struct ec_node_file *node = (struct ec_node_file *)gen_node;
+ struct ec_node_file *priv = ec_node_priv(node);
- node->lstat = lstat;
- node->opendir = opendir;
- node->readdir = readdir;
- node->dirfd = dirfd;
- node->fstatat = fstatat;
+ priv->lstat = lstat;
+ priv->opendir = opendir;
+ priv->readdir = readdir;
+ priv->dirfd = dirfd;
+ priv->fstatat = fstatat;
return 0;
}
}
static int
-ec_node_file_override_functions(struct ec_node *gen_node)
+ec_node_file_override_functions(struct ec_node *node)
{
- struct ec_node_file *node = (struct ec_node_file *)gen_node;
-
- node->lstat = test_lstat;
- node->opendir = test_opendir;
- node->readdir = test_readdir;
- node->closedir = test_closedir;
- node->dirfd = test_dirfd;
- node->fstatat = test_fstatat;
+ struct ec_node_file *priv = ec_node_priv(node);
+
+ priv->lstat = test_lstat;
+ priv->opendir = test_opendir;
+ priv->readdir = test_readdir;
+ priv->closedir = test_closedir;
+ priv->dirfd = test_dirfd;
+ priv->fstatat = test_fstatat;
return 0;
}
/* common to int and uint */
struct ec_node_int_uint {
- struct ec_node gen;
bool is_signed;
bool check_min;
bool check_max;
unsigned int base;
};
-static int parse_llint(struct ec_node_int_uint *node, const char *str,
+static int parse_llint(struct ec_node_int_uint *priv, const char *str,
int64_t *val)
{
int64_t min, max;
- if (node->check_min)
- min = node->min;
+ if (priv->check_min)
+ min = priv->min;
else
min = LLONG_MIN;
- if (node->check_max)
- max = node->max;
+ if (priv->check_max)
+ max = priv->max;
else
max = LLONG_MAX;
- return ec_str_parse_llint(str, node->base, min, max, val);
+ return ec_str_parse_llint(str, priv->base, min, max, val);
}
-static int parse_ullint(struct ec_node_int_uint *node, const char *str,
+static int parse_ullint(struct ec_node_int_uint *priv, const char *str,
uint64_t *val)
{
uint64_t min, max;
- if (node->check_min)
- min = node->min;
+ if (priv->check_min)
+ min = priv->min;
else
min = 0;
- if (node->check_max)
- max = node->max;
+ if (priv->check_max)
+ max = priv->max;
else
max = ULLONG_MAX;
- return ec_str_parse_ullint(str, node->base, min, max, val);
+ return ec_str_parse_ullint(str, priv->base, min, max, val);
}
-static int ec_node_int_uint_parse(const struct ec_node *gen_node,
+static int ec_node_int_uint_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+ struct ec_node_int_uint *priv = ec_node_priv(node);
const char *str;
uint64_t u64;
int64_t i64;
return EC_PARSE_NOMATCH;
str = ec_strvec_val(strvec, 0);
- if (node->is_signed) {
- if (parse_llint(node, str, &i64) < 0)
+ if (priv->is_signed) {
+ if (parse_llint(priv, str, &i64) < 0)
return EC_PARSE_NOMATCH;
} else {
- if (parse_ullint(node, str, &u64) < 0)
+ if (parse_ullint(priv, str, &u64) < 0)
return EC_PARSE_NOMATCH;
}
return 1;
}
static int
-ec_node_uint_init_priv(struct ec_node *gen_node)
+ec_node_uint_init_priv(struct ec_node *node)
{
- struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+ struct ec_node_int_uint *priv = ec_node_priv(node);
- node->is_signed = true;
+ priv->is_signed = true;
return 0;
}
},
};
-static int ec_node_int_set_config(struct ec_node *gen_node,
+static int ec_node_int_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+ struct ec_node_int_uint *priv = ec_node_priv(node);
const struct ec_config *min_value = NULL;
const struct ec_config *max_value = NULL;
const struct ec_config *base_value = NULL;
}
if (min_value != NULL) {
- node->check_min = true;
- node->min = min_value->i64;
+ priv->check_min = true;
+ priv->min = min_value->i64;
} else {
- node->check_min = false;
+ priv->check_min = false;
}
if (max_value != NULL) {
- node->check_max = true;
- node->max = max_value->i64;
+ priv->check_max = true;
+ priv->max = max_value->i64;
} else {
- node->check_min = false;
+ priv->check_min = false;
}
if (base_value != NULL)
- node->base = base_value->u64;
+ priv->base = base_value->u64;
else
- node->base = 0;
+ priv->base = 0;
return 0;
int64_t max, unsigned int base)
{
struct ec_config *config = NULL;
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
int ret;
- gen_node = ec_node_from_type(&ec_node_int_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_int_type, id);
+ if (node == NULL)
return NULL;
config = ec_config_dict();
if (ret < 0)
goto fail;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL;
if (ret < 0)
goto fail;
- return gen_node;
+ return node;
fail:
ec_config_free(config);
- ec_node_free(gen_node);
+ ec_node_free(node);
return NULL;
}
},
};
-static int ec_node_uint_set_config(struct ec_node *gen_node,
+static int ec_node_uint_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+ struct ec_node_int_uint *priv = ec_node_priv(node);
const struct ec_config *min_value = NULL;
const struct ec_config *max_value = NULL;
const struct ec_config *base_value = NULL;
}
if (min_value != NULL) {
- node->check_min = true;
- node->min = min_value->u64;
+ priv->check_min = true;
+ priv->min = min_value->u64;
} else {
- node->check_min = false;
+ priv->check_min = false;
}
if (max_value != NULL) {
- node->check_max = true;
- node->max = max_value->u64;
+ priv->check_max = true;
+ priv->max = max_value->u64;
} else {
- node->check_min = false;
+ priv->check_min = false;
}
if (base_value != NULL)
- node->base = base_value->u64;
+ priv->base = base_value->u64;
else
- node->base = 0;
+ priv->base = 0;
return 0;
uint64_t max, unsigned int base)
{
struct ec_config *config = NULL;
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
int ret;
- gen_node = ec_node_from_type(&ec_node_uint_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_uint_type, id);
+ if (node == NULL)
return NULL;
config = ec_config_dict();
if (ret < 0)
goto fail;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL;
if (ret < 0)
goto fail;
- return gen_node;
+ return node;
fail:
ec_config_free(config);
- ec_node_free(gen_node);
+ ec_node_free(node);
return NULL;
}
-int ec_node_int_getval(const struct ec_node *gen_node, const char *str,
+int ec_node_int_getval(const struct ec_node *node, const char *str,
int64_t *result)
{
- struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+ struct ec_node_int_uint *priv = ec_node_priv(node);
int ret;
- ret = ec_node_check_type(gen_node, &ec_node_int_type);
+ ret = ec_node_check_type(node, &ec_node_int_type);
if (ret < 0)
return ret;
- if (parse_llint(node, str, result) < 0)
+ if (parse_llint(priv, str, result) < 0)
return -1;
return 0;
}
-int ec_node_uint_getval(const struct ec_node *gen_node, const char *str,
+int ec_node_uint_getval(const struct ec_node *node, const char *str,
uint64_t *result)
{
- struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+ struct ec_node_int_uint *priv = ec_node_priv(node);
int ret;
- ret = ec_node_check_type(gen_node, &ec_node_uint_type);
+ ret = ec_node_check_type(node, &ec_node_uint_type);
if (ret < 0)
return ret;
- if (parse_ullint(node, str, result) < 0)
+ if (parse_ullint(priv, str, result) < 0)
return -1;
return 0;
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;
}
EC_LOG_TYPE_REGISTER(node_none);
struct ec_node_none {
- struct ec_node gen;
};
-static int ec_node_none_parse(const struct ec_node *gen_node,
+static int ec_node_none_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- (void)gen_node;
+ (void)node;
(void)state;
(void)strvec;
}
static int
-ec_node_none_complete(const struct ec_node *gen_node,
+ec_node_none_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- (void)gen_node;
+ (void)node;
(void)comp;
(void)strvec;
EC_LOG_TYPE_REGISTER(node_once);
struct ec_node_once {
- struct ec_node gen;
struct ec_node *child;
};
}
static int
-ec_node_once_parse(const struct ec_node *gen_node,
+ec_node_once_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_once *node = (struct ec_node_once *)gen_node;
+ struct ec_node_once *priv = ec_node_priv(node);
unsigned int count;
/* count the number of occurences of the node: if already parsed,
* do not match
*/
- count = count_node(ec_parse_get_root(state), node->child);
+ count = count_node(ec_parse_get_root(state), priv->child);
if (count > 0)
return EC_PARSE_NOMATCH;
- return ec_node_parse_child(node->child, state, strvec);
+ return ec_node_parse_child(priv->child, state, strvec);
}
static int
-ec_node_once_complete(const struct ec_node *gen_node,
+ec_node_once_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_once *node = (struct ec_node_once *)gen_node;
+ struct ec_node_once *priv = ec_node_priv(node);
struct ec_parse *parse = ec_comp_get_state(comp);
unsigned int count;
int ret;
/* count the number of occurences of the node: if already parsed,
* do not match
*/
- count = count_node(ec_parse_get_root(parse), node->child);
+ count = count_node(ec_parse_get_root(parse), priv->child);
if (count > 0)
return 0;
- ret = ec_node_complete_child(node->child, comp, strvec);
+ ret = ec_node_complete_child(priv->child, comp, strvec);
if (ret < 0)
return ret;
return 0;
}
-static void ec_node_once_free_priv(struct ec_node *gen_node)
+static void ec_node_once_free_priv(struct ec_node *node)
{
- struct ec_node_once *node = (struct ec_node_once *)gen_node;
+ struct ec_node_once *priv = ec_node_priv(node);
- ec_node_free(node->child);
+ ec_node_free(priv->child);
}
static size_t
-ec_node_once_get_children_count(const struct ec_node *gen_node)
+ec_node_once_get_children_count(const struct ec_node *node)
{
- struct ec_node_once *node = (struct ec_node_once *)gen_node;
+ struct ec_node_once *priv = ec_node_priv(node);
- if (node->child)
+ if (priv->child)
return 1;
return 0;
}
static int
-ec_node_once_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_once_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_once *node = (struct ec_node_once *)gen_node;
+ struct ec_node_once *priv = ec_node_priv(node);
if (i >= 1)
return -1;
- *child = node->child;
+ *child = priv->child;
*refs = 2;
return 0;
}
},
};
-static int ec_node_once_set_config(struct ec_node *gen_node,
+static int ec_node_once_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_once *node = (struct ec_node_once *)gen_node;
+ struct ec_node_once *priv = ec_node_priv(node);
const struct ec_config *child;
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);
return 0;
EC_NODE_TYPE_REGISTER(ec_node_once_type);
int
-ec_node_once_set_child(struct ec_node *gen_node, struct ec_node *child)
+ec_node_once_set_child(struct ec_node *node, struct ec_node *child)
{
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL;
int ret;
- if (ec_node_check_type(gen_node, &ec_node_once_type) < 0)
+ if (ec_node_check_type(node, &ec_node_once_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
}
child = NULL; /* freed */
- 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_once(const char *id, struct ec_node *child)
{
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
if (child == NULL)
return NULL;
- gen_node = ec_node_from_type(&ec_node_once_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_once_type, id);
+ if (node == NULL)
goto fail;
- ec_node_once_set_child(gen_node, child);
+ ec_node_once_set_child(node, child);
child = NULL;
- return gen_node;
+ return node;
fail:
ec_node_free(child);
EC_LOG_TYPE_REGISTER(node_option);
struct ec_node_option {
- struct ec_node gen;
struct ec_node *child;
};
static int
-ec_node_option_parse(const struct ec_node *gen_node,
+ec_node_option_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_option *node = (struct ec_node_option *)gen_node;
+ struct ec_node_option *priv = ec_node_priv(node);
int ret;
- ret = ec_node_parse_child(node->child, state, strvec);
+ ret = ec_node_parse_child(priv->child, state, strvec);
if (ret < 0)
return ret;
}
static int
-ec_node_option_complete(const struct ec_node *gen_node,
+ec_node_option_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_option *node = (struct ec_node_option *)gen_node;
+ struct ec_node_option *priv = ec_node_priv(node);
- return ec_node_complete_child(node->child, comp, strvec);
+ return ec_node_complete_child(priv->child, comp, strvec);
}
-static void ec_node_option_free_priv(struct ec_node *gen_node)
+static void ec_node_option_free_priv(struct ec_node *node)
{
- struct ec_node_option *node = (struct ec_node_option *)gen_node;
+ struct ec_node_option *priv = ec_node_priv(node);
- ec_node_free(node->child);
+ ec_node_free(priv->child);
}
static size_t
-ec_node_option_get_children_count(const struct ec_node *gen_node)
+ec_node_option_get_children_count(const struct ec_node *node)
{
- struct ec_node_option *node = (struct ec_node_option *)gen_node;
+ struct ec_node_option *priv = ec_node_priv(node);
- if (node->child)
+ if (priv->child)
return 1;
return 0;
}
static int
-ec_node_option_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_option_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_option *node = (struct ec_node_option *)gen_node;
+ struct ec_node_option *priv = ec_node_priv(node);
if (i >= 1)
return -1;
- *child = node->child;
+ *child = priv->child;
*refs = 2;
return 0;
}
},
};
-static int ec_node_option_set_config(struct ec_node *gen_node,
+static int ec_node_option_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_option *node = (struct ec_node_option *)gen_node;
+ struct ec_node_option *priv = ec_node_priv(node);
const struct ec_config *child;
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);
return 0;
EC_NODE_TYPE_REGISTER(ec_node_option_type);
int
-ec_node_option_set_child(struct ec_node *gen_node, struct ec_node *child)
+ec_node_option_set_child(struct ec_node *node, struct ec_node *child)
{
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL;
int ret;
- if (ec_node_check_type(gen_node, &ec_node_option_type) < 0)
+ if (ec_node_check_type(node, &ec_node_option_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
}
child = NULL; /* freed */
- 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_option(const char *id, struct ec_node *child)
{
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
if (child == NULL)
goto fail;
- gen_node = ec_node_from_type(&ec_node_option_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_option_type, id);
+ if (node == NULL)
goto fail;
- ec_node_option_set_child(gen_node, child);
+ ec_node_option_set_child(node, child);
child = NULL;
- return gen_node;
+ return node;
fail:
ec_node_free(child);
EC_LOG_TYPE_REGISTER(node_or);
struct ec_node_or {
- struct ec_node gen;
struct ec_node **table;
size_t len;
};
static int
-ec_node_or_parse(const struct ec_node *gen_node,
+ec_node_or_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_or *node = (struct ec_node_or *)gen_node;
+ struct ec_node_or *priv = ec_node_priv(node);
unsigned int i;
int ret;
- for (i = 0; i < node->len; i++) {
- ret = ec_node_parse_child(node->table[i], state, strvec);
+ for (i = 0; i < priv->len; i++) {
+ ret = ec_node_parse_child(priv->table[i], state, strvec);
if (ret == EC_PARSE_NOMATCH)
continue;
return ret;
}
static int
-ec_node_or_complete(const struct ec_node *gen_node,
+ec_node_or_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_or *node = (struct ec_node_or *)gen_node;
+ struct ec_node_or *priv = ec_node_priv(node);
int ret;
size_t n;
- for (n = 0; n < node->len; n++) {
- ret = ec_node_complete_child(node->table[n],
+ for (n = 0; n < priv->len; n++) {
+ ret = ec_node_complete_child(priv->table[n],
comp, strvec);
if (ret < 0)
return ret;
return 0;
}
-static void ec_node_or_free_priv(struct ec_node *gen_node)
+static void ec_node_or_free_priv(struct ec_node *node)
{
- struct ec_node_or *node = (struct ec_node_or *)gen_node;
+ struct ec_node_or *priv = ec_node_priv(node);
size_t i;
- for (i = 0; i < node->len; i++)
- ec_node_free(node->table[i]);
- ec_free(node->table);
- node->table = NULL;
- node->len = 0;
+ for (i = 0; i < priv->len; i++)
+ ec_node_free(priv->table[i]);
+ ec_free(priv->table);
+ priv->table = NULL;
+ priv->len = 0;
}
static const struct ec_config_schema ec_node_or_subschema[] = {
},
};
-static int ec_node_or_set_config(struct ec_node *gen_node,
+static int ec_node_or_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_or *node = (struct ec_node_or *)gen_node;
+ struct ec_node_or *priv = ec_node_priv(node);
struct ec_node **table = NULL;
size_t i, len = 0;
if (table == NULL)
goto fail;
- for (i = 0; i < node->len; i++)
- ec_node_free(node->table[i]);
- ec_free(node->table);
- node->table = table;
- node->len = len;
+ for (i = 0; i < priv->len; i++)
+ ec_node_free(priv->table[i]);
+ ec_free(priv->table);
+ priv->table = table;
+ priv->len = len;
return 0;
}
static size_t
-ec_node_or_get_children_count(const struct ec_node *gen_node)
+ec_node_or_get_children_count(const struct ec_node *node)
{
- struct ec_node_or *node = (struct ec_node_or *)gen_node;
- return node->len;
+ struct ec_node_or *priv = ec_node_priv(node);
+ return priv->len;
}
static int
-ec_node_or_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_or_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_or *node = (struct ec_node_or *)gen_node;
+ struct ec_node_or *priv = ec_node_priv(node);
- if (i >= node->len)
+ if (i >= priv->len)
return -1;
- *child = node->table[i];
+ *child = priv->table[i];
/* each child node is referenced twice: once in the config and
- * once in the node->table[] */
+ * once in the priv->table[] */
*refs = 2;
return 0;
}
EC_NODE_TYPE_REGISTER(ec_node_or_type);
-int ec_node_or_add(struct ec_node *gen_node, struct ec_node *child)
+int ec_node_or_add(struct ec_node *node, struct ec_node *child)
{
- struct ec_node_or *node = (struct ec_node_or *)gen_node;
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL, *children;
int ret;
/* XXX factorize this code in a helper */
- if (ec_node_check_type(gen_node, &ec_node_or_type) < 0)
+ if (ec_node_check_type(node, &ec_node_or_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
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_or(const char *id, ...)
{
struct ec_config *config = NULL, *children = NULL;
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
struct ec_node *child;
va_list ap;
int ret;
va_start(ap, id);
child = va_arg(ap, struct ec_node *);
- gen_node = ec_node_from_type(&ec_node_or_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_or_type, id);
+ if (node == NULL)
goto fail_free_children;
config = ec_config_dict();
}
children = NULL;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL; /* freed */
if (ret < 0)
goto fail;
va_end(ap);
- return gen_node;
+ return node;
fail_free_children:
for (; child != EC_NODE_ENDLIST; child = va_arg(ap, struct ec_node *))
ec_node_free(child);
fail:
- ec_node_free(gen_node); /* will also free added children */
+ ec_node_free(node); /* will also free added children */
ec_config_free(children);
ec_config_free(config);
va_end(ap);
EC_LOG_TYPE_REGISTER(node_re);
struct ec_node_re {
- struct ec_node gen;
char *re_str;
regex_t re;
};
static int
-ec_node_re_parse(const struct ec_node *gen_node,
+ec_node_re_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_re *node = (struct ec_node_re *)gen_node;
+ struct ec_node_re *priv = ec_node_priv(node);
const char *str;
regmatch_t pos;
return EC_PARSE_NOMATCH;
str = ec_strvec_val(strvec, 0);
- if (regexec(&node->re, str, 1, &pos, 0) != 0)
+ if (regexec(&priv->re, str, 1, &pos, 0) != 0)
return EC_PARSE_NOMATCH;
if (pos.rm_so != 0 || pos.rm_eo != (int)strlen(str))
return EC_PARSE_NOMATCH;
return 1;
}
-static void ec_node_re_free_priv(struct ec_node *gen_node)
+static void ec_node_re_free_priv(struct ec_node *node)
{
- struct ec_node_re *node = (struct ec_node_re *)gen_node;
+ struct ec_node_re *priv = ec_node_priv(node);
- if (node->re_str != NULL) {
- ec_free(node->re_str);
- regfree(&node->re);
+ if (priv->re_str != NULL) {
+ ec_free(priv->re_str);
+ regfree(&priv->re);
}
}
},
};
-static int ec_node_re_set_config(struct ec_node *gen_node,
+static int ec_node_re_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_re *node = (struct ec_node_re *)gen_node;
+ struct ec_node_re *priv = ec_node_priv(node);
const struct ec_config *value = NULL;
char *s = NULL;
regex_t re;
goto fail;
}
- if (node->re_str != NULL) {
- ec_free(node->re_str);
- regfree(&node->re);
+ if (priv->re_str != NULL) {
+ ec_free(priv->re_str);
+ regfree(&priv->re);
}
- node->re_str = s;
- node->re = re;
+ priv->re_str = s;
+ priv->re = re;
return 0;
EC_NODE_TYPE_REGISTER(ec_node_re_type);
-int ec_node_re_set_regexp(struct ec_node *gen_node, const char *str)
+int ec_node_re_set_regexp(struct ec_node *node, const char *str)
{
struct ec_config *config = NULL;
int ret;
EC_CHECK_ARG(str != NULL, -1, EINVAL);
- if (ec_node_check_type(gen_node, &ec_node_re_type) < 0)
+ if (ec_node_check_type(node, &ec_node_re_type) < 0)
goto fail;
config = ec_config_dict();
if (ret < 0)
goto fail;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL;
if (ret < 0)
goto fail;
struct ec_node *ec_node_re(const char *id, const char *re_str)
{
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
- gen_node = ec_node_from_type(&ec_node_re_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_re_type, id);
+ if (node == NULL)
goto fail;
- if (ec_node_re_set_regexp(gen_node, re_str) < 0)
+ if (ec_node_re_set_regexp(node, re_str) < 0)
goto fail;
- return gen_node;
+ return node;
fail:
- ec_node_free(gen_node);
+ ec_node_free(node);
return NULL;
}
};
struct ec_node_re_lex {
- struct ec_node gen;
struct ec_node *child;
struct regexp_pattern *table;
size_t len;
}
static int
-ec_node_re_lex_parse(const struct ec_node *gen_node,
+ec_node_re_lex_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_re_lex *node = (struct ec_node_re_lex *)gen_node;
+ struct ec_node_re_lex *priv = ec_node_priv(node);
struct ec_strvec *new_vec = NULL;
struct ec_parse *child_parse;
const char *str;
int ret;
- if (node->child == NULL) {
+ if (priv->child == NULL) {
errno = EINVAL;
goto fail;
}
new_vec = ec_strvec();
} else {
str = ec_strvec_val(strvec, 0);
- new_vec = tokenize(node->table, node->len, str);
+ new_vec = tokenize(priv->table, priv->len, str);
}
if (new_vec == NULL)
goto fail;
- ret = ec_node_parse_child(node->child, state, new_vec);
+ ret = ec_node_parse_child(priv->child, state, new_vec);
if (ret < 0)
goto fail;
return -1;
}
-static void ec_node_re_lex_free_priv(struct ec_node *gen_node)
+static void ec_node_re_lex_free_priv(struct ec_node *node)
{
- struct ec_node_re_lex *node = (struct ec_node_re_lex *)gen_node;
+ struct ec_node_re_lex *priv = ec_node_priv(node);
unsigned int i;
- ec_node_free(node->child);
- for (i = 0; i < node->len; i++) {
- ec_free(node->table[i].pattern);
- ec_free(node->table[i].attr_name);
- regfree(&node->table[i].r);
+ ec_node_free(priv->child);
+ for (i = 0; i < priv->len; i++) {
+ ec_free(priv->table[i].pattern);
+ ec_free(priv->table[i].attr_name);
+ regfree(&priv->table[i].r);
}
- ec_free(node->table);
+ ec_free(priv->table);
}
static size_t
-ec_node_re_lex_get_children_count(const struct ec_node *gen_node)
+ec_node_re_lex_get_children_count(const struct ec_node *node)
{
- struct ec_node_re_lex *node = (struct ec_node_re_lex *)gen_node;
+ struct ec_node_re_lex *priv = ec_node_priv(node);
- if (node->child)
+ if (priv->child)
return 1;
return 0;
}
static int
-ec_node_re_lex_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_re_lex_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_re_lex *node = (struct ec_node_re_lex *)gen_node;
+ struct ec_node_re_lex *priv = ec_node_priv(node);
if (i >= 1)
return -1;
- *child = node->child;
+ *child = priv->child;
*refs = 2;
return 0;
}
},
};
-static int ec_node_re_lex_set_config(struct ec_node *gen_node,
+static int ec_node_re_lex_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_re_lex *node = (struct ec_node_re_lex *)gen_node;
+ struct ec_node_re_lex *priv = ec_node_priv(node);
struct regexp_pattern *table = NULL;
const struct ec_config *patterns, *child, *elt, *pattern, *keep, *attr;
char *pattern_str = NULL, *attr_name = NULL;
}
}
- if (node->child != NULL)
- ec_node_free(node->child);
- node->child = ec_node_clone(child->node);
- for (i = 0; i < (ssize_t)node->len; i++) {
- ec_free(node->table[i].pattern);
- ec_free(node->table[i].attr_name);
- regfree(&node->table[i].r);
+ if (priv->child != NULL)
+ ec_node_free(priv->child);
+ priv->child = ec_node_clone(child->node);
+ for (i = 0; i < (ssize_t)priv->len; i++) {
+ ec_free(priv->table[i].pattern);
+ ec_free(priv->table[i].attr_name);
+ regfree(&priv->table[i].r);
}
- ec_free(node->table);
- node->table = table;
- node->len = n;
+ ec_free(priv->table);
+ priv->table = table;
+ priv->len = n;
return 0;
EC_NODE_TYPE_REGISTER(ec_node_re_lex_type);
-int ec_node_re_lex_add(struct ec_node *gen_node, const char *pattern, int keep,
+int ec_node_re_lex_add(struct ec_node *node, const char *pattern, int keep,
const char *attr_name)
{
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL, *patterns = NULL, *elt = NULL;
int ret;
- if (ec_node_check_type(gen_node, &ec_node_re_lex_type) < 0)
+ if (ec_node_check_type(node, &ec_node_re_lex_type) < 0)
goto fail;
elt = ec_config_dict();
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
}
elt = NULL;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL; /* freed */
if (ret < 0)
goto fail;
}
static int
-ec_node_re_lex_set_child(struct ec_node *gen_node, struct ec_node *child)
+ec_node_re_lex_set_child(struct ec_node *node, struct ec_node *child)
{
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL;
int ret;
- if (ec_node_check_type(gen_node, &ec_node_re_lex_type) < 0)
+ if (ec_node_check_type(node, &ec_node_re_lex_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
}
child = NULL; /* freed */
- 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_re_lex(const char *id, struct ec_node *child)
{
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
if (child == NULL)
return NULL;
- gen_node = ec_node_from_type(&ec_node_re_lex_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_re_lex_type, id);
+ if (node == NULL)
goto fail;
- if (ec_node_re_lex_set_child(gen_node, child) < 0) {
+ if (ec_node_re_lex_set_child(node, child) < 0) {
child = NULL; /* freed */
goto fail;
}
- return gen_node;
+ return node;
fail:
- ec_node_free(gen_node);
+ ec_node_free(node);
ec_node_free(child);
return NULL;
}
EC_LOG_TYPE_REGISTER(node_seq);
struct ec_node_seq {
- struct ec_node gen;
struct ec_node **table;
size_t len;
};
static int
-ec_node_seq_parse(const struct ec_node *gen_node,
+ec_node_seq_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
+ struct ec_node_seq *priv = ec_node_priv(node);
struct ec_strvec *childvec = NULL;
size_t len = 0;
unsigned int i;
int ret;
- for (i = 0; i < node->len; i++) {
+ for (i = 0; i < priv->len; i++) {
childvec = ec_strvec_ndup(strvec, len,
ec_strvec_len(strvec) - len);
if (childvec == NULL)
goto fail;
- ret = ec_node_parse_child(node->table[i], state, childvec);
+ ret = ec_node_parse_child(priv->table[i], state, childvec);
if (ret < 0)
goto fail;
}
static int
-ec_node_seq_complete(const struct ec_node *gen_node,
+ec_node_seq_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
+ struct ec_node_seq *priv = ec_node_priv(node);
- return __ec_node_seq_complete(node->table, node->len, comp,
+ return __ec_node_seq_complete(priv->table, priv->len, comp,
strvec);
}
-static void ec_node_seq_free_priv(struct ec_node *gen_node)
+static void ec_node_seq_free_priv(struct ec_node *node)
{
- struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
+ struct ec_node_seq *priv = ec_node_priv(node);
size_t i;
- for (i = 0; i < node->len; i++)
- ec_node_free(node->table[i]);
- ec_free(node->table);
- node->table = NULL;
- node->len = 0;
+ for (i = 0; i < priv->len; i++)
+ ec_node_free(priv->table[i]);
+ ec_free(priv->table);
+ priv->table = NULL;
+ priv->len = 0;
}
static const struct ec_config_schema ec_node_seq_subschema[] = {
},
};
-static int ec_node_seq_set_config(struct ec_node *gen_node,
+static int ec_node_seq_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
+ struct ec_node_seq *priv = ec_node_priv(node);
struct ec_node **table = NULL;
size_t i, len = 0;
if (table == NULL)
goto fail;
- for (i = 0; i < node->len; i++)
- ec_node_free(node->table[i]);
- ec_free(node->table);
- node->table = table;
- node->len = len;
+ for (i = 0; i < priv->len; i++)
+ ec_node_free(priv->table[i]);
+ ec_free(priv->table);
+ priv->table = table;
+ priv->len = len;
return 0;
}
static size_t
-ec_node_seq_get_children_count(const struct ec_node *gen_node)
+ec_node_seq_get_children_count(const struct ec_node *node)
{
- struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
- return node->len;
+ struct ec_node_seq *priv = ec_node_priv(node);
+ return priv->len;
}
static int
-ec_node_seq_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_seq_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
+ struct ec_node_seq *priv = ec_node_priv(node);
- if (i >= node->len)
+ if (i >= priv->len)
return -1;
- *child = node->table[i];
+ *child = priv->table[i];
/* each child node is referenced twice: once in the config and
- * once in the node->table[] */
+ * once in the priv->table[] */
*refs = 2;
return 0;
}
EC_NODE_TYPE_REGISTER(ec_node_seq_type);
-int ec_node_seq_add(struct ec_node *gen_node, struct ec_node *child)
+int ec_node_seq_add(struct ec_node *node, struct ec_node *child)
{
- struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL, *children;
int ret;
/* XXX factorize this code in a helper */
- if (ec_node_check_type(gen_node, &ec_node_seq_type) < 0)
+ if (ec_node_check_type(node, &ec_node_seq_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
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_seq(const char *id, ...)
{
struct ec_config *config = NULL, *children = NULL;
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
struct ec_node *child;
va_list ap;
int ret;
va_start(ap, id);
child = va_arg(ap, struct ec_node *);
- gen_node = ec_node_from_type(&ec_node_seq_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_seq_type, id);
+ if (node == NULL)
goto fail_free_children;
config = ec_config_dict();
}
children = NULL;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL; /* freed */
if (ret < 0)
goto fail;
va_end(ap);
- return gen_node;
+ return node;
fail_free_children:
for (; child != EC_NODE_ENDLIST; child = va_arg(ap, struct ec_node *))
ec_node_free(child);
fail:
- ec_node_free(gen_node); /* will also free added children */
+ ec_node_free(node); /* will also free added children */
ec_config_free(children);
ec_config_free(config);
va_end(ap);
EC_LOG_TYPE_REGISTER(node_sh_lex);
struct ec_node_sh_lex {
- struct ec_node gen;
struct ec_node *child;
};
}
static int
-ec_node_sh_lex_parse(const struct ec_node *gen_node,
+ec_node_sh_lex_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
+ struct ec_node_sh_lex *priv = ec_node_priv(node);
struct ec_strvec *new_vec = NULL;
struct ec_parse *child_parse;
const char *str;
if (new_vec == NULL)
goto fail;
- ret = ec_node_parse_child(node->child, state, new_vec);
+ ret = ec_node_parse_child(priv->child, state, new_vec);
if (ret < 0)
goto fail;
}
static int
-ec_node_sh_lex_complete(const struct ec_node *gen_node,
+ec_node_sh_lex_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
+ struct ec_node_sh_lex *priv = ec_node_priv(node);
struct ec_comp *tmp_comp = NULL;
struct ec_strvec *new_vec = NULL;
struct ec_comp_iter *iter = NULL;
if (tmp_comp == NULL)
goto fail;
- ret = ec_node_complete_child(node->child, tmp_comp, new_vec);
+ ret = ec_node_complete_child(priv->child, tmp_comp, new_vec);
if (ret < 0)
goto fail;
return -1;
}
-static void ec_node_sh_lex_free_priv(struct ec_node *gen_node)
+static void ec_node_sh_lex_free_priv(struct ec_node *node)
{
- struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
+ struct ec_node_sh_lex *priv = ec_node_priv(node);
- ec_node_free(node->child);
+ ec_node_free(priv->child);
}
static size_t
-ec_node_sh_lex_get_children_count(const struct ec_node *gen_node)
+ec_node_sh_lex_get_children_count(const struct ec_node *node)
{
- struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
+ struct ec_node_sh_lex *priv = ec_node_priv(node);
- if (node->child)
+ if (priv->child)
return 1;
return 0;
}
static int
-ec_node_sh_lex_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_sh_lex_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
+ struct ec_node_sh_lex *priv = ec_node_priv(node);
if (i >= 1)
return -1;
*refs = 1;
- *child = node->child;
+ *child = priv->child;
return 0;
}
struct ec_node *ec_node_sh_lex(const char *id, struct ec_node *child)
{
- struct ec_node_sh_lex *node = NULL;
+ struct ec_node *node = NULL;
+ struct ec_node_sh_lex *priv;
if (child == NULL)
return NULL;
- node = (struct ec_node_sh_lex *)ec_node_from_type(&ec_node_sh_lex_type, id);
+ node = ec_node_from_type(&ec_node_sh_lex_type, id);
if (node == NULL) {
ec_node_free(child);
return NULL;
}
- node->child = child;
+ priv = ec_node_priv(node);
+ priv->child = child;
- return &node->gen;
+ return node;
}
/* LCOV_EXCL_START */
EC_LOG_TYPE_REGISTER(node_space);
struct ec_node_space {
- struct ec_node gen;
};
static int
-ec_node_space_parse(const struct ec_node *gen_node,
+ec_node_space_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
size_t len = 0;
(void)state;
- (void)gen_node;
+ (void)node;
if (ec_strvec_len(strvec) == 0)
return EC_PARSE_NOMATCH;
EC_LOG_TYPE_REGISTER(node_str);
struct ec_node_str {
- struct ec_node gen;
char *string;
unsigned len;
};
static int
-ec_node_str_parse(const struct ec_node *gen_node,
+ec_node_str_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_str *node = (struct ec_node_str *)gen_node;
+ struct ec_node_str *priv = ec_node_priv(node);
const char *str;
(void)state;
- if (node->string == NULL) {
+ if (priv->string == NULL) {
errno = EINVAL;
return -1;
}
return EC_PARSE_NOMATCH;
str = ec_strvec_val(strvec, 0);
- if (strcmp(str, node->string) != 0)
+ if (strcmp(str, priv->string) != 0)
return EC_PARSE_NOMATCH;
return 1;
}
static int
-ec_node_str_complete(const struct ec_node *gen_node,
+ec_node_str_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_str *node = (struct ec_node_str *)gen_node;
+ struct ec_node_str *priv = ec_node_priv(node);
const char *str;
size_t n = 0;
return 0;
str = ec_strvec_val(strvec, 0);
- for (n = 0; n < node->len; n++) {
- if (str[n] != node->string[n])
+ for (n = 0; n < priv->len; n++) {
+ if (str[n] != priv->string[n])
break;
}
if (str[n] != '\0')
return EC_PARSE_NOMATCH;
- if (ec_comp_add_item(comp, gen_node, NULL, EC_COMP_FULL,
- str, node->string) < 0)
+ if (ec_comp_add_item(comp, node, NULL, EC_COMP_FULL,
+ str, priv->string) < 0)
return -1;
return 0;
}
-static const char *ec_node_str_desc(const struct ec_node *gen_node)
+static const char *ec_node_str_desc(const struct ec_node *node)
{
- struct ec_node_str *node = (struct ec_node_str *)gen_node;
+ struct ec_node_str *priv = ec_node_priv(node);
- return node->string;
+ return priv->string;
}
-static void ec_node_str_free_priv(struct ec_node *gen_node)
+static void ec_node_str_free_priv(struct ec_node *node)
{
- struct ec_node_str *node = (struct ec_node_str *)gen_node;
+ struct ec_node_str *priv = ec_node_priv(node);
- ec_free(node->string);
+ ec_free(priv->string);
}
static const struct ec_config_schema ec_node_str_schema[] = {
},
};
-static int ec_node_str_set_config(struct ec_node *gen_node,
+static int ec_node_str_set_config(struct ec_node *node,
const struct ec_config *config)
{
- struct ec_node_str *node = (struct ec_node_str *)gen_node;
+ struct ec_node_str *priv = ec_node_priv(node);
const struct ec_config *value = NULL;
char *s = NULL;
if (s == NULL)
goto fail;
- ec_free(node->string);
- node->string = s;
- node->len = strlen(node->string);
+ ec_free(priv->string);
+ priv->string = s;
+ priv->len = strlen(priv->string);
return 0;
EC_NODE_TYPE_REGISTER(ec_node_str_type);
-int ec_node_str_set_str(struct ec_node *gen_node, const char *str)
+int ec_node_str_set_str(struct ec_node *node, const char *str)
{
struct ec_config *config = NULL;
int ret;
- if (ec_node_check_type(gen_node, &ec_node_str_type) < 0)
+ if (ec_node_check_type(node, &ec_node_str_type) < 0)
goto fail;
if (str == NULL) {
if (ret < 0)
goto fail;
- ret = ec_node_set_config(gen_node, config);
+ ret = ec_node_set_config(node, config);
config = NULL;
if (ret < 0)
goto fail;
struct ec_node *ec_node_str(const char *id, const char *str)
{
- struct ec_node *gen_node = NULL;
+ struct ec_node *node = NULL;
- gen_node = ec_node_from_type(&ec_node_str_type, id);
- if (gen_node == NULL)
+ node = ec_node_from_type(&ec_node_str_type, id);
+ if (node == NULL)
goto fail;
- if (ec_node_str_set_str(gen_node, str) < 0)
+ if (ec_node_str_set_str(node, str) < 0)
goto fail;
- return gen_node;
+ return node;
fail:
- ec_node_free(gen_node);
+ ec_node_free(node);
return NULL;
}
EC_LOG_TYPE_REGISTER(node_subset);
struct ec_node_subset {
- struct ec_node gen;
struct ec_node **table;
unsigned int len;
};
}
static int
-ec_node_subset_parse(const struct ec_node *gen_node,
+ec_node_subset_parse(const struct ec_node *node,
struct ec_parse *state,
const struct ec_strvec *strvec)
{
- struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
+ struct ec_node_subset *priv = ec_node_priv(node);
struct ec_parse *parse = NULL;
struct parse_result result;
int ret;
memset(&result, 0, sizeof(result));
- ret = __ec_node_subset_parse(&result, node->table,
- node->len, state, strvec);
+ ret = __ec_node_subset_parse(&result, priv->table,
+ priv->len, state, strvec);
if (ret < 0)
goto fail;
}
static int
-ec_node_subset_complete(const struct ec_node *gen_node,
+ec_node_subset_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
+ struct ec_node_subset *priv = ec_node_priv(node);
- return __ec_node_subset_complete(node->table, node->len, comp,
+ return __ec_node_subset_complete(priv->table, priv->len, comp,
strvec);
}
-static void ec_node_subset_free_priv(struct ec_node *gen_node)
+static void ec_node_subset_free_priv(struct ec_node *node)
{
- struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
+ struct ec_node_subset *priv = ec_node_priv(node);
size_t i;
- for (i = 0; i < node->len; i++)
- ec_node_free(node->table[i]);
- ec_free(node->table);
+ for (i = 0; i < priv->len; i++)
+ ec_node_free(priv->table[i]);
+ ec_free(priv->table);
}
static size_t
-ec_node_subset_get_children_count(const struct ec_node *gen_node)
+ec_node_subset_get_children_count(const struct ec_node *node)
{
- struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
- return node->len;
+ struct ec_node_subset *priv = ec_node_priv(node);
+ return priv->len;
}
static int
-ec_node_subset_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_subset_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
+ struct ec_node_subset *priv = ec_node_priv(node);
- if (i >= node->len)
+ if (i >= priv->len)
return -1;
- *child = node->table[i];
+ *child = priv->table[i];
*refs = 1;
return 0;
}
EC_NODE_TYPE_REGISTER(ec_node_subset_type);
-int ec_node_subset_add(struct ec_node *gen_node, struct ec_node *child)
+int ec_node_subset_add(struct ec_node *node, struct ec_node *child)
{
- struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
+ struct ec_node_subset *priv = ec_node_priv(node);
struct ec_node **table;
assert(node != NULL); // XXX specific assert for it, like in libyang
goto fail;
}
- if (ec_node_check_type(gen_node, &ec_node_subset_type) < 0)
+ if (ec_node_check_type(node, &ec_node_subset_type) < 0)
goto fail;
- table = ec_realloc(node->table, (node->len + 1) * sizeof(*node->table));
+ table = ec_realloc(priv->table, (priv->len + 1) * sizeof(*priv->table));
if (table == NULL) {
ec_node_free(child);
return -1;
}
- node->table = table;
- table[node->len] = child;
- node->len++;
+ priv->table = table;
+ table[priv->len] = child;
+ priv->len++;
return 0;
struct ec_node *__ec_node_subset(const char *id, ...)
{
- struct ec_node *gen_node = NULL;
- struct ec_node_subset *node = NULL;
+ struct ec_node *node = NULL;
struct ec_node *child;
va_list ap;
int fail = 0;
va_start(ap, id);
- gen_node = ec_node_from_type(&ec_node_subset_type, id);
- node = (struct ec_node_subset *)gen_node;
+ node = ec_node_from_type(&ec_node_subset_type, id);
if (node == NULL)
fail = 1;;
/* on error, don't quit the loop to avoid leaks */
if (fail == 1 || child == NULL ||
- ec_node_subset_add(gen_node, child) < 0) {
+ ec_node_subset_add(node, child) < 0) {
fail = 1;
ec_node_free(child);
}
goto fail;
va_end(ap);
- return gen_node;
+ return node;
fail:
- ec_node_free(gen_node); /* will also free children */
+ ec_node_free(node); /* will also free children */
va_end(ap);
return NULL;
}
/* node can be null when parsing is incomplete */
if (parse->node != NULL) {
- id = parse->node->id;
+ id = ec_node_id(parse->node);
typename = ec_node_type(parse->node)->name;
}
for (iter = start; iter != NULL;
iter = EC_PARSE_ITER_NEXT(root, iter, 1)) {
if (iter->node != NULL &&
- iter->node->id != NULL &&
- !strcmp(iter->node->id, id))
+ !strcmp(ec_node_id(iter->node), id))
return iter;
}