X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=src%2Fecoli_node_once.c;h=e3ed96a9889187e18f48c37a939cfc653a8a857c;hb=67b4d8d2b2593e3e64a848ce548bc0fd76bc440a;hp=989c710d5f22c2afdbce342ba51b916c084df038;hpb=18d03456d96f7a086a2ccc82ce97fcf056848d90;p=protos%2Flibecoli.git diff --git a/src/ecoli_node_once.c b/src/ecoli_node_once.c index 989c710..e3ed96a 100644 --- a/src/ecoli_node_once.c +++ b/src/ecoli_node_once.c @@ -25,97 +25,96 @@ EC_LOG_TYPE_REGISTER(node_once); struct ec_node_once { - struct ec_node gen; struct ec_node *child; }; static unsigned int -count_node(struct ec_parse *parse, const struct ec_node *node) +count_node(struct ec_pnode *parse, const struct ec_node *node) { - struct ec_parse *child; + struct ec_pnode *child; unsigned int count = 0; if (parse == NULL) return 0; - if (ec_parse_get_node(parse) == node) + if (ec_pnode_get_node(parse) == node) count++; - EC_PARSE_FOREACH_CHILD(child, parse) + EC_PNODE_FOREACH_CHILD(child, parse) count += count_node(child, node); return count; } static int -ec_node_once_parse(const struct ec_node *gen_node, - struct ec_parse *state, +ec_node_once_parse(const struct ec_node *node, + struct ec_pnode *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_pnode_get_root(state), priv->child); if (count > 0) return EC_PARSE_NOMATCH; - return ec_node_parse_child(node->child, state, strvec); + return ec_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_parse *parse = ec_comp_get_state(comp); + struct ec_node_once *priv = ec_node_priv(node); + struct ec_pnode *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_pnode_get_root(parse), priv->child); if (count > 0) return 0; - ret = ec_node_complete_child(node->child, comp, strvec); + ret = ec_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; } @@ -131,10 +130,10 @@ static const struct ec_config_schema ec_node_once_schema[] = { }, }; -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"); @@ -145,9 +144,9 @@ static int ec_node_once_set_config(struct ec_node *gen_node, 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; @@ -170,16 +169,16 @@ static struct ec_node_type ec_node_once_type = { 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 @@ -193,7 +192,7 @@ ec_node_once_set_child(struct ec_node *gen_node, struct ec_node *child) } 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; @@ -208,19 +207,19 @@ 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); @@ -254,20 +253,20 @@ static int ec_node_once_testcase(void) testres |= EC_TEST_CHECK_PARSE(node, 0, "foox"); testres |= EC_TEST_CHECK_COMPLETE(node, - "", EC_NODE_ENDLIST, - "foo", "bar", EC_NODE_ENDLIST); + "", EC_VA_END, + "foo", "bar", EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "f", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST); + "f", EC_VA_END, + "foo", EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "b", EC_NODE_ENDLIST, - "bar", EC_NODE_ENDLIST); + "b", EC_VA_END, + "bar", EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "foo", "", EC_NODE_ENDLIST, - "bar", EC_NODE_ENDLIST); + "foo", "", EC_VA_END, + "bar", EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "bar", "", EC_NODE_ENDLIST, - "foo", "bar", EC_NODE_ENDLIST); + "bar", "", EC_VA_END, + "foo", "bar", EC_VA_END); ec_node_free(node); return testres;