hide some completion structures
authorOlivier Matz <zer0@droids-corp.org>
Fri, 18 Oct 2019 20:26:55 +0000 (22:26 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Fri, 18 Oct 2019 20:26:55 +0000 (22:26 +0200)
examples/readline/main.c
include/ecoli_complete.h
src/ecoli_complete.c
src/ecoli_editline.c
src/ecoli_node_dynamic.c

index a30953d..6095808 100644 (file)
@@ -70,7 +70,7 @@ static char *my_completion_entry(const char *s, int state)
                return NULL;
 
        item_str = ec_comp_item_get_str(item);
-       if (c->count_full == 1) {
+       if (ec_comp_count(c, EC_COMP_FULL) == 1) {
 
                /* don't add the trailing space for partial completions */
                if (state == 0) {
@@ -113,8 +113,7 @@ static char *get_node_help(const struct ec_comp_item *item)
        const char *node_desc = NULL;
 
        grp = ec_comp_item_get_grp(item);
-       state = grp->state;
-       for (state = grp->state; state != NULL;
+       for (state = ec_comp_group_get_state(grp); state != NULL;
             state = ec_parse_get_parent(state)) {
                node = ec_parse_get_node(state);
                if (node_help == NULL)
index b28aa4a..c57eb67 100644 (file)
@@ -33,29 +33,8 @@ enum ec_comp_type { /* XXX should be a define */
 };
 
 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_parse *state;
-       struct ec_dict *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_parse *cur_state;
-       struct ec_comp_group *cur_group;
-       struct ec_comp_group_list groups;
-       struct ec_dict *attrs;
-};
+struct ec_comp_group;
+struct ec_comp;
 
 /*
  * return a comp object filled with items
@@ -101,7 +80,23 @@ void ec_comp_dump(FILE *out,
 int ec_comp_merge(struct ec_comp *to,
                struct ec_comp *from);
 
-struct ec_parse *ec_comp_get_state(struct ec_comp *comp);
+/**
+ * Get current completion state.
+ *
+ */
+struct ec_parse *ec_comp_get_state(const struct ec_comp *comp);
+
+/**
+ * Get current completion group.
+ *
+ */
+struct ec_comp_group *ec_comp_get_group(const struct ec_comp *comp);
+
+/**
+ * Get completion group attributes.
+ *
+ */
+struct ec_dict *ec_comp_get_attrs(const struct ec_comp *comp);
 
 /* shortcut for ec_comp_item() + ec_comp_item_add() */
 int ec_comp_add_item(struct ec_comp *comp,
@@ -180,6 +175,31 @@ int ec_comp_item_set_display(struct ec_comp_item *item,
 int ec_comp_item_set_completion(struct ec_comp_item *item,
                                const char *completion);
 
+/**
+ * Get the completion group node.
+ *
+ *
+ */
+const struct ec_node *
+ec_comp_group_get_node(const struct ec_comp_group *grp);
+
+/**
+ * Get the completion group parsed state.
+ *
+ *
+ */
+const struct ec_parse *
+ec_comp_group_get_state(const struct ec_comp_group *grp);
+
+/**
+ * Get the completion group attributes.
+ *
+ *
+ */
+const struct ec_dict *
+ec_comp_group_get_attrs(const struct ec_comp_group *grp);
+
+
 /**
  *
  *
index e2f150a..22459bb 100644 (file)
@@ -34,6 +34,29 @@ struct ec_comp_item {
        struct ec_dict *attrs;
 };
 
+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_parse *state;
+       struct ec_dict *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_parse *cur_state;
+       struct ec_comp_group *cur_group;
+       struct ec_comp_group_list groups;
+       struct ec_dict *attrs;
+};
+
 struct ec_comp *ec_comp(struct ec_parse *state)
 {
        struct ec_comp *comp = NULL;
@@ -60,11 +83,21 @@ struct ec_comp *ec_comp(struct ec_parse *state)
        return NULL;
 }
 
-struct ec_parse *ec_comp_get_state(struct ec_comp *comp)
+struct ec_parse *ec_comp_get_state(const struct ec_comp *comp)
 {
        return comp->cur_state;
 }
 
+struct ec_comp_group *ec_comp_get_group(const struct ec_comp *comp)
+{
+       return comp->cur_group;
+}
+
+struct ec_dict *ec_comp_get_attrs(const struct ec_comp *comp)
+{
+       return comp->attrs;
+}
+
 int
 ec_node_complete_child(const struct ec_node *node,
                struct ec_comp *comp,
@@ -485,6 +518,24 @@ static void ec_comp_group_free(struct ec_comp_group *grp)
        ec_free(grp);
 }
 
+const struct ec_node *
+ec_comp_group_get_node(const struct ec_comp_group *grp)
+{
+       return grp->node;
+}
+
+const struct ec_parse *
+ec_comp_group_get_state(const struct ec_comp_group *grp)
+{
+       return grp->state;
+}
+
+const struct ec_dict *
+ec_comp_group_get_attrs(const struct ec_comp_group *grp)
+{
+       return grp->attrs;
+}
+
 void ec_comp_free(struct ec_comp *comp)
 {
        struct ec_comp_group *grp;
index ed8ea21..2610bf5 100644 (file)
@@ -393,7 +393,7 @@ static int get_node_help(const struct ec_comp_item *item,
 
        grp = ec_comp_item_get_grp(item);
 
-       for (state = grp->state; state != NULL;
+       for (state = ec_comp_group_get_state(grp); state != NULL;
             state = ec_parse_get_parent(state)) {
                node = ec_parse_get_node(state);
                if (node_help == NULL)
index 2b79f7a..e511f68 100644 (file)
@@ -80,7 +80,7 @@ ec_node_dynamic_complete(const struct ec_node *node,
        /* add the node pointer in the attributes, so it will be freed
         * when parse is freed */
        snprintf(key, sizeof(key), "_dyn_%p", child);
-       ret = ec_dict_set(comp->attrs, key, child,
+       ret = ec_dict_set(ec_comp_get_attrs(comp), key, child,
                        (void *)node_free);
        if (ret < 0) {
                child = NULL; /* already freed */