X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Fecoli_node_sh_lex.c;h=b39ce213e580c725e3b6b7f94aa3777545f58e0d;hb=2be188c2858fa975d6b2ba3f91405d260d3c5b75;hp=82da5d765bde09e3aa8e416a1a258ff199d688a2;hpb=539a859dde94b304e93f44a52b7e7fc0734e3a5d;p=protos%2Flibecoli.git diff --git a/lib/ecoli_node_sh_lex.c b/lib/ecoli_node_sh_lex.c index 82da5d7..b39ce21 100644 --- a/lib/ecoli_node_sh_lex.c +++ b/lib/ecoli_node_sh_lex.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -93,7 +93,7 @@ static char *unquote_str(const char *str, size_t n, int allow_missing_quote, *missing_quote = str[0]; if (allow_missing_quote == 0) { ec_free(dst); - errno = EINVAL; + errno = EBADMSG; return NULL; } } @@ -214,12 +214,12 @@ static struct ec_strvec *tokenize(const char *str, int completion, static int ec_node_sh_lex_parse(const struct ec_node *gen_node, - struct ec_parsed *state, + struct ec_parse *state, const struct ec_strvec *strvec) { struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node; struct ec_strvec *new_vec = NULL; - struct ec_parsed *child_parsed; + struct ec_parse *child_parse; const char *str; int ret; @@ -229,13 +229,10 @@ ec_node_sh_lex_parse(const struct ec_node *gen_node, str = ec_strvec_val(strvec, 0); new_vec = tokenize(str, 0, 0, NULL); } - if (new_vec == NULL) { - if (errno == EINVAL) - ret = EC_PARSED_NOMATCH; - else - ret = -ENOMEM; + if (new_vec == NULL && errno == EBADMSG) /* quotes not closed */ + return EC_PARSE_NOMATCH; + if (new_vec == NULL) goto fail; - } ret = ec_node_parse_child(node->child, state, new_vec); if (ret < 0) @@ -243,11 +240,11 @@ ec_node_sh_lex_parse(const struct ec_node *gen_node, if ((unsigned)ret == ec_strvec_len(new_vec)) { ret = 1; - } else if (ret != EC_PARSED_NOMATCH) { - child_parsed = ec_parsed_get_last_child(state); - ec_parsed_unlink_child(state, child_parsed); - ec_parsed_free(child_parsed); - ret = EC_PARSED_NOMATCH; + } else if (ret != EC_PARSE_NOMATCH) { + child_parse = ec_parse_get_last_child(state); + ec_parse_unlink_child(state, child_parse); + ec_parse_free(child_parse); + ret = EC_PARSE_NOMATCH; } ec_strvec_free(new_vec); @@ -257,7 +254,7 @@ ec_node_sh_lex_parse(const struct ec_node *gen_node, fail: ec_strvec_free(new_vec); - return ret; + return -1; } static int @@ -346,12 +343,35 @@ static void ec_node_sh_lex_free_priv(struct ec_node *gen_node) ec_node_free(node->child); } +static size_t +ec_node_sh_lex_get_children_count(const struct ec_node *gen_node) +{ + struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node; + + if (node->child) + return 1; + return 0; +} + +static struct ec_node * +ec_node_sh_lex_get_child(const struct ec_node *gen_node, size_t i) +{ + struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node; + + if (i >= 1) + return NULL; + + return node->child; +} + static struct ec_node_type ec_node_sh_lex_type = { .name = "sh_lex", .parse = ec_node_sh_lex_parse, .complete = ec_node_sh_lex_complete, .size = sizeof(struct ec_node_sh_lex), .free_priv = ec_node_sh_lex_free_priv, + .get_children_count = ec_node_sh_lex_get_children_count, + .get_child = ec_node_sh_lex_get_child, }; EC_NODE_TYPE_REGISTER(ec_node_sh_lex_type);