X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=src%2Fecoli_node_seq.c;h=1102f3d4fcc0bf8271c67c20138dc29c87ef2569;hb=74ce3d6a8a834a003bff84a8cd6344a94dade895;hp=ff0c5de8e928ef39e75b82412f978088824b9c1c;hpb=18d03456d96f7a086a2ccc82ce97fcf056848d90;p=protos%2Flibecoli.git diff --git a/src/ecoli_node_seq.c b/src/ecoli_node_seq.c index ff0c5de..1102f3d 100644 --- a/src/ecoli_node_seq.c +++ b/src/ecoli_node_seq.c @@ -28,29 +28,28 @@ 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, - struct ec_parse *state, +ec_node_seq_parse(const struct ec_node *node, + struct ec_pnode *pstate, 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_parse_child(priv->table[i], pstate, childvec); if (ret < 0) goto fail; @@ -58,7 +57,7 @@ ec_node_seq_parse(const struct ec_node *gen_node, childvec = NULL; if (ret == EC_PARSE_NOMATCH) { - ec_parse_free_children(state); + ec_pnode_free_children(pstate); return EC_PARSE_NOMATCH; } @@ -77,7 +76,7 @@ __ec_node_seq_complete(struct ec_node **table, size_t table_len, struct ec_comp *comp, const struct ec_strvec *strvec) { - struct ec_parse *parse = ec_comp_get_state(comp); + struct ec_pnode *parse = ec_comp_get_cur_pstate(comp); struct ec_strvec *childvec = NULL; unsigned int i; int ret; @@ -97,7 +96,7 @@ __ec_node_seq_complete(struct ec_node **table, size_t table_len, */ /* first, try to complete with the first node of the table */ - ret = ec_node_complete_child(table[0], comp, strvec); + ret = ec_complete_child(table[0], comp, strvec); if (ret < 0) goto fail; @@ -108,7 +107,7 @@ __ec_node_seq_complete(struct ec_node **table, size_t table_len, if (childvec == NULL) goto fail; - ret = ec_node_parse_child(table[0], parse, childvec); + ret = ec_parse_child(table[0], parse, childvec); if (ret < 0) goto fail; @@ -117,20 +116,20 @@ __ec_node_seq_complete(struct ec_node **table, size_t table_len, if ((unsigned int)ret != i) { if (ret != EC_PARSE_NOMATCH) - ec_parse_del_last_child(parse); + ec_pnode_del_last_child(parse); continue; } childvec = ec_strvec_ndup(strvec, i, ec_strvec_len(strvec) - i); if (childvec == NULL) { - ec_parse_del_last_child(parse); + ec_pnode_del_last_child(parse); goto fail; } ret = __ec_node_seq_complete(&table[1], table_len - 1, comp, childvec); - ec_parse_del_last_child(parse); + ec_pnode_del_last_child(parse); ec_strvec_free(childvec); childvec = NULL; @@ -146,26 +145,26 @@ 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[] = { @@ -190,10 +189,10 @@ static const struct ec_config_schema ec_node_seq_schema[] = { }, }; -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; @@ -202,11 +201,11 @@ static int ec_node_seq_set_config(struct ec_node *gen_node, 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; @@ -218,24 +217,24 @@ fail: } 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; } @@ -254,9 +253,8 @@ static struct ec_node_type ec_node_seq_type = { 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; @@ -265,10 +263,10 @@ int ec_node_seq_add(struct ec_node *gen_node, struct ec_node *child) /* 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 @@ -291,7 +289,7 @@ int ec_node_seq_add(struct ec_node *gen_node, struct ec_node *child) 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; @@ -307,7 +305,7 @@ 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; @@ -315,8 +313,8 @@ struct ec_node *__ec_node_seq(const char *id, ...) 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(); @@ -327,7 +325,7 @@ struct ec_node *__ec_node_seq(const char *id, ...) if (children == NULL) goto fail_free_children; - for (; child != EC_NODE_ENDLIST; child = va_arg(ap, struct ec_node *)) { + for (; child != EC_VA_END; child = va_arg(ap, struct ec_node *)) { if (child == NULL) goto fail_free_children; @@ -343,20 +341,20 @@ struct ec_node *__ec_node_seq(const char *id, ...) } 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 *)) + for (; child != EC_VA_END; 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); @@ -402,32 +400,32 @@ static int ec_node_seq_testcase(void) return -1; } testres |= EC_TEST_CHECK_COMPLETE(node, - "", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST); + "", EC_VA_END, + "foo", 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, - "foo", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST); + "foo", EC_VA_END, + "foo", EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "foo", "", EC_NODE_ENDLIST, - "bar", "toto", EC_NODE_ENDLIST); + "foo", "", EC_VA_END, + "bar", "toto", EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "foo", "t", EC_NODE_ENDLIST, - "toto", EC_NODE_ENDLIST); + "foo", "t", EC_VA_END, + "toto", EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "foo", "b", EC_NODE_ENDLIST, - "bar", EC_NODE_ENDLIST); + "foo", "b", EC_VA_END, + "bar", EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "foo", "bar", EC_NODE_ENDLIST, - "bar", EC_NODE_ENDLIST); + "foo", "bar", EC_VA_END, + "bar", EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "x", EC_NODE_ENDLIST, - EC_NODE_ENDLIST); + "x", EC_VA_END, + EC_VA_END); testres |= EC_TEST_CHECK_COMPLETE(node, - "foobarx", EC_NODE_ENDLIST, - EC_NODE_ENDLIST); + "foobarx", EC_VA_END, + EC_VA_END); ec_node_free(node); return testres;