X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=src%2Fecoli_node_sh_lex.c;h=7dd0358af93753c8a818d6e54b3c7c85db09997a;hb=74ce3d6a8a834a003bff84a8cd6344a94dade895;hp=246162010e4029f769f4d4475fc4934dd69cf583;hpb=984760622f2c8472fd2667e24bcceb543bdb1aff;p=protos%2Flibecoli.git diff --git a/src/ecoli_node_sh_lex.c b/src/ecoli_node_sh_lex.c index 2461620..7dd0358 100644 --- a/src/ecoli_node_sh_lex.c +++ b/src/ecoli_node_sh_lex.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -213,7 +214,7 @@ static struct ec_strvec *tokenize(const char *str, int completion, static int ec_node_sh_lex_parse(const struct ec_node *node, - struct ec_pnode *state, + struct ec_pnode *pstate, const struct ec_strvec *strvec) { struct ec_node_sh_lex *priv = ec_node_priv(node); @@ -233,15 +234,15 @@ ec_node_sh_lex_parse(const struct ec_node *node, if (new_vec == NULL) goto fail; - ret = ec_parse_child(priv->child, state, new_vec); + ret = ec_parse_child(priv->child, pstate, new_vec); if (ret < 0) goto fail; if ((unsigned)ret == ec_strvec_len(new_vec)) { ret = 1; } else if (ret != EC_PARSE_NOMATCH) { - child_parse = ec_pnode_get_last_child(state); - ec_pnode_unlink_child(state, child_parse); + child_parse = ec_pnode_get_last_child(pstate); + ec_pnode_unlink_child(pstate, child_parse); ec_pnode_free(child_parse); ret = EC_PARSE_NOMATCH; } @@ -262,10 +263,9 @@ ec_node_sh_lex_complete(const struct ec_node *node, const struct ec_strvec *strvec) { struct ec_node_sh_lex *priv = ec_node_priv(node); - struct ec_comp *tmp_comp = NULL; struct ec_strvec *new_vec = NULL; - struct ec_comp_iter *iter = NULL; struct ec_comp_item *item = NULL; + struct ec_htable *htable = NULL; char *new_str = NULL; const char *str; char missing_quote = '\0'; @@ -279,22 +279,27 @@ ec_node_sh_lex_complete(const struct ec_node *node, if (new_vec == NULL) goto fail; - /* we will store the completions in a temporary struct, because - * we want to update them (ex: add missing quotes) */ - tmp_comp = ec_comp(ec_comp_get_state(comp)); - if (tmp_comp == NULL) + /* let's store the existing full completions in a htable */ + htable = ec_htable(); + if (htable == NULL) goto fail; - ret = ec_complete_child(priv->child, tmp_comp, new_vec); + EC_COMP_FOREACH(item, comp, EC_COMP_FULL) { + if (ec_htable_set(htable, &item, sizeof(item), NULL, NULL) < 0) + goto fail; + } + + /* do the completion */ + ret = ec_complete_child(priv->child, comp, new_vec); if (ret < 0) goto fail; - /* add missing quote for full completions */ + /* add missing quote for any new full completions */ if (missing_quote != '\0') { - iter = ec_comp_iter(tmp_comp, EC_COMP_FULL); - if (iter == NULL) - goto fail; - while ((item = ec_comp_iter_next(iter)) != NULL) { + EC_COMP_FOREACH(item, comp, EC_COMP_FULL) { + if (ec_htable_has_key(htable, &item, sizeof(item))) + continue; + str = ec_comp_item_get_str(item); if (ec_asprintf(&new_str, "%c%s%c", missing_quote, str, missing_quote) < 0) { @@ -319,18 +324,15 @@ ec_node_sh_lex_complete(const struct ec_node *node, } } - ec_comp_iter_free(iter); ec_strvec_free(new_vec); - - ec_comp_merge(comp, tmp_comp); + ec_htable_free(htable); return 0; fail: - ec_comp_free(tmp_comp); - ec_comp_iter_free(iter); ec_strvec_free(new_vec); ec_free(new_str); + ec_htable_free(htable); return -1; }