remove node build
[protos/libecoli.git] / lib / ecoli_completed.h
index 1627cfe..191c443 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/**
+ * 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_
 
 struct ec_node;
 
 enum ec_completed_type {
-       EC_NO_MATCH,
-       EC_MATCH,
-       EC_PARTIAL_MATCH,
+       EC_COMP_UNKNOWN = 0x1,
+       EC_COMP_FULL = 0x2,
+       EC_COMP_PARTIAL = 0x4,
+       EC_COMP_ALL = 0x7,
 };
 
-struct ec_completed_item {
-       TAILQ_ENTRY(ec_completed_item) next;
-       enum ec_completed_type type;
-       const struct ec_node *node;
-       char *str;
-       char *display;
-       /* XXX add a keyval (attrs) */
-
-       /* reverse order: [0] = last, [len-1] = root */
-       const struct ec_node **path;
-       size_t pathlen;
-};
+struct ec_completed_item;
 
 TAILQ_HEAD(ec_completed_item_list, ec_completed_item);
 
-struct ec_completed_node {
-       TAILQ_ENTRY(ec_completed_node) next;
+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_node_list, ec_completed_node);
+TAILQ_HEAD(ec_completed_group_list, ec_completed_group);
 
 struct ec_completed {
        unsigned count;
        unsigned count_match;
-       struct ec_completed_node_list nodes;
+       struct ec_parsed *cur_state;
+       struct ec_completed_group *cur_group;
+       struct ec_completed_group_list groups;
+       struct ec_keyval *attrs;
 };
 
 /*
@@ -81,49 +85,170 @@ struct ec_completed *ec_node_complete_strvec(struct ec_node *node,
 /* internal: used by nodes */
 int ec_node_complete_child(struct ec_node *node,
                        struct ec_completed *completed,
-                       struct ec_parsed *parsed_state,
                        const struct ec_strvec *strvec);
 
-struct ec_completed *ec_completed(void);
+/**
+ * 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);
 
-struct ec_completed_item *
-ec_completed_item(struct ec_parsed *state, const struct ec_node *node);
-int ec_completed_item_set(struct ec_completed_item *item,
-                       enum ec_completed_type type, const char *str);
-int ec_completed_item_add(struct ec_completed *completed,
-                       struct ec_completed_item *item);
-void ec_completed_item_free(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);
 
-void ec_completed_free(struct ec_completed *completed);
-void ec_completed_dump(FILE *out,
-       const struct ec_completed *completed);
+/**
+ * Set the completion value of an item.
+ *
+ *
+ */
+int ec_completed_item_set_completion(struct ec_completed_item *item,
+                               const char *completion);
+
+/**
+ *
+ *
+ *
+ */
 int
 ec_node_default_complete(const struct ec_node *gen_node,
                        struct ec_completed *completed,
-                       struct ec_parsed *state,
                        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;
-       const struct ec_completed *completed;
-       const struct ec_completed_node *cur_node;
-       const struct ec_completed_item *cur_match;
+       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);
 
-const struct ec_completed_item *ec_completed_iter_next(
+/**
+ *
+ *
+ *
+ */
+struct ec_completed_item *ec_completed_iter_next(
        struct ec_completed_iter *iter);
 
+/**
+ *
+ *
+ *
+ */
 void ec_completed_iter_free(struct ec_completed_iter *iter);