1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
6 * API for generating completions item on a node.
8 * This file provide helpers to list and manipulate the possible
9 * completions for a given input.
14 #ifndef ECOLI_COMPLETE_
15 #define ECOLI_COMPLETE_
17 #include <sys/queue.h>
18 #include <sys/types.h>
23 enum ec_comp_type { /* XXX should be a define */
24 EC_COMP_UNKNOWN = 0x1,
26 EC_COMP_PARTIAL = 0x4,
32 TAILQ_HEAD(ec_comp_item_list, ec_comp_item);
34 struct ec_comp_group {
35 TAILQ_ENTRY(ec_comp_group) next;
36 const struct ec_node *node;
37 struct ec_comp_item_list items;
38 struct ec_parse *state;
39 struct ec_keyval *attrs;
42 TAILQ_HEAD(ec_comp_group_list, ec_comp_group);
47 unsigned count_partial;
48 unsigned count_unknown;
49 struct ec_parse *cur_state;
50 struct ec_comp_group *cur_group;
51 struct ec_comp_group_list groups;
52 struct ec_keyval *attrs;
56 * return a comp object filled with items
57 * return NULL on error (nomem?)
59 struct ec_comp *ec_node_complete(const struct ec_node *node,
61 struct ec_comp *ec_node_complete_strvec(const struct ec_node *node,
62 const struct ec_strvec *strvec);
64 /* internal: used by nodes */
65 int ec_node_complete_child(const struct ec_node *node,
67 const struct ec_strvec *strvec);
70 * Create a completion object (list of completion items).
74 struct ec_comp *ec_comp(struct ec_parse *state);
77 * Free a completion object and all its items.
81 void ec_comp_free(struct ec_comp *comp);
88 void ec_comp_dump(FILE *out,
89 const struct ec_comp *comp);
92 * Merge items contained in 'from' into 'to'
94 * The 'from' comp struct is freed.
96 int ec_comp_merge(struct ec_comp *to,
97 struct ec_comp *from);
99 struct ec_parse *ec_comp_get_state(struct ec_comp *comp);
101 /* shortcut for ec_comp_item() + ec_comp_item_add() */
102 int ec_comp_add_item(struct ec_comp *comp,
103 const struct ec_node *node,
104 struct ec_comp_item **p_item,
105 enum ec_comp_type type,
106 const char *start, const char *full);
111 int ec_comp_item_set_str(struct ec_comp_item *item,
115 * Get the string value of a completion item.
120 ec_comp_item_get_str(const struct ec_comp_item *item);
123 * Get the display string value of a completion item.
128 ec_comp_item_get_display(const struct ec_comp_item *item);
131 * Get the completion string value of a completion item.
136 ec_comp_item_get_completion(const struct ec_comp_item *item);
139 * Get the group of a completion item.
143 const struct ec_comp_group *
144 ec_comp_item_get_grp(const struct ec_comp_item *item);
147 * Get the type of a completion item.
152 ec_comp_item_get_type(const struct ec_comp_item *item);
155 * Get the node associated to a completion item.
159 const struct ec_node *
160 ec_comp_item_get_node(const struct ec_comp_item *item);
163 * Set the display value of an item.
167 int ec_comp_item_set_display(struct ec_comp_item *item,
168 const char *display);
171 * Set the completion value of an item.
175 int ec_comp_item_set_completion(struct ec_comp_item *item,
176 const char *completion);
184 ec_node_complete_unknown(const struct ec_node *gen_node,
185 struct ec_comp *comp,
186 const struct ec_strvec *strvec);
193 unsigned int ec_comp_count(
194 const struct ec_comp *comp,
195 enum ec_comp_type flags);
202 struct ec_comp_iter {
203 enum ec_comp_type type;
204 struct ec_comp *comp;
205 struct ec_comp_group *cur_node;
206 struct ec_comp_item *cur_match;
214 struct ec_comp_iter *
215 ec_comp_iter(struct ec_comp *comp,
216 enum ec_comp_type type);
223 struct ec_comp_item *ec_comp_iter_next(
224 struct ec_comp_iter *iter);
231 void ec_comp_iter_free(struct ec_comp_iter *iter);