]> git.droids-corp.org - protos/libecoli.git/commitdiff
elt -> item
authorOlivier Matz <zer0@droids-corp.org>
Fri, 18 Aug 2017 20:26:45 +0000 (22:26 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Fri, 18 Aug 2017 20:50:04 +0000 (22:50 +0200)
lib/ecoli_completed.c
lib/ecoli_completed.h
lib/ecoli_test.c
lib/main-readline.c

index 4547e6214da366928cada4ea309aef8bf8e8e286..ea3d18cb758b4ed0e41c772b901814da8550a496 100644 (file)
@@ -47,7 +47,7 @@ struct ec_completed *ec_completed(void)
        if (completed == NULL)
                return NULL;
 
-       TAILQ_INIT(&completed->elts);
+       TAILQ_INIT(&completed->items);
        completed->count_match = 0;
 
        return completed;
@@ -154,14 +154,14 @@ static size_t strcmp_count(const char *s1, const char *s2)
        return i;
 }
 
-static struct ec_completed_elt *
-ec_completed_elt(enum ec_completed_type type, struct ec_parsed *state,
+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)
 {
-       struct ec_completed_elt *elt = NULL;
+       struct ec_completed_item *item = NULL;
 
-       elt = ec_calloc(1, sizeof(*elt));
-       if (elt == NULL)
+       item = ec_calloc(1, sizeof(*item));
+       if (item == NULL)
                return NULL;
 
        /* XXX can state be NULL? */
@@ -174,56 +174,56 @@ ec_completed_elt(enum ec_completed_type type, struct ec_parsed *state,
                     p = ec_parsed_get_parent(p), len++)
                        ;
 
-               elt->path = ec_calloc(len, sizeof(*elt->path));
-               if (elt->path == NULL)
+               item->path = ec_calloc(len, sizeof(*item->path));
+               if (item->path == NULL)
                        goto fail;
 
-               elt->pathlen = len;
+               item->pathlen = len;
 
                /* write path in array */
                for (p = state, len = 0; p != NULL;
                     p = ec_parsed_get_parent(p), len++)
-                       elt->path[len] = p->node;
+                       item->path[len] = p->node;
        }
 
-       elt->type = type;
-       elt->node = node;
+       item->type = type;
+       item->node = node;
        if (add != NULL) {
-               elt->add = ec_strdup(add);
-               if (elt->add == NULL)
+               item->add = ec_strdup(add);
+               if (item->add == NULL)
                        goto fail;
        }
 
-       return elt;
+       return item;
 
 fail:
-       if (elt != NULL) {
-               ec_free(elt->path);
-               ec_free(elt->add);
+       if (item != NULL) {
+               ec_free(item->path);
+               ec_free(item->add);
        }
-       ec_completed_elt_free(elt);
+       ec_completed_item_free(item);
 
        return NULL;
 }
 
