]> git.droids-corp.org - protos/libecoli.git/commitdiff
change add to full str
authorOlivier Matz <zer0@droids-corp.org>
Thu, 21 Sep 2017 15:13:19 +0000 (17:13 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 21 Sep 2017 15:13:19 +0000 (17:13 +0200)
17 files changed:
lib/ecoli_completed.c
lib/ecoli_completed.h
lib/ecoli_node_cmd.c
lib/ecoli_node_empty.c
lib/ecoli_node_file.c
lib/ecoli_node_int.c
lib/ecoli_node_many.c
lib/ecoli_node_once.c
lib/ecoli_node_option.c
lib/ecoli_node_or.c
lib/ecoli_node_seq.c
lib/ecoli_node_sh_lex.c
lib/ecoli_node_space.c
lib/ecoli_node_str.c
lib/ecoli_node_subset.c
lib/ecoli_test.c
lib/main-readline.c

index 71849d1270dd030f1f28cfa923b3a25f9f6612a0..728b284f97da7bb98062ecb2b7ebde262b71cd9e 100644 (file)
@@ -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;
index 33512dafe9f70e76294db0a8477b001967f7646f..39816bb1838396946fe31e667f656fb3bdd07c0a 100644 (file)
@@ -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);
index 01c2cd222a001cd448cd81ead9bba3a2dd38cdfe..9f14ae2792749245d3e75442e49fb15eab2f0116 100644 (file)
@@ -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);
 
index cc29779f54eca5f888dffa3a63a0ec366efa17a2..e513d6b9462b993076602f385a62251146b3e724 100644 (file)
@@ -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;
index c4f54af4ce77eb21fe8707109bb0519c06e69149..0a5caa3da88a323d18603c50a87eccd314440dee 100644 (file)
@@ -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);
 
index a7bd0573972bdcfdc4f84f250f160747440d694d..635b549e3a82e087dcb3d3b024bb465fe7e6f13b 100644 (file)
@@ -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;
index 4d748f865e73b1f4aa013484d38155e2d1d47883..8746269f1c6bda08972e5c76633a683014348d5d 100644 (file)
@@ -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;
index fd427b9076ab00443a92b3fd279bbaf338c2a38a..d52e0994600de384e2105038fab0157ff1b56877 100644 (file)
@@ -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;
index 4610a465851287501170347f1a6e35be661b3aef..ee2c4b15bfde04a67e7c0175008fcfad0222b0b6 100644 (file)
@@ -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;
index c1b808f714acd79432b51645e0fed6b5a5741319..391d84ed92da4f8a2f71dcbf1345abb18508bb4e 100644 (file)
@@ -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;
index d6338e9098571dee242dace6ece82ec5871b735b..7b22709575b925785436390fc28d8a868725e98f 100644 (file)
@@ -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;
index 897f922abdf0d4c3a33b4b848d299cc83d3f3370..1da0a90bbf5dadc784827e5406aee5614eb59c12 100644 (file)
@@ -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;
index fd526e6a3d3578fd5b6ec168f5e7d2ccbb07a208..48ffb6e5a627400c65ab1ed8819ca3837dd1ee72 100644 (file)
@@ -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;
index 30e1a1a11c89876feeef05fb4c634d63f010e6ac..b846448765873e3aad2406262e5d35efb7e42c2f 100644 (file)
@@ -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,
index 615abd59b1d22bd593df3da2a4f9e22de5e5104a..1bd7a127bf67a2a33eb5b129d862f0425baba989 100644 (file)
@@ -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;
index 070d99b5d65f27ae441345271ccbb2c90615d052..291417da90f123d63e004de49c7d69c3a00f5022 100644 (file)
@@ -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;
 }
index 2d3a39c419ee342357242496190dba5831a8e310..6133c54adc3dbac73236e8f3b8230dc143c3dcec 100644 (file)
@@ -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] = "<return>";
 
+       /* 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