From e746f568b6a3ab77d0100976d8fa5a68f611bcd3 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Thu, 21 Sep 2017 17:13:19 +0200 Subject: [PATCH] change add to full str --- lib/ecoli_completed.c | 99 +++++++++++++++++++++++++++-------------- lib/ecoli_completed.h | 4 +- lib/ecoli_node_cmd.c | 9 ++-- lib/ecoli_node_empty.c | 6 +-- lib/ecoli_node_file.c | 34 +++++++------- lib/ecoli_node_int.c | 9 ++-- lib/ecoli_node_many.c | 21 +++------ lib/ecoli_node_once.c | 6 +-- lib/ecoli_node_option.c | 9 ++-- lib/ecoli_node_or.c | 21 +++------ lib/ecoli_node_seq.c | 27 ++++------- lib/ecoli_node_sh_lex.c | 36 +++++---------- lib/ecoli_node_space.c | 10 ++--- lib/ecoli_node_str.c | 10 ++--- lib/ecoli_node_subset.c | 30 +++++-------- lib/ecoli_test.c | 18 +------- lib/main-readline.c | 15 +++---- 17 files changed, 158 insertions(+), 206 deletions(-) diff --git a/lib/ecoli_completed.c b/lib/ecoli_completed.c index 71849d1..728b284 100644 --- a/lib/ecoli_completed.c +++ b/lib/ecoli_completed.c @@ -183,14 +183,13 @@ ec_completed_node(const struct ec_node *node) return NULL; compnode->node = node; - TAILQ_INIT(&compnode->matches); + TAILQ_INIT(&compnode->items); return compnode; } static struct ec_completed_item * -ec_completed_item(enum ec_completed_type type, struct ec_parsed *state, - const struct ec_node *node, const char *add) +ec_completed_item(struct ec_parsed *state, const struct ec_node *node) { struct ec_completed_item *item = NULL; struct ec_parsed *p; @@ -214,20 +213,15 @@ ec_completed_item(enum ec_completed_type type, struct ec_parsed *state, p = ec_parsed_get_parent(p), len++) item->path[len] = p->node; - item->type = type; + item->type = EC_NO_MATCH; item->node = node; - if (add != NULL) { - item->add = ec_strdup(add); - if (item->add == NULL) - goto fail; - } return item; fail: if (item != NULL) { ec_free(item->path); - ec_free(item->add); + ec_free(item->str); } ec_completed_item_free(item); @@ -238,10 +232,10 @@ static int __ec_completed_add_match(enum ec_completed_type type, struct ec_completed *completed, struct ec_parsed *parsed_state, - const struct ec_node *node, const char *add) + const struct ec_node *node, const char *str) { struct ec_completed_node *compnode = NULL; - struct ec_completed_item *match = NULL; + struct ec_completed_item *item = NULL; int ret = -ENOMEM; /* find the compnode entry corresponding to this node */ @@ -252,30 +246,67 @@ __ec_completed_add_match(enum ec_completed_type type, if (compnode == NULL) return -ENOENT; - match = ec_completed_item(type, parsed_state, node, add); - if (match == NULL) + item = ec_completed_item(parsed_state, node); + if (item == NULL) goto fail; + item->type = type; + if (str != NULL) { + item->str = ec_strdup(str); + if (item->str == NULL) + goto fail; + } - if (match->add != NULL) + if (item->str != NULL) completed->count_match++; - TAILQ_INSERT_TAIL(&compnode->matches, match, next); + TAILQ_INSERT_TAIL(&compnode->items, item, next); completed->count++; return 0; fail: - ec_completed_item_free(match); + ec_completed_item_free(item); return ret; } int ec_completed_add_match(struct ec_completed *completed, struct ec_parsed *parsed_state, - const struct ec_node *node, const char *add) + const struct ec_node *node, const char *str) { - return __ec_completed_add_match(EC_MATCH, completed, parsed_state, - node, add); + struct ec_completed_node *compnode = NULL; + struct ec_completed_item *item = NULL; + int ret = -ENOMEM; + + /* find the compnode entry corresponding to this node */ + TAILQ_FOREACH(compnode, &completed->nodes, next) { + if (compnode->node == node) + break; + } + if (compnode == NULL) + return -ENOENT; + + item = ec_completed_item(parsed_state, node); + if (item == NULL) + goto fail; + item->type = EC_MATCH; + if (str != NULL) { + item->str = ec_strdup(str); + if (item->str == NULL) + goto fail; + } + + if (item->str != NULL) + completed->count_match++; + + TAILQ_INSERT_TAIL(&compnode->items, item, next); + completed->count++; + + return 0; + +fail: + ec_completed_item_free(item); + return ret; } int @@ -290,10 +321,10 @@ ec_completed_add_no_match(struct ec_completed *completed, int ec_completed_add_partial_match(struct ec_completed *completed, struct ec_parsed *parsed_state, - const struct ec_node *node, const char *add) + const struct ec_node *node, const char *str) { return __ec_completed_add_match(EC_PARTIAL_MATCH, completed, parsed_state, - node, add); + node, str); } int @@ -312,7 +343,7 @@ ec_completed_add_node(struct ec_completed *completed, void ec_completed_item_free(struct ec_completed_item *match) { - ec_free(match->add); + ec_free(match->str); ec_free(match->path); ec_free(match); } @@ -348,9 +379,9 @@ void ec_completed_free(struct ec_completed *completed) compnode = TAILQ_FIRST(&completed->nodes); TAILQ_REMOVE(&completed->nodes, compnode, next); - while (!TAILQ_EMPTY(&compnode->matches)) { - item = TAILQ_FIRST(&compnode->matches); - TAILQ_REMOVE(&compnode->matches, item, next); + while (!TAILQ_EMPTY(&compnode->items)) { + item = TAILQ_FIRST(&compnode->items); + TAILQ_REMOVE(&compnode->items, item, next); ec_completed_item_free(item); } ec_free(compnode); @@ -374,7 +405,7 @@ void ec_completed_dump(FILE *out, const struct ec_completed *completed) TAILQ_FOREACH(compnode, &completed->nodes, next) { fprintf(out, "node=%p, node_type=%s\n", compnode->node, compnode->node->type->name); - TAILQ_FOREACH(item, &compnode->matches, next) { + TAILQ_FOREACH(item, &compnode->items, next) { const char *typestr; switch (item->type) { @@ -384,7 +415,7 @@ void ec_completed_dump(FILE *out, const struct ec_completed *completed) default: typestr = "unknown"; break; } - fprintf(out, " type=%s add=<%s>\n", typestr, item->add); + fprintf(out, " type=%s str=<%s>\n", typestr, item->str); } } } @@ -400,15 +431,15 @@ char *ec_completed_smallest_start(const struct ec_completed *completed) goto fail; TAILQ_FOREACH(compnode, &completed->nodes, next) { - TAILQ_FOREACH(item, &compnode->matches, next) { - if (item->add == NULL) + TAILQ_FOREACH(item, &compnode->items, next) { + if (item->str == NULL) continue; if (smallest_start == NULL) { - smallest_start = ec_strdup(item->add); + smallest_start = ec_strdup(item->str); if (smallest_start == NULL) goto fail; } else { - n = strcmp_count(item->add, smallest_start); + n = strcmp_count(item->str, smallest_start); smallest_start[n] = '\0'; } } @@ -472,7 +503,7 @@ const struct ec_completed_item *ec_completed_iter_next( /* first call */ if (cur_node == NULL) { TAILQ_FOREACH(cur_node, &completed->nodes, next) { - TAILQ_FOREACH(cur_match, &cur_node->matches, next) { + TAILQ_FOREACH(cur_match, &cur_node->items, next) { if (cur_match != NULL && cur_match->type & iter->type) goto found; @@ -486,7 +517,7 @@ const struct ec_completed_item *ec_completed_iter_next( goto found; cur_node = TAILQ_NEXT(cur_node, next); while (cur_node != NULL) { - cur_match = TAILQ_FIRST(&cur_node->matches); + cur_match = TAILQ_FIRST(&cur_node->items); if (cur_match != NULL && cur_match->type & iter->type) goto found; diff --git a/lib/ecoli_completed.h b/lib/ecoli_completed.h index 33512da..39816bb 100644 --- a/lib/ecoli_completed.h +++ b/lib/ecoli_completed.h @@ -44,7 +44,7 @@ struct ec_completed_item { TAILQ_ENTRY(ec_completed_item) next; enum ec_completed_type type; const struct ec_node *node; - char *add; + char *str; /* reverse order: [0] = last, [len-1] = root */ const struct ec_node **path; @@ -56,7 +56,7 @@ TAILQ_HEAD(ec_completed_item_list, ec_completed_item); struct ec_completed_node { TAILQ_ENTRY(ec_completed_node) next; const struct ec_node *node; - struct ec_completed_item_list matches; + struct ec_completed_item_list items; }; TAILQ_HEAD(ec_completed_node_list, ec_completed_node); diff --git a/lib/ecoli_node_cmd.c b/lib/ecoli_node_cmd.c index 01c2cd2..9f14ae2 100644 --- a/lib/ecoli_node_cmd.c +++ b/lib/ecoli_node_cmd.c @@ -525,16 +525,13 @@ static int ec_node_cmd_testcase(void) ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - "good", EC_NODE_ENDLIST, - "good"); + "good", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "g", EC_NODE_ENDLIST, - "ood", EC_NODE_ENDLIST, - "ood"); + "good", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "good", "morning", "", EC_NODE_ENDLIST, - "bob", "bobby", "michael", EC_NODE_ENDLIST, - ""); + "bob", "bobby", "michael", EC_NODE_ENDLIST); ec_node_free(node); diff --git a/lib/ecoli_node_empty.c b/lib/ecoli_node_empty.c index cc29779..e513d6b 100644 --- a/lib/ecoli_node_empty.c +++ b/lib/ecoli_node_empty.c @@ -86,12 +86,10 @@ static int ec_node_empty_testcase(void) } ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ec_node_free(node); return ret; diff --git a/lib/ecoli_node_file.c b/lib/ecoli_node_file.c index c4f54af..0a5caa3 100644 --- a/lib/ecoli_node_file.c +++ b/lib/ecoli_node_file.c @@ -63,12 +63,12 @@ ec_node_file_parse(const struct ec_node *gen_node, } /* - * Almost the same than dirname (3) and basename (3) except that - * it always returns a substring of the given path, which can - * be empty. + * Almost the same than dirname (3) and basename (3) except that: + * - it always returns a substring of the given path, which can + * be empty. * - the behavior is different when the path finishes with a '/' - * - the argument is not modified - * - the output is allocated and must be freed with ec_free(). + * - the path argument is not modified + * - the outputs are allocated and must be freed with ec_free(). * * path dirname basename split_path * /usr/lib /usr lib /usr/ lib @@ -196,7 +196,8 @@ ec_node_file_complete(const struct ec_node *gen_node, } if (is_dir) { - if (asprintf(&add, "%s/", &de->d_name[bname_len]) < 0) { + if (asprintf(&add, "%s%s/", path, + &de->d_name[bname_len]) < 0) { ret = -errno; goto out; } @@ -207,7 +208,8 @@ ec_node_file_complete(const struct ec_node *gen_node, goto out; } } else { - if (asprintf(&add, "%s", &de->d_name[bname_len]) < 0) { + if (asprintf(&add, "%s%s", path, + &de->d_name[bname_len]) < 0) { ret = -errno; goto out; } @@ -260,28 +262,22 @@ static int ec_node_file_testcase(void) #if 0 // XXX how to properly test file completion? ret |= EC_TEST_CHECK_COMPLETE(node, EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "/", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "/tmp", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "/tmp/", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "/tmp/.", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); #endif ec_node_free(node); diff --git a/lib/ecoli_node_int.c b/lib/ecoli_node_int.c index a7bd057..635b549 100644 --- a/lib/ecoli_node_int.c +++ b/lib/ecoli_node_int.c @@ -214,16 +214,13 @@ static int ec_node_int_testcase(void) } ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "x", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "1", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ec_node_free(node); return ret; diff --git a/lib/ecoli_node_many.c b/lib/ecoli_node_many.c index 4d748f8..8746269 100644 --- a/lib/ecoli_node_many.c +++ b/lib/ecoli_node_many.c @@ -265,32 +265,25 @@ static int ec_node_many_testcase(void) } ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST, - "foo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "f", EC_NODE_ENDLIST, - "oo", EC_NODE_ENDLIST, - "oo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", EC_NODE_ENDLIST, - "", EC_NODE_ENDLIST, - ""); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", "", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST, - "foo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", "foo", "", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST, - "foo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", "foo", "foo", "", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST, - "foo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", "foo", "foo", "foo", "", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ec_node_free(node); return ret; diff --git a/lib/ecoli_node_once.c b/lib/ecoli_node_once.c index fd427b9..d52e099 100644 --- a/lib/ecoli_node_once.c +++ b/lib/ecoli_node_once.c @@ -206,12 +206,10 @@ static int ec_node_once_testcase(void) } ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - "foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST, - ""); + "foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "f", EC_NODE_ENDLIST, - "oo", EC_NODE_ENDLIST, - "oo"); + "foo", EC_NODE_ENDLIST); ec_node_free(node); #endif return ret; diff --git a/lib/ecoli_node_option.c b/lib/ecoli_node_option.c index 4610a46..ee2c4b1 100644 --- a/lib/ecoli_node_option.c +++ b/lib/ecoli_node_option.c @@ -139,16 +139,13 @@ static int ec_node_option_testcase(void) } ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST, - "foo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "f", EC_NODE_ENDLIST, - "oo", EC_NODE_ENDLIST, - "oo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "b", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ec_node_free(node); return ret; diff --git a/lib/ecoli_node_or.c b/lib/ecoli_node_or.c index c1b808f..391d84e 100644 --- a/lib/ecoli_node_or.c +++ b/lib/ecoli_node_or.c @@ -226,32 +226,25 @@ static int ec_node_or_testcase(void) } ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - "foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST, - ""); + "foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "f", EC_NODE_ENDLIST, - "oo", EC_NODE_ENDLIST, - "oo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "b", EC_NODE_ENDLIST, - "ar", "ar2", EC_NODE_ENDLIST, - "ar"); + "bar", "bar2", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "bar", EC_NODE_ENDLIST, - "", "2", EC_NODE_ENDLIST, - ""); + "bar", "bar2", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "t", EC_NODE_ENDLIST, - "oto", "iti", EC_NODE_ENDLIST, - ""); + "toto", "titi", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "to", EC_NODE_ENDLIST, - "to", EC_NODE_ENDLIST, - "to"); + "toto", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "x", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ec_node_free(node); return ret; diff --git a/lib/ecoli_node_seq.c b/lib/ecoli_node_seq.c index d6338e9..7b22709 100644 --- a/lib/ecoli_node_seq.c +++ b/lib/ecoli_node_seq.c @@ -317,40 +317,31 @@ static int ec_node_seq_testcase(void) } ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST, - "foo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "f", EC_NODE_ENDLIST, - "oo", EC_NODE_ENDLIST, - "oo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", EC_NODE_ENDLIST, - "", EC_NODE_ENDLIST, - ""); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", "", EC_NODE_ENDLIST, - "bar", "toto", EC_NODE_ENDLIST, - ""); + "bar", "toto", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", "t", EC_NODE_ENDLIST, - "oto", EC_NODE_ENDLIST, - "oto"); + "toto", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", "b", EC_NODE_ENDLIST, - "ar", EC_NODE_ENDLIST, - "ar"); + "bar", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", "bar", EC_NODE_ENDLIST, - "", EC_NODE_ENDLIST, - ""); + "bar", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "x", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foobarx", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ec_node_free(node); return ret; diff --git a/lib/ecoli_node_sh_lex.c b/lib/ecoli_node_sh_lex.c index 897f922..1da0a90 100644 --- a/lib/ecoli_node_sh_lex.c +++ b/lib/ecoli_node_sh_lex.c @@ -395,52 +395,40 @@ static int ec_node_sh_lex_testcase(void) } ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST, - "foo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, " ", EC_NODE_ENDLIST, - "foo", EC_NODE_ENDLIST, - "foo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "f", EC_NODE_ENDLIST, - "oo", EC_NODE_ENDLIST, - "oo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", EC_NODE_ENDLIST, - "", EC_NODE_ENDLIST, - ""); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo ", EC_NODE_ENDLIST, - "bar", "toto", EC_NODE_ENDLIST, - ""); + "bar", "toto", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo t", EC_NODE_ENDLIST, - "oto", EC_NODE_ENDLIST, - "oto"); + "toto", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo b", EC_NODE_ENDLIST, - "ar", EC_NODE_ENDLIST, - "ar"); + "bar", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo bar", EC_NODE_ENDLIST, - "", EC_NODE_ENDLIST, - ""); + "bar", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo bar ", EC_NODE_ENDLIST, - "titi", EC_NODE_ENDLIST, - "titi"); + "titi", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo toto bar ", EC_NODE_ENDLIST, - "titi", EC_NODE_ENDLIST, - "titi"); + "titi", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "x", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo barx", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ec_node_free(node); return ret; diff --git a/lib/ecoli_node_space.c b/lib/ecoli_node_space.c index fd526e6..48ffb6e 100644 --- a/lib/ecoli_node_space.c +++ b/lib/ecoli_node_space.c @@ -99,18 +99,16 @@ static int ec_node_space_testcase(void) ec_log(EC_LOG_ERR, "cannot create node\n"); return -1; } + /* never completes whatever the input */ ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, " ", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ec_node_free(node); return ret; diff --git a/lib/ecoli_node_str.c b/lib/ecoli_node_str.c index 30e1a1a..b846448 100644 --- a/lib/ecoli_node_str.c +++ b/lib/ecoli_node_str.c @@ -88,7 +88,7 @@ ec_node_str_complete(const struct ec_node *gen_node, if (str[n] == '\0') { if (ec_completed_add_match(completed, parsed, gen_node, - node->string + n) < 0) + node->string) < 0) return -1; } @@ -221,12 +221,12 @@ static int ec_node_str_testcase(void) "foo"); ret |= EC_TEST_CHECK_COMPLETE(node, "f", EC_NODE_ENDLIST, - "oo", EC_NODE_ENDLIST, - "oo"); + "foo", EC_NODE_ENDLIST, + "foo"); ret |= EC_TEST_CHECK_COMPLETE(node, "foo", EC_NODE_ENDLIST, - "", EC_NODE_ENDLIST, - ""); + "foo", EC_NODE_ENDLIST, + "foo"); ret |= EC_TEST_CHECK_COMPLETE(node, "x", EC_NODE_ENDLIST, EC_NODE_ENDLIST, diff --git a/lib/ecoli_node_subset.c b/lib/ecoli_node_subset.c index 615abd5..1bd7a12 100644 --- a/lib/ecoli_node_subset.c +++ b/lib/ecoli_node_subset.c @@ -385,44 +385,34 @@ static int ec_node_subset_testcase(void) } ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - "foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST, - ""); + "foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "", EC_NODE_ENDLIST, - "bar2", "bar", "foo", "toto", "titi", EC_NODE_ENDLIST, - ""); + "bar2", "bar", "foo", "toto", "titi", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "bar", "bar2", "", EC_NODE_ENDLIST, - "foo", "toto", "titi", EC_NODE_ENDLIST, - ""); + "foo", "toto", "titi", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "f", EC_NODE_ENDLIST, - "oo", EC_NODE_ENDLIST, - "oo"); + "foo", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "b", EC_NODE_ENDLIST, - "ar", "ar2", EC_NODE_ENDLIST, - "ar"); + "bar", "bar2", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "bar", EC_NODE_ENDLIST, - "", "2", EC_NODE_ENDLIST, - ""); + "bar", "bar2", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "bar", "b", EC_NODE_ENDLIST, - "ar2", EC_NODE_ENDLIST, - "ar2"); + "bar2", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "t", EC_NODE_ENDLIST, - "oto", "iti", EC_NODE_ENDLIST, - ""); + "toto", "titi", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "to", EC_NODE_ENDLIST, - "to", EC_NODE_ENDLIST, - "to"); + "toto", EC_NODE_ENDLIST); ret |= EC_TEST_CHECK_COMPLETE(node, "x", EC_NODE_ENDLIST, - EC_NODE_ENDLIST, - ""); + EC_NODE_ENDLIST); ec_node_free(node); return ret; diff --git a/lib/ecoli_test.c b/lib/ecoli_test.c index 070d99b..291417d 100644 --- a/lib/ecoli_test.c +++ b/lib/ecoli_test.c @@ -102,8 +102,7 @@ int ec_test_check_complete(struct ec_node *tk, ...) { struct ec_completed *c = NULL; struct ec_strvec *vec = NULL; - const char *expected, *s; - char *smallest_start = NULL; + const char *s; int ret = 0; unsigned int count = 0; va_list ap; @@ -148,7 +147,7 @@ int ec_test_check_complete(struct ec_node *tk, ...) /* only check matching completions */ iter = ec_completed_iter(c, EC_MATCH); while ((item = ec_completed_iter_next(iter)) != NULL) { - if (item->add != NULL && strcmp(item->add, s) == 0) + if (item->str != NULL && strcmp(item->str, s) == 0) break; } @@ -170,22 +169,9 @@ int ec_test_check_complete(struct ec_node *tk, ...) } else ec_completed_dump(stdout, c); //XXX - /* check the expected smallest start */ - expected = va_arg(ap, const char *); - smallest_start = ec_completed_smallest_start(c); - if (smallest_start == NULL) - goto out; - if (strcmp(smallest_start, expected)) { - ret = -1; - ec_log(EC_LOG_ERR, - "should complete with <%s> but completes with <%s>\n", - expected, s); - } - out: ec_strvec_free(vec); ec_completed_free(c); - ec_free(smallest_start); va_end(ap); return ret; } diff --git a/lib/main-readline.c b/lib/main-readline.c index 2d3a39c..6133c54 100644 --- a/lib/main-readline.c +++ b/lib/main-readline.c @@ -56,7 +56,8 @@ static char *my_completion_entry(const char *s, int state) static struct ec_completed *c; static struct ec_completed_iter *iter; static const struct ec_completed_item *item; - char *out_string; + + (void)s; /* don't append a quote */ rl_completion_suppress_quote = 1; @@ -98,10 +99,7 @@ static char *my_completion_entry(const char *s, int state) //XXX see printable_part() and rl_display_match_list() //XXX or: if match count > 1, strip beginning (in node_file) - if (asprintf(&out_string, "%s%s", s, item->add) < 0) // XXX ec_asprintf (check all in code) - return NULL; - - return out_string; + return strdup(item->str); } static char **my_attempted_completion(const char *text, int start, int end) @@ -200,7 +198,7 @@ static int show_help(int ignore, int invoking_key) #else count = 0; TAILQ_FOREACH(compnode, &c->nodes, next) { - if (TAILQ_EMPTY(&compnode->matches)) + if (TAILQ_EMPTY(&compnode->items)) continue; count++; } @@ -212,12 +210,13 @@ static int show_help(int ignore, int invoking_key) if (match) helps[1] = ""; + /* strangely, rl_display_match_list() expects first index at 1 */ i = match + 1; TAILQ_FOREACH(compnode, &c->nodes, next) { - if (TAILQ_EMPTY(&compnode->matches)) + if (TAILQ_EMPTY(&compnode->items)) continue; // we should pass compnode instead - helps[i++] = get_node_help(TAILQ_FIRST(&compnode->matches)); //XXX + helps[i++] = get_node_help(TAILQ_FIRST(&compnode->items)); //XXX } #endif -- 2.39.5