-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcligen_handle.h
More file actions
261 lines (205 loc) · 10.1 KB
/
cligen_handle.h
File metadata and controls
261 lines (205 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2001-2022 Olof Hagsand
This file is part of CLIgen.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 2 or later (the "GPL"),
in which case the provisions of the GPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of the GPL, and not to allow others to
use your version of this file under the terms of Apache License version 2, indicate
your decision by deleting the provisions above and replace them with the
notice and other provisions required by the GPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the Apache License version 2 or the GPL.
***** END LICENSE BLOCK *****
*/
#ifndef _CLIGEN_HANDLE_H_
#define _CLIGEN_HANDLE_H_
/*
* Constants
*/
#define CLIGEN_PROMPT_DEFAULT "cli> "
#define TERM_MIN_SCREEN_WIDTH 21 /* hardcoded by getline */
#define CLIGEN_HISTSIZE_DEFAULT 100 /* default size of cli history (lines) */
/* OR CLIGEN_TABMODE_* using cligen_tabmode_set() */
/* Show columns info: 0: short/ios mode, 1: long/junos mode */
#define CLIGEN_TABMODE_COLUMNS 0x01
/* Command keyword preference over variables:
* 0: command completion preference,
* 1: same preference for vars
*/
#define CLIGEN_TABMODE_VARS 0x02
/* Steps to complete
* 0: complete single step. 1: complete all steps at once
*/
#define CLIGEN_TABMODE_STEPS 0x04
/* Dont show alternatives after completion
* 0: Dont 1: show alternatives / help after completion
*/
#define CLIGEN_TABMODE_SHOW 0x08
/*
* Types
*/
/*! CLIgen eval wrap function to check state before and after a callback function
*
* @param[in] arg Argument to wrap function
* @param[in] wh Wrap handle. If NULL: init, othewise compare present state with wh
* @param[in] name A name for logging
* @param[in] fn A function name for loggin
* @retval 1 OK
* @retval 0 Fail (for info only, cligen_eval does not handle fails)
* @retval -1 Error
* @code
* void *wh = NULL;
* cligen_eval_wrap_cb(h, &wh, "myfn", __FUNCTION__);
* .. User callback
* cligen_eval_wrap_cb(h, &wh, "myfn", __FUNCTION__);
* See cligen_eval
*/
typedef int (cligen_eval_wrap_fn)(void *arg, void **wh, const char *name, const char *fn);
/*! CLIgen wrap function for making treeref lookup
*
* This adds an indirection based on name and context
* @param[in] h CLIgen handle
* @param[in] name Base tree name
* @param[in] cvt Tokenized string: vector of tokens providing some context
* @param[in] arg Argument given when registering wrap function (maybe not needed?)
* @param[out] namep New (malloced) name or NULL if use original "name"
* @retval 0 OK
* @retval -1 Error
*/
typedef int (cligen_tree_resolve_wrapper_fn)(cligen_handle h, const char *name, cvec *cvt, void *arg, char **namep);
/*! CLIgen history callback function, each added command makes a callback
*
* Could be used for logging all CLI commands for example, or just mirroring the history file
* Note this is not exactly the same as the history command file, which filters equal commands.
* @param[in] h CLIgen handle
* @param[in] cmd Input string as entered by user (potentially abbreviated)
* @param[in] cmd_expanded Expanded/completed command string (all keywords spelled out)
* @param[in] arg Callback argument
* @retval 0 OK
* @retval -1 Error
*/
typedef int (cligen_hist_fn)(cligen_handle h, const char *cmd, const char *cmd_expanded, void *arg);
/*! CLIgen node filter callback: called for each candidate node during expand/completion
*
* Called just before a node is added to the expansion result. The callback may
* set *skip=1 to exclude the node from completions (e.g. for NACM filtering).
* @param[in] h CLIgen handle
* @param[in] co Candidate cligen object being considered for inclusion
* @param[in] cvv Accumulated matched tokens so far.
* CO_COMMAND entries have cv_const=1 and cv_name==cv_value (YANG node names).
* CO_VARIABLE entries have cv_name=variable name, cv_value=user input.
* @param[in] arg Argument provided at registration time
* @param[out] skip Set to 1 to exclude this node from completions
* @retval 0 OK
* @retval -1 Error
*/
typedef int (cligen_node_filter_fn)(cligen_handle h, cg_obj *co, cvec *cvv, void *arg, int *skip);
/*! Callback type: determine CO_FLAGS_TREEREF propagation during tree-reference expansion
*
* Called by CLIgen for each CO_REFERENCE encountered during expansion.
* The callback decides what flags to OR onto every copy produced within
* the expansion of tree @treename (and transitively into nested expansions).
* @param[in] h CLIgen handle
* @param[in] treename Name of tree being expanded (co_command, '@' already stripped)
* @param[in] inherit Flags propagated from the enclosing expansion (0 at top level)
* @param[out] flagsp Flags to OR onto all copies within this expansion
* @retval 0 OK
* @retval -1 Error
*/
typedef int (cligen_treeref_flags_fn)(cligen_handle h, const char *treename, uint32_t inherit, uint32_t *flagsp);
/*
* Prototypes
*/
cligen_handle cligen_init(void);
int cligen_exit(cligen_handle);
int cligen_check(cligen_handle h);
int cligen_exiting(cligen_handle h);
int cligen_exiting_set(cligen_handle h, int status);
char cligen_comment(cligen_handle h);
int cligen_comment_set(cligen_handle h, char c);
char* cligen_prompt(cligen_handle h);
int cligen_prompt_set(cligen_handle h, const char *prompt);
pt_head *cligen_pt_head_get(cligen_handle h);
int cligen_pt_head_set(cligen_handle h, pt_head *ph);
pt_head *cligen_pt_head_active_get(cligen_handle h);
int cligen_pt_head_active_set(cligen_handle h, pt_head *ph);
char *cligen_treename_keyword(cligen_handle h);
int cligen_treename_keyword_set(cligen_handle h, const char *name);
/* After an evaluation (callback), which node in the parse-tree? */
cg_obj *cligen_co_match(cligen_handle h);
int cligen_co_match_set(cligen_handle h, cg_obj *co);
cvec *cligen_callback_arguments_get(cligen_handle h);
int cligen_callback_arguments_set(cligen_handle h, cvec *args);
char *cligen_fn_str_get(cligen_handle h);
int cligen_fn_str_set(cligen_handle h, const char *fn_str);
int cligen_spipe_get(cligen_handle h);
int cligen_spipe_set(cligen_handle h, int s);
int cligen_terminal_rows(cligen_handle h);
int cligen_terminal_rows_set(cligen_handle h, int rows);
int cligen_paging_get(cligen_handle h);
int cligen_paging_set(cligen_handle h, int state);
int cligen_terminal_width(cligen_handle h);
int cligen_terminal_width_set(cligen_handle h, int length);
int cligen_utf8_get(cligen_handle h);
int cligen_utf8_set(cligen_handle h, int mode);
int cligen_line_scrolling(cligen_handle h);
int cligen_line_scrolling_set(cligen_handle h, int mode);
int cligen_helpstring_truncate(cligen_handle h);
int cligen_helpstring_truncate_set(cligen_handle h, int mode);
int cligen_helpstring_lines(cligen_handle h);
int cligen_helpstring_lines_set(cligen_handle h, int lines);
int cligen_tabmode(cligen_handle h);
int cligen_tabmode_set(cligen_handle h, int mode);
char *cligen_killbuf(cligen_handle h);
char *cligen_buf(cligen_handle h);
int cligen_buf_size(cligen_handle h);
int cligen_killbuf_size(cligen_handle h);
int cligen_buf_init(cligen_handle h);
int cligen_buf_cleanup(cligen_handle h);
int cligen_buf_increase(cligen_handle h, size_t size);
int cligen_killbuf_increase(cligen_handle h, size_t size);
/* hack */
int cligen_parsetree_expand(cligen_handle h, parse_tree ***pt, int **e_len, int **e_i);
int cligen_lexicalorder(cligen_handle h);
int cligen_lexicalorder_set(cligen_handle h, int n);
int cligen_ignorecase(cligen_handle h);
int cligen_ignorecase_set(cligen_handle h, int n);
int cligen_logsyntax(cligen_handle h);
int cligen_logsyntax_set(cligen_handle h, int n);
int cligen_hist_fn_set(cligen_handle h, cligen_hist_fn *fn, void *arg);
int cligen_hist_fn_get(cligen_handle h, cligen_hist_fn **fn, void **arg);
void *cligen_userhandle(cligen_handle h);
int cligen_userhandle_set(cligen_handle h, void *userhandle);
int cligen_regex_xsd(cligen_handle h);
int cligen_regex_xsd_set(cligen_handle h, int mode);
char cligen_delimiter(cligen_handle h);
int cligen_delimiter_set(cligen_handle h, char delimiter);
int cligen_preference_mode(cligen_handle h);
int cligen_preference_mode_set(cligen_handle h, int flag);
int cligen_caseignore_get(cligen_handle h);
int cligen_caseignore_set(cligen_handle h, int ignorecase);
int cligen_expand_first_get(cligen_handle h);
int cligen_expand_first_set(cligen_handle h, int cvv0expand);
int cligen_exclude_keys_set(cligen_handle h, int status);
int cligen_exclude_keys_get(cligen_handle h);
int cligen_eval_wrap_fn_set(cligen_handle h, cligen_eval_wrap_fn *fn, void *arg);
int cligen_eval_wrap_fn_get(cligen_handle h, cligen_eval_wrap_fn **fn, void **arg);
int cligen_tree_resolve_wrapper_set(cligen_handle h, cligen_tree_resolve_wrapper_fn *fn, void *arg);
int cligen_tree_resolve_wrapper_get(cligen_handle h, cligen_tree_resolve_wrapper_fn **fn, void **arg);
int cligen_node_filter_set(cligen_handle h, cligen_node_filter_fn *fn, void *arg);
int cligen_node_filter_get(cligen_handle h, cligen_node_filter_fn **fn, void **arg);
int cligen_treeref_flags_fn_set(cligen_handle h, cligen_treeref_flags_fn *fn);
int cligen_treeref_flags_fn_get(cligen_handle h, cligen_treeref_flags_fn **fn);
#endif /* _CLIGEN_HANDLE_H_ */