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.
11 * XXX completed vs item
14 #ifndef ECOLI_COMPLETED_
15 #define ECOLI_COMPLETED_
17 #include <sys/queue.h>
18 #include <sys/types.h>
23 enum ec_completed_type {
24 EC_COMP_UNKNOWN = 0x1,
26 EC_COMP_PARTIAL = 0x4,
30 struct ec_completed_item;
32 TAILQ_HEAD(ec_completed_item_list, ec_completed_item);
34 struct ec_completed_group {
35 TAILQ_ENTRY(ec_completed_group) next;
36 const struct ec_node *node;
37 struct ec_completed_item_list items;
38 struct ec_parsed *state;
39 struct ec_keyval *attrs;
42 TAILQ_HEAD(ec_completed_group_list, ec_completed_group);
47 unsigned count_partial;
48 unsigned count_unknown;
49 struct ec_parsed *cur_state;
50 struct ec_completed_group *cur_group;
51 struct ec_completed_group_list groups;
52 struct ec_keyval *attrs;
56 * return a completed object filled with items
57 * return NULL on error (nomem?)
59 struct ec_completed *ec_node_complete(const struct ec_node *node,
61 struct ec_completed *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,
66 struct ec_completed *completed,
67 const struct ec_strvec *strvec);
70 * Create a completion object (list of completion items).
74 struct ec_completed *ec_completed(struct ec_parsed *state);
77 * Free a completion object and all its items.
81 void ec_completed_free(struct ec_completed *completed);
88 void ec_completed_dump(FILE *out,
89 const struct ec_completed *completed);
92 * Merge items contained in 'from' into 'to'
94 * The 'from' completed struct is freed.
96 int ec_completed_merge(struct ec_completed *to,
97 struct ec_completed *from);
99 struct ec_parsed *ec_completed_get_state(struct ec_completed *completed);
101 /* shortcut for ec_completed_item() + ec_completed_item_add() */
102 int ec_completed_add_item(struct ec_completed *completed,
103 const struct ec_node *node,
104 struct ec_completed_item **p_item,
105 enum ec_completed_type type,
106 const char *start, const char *full);
111 int ec_completed_item_set_str(struct ec_completed_item *item,
115 * Get the string value of a completion item.
120 ec_completed_item_get_str(const struct ec_completed_item *item);
123 * Get the display string value of a completion item.
128 ec_completed_item_get_display(const struct ec_completed_item *item);
131 * Get the completion string value of a completion item.
136 ec_completed_item_get_completion(const struct ec_completed_item *item);
139 * Get the group of a completion item.
143 const struct ec_completed_group *
144 ec_completed_item_get_grp(const struct ec_completed_item *item);
147 * Get the type of a completion item.
151 enum ec_completed_type
152 ec_completed_item_get_type(const struct ec_completed_item *item);
155 * Get the node associated to a completion item.
159 const struct ec_node *
160 ec_completed_item_get_node(const struct ec_completed_item *item);
163 * Set the display value of an item.
167 int ec_completed_item_set_display(struct ec_completed_item *item,
168 const char *display);
171 * Set the completion value of an item.
175 int ec_completed_item_set_completion(struct ec_completed_item *item,
176 const char *completion);
184 ec_node_default_complete(const struct ec_node *gen_node,
185 struct ec_completed *completed,
186 const struct ec_strvec *strvec);
193 unsigned int ec_completed_count(
194 const struct ec_completed *completed,
195 enum ec_completed_type flags);
202 struct ec_completed_iter {
203 enum ec_completed_type type;
204 struct ec_completed *completed;
205 struct ec_completed_group *cur_node;
206 struct ec_completed_item *cur_match;
214 struct ec_completed_iter *
215 ec_completed_iter(struct ec_completed *completed,
216 enum ec_completed_type type);
223 struct ec_completed_item *ec_completed_iter_next(
224 struct ec_completed_iter *iter);
231 void ec_completed_iter_free(struct ec_completed_iter *iter);