X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fecoli_node_seq.c;h=dc6954d8a963701733042e9161cb96b553b9b1f4;hb=786e4464e886f4e1485ba2beb6ed74c8a5914fbf;hp=ae0bb600f44708598477c9af470614160c492910;hpb=8937e9addfe15dfe34ea241884aa10cfb3dc54fb;p=protos%2Flibecoli.git diff --git a/lib/ecoli_node_seq.c b/lib/ecoli_node_seq.c index ae0bb60..dc6954d 100644 --- a/lib/ecoli_node_seq.c +++ b/lib/ecoli_node_seq.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -170,6 +171,9 @@ static const struct ec_config_schema ec_node_seq_subschema[] = { .desc = "A child node which is part of the sequence.", .type = EC_CONFIG_TYPE_NODE, }, + { + .type = EC_CONFIG_TYPE_NONE, + }, }; static const struct ec_config_schema ec_node_seq_schema[] = { @@ -178,7 +182,9 @@ static const struct ec_config_schema ec_node_seq_schema[] = { .desc = "The list of children nodes, to be parsed in sequence.", .type = EC_CONFIG_TYPE_LIST, .subschema = ec_node_seq_subschema, - .subschema_len = EC_COUNT_OF(ec_node_seq_subschema), + }, + { + .type = EC_CONFIG_TYPE_NONE, }, }; @@ -186,43 +192,25 @@ static int ec_node_seq_set_config(struct ec_node *gen_node, const struct ec_config *config) { struct ec_node_seq *node = (struct ec_node_seq *)gen_node; - const struct ec_config *children = NULL, *child; struct ec_node **table = NULL; - size_t n, i; + size_t i, len = 0; - children = ec_config_dict_get(config, "children"); - if (children == NULL) { - errno = EINVAL; - goto fail; - } - - n = 0; - TAILQ_FOREACH(child, &children->list, next) - n++; - - table = ec_malloc(n * sizeof(*table)); + table = ec_node_config_node_list_to_table( + ec_config_dict_get(config, "children"), &len); if (table == NULL) goto fail; - n = 0; - TAILQ_FOREACH(child, &children->list, next) { - table[n] = ec_node_clone(child->node); - n++; - } - for (i = 0; i < node->len; i++) ec_node_free(node->table[i]); ec_free(node->table); node->table = table; - node->len = n; + node->len = len; return 0; fail: - if (table != NULL) { - for (i = 0; i < n; i++) - ec_node_free(table[i]); - } + for (i = 0; i < len; i++) + ec_node_free(table[i]); ec_free(table); return -1; } @@ -253,7 +241,6 @@ ec_node_seq_get_child(const struct ec_node *gen_node, size_t i, static struct ec_node_type ec_node_seq_type = { .name = "seq", .schema = ec_node_seq_schema, - .schema_len = EC_COUNT_OF(ec_node_seq_schema), .set_config = ec_node_seq_set_config, .parse = ec_node_seq_parse, .complete = ec_node_seq_complete, @@ -326,7 +313,7 @@ struct ec_node *__ec_node_seq(const char *id, ...) va_start(ap, id); child = va_arg(ap, struct ec_node *); - gen_node = __ec_node(&ec_node_seq_type, id); + gen_node = ec_node_from_type(&ec_node_seq_type, id); if (gen_node == NULL) goto fail_free_children;