]> git.droids-corp.org - protos/libecoli.git/commitdiff
completed -> comp
authorOlivier Matz <zer0@droids-corp.org>
Mon, 12 Mar 2018 20:51:25 +0000 (21:51 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Mon, 12 Mar 2018 20:51:38 +0000 (21:51 +0100)
29 files changed:
lib/Makefile
lib/ecoli_complete.c [new file with mode: 0644]
lib/ecoli_complete.h [new file with mode: 0644]
lib/ecoli_completed.c [deleted file]
lib/ecoli_completed.h [deleted file]
lib/ecoli_node.h
lib/ecoli_node_any.c
lib/ecoli_node_cmd.c
lib/ecoli_node_dynamic.c
lib/ecoli_node_empty.c
lib/ecoli_node_expr.c
lib/ecoli_node_file.c
lib/ecoli_node_int.c
lib/ecoli_node_many.c
lib/ecoli_node_none.c
lib/ecoli_node_once.c
lib/ecoli_node_option.c
lib/ecoli_node_or.c
lib/ecoli_node_re.c
lib/ecoli_node_re_lex.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_node_weakref.c
lib/ecoli_test.c
lib/ecoli_test.h
lib/main-readline.c

index 9ee7f978a7765c96f031383b42042ff7b69c6ec0..a6d5057a801d0e3f9085d3cbdb34b51bf2bbb61a 100644 (file)
@@ -20,7 +20,7 @@ LDFLAGS += --coverage
 
 srcs :=
 srcs += ecoli_assert.c
-srcs += ecoli_completed.c
+srcs += ecoli_complete.c
 srcs += ecoli_keyval.c
 srcs += ecoli_init.c
 srcs += ecoli_log.c
diff --git a/lib/ecoli_complete.c b/lib/ecoli_complete.c
new file mode 100644 (file)
index 0000000..72abdf9
--- /dev/null
@@ -0,0 +1,636 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <ecoli_malloc.h>
+#include <ecoli_string.h>
+#include <ecoli_strvec.h>
+#include <ecoli_keyval.h>
+#include <ecoli_log.h>
+#include <ecoli_node.h>
+#include <ecoli_parsed.h>
+#include <ecoli_complete.h>
+
+struct ec_comp_item {
+       TAILQ_ENTRY(ec_comp_item) next;
+       enum ec_comp_type type;
+       const struct ec_node *node;
+       struct ec_comp_group *grp;
+       char *start;      /* the initial token */
+       char *full;       /* the full token after completion */
+       char *completion; /* chars that are added, NULL if not applicable */
+       char *display;    /* what should be displayed by help/completers */
+       struct ec_keyval *attrs;
+};
+
+struct ec_comp *ec_comp(struct ec_parsed *state)
+{
+       struct ec_comp *comp = NULL;
+
+       comp = ec_calloc(1, sizeof(*comp));
+       if (comp == NULL)
+               goto fail;
+
+       comp->attrs = ec_keyval();
+       if (comp->attrs == NULL)
+               goto fail;
+
+       TAILQ_INIT(&comp->groups);
+
+       comp->cur_state = state;
+
+       return comp;
+
+ fail:
+       if (comp != NULL)
+               ec_keyval_free(comp->attrs);
+       ec_free(comp);
+
+       return NULL;
+}
+
+struct ec_parsed *ec_comp_get_state(struct ec_comp *comp)
+{
+       return comp->cur_state;
+}
+
+int
+ec_node_complete_child(const struct ec_node *node,
+               struct ec_comp *comp,
+               const struct ec_strvec *strvec)
+{
+       struct ec_parsed *child_state, *cur_state;
+       struct ec_comp_group *cur_group;
+       int ret;
+
+       if (node->type->complete == NULL)
+               return -ENOTSUP;
+
+       /* save previous parse state, prepare child state */
+       cur_state = comp->cur_state;
+       child_state = ec_parsed(node);
+       if (child_state == NULL)
+               return -ENOMEM;
+
+       if (cur_state != NULL)
+               ec_parsed_link_child(cur_state, child_state);
+       comp->cur_state = child_state;
+       cur_group = comp->cur_group;
+       comp->cur_group = NULL;
+
+       /* fill the comp struct with items */
+       ret = node->type->complete(node, comp, strvec);
+
+       /* restore parent parse state */
+       if (cur_state != NULL) {
+               ec_parsed_unlink_child(cur_state, child_state);
+               assert(!ec_parsed_has_child(child_state));
+       }
+       ec_parsed_free(child_state);
+       comp->cur_state = cur_state;
+       comp->cur_group = cur_group;
+
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+struct ec_comp *ec_node_complete_strvec(const struct ec_node *node,
+       const struct ec_strvec *strvec)
+{
+       struct ec_comp *comp = NULL;
+       int ret;
+
+       comp = ec_comp(NULL);
+       if (comp == NULL)
+               goto fail;
+
+       ret = ec_node_complete_child(node, comp, strvec);
+       if (ret < 0)
+               goto fail;
+
+       return comp;
+
+fail:
+       ec_comp_free(comp);
+       return NULL;
+}
+
+struct ec_comp *ec_node_complete(const struct ec_node *node,
+       const char *str)
+{
+       struct ec_strvec *strvec = NULL;
+       struct ec_comp *comp;
+
+       errno = ENOMEM;
+       strvec = ec_strvec();
+       if (strvec == NULL)
+               goto fail;
+
+       if (ec_strvec_add(strvec, str) < 0)
+               goto fail;
+
+       comp = ec_node_complete_strvec(node, strvec);
+       if (comp == NULL)
+               goto fail;
+
+       ec_strvec_free(strvec);
+       return comp;
+
+ fail:
+       ec_strvec_free(strvec);
+       return NULL;
+}
+
+static struct ec_comp_group *
+ec_comp_group(const struct ec_node *node, struct ec_parsed *parsed)
+{
+       struct ec_comp_group *grp = NULL;
+
+       grp = ec_calloc(1, sizeof(*grp));
+       if (grp == NULL)
+               return NULL;
+
+       grp->attrs = ec_keyval();
+       if (grp->attrs == NULL)
+               goto fail;
+
+       grp->state = ec_parsed_dup(parsed);
+       if (grp->state == NULL)
+               goto fail;
+
+       grp->node = node;
+       TAILQ_INIT(&grp->items);
+
+       return grp;
+
+fail:
+       if (grp != NULL) {
+               ec_parsed_free(grp->state);
+               ec_keyval_free(grp->attrs);
+       }
+       ec_free(grp);
+       return NULL;
+}
+
+static struct ec_comp_item *
+ec_comp_item(const struct ec_node *node, enum ec_comp_type type,
+               const char *start, const char *full)
+{
+       struct ec_comp_item *item = NULL;
+       struct ec_keyval *attrs = NULL;
+       char *comp_cp = NULL, *start_cp = NULL;
+       char *full_cp = NULL, *display_cp = NULL;
+
+       if (type == EC_COMP_UNKNOWN && full != NULL) {
+               errno = EINVAL;
+               return NULL;
+       }
+       if (type != EC_COMP_UNKNOWN && full == NULL) {
+               errno = EINVAL;
+               return NULL;
+       }
+
+       item = ec_calloc(1, sizeof(*item));
+       if (item == NULL)
+               goto fail;
+
+       attrs = ec_keyval();
+       if (attrs == NULL)
+               goto fail;
+
+       if (start != NULL) {
+               start_cp = ec_strdup(start);
+               if (start_cp == NULL)
+                       goto fail;
+
+               if (ec_str_startswith(full, start)) {
+                       comp_cp = ec_strdup(&full[strlen(start)]);
+                       if (comp_cp == NULL)
+                               goto fail;
+               }
+       }
+       if (full != NULL) {
+               full_cp = ec_strdup(full);
+               if (full_cp == NULL)
+                       goto fail;
+               display_cp = ec_strdup(full);
+               if (display_cp == NULL)
+                       goto fail;
+       }
+
+       item->node = node;
+       item->type = type;
+       item->start = start_cp;
+       item->full = full_cp;
+       item->completion = comp_cp;
+       item->display = display_cp;
+       item->attrs = attrs;
+
+       return item;
+
+fail:
+       ec_keyval_free(attrs);
+       ec_free(comp_cp);
+       ec_free(start_cp);
+       ec_free(full_cp);
+       ec_free(display_cp);
+       ec_free(item);
+
+       return NULL;
+}
+
+int ec_comp_item_set_display(struct ec_comp_item *item,
+                               const char *display)
+{
+       char *display_copy = NULL;
+       int ret = 0;
+
+       if (item == NULL || display == NULL ||
+                       item->type == EC_COMP_UNKNOWN)
+               return -EINVAL;
+
+       display_copy = ec_strdup(display);
+       if (display_copy == NULL)
+               goto fail;
+
+       ec_free(item->display);
+       item->display = display_copy;
+
+       return 0;
+
+fail:
+       ec_free(display_copy);
+       return ret;
+}
+
+int
+ec_comp_item_set_completion(struct ec_comp_item *item,
+                               const char *completion)
+{
+       char *completion_copy = NULL;
+       int ret = 0;
+
+       if (item == NULL || completion == NULL ||
+                       item->type == EC_COMP_UNKNOWN)
+               return -EINVAL;
+
+       ret = -ENOMEM;
+       completion_copy = ec_strdup(completion);
+       if (completion_copy == NULL)
+               goto fail;
+
+       ec_free(item->completion);
+       item->completion = completion_copy;
+
+       return 0;
+
+fail:
+       ec_free(completion_copy);
+       return ret;
+}
+
+int
+ec_comp_item_set_str(struct ec_comp_item *item,
+                       const char *str)
+{
+       char *str_copy = NULL;
+       int ret = 0;
+
+       if (item == NULL || str == NULL ||
+                       item->type == EC_COMP_UNKNOWN)
+               return -EINVAL;
+
+       ret = -ENOMEM;
+       str_copy = ec_strdup(str);
+       if (str_copy == NULL)
+               goto fail;
+
+       ec_free(item->full);
+       item->full = str_copy;
+
+       return 0;
+
+fail:
+       ec_free(str_copy);
+       return ret;
+}
+
+static int
+ec_comp_item_add(struct ec_comp *comp,
+               struct ec_comp_item *item)
+{
+       if (comp == NULL || item == NULL || item->node == NULL)
+               return -EINVAL;
+
+       switch (item->type) {
+       case EC_COMP_UNKNOWN:
+               comp->count_unknown++;
+               break;
+       case EC_COMP_FULL:
+               comp->count_full++;
+               break;
+       case EC_COMP_PARTIAL:
+               comp->count_partial++;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (comp->cur_group == NULL) {
+               struct ec_comp_group *grp;
+
+               grp = ec_comp_group(item->node, comp->cur_state);
+               if (grp == NULL)
+                       return -ENOMEM;
+               TAILQ_INSERT_TAIL(&comp->groups, grp, next);
+               comp->cur_group = grp;
+       }
+
+       comp->count++;
+       TAILQ_INSERT_TAIL(&comp->cur_group->items, item, next);
+       item->grp = comp->cur_group;
+
+       return 0;
+}
+
+const char *
+ec_comp_item_get_str(const struct ec_comp_item *item)
+{
+       return item->full;
+}
+
+const char *
+ec_comp_item_get_display(const struct ec_comp_item *item)
+{
+       return item->display;
+}
+
+const char *
+ec_comp_item_get_completion(const struct ec_comp_item *item)
+{
+       return item->completion;
+}
+
+enum ec_comp_type
+ec_comp_item_get_type(const struct ec_comp_item *item)
+{
+       return item->type;
+}
+
+const struct ec_node *
+ec_comp_item_get_node(const struct ec_comp_item *item)
+{
+       return item->node;
+}
+
+const struct ec_comp_group *
+ec_comp_item_get_grp(const struct ec_comp_item *item)
+{
+       return item->grp;
+}
+
+static void
+ec_comp_item_free(struct ec_comp_item *item)
+{
+       if (item == NULL)
+               return;
+
+       ec_free(item->full);
+       ec_free(item->start);
+       ec_free(item->completion);
+       ec_free(item->display);
+       ec_keyval_free(item->attrs);
+       ec_free(item);
+}
+
+int ec_comp_add_item(struct ec_comp *comp,
+                       const struct ec_node *node,
+                       struct ec_comp_item **p_item,
+                       enum ec_comp_type type,
+                       const char *start, const char *full)
+{
+       struct ec_comp_item *item = NULL;
+       int ret;
+
+       item = ec_comp_item(node, type, start, full);
+       if (item == NULL)
+               return -1;
+
+       ret = ec_comp_item_add(comp, item);
+       if (ret < 0)
+               goto fail;
+
+       if (p_item != NULL)
+               *p_item = item;
+
+       return 0;
+
+fail:
+       ec_comp_item_free(item);
+
+       return -1;
+}
+
+/* return a completion item of type "unknown" */
+int
+ec_node_complete_unknown(const struct ec_node *gen_node,
+                       struct ec_comp *comp,
+                       const struct ec_strvec *strvec)
+{
+       int ret;
+
+       if (ec_strvec_len(strvec) != 1)
+               return 0;
+
+       ret = ec_comp_add_item(comp, gen_node, NULL,
+                               EC_COMP_UNKNOWN, NULL, NULL);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static void ec_comp_group_free(struct ec_comp_group *grp)
+{
+       struct ec_comp_item *item;
+
+       if (grp == NULL)
+               return;
+
+       while (!TAILQ_EMPTY(&grp->items)) {
+               item = TAILQ_FIRST(&grp->items);
+               TAILQ_REMOVE(&grp->items, item, next);
+               ec_comp_item_free(item);
+       }
+       ec_parsed_free(ec_parsed_get_root(grp->state));
+       ec_keyval_free(grp->attrs);
+       ec_free(grp);
+}
+
+void ec_comp_free(struct ec_comp *comp)
+{
+       struct ec_comp_group *grp;
+
+       if (comp == NULL)
+               return;
+
+       while (!TAILQ_EMPTY(&comp->groups)) {
+               grp = TAILQ_FIRST(&comp->groups);
+               TAILQ_REMOVE(&comp->groups, grp, next);
+               ec_comp_group_free(grp);
+       }
+       ec_keyval_free(comp->attrs);
+       ec_free(comp);
+}
+
+void ec_comp_dump(FILE *out, const struct ec_comp *comp)
+{
+       struct ec_comp_group *grp;
+       struct ec_comp_item *item;
+
+       if (comp == NULL || comp->count == 0) {
+               fprintf(out, "no completion\n");
+               return;
+       }
+
+       fprintf(out, "completion: count=%u full=%u partial=%u unknown=%u\n",
+               comp->count, comp->count_full,
+               comp->count_partial,  comp->count_unknown);
+
+       TAILQ_FOREACH(grp, &comp->groups, next) {
+               fprintf(out, "node=%p, node_type=%s\n",
+                       grp->node, grp->node->type->name);
+               TAILQ_FOREACH(item, &grp->items, next) {
+                       const char *typestr;
+
+                       switch (item->type) {
+                       case EC_COMP_UNKNOWN: typestr = "unknown"; break;
+                       case EC_COMP_FULL: typestr = "full"; break;
+                       case EC_COMP_PARTIAL: typestr = "partial"; break;
+                       default: typestr = "unknown"; break;
+                       }
+
+                       fprintf(out, "  type=%s str=<%s> comp=<%s> disp=<%s>\n",
+                               typestr, item->full, item->completion,
+                               item->display);
+               }
+       }
+}
+
+int ec_comp_merge(struct ec_comp *to,
+               struct ec_comp *from)
+{
+       struct ec_comp_group *grp;
+
+       while (!TAILQ_EMPTY(&from->groups)) {
+               grp = TAILQ_FIRST(&from->groups);
+               TAILQ_REMOVE(&from->groups, grp, next);
+               TAILQ_INSERT_TAIL(&to->groups, grp, next);
+       }
+       to->count += from->count;
+       to->count_full += from->count_full;
+       to->count_partial += from->count_partial;
+       to->count_unknown += from->count_unknown;
+
+       ec_comp_free(from);
+       return 0;
+}
+
+unsigned int ec_comp_count(
+       const struct ec_comp *comp,
+       enum ec_comp_type type)
+{
+       unsigned int count = 0;
+
+       if (comp == NULL)
+               return count;
+
+       if (type & EC_COMP_FULL)
+               count += comp->count_full;
+       if (type & EC_COMP_PARTIAL)
+               count += comp->count_partial;
+       if (type & EC_COMP_UNKNOWN)
+               count += comp->count_unknown;
+
+       return count;
+}
+
+struct ec_comp_iter *
+ec_comp_iter(struct ec_comp *comp,
+       enum ec_comp_type type)
+{
+       struct ec_comp_iter *iter;
+
+       iter = ec_calloc(1, sizeof(*iter));
+       if (iter == NULL)
+               return NULL;
+
+       iter->comp = comp;
+       iter->type = type;
+       iter->cur_node = NULL;
+       iter->cur_match = NULL;
+
+       return iter;
+}
+
+struct ec_comp_item *ec_comp_iter_next(
+       struct ec_comp_iter *iter)
+{
+       struct ec_comp *comp;
+       struct ec_comp_group *cur_node;
+       struct ec_comp_item *cur_match;
+
+       if (iter == NULL)
+               return NULL;
+       comp = iter->comp;
+       if (comp == NULL)
+               return NULL;
+
+       cur_node = iter->cur_node;
+       cur_match = iter->cur_match;
+
+       /* first call */
+       if (cur_node == NULL) {
+               TAILQ_FOREACH(cur_node, &comp->groups, next) {
+                       TAILQ_FOREACH(cur_match, &cur_node->items, next) {
+                               if (cur_match != NULL &&
+                                               cur_match->type & iter->type)
+                                       goto found;
+                       }
+               }
+               return NULL;
+       } else {
+               cur_match = TAILQ_NEXT(cur_match, next);
+               if (cur_match != NULL &&
+                               cur_match->type & iter->type)
+                       goto found;
+               cur_node = TAILQ_NEXT(cur_node, next);
+               while (cur_node != NULL) {
+                       cur_match = TAILQ_FIRST(&cur_node->items);
+                       if (cur_match != NULL &&
+                                       cur_match->type & iter->type)
+                               goto found;
+                       cur_node = TAILQ_NEXT(cur_node, next);
+               }
+               return NULL;
+       }
+
+found:
+       iter->cur_node = cur_node;
+       iter->cur_match = cur_match;
+
+       return iter->cur_match;
+}
+
+void ec_comp_iter_free(struct ec_comp_iter *iter)
+{
+       ec_free(iter);
+}
diff --git a/lib/ecoli_complete.h b/lib/ecoli_complete.h
new file mode 100644 (file)
index 0000000..123d3fe
--- /dev/null
@@ -0,0 +1,234 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
+ */
+
+/**
+ * API for generating completions item on a node.
+ *
+ * This file provide helpers to list and manipulate the possible
+ * completions for a given input.
+ *
+ * XXX comp vs item
+ */
+
+#ifndef ECOLI_COMPLETE_
+#define ECOLI_COMPLETE_
+
+#include <sys/queue.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+struct ec_node;
+
+enum ec_comp_type {
+       EC_COMP_UNKNOWN = 0x1,
+       EC_COMP_FULL = 0x2,
+       EC_COMP_PARTIAL = 0x4,
+       EC_COMP_ALL = 0x7,
+};
+
+struct ec_comp_item;
+
+TAILQ_HEAD(ec_comp_item_list, ec_comp_item);
+
+struct ec_comp_group {
+       TAILQ_ENTRY(ec_comp_group) next;
+       const struct ec_node *node;
+       struct ec_comp_item_list items;
+       struct ec_parsed *state;
+       struct ec_keyval *attrs;
+};
+
+TAILQ_HEAD(ec_comp_group_list, ec_comp_group);
+
+struct ec_comp {
+       unsigned count;
+       unsigned count_full;
+       unsigned count_partial;
+       unsigned count_unknown;
+       struct ec_parsed *cur_state;
+       struct ec_comp_group *cur_group;
+       struct ec_comp_group_list groups;
+       struct ec_keyval *attrs;
+};
+
+/*
+ * return a comp object filled with items
+ * return NULL on error (nomem?)
+ */
+struct ec_comp *ec_node_complete(const struct ec_node *node,
+       const char *str);
+struct ec_comp *ec_node_complete_strvec(const struct ec_node *node,
+       const struct ec_strvec *strvec);
+
+/* internal: used by nodes */
+int ec_node_complete_child(const struct ec_node *node,
+                       struct ec_comp *comp,
+                       const struct ec_strvec *strvec);
+
+/**
+ * Create a completion object (list of completion items).
+ *
+ *
+ */
+struct ec_comp *ec_comp(struct ec_parsed *state);
+
+/**
+ * Free a completion object and all its items.
+ *
+ *
+ */
+void ec_comp_free(struct ec_comp *comp);
+
+/**
+ *
+ *
+ *
+ */
+void ec_comp_dump(FILE *out,
+       const struct ec_comp *comp);
+
+/**
+ * Merge items contained in 'from' into 'to'
+ *
+ * The 'from' comp struct is freed.
+ */
+int ec_comp_merge(struct ec_comp *to,
+               struct ec_comp *from);
+
+struct ec_parsed *ec_comp_get_state(struct ec_comp *comp);
+
+/* shortcut for ec_comp_item() + ec_comp_item_add() */
+int ec_comp_add_item(struct ec_comp *comp,
+                       const struct ec_node *node,
+                       struct ec_comp_item **p_item,
+                       enum ec_comp_type type,
+                       const char *start, const char *full);
+
+/**
+ *
+ */
+int ec_comp_item_set_str(struct ec_comp_item *item,
+                       const char *str);
+
+/**
+ * Get the string value of a completion item.
+ *
+ *
+ */
+const char *
+ec_comp_item_get_str(const struct ec_comp_item *item);
+
+/**
+ * Get the display string value of a completion item.
+ *
+ *
+ */
+const char *
+ec_comp_item_get_display(const struct ec_comp_item *item);
+
+/**
+ * Get the completion string value of a completion item.
+ *
+ *
+ */
+const char *
+ec_comp_item_get_completion(const struct ec_comp_item *item);
+
+/**
+ * Get the group of a completion item.
+ *
+ *
+ */
+const struct ec_comp_group *
+ec_comp_item_get_grp(const struct ec_comp_item *item);
+
+/**
+ * Get the type of a completion item.
+ *
+ *
+ */
+enum ec_comp_type
+ec_comp_item_get_type(const struct ec_comp_item *item);
+
+/**
+ * Get the node associated to a completion item.
+ *
+ *
+ */
+const struct ec_node *
+ec_comp_item_get_node(const struct ec_comp_item *item);
+
+/**
+ * Set the display value of an item.
+ *
+ *
+ */
+int ec_comp_item_set_display(struct ec_comp_item *item,
+                               const char *display);
+
+/**
+ * Set the completion value of an item.
+ *
+ *
+ */
+int ec_comp_item_set_completion(struct ec_comp_item *item,
+                               const char *completion);
+
+/**
+ *
+ *
+ *
+ */
+int
+ec_node_complete_unknown(const struct ec_node *gen_node,
+                       struct ec_comp *comp,
+                       const struct ec_strvec *strvec);
+
+/**
+ *
+ *
+ *
+ */
+unsigned int ec_comp_count(
+       const struct ec_comp *comp,
+       enum ec_comp_type flags);
+
+/**
+ *
+ *
+ *
+ */
+struct ec_comp_iter {
+       enum ec_comp_type type;
+       struct ec_comp *comp;
+       struct ec_comp_group *cur_node;
+       struct ec_comp_item *cur_match;
+};
+
+/**
+ *
+ *
+ *
+ */
+struct ec_comp_iter *
+ec_comp_iter(struct ec_comp *comp,
+       enum ec_comp_type type);
+
+/**
+ *
+ *
+ *
+ */
+struct ec_comp_item *ec_comp_iter_next(
+       struct ec_comp_iter *iter);
+
+/**
+ *
+ *
+ *
+ */
+void ec_comp_iter_free(struct ec_comp_iter *iter);
+
+
+#endif
diff --git a/lib/ecoli_completed.c b/lib/ecoli_completed.c
deleted file mode 100644 (file)
index cde9e9d..0000000
+++ /dev/null
@@ -1,636 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
-
-#include <ecoli_malloc.h>
-#include <ecoli_string.h>
-#include <ecoli_strvec.h>
-#include <ecoli_keyval.h>
-#include <ecoli_log.h>
-#include <ecoli_node.h>
-#include <ecoli_parsed.h>
-#include <ecoli_completed.h>
-
-struct ec_completed_item {
-       TAILQ_ENTRY(ec_completed_item) next;
-       enum ec_completed_type type;
-       const struct ec_node *node;
-       struct ec_completed_group *grp;
-       char *start;      /* the initial token */
-       char *full;       /* the full token after completion */
-       char *completion; /* chars that are added, NULL if not applicable */
-       char *display;    /* what should be displayed by help/completers */
-       struct ec_keyval *attrs;
-};
-
-struct ec_completed *ec_completed(struct ec_parsed *state)
-{
-       struct ec_completed *completed = NULL;
-
-       completed = ec_calloc(1, sizeof(*completed));
-       if (completed == NULL)
-               goto fail;
-
-       completed->attrs = ec_keyval();
-       if (completed->attrs == NULL)
-               goto fail;
-
-       TAILQ_INIT(&completed->groups);
-
-       completed->cur_state = state;
-
-       return completed;
-
- fail:
-       if (completed != NULL)
-               ec_keyval_free(completed->attrs);
-       ec_free(completed);
-
-       return NULL;
-}
-
-struct ec_parsed *ec_completed_get_state(struct ec_completed *completed)
-{
-       return completed->cur_state;
-}
-
-int
-ec_node_complete_child(const struct ec_node *node,
-               struct ec_completed *completed,
-               const struct ec_strvec *strvec)
-{
-       struct ec_parsed *child_state, *cur_state;
-       struct ec_completed_group *cur_group;
-       int ret;
-
-       if (node->type->complete == NULL)
-               return -ENOTSUP;
-
-       /* save previous parse state, prepare child state */
-       cur_state = completed->cur_state;
-       child_state = ec_parsed(node);
-       if (child_state == NULL)
-               return -ENOMEM;
-
-       if (cur_state != NULL)
-               ec_parsed_link_child(cur_state, child_state);
-       completed->cur_state = child_state;
-       cur_group = completed->cur_group;
-       completed->cur_group = NULL;
-
-       /* fill the completed struct with items */
-       ret = node->type->complete(node, completed, strvec);
-
-       /* restore parent parse state */
-       if (cur_state != NULL) {
-               ec_parsed_unlink_child(cur_state, child_state);
-               assert(!ec_parsed_has_child(child_state));
-       }
-       ec_parsed_free(child_state);
-       completed->cur_state = cur_state;
-       completed->cur_group = cur_group;
-
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-struct ec_completed *ec_node_complete_strvec(const struct ec_node *node,
-       const struct ec_strvec *strvec)
-{
-       struct ec_completed *completed = NULL;
-       int ret;
-
-       completed = ec_completed(NULL);
-       if (completed == NULL)
-               goto fail;
-
-       ret = ec_node_complete_child(node, completed, strvec);
-       if (ret < 0)
-               goto fail;
-
-       return completed;
-
-fail:
-       ec_completed_free(completed);
-       return NULL;
-}
-
-struct ec_completed *ec_node_complete(const struct ec_node *node,
-       const char *str)
-{
-       struct ec_strvec *strvec = NULL;
-       struct ec_completed *completed;
-
-       errno = ENOMEM;
-       strvec = ec_strvec();
-       if (strvec == NULL)
-               goto fail;
-
-       if (ec_strvec_add(strvec, str) < 0)
-               goto fail;
-
-       completed = ec_node_complete_strvec(node, strvec);
-       if (completed == NULL)
-               goto fail;
-
-       ec_strvec_free(strvec);
-       return completed;
-
- fail:
-       ec_strvec_free(strvec);
-       return NULL;
-}
-
-static struct ec_completed_group *
-ec_completed_group(const struct ec_node *node, struct ec_parsed *parsed)
-{
-       struct ec_completed_group *grp = NULL;
-
-       grp = ec_calloc(1, sizeof(*grp));
-       if (grp == NULL)
-               return NULL;
-
-       grp->attrs = ec_keyval();
-       if (grp->attrs == NULL)
-               goto fail;
-
-       grp->state = ec_parsed_dup(parsed);
-       if (grp->state == NULL)
-               goto fail;
-
-       grp->node = node;
-       TAILQ_INIT(&grp->items);
-
-       return grp;
-
-fail:
-       if (grp != NULL) {
-               ec_parsed_free(grp->state);
-               ec_keyval_free(grp->attrs);
-       }
-       ec_free(grp);
-       return NULL;
-}
-
-static struct ec_completed_item *
-ec_completed_item(const struct ec_node *node, enum ec_completed_type type,
-               const char *start, const char *full)
-{
-       struct ec_completed_item *item = NULL;
-       struct ec_keyval *attrs = NULL;
-       char *comp_cp = NULL, *start_cp = NULL;
-       char *full_cp = NULL, *display_cp = NULL;
-
-       if (type == EC_COMP_UNKNOWN && full != NULL) {
-               errno = EINVAL;
-               return NULL;
-       }
-       if (type != EC_COMP_UNKNOWN && full == NULL) {
-               errno = EINVAL;
-               return NULL;
-       }
-
-       item = ec_calloc(1, sizeof(*item));
-       if (item == NULL)
-               goto fail;
-
-       attrs = ec_keyval();
-       if (attrs == NULL)
-               goto fail;
-
-       if (start != NULL) {
-               start_cp = ec_strdup(start);
-               if (start_cp == NULL)
-                       goto fail;
-
-               if (ec_str_startswith(full, start)) {
-                       comp_cp = ec_strdup(&full[strlen(start)]);
-                       if (comp_cp == NULL)
-                               goto fail;
-               }
-       }
-       if (full != NULL) {
-               full_cp = ec_strdup(full);
-               if (full_cp == NULL)
-                       goto fail;
-               display_cp = ec_strdup(full);
-               if (display_cp == NULL)
-                       goto fail;
-       }
-
-       item->node = node;
-       item->type = type;
-       item->start = start_cp;
-       item->full = full_cp;
-       item->completion = comp_cp;
-       item->display = display_cp;
-       item->attrs = attrs;
-
-       return item;
-
-fail:
-       ec_keyval_free(attrs);
-       ec_free(comp_cp);
-       ec_free(start_cp);
-       ec_free(full_cp);
-       ec_free(display_cp);
-       ec_free(item);
-
-       return NULL;
-}
-
-int ec_completed_item_set_display(struct ec_completed_item *item,
-                               const char *display)
-{
-       char *display_copy = NULL;
-       int ret = 0;
-
-       if (item == NULL || display == NULL ||
-                       item->type == EC_COMP_UNKNOWN)
-               return -EINVAL;
-
-       display_copy = ec_strdup(display);
-       if (display_copy == NULL)
-               goto fail;
-
-       ec_free(item->display);
-       item->display = display_copy;
-
-       return 0;
-
-fail:
-       ec_free(display_copy);
-       return ret;
-}
-
-int
-ec_completed_item_set_completion(struct ec_completed_item *item,
-                               const char *completion)
-{
-       char *completion_copy = NULL;
-       int ret = 0;
-
-       if (item == NULL || completion == NULL ||
-                       item->type == EC_COMP_UNKNOWN)
-               return -EINVAL;
-
-       ret = -ENOMEM;
-       completion_copy = ec_strdup(completion);
-       if (completion_copy == NULL)
-               goto fail;
-
-       ec_free(item->completion);
-       item->completion = completion_copy;
-
-       return 0;
-
-fail:
-       ec_free(completion_copy);
-       return ret;
-}
-
-int
-ec_completed_item_set_str(struct ec_completed_item *item,
-                       const char *str)
-{
-       char *str_copy = NULL;
-       int ret = 0;
-
-       if (item == NULL || str == NULL ||
-                       item->type == EC_COMP_UNKNOWN)
-               return -EINVAL;
-
-       ret = -ENOMEM;
-       str_copy = ec_strdup(str);
-       if (str_copy == NULL)
-               goto fail;
-
-       ec_free(item->full);
-       item->full = str_copy;
-
-       return 0;
-
-fail:
-       ec_free(str_copy);
-       return ret;
-}
-
-static int
-ec_completed_item_add(struct ec_completed *completed,
-               struct ec_completed_item *item)
-{
-       if (completed == NULL || item == NULL || item->node == NULL)
-               return -EINVAL;
-
-       switch (item->type) {
-       case EC_COMP_UNKNOWN:
-               completed->count_unknown++;
-               break;
-       case EC_COMP_FULL:
-               completed->count_full++;
-               break;
-       case EC_COMP_PARTIAL:
-               completed->count_partial++;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       if (completed->cur_group == NULL) {
-               struct ec_completed_group *grp;
-
-               grp = ec_completed_group(item->node, completed->cur_state);
-               if (grp == NULL)
-                       return -ENOMEM;
-               TAILQ_INSERT_TAIL(&completed->groups, grp, next);
-               completed->cur_group = grp;
-       }
-
-       completed->count++;
-       TAILQ_INSERT_TAIL(&completed->cur_group->items, item, next);
-       item->grp = completed->cur_group;
-
-       return 0;
-}
-
-const char *
-ec_completed_item_get_str(const struct ec_completed_item *item)
-{
-       return item->full;
-}
-
-const char *
-ec_completed_item_get_display(const struct ec_completed_item *item)
-{
-       return item->display;
-}
-
-const char *
-ec_completed_item_get_completion(const struct ec_completed_item *item)
-{
-       return item->completion;
-}
-
-enum ec_completed_type
-ec_completed_item_get_type(const struct ec_completed_item *item)
-{
-       return item->type;
-}
-
-const struct ec_node *
-ec_completed_item_get_node(const struct ec_completed_item *item)
-{
-       return item->node;
-}
-
-const struct ec_completed_group *
-ec_completed_item_get_grp(const struct ec_completed_item *item)
-{
-       return item->grp;
-}
-
-static void
-ec_completed_item_free(struct ec_completed_item *item)
-{
-       if (item == NULL)
-               return;
-
-       ec_free(item->full);
-       ec_free(item->start);
-       ec_free(item->completion);
-       ec_free(item->display);
-       ec_keyval_free(item->attrs);
-       ec_free(item);
-}
-
-int ec_completed_add_item(struct ec_completed *completed,
-                       const struct ec_node *node,
-                       struct ec_completed_item **p_item,
-                       enum ec_completed_type type,
-                       const char *start, const char *full)
-{
-       struct ec_completed_item *item = NULL;
-       int ret;
-
-       item = ec_completed_item(node, type, start, full);
-       if (item == NULL)
-               return -1;
-
-       ret = ec_completed_item_add(completed, item);
-       if (ret < 0)
-               goto fail;
-
-       if (p_item != NULL)
-               *p_item = item;
-
-       return 0;
-
-fail:
-       ec_completed_item_free(item);
-
-       return -1;
-}
-
-/* return a completion item of type "unknown" */
-int
-ec_node_complete_unknown(const struct ec_node *gen_node,
-                       struct ec_completed *completed,
-                       const struct ec_strvec *strvec)
-{
-       int ret;
-
-       if (ec_strvec_len(strvec) != 1)
-               return 0;
-
-       ret = ec_completed_add_item(completed, gen_node, NULL,
-                               EC_COMP_UNKNOWN, NULL, NULL);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-static void ec_completed_group_free(struct ec_completed_group *grp)
-{
-       struct ec_completed_item *item;
-
-       if (grp == NULL)
-               return;
-
-       while (!TAILQ_EMPTY(&grp->items)) {
-               item = TAILQ_FIRST(&grp->items);
-               TAILQ_REMOVE(&grp->items, item, next);
-               ec_completed_item_free(item);
-       }
-       ec_parsed_free(ec_parsed_get_root(grp->state));
-       ec_keyval_free(grp->attrs);
-       ec_free(grp);
-}
-
-void ec_completed_free(struct ec_completed *completed)
-{
-       struct ec_completed_group *grp;
-
-       if (completed == NULL)
-               return;
-
-       while (!TAILQ_EMPTY(&completed->groups)) {
-               grp = TAILQ_FIRST(&completed->groups);
-               TAILQ_REMOVE(&completed->groups, grp, next);
-               ec_completed_group_free(grp);
-       }
-       ec_keyval_free(completed->attrs);
-       ec_free(completed);
-}
-
-void ec_completed_dump(FILE *out, const struct ec_completed *completed)
-{
-       struct ec_completed_group *grp;
-       struct ec_completed_item *item;
-
-       if (completed == NULL || completed->count == 0) {
-               fprintf(out, "no completion\n");
-               return;
-       }
-
-       fprintf(out, "completion: count=%u full=%u partial=%u unknown=%u\n",
-               completed->count, completed->count_full,
-               completed->count_partial,  completed->count_unknown);
-
-       TAILQ_FOREACH(grp, &completed->groups, next) {
-               fprintf(out, "node=%p, node_type=%s\n",
-                       grp->node, grp->node->type->name);
-               TAILQ_FOREACH(item, &grp->items, next) {
-                       const char *typestr;
-
-                       switch (item->type) {
-                       case EC_COMP_UNKNOWN: typestr = "unknown"; break;
-                       case EC_COMP_FULL: typestr = "full"; break;
-                       case EC_COMP_PARTIAL: typestr = "partial"; break;
-                       default: typestr = "unknown"; break;
-                       }
-
-                       fprintf(out, "  type=%s str=<%s> comp=<%s> disp=<%s>\n",
-                               typestr, item->full, item->completion,
-                               item->display);
-               }
-       }
-}
-
-int ec_completed_merge(struct ec_completed *to,
-               struct ec_completed *from)
-{
-       struct ec_completed_group *grp;
-
-       while (!TAILQ_EMPTY(&from->groups)) {
-               grp = TAILQ_FIRST(&from->groups);
-               TAILQ_REMOVE(&from->groups, grp, next);
-               TAILQ_INSERT_TAIL(&to->groups, grp, next);
-       }
-       to->count += from->count;
-       to->count_full += from->count_full;
-       to->count_partial += from->count_partial;
-       to->count_unknown += from->count_unknown;
-
-       ec_completed_free(from);
-       return 0;
-}
-
-unsigned int ec_completed_count(
-       const struct ec_completed *completed,
-       enum ec_completed_type type)
-{
-       unsigned int count = 0;
-
-       if (completed == NULL)
-               return count;
-
-       if (type & EC_COMP_FULL)
-               count += completed->count_full;
-       if (type & EC_COMP_PARTIAL)
-               count += completed->count_partial;
-       if (type & EC_COMP_UNKNOWN)
-               count += completed->count_unknown;
-
-       return count;
-}
-
-struct ec_completed_iter *
-ec_completed_iter(struct ec_completed *completed,
-       enum ec_completed_type type)
-{
-       struct ec_completed_iter *iter;
-
-       iter = ec_calloc(1, sizeof(*iter));
-       if (iter == NULL)
-               return NULL;
-
-       iter->completed = completed;
-       iter->type = type;
-       iter->cur_node = NULL;
-       iter->cur_match = NULL;
-
-       return iter;
-}
-
-struct ec_completed_item *ec_completed_iter_next(
-       struct ec_completed_iter *iter)
-{
-       struct ec_completed *completed;
-       struct ec_completed_group *cur_node;
-       struct ec_completed_item *cur_match;
-
-       if (iter == NULL)
-               return NULL;
-       completed = iter->completed;
-       if (completed == NULL)
-               return NULL;
-
-       cur_node = iter->cur_node;
-       cur_match = iter->cur_match;
-
-       /* first call */
-       if (cur_node == NULL) {
-               TAILQ_FOREACH(cur_node, &completed->groups, next) {
-                       TAILQ_FOREACH(cur_match, &cur_node->items, next) {
-                               if (cur_match != NULL &&
-                                               cur_match->type & iter->type)
-                                       goto found;
-                       }
-               }
-               return NULL;
-       } else {
-               cur_match = TAILQ_NEXT(cur_match, next);
-               if (cur_match != NULL &&
-                               cur_match->type & iter->type)
-                       goto found;
-               cur_node = TAILQ_NEXT(cur_node, next);
-               while (cur_node != NULL) {
-                       cur_match = TAILQ_FIRST(&cur_node->items);
-                       if (cur_match != NULL &&
-                                       cur_match->type & iter->type)
-                               goto found;
-                       cur_node = TAILQ_NEXT(cur_node, next);
-               }
-               return NULL;
-       }
-
-found:
-       iter->cur_node = cur_node;
-       iter->cur_match = cur_match;
-
-       return iter->cur_match;
-}
-
-void ec_completed_iter_free(struct ec_completed_iter *iter)
-{
-       ec_free(iter);
-}
diff --git a/lib/ecoli_completed.h b/lib/ecoli_completed.h
deleted file mode 100644 (file)
index 7aeb905..0000000
+++ /dev/null
@@ -1,234 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
- */
-
-/**
- * API for generating completions item on a node.
- *
- * This file provide helpers to list and manipulate the possible
- * completions for a given input.
- *
- * XXX completed vs item
- */
-
-#ifndef ECOLI_COMPLETED_
-#define ECOLI_COMPLETED_
-
-#include <sys/queue.h>
-#include <sys/types.h>
-#include <stdio.h>
-
-struct ec_node;
-
-enum ec_completed_type {
-       EC_COMP_UNKNOWN = 0x1,
-       EC_COMP_FULL = 0x2,
-       EC_COMP_PARTIAL = 0x4,
-       EC_COMP_ALL = 0x7,
-};
-
-struct ec_completed_item;
-
-TAILQ_HEAD(ec_completed_item_list, ec_completed_item);
-
-struct ec_completed_group {
-       TAILQ_ENTRY(ec_completed_group) next;
-       const struct ec_node *node;
-       struct ec_completed_item_list items;
-       struct ec_parsed *state;
-       struct ec_keyval *attrs;
-};
-
-TAILQ_HEAD(ec_completed_group_list, ec_completed_group);
-
-struct ec_completed {
-       unsigned count;
-       unsigned count_full;
-       unsigned count_partial;
-       unsigned count_unknown;
-       struct ec_parsed *cur_state;
-       struct ec_completed_group *cur_group;
-       struct ec_completed_group_list groups;
-       struct ec_keyval *attrs;
-};
-
-/*
- * return a completed object filled with items
- * return NULL on error (nomem?)
- */
-struct ec_completed *ec_node_complete(const struct ec_node *node,
-       const char *str);
-struct ec_completed *ec_node_complete_strvec(const struct ec_node *node,
-       const struct ec_strvec *strvec);
-
-/* internal: used by nodes */
-int ec_node_complete_child(const struct ec_node *node,
-                       struct ec_completed *completed,
-                       const struct ec_strvec *strvec);
-
-/**
- * Create a completion object (list of completion items).
- *
- *
- */
-struct ec_completed *ec_completed(struct ec_parsed *state);
-
-/**
- * Free a completion object and all its items.
- *
- *
- */
-void ec_completed_free(struct ec_completed *completed);
-
-/**
- *
- *
- *
- */
-void ec_completed_dump(FILE *out,
-       const struct ec_completed *completed);
-
-/**
- * Merge items contained in 'from' into 'to'
- *
- * The 'from' completed struct is freed.
- */
-int ec_completed_merge(struct ec_completed *to,
-               struct ec_completed *from);
-
-struct ec_parsed *ec_completed_get_state(struct ec_completed *completed);
-
-/* shortcut for ec_completed_item() + ec_completed_item_add() */
-int ec_completed_add_item(struct ec_completed *completed,
-                       const struct ec_node *node,
-                       struct ec_completed_item **p_item,
-                       enum ec_completed_type type,
-                       const char *start, const char *full);
-
-/**
- *
- */
-int ec_completed_item_set_str(struct ec_completed_item *item,
-                       const char *str);
-
-/**
- * Get the string value of a completion item.
- *
- *
- */
-const char *
-ec_completed_item_get_str(const struct ec_completed_item *item);
-
-/**
- * Get the display string value of a completion item.
- *
- *
- */
-const char *
-ec_completed_item_get_display(const struct ec_completed_item *item);
-
-/**
- * Get the completion string value of a completion item.
- *
- *
- */
-const char *
-ec_completed_item_get_completion(const struct ec_completed_item *item);
-
-/**
- * Get the group of a completion item.
- *
- *
- */
-const struct ec_completed_group *
-ec_completed_item_get_grp(const struct ec_completed_item *item);
-
-/**
- * Get the type of a completion item.
- *
- *
- */
-enum ec_completed_type
-ec_completed_item_get_type(const struct ec_completed_item *item);
-
-/**
- * Get the node associated to a completion item.
- *
- *
- */
-const struct ec_node *
-ec_completed_item_get_node(const struct ec_completed_item *item);
-
-/**
- * Set the display value of an item.
- *
- *
- */
-int ec_completed_item_set_display(struct ec_completed_item *item,
-                               const char *display);
-
-/**
- * Set the completion value of an item.
- *
- *
- */
-int ec_completed_item_set_completion(struct ec_completed_item *item,
-                               const char *completion);
-
-/**
- *
- *
- *
- */
-int
-ec_node_complete_unknown(const struct ec_node *gen_node,
-                       struct ec_completed *completed,
-                       const struct ec_strvec *strvec);
-
-/**
- *
- *
- *
- */
-unsigned int ec_completed_count(
-       const struct ec_completed *completed,
-       enum ec_completed_type flags);
-
-/**
- *
- *
- *
- */
-struct ec_completed_iter {
-       enum ec_completed_type type;
-       struct ec_completed *completed;
-       struct ec_completed_group *cur_node;
-       struct ec_completed_item *cur_match;
-};
-
-/**
- *
- *
- *
- */
-struct ec_completed_iter *
-ec_completed_iter(struct ec_completed *completed,
-       enum ec_completed_type type);
-
-/**
- *
- *
- *
- */
-struct ec_completed_item *ec_completed_iter_next(
-       struct ec_completed_iter *iter);
-
-/**
- *
- *
- *
- */
-void ec_completed_iter_free(struct ec_completed_iter *iter);
-
-
-#endif
index c8803245179a479eed8a2592279079975e99e478..34b1139598c8bad262876a603f7ce0faee173687 100644 (file)
@@ -52,7 +52,7 @@
 
 struct ec_node;
 struct ec_parsed;
-struct ec_completed;
+struct ec_comp;
 struct ec_strvec;
 struct ec_keyval;
 
@@ -76,7 +76,7 @@ typedef int (*ec_node_parse_t)(const struct ec_node *node,
                        struct ec_parsed *state,
                        const struct ec_strvec *strvec);
 typedef int (*ec_node_complete_t)(const struct ec_node *node,
-                               struct ec_completed *completed_state,
+                               struct ec_comp *comp_state,
                                const struct ec_strvec *strvec);
 typedef const char * (*ec_node_desc_t)(const struct ec_node *);
 typedef int (*ec_node_init_priv_t)(struct ec_node *);
index 9ee1d39c4ba7e7110de475be9e150f63c72181d4..e9452b2fea1890626a249658189b157917684ca3 100644 (file)
@@ -13,7 +13,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_any.h>
 
 EC_LOG_TYPE_REGISTER(node_any);
index 01d96ac87a3b13a24c222614f645bf05f220cf42..180be4393b91df872a62b894d8bfe5058ed5f94f 100644 (file)
@@ -17,7 +17,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_expr.h>
 #include <ecoli_node_str.h>
 #include <ecoli_node_or.h>
@@ -370,14 +370,14 @@ ec_node_cmd_parse(const struct ec_node *gen_node, struct ec_parsed *state,
 
 static int
 ec_node_cmd_complete(const struct ec_node *gen_node,
-               struct ec_completed *completed,
+               struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
        struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
 
        if (node->cmd == NULL)
                return -ENOENT;
-       return ec_node_complete_child(node->cmd, completed, strvec);
+       return ec_node_complete_child(node->cmd, comp, strvec);
 }
 
 static void ec_node_cmd_free_priv(struct ec_node *gen_node)
index 1d11f1ca66ac0066056bf5aab00fe8f310b8e302..84b603e2b57266c47e60e3503d73cf884e7717bc 100644 (file)
@@ -14,7 +14,7 @@
 #include <ecoli_keyval.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_string.h>
 #include <ecoli_node_str.h>
 #include <ecoli_node_many.h>
@@ -63,7 +63,7 @@ fail:
 
 static int
 ec_node_dynamic_complete(const struct ec_node *gen_node,
-               struct ec_completed *completed,
+               struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
        struct ec_node_dynamic *node = (struct ec_node_dynamic *)gen_node;
@@ -73,7 +73,7 @@ ec_node_dynamic_complete(const struct ec_node *gen_node,
        char key[64];
        int ret = -1;
 
-       parsed = ec_completed_get_state(completed);
+       parsed = ec_comp_get_state(comp);
        child = node->build(parsed, node->opaque);
        if (child == NULL)
                goto fail;
@@ -81,14 +81,14 @@ ec_node_dynamic_complete(const struct ec_node *gen_node,
        /* add the node pointer in the attributes, so it will be freed
         * when parsed is freed */
        snprintf(key, sizeof(key), "_dyn_%p", child);
-       ret = ec_keyval_set(completed->attrs, key, child,
+       ret = ec_keyval_set(comp->attrs, key, child,
                        (void *)node_free);
        if (ret < 0) {
                child = NULL; /* already freed */
                goto fail;
        }
 
-       return ec_node_complete_child(child, completed, strvec);
+       return ec_node_complete_child(child, comp, strvec);
 
 fail:
        ec_node_free(child);
index 98a761485708151981e29baac3a71cfd5c928ffc..7d40c6c41d77fa0ad60d9fb8e99b134dc088cfd2 100644 (file)
@@ -13,7 +13,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_empty.h>
 
 EC_LOG_TYPE_REGISTER(node_empty);
index b4cc72d7b95e4e4158740c3fae58be4987b9425b..b72222064ab235d4992d7c2717b10dd0bc634567 100644 (file)
@@ -17,7 +17,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_seq.h>
 #include <ecoli_node_many.h>
 #include <ecoli_node_or.h>
@@ -58,14 +58,14 @@ static int ec_node_expr_parse(const struct ec_node *gen_node,
 
 static int
 ec_node_expr_complete(const struct ec_node *gen_node,
-               struct ec_completed *completed,
+               struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
        struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
 
        if (node->child == NULL)
                return -ENOENT;
-       return ec_node_complete_child(node->child, completed, strvec);
+       return ec_node_complete_child(node->child, comp, strvec);
 }
 
 static void ec_node_expr_free_priv(struct ec_node *gen_node)
index fd8bef4f6c92ba241ec93d0580fcc236bb413bc8..ab772dc3625d4b51642c1380c1c3043b1df8ab72 100644 (file)
@@ -18,7 +18,7 @@
 #include <ecoli_string.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_file.h>
 
 EC_LOG_TYPE_REGISTER(node_file);
@@ -100,13 +100,13 @@ static int split_path(const char *path, char **dname_p, char **bname_p)
 
 static int
 ec_node_file_complete(const struct ec_node *gen_node,
-               struct ec_completed *completed,
+               struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
        struct ec_node_file *node = (struct ec_node_file *)gen_node;
        char *dname = NULL, *bname = NULL, *effective_dir;
-       struct ec_completed_item *item = NULL;
-       enum ec_completed_type type;
+       struct ec_comp_item *item = NULL;
+       enum ec_comp_type type;
        struct stat st, st2;
        const char *input;
        size_t bname_len;
@@ -208,13 +208,13 @@ ec_node_file_complete(const struct ec_node *gen_node,
                        if (ec_asprintf(&disp_str, "%s", de->d_name) < 0)
                                goto fail;
                }
-               if (ec_completed_add_item(completed, gen_node, &item,
+               if (ec_comp_add_item(comp, gen_node, &item,
                                                type, input, comp_str) < 0)
                        goto out;
 
                /* fix the display string: we don't want to display the full
                 * path. */
-               if (ec_completed_item_set_display(item, disp_str) < 0)
+               if (ec_comp_item_set_display(item, disp_str) < 0)
                        goto out;
 
                item = NULL;
index 8e92c8a731f6800ea6dc6feafdfe24f072a5e624..48577cf6ed332e98cd47ebe59e981f3c101c9435 100644 (file)
@@ -16,7 +16,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_int.h>
 #include <ecoli_test.h>
 
index 7d38a895934b362a7d92614fdb0298f57f46b7b2..7c9a50aa3b7d6d8f2f7e49d46e6b241eaf48bd90 100644 (file)
@@ -15,7 +15,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_str.h>
 #include <ecoli_node_option.h>
 #include <ecoli_node_many.h>
@@ -82,16 +82,16 @@ fail:
 
 static int
 __ec_node_many_complete(struct ec_node_many *node, unsigned int max,
-                       struct ec_completed *completed,
+                       struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
-       struct ec_parsed *parsed = ec_completed_get_state(completed);
+       struct ec_parsed *parsed = ec_comp_get_state(comp);
        struct ec_strvec *childvec = NULL;
        unsigned int i;
        int ret;
 
        /* first, try to complete with the child node */
-       ret = ec_node_complete_child(node->child, completed, strvec);
+       ret = ec_node_complete_child(node->child, comp, strvec);
        if (ret < 0)
                goto fail;
 
@@ -129,7 +129,7 @@ __ec_node_many_complete(struct ec_node_many *node, unsigned int max,
                        goto fail;
                }
 
-               ret = __ec_node_many_complete(node, max, completed, childvec);
+               ret = __ec_node_many_complete(node, max, comp, childvec);
                ec_parsed_del_last_child(parsed);
                ec_strvec_free(childvec);
                childvec = NULL;
@@ -147,12 +147,12 @@ fail:
 
 static int
 ec_node_many_complete(const struct ec_node *gen_node,
-               struct ec_completed *completed,
+               struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
        struct ec_node_many *node = (struct ec_node_many *)gen_node;
 
-       return __ec_node_many_complete(node, node->max, completed,
+       return __ec_node_many_complete(node, node->max, comp,
                                strvec);
 }
 
index 8c5b3a9f7f5246c4916bcc8f710201695d8bc811..be1558a560fbb1cd1704ac9ca4d8f504e75246d1 100644 (file)
@@ -13,7 +13,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_none.h>
 
 EC_LOG_TYPE_REGISTER(node_none);
@@ -35,11 +35,11 @@ static int ec_node_none_parse(const struct ec_node *gen_node,
 
 static int
 ec_node_none_complete(const struct ec_node *gen_node,
-                       struct ec_completed *completed,
+                       struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
        (void)gen_node;
-       (void)completed;
+       (void)comp;
        (void)strvec;
 
        return 0;
index 51538f108d4137b92149380904201c93b01335d8..6052f6a7c233033395d9d0f36347ab86fdced22f 100644 (file)
@@ -15,7 +15,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_str.h>
 #include <ecoli_node_or.h>
 #include <ecoli_node_many.h>
@@ -66,11 +66,11 @@ ec_node_once_parse(const struct ec_node *gen_node,
 
 static int
 ec_node_once_complete(const struct ec_node *gen_node,
-               struct ec_completed *completed,
+               struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
        struct ec_node_once *node = (struct ec_node_once *)gen_node;
-       struct ec_parsed *parsed = ec_completed_get_state(completed);
+       struct ec_parsed *parsed = ec_comp_get_state(comp);
        unsigned int count;
        int ret;
 
@@ -81,7 +81,7 @@ ec_node_once_complete(const struct ec_node *gen_node,
        if (count > 0)
                return 0;
 
-       ret = ec_node_complete_child(node->child, completed, strvec);
+       ret = ec_node_complete_child(node->child, comp, strvec);
        if (ret < 0)
                return ret;
 
index 2d9db77c5df0eb5cc9b10cf775c37b2c0d4e0121..b454de2aa081c694f8fa6e57b1f8b7b31cac88c2 100644 (file)
@@ -14,7 +14,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_str.h>
 #include <ecoli_test.h>
 #include <ecoli_node_option.h>
@@ -46,12 +46,12 @@ ec_node_option_parse(const struct ec_node *gen_node,
 
 static int
 ec_node_option_complete(const struct ec_node *gen_node,
-                       struct ec_completed *completed,
+                       struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
        struct ec_node_option *node = (struct ec_node_option *)gen_node;
 
-       return ec_node_complete_child(node->child, completed, strvec);
+       return ec_node_complete_child(node->child, comp, strvec);
 }
 
 static void ec_node_option_free_priv(struct ec_node *gen_node)
index 38f8a3dd9ac4843f3a5f9b18ce81c1f2cf922425..b1af7909d528c8245e210b17bd46aab667ba0f0b 100644 (file)
@@ -14,7 +14,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_or.h>
 #include <ecoli_node_str.h>
 #include <ecoli_test.h>
@@ -48,7 +48,7 @@ ec_node_or_parse(const struct ec_node *gen_node,
 
 static int
 ec_node_or_complete(const struct ec_node *gen_node,
-               struct ec_completed *completed,
+               struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
        struct ec_node_or *node = (struct ec_node_or *)gen_node;
@@ -57,7 +57,7 @@ ec_node_or_complete(const struct ec_node *gen_node,
 
        for (n = 0; n < node->len; n++) {
                ret = ec_node_complete_child(node->table[n],
-                                       completed, strvec);
+                                       comp, strvec);
                if (ret < 0)
                        return ret;
        }
index 8563d6dc40680b181d0dc40a03a16d64b7b69b6e..2a42fa23845504ea021292bcb0e61873a0bb96c0 100644 (file)
@@ -14,7 +14,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_re.h>
 
 EC_LOG_TYPE_REGISTER(node_re);
index 91e4f8250986b3f55c8eaf3a11abf8e235fd80c2..91ddeedc2c7aac2da5f57f5eb94506e92120ae6b 100644 (file)
@@ -14,7 +14,7 @@
 #include <ecoli_test.h>
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_parsed.h>
 #include <ecoli_node_many.h>
 #include <ecoli_node_or.h>
index 21221f6d206b50d25f614b6b9cd3ba2739132ca4..ff370aa773a1821d3dd9f34b9a58112f27af3a99 100644 (file)
@@ -16,7 +16,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_str.h>
 #include <ecoli_node_option.h>
 #include <ecoli_node_or.h>
@@ -74,10 +74,10 @@ fail:
 
 static int
 __ec_node_seq_complete(struct ec_node **table, size_t table_len,
-               struct ec_completed *completed,
+               struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_parsed *parsed = ec_completed_get_state(completed);
+       struct ec_parsed *parsed = ec_comp_get_state(comp);
        struct ec_strvec *childvec = NULL;
        unsigned int i;
        int ret;
@@ -97,7 +97,7 @@ __ec_node_seq_complete(struct ec_node **table, size_t table_len,
         */
 
        /* first, try to complete with the first node of the table */
-       ret = ec_node_complete_child(table[0], completed, strvec);
+       ret = ec_node_complete_child(table[0], comp, strvec);
        if (ret < 0)
                goto fail;
 
@@ -129,7 +129,7 @@ __ec_node_seq_complete(struct ec_node **table, size_t table_len,
 
                ret = __ec_node_seq_complete(&table[1],
                                        table_len - 1,
-                                       completed, childvec);
+                                       comp, childvec);
                ec_parsed_del_last_child(parsed);
                ec_strvec_free(childvec);
                childvec = NULL;
@@ -147,12 +147,12 @@ fail:
 
 static int
 ec_node_seq_complete(const struct ec_node *gen_node,
-               struct ec_completed *completed,
+               struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
        struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
 
-       return __ec_node_seq_complete(node->table, node->len, completed,
+       return __ec_node_seq_complete(node->table, node->len, comp,
                                strvec);
 }
 
index d5c86ebf3202ca22f5038bb946bae26e16e7a7df..82da5d765bde09e3aa8e416a1a258ff199d688a2 100644 (file)
@@ -17,7 +17,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_seq.h>
 #include <ecoli_node_str.h>
 #include <ecoli_node_option.h>
@@ -262,14 +262,14 @@ ec_node_sh_lex_parse(const struct ec_node *gen_node,
 
 static int
 ec_node_sh_lex_complete(const struct ec_node *gen_node,
-                       struct ec_completed *completed,
+                       struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
        struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
-       struct ec_completed *tmp_completed = NULL;
+       struct ec_comp *tmp_comp = NULL;
        struct ec_strvec *new_vec = NULL;
-       struct ec_completed_iter *iter = NULL;
-       struct ec_completed_item *item = NULL;
+       struct ec_comp_iter *iter = NULL;
+       struct ec_comp_item *item = NULL;
        char *new_str = NULL;
        const char *str;
        char missing_quote = '\0';
@@ -285,54 +285,54 @@ ec_node_sh_lex_complete(const struct ec_node *gen_node,
 
        /* we will store the completions in a temporary struct, because
         * we want to update them (ex: add missing quotes) */
-       tmp_completed = ec_completed(ec_completed_get_state(completed));
-       if (tmp_completed == NULL)
+       tmp_comp = ec_comp(ec_comp_get_state(comp));
+       if (tmp_comp == NULL)
                goto fail;
 
-       ret = ec_node_complete_child(node->child, tmp_completed, new_vec);
+       ret = ec_node_complete_child(node->child, tmp_comp, new_vec);
        if (ret < 0)
                goto fail;
 
        /* add missing quote for full completions  */
        if (missing_quote != '\0') {
-               iter = ec_completed_iter(tmp_completed, EC_COMP_FULL);
+               iter = ec_comp_iter(tmp_comp, EC_COMP_FULL);
                if (iter == NULL)
                        goto fail;
-               while ((item = ec_completed_iter_next(iter)) != NULL) {
-                       str = ec_completed_item_get_str(item);
+               while ((item = ec_comp_iter_next(iter)) != NULL) {
+                       str = ec_comp_item_get_str(item);
                        if (ec_asprintf(&new_str, "%c%s%c", missing_quote, str,
                                        missing_quote) < 0) {
                                new_str = NULL;
                                goto fail;
                        }
-                       if (ec_completed_item_set_str(item, new_str) < 0)
+                       if (ec_comp_item_set_str(item, new_str) < 0)
                                goto fail;
                        ec_free(new_str);
                        new_str = NULL;
 
-                       str = ec_completed_item_get_completion(item);
+                       str = ec_comp_item_get_completion(item);
                        if (ec_asprintf(&new_str, "%s%c", str,
                                        missing_quote) < 0) {
                                new_str = NULL;
                                goto fail;
                        }
-                       if (ec_completed_item_set_completion(item, new_str) < 0)
+                       if (ec_comp_item_set_completion(item, new_str) < 0)
                                goto fail;
                        ec_free(new_str);
                        new_str = NULL;
                }
        }
 
-       ec_completed_iter_free(iter);
+       ec_comp_iter_free(iter);
        ec_strvec_free(new_vec);
 
-       ec_completed_merge(completed, tmp_completed);
+       ec_comp_merge(comp, tmp_comp);
 
        return 0;
 
  fail:
-       ec_completed_free(tmp_completed);
-       ec_completed_iter_free(iter);
+       ec_comp_free(tmp_comp);
+       ec_comp_iter_free(iter);
        ec_strvec_free(new_vec);
        ec_free(new_str);
 
index c905882f4c4b85eb6947e371e364296052a5baad..3f34629d1fafa044153bb475e00f9fa45b1bb31a 100644 (file)
@@ -13,7 +13,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_space.h>
 
 EC_LOG_TYPE_REGISTER(node_space);
index 1efe224044974a46251643c0fc732df269e29d5f..fdb277ee68ce816779cfc885814270cc56795a05 100644 (file)
@@ -13,7 +13,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_str.h>
 
 EC_LOG_TYPE_REGISTER(node_str);
@@ -46,7 +46,7 @@ ec_node_str_parse(const struct ec_node *gen_node,
 
 static int
 ec_node_str_complete(const struct ec_node *gen_node,
-               struct ec_completed *completed,
+               struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
        struct ec_node_str *node = (struct ec_node_str *)gen_node;
@@ -66,7 +66,7 @@ ec_node_str_complete(const struct ec_node *gen_node,
        if (str[n] != '\0')
                return EC_PARSED_NOMATCH;
 
-       if (ec_completed_add_item(completed, gen_node, NULL, EC_COMP_FULL,
+       if (ec_comp_add_item(comp, gen_node, NULL, EC_COMP_FULL,
                                        str, node->string) < 0)
                return -1;
 
index 3ec44dc473ef81f5ae17ff2ef856d020174f1768..756def131e24b20de5653839be511da3d9550c09 100644 (file)
@@ -15,7 +15,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_subset.h>
 #include <ecoli_node_str.h>
 #include <ecoli_node_or.h>
@@ -155,10 +155,10 @@ ec_node_subset_parse(const struct ec_node *gen_node,
 
 static int
 __ec_node_subset_complete(struct ec_node **table, size_t table_len,
-                       struct ec_completed *completed,
+                       struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
-       struct ec_parsed *parsed = ec_completed_get_state(completed);
+       struct ec_parsed *parsed = ec_comp_get_state(comp);
        struct ec_strvec *childvec = NULL;
        struct ec_node *save;
        size_t i, len;
@@ -179,7 +179,7 @@ __ec_node_subset_complete(struct ec_node **table, size_t table_len,
                        continue;
 
                ret = ec_node_complete_child(table[i],
-                                       completed, strvec);
+                                       comp, strvec);
                if (ret < 0)
                        goto fail;
        }
@@ -208,7 +208,7 @@ __ec_node_subset_complete(struct ec_node **table, size_t table_len,
                save = table[i];
                table[i] = NULL;
                ret = __ec_node_subset_complete(table, table_len,
-                                               completed, childvec);
+                                               comp, childvec);
                table[i] = save;
                ec_strvec_free(childvec);
                childvec = NULL;
@@ -226,12 +226,12 @@ fail:
 
 static int
 ec_node_subset_complete(const struct ec_node *gen_node,
-                       struct ec_completed *completed,
+                       struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
        struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
 
-       return __ec_node_subset_complete(node->table, node->len, completed,
+       return __ec_node_subset_complete(node->table, node->len, comp,
                                        strvec);
 }
 
index 4d75cfbf49c2764663291cdcc9344009de26d742..fad8e828d00e9fcc7875bca3e68cd3b8024d7f34 100644 (file)
@@ -15,7 +15,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_node_str.h>
 #include <ecoli_node_option.h>
 #include <ecoli_node_weakref.h>
@@ -42,12 +42,12 @@ ec_node_weakref_parse(const struct ec_node *gen_node,
 
 static int
 ec_node_weakref_complete(const struct ec_node *gen_node,
-                       struct ec_completed *completed,
+                       struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
        struct ec_node_weakref *node = (struct ec_node_weakref *)gen_node;
 
-       return ec_node_complete_child(node->child, completed, strvec);
+       return ec_node_complete_child(node->child, comp, strvec);
 }
 
 static struct ec_node_type ec_node_weakref_type = {
index b62e169d6641bc856e169768e0aa669c2e32d2f6..319e7e870454db2172b7da9bcd3a58cbb300f2bf 100644 (file)
@@ -14,7 +14,7 @@
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_parsed.h>
 
 static struct ec_test_list test_list = TAILQ_HEAD_INITIALIZER(test_list);
@@ -93,9 +93,9 @@ out:
        return ret;
 }
 
-int ec_test_check_complete(struct ec_node *tk, enum ec_completed_type type, ...)
+int ec_test_check_complete(struct ec_node *tk, enum ec_comp_type type, ...)
 {
-       struct ec_completed *c = NULL;
+       struct ec_comp *c = NULL;
        struct ec_strvec *vec = NULL;
        const char *s;
        int ret = 0;
@@ -129,8 +129,8 @@ int ec_test_check_complete(struct ec_node *tk, enum ec_completed_type type, ...)
        for (s = va_arg(ap, const char *);
             s != EC_NODE_ENDLIST;
             s = va_arg(ap, const char *)) {
-               struct ec_completed_iter *iter;
-               const struct ec_completed_item *item;
+               struct ec_comp_iter *iter;
+               const struct ec_comp_item *item;
 
                if (s == NULL) {
                        ret = -1;
@@ -140,9 +140,9 @@ int ec_test_check_complete(struct ec_node *tk, enum ec_completed_type type, ...)
                count++;
 
                /* only check matching completions */
-               iter = ec_completed_iter(c, type);
-               while ((item = ec_completed_iter_next(iter)) != NULL) {
-                       const char *str = ec_completed_item_get_str(item);
+               iter = ec_comp_iter(c, type);
+               while ((item = ec_comp_iter_next(iter)) != NULL) {
+                       const char *str = ec_comp_item_get_str(item);
                        if (str != NULL && strcmp(str, s) == 0)
                                break;
                }
@@ -152,21 +152,21 @@ int ec_test_check_complete(struct ec_node *tk, enum ec_completed_type type, ...)
                                "completion <%s> not in list\n", s);
                        ret = -1;
                }
-               ec_completed_iter_free(iter);
+               ec_comp_iter_free(iter);
        }
 
        /* check if we have more completions (or less) than expected */
-       if (count != ec_completed_count(c, type)) {
+       if (count != ec_comp_count(c, type)) {
                EC_LOG(EC_LOG_ERR,
                        "nb_completion (%d) does not match (%d)\n",
-                       count, ec_completed_count(c, type));
-               ec_completed_dump(stdout, c);
+                       count, ec_comp_count(c, type));
+               ec_comp_dump(stdout, c);
                ret = -1;
        }
 
 out:
        ec_strvec_free(vec);
-       ec_completed_free(c);
+       ec_comp_free(c);
        va_end(ap);
        return ret;
 }
index 56102cf862b53b8f9c63de187ada288f3bdbf736..82094ce224ffea64da46c62258ccc10eb3d5b911 100644 (file)
@@ -10,7 +10,7 @@
 #include <ecoli_log.h>
 
 struct ec_node;
-enum ec_completed_type;
+enum ec_comp_type;
 
 #define EC_TEST_REGISTER(t)                                            \
        static void ec_test_init_##t(void);                             \
@@ -78,7 +78,7 @@ int ec_test_check_parse(struct ec_node *node, int expected, ...);
 })
 
 int ec_test_check_complete(struct ec_node *node,
-                       enum ec_completed_type type, ...);
+                       enum ec_comp_type type, ...);
 
 #define EC_TEST_CHECK_COMPLETE(node, args...) ({                       \
        int ret_ = ec_test_check_complete(node, EC_COMP_FULL, args);    \
index 0f6abb2f226d805a0fedc5ddd1debe1b87af53a6..0fb57ab639ffaf30344dc4baf5e7f12b70254242 100644 (file)
@@ -14,7 +14,7 @@
 #include <ecoli_init.h>
 #include <ecoli_node.h>
 #include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_complete.h>
 #include <ecoli_keyval.h>
 #include <ecoli_node_str.h>
 #include <ecoli_node_seq.h>
@@ -32,10 +32,10 @@ static struct ec_node *commands;
 
 static char *my_completion_entry(const char *s, int state)
 {
-       static struct ec_completed *c;
-       static struct ec_completed_iter *iter;
-       const struct ec_completed_item *item;
-       enum ec_completed_type item_type;
+       static struct ec_comp *c;
+       static struct ec_comp_iter *iter;
+       const struct ec_comp_item *item;
+       enum ec_comp_type item_type;
        const char *item_str, *item_display;
 
        (void)s;
@@ -48,7 +48,7 @@ static char *my_completion_entry(const char *s, int state)
        if (state == 0) {
                char *line;
 
-               ec_completed_free(c);
+               ec_comp_free(c);
                line = strdup(rl_line_buffer);
                if (line == NULL)
                        return NULL;
@@ -59,22 +59,22 @@ static char *my_completion_entry(const char *s, int state)
                if (c == NULL)
                        return NULL;
 
-               ec_completed_iter_free(iter);
-               iter = ec_completed_iter(c, EC_COMP_FULL | EC_COMP_PARTIAL);
+               ec_comp_iter_free(iter);
+               iter = ec_comp_iter(c, EC_COMP_FULL | EC_COMP_PARTIAL);
                if (iter == NULL)
                        return NULL;
        }
 
-       item = ec_completed_iter_next(iter);
+       item = ec_comp_iter_next(iter);
        if (item == NULL)
                return NULL;
 
-       item_str = ec_completed_item_get_str(item);
+       item_str = ec_comp_item_get_str(item);
        if (c->count_full == 1) {
 
                /* don't add the trailing space for partial completions */
                if (state == 0) {
-                       item_type = ec_completed_item_get_type(item);
+                       item_type = ec_comp_item_get_type(item);
                        if (item_type == EC_COMP_FULL)
                                rl_completion_suppress_append = 0;
                        else
@@ -84,7 +84,7 @@ static char *my_completion_entry(const char *s, int state)
                return strdup(item_str);
        } else if (rl_completion_type == '?') {
                /* on second try only show the display part */
-               item_display = ec_completed_item_get_display(item);
+               item_display = ec_comp_item_get_display(item);
                return strdup(item_display);
        }
 
@@ -103,16 +103,16 @@ 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_item *item)
+static char *get_node_help(const struct ec_comp_item *item)
 {
-       const struct ec_completed_group *grp;
+       const struct ec_comp_group *grp;
        const struct ec_parsed *state;
        const struct ec_node *node;
        char *help = NULL;
        const char *node_help = NULL;
        const char *node_desc = NULL;
 
-       grp = ec_completed_item_get_grp(item);
+       grp = ec_comp_item_get_grp(item);
        state = grp->state;
        for (state = grp->state; state != NULL;
             state = ec_parsed_get_parent(state)) {
@@ -136,10 +136,10 @@ static char *get_node_help(const struct ec_completed_item *item)
 
 static int show_help(int ignore, int invoking_key)
 {
-       struct ec_completed_iter *iter;
-       const struct ec_completed_group *grp, *prev_grp = NULL;
-       const struct ec_completed_item *item;
-       struct ec_completed *c;
+       struct ec_comp_iter *iter;
+       const struct ec_comp_group *grp, *prev_grp = NULL;
+       const struct ec_comp_item *item;
+       struct ec_comp *c;
        struct ec_parsed *p;
        char *line = NULL;
        unsigned int count;
@@ -171,7 +171,7 @@ static int show_help(int ignore, int invoking_key)
 
        /* let's display one contextual help per node */
        count = 0;
-       iter = ec_completed_iter(c,
+       iter = ec_comp_iter(c,
                EC_COMP_UNKNOWN | EC_COMP_FULL | EC_COMP_PARTIAL);
        if (iter == NULL)
                goto fail;
@@ -183,11 +183,11 @@ static int show_help(int ignore, int invoking_key)
        if (match)
                helps[1] = "<return>";
 
-       while ((item = ec_completed_iter_next(iter)) != NULL) {
+       while ((item = ec_comp_iter_next(iter)) != NULL) {
                char **tmp;
 
                /* keep one help per group, skip other items  */
-               grp = ec_completed_item_get_grp(item);
+               grp = ec_comp_item_get_grp(item);
                if (grp == prev_grp)
                        continue;
 
@@ -201,8 +201,8 @@ static int show_help(int ignore, int invoking_key)
                count++;
        }
 
-       ec_completed_iter_free(iter);
-       ec_completed_free(c);
+       ec_comp_iter_free(iter);
+       ec_comp_free(c);
        /* ensure not more than 1 entry per line */
        rl_get_screen_size(NULL, &cols);
        rl_display_match_list(helps, count + match, cols);
@@ -211,10 +211,10 @@ static int show_help(int ignore, int invoking_key)
        return 0;
 
 fail:
-       ec_completed_iter_free(iter);
+       ec_comp_iter_free(iter);
        ec_parsed_free(p);
        free(line);
-       ec_completed_free(c);
+       ec_comp_free(c);
        if (helps != NULL) {
                while (count--)
                        free(helps[count + match + 1]);