X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Fecoli_node_option.c;h=ab4f35265e43fe0190c2e8b009509d9173bad29a;hb=15718f19cbf3868bf6fba79f4e26b5254c57873e;hp=2d9db77c5df0eb5cc9b10cf775c37b2c0d4e0121;hpb=0a2b19af9303c4a0ec05bea7afe1803a429517bf;p=protos%2Flibecoli.git diff --git a/lib/ecoli_node_option.c b/lib/ecoli_node_option.c index 2d9db77..ab4f352 100644 --- a/lib/ecoli_node_option.c +++ b/lib/ecoli_node_option.c @@ -13,8 +13,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -28,7 +28,7 @@ struct ec_node_option { static int ec_node_option_parse(const struct ec_node *gen_node, - struct ec_parsed *state, + struct ec_parse *state, const struct ec_strvec *strvec) { struct ec_node_option *node = (struct ec_node_option *)gen_node; @@ -38,7 +38,7 @@ ec_node_option_parse(const struct ec_node *gen_node, if (ret < 0) return ret; - if (ret == EC_PARSED_NOMATCH) + if (ret == EC_PARSE_NOMATCH) return 0; return ret; @@ -46,12 +46,12 @@ ec_node_option_parse(const struct ec_node *gen_node, static int ec_node_option_complete(const struct ec_node *gen_node, - struct ec_completed *completed, + struct ec_comp *comp, const struct ec_strvec *strvec) { struct ec_node_option *node = (struct ec_node_option *)gen_node; - return ec_node_complete_child(node->child, completed, strvec); + return ec_node_complete_child(node->child, comp, strvec); } static void ec_node_option_free_priv(struct ec_node *gen_node) @@ -61,12 +61,38 @@ static void ec_node_option_free_priv(struct ec_node *gen_node) ec_node_free(node->child); } +static size_t +ec_node_option_get_children_count(const struct ec_node *gen_node) +{ + struct ec_node_option *node = (struct ec_node_option *)gen_node; + + if (node->child) + return 1; + return 0; +} + +static int +ec_node_option_get_child(const struct ec_node *gen_node, size_t i, + struct ec_node **child, unsigned int *refs) +{ + struct ec_node_option *node = (struct ec_node_option *)gen_node; + + if (i >= 1) + return -1; + + *child = node->child; + *refs = 1; + return 0; +} + static struct ec_node_type ec_node_option_type = { .name = "option", .parse = ec_node_option_parse, .complete = ec_node_option_complete, .size = sizeof(struct ec_node_option), .free_priv = ec_node_option_free_priv, + .get_children_count = ec_node_option_get_children_count, + .get_child = ec_node_option_get_child, }; EC_NODE_TYPE_REGISTER(ec_node_option_type); @@ -83,9 +109,6 @@ int ec_node_option_set(struct ec_node *gen_node, struct ec_node *child) if (ec_node_check_type(gen_node, &ec_node_option_type) < 0) goto fail; - if (ec_node_add_child(gen_node, child) < 0) - goto fail; - node->child = child; return 0; @@ -102,7 +125,7 @@ struct ec_node *ec_node_option(const char *id, struct ec_node *child) if (child == NULL) goto fail; - gen_node = __ec_node(&ec_node_option_type, id); + gen_node = ec_node_from_type(&ec_node_option_type, id); if (gen_node == NULL) goto fail;