1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
6 * @defgroup complete Complete
9 * @brief Complete string input using a grammar tree
11 * This file provide helpers to list and manipulate the possible
12 * completions for a given input.
19 #ifndef ECOLI_COMPLETE_
20 #define ECOLI_COMPLETE_
22 #include <sys/queue.h>
23 #include <sys/types.h>
28 enum ec_comp_type { /* XXX should be a define */
29 EC_COMP_UNKNOWN = 0x1,
31 EC_COMP_PARTIAL = 0x4,
40 * return a comp object filled with items
41 * return NULL on error (nomem?)
43 struct ec_comp *ec_node_complete(const struct ec_node *node,
45 struct ec_comp *ec_node_complete_strvec(const struct ec_node *node,
46 const struct ec_strvec *strvec);
48 /* internal: used by nodes */
49 int ec_node_complete_child(const struct ec_node *node,
51 const struct ec_strvec *strvec);
54 * Create a completion object (list of completion items).
58 struct ec_comp *ec_comp(struct ec_parse *state);
61 * Free a completion object and all its items.
65 void ec_comp_free(struct ec_comp *comp);
72 void ec_comp_dump(FILE *out,
73 const struct ec_comp *comp);
76 * Merge items contained in 'from' into 'to'
78 * The 'from' comp struct is freed.
80 int ec_comp_merge(struct ec_comp *to,
81 struct ec_comp *from);
84 * Get current completion state.
87 struct ec_parse *ec_comp_get_state(const struct ec_comp *comp);
90 * Get current completion group.
93 struct ec_comp_group *ec_comp_get_group(const struct ec_comp *comp);
96 * Get completion group attributes.
99 struct ec_dict *ec_comp_get_attrs(const 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);
179 * Get the completion group node.
183 const struct ec_node *
184 ec_comp_group_get_node(const struct ec_comp_group *grp);
187 * Get the completion group parsed state.
191 const struct ec_parse *
192 ec_comp_group_get_state(const struct ec_comp_group *grp);
195 * Get the completion group attributes.
199 const struct ec_dict *
200 ec_comp_group_get_attrs(const struct ec_comp_group *grp);
209 ec_node_complete_unknown(const struct ec_node *gen_node,
210 struct ec_comp *comp,
211 const struct ec_strvec *strvec);
218 unsigned int ec_comp_count(
219 const struct ec_comp *comp,
220 enum ec_comp_type flags);
227 struct ec_comp_iter {
228 enum ec_comp_type type;
229 const struct ec_comp *comp;
230 struct ec_comp_group *cur_node;
231 struct ec_comp_item *cur_match;
239 struct ec_comp_iter *
240 ec_comp_iter(const struct ec_comp *comp,
241 enum ec_comp_type type);
248 struct ec_comp_item *ec_comp_iter_next(
249 struct ec_comp_iter *iter);
256 void ec_comp_iter_free(struct ec_comp_iter *iter);