-static int ec_completed_add_elt(struct ec_completed *completed,
-                               struct ec_completed_elt *elt)
+static int ec_completed_add_item(struct ec_completed *completed,
+                               struct ec_completed_item *item)
 {
        size_t n;
 
-       if (elt->add != NULL) {
+       if (item->add != NULL) {
                if (completed->smallest_start == NULL) {
-                       completed->smallest_start = ec_strdup(elt->add);
+                       completed->smallest_start = ec_strdup(item->add);
                        if (completed->smallest_start == NULL)
                                return -ENOMEM;
                } else {
-                       n = strcmp_count(elt->add,
+                       n = strcmp_count(item->add,
                                completed->smallest_start);
                        completed->smallest_start[n] = '\0';
                }
                completed->count_match++;
        }
-       TAILQ_INSERT_TAIL(&completed->elts, elt, next);
+       TAILQ_INSERT_TAIL(&completed->items, item, next);
        completed->count++;
 
        return 0;
@@ -233,16 +233,16 @@ int ec_completed_add_match(struct ec_completed *completed,
                        struct ec_parsed *state,
                        const struct ec_node *node, const char *add)
 {
-       struct ec_completed_elt *elt;
+       struct ec_completed_item *item;
        int ret;
 
-       elt = ec_completed_elt(EC_MATCH, state, node, add);
-       if (elt == NULL)
+       item = ec_completed_item(EC_MATCH, state, node, add);
+       if (item == NULL)
                return -ENOMEM;
 
-       ret = ec_completed_add_elt(completed, elt);
+       ret = ec_completed_add_item(completed, item);
        if (ret < 0) {
-               ec_completed_elt_free(elt);
+               ec_completed_item_free(item);
                return ret;
        }
 
@@ -252,27 +252,27 @@ int ec_completed_add_match(struct ec_completed *completed,
 int ec_completed_add_no_match(struct ec_completed *completed,
                        struct ec_parsed *state, const struct ec_node *node)
 {
-       struct ec_completed_elt *elt;
+       struct ec_completed_item *item;
        int ret;
 
-       elt = ec_completed_elt(EC_NO_MATCH, state, node, NULL);
-       if (elt == NULL)
+       item = ec_completed_item(EC_NO_MATCH, state, node, NULL);
+       if (item == NULL)
                return -ENOMEM;
 
-       ret = ec_completed_add_elt(completed, elt);
+       ret = ec_completed_add_item(completed, item);
        if (ret < 0) {
-               ec_completed_elt_free(elt);
+               ec_completed_item_free(item);
                return ret;
        }
 
        return 0;
 }
 
-void ec_completed_elt_free(struct ec_completed_elt *elt)
+void ec_completed_item_free(struct ec_completed_item *item)
 {
-       ec_free(elt->add);
-       ec_free(elt->path);
-       ec_free(elt);
+       ec_free(item->add);
+       ec_free(item->path);
+       ec_free(item);
 }
 
 /* default completion function: return a no-match element */
@@ -303,15 +303,15 @@ struct ec_completed *ec_node_default_complete(const struct ec_node *gen_node,
 void ec_completed_merge(struct ec_completed *completed1,
        struct ec_completed *completed2)
 {
-       struct ec_completed_elt *elt;
+       struct ec_completed_item *item;
 
        assert(completed1 != NULL);
        assert(completed2 != NULL);
 
-       while (!TAILQ_EMPTY(&completed2->elts)) {
-               elt = TAILQ_FIRST(&completed2->elts);
-               TAILQ_REMOVE(&completed2->elts, elt, next);
-               ec_completed_add_elt(completed1, elt);
+       while (!TAILQ_EMPTY(&completed2->items)) {
+               item = TAILQ_FIRST(&completed2->items);
+               TAILQ_REMOVE(&completed2->items, item, next);
+               ec_completed_add_item(completed1, item);
        }
 
        ec_completed_free(completed2);
@@ -319,15 +319,15 @@ void ec_completed_merge(struct ec_completed *completed1,
 
 void ec_completed_free(struct ec_completed *completed)
 {
-       struct ec_completed_elt *elt;
+       struct ec_completed_item *item;
 
        if (completed == NULL)
                return;
 
-       while (!TAILQ_EMPTY(&completed->elts)) {
-               elt = TAILQ_FIRST(&completed->elts);
-               TAILQ_REMOVE(&completed->elts, elt, next);
-               ec_completed_elt_free(elt);
+       while (!TAILQ_EMPTY(&completed->items)) {
+               item = TAILQ_FIRST(&completed->items);
+               TAILQ_REMOVE(&completed->items, item, next);
+               ec_completed_item_free(item);
        }
        ec_free(completed->smallest_start);
        ec_free(completed);
@@ -335,7 +335,7 @@ void ec_completed_free(struct ec_completed *completed)
 
 void ec_completed_dump(FILE *out, const struct ec_completed *completed)
 {
-       struct ec_completed_elt *elt;
+       struct ec_completed_item *item;
 
        if (completed == NULL || completed->count == 0) {
                fprintf(out, "no completion\n");
@@ -346,9 +346,9 @@ void ec_completed_dump(FILE *out, const struct ec_completed *completed)
                completed->count, completed->count_match,
                completed->smallest_start);
 
-       TAILQ_FOREACH(elt, &completed->elts, next) {
+       TAILQ_FOREACH(item, &completed->items, next) {
                fprintf(out, "add=<%s>, node=%p, node_type=%s\n",
-                       elt->add, elt->node, elt->node->type->name);
+                       item->add, item->node, item->node->type->name);
        }
 }
 
@@ -395,7 +395,7 @@ ec_completed_iter(struct ec_completed *completed,
        return iter;
 }
 
-const struct ec_completed_elt *ec_completed_iter_next(
+const struct ec_completed_item *ec_completed_iter_next(
        struct ec_completed_iter *iter)
 {
        if (iter->completed == NULL)
@@ -403,7 +403,7 @@ const struct ec_completed_elt *ec_completed_iter_next(
 
        do {
                if (iter->cur == NULL)
-                       iter->cur = TAILQ_FIRST(&iter->completed->elts);
+                       iter->cur = TAILQ_FIRST(&iter->completed->items);
                else
                        iter->cur = TAILQ_NEXT(iter->cur, next);
 
index 70c0b9873ecfbb8f9d0f4211bc509d9792d8fe9b..5e5690b2451ba1cd0e23d26149e9ca79914f175b 100644 (file)
@@ -40,8 +40,8 @@ enum ec_completed_type {
        EC_PARTIAL = 4,
 };
 
-struct ec_completed_elt {
-       TAILQ_ENTRY(ec_completed_elt) next;
+struct ec_completed_item {
+       TAILQ_ENTRY(ec_completed_item) next;
        enum ec_completed_type type;
        const struct ec_node *node;
        char *add;
@@ -51,17 +51,17 @@ struct ec_completed_elt {
        size_t pathlen;
 };
 
-TAILQ_HEAD(ec_completed_elt_list, ec_completed_elt);
+TAILQ_HEAD(ec_completed_item_list, ec_completed_item);
 
 struct ec_completed {
-       struct ec_completed_elt_list elts;
+       struct ec_completed_item_list items;
        unsigned count;
        unsigned count_match;
        char *smallest_start;
 };
 
 /*
- * return a completed object filled with elts
+ * return a completed object filled with items
  * return NULL on error (nomem?)
  */
 struct ec_completed *ec_node_complete(struct ec_node *node,
@@ -82,7 +82,7 @@ int ec_completed_add_match(struct ec_completed *completed,
 int ec_completed_add_no_match(struct ec_completed *completed,
                        struct ec_parsed *state, const struct ec_node *node);
 
-void ec_completed_elt_free(struct ec_completed_elt *elt);
+void ec_completed_item_free(struct ec_completed_item *item);
 void ec_completed_merge(struct ec_completed *completed1,
        struct ec_completed *completed2);
 void ec_completed_free(struct ec_completed *completed);
@@ -103,14 +103,14 @@ unsigned int ec_completed_count(
 struct ec_completed_iter {
        enum ec_completed_type type;
        const struct ec_completed *completed;
-       const struct ec_completed_elt *cur;
+       const struct ec_completed_item *cur;
 };
 
 struct ec_completed_iter *
 ec_completed_iter(struct ec_completed *completed,
        enum ec_completed_type type);
 
-const struct ec_completed_elt *ec_completed_iter_next(
+const struct ec_completed_item *ec_completed_iter_next(
        struct ec_completed_iter *iter);
 
 void ec_completed_iter_free(struct ec_completed_iter *iter);
index 31083242456cb854cebf5406476239ec17220706..fb4b1febf916888d21ec8db43d8f1cff1469aa5a 100644 (file)
@@ -101,7 +101,7 @@ out:
 int ec_test_check_complete(struct ec_node *tk, ...)
 {
        struct ec_completed *c = NULL;
-       struct ec_completed_elt *elt;
+       struct ec_completed_item *item;
        struct ec_strvec *vec = NULL;
        const char *s, *expected;
        int ret = 0;
@@ -140,13 +140,13 @@ int ec_test_check_complete(struct ec_node *tk, ...)
                }
 
                count++;
-               TAILQ_FOREACH(elt, &c->elts, next) {
+               TAILQ_FOREACH(item, &c->items, next) {
                        /* only check matching completions */
-                       if (elt->add != NULL && strcmp(elt->add, s) == 0)
+                       if (item->add != NULL && strcmp(item->add, s) == 0)
                                break;
                }
 
-               if (elt == NULL) {
+               if (item == NULL) {
                        ec_log(EC_LOG_ERR,
                                "completion <%s> not in list\n", s);
                        ret = -1;
index 7aef334063f615bae33a416a5520cb4a0aba1032..b147e8a3e2fca4dc9dbefb0f5590fa799b93e271 100644 (file)
@@ -54,7 +54,7 @@ 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_elt *elt;
+       static const struct ec_completed_item *item;
        char *out_string;
 
 
@@ -79,11 +79,11 @@ static char *my_completion_entry(const char *s, int state)
                        return NULL;
        }
 
-       elt = ec_completed_iter_next(iter);
-       if (elt == NULL)
+       item = ec_completed_iter_next(iter);
+       if (item == NULL)
                return NULL;
 
-       if (asprintf(&out_string, "%s%s", s, elt->add) < 0)
+       if (asprintf(&out_string, "%s%s", s, item->add) < 0)
                return NULL;
 
        return out_string;
@@ -101,7 +101,7 @@ static char **my_attempted_completion(const char *text, int start, int end)
 }
 
 /* this function builds the help string */
-static char *get_node_help(const struct ec_completed_elt *elt)
+static char *get_node_help(const struct ec_completed_item *item)
 {
        const struct ec_node *node;
        char *help = NULL;
@@ -109,8 +109,8 @@ static char *get_node_help(const struct ec_completed_elt *elt)
        const char *node_desc = NULL;
        size_t i;
 
-       for (i = 0; i < elt->pathlen; i++) {
-               node = elt->path[i];
+       for (i = 0; i < item->pathlen; i++) {
+               node = item->path[i];
                if (node_help == NULL)
                        node_help = ec_keyval_get(ec_node_attrs(node), "help");
                if (node_desc == NULL)
@@ -130,7 +130,7 @@ static char *get_node_help(const struct ec_completed_elt *elt)
 
 static int show_help(int ignore, int invoking_key)
 {
-       const struct ec_completed_elt *elt;
+       const struct ec_completed_item *item;
        struct ec_completed_iter *iter;
        struct ec_completed *c;
        struct ec_parsed *p;
@@ -173,10 +173,10 @@ static int show_help(int ignore, int invoking_key)
                goto fail;
 
        /* strangely, rl_display_match_list() expects first index at 1 */
-       for (i = match + 1, elt = ec_completed_iter_next(iter);
-            i < count + match + 1 && elt != NULL;
-            i++, elt = ec_completed_iter_next(iter)) {
-               helps[i] = get_node_help(elt);
+       for (i = match + 1, item = ec_completed_iter_next(iter);
+            i < count + match + 1 && item != NULL;
+            i++, item = ec_completed_iter_next(iter)) {
+               helps[i] = get_node_help(item);
        }
 
        ec_completed_free(c);