Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Handle lists of commands, their decoding and documentation, for GDB. |
8926118c | 2 | |
b811d2c2 | 3 | Copyright (C) 1986-2020 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b JM |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 7 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 8 | (at your option) any later version. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
c906108c | 14 | |
c5aa993b | 15 | You should have received a copy of the GNU General Public License |
a9762ec7 | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
17 | |
18 | #include "defs.h" | |
c906108c | 19 | #include "symtab.h" |
c906108c | 20 | #include <ctype.h> |
f77b92bf | 21 | #include "gdb_regex.h" |
f397e303 | 22 | #include "completer.h" |
8b93c638 | 23 | #include "ui-out.h" |
d318976c FN |
24 | #include "cli/cli-cmds.h" |
25 | #include "cli/cli-decode.h" | |
66d8c862 | 26 | #include "cli/cli-style.h" |
268a13a5 | 27 | #include "gdbsupport/gdb_optional.h" |
b2875cc0 | 28 | |
ebcd3b23 | 29 | /* Prototypes for local functions. */ |
c906108c | 30 | |
6f937416 | 31 | static void undef_cmd_error (const char *, const char *); |
c906108c | 32 | |
6f937416 | 33 | static struct cmd_list_element *delete_cmd (const char *name, |
fad6eecd TT |
34 | struct cmd_list_element **list, |
35 | struct cmd_list_element **prehook, | |
36 | struct cmd_list_element **prehookee, | |
37 | struct cmd_list_element **posthook, | |
38 | struct cmd_list_element **posthookee); | |
b05dcbb7 | 39 | |
6f937416 | 40 | static struct cmd_list_element *find_cmd (const char *command, |
a14ed312 KB |
41 | int len, |
42 | struct cmd_list_element *clist, | |
43 | int ignore_help_classes, | |
44 | int *nfound); | |
6837a0a2 | 45 | |
c85871a3 | 46 | static void help_all (struct ui_file *stream); |
6e381ba0 | 47 | |
5b9afe8a YQ |
48 | /* Look up a command whose 'prefixlist' is KEY. Return the command if found, |
49 | otherwise return NULL. */ | |
50 | ||
51 | static struct cmd_list_element * | |
52 | lookup_cmd_for_prefixlist (struct cmd_list_element **key, | |
53 | struct cmd_list_element *list) | |
54 | { | |
55 | struct cmd_list_element *p = NULL; | |
56 | ||
57 | for (p = list; p != NULL; p = p->next) | |
58 | { | |
59 | struct cmd_list_element *q; | |
60 | ||
61 | if (p->prefixlist == NULL) | |
62 | continue; | |
63 | else if (p->prefixlist == key) | |
64 | return p; | |
65 | ||
66 | q = lookup_cmd_for_prefixlist (key, *(p->prefixlist)); | |
67 | if (q != NULL) | |
68 | return q; | |
69 | } | |
70 | ||
71 | return NULL; | |
72 | } | |
73 | ||
74 | static void | |
75 | set_cmd_prefix (struct cmd_list_element *c, struct cmd_list_element **list) | |
76 | { | |
77 | struct cmd_list_element *p; | |
78 | ||
79 | /* Check to see if *LIST contains any element other than C. */ | |
80 | for (p = *list; p != NULL; p = p->next) | |
81 | if (p != c) | |
82 | break; | |
83 | ||
84 | if (p == NULL) | |
85 | { | |
86 | /* *SET_LIST only contains SET. */ | |
87 | p = lookup_cmd_for_prefixlist (list, setlist); | |
88 | ||
89 | c->prefix = p ? (p->cmd_pointer ? p->cmd_pointer : p) : p; | |
90 | } | |
91 | else | |
92 | c->prefix = p->prefix; | |
93 | } | |
94 | ||
6e381ba0 | 95 | static void |
64e61d29 TT |
96 | print_help_for_command (struct cmd_list_element *c, const char *prefix, |
97 | int recurse, struct ui_file *stream); | |
6e381ba0 | 98 | |
d318976c | 99 | \f |
9f60d481 AC |
100 | /* Set the callback function for the specified command. For each both |
101 | the commands callback and func() are set. The latter set to a | |
102 | bounce function (unless cfunc / sfunc is NULL that is). */ | |
103 | ||
0450cc4c | 104 | static void |
95a6b0a1 | 105 | do_const_cfunc (struct cmd_list_element *c, const char *args, int from_tty) |
0450cc4c TT |
106 | { |
107 | c->function.const_cfunc (args, from_tty); | |
108 | } | |
109 | ||
c2252c0d | 110 | static void |
0450cc4c TT |
111 | set_cmd_cfunc (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc) |
112 | { | |
113 | if (cfunc == NULL) | |
114 | cmd->func = NULL; | |
115 | else | |
116 | cmd->func = do_const_cfunc; | |
117 | cmd->function.const_cfunc = cfunc; | |
9f60d481 AC |
118 | } |
119 | ||
120 | static void | |
95a6b0a1 | 121 | do_sfunc (struct cmd_list_element *c, const char *args, int from_tty) |
9f60d481 | 122 | { |
0450cc4c | 123 | c->function.sfunc (args, from_tty, c); |
9f60d481 AC |
124 | } |
125 | ||
126 | void | |
eb4c3f4a | 127 | set_cmd_sfunc (struct cmd_list_element *cmd, cmd_const_sfunc_ftype *sfunc) |
9f60d481 AC |
128 | { |
129 | if (sfunc == NULL) | |
130 | cmd->func = NULL; | |
131 | else | |
132 | cmd->func = do_sfunc; | |
0450cc4c | 133 | cmd->function.sfunc = sfunc; |
9f60d481 AC |
134 | } |
135 | ||
0450cc4c TT |
136 | int |
137 | cmd_cfunc_eq (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc) | |
138 | { | |
139 | return cmd->func == do_const_cfunc && cmd->function.const_cfunc == cfunc; | |
140 | } | |
141 | ||
7d0766f3 AC |
142 | void |
143 | set_cmd_context (struct cmd_list_element *cmd, void *context) | |
144 | { | |
145 | cmd->context = context; | |
146 | } | |
147 | ||
148 | void * | |
149 | get_cmd_context (struct cmd_list_element *cmd) | |
150 | { | |
151 | return cmd->context; | |
152 | } | |
153 | ||
1868c04e AC |
154 | enum cmd_types |
155 | cmd_type (struct cmd_list_element *cmd) | |
156 | { | |
157 | return cmd->type; | |
158 | } | |
159 | ||
5ba2abeb | 160 | void |
625e8578 | 161 | set_cmd_completer (struct cmd_list_element *cmd, completer_ftype *completer) |
5ba2abeb AC |
162 | { |
163 | cmd->completer = completer; /* Ok. */ | |
164 | } | |
165 | ||
7d793aa9 SDJ |
166 | /* See definition in commands.h. */ |
167 | ||
168 | void | |
169 | set_cmd_completer_handle_brkchars (struct cmd_list_element *cmd, | |
6e1dbf8c | 170 | completer_handle_brkchars_ftype *func) |
7d793aa9 | 171 | { |
6e1dbf8c | 172 | cmd->completer_handle_brkchars = func; |
7d793aa9 SDJ |
173 | } |
174 | ||
c906108c | 175 | /* Add element named NAME. |
bc587a6b | 176 | Space for NAME and DOC must be allocated by the caller. |
c906108c SS |
177 | CLASS is the top level category into which commands are broken down |
178 | for "help" purposes. | |
179 | FUN should be the function to execute the command; | |
180 | it will get a character string as argument, with leading | |
181 | and trailing blanks already eliminated. | |
182 | ||
183 | DOC is a documentation string for the command. | |
184 | Its first line should be a complete sentence. | |
185 | It should start with ? for a command that is an abbreviation | |
186 | or with * for a command that most users don't need to know about. | |
187 | ||
ebcd3b23 | 188 | Add this command to command list *LIST. |
c906108c SS |
189 | |
190 | Returns a pointer to the added command (not necessarily the head | |
ebcd3b23 | 191 | of *LIST). */ |
c906108c | 192 | |
0450cc4c TT |
193 | static struct cmd_list_element * |
194 | do_add_cmd (const char *name, enum command_class theclass, | |
195 | const char *doc, struct cmd_list_element **list) | |
c906108c | 196 | { |
e2fc72e2 TT |
197 | struct cmd_list_element *c = new struct cmd_list_element (name, theclass, |
198 | doc); | |
b05dcbb7 | 199 | struct cmd_list_element *p, *iter; |
c906108c | 200 | |
b05dcbb7 TT |
201 | /* Turn each alias of the old command into an alias of the new |
202 | command. */ | |
fad6eecd TT |
203 | c->aliases = delete_cmd (name, list, &c->hook_pre, &c->hookee_pre, |
204 | &c->hook_post, &c->hookee_post); | |
b05dcbb7 TT |
205 | for (iter = c->aliases; iter; iter = iter->alias_chain) |
206 | iter->cmd_pointer = c; | |
fad6eecd TT |
207 | if (c->hook_pre) |
208 | c->hook_pre->hookee_pre = c; | |
209 | if (c->hookee_pre) | |
210 | c->hookee_pre->hook_pre = c; | |
211 | if (c->hook_post) | |
212 | c->hook_post->hookee_post = c; | |
213 | if (c->hookee_post) | |
214 | c->hookee_post->hook_post = c; | |
c906108c | 215 | |
494b7ec9 | 216 | if (*list == NULL || strcmp ((*list)->name, name) >= 0) |
c906108c SS |
217 | { |
218 | c->next = *list; | |
219 | *list = c; | |
220 | } | |
221 | else | |
222 | { | |
223 | p = *list; | |
494b7ec9 | 224 | while (p->next && strcmp (p->next->name, name) <= 0) |
c5aa993b JM |
225 | { |
226 | p = p->next; | |
227 | } | |
c906108c SS |
228 | c->next = p->next; |
229 | p->next = c; | |
230 | } | |
231 | ||
c906108c SS |
232 | return c; |
233 | } | |
234 | ||
0450cc4c TT |
235 | struct cmd_list_element * |
236 | add_cmd (const char *name, enum command_class theclass, | |
237 | const char *doc, struct cmd_list_element **list) | |
238 | { | |
239 | cmd_list_element *result = do_add_cmd (name, theclass, doc, list); | |
240 | result->func = NULL; | |
5fed81ff | 241 | result->function.const_cfunc = NULL; |
0450cc4c TT |
242 | return result; |
243 | } | |
244 | ||
245 | struct cmd_list_element * | |
246 | add_cmd (const char *name, enum command_class theclass, | |
247 | cmd_const_cfunc_ftype *fun, | |
248 | const char *doc, struct cmd_list_element **list) | |
249 | { | |
250 | cmd_list_element *result = do_add_cmd (name, theclass, doc, list); | |
251 | set_cmd_cfunc (result, fun); | |
252 | return result; | |
253 | } | |
254 | ||
f67ffa6a AB |
255 | /* Add an element with a suppress notification to the LIST of commands. */ |
256 | ||
257 | struct cmd_list_element * | |
258 | add_cmd_suppress_notification (const char *name, enum command_class theclass, | |
259 | cmd_const_cfunc_ftype *fun, const char *doc, | |
260 | struct cmd_list_element **list, | |
261 | int *suppress_notification) | |
262 | { | |
263 | struct cmd_list_element *element; | |
264 | ||
265 | element = add_cmd (name, theclass, fun, doc, list); | |
266 | element->suppress_notification = suppress_notification; | |
267 | ||
268 | return element; | |
269 | } | |
270 | ||
271 | ||
56382845 | 272 | /* Deprecates a command CMD. |
ebcd3b23 MS |
273 | REPLACEMENT is the name of the command which should be used in |
274 | place of this command, or NULL if no such command exists. | |
56382845 FN |
275 | |
276 | This function does not check to see if command REPLACEMENT exists | |
ebcd3b23 MS |
277 | since gdb may not have gotten around to adding REPLACEMENT when |
278 | this function is called. | |
56382845 FN |
279 | |
280 | Returns a pointer to the deprecated command. */ | |
281 | ||
282 | struct cmd_list_element * | |
429e55ea | 283 | deprecate_cmd (struct cmd_list_element *cmd, const char *replacement) |
56382845 | 284 | { |
1f2bdf09 TT |
285 | cmd->cmd_deprecated = 1; |
286 | cmd->deprecated_warn_user = 1; | |
56382845 FN |
287 | |
288 | if (replacement != NULL) | |
289 | cmd->replacement = replacement; | |
290 | else | |
291 | cmd->replacement = NULL; | |
292 | ||
293 | return cmd; | |
294 | } | |
295 | ||
c906108c | 296 | struct cmd_list_element * |
21873064 YQ |
297 | add_alias_cmd (const char *name, cmd_list_element *old, |
298 | enum command_class theclass, int abbrev_flag, | |
299 | struct cmd_list_element **list) | |
c906108c | 300 | { |
c906108c SS |
301 | if (old == 0) |
302 | { | |
fad6eecd TT |
303 | struct cmd_list_element *prehook, *prehookee, *posthook, *posthookee; |
304 | struct cmd_list_element *aliases = delete_cmd (name, list, | |
305 | &prehook, &prehookee, | |
306 | &posthook, &posthookee); | |
cdb27c12 | 307 | |
b05dcbb7 | 308 | /* If this happens, it means a programmer error somewhere. */ |
300d0284 | 309 | gdb_assert (!aliases && !prehook && !prehookee |
fad6eecd | 310 | && !posthook && ! posthookee); |
c906108c SS |
311 | return 0; |
312 | } | |
313 | ||
0450cc4c | 314 | struct cmd_list_element *c = add_cmd (name, theclass, old->doc, list); |
5bc81a00 PM |
315 | |
316 | /* If OLD->DOC can be freed, we should make another copy. */ | |
1f2bdf09 | 317 | if (old->doc_allocated) |
5bc81a00 PM |
318 | { |
319 | c->doc = xstrdup (old->doc); | |
1f2bdf09 | 320 | c->doc_allocated = 1; |
5bc81a00 | 321 | } |
9f60d481 AC |
322 | /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */ |
323 | c->func = old->func; | |
324 | c->function = old->function; | |
c906108c SS |
325 | c->prefixlist = old->prefixlist; |
326 | c->prefixname = old->prefixname; | |
327 | c->allow_unknown = old->allow_unknown; | |
328 | c->abbrev_flag = abbrev_flag; | |
329 | c->cmd_pointer = old; | |
b05dcbb7 TT |
330 | c->alias_chain = old->aliases; |
331 | old->aliases = c; | |
5b9afe8a YQ |
332 | |
333 | set_cmd_prefix (c, list); | |
c906108c SS |
334 | return c; |
335 | } | |
336 | ||
21873064 YQ |
337 | struct cmd_list_element * |
338 | add_alias_cmd (const char *name, const char *oldname, | |
339 | enum command_class theclass, int abbrev_flag, | |
340 | struct cmd_list_element **list) | |
341 | { | |
342 | const char *tmp; | |
343 | struct cmd_list_element *old; | |
344 | ||
345 | tmp = oldname; | |
346 | old = lookup_cmd (&tmp, *list, "", 1, 1); | |
347 | ||
348 | return add_alias_cmd (name, old, theclass, abbrev_flag, list); | |
349 | } | |
350 | ||
351 | ||
ebcd3b23 MS |
352 | /* Like add_cmd but adds an element for a command prefix: a name that |
353 | should be followed by a subcommand to be looked up in another | |
354 | command list. PREFIXLIST should be the address of the variable | |
355 | containing that list. */ | |
c906108c SS |
356 | |
357 | struct cmd_list_element * | |
fe978cb0 | 358 | add_prefix_cmd (const char *name, enum command_class theclass, |
981a3fb3 | 359 | cmd_const_cfunc_ftype *fun, |
1947513d | 360 | const char *doc, struct cmd_list_element **prefixlist, |
64e61d29 | 361 | const char *prefixname, int allow_unknown, |
af1c1752 | 362 | struct cmd_list_element **list) |
c906108c | 363 | { |
fe978cb0 | 364 | struct cmd_list_element *c = add_cmd (name, theclass, fun, doc, list); |
5b9afe8a | 365 | struct cmd_list_element *p; |
cdb27c12 | 366 | |
c906108c SS |
367 | c->prefixlist = prefixlist; |
368 | c->prefixname = prefixname; | |
369 | c->allow_unknown = allow_unknown; | |
5b9afe8a YQ |
370 | |
371 | if (list == &cmdlist) | |
372 | c->prefix = NULL; | |
373 | else | |
374 | set_cmd_prefix (c, list); | |
375 | ||
376 | /* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */ | |
377 | for (p = *prefixlist; p != NULL; p = p->next) | |
378 | p->prefix = c; | |
379 | ||
c906108c SS |
380 | return c; |
381 | } | |
382 | ||
0743fc83 TT |
383 | /* A helper function for add_basic_prefix_cmd. This is a command |
384 | function that just forwards to help_list. */ | |
385 | ||
386 | static void | |
387 | do_prefix_cmd (const char *args, int from_tty, struct cmd_list_element *c) | |
388 | { | |
389 | /* Look past all aliases. */ | |
390 | while (c->cmd_pointer != nullptr) | |
391 | c = c->cmd_pointer; | |
392 | ||
393 | help_list (*c->prefixlist, c->prefixname, all_commands, gdb_stdout); | |
394 | } | |
395 | ||
396 | /* See command.h. */ | |
397 | ||
398 | struct cmd_list_element * | |
399 | add_basic_prefix_cmd (const char *name, enum command_class theclass, | |
400 | const char *doc, struct cmd_list_element **prefixlist, | |
401 | const char *prefixname, int allow_unknown, | |
402 | struct cmd_list_element **list) | |
403 | { | |
404 | struct cmd_list_element *cmd = add_prefix_cmd (name, theclass, nullptr, | |
405 | doc, prefixlist, prefixname, | |
406 | allow_unknown, list); | |
407 | set_cmd_sfunc (cmd, do_prefix_cmd); | |
408 | return cmd; | |
409 | } | |
410 | ||
411 | /* A helper function for add_show_prefix_cmd. This is a command | |
412 | function that just forwards to cmd_show_list. */ | |
413 | ||
414 | static void | |
415 | do_show_prefix_cmd (const char *args, int from_tty, struct cmd_list_element *c) | |
416 | { | |
417 | cmd_show_list (*c->prefixlist, from_tty, ""); | |
418 | } | |
419 | ||
420 | /* See command.h. */ | |
421 | ||
422 | struct cmd_list_element * | |
423 | add_show_prefix_cmd (const char *name, enum command_class theclass, | |
424 | const char *doc, struct cmd_list_element **prefixlist, | |
425 | const char *prefixname, int allow_unknown, | |
426 | struct cmd_list_element **list) | |
427 | { | |
428 | struct cmd_list_element *cmd = add_prefix_cmd (name, theclass, nullptr, | |
429 | doc, prefixlist, prefixname, | |
430 | allow_unknown, list); | |
431 | set_cmd_sfunc (cmd, do_show_prefix_cmd); | |
432 | return cmd; | |
433 | } | |
434 | ||
f67ffa6a AB |
435 | /* Like ADD_PREFIX_CMD but sets the suppress_notification pointer on the |
436 | new command list element. */ | |
437 | ||
438 | struct cmd_list_element * | |
439 | add_prefix_cmd_suppress_notification | |
440 | (const char *name, enum command_class theclass, | |
441 | cmd_const_cfunc_ftype *fun, | |
442 | const char *doc, struct cmd_list_element **prefixlist, | |
443 | const char *prefixname, int allow_unknown, | |
444 | struct cmd_list_element **list, | |
445 | int *suppress_notification) | |
446 | { | |
447 | struct cmd_list_element *element | |
448 | = add_prefix_cmd (name, theclass, fun, doc, prefixlist, | |
449 | prefixname, allow_unknown, list); | |
450 | element->suppress_notification = suppress_notification; | |
451 | return element; | |
452 | } | |
453 | ||
ebcd3b23 | 454 | /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */ |
c5aa993b | 455 | |
c906108c | 456 | struct cmd_list_element * |
fe978cb0 | 457 | add_abbrev_prefix_cmd (const char *name, enum command_class theclass, |
ee7ddd71 | 458 | cmd_const_cfunc_ftype *fun, const char *doc, |
64e61d29 TT |
459 | struct cmd_list_element **prefixlist, |
460 | const char *prefixname, | |
af1c1752 | 461 | int allow_unknown, struct cmd_list_element **list) |
c906108c | 462 | { |
fe978cb0 | 463 | struct cmd_list_element *c = add_cmd (name, theclass, fun, doc, list); |
cdb27c12 | 464 | |
c906108c SS |
465 | c->prefixlist = prefixlist; |
466 | c->prefixname = prefixname; | |
467 | c->allow_unknown = allow_unknown; | |
468 | c->abbrev_flag = 1; | |
469 | return c; | |
470 | } | |
471 | ||
472 | /* This is an empty "cfunc". */ | |
473 | void | |
eb7c454d | 474 | not_just_help_class_command (const char *args, int from_tty) |
c906108c SS |
475 | { |
476 | } | |
477 | ||
478 | /* This is an empty "sfunc". */ | |
c906108c SS |
479 | |
480 | static void | |
eb4c3f4a | 481 | empty_sfunc (const char *args, int from_tty, struct cmd_list_element *c) |
c906108c SS |
482 | { |
483 | } | |
484 | ||
b2875cc0 | 485 | /* Add element named NAME to command list LIST (the list for set/show |
c906108c | 486 | or some sublist thereof). |
b2875cc0 | 487 | TYPE is set_cmd or show_cmd. |
c906108c SS |
488 | CLASS is as in add_cmd. |
489 | VAR_TYPE is the kind of thing we are setting. | |
490 | VAR is address of the variable being controlled by this command. | |
491 | DOC is the documentation string. */ | |
492 | ||
b2875cc0 | 493 | static struct cmd_list_element * |
6f937416 | 494 | add_set_or_show_cmd (const char *name, |
b2875cc0 | 495 | enum cmd_types type, |
fe978cb0 | 496 | enum command_class theclass, |
b2875cc0 AC |
497 | var_types var_type, |
498 | void *var, | |
1947513d | 499 | const char *doc, |
b2875cc0 | 500 | struct cmd_list_element **list) |
c906108c | 501 | { |
0450cc4c | 502 | struct cmd_list_element *c = add_cmd (name, theclass, doc, list); |
cdb27c12 | 503 | |
b2875cc0 AC |
504 | gdb_assert (type == set_cmd || type == show_cmd); |
505 | c->type = type; | |
c906108c SS |
506 | c->var_type = var_type; |
507 | c->var = var; | |
e00d1dc8 | 508 | /* This needs to be something besides NULL so that this isn't |
c906108c | 509 | treated as a help class. */ |
9f60d481 | 510 | set_cmd_sfunc (c, empty_sfunc); |
c906108c SS |
511 | return c; |
512 | } | |
513 | ||
e707bbc2 AC |
514 | /* Add element named NAME to both the command SET_LIST and SHOW_LIST. |
515 | CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are | |
516 | setting. VAR is address of the variable being controlled by this | |
517 | command. SET_FUNC and SHOW_FUNC are the callback functions (if | |
3b64bf98 AC |
518 | non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation |
519 | strings. PRINT the format string to print the value. SET_RESULT | |
520 | and SHOW_RESULT, if not NULL, are set to the resulting command | |
521 | structures. */ | |
e707bbc2 | 522 | |
b3f42336 | 523 | static void |
6f937416 | 524 | add_setshow_cmd_full (const char *name, |
fe978cb0 | 525 | enum command_class theclass, |
9f064c95 | 526 | var_types var_type, void *var, |
3b64bf98 | 527 | const char *set_doc, const char *show_doc, |
335cca0d | 528 | const char *help_doc, |
eb4c3f4a | 529 | cmd_const_sfunc_ftype *set_func, |
08546159 | 530 | show_value_ftype *show_func, |
9f064c95 TT |
531 | struct cmd_list_element **set_list, |
532 | struct cmd_list_element **show_list, | |
533 | struct cmd_list_element **set_result, | |
534 | struct cmd_list_element **show_result) | |
e707bbc2 AC |
535 | { |
536 | struct cmd_list_element *set; | |
537 | struct cmd_list_element *show; | |
be7d7357 AC |
538 | char *full_set_doc; |
539 | char *full_show_doc; | |
540 | ||
541 | if (help_doc != NULL) | |
542 | { | |
543 | full_set_doc = xstrprintf ("%s\n%s", set_doc, help_doc); | |
544 | full_show_doc = xstrprintf ("%s\n%s", show_doc, help_doc); | |
545 | } | |
546 | else | |
547 | { | |
548 | full_set_doc = xstrdup (set_doc); | |
549 | full_show_doc = xstrdup (show_doc); | |
550 | } | |
fe978cb0 | 551 | set = add_set_or_show_cmd (name, set_cmd, theclass, var_type, var, |
3b64bf98 | 552 | full_set_doc, set_list); |
1f2bdf09 | 553 | set->doc_allocated = 1; |
5bc81a00 | 554 | |
e707bbc2 AC |
555 | if (set_func != NULL) |
556 | set_cmd_sfunc (set, set_func); | |
5b9afe8a YQ |
557 | |
558 | set_cmd_prefix (set, set_list); | |
559 | ||
fe978cb0 | 560 | show = add_set_or_show_cmd (name, show_cmd, theclass, var_type, var, |
3b64bf98 | 561 | full_show_doc, show_list); |
1f2bdf09 | 562 | show->doc_allocated = 1; |
08546159 | 563 | show->show_value_func = show_func; |
597bf39d PA |
564 | /* Disable the default symbol completer. Doesn't make much sense |
565 | for the "show" command to complete on anything. */ | |
566 | set_cmd_completer (show, nullptr); | |
9f064c95 TT |
567 | |
568 | if (set_result != NULL) | |
569 | *set_result = set; | |
570 | if (show_result != NULL) | |
571 | *show_result = show; | |
572 | } | |
573 | ||
1b295c3d AC |
574 | /* Add element named NAME to command list LIST (the list for set or |
575 | some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list | |
576 | of strings which may follow NAME. VAR is address of the variable | |
577 | which will contain the matching string (from ENUMLIST). */ | |
578 | ||
579 | void | |
6f937416 | 580 | add_setshow_enum_cmd (const char *name, |
fe978cb0 | 581 | enum command_class theclass, |
40478521 | 582 | const char *const *enumlist, |
1b295c3d AC |
583 | const char **var, |
584 | const char *set_doc, | |
585 | const char *show_doc, | |
586 | const char *help_doc, | |
eb4c3f4a | 587 | cmd_const_sfunc_ftype *set_func, |
08546159 | 588 | show_value_ftype *show_func, |
1b295c3d | 589 | struct cmd_list_element **set_list, |
7170dadf TT |
590 | struct cmd_list_element **show_list, |
591 | void *context) | |
1b295c3d | 592 | { |
7170dadf | 593 | struct cmd_list_element *c, *show; |
cdb27c12 | 594 | |
fe978cb0 | 595 | add_setshow_cmd_full (name, theclass, var_enum, var, |
335cca0d | 596 | set_doc, show_doc, help_doc, |
1b295c3d AC |
597 | set_func, show_func, |
598 | set_list, show_list, | |
7170dadf | 599 | &c, &show); |
1b295c3d | 600 | c->enums = enumlist; |
7170dadf TT |
601 | |
602 | set_cmd_context (c, context); | |
603 | set_cmd_context (show, context); | |
1b295c3d AC |
604 | } |
605 | ||
9d0faba9 | 606 | /* See cli-decode.h. */ |
5b9afe8a YQ |
607 | const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL }; |
608 | ||
e9e68a56 AC |
609 | /* Add an auto-boolean command named NAME to both the set and show |
610 | command list lists. CLASS is as in add_cmd. VAR is address of the | |
611 | variable which will contain the value. DOC is the documentation | |
612 | string. FUNC is the corresponding callback. */ | |
613 | void | |
6f937416 | 614 | add_setshow_auto_boolean_cmd (const char *name, |
fe978cb0 | 615 | enum command_class theclass, |
e9e68a56 | 616 | enum auto_boolean *var, |
3b64bf98 | 617 | const char *set_doc, const char *show_doc, |
335cca0d | 618 | const char *help_doc, |
eb4c3f4a | 619 | cmd_const_sfunc_ftype *set_func, |
08546159 | 620 | show_value_ftype *show_func, |
e9e68a56 AC |
621 | struct cmd_list_element **set_list, |
622 | struct cmd_list_element **show_list) | |
97c3646f | 623 | { |
97c3646f | 624 | struct cmd_list_element *c; |
cdb27c12 | 625 | |
fe978cb0 | 626 | add_setshow_cmd_full (name, theclass, var_auto_boolean, var, |
2c5b56ce | 627 | set_doc, show_doc, help_doc, |
3b64bf98 | 628 | set_func, show_func, |
9f064c95 TT |
629 | set_list, show_list, |
630 | &c, NULL); | |
97c3646f | 631 | c->enums = auto_boolean_enums; |
97c3646f AC |
632 | } |
633 | ||
9d0faba9 PA |
634 | /* See cli-decode.h. */ |
635 | const char * const boolean_enums[] = { "on", "off", NULL }; | |
636 | ||
e707bbc2 AC |
637 | /* Add element named NAME to both the set and show command LISTs (the |
638 | list for set/show or some sublist thereof). CLASS is as in | |
639 | add_cmd. VAR is address of the variable which will contain the | |
2daf894e PA |
640 | value. SET_DOC and SHOW_DOC are the documentation strings. |
641 | Returns the new command element. */ | |
642 | ||
643 | cmd_list_element * | |
491144b5 | 644 | add_setshow_boolean_cmd (const char *name, enum command_class theclass, bool *var, |
3b64bf98 | 645 | const char *set_doc, const char *show_doc, |
335cca0d | 646 | const char *help_doc, |
eb4c3f4a | 647 | cmd_const_sfunc_ftype *set_func, |
08546159 | 648 | show_value_ftype *show_func, |
e707bbc2 AC |
649 | struct cmd_list_element **set_list, |
650 | struct cmd_list_element **show_list) | |
f3796e26 | 651 | { |
f3796e26 | 652 | struct cmd_list_element *c; |
cdb27c12 | 653 | |
fe978cb0 | 654 | add_setshow_cmd_full (name, theclass, var_boolean, var, |
2c5b56ce | 655 | set_doc, show_doc, help_doc, |
9f064c95 TT |
656 | set_func, show_func, |
657 | set_list, show_list, | |
658 | &c, NULL); | |
f3796e26 | 659 | c->enums = boolean_enums; |
2daf894e PA |
660 | |
661 | return c; | |
f3796e26 AC |
662 | } |
663 | ||
b3f42336 AC |
664 | /* Add element named NAME to both the set and show command LISTs (the |
665 | list for set/show or some sublist thereof). */ | |
666 | void | |
fe978cb0 | 667 | add_setshow_filename_cmd (const char *name, enum command_class theclass, |
b3f42336 AC |
668 | char **var, |
669 | const char *set_doc, const char *show_doc, | |
335cca0d | 670 | const char *help_doc, |
eb4c3f4a | 671 | cmd_const_sfunc_ftype *set_func, |
08546159 | 672 | show_value_ftype *show_func, |
b3f42336 AC |
673 | struct cmd_list_element **set_list, |
674 | struct cmd_list_element **show_list) | |
675 | { | |
f397e303 | 676 | struct cmd_list_element *set_result; |
cdb27c12 | 677 | |
fe978cb0 | 678 | add_setshow_cmd_full (name, theclass, var_filename, var, |
2c5b56ce | 679 | set_doc, show_doc, help_doc, |
b3f42336 AC |
680 | set_func, show_func, |
681 | set_list, show_list, | |
f397e303 AC |
682 | &set_result, NULL); |
683 | set_cmd_completer (set_result, filename_completer); | |
b3f42336 AC |
684 | } |
685 | ||
686 | /* Add element named NAME to both the set and show command LISTs (the | |
5efd5804 PA |
687 | list for set/show or some sublist thereof). */ |
688 | void | |
fe978cb0 | 689 | add_setshow_string_cmd (const char *name, enum command_class theclass, |
6df3bc68 MS |
690 | char **var, |
691 | const char *set_doc, const char *show_doc, | |
692 | const char *help_doc, | |
eb4c3f4a | 693 | cmd_const_sfunc_ftype *set_func, |
6df3bc68 MS |
694 | show_value_ftype *show_func, |
695 | struct cmd_list_element **set_list, | |
696 | struct cmd_list_element **show_list) | |
b3f42336 | 697 | { |
597bf39d PA |
698 | cmd_list_element *set_cmd; |
699 | ||
fe978cb0 | 700 | add_setshow_cmd_full (name, theclass, var_string, var, |
2c5b56ce | 701 | set_doc, show_doc, help_doc, |
b3f42336 AC |
702 | set_func, show_func, |
703 | set_list, show_list, | |
597bf39d PA |
704 | &set_cmd, NULL); |
705 | ||
706 | /* Disable the default symbol completer. */ | |
707 | set_cmd_completer (set_cmd, nullptr); | |
b3f42336 AC |
708 | } |
709 | ||
26c41df3 | 710 | /* Add element named NAME to both the set and show command LISTs (the |
5efd5804 | 711 | list for set/show or some sublist thereof). */ |
44478ab3 | 712 | struct cmd_list_element * |
fe978cb0 | 713 | add_setshow_string_noescape_cmd (const char *name, enum command_class theclass, |
26c41df3 AC |
714 | char **var, |
715 | const char *set_doc, const char *show_doc, | |
716 | const char *help_doc, | |
eb4c3f4a | 717 | cmd_const_sfunc_ftype *set_func, |
26c41df3 AC |
718 | show_value_ftype *show_func, |
719 | struct cmd_list_element **set_list, | |
720 | struct cmd_list_element **show_list) | |
721 | { | |
44478ab3 TT |
722 | struct cmd_list_element *set_cmd; |
723 | ||
fe978cb0 | 724 | add_setshow_cmd_full (name, theclass, var_string_noescape, var, |
26c41df3 AC |
725 | set_doc, show_doc, help_doc, |
726 | set_func, show_func, | |
727 | set_list, show_list, | |
44478ab3 | 728 | &set_cmd, NULL); |
597bf39d PA |
729 | |
730 | /* Disable the default symbol completer. */ | |
731 | set_cmd_completer (set_cmd, nullptr); | |
732 | ||
44478ab3 | 733 | return set_cmd; |
26c41df3 AC |
734 | } |
735 | ||
b4b4ac0b AC |
736 | /* Add element named NAME to both the set and show command LISTs (the |
737 | list for set/show or some sublist thereof). */ | |
738 | void | |
fe978cb0 | 739 | add_setshow_optional_filename_cmd (const char *name, enum command_class theclass, |
b4b4ac0b AC |
740 | char **var, |
741 | const char *set_doc, const char *show_doc, | |
742 | const char *help_doc, | |
eb4c3f4a | 743 | cmd_const_sfunc_ftype *set_func, |
b4b4ac0b AC |
744 | show_value_ftype *show_func, |
745 | struct cmd_list_element **set_list, | |
746 | struct cmd_list_element **show_list) | |
747 | { | |
7f6a6314 PM |
748 | struct cmd_list_element *set_result; |
749 | ||
fe978cb0 | 750 | add_setshow_cmd_full (name, theclass, var_optional_filename, var, |
b4b4ac0b AC |
751 | set_doc, show_doc, help_doc, |
752 | set_func, show_func, | |
753 | set_list, show_list, | |
7f6a6314 PM |
754 | &set_result, NULL); |
755 | ||
756 | set_cmd_completer (set_result, filename_completer); | |
757 | ||
b4b4ac0b AC |
758 | } |
759 | ||
f81d1120 PA |
760 | /* Completes on literal "unlimited". Used by integer commands that |
761 | support a special "unlimited" value. */ | |
762 | ||
eb3ff9a5 | 763 | static void |
f81d1120 | 764 | integer_unlimited_completer (struct cmd_list_element *ignore, |
eb3ff9a5 | 765 | completion_tracker &tracker, |
f81d1120 PA |
766 | const char *text, const char *word) |
767 | { | |
768 | static const char * const keywords[] = | |
769 | { | |
770 | "unlimited", | |
771 | NULL, | |
772 | }; | |
773 | ||
eb3ff9a5 | 774 | complete_on_enum (tracker, keywords, text, word); |
f81d1120 PA |
775 | } |
776 | ||
c0d88b1b AC |
777 | /* Add element named NAME to both the set and show command LISTs (the |
778 | list for set/show or some sublist thereof). CLASS is as in | |
779 | add_cmd. VAR is address of the variable which will contain the | |
6fc1c773 YQ |
780 | value. SET_DOC and SHOW_DOC are the documentation strings. This |
781 | function is only used in Python API. Please don't use it elsewhere. */ | |
5efd5804 | 782 | void |
fe978cb0 | 783 | add_setshow_integer_cmd (const char *name, enum command_class theclass, |
47b667de | 784 | int *var, |
6df3bc68 MS |
785 | const char *set_doc, const char *show_doc, |
786 | const char *help_doc, | |
eb4c3f4a | 787 | cmd_const_sfunc_ftype *set_func, |
6df3bc68 MS |
788 | show_value_ftype *show_func, |
789 | struct cmd_list_element **set_list, | |
790 | struct cmd_list_element **show_list) | |
c0d88b1b | 791 | { |
f81d1120 PA |
792 | struct cmd_list_element *set; |
793 | ||
fe978cb0 | 794 | add_setshow_cmd_full (name, theclass, var_integer, var, |
c0d88b1b AC |
795 | set_doc, show_doc, help_doc, |
796 | set_func, show_func, | |
797 | set_list, show_list, | |
f81d1120 PA |
798 | &set, NULL); |
799 | ||
800 | set_cmd_completer (set, integer_unlimited_completer); | |
c0d88b1b AC |
801 | } |
802 | ||
25d29d70 AC |
803 | /* Add element named NAME to both the set and show command LISTs (the |
804 | list for set/show or some sublist thereof). CLASS is as in | |
805 | add_cmd. VAR is address of the variable which will contain the | |
5efd5804 PA |
806 | value. SET_DOC and SHOW_DOC are the documentation strings. */ |
807 | void | |
fe978cb0 | 808 | add_setshow_uinteger_cmd (const char *name, enum command_class theclass, |
3b64bf98 AC |
809 | unsigned int *var, |
810 | const char *set_doc, const char *show_doc, | |
335cca0d | 811 | const char *help_doc, |
eb4c3f4a | 812 | cmd_const_sfunc_ftype *set_func, |
08546159 | 813 | show_value_ftype *show_func, |
25d29d70 AC |
814 | struct cmd_list_element **set_list, |
815 | struct cmd_list_element **show_list) | |
816 | { | |
f81d1120 PA |
817 | struct cmd_list_element *set; |
818 | ||
fe978cb0 | 819 | add_setshow_cmd_full (name, theclass, var_uinteger, var, |
2c5b56ce | 820 | set_doc, show_doc, help_doc, |
25d29d70 AC |
821 | set_func, show_func, |
822 | set_list, show_list, | |
f81d1120 PA |
823 | &set, NULL); |
824 | ||
825 | set_cmd_completer (set, integer_unlimited_completer); | |
25d29d70 AC |
826 | } |
827 | ||
15170568 AC |
828 | /* Add element named NAME to both the set and show command LISTs (the |
829 | list for set/show or some sublist thereof). CLASS is as in | |
830 | add_cmd. VAR is address of the variable which will contain the | |
5efd5804 PA |
831 | value. SET_DOC and SHOW_DOC are the documentation strings. */ |
832 | void | |
fe978cb0 | 833 | add_setshow_zinteger_cmd (const char *name, enum command_class theclass, |
3b64bf98 AC |
834 | int *var, |
835 | const char *set_doc, const char *show_doc, | |
335cca0d | 836 | const char *help_doc, |
eb4c3f4a | 837 | cmd_const_sfunc_ftype *set_func, |
08546159 | 838 | show_value_ftype *show_func, |
15170568 AC |
839 | struct cmd_list_element **set_list, |
840 | struct cmd_list_element **show_list) | |
841 | { | |
fe978cb0 | 842 | add_setshow_cmd_full (name, theclass, var_zinteger, var, |
2c5b56ce | 843 | set_doc, show_doc, help_doc, |
15170568 AC |
844 | set_func, show_func, |
845 | set_list, show_list, | |
5efd5804 | 846 | NULL, NULL); |
15170568 AC |
847 | } |
848 | ||
6fc1c773 | 849 | void |
6f937416 | 850 | add_setshow_zuinteger_unlimited_cmd (const char *name, |
fe978cb0 | 851 | enum command_class theclass, |
b69b1fb1 | 852 | int *var, |
6fc1c773 YQ |
853 | const char *set_doc, |
854 | const char *show_doc, | |
855 | const char *help_doc, | |
eb4c3f4a | 856 | cmd_const_sfunc_ftype *set_func, |
6fc1c773 YQ |
857 | show_value_ftype *show_func, |
858 | struct cmd_list_element **set_list, | |
859 | struct cmd_list_element **show_list) | |
860 | { | |
f81d1120 PA |
861 | struct cmd_list_element *set; |
862 | ||
fe978cb0 | 863 | add_setshow_cmd_full (name, theclass, var_zuinteger_unlimited, var, |
6fc1c773 YQ |
864 | set_doc, show_doc, help_doc, |
865 | set_func, show_func, | |
866 | set_list, show_list, | |
f81d1120 PA |
867 | &set, NULL); |
868 | ||
869 | set_cmd_completer (set, integer_unlimited_completer); | |
6fc1c773 YQ |
870 | } |
871 | ||
1e8fb976 PA |
872 | /* Add element named NAME to both the set and show command LISTs (the |
873 | list for set/show or some sublist thereof). CLASS is as in | |
874 | add_cmd. VAR is address of the variable which will contain the | |
5efd5804 PA |
875 | value. SET_DOC and SHOW_DOC are the documentation strings. */ |
876 | void | |
fe978cb0 | 877 | add_setshow_zuinteger_cmd (const char *name, enum command_class theclass, |
1e8fb976 PA |
878 | unsigned int *var, |
879 | const char *set_doc, const char *show_doc, | |
880 | const char *help_doc, | |
eb4c3f4a | 881 | cmd_const_sfunc_ftype *set_func, |
1e8fb976 PA |
882 | show_value_ftype *show_func, |
883 | struct cmd_list_element **set_list, | |
884 | struct cmd_list_element **show_list) | |
885 | { | |
fe978cb0 | 886 | add_setshow_cmd_full (name, theclass, var_zuinteger, var, |
1e8fb976 PA |
887 | set_doc, show_doc, help_doc, |
888 | set_func, show_func, | |
889 | set_list, show_list, | |
5efd5804 | 890 | NULL, NULL); |
1e8fb976 PA |
891 | } |
892 | ||
b05dcbb7 TT |
893 | /* Remove the command named NAME from the command list. Return the |
894 | list commands which were aliased to the deleted command. If the | |
fad6eecd TT |
895 | command had no aliases, return NULL. The various *HOOKs are set to |
896 | the pre- and post-hook commands for the deleted command. If the | |
897 | command does not have a hook, the corresponding out parameter is | |
898 | set to NULL. */ | |
c906108c | 899 | |
b05dcbb7 | 900 | static struct cmd_list_element * |
6f937416 | 901 | delete_cmd (const char *name, struct cmd_list_element **list, |
fad6eecd TT |
902 | struct cmd_list_element **prehook, |
903 | struct cmd_list_element **prehookee, | |
904 | struct cmd_list_element **posthook, | |
905 | struct cmd_list_element **posthookee) | |
c906108c | 906 | { |
b05dcbb7 TT |
907 | struct cmd_list_element *iter; |
908 | struct cmd_list_element **previous_chain_ptr; | |
909 | struct cmd_list_element *aliases = NULL; | |
c906108c | 910 | |
fad6eecd TT |
911 | *prehook = NULL; |
912 | *prehookee = NULL; | |
913 | *posthook = NULL; | |
914 | *posthookee = NULL; | |
b05dcbb7 TT |
915 | previous_chain_ptr = list; |
916 | ||
917 | for (iter = *previous_chain_ptr; iter; iter = *previous_chain_ptr) | |
c906108c | 918 | { |
b05dcbb7 TT |
919 | if (strcmp (iter->name, name) == 0) |
920 | { | |
d8906c6f TJB |
921 | if (iter->destroyer) |
922 | iter->destroyer (iter, iter->context); | |
b05dcbb7 TT |
923 | if (iter->hookee_pre) |
924 | iter->hookee_pre->hook_pre = 0; | |
fad6eecd TT |
925 | *prehook = iter->hook_pre; |
926 | *prehookee = iter->hookee_pre; | |
b05dcbb7 TT |
927 | if (iter->hookee_post) |
928 | iter->hookee_post->hook_post = 0; | |
fad6eecd TT |
929 | *posthook = iter->hook_post; |
930 | *posthookee = iter->hookee_post; | |
b05dcbb7 TT |
931 | |
932 | /* Update the link. */ | |
933 | *previous_chain_ptr = iter->next; | |
934 | ||
935 | aliases = iter->aliases; | |
936 | ||
937 | /* If this command was an alias, remove it from the list of | |
938 | aliases. */ | |
939 | if (iter->cmd_pointer) | |
940 | { | |
941 | struct cmd_list_element **prevp = &iter->cmd_pointer->aliases; | |
942 | struct cmd_list_element *a = *prevp; | |
943 | ||
944 | while (a != iter) | |
945 | { | |
946 | prevp = &a->alias_chain; | |
947 | a = *prevp; | |
948 | } | |
949 | *prevp = iter->alias_chain; | |
950 | } | |
951 | ||
e2fc72e2 | 952 | delete iter; |
b05dcbb7 TT |
953 | |
954 | /* We won't see another command with the same name. */ | |
955 | break; | |
956 | } | |
957 | else | |
958 | previous_chain_ptr = &iter->next; | |
c906108c SS |
959 | } |
960 | ||
b05dcbb7 | 961 | return aliases; |
c906108c | 962 | } |
d318976c | 963 | \f |
ebcd3b23 | 964 | /* Shorthands to the commands above. */ |
d318976c FN |
965 | |
966 | /* Add an element to the list of info subcommands. */ | |
967 | ||
968 | struct cmd_list_element * | |
1d12d88f | 969 | add_info (const char *name, cmd_const_cfunc_ftype *fun, const char *doc) |
d318976c | 970 | { |
f3575e08 | 971 | return add_cmd (name, class_info, fun, doc, &infolist); |
d318976c FN |
972 | } |
973 | ||
974 | /* Add an alias to the list of info subcommands. */ | |
975 | ||
976 | struct cmd_list_element * | |
1947513d | 977 | add_info_alias (const char *name, const char *oldname, int abbrev_flag) |
d318976c | 978 | { |
f486487f | 979 | return add_alias_cmd (name, oldname, class_run, abbrev_flag, &infolist); |
d318976c FN |
980 | } |
981 | ||
982 | /* Add an element to the list of commands. */ | |
983 | ||
984 | struct cmd_list_element * | |
0b39b52e TT |
985 | add_com (const char *name, enum command_class theclass, |
986 | cmd_const_cfunc_ftype *fun, | |
1947513d | 987 | const char *doc) |
d318976c | 988 | { |
fe978cb0 | 989 | return add_cmd (name, theclass, fun, doc, &cmdlist); |
d318976c FN |
990 | } |
991 | ||
992 | /* Add an alias or abbreviation command to the list of commands. */ | |
993 | ||
994 | struct cmd_list_element * | |
fe978cb0 | 995 | add_com_alias (const char *name, const char *oldname, enum command_class theclass, |
d318976c FN |
996 | int abbrev_flag) |
997 | { | |
fe978cb0 | 998 | return add_alias_cmd (name, oldname, theclass, abbrev_flag, &cmdlist); |
d318976c | 999 | } |
4034d0ff AT |
1000 | |
1001 | /* Add an element with a suppress notification to the list of commands. */ | |
1002 | ||
1003 | struct cmd_list_element * | |
1004 | add_com_suppress_notification (const char *name, enum command_class theclass, | |
1ee870c5 | 1005 | cmd_const_cfunc_ftype *fun, const char *doc, |
4034d0ff AT |
1006 | int *suppress_notification) |
1007 | { | |
f67ffa6a AB |
1008 | return add_cmd_suppress_notification (name, theclass, fun, doc, |
1009 | &cmdlist, suppress_notification); | |
4034d0ff AT |
1010 | } |
1011 | ||
66d8c862 PW |
1012 | /* If VERBOSE, print the full help for command C and highlight the |
1013 | documentation parts matching HIGHLIGHT, | |
1014 | otherwise print only one-line help for command C. */ | |
1015 | ||
1016 | static void | |
1017 | print_doc_of_command (struct cmd_list_element *c, const char *prefix, | |
1018 | bool verbose, compiled_regex &highlight, | |
1019 | struct ui_file *stream) | |
1020 | { | |
1021 | /* When printing the full documentation, add a line to separate | |
1022 | this documentation from the previous command help, in the likely | |
1023 | case that apropos finds several commands. */ | |
1024 | if (verbose) | |
1025 | fputs_filtered ("\n", stream); | |
1026 | ||
1027 | fprintf_styled (stream, title_style.style (), | |
1028 | "%s%s", prefix, c->name); | |
1029 | fputs_filtered (" -- ", stream); | |
1030 | if (verbose) | |
1031 | fputs_highlighted (c->doc, highlight, stream); | |
1032 | else | |
590042fc | 1033 | print_doc_line (stream, c->doc, false); |
66d8c862 PW |
1034 | fputs_filtered ("\n", stream); |
1035 | } | |
1036 | ||
6837a0a2 DB |
1037 | /* Recursively walk the commandlist structures, and print out the |
1038 | documentation of commands that match our regex in either their | |
1039 | name, or their documentation. | |
66d8c862 PW |
1040 | If VERBOSE, prints the complete documentation and highlight the |
1041 | documentation parts matching REGEX, otherwise prints only | |
1042 | the first line. | |
6837a0a2 | 1043 | */ |
66d8c862 PW |
1044 | void |
1045 | apropos_cmd (struct ui_file *stream, | |
ebcd3b23 | 1046 | struct cmd_list_element *commandlist, |
66d8c862 | 1047 | bool verbose, compiled_regex ®ex, const char *prefix) |
6837a0a2 | 1048 | { |
d5b5ac79 | 1049 | struct cmd_list_element *c; |
4a98be19 | 1050 | int returnvalue; |
cdb27c12 | 1051 | |
ebcd3b23 | 1052 | /* Walk through the commands. */ |
6837a0a2 DB |
1053 | for (c=commandlist;c;c=c->next) |
1054 | { | |
ebcd3b23 | 1055 | returnvalue = -1; /* Needed to avoid double printing. */ |
6837a0a2 DB |
1056 | if (c->name != NULL) |
1057 | { | |
2d7cc5c7 PA |
1058 | size_t name_len = strlen (c->name); |
1059 | ||
ebcd3b23 | 1060 | /* Try to match against the name. */ |
2d7cc5c7 | 1061 | returnvalue = regex.search (c->name, name_len, 0, name_len, NULL); |
6837a0a2 | 1062 | if (returnvalue >= 0) |
66d8c862 | 1063 | print_doc_of_command (c, prefix, verbose, regex, stream); |
6837a0a2 | 1064 | } |
4a98be19 | 1065 | if (c->doc != NULL && returnvalue < 0) |
6837a0a2 | 1066 | { |
2d7cc5c7 PA |
1067 | size_t doc_len = strlen (c->doc); |
1068 | ||
ebcd3b23 | 1069 | /* Try to match against documentation. */ |
2d7cc5c7 | 1070 | if (regex.search (c->doc, doc_len, 0, doc_len, NULL) >= 0) |
66d8c862 | 1071 | print_doc_of_command (c, prefix, verbose, regex, stream); |
6837a0a2 | 1072 | } |
ebcd3b23 MS |
1073 | /* Check if this command has subcommands and is not an |
1074 | abbreviation. We skip listing subcommands of abbreviations | |
1075 | in order to avoid duplicates in the output. */ | |
5d2c29b8 | 1076 | if (c->prefixlist != NULL && !c->abbrev_flag) |
6837a0a2 DB |
1077 | { |
1078 | /* Recursively call ourselves on the subcommand list, | |
ebcd3b23 | 1079 | passing the right prefix in. */ |
66d8c862 | 1080 | apropos_cmd (stream, *c->prefixlist, verbose, regex, c->prefixname); |
6837a0a2 DB |
1081 | } |
1082 | } | |
1083 | } | |
c906108c SS |
1084 | |
1085 | /* This command really has to deal with two things: | |
ebcd3b23 MS |
1086 | 1) I want documentation on *this string* (usually called by |
1087 | "help commandname"). | |
1088 | ||
1089 | 2) I want documentation on *this list* (usually called by giving a | |
1090 | command that requires subcommands. Also called by saying just | |
1091 | "help".) | |
1092 | ||
30baf67b | 1093 | I am going to split this into two separate commands, help_cmd and |
ebcd3b23 | 1094 | help_list. */ |
c906108c SS |
1095 | |
1096 | void | |
64669f3b | 1097 | help_cmd (const char *command, struct ui_file *stream) |
c906108c SS |
1098 | { |
1099 | struct cmd_list_element *c; | |
c906108c SS |
1100 | |
1101 | if (!command) | |
1102 | { | |
1103 | help_list (cmdlist, "", all_classes, stream); | |
1104 | return; | |
1105 | } | |
1106 | ||
49a5a3a3 GM |
1107 | if (strcmp (command, "all") == 0) |
1108 | { | |
1109 | help_all (stream); | |
1110 | return; | |
1111 | } | |
1112 | ||
c906108c SS |
1113 | c = lookup_cmd (&command, cmdlist, "", 0, 0); |
1114 | ||
1115 | if (c == 0) | |
1116 | return; | |
1117 | ||
1118 | /* There are three cases here. | |
1119 | If c->prefixlist is nonzero, we have a prefix command. | |
1120 | Print its documentation, then list its subcommands. | |
c5aa993b | 1121 | |
9f60d481 AC |
1122 | If c->func is non NULL, we really have a command. Print its |
1123 | documentation and return. | |
c5aa993b | 1124 | |
9f60d481 AC |
1125 | If c->func is NULL, we have a class name. Print its |
1126 | documentation (as if it were a command) and then set class to the | |
1127 | number of this class so that the commands in the class will be | |
1128 | listed. */ | |
c906108c SS |
1129 | |
1130 | fputs_filtered (c->doc, stream); | |
1131 | fputs_filtered ("\n", stream); | |
1132 | ||
9f60d481 | 1133 | if (c->prefixlist == 0 && c->func != NULL) |
c906108c SS |
1134 | return; |
1135 | fprintf_filtered (stream, "\n"); | |
1136 | ||
ebcd3b23 | 1137 | /* If this is a prefix command, print it's subcommands. */ |
c906108c SS |
1138 | if (c->prefixlist) |
1139 | help_list (*c->prefixlist, c->prefixname, all_commands, stream); | |
1140 | ||
ebcd3b23 | 1141 | /* If this is a class name, print all of the commands in the class. */ |
9f60d481 | 1142 | if (c->func == NULL) |
fe978cb0 | 1143 | help_list (cmdlist, "", c->theclass, stream); |
c906108c | 1144 | |
73bc900d FN |
1145 | if (c->hook_pre || c->hook_post) |
1146 | fprintf_filtered (stream, | |
1147 | "\nThis command has a hook (or hooks) defined:\n"); | |
1148 | ||
1149 | if (c->hook_pre) | |
327529e9 | 1150 | fprintf_filtered (stream, |
72fe0832 | 1151 | "\tThis command is run after : %s (pre hook)\n", |
73bc900d FN |
1152 | c->hook_pre->name); |
1153 | if (c->hook_post) | |
327529e9 | 1154 | fprintf_filtered (stream, |
72fe0832 | 1155 | "\tThis command is run before : %s (post hook)\n", |
73bc900d | 1156 | c->hook_post->name); |
c906108c SS |
1157 | } |
1158 | ||
1159 | /* | |
1160 | * Get a specific kind of help on a command list. | |
1161 | * | |
1162 | * LIST is the list. | |
1163 | * CMDTYPE is the prefix to use in the title string. | |
1164 | * CLASS is the class with which to list the nodes of this list (see | |
1165 | * documentation for help_cmd_list below), As usual, ALL_COMMANDS for | |
1166 | * everything, ALL_CLASSES for just classes, and non-negative for only things | |
1167 | * in a specific class. | |
1168 | * and STREAM is the output stream on which to print things. | |
1169 | * If you call this routine with a class >= 0, it recurses. | |
1170 | */ | |
1171 | void | |
64e61d29 | 1172 | help_list (struct cmd_list_element *list, const char *cmdtype, |
fe978cb0 | 1173 | enum command_class theclass, struct ui_file *stream) |
c906108c SS |
1174 | { |
1175 | int len; | |
1176 | char *cmdtype1, *cmdtype2; | |
c5aa993b | 1177 | |
ebcd3b23 MS |
1178 | /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub". |
1179 | */ | |
c906108c SS |
1180 | len = strlen (cmdtype); |
1181 | cmdtype1 = (char *) alloca (len + 1); | |
1182 | cmdtype1[0] = 0; | |
1183 | cmdtype2 = (char *) alloca (len + 4); | |
1184 | cmdtype2[0] = 0; | |
1185 | if (len) | |
1186 | { | |
1187 | cmdtype1[0] = ' '; | |
29f9a567 | 1188 | memcpy (cmdtype1 + 1, cmdtype, len - 1); |
c906108c | 1189 | cmdtype1[len] = 0; |
29f9a567 | 1190 | memcpy (cmdtype2, cmdtype, len - 1); |
c906108c SS |
1191 | strcpy (cmdtype2 + len - 1, " sub"); |
1192 | } | |
1193 | ||
fe978cb0 | 1194 | if (theclass == all_classes) |
c906108c SS |
1195 | fprintf_filtered (stream, "List of classes of %scommands:\n\n", cmdtype2); |
1196 | else | |
1197 | fprintf_filtered (stream, "List of %scommands:\n\n", cmdtype2); | |
1198 | ||
fe978cb0 | 1199 | help_cmd_list (list, theclass, cmdtype, (int) theclass >= 0, stream); |
c906108c | 1200 | |
fe978cb0 | 1201 | if (theclass == all_classes) |
de74f71f MS |
1202 | { |
1203 | fprintf_filtered (stream, "\n\ | |
1204 | Type \"help%s\" followed by a class name for a list of commands in ", | |
1205 | cmdtype1); | |
1206 | wrap_here (""); | |
1207 | fprintf_filtered (stream, "that class."); | |
6e381ba0 VP |
1208 | |
1209 | fprintf_filtered (stream, "\n\ | |
1210 | Type \"help all\" for the list of all commands."); | |
de74f71f | 1211 | } |
c906108c | 1212 | |
de74f71f | 1213 | fprintf_filtered (stream, "\nType \"help%s\" followed by %scommand name ", |
c5aa993b | 1214 | cmdtype1, cmdtype2); |
de74f71f MS |
1215 | wrap_here (""); |
1216 | fputs_filtered ("for ", stream); | |
1217 | wrap_here (""); | |
1218 | fputs_filtered ("full ", stream); | |
1219 | wrap_here (""); | |
1220 | fputs_filtered ("documentation.\n", stream); | |
6e381ba0 | 1221 | fputs_filtered ("Type \"apropos word\" to search " |
ebcd3b23 | 1222 | "for commands related to \"word\".\n", stream); |
66d8c862 PW |
1223 | fputs_filtered ("Type \"apropos -v word\" for full documentation", stream); |
1224 | wrap_here (""); | |
1225 | fputs_filtered (" of commands related to \"word\".\n", stream); | |
de74f71f MS |
1226 | fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n", |
1227 | stream); | |
c906108c | 1228 | } |
c5aa993b | 1229 | |
49a5a3a3 | 1230 | static void |
c85871a3 | 1231 | help_all (struct ui_file *stream) |
49a5a3a3 GM |
1232 | { |
1233 | struct cmd_list_element *c; | |
6e381ba0 | 1234 | int seen_unclassified = 0; |
49a5a3a3 GM |
1235 | |
1236 | for (c = cmdlist; c; c = c->next) | |
1237 | { | |
1238 | if (c->abbrev_flag) | |
1239 | continue; | |
ebcd3b23 MS |
1240 | /* If this is a class name, print all of the commands in the |
1241 | class. */ | |
6e381ba0 VP |
1242 | |
1243 | if (c->func == NULL) | |
1244 | { | |
1245 | fprintf_filtered (stream, "\nCommand class: %s\n\n", c->name); | |
fe978cb0 | 1246 | help_cmd_list (cmdlist, c->theclass, "", 1, stream); |
6e381ba0 | 1247 | } |
49a5a3a3 | 1248 | } |
6e381ba0 VP |
1249 | |
1250 | /* While it's expected that all commands are in some class, | |
1251 | as a safety measure, we'll print commands outside of any | |
1252 | class at the end. */ | |
1253 | ||
1254 | for (c = cmdlist; c; c = c->next) | |
1255 | { | |
1256 | if (c->abbrev_flag) | |
1257 | continue; | |
1258 | ||
fe978cb0 | 1259 | if (c->theclass == no_class) |
6e381ba0 VP |
1260 | { |
1261 | if (!seen_unclassified) | |
1262 | { | |
1263 | fprintf_filtered (stream, "\nUnclassified commands\n\n"); | |
1264 | seen_unclassified = 1; | |
1265 | } | |
1266 | print_help_for_command (c, "", 1, stream); | |
1267 | } | |
1268 | } | |
1269 | ||
49a5a3a3 GM |
1270 | } |
1271 | ||
590042fc PW |
1272 | /* See cli-decode.h. */ |
1273 | ||
d318976c | 1274 | void |
590042fc PW |
1275 | print_doc_line (struct ui_file *stream, const char *str, |
1276 | bool for_value_prefix) | |
c906108c SS |
1277 | { |
1278 | static char *line_buffer = 0; | |
1279 | static int line_size; | |
1947513d | 1280 | const char *p; |
c906108c SS |
1281 | |
1282 | if (!line_buffer) | |
1283 | { | |
1284 | line_size = 80; | |
1285 | line_buffer = (char *) xmalloc (line_size); | |
1286 | } | |
1287 | ||
590042fc | 1288 | /* Searches for the first end of line or the end of STR. */ |
c906108c | 1289 | p = str; |
590042fc | 1290 | while (*p && *p != '\n') |
c906108c SS |
1291 | p++; |
1292 | if (p - str > line_size - 1) | |
1293 | { | |
1294 | line_size = p - str + 1; | |
b8c9b27d | 1295 | xfree (line_buffer); |
c906108c SS |
1296 | line_buffer = (char *) xmalloc (line_size); |
1297 | } | |
1298 | strncpy (line_buffer, str, p - str); | |
590042fc PW |
1299 | if (for_value_prefix) |
1300 | { | |
1301 | if (islower (line_buffer[0])) | |
1302 | line_buffer[0] = toupper (line_buffer[0]); | |
1303 | gdb_assert (p > str); | |
1304 | if (line_buffer[p - str - 1] == '.') | |
1305 | line_buffer[p - str - 1] = '\0'; | |
1306 | else | |
1307 | line_buffer[p - str] = '\0'; | |
1308 | } | |
1309 | else | |
1310 | line_buffer[p - str] = '\0'; | |
b6201d44 | 1311 | fputs_filtered (line_buffer, stream); |
c906108c SS |
1312 | } |
1313 | ||
6e381ba0 VP |
1314 | /* Print one-line help for command C. |
1315 | If RECURSE is non-zero, also print one-line descriptions | |
ebcd3b23 | 1316 | of all prefixed subcommands. */ |
6e381ba0 | 1317 | static void |
64e61d29 TT |
1318 | print_help_for_command (struct cmd_list_element *c, const char *prefix, |
1319 | int recurse, struct ui_file *stream) | |
6e381ba0 | 1320 | { |
66d8c862 PW |
1321 | fprintf_styled (stream, title_style.style (), |
1322 | "%s%s", prefix, c->name); | |
1323 | fputs_filtered (" -- ", stream); | |
590042fc | 1324 | print_doc_line (stream, c->doc, false); |
6e381ba0 | 1325 | fputs_filtered ("\n", stream); |
66d8c862 | 1326 | |
6e381ba0 VP |
1327 | if (recurse |
1328 | && c->prefixlist != 0 | |
1329 | && c->abbrev_flag == 0) | |
1330 | /* Subcommands of a prefix command typically have 'all_commands' | |
1331 | as class. If we pass CLASS to recursive invocation, | |
ebcd3b23 | 1332 | most often we won't see anything. */ |
6e381ba0 VP |
1333 | help_cmd_list (*c->prefixlist, all_commands, c->prefixname, 1, stream); |
1334 | } | |
1335 | ||
c906108c SS |
1336 | /* |
1337 | * Implement a help command on command list LIST. | |
1338 | * RECURSE should be non-zero if this should be done recursively on | |
1339 | * all sublists of LIST. | |
1340 | * PREFIX is the prefix to print before each command name. | |
1341 | * STREAM is the stream upon which the output should be written. | |
2aa08bd1 | 1342 | * THECLASS should be: |
c5aa993b | 1343 | * A non-negative class number to list only commands in that |
c906108c | 1344 | * class. |
c5aa993b JM |
1345 | * ALL_COMMANDS to list all commands in list. |
1346 | * ALL_CLASSES to list all classes in list. | |
c906108c SS |
1347 | * |
1348 | * Note that RECURSE will be active on *all* sublists, not just the | |
1349 | * ones selected by the criteria above (ie. the selection mechanism | |
1350 | * is at the low level, not the high-level). | |
1351 | */ | |
1352 | void | |
fe978cb0 | 1353 | help_cmd_list (struct cmd_list_element *list, enum command_class theclass, |
64e61d29 | 1354 | const char *prefix, int recurse, struct ui_file *stream) |
c906108c | 1355 | { |
d5b5ac79 | 1356 | struct cmd_list_element *c; |
c906108c SS |
1357 | |
1358 | for (c = list; c; c = c->next) | |
2aa08bd1 | 1359 | { |
5aafa1cc | 1360 | if (c->abbrev_flag == 0 |
0400cf2f | 1361 | && !c->cmd_deprecated |
fe978cb0 PA |
1362 | && (theclass == all_commands |
1363 | || (theclass == all_classes && c->func == NULL) | |
1364 | || (theclass == c->theclass && c->func != NULL))) | |
c906108c | 1365 | { |
6e381ba0 | 1366 | print_help_for_command (c, prefix, recurse, stream); |
c906108c | 1367 | } |
0400cf2f SM |
1368 | else if (c->abbrev_flag == 0 |
1369 | && recurse | |
1370 | && !c->cmd_deprecated | |
fe978cb0 | 1371 | && theclass == class_user && c->prefixlist != NULL) |
adb483fe | 1372 | /* User-defined commands may be subcommands. */ |
fe978cb0 | 1373 | help_cmd_list (*c->prefixlist, theclass, c->prefixname, |
ebcd3b23 | 1374 | recurse, stream); |
c906108c SS |
1375 | } |
1376 | } | |
c906108c | 1377 | \f |
c5aa993b | 1378 | |
c906108c SS |
1379 | /* Search the input clist for 'command'. Return the command if |
1380 | found (or NULL if not), and return the number of commands | |
ebcd3b23 | 1381 | found in nfound. */ |
c906108c SS |
1382 | |
1383 | static struct cmd_list_element * | |
6f937416 | 1384 | find_cmd (const char *command, int len, struct cmd_list_element *clist, |
fba45db2 | 1385 | int ignore_help_classes, int *nfound) |
c906108c SS |
1386 | { |
1387 | struct cmd_list_element *found, *c; | |
1388 | ||
b03e6ad9 | 1389 | found = NULL; |
c906108c SS |
1390 | *nfound = 0; |
1391 | for (c = clist; c; c = c->next) | |
1392 | if (!strncmp (command, c->name, len) | |
9f60d481 | 1393 | && (!ignore_help_classes || c->func)) |
c906108c | 1394 | { |
c5aa993b JM |
1395 | found = c; |
1396 | (*nfound)++; | |
1397 | if (c->name[len] == '\0') | |
1398 | { | |
1399 | *nfound = 1; | |
1400 | break; | |
1401 | } | |
c906108c SS |
1402 | } |
1403 | return found; | |
1404 | } | |
1405 | ||
604c4576 JG |
1406 | /* Return the length of command name in TEXT. */ |
1407 | ||
1408 | int | |
3386243e AS |
1409 | find_command_name_length (const char *text) |
1410 | { | |
1411 | const char *p = text; | |
1412 | ||
1413 | /* Treating underscores as part of command words is important | |
1414 | so that "set args_foo()" doesn't get interpreted as | |
1415 | "set args _foo()". */ | |
ebcd3b23 MS |
1416 | /* Some characters are only used for TUI specific commands. |
1417 | However, they are always allowed for the sake of consistency. | |
1418 | ||
ebcd3b23 MS |
1419 | Note that this is larger than the character set allowed when |
1420 | creating user-defined commands. */ | |
1421 | ||
947d3946 | 1422 | /* Recognize the single character commands so that, e.g., "!ls" |
ed59ded5 | 1423 | works as expected. */ |
947d3946 | 1424 | if (*p == '!' || *p == '|') |
ed59ded5 DE |
1425 | return 1; |
1426 | ||
be09caf1 | 1427 | while (valid_cmd_char_p (*p) |
3386243e | 1428 | /* Characters used by TUI specific commands. */ |
4f45d445 | 1429 | || *p == '+' || *p == '<' || *p == '>' || *p == '$') |
3386243e AS |
1430 | p++; |
1431 | ||
1432 | return p - text; | |
1433 | } | |
1434 | ||
be09caf1 PW |
1435 | /* See command.h. */ |
1436 | ||
1437 | bool | |
1438 | valid_cmd_char_p (int c) | |
1439 | { | |
1440 | /* Alas "42" is a legitimate user-defined command. | |
1441 | In the interests of not breaking anything we preserve that. */ | |
1442 | ||
1443 | return isalnum (c) || c == '-' || c == '_' || c == '.'; | |
1444 | } | |
1445 | ||
1446 | /* See command.h. */ | |
5a56e9c5 | 1447 | |
7f008c9e | 1448 | bool |
5a56e9c5 DE |
1449 | valid_user_defined_cmd_name_p (const char *name) |
1450 | { | |
1451 | const char *p; | |
1452 | ||
1453 | if (*name == '\0') | |
7f008c9e | 1454 | return false; |
5a56e9c5 | 1455 | |
5a56e9c5 DE |
1456 | for (p = name; *p != '\0'; ++p) |
1457 | { | |
be09caf1 | 1458 | if (valid_cmd_char_p (*p)) |
5a56e9c5 DE |
1459 | ; /* Ok. */ |
1460 | else | |
7f008c9e | 1461 | return false; |
5a56e9c5 DE |
1462 | } |
1463 | ||
7f008c9e | 1464 | return true; |
5a56e9c5 DE |
1465 | } |
1466 | ||
c906108c SS |
1467 | /* This routine takes a line of TEXT and a CLIST in which to start the |
1468 | lookup. When it returns it will have incremented the text pointer past | |
1469 | the section of text it matched, set *RESULT_LIST to point to the list in | |
1470 | which the last word was matched, and will return a pointer to the cmd | |
1471 | list element which the text matches. It will return NULL if no match at | |
1472 | all was possible. It will return -1 (cast appropriately, ick) if ambigous | |
1473 | matches are possible; in this case *RESULT_LIST will be set to point to | |
1474 | the list in which there are ambiguous choices (and *TEXT will be set to | |
1475 | the ambiguous text string). | |
1476 | ||
1477 | If the located command was an abbreviation, this routine returns the base | |
1478 | command of the abbreviation. | |
1479 | ||
1480 | It does no error reporting whatsoever; control will always return | |
1481 | to the superior routine. | |
1482 | ||
1483 | In the case of an ambiguous return (-1), *RESULT_LIST will be set to point | |
1484 | at the prefix_command (ie. the best match) *or* (special case) will be NULL | |
1485 | if no prefix command was ever found. For example, in the case of "info a", | |
1486 | "info" matches without ambiguity, but "a" could be "args" or "address", so | |
1487 | *RESULT_LIST is set to the cmd_list_element for "info". So in this case | |
4ad2da73 | 1488 | RESULT_LIST should not be interpreted as a pointer to the beginning of a |
c906108c SS |
1489 | list; it simply points to a specific command. In the case of an ambiguous |
1490 | return *TEXT is advanced past the last non-ambiguous prefix (e.g. | |
1491 | "info t" can be "info types" or "info target"; upon return *TEXT has been | |
1492 | advanced past "info "). | |
1493 | ||
1494 | If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise | |
1495 | affect the operation). | |
1496 | ||
1497 | This routine does *not* modify the text pointed to by TEXT. | |
c5aa993b | 1498 | |
c906108c SS |
1499 | If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which |
1500 | are actually help classes rather than commands (i.e. the function field of | |
1501 | the struct cmd_list_element is NULL). */ | |
1502 | ||
1503 | struct cmd_list_element * | |
6f937416 | 1504 | lookup_cmd_1 (const char **text, struct cmd_list_element *clist, |
fba45db2 | 1505 | struct cmd_list_element **result_list, int ignore_help_classes) |
c906108c | 1506 | { |
3386243e | 1507 | char *command; |
798a7429 | 1508 | int len, nfound; |
c906108c | 1509 | struct cmd_list_element *found, *c; |
6f937416 | 1510 | const char *line = *text; |
c906108c SS |
1511 | |
1512 | while (**text == ' ' || **text == '\t') | |
1513 | (*text)++; | |
1514 | ||
3386243e AS |
1515 | /* Identify the name of the command. */ |
1516 | len = find_command_name_length (*text); | |
c906108c SS |
1517 | |
1518 | /* If nothing but whitespace, return 0. */ | |
3386243e | 1519 | if (len == 0) |
c906108c | 1520 | return 0; |
c5aa993b | 1521 | |
c906108c | 1522 | /* *text and p now bracket the first command word to lookup (and |
ebcd3b23 | 1523 | it's length is len). We copy this into a local temporary. */ |
c906108c SS |
1524 | |
1525 | ||
1526 | command = (char *) alloca (len + 1); | |
22ad7fee | 1527 | memcpy (command, *text, len); |
c906108c SS |
1528 | command[len] = '\0'; |
1529 | ||
1530 | /* Look it up. */ | |
1531 | found = 0; | |
1532 | nfound = 0; | |
c5aa993b | 1533 | found = find_cmd (command, len, clist, ignore_help_classes, &nfound); |
c906108c | 1534 | |
c906108c SS |
1535 | /* If nothing matches, we have a simple failure. */ |
1536 | if (nfound == 0) | |
1537 | return 0; | |
1538 | ||
1539 | if (nfound > 1) | |
1540 | { | |
1541 | if (result_list != NULL) | |
1542 | /* Will be modified in calling routine | |
1543 | if we know what the prefix command is. */ | |
c5aa993b | 1544 | *result_list = 0; |
1427fe5e | 1545 | return CMD_LIST_AMBIGUOUS; /* Ambiguous. */ |
c906108c SS |
1546 | } |
1547 | ||
ebcd3b23 | 1548 | /* We've matched something on this list. Move text pointer forward. */ |
c906108c | 1549 | |
3386243e | 1550 | *text += len; |
c906108c | 1551 | |
c906108c | 1552 | if (found->cmd_pointer) |
56382845 | 1553 | { |
ebcd3b23 MS |
1554 | /* We drop the alias (abbreviation) in favor of the command it |
1555 | is pointing to. If the alias is deprecated, though, we need to | |
56382845 FN |
1556 | warn the user about it before we drop it. Note that while we |
1557 | are warning about the alias, we may also warn about the command | |
1558 | itself and we will adjust the appropriate DEPRECATED_WARN_USER | |
ebcd3b23 | 1559 | flags. */ |
56382845 | 1560 | |
1f2bdf09 | 1561 | if (found->deprecated_warn_user) |
6f937416 | 1562 | deprecated_cmd_warning (line); |
56382845 FN |
1563 | found = found->cmd_pointer; |
1564 | } | |
c906108c SS |
1565 | /* If we found a prefix command, keep looking. */ |
1566 | ||
1567 | if (found->prefixlist) | |
1568 | { | |
1569 | c = lookup_cmd_1 (text, *found->prefixlist, result_list, | |
1570 | ignore_help_classes); | |
1571 | if (!c) | |
1572 | { | |
1573 | /* Didn't find anything; this is as far as we got. */ | |
1574 | if (result_list != NULL) | |
1575 | *result_list = clist; | |
1576 | return found; | |
1577 | } | |
1427fe5e | 1578 | else if (c == CMD_LIST_AMBIGUOUS) |
c906108c | 1579 | { |
ebcd3b23 MS |
1580 | /* We've gotten this far properly, but the next step is |
1581 | ambiguous. We need to set the result list to the best | |
c906108c SS |
1582 | we've found (if an inferior hasn't already set it). */ |
1583 | if (result_list != NULL) | |
1584 | if (!*result_list) | |
ebcd3b23 | 1585 | /* This used to say *result_list = *found->prefixlist. |
c5aa993b | 1586 | If that was correct, need to modify the documentation |
ebcd3b23 MS |
1587 | at the top of this function to clarify what is |
1588 | supposed to be going on. */ | |
c906108c SS |
1589 | *result_list = found; |
1590 | return c; | |
1591 | } | |
1592 | else | |
1593 | { | |
1594 | /* We matched! */ | |
1595 | return c; | |
1596 | } | |
1597 | } | |
1598 | else | |
1599 | { | |
1600 | if (result_list != NULL) | |
1601 | *result_list = clist; | |
1602 | return found; | |
1603 | } | |
1604 | } | |
1605 | ||
1606 | /* All this hair to move the space to the front of cmdtype */ | |
1607 | ||
1608 | static void | |
6f937416 | 1609 | undef_cmd_error (const char *cmdtype, const char *q) |
c906108c | 1610 | { |
8a3fe4f8 | 1611 | error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."), |
c5aa993b JM |
1612 | cmdtype, |
1613 | q, | |
1614 | *cmdtype ? " " : "", | |
823ca731 | 1615 | (int) strlen (cmdtype) - 1, |
c5aa993b | 1616 | cmdtype); |
c906108c SS |
1617 | } |
1618 | ||
1619 | /* Look up the contents of *LINE as a command in the command list LIST. | |
1620 | LIST is a chain of struct cmd_list_element's. | |
1621 | If it is found, return the struct cmd_list_element for that command | |
1622 | and update *LINE to point after the command name, at the first argument. | |
1623 | If not found, call error if ALLOW_UNKNOWN is zero | |
1624 | otherwise (or if error returns) return zero. | |
1625 | Call error if specified command is ambiguous, | |
1626 | unless ALLOW_UNKNOWN is negative. | |
1627 | CMDTYPE precedes the word "command" in the error message. | |
1628 | ||
30baf67b | 1629 | If IGNORE_HELP_CLASSES is nonzero, ignore any command list |
c906108c SS |
1630 | elements which are actually help classes rather than commands (i.e. |
1631 | the function field of the struct cmd_list_element is 0). */ | |
1632 | ||
1633 | struct cmd_list_element * | |
a121b7c1 PA |
1634 | lookup_cmd (const char **line, struct cmd_list_element *list, |
1635 | const char *cmdtype, | |
fba45db2 | 1636 | int allow_unknown, int ignore_help_classes) |
c906108c SS |
1637 | { |
1638 | struct cmd_list_element *last_list = 0; | |
3cebf8d8 | 1639 | struct cmd_list_element *c; |
c64601c7 FN |
1640 | |
1641 | /* Note: Do not remove trailing whitespace here because this | |
1642 | would be wrong for complete_command. Jim Kingdon */ | |
c5aa993b | 1643 | |
3cebf8d8 MS |
1644 | if (!*line) |
1645 | error (_("Lack of needed %scommand"), cmdtype); | |
1646 | ||
1647 | c = lookup_cmd_1 (line, list, &last_list, ignore_help_classes); | |
1648 | ||
c906108c SS |
1649 | if (!c) |
1650 | { | |
1651 | if (!allow_unknown) | |
1652 | { | |
3cebf8d8 MS |
1653 | char *q; |
1654 | int len = find_command_name_length (*line); | |
c906108c | 1655 | |
3cebf8d8 MS |
1656 | q = (char *) alloca (len + 1); |
1657 | strncpy (q, *line, len); | |
1658 | q[len] = '\0'; | |
1659 | undef_cmd_error (cmdtype, q); | |
c906108c SS |
1660 | } |
1661 | else | |
1662 | return 0; | |
1663 | } | |
1427fe5e | 1664 | else if (c == CMD_LIST_AMBIGUOUS) |
c906108c SS |
1665 | { |
1666 | /* Ambigous. Local values should be off prefixlist or called | |
c5aa993b | 1667 | values. */ |
c906108c SS |
1668 | int local_allow_unknown = (last_list ? last_list->allow_unknown : |
1669 | allow_unknown); | |
64e61d29 | 1670 | const char *local_cmdtype = last_list ? last_list->prefixname : cmdtype; |
c906108c | 1671 | struct cmd_list_element *local_list = |
cdb27c12 | 1672 | (last_list ? *(last_list->prefixlist) : list); |
c5aa993b | 1673 | |
c906108c SS |
1674 | if (local_allow_unknown < 0) |
1675 | { | |
1676 | if (last_list) | |
1677 | return last_list; /* Found something. */ | |
1678 | else | |
1679 | return 0; /* Found nothing. */ | |
1680 | } | |
1681 | else | |
1682 | { | |
1683 | /* Report as error. */ | |
1684 | int amb_len; | |
1685 | char ambbuf[100]; | |
1686 | ||
1687 | for (amb_len = 0; | |
1688 | ((*line)[amb_len] && (*line)[amb_len] != ' ' | |
1689 | && (*line)[amb_len] != '\t'); | |
1690 | amb_len++) | |
1691 | ; | |
c5aa993b | 1692 | |
c906108c SS |
1693 | ambbuf[0] = 0; |
1694 | for (c = local_list; c; c = c->next) | |
1695 | if (!strncmp (*line, c->name, amb_len)) | |
1696 | { | |
9a2b4c1b MS |
1697 | if (strlen (ambbuf) + strlen (c->name) + 6 |
1698 | < (int) sizeof ambbuf) | |
c906108c SS |
1699 | { |
1700 | if (strlen (ambbuf)) | |
1701 | strcat (ambbuf, ", "); | |
1702 | strcat (ambbuf, c->name); | |
1703 | } | |
1704 | else | |
1705 | { | |
1706 | strcat (ambbuf, ".."); | |
1707 | break; | |
1708 | } | |
1709 | } | |
8a3fe4f8 | 1710 | error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype, |
c906108c | 1711 | *line, ambbuf); |
c906108c SS |
1712 | } |
1713 | } | |
1714 | else | |
1715 | { | |
bf9e4d0c MB |
1716 | if (c->type == set_cmd && **line != '\0' && !isspace (**line)) |
1717 | error (_("Argument must be preceded by space.")); | |
1718 | ||
c906108c SS |
1719 | /* We've got something. It may still not be what the caller |
1720 | wants (if this command *needs* a subcommand). */ | |
1721 | while (**line == ' ' || **line == '\t') | |
1722 | (*line)++; | |
1723 | ||
1724 | if (c->prefixlist && **line && !c->allow_unknown) | |
1725 | undef_cmd_error (c->prefixname, *line); | |
1726 | ||
1727 | /* Seems to be what he wants. Return it. */ | |
1728 | return c; | |
1729 | } | |
1730 | return 0; | |
1731 | } | |
c5aa993b | 1732 | |
6f937416 | 1733 | /* We are here presumably because an alias or command in TEXT is |
ebcd3b23 | 1734 | deprecated and a warning message should be generated. This |
6f937416 | 1735 | function decodes TEXT and potentially generates a warning message |
ebcd3b23 | 1736 | as outlined below. |
56382845 FN |
1737 | |
1738 | Example for 'set endian big' which has a fictitious alias 'seb'. | |
1739 | ||
6f937416 | 1740 | If alias wasn't used in TEXT, and the command is deprecated: |
56382845 FN |
1741 | "warning: 'set endian big' is deprecated." |
1742 | ||
1743 | If alias was used, and only the alias is deprecated: | |
1744 | "warning: 'seb' an alias for the command 'set endian big' is deprecated." | |
1745 | ||
ebcd3b23 MS |
1746 | If alias was used and command is deprecated (regardless of whether |
1747 | the alias itself is deprecated: | |
56382845 FN |
1748 | |
1749 | "warning: 'set endian big' (seb) is deprecated." | |
1750 | ||
1751 | After the message has been sent, clear the appropriate flags in the | |
1752 | command and/or the alias so the user is no longer bothered. | |
1753 | ||
1754 | */ | |
1755 | void | |
6f937416 | 1756 | deprecated_cmd_warning (const char *text) |
56382845 FN |
1757 | { |
1758 | struct cmd_list_element *alias = NULL; | |
1759 | struct cmd_list_element *prefix_cmd = NULL; | |
1760 | struct cmd_list_element *cmd = NULL; | |
edefbb7c | 1761 | |
6f937416 | 1762 | if (!lookup_cmd_composition (text, &alias, &prefix_cmd, &cmd)) |
ebcd3b23 | 1763 | /* Return if text doesn't evaluate to a command. */ |
56382845 FN |
1764 | return; |
1765 | ||
1f2bdf09 TT |
1766 | if (!((alias ? alias->deprecated_warn_user : 0) |
1767 | || cmd->deprecated_warn_user) ) | |
ebcd3b23 | 1768 | /* Return if nothing is deprecated. */ |
56382845 FN |
1769 | return; |
1770 | ||
1771 | printf_filtered ("Warning:"); | |
1772 | ||
1f2bdf09 | 1773 | if (alias && !cmd->cmd_deprecated) |
56382845 FN |
1774 | printf_filtered (" '%s', an alias for the", alias->name); |
1775 | ||
1776 | printf_filtered (" command '"); | |
1777 | ||
1778 | if (prefix_cmd) | |
1779 | printf_filtered ("%s", prefix_cmd->prefixname); | |
1780 | ||
1781 | printf_filtered ("%s", cmd->name); | |
1782 | ||
1f2bdf09 | 1783 | if (alias && cmd->cmd_deprecated) |
56382845 FN |
1784 | printf_filtered ("' (%s) is deprecated.\n", alias->name); |
1785 | else | |
1786 | printf_filtered ("' is deprecated.\n"); | |
1787 | ||
1788 | ||
ebcd3b23 MS |
1789 | /* If it is only the alias that is deprecated, we want to indicate |
1790 | the new alias, otherwise we'll indicate the new command. */ | |
56382845 | 1791 | |
1f2bdf09 | 1792 | if (alias && !cmd->cmd_deprecated) |
56382845 FN |
1793 | { |
1794 | if (alias->replacement) | |
cdb27c12 | 1795 | printf_filtered ("Use '%s'.\n\n", alias->replacement); |
56382845 | 1796 | else |
cdb27c12 | 1797 | printf_filtered ("No alternative known.\n\n"); |
56382845 FN |
1798 | } |
1799 | else | |
1800 | { | |
1801 | if (cmd->replacement) | |
cdb27c12 | 1802 | printf_filtered ("Use '%s'.\n\n", cmd->replacement); |
56382845 | 1803 | else |
cdb27c12 | 1804 | printf_filtered ("No alternative known.\n\n"); |
56382845 FN |
1805 | } |
1806 | ||
ebcd3b23 | 1807 | /* We've warned you, now we'll keep quiet. */ |
56382845 | 1808 | if (alias) |
1f2bdf09 | 1809 | alias->deprecated_warn_user = 0; |
56382845 | 1810 | |
1f2bdf09 | 1811 | cmd->deprecated_warn_user = 0; |
56382845 FN |
1812 | } |
1813 | ||
1814 | ||
bc3609fd | 1815 | /* Look up the contents of TEXT as a command in the command list 'cmdlist'. |
56382845 | 1816 | Return 1 on success, 0 on failure. |
bc3609fd PW |
1817 | |
1818 | If TEXT refers to an alias, *ALIAS will point to that alias. | |
1819 | ||
1820 | If TEXT is a subcommand (i.e. one that is preceded by a prefix | |
1821 | command) set *PREFIX_CMD. | |
1822 | ||
1823 | Set *CMD to point to the command TEXT indicates. | |
1824 | ||
1825 | If any of *ALIAS, *PREFIX_CMD, or *CMD cannot be determined or do not | |
56382845 | 1826 | exist, they are NULL when we return. |
bc3609fd | 1827 | |
56382845 FN |
1828 | */ |
1829 | int | |
6f937416 | 1830 | lookup_cmd_composition (const char *text, |
bc3609fd PW |
1831 | struct cmd_list_element **alias, |
1832 | struct cmd_list_element **prefix_cmd, | |
1833 | struct cmd_list_element **cmd) | |
56382845 | 1834 | { |
3386243e | 1835 | char *command; |
798a7429 | 1836 | int len, nfound; |
56382845 FN |
1837 | struct cmd_list_element *cur_list; |
1838 | struct cmd_list_element *prev_cmd; | |
cdb27c12 | 1839 | |
56382845 FN |
1840 | *alias = NULL; |
1841 | *prefix_cmd = NULL; | |
1842 | *cmd = NULL; | |
bc3609fd | 1843 | |
56382845 | 1844 | cur_list = cmdlist; |
bc3609fd | 1845 | |
56382845 | 1846 | while (1) |
bc3609fd | 1847 | { |
7a9dd1b2 | 1848 | /* Go through as many command lists as we need to, |
ebcd3b23 | 1849 | to find the command TEXT refers to. */ |
bc3609fd | 1850 | |
56382845 | 1851 | prev_cmd = *cmd; |
bc3609fd | 1852 | |
56382845 | 1853 | while (*text == ' ' || *text == '\t') |
cdb27c12 | 1854 | (text)++; |
bc3609fd | 1855 | |
3386243e AS |
1856 | /* Identify the name of the command. */ |
1857 | len = find_command_name_length (text); | |
bc3609fd | 1858 | |
56382845 | 1859 | /* If nothing but whitespace, return. */ |
3386243e AS |
1860 | if (len == 0) |
1861 | return 0; | |
bc3609fd PW |
1862 | |
1863 | /* TEXT is the start of the first command word to lookup (and | |
cdb27c12 | 1864 | it's length is len). We copy this into a local temporary. */ |
bc3609fd | 1865 | |
56382845 | 1866 | command = (char *) alloca (len + 1); |
22ad7fee | 1867 | memcpy (command, text, len); |
56382845 | 1868 | command[len] = '\0'; |
bc3609fd | 1869 | |
56382845 FN |
1870 | /* Look it up. */ |
1871 | *cmd = 0; | |
1872 | nfound = 0; | |
1873 | *cmd = find_cmd (command, len, cur_list, 1, &nfound); | |
bc3609fd | 1874 | |
1427fe5e | 1875 | if (*cmd == CMD_LIST_AMBIGUOUS) |
cdb27c12 MS |
1876 | { |
1877 | return 0; /* ambiguous */ | |
1878 | } | |
bc3609fd | 1879 | |
56382845 | 1880 | if (*cmd == NULL) |
cdb27c12 | 1881 | return 0; /* nothing found */ |
56382845 | 1882 | else |
cdb27c12 MS |
1883 | { |
1884 | if ((*cmd)->cmd_pointer) | |
1885 | { | |
ebcd3b23 | 1886 | /* cmd was actually an alias, we note that an alias was |
bc3609fd | 1887 | used (by assigning *ALIAS) and we set *CMD. */ |
cdb27c12 MS |
1888 | *alias = *cmd; |
1889 | *cmd = (*cmd)->cmd_pointer; | |
1890 | } | |
1891 | *prefix_cmd = prev_cmd; | |
1892 | } | |
56382845 | 1893 | if ((*cmd)->prefixlist) |
cdb27c12 | 1894 | cur_list = *(*cmd)->prefixlist; |
56382845 | 1895 | else |
cdb27c12 | 1896 | return 1; |
bc3609fd | 1897 | |
3386243e | 1898 | text += len; |
56382845 FN |
1899 | } |
1900 | } | |
1901 | ||
c906108c SS |
1902 | /* Helper function for SYMBOL_COMPLETION_FUNCTION. */ |
1903 | ||
1904 | /* Return a vector of char pointers which point to the different | |
ebcd3b23 | 1905 | possible completions in LIST of TEXT. |
c906108c SS |
1906 | |
1907 | WORD points in the same buffer as TEXT, and completions should be | |
ebcd3b23 MS |
1908 | returned relative to this position. For example, suppose TEXT is |
1909 | "foo" and we want to complete to "foobar". If WORD is "oo", return | |
c906108c SS |
1910 | "oobar"; if WORD is "baz/foo", return "baz/foobar". */ |
1911 | ||
eb3ff9a5 | 1912 | void |
6f937416 | 1913 | complete_on_cmdlist (struct cmd_list_element *list, |
eb3ff9a5 | 1914 | completion_tracker &tracker, |
6f937416 | 1915 | const char *text, const char *word, |
ace21957 | 1916 | int ignore_help_classes) |
c906108c SS |
1917 | { |
1918 | struct cmd_list_element *ptr; | |
c906108c | 1919 | int textlen = strlen (text); |
3f172e24 TT |
1920 | int pass; |
1921 | int saw_deprecated_match = 0; | |
c906108c | 1922 | |
3f172e24 TT |
1923 | /* We do one or two passes. In the first pass, we skip deprecated |
1924 | commands. If we see no matching commands in the first pass, and | |
1925 | if we did happen to see a matching deprecated command, we do | |
1926 | another loop to collect those. */ | |
eb3ff9a5 | 1927 | for (pass = 0; pass < 2; ++pass) |
3f172e24 | 1928 | { |
eb3ff9a5 PA |
1929 | bool got_matches = false; |
1930 | ||
3f172e24 TT |
1931 | for (ptr = list; ptr; ptr = ptr->next) |
1932 | if (!strncmp (ptr->name, text, textlen) | |
1933 | && !ptr->abbrev_flag | |
ace21957 | 1934 | && (!ignore_help_classes || ptr->func |
3f172e24 | 1935 | || ptr->prefixlist)) |
c906108c | 1936 | { |
3f172e24 TT |
1937 | if (pass == 0) |
1938 | { | |
1f2bdf09 | 1939 | if (ptr->cmd_deprecated) |
3f172e24 TT |
1940 | { |
1941 | saw_deprecated_match = 1; | |
1942 | continue; | |
1943 | } | |
1944 | } | |
c906108c | 1945 | |
60a20c19 PA |
1946 | tracker.add_completion |
1947 | (make_completion_match_str (ptr->name, text, word)); | |
eb3ff9a5 | 1948 | got_matches = true; |
c906108c | 1949 | } |
eb3ff9a5 PA |
1950 | |
1951 | if (got_matches) | |
1952 | break; | |
1953 | ||
3f172e24 TT |
1954 | /* If we saw no matching deprecated commands in the first pass, |
1955 | just bail out. */ | |
1956 | if (!saw_deprecated_match) | |
1957 | break; | |
1958 | } | |
c906108c SS |
1959 | } |
1960 | ||
1961 | /* Helper function for SYMBOL_COMPLETION_FUNCTION. */ | |
1962 | ||
eb3ff9a5 | 1963 | /* Add the different possible completions in ENUMLIST of TEXT. |
c906108c SS |
1964 | |
1965 | WORD points in the same buffer as TEXT, and completions should be | |
1966 | returned relative to this position. For example, suppose TEXT is "foo" | |
1967 | and we want to complete to "foobar". If WORD is "oo", return | |
1968 | "oobar"; if WORD is "baz/foo", return "baz/foobar". */ | |
1969 | ||
eb3ff9a5 PA |
1970 | void |
1971 | complete_on_enum (completion_tracker &tracker, | |
1972 | const char *const *enumlist, | |
6f937416 | 1973 | const char *text, const char *word) |
c906108c | 1974 | { |
c906108c SS |
1975 | int textlen = strlen (text); |
1976 | int i; | |
53904c9e | 1977 | const char *name; |
c906108c | 1978 | |
c906108c SS |
1979 | for (i = 0; (name = enumlist[i]) != NULL; i++) |
1980 | if (strncmp (name, text, textlen) == 0) | |
60a20c19 | 1981 | tracker.add_completion (make_completion_match_str (name, text, word)); |
c906108c SS |
1982 | } |
1983 | ||
f436dd25 | 1984 | |
ebcd3b23 | 1985 | /* Check function pointer. */ |
f436dd25 MH |
1986 | int |
1987 | cmd_func_p (struct cmd_list_element *cmd) | |
1988 | { | |
1989 | return (cmd->func != NULL); | |
1990 | } | |
1991 | ||
1992 | ||
ebcd3b23 | 1993 | /* Call the command function. */ |
f436dd25 | 1994 | void |
95a6b0a1 | 1995 | cmd_func (struct cmd_list_element *cmd, const char *args, int from_tty) |
f436dd25 MH |
1996 | { |
1997 | if (cmd_func_p (cmd)) | |
4034d0ff | 1998 | { |
156d9eab | 1999 | gdb::optional<scoped_restore_tmpl<int>> restore_suppress; |
4034d0ff AT |
2000 | |
2001 | if (cmd->suppress_notification != NULL) | |
156d9eab | 2002 | restore_suppress.emplace (cmd->suppress_notification, 1); |
4034d0ff AT |
2003 | |
2004 | (*cmd->func) (cmd, args, from_tty); | |
4034d0ff | 2005 | } |
f436dd25 | 2006 | else |
8a3fe4f8 | 2007 | error (_("Invalid command")); |
f436dd25 | 2008 | } |
a9f116cb GKB |
2009 | |
2010 | int | |
2011 | cli_user_command_p (struct cmd_list_element *cmd) | |
2012 | { | |
fe978cb0 | 2013 | return (cmd->theclass == class_user |
5fed81ff | 2014 | && (cmd->func == do_const_cfunc || cmd->func == do_sfunc)); |
a9f116cb | 2015 | } |