2 * Copyright (c) 2016, Olivier MATZ <zer0@droids-corp.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University of California, Berkeley nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * API for generating completions item on a node.
31 * This file provide helpers to list and manipulate the possible
32 * completions for a given input.
34 * XXX completed vs item
37 #ifndef ECOLI_COMPLETED_
38 #define ECOLI_COMPLETED_
40 #include <sys/queue.h>
41 #include <sys/types.h>
46 enum ec_completed_type {
47 EC_COMP_UNKNOWN = 0x1,
49 EC_COMP_PARTIAL = 0x4,
53 struct ec_completed_item;
55 TAILQ_HEAD(ec_completed_item_list, ec_completed_item);
57 struct ec_completed_group {
58 TAILQ_ENTRY(ec_completed_group) next;
59 const struct ec_node *node;
60 struct ec_completed_item_list items;
61 struct ec_parsed *state;
62 struct ec_keyval *attrs;
65 TAILQ_HEAD(ec_completed_group_list, ec_completed_group);
70 struct ec_parsed *cur_state;
71 struct ec_completed_group *cur_group;
72 struct ec_completed_group_list groups;
73 struct ec_keyval *attrs;
77 * return a completed object filled with items
78 * return NULL on error (nomem?)
80 struct ec_completed *ec_node_complete(struct ec_node *node,
82 struct ec_completed *ec_node_complete_strvec(struct ec_node *node,
83 const struct ec_strvec *strvec);
85 /* internal: used by nodes */
86 int ec_node_complete_child(struct ec_node *node,
87 struct ec_completed *completed,
88 const struct ec_strvec *strvec);
91 * Create a completion object (list of completion items).
95 struct ec_completed *ec_completed(struct ec_parsed *state);
98 * Free a completion object and all its items.
102 void ec_completed_free(struct ec_completed *completed);
109 void ec_completed_dump(FILE *out,
110 const struct ec_completed *completed);
113 * Merge items contained in 'from' into 'to'
115 * The 'from' completed struct is freed.
117 int ec_completed_merge(struct ec_completed *to,
118 struct ec_completed *from);
120 struct ec_parsed *ec_completed_get_state(struct ec_completed *completed);
122 /* shortcut for ec_completed_item() + ec_completed_item_add() */
123 int ec_completed_add_item(struct ec_completed *completed,
124 const struct ec_node *node,
125 struct ec_completed_item **p_item,
126 enum ec_completed_type type,
127 const char *start, const char *full);
132 int ec_completed_item_set_str(struct ec_completed_item *item,
136 * Get the string value of a completion item.
141 ec_completed_item_get_str(const struct ec_completed_item *item);
144 * Get the display string value of a completion item.
149 ec_completed_item_get_display(const struct ec_completed_item *item);
152 * Get the completion string value of a completion item.
157 ec_completed_item_get_completion(const struct ec_completed_item *item);
160 * Get the group of a completion item.
164 const struct ec_completed_group *
165 ec_completed_item_get_grp(const struct ec_completed_item *item);
168 * Get the type of a completion item.
172 enum ec_completed_type
173 ec_completed_item_get_type(const struct ec_completed_item *item);
176 * Get the node associated to a completion item.
180 const struct ec_node *
181 ec_completed_item_get_node(const struct ec_completed_item *item);
184 * Set the display value of an item.
188 int ec_completed_item_set_display(struct ec_completed_item *item,
189 const char *display);
192 * Set the completion value of an item.
196 int ec_completed_item_set_completion(struct ec_completed_item *item,
197 const char *completion);
205 ec_node_default_complete(const struct ec_node *gen_node,
206 struct ec_completed *completed,
207 const struct ec_strvec *strvec);
214 unsigned int ec_completed_count(
215 const struct ec_completed *completed,
216 enum ec_completed_type flags);
223 struct ec_completed_iter {
224 enum ec_completed_type type;
225 struct ec_completed *completed;
226 struct ec_completed_group *cur_node;
227 struct ec_completed_item *cur_match;
235 struct ec_completed_iter *
236 ec_completed_iter(struct ec_completed *completed,
237 enum ec_completed_type type);
244 struct ec_completed_item *ec_completed_iter_next(
245 struct ec_completed_iter *iter);
252 void ec_completed_iter_free(struct ec_completed_iter *iter);