1 /* Header file for command creation.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
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
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #if !defined (COMMAND_H)
22 #include "common/scoped_restore.h"
24 struct completion_tracker;
26 /* This file defines the public interface for any code wanting to
29 /* Command classes are top-level categories into which commands are
30 broken down for "help" purposes.
32 Notes on classes: class_alias is for alias commands which are not
33 abbreviations of the original command. class-pseudo is for
34 commands which are not really commands nor help topics ("stop"). */
38 /* Special args to help_list */
39 class_deprecated = -3, all_classes = -2, all_commands = -1,
40 /* Classes of commands */
41 no_class = -1, class_run = 0, class_vars, class_stack, class_files,
42 class_support, class_info, class_breakpoint, class_trace,
43 class_alias, class_bookmark, class_obscure, class_maintenance,
44 class_pseudo, class_tui, class_user, class_xdb,
45 no_set_class /* Used for "show" commands that have no corresponding
49 /* FIXME: cagney/2002-03-17: Once cmd_type() has been removed, ``enum
50 cmd_types'' can be moved from "command.h" to "cli-decode.h". */
51 /* Not a set/show command. Note that some commands which begin with
52 "set" or "show" might be in this category, if their syntax does
53 not fall into one of the following categories. */
54 typedef enum cmd_types
62 /* Types of "set" or "show" command. */
63 typedef enum var_types
65 /* "on" or "off". *VAR is an integer which is nonzero for on,
69 /* "on" / "true" / "enable" or "off" / "false" / "disable" or
70 "auto. *VAR is an ``enum auto_boolean''. NOTE: In general a
71 custom show command will need to be implemented - one that for
72 "auto" prints both the "auto" and the current auto-selected
76 /* Unsigned Integer. *VAR is an unsigned int. The user can type
77 0 to mean "unlimited", which is stored in *VAR as UINT_MAX. */
80 /* Like var_uinteger but signed. *VAR is an int. The user can
81 type 0 to mean "unlimited", which is stored in *VAR as
82 INT_MAX. The only remaining use of it is the Python API.
83 Don't use it elsewhere. */
86 /* String which the user enters with escapes (e.g. the user types
87 \n and it is a real newline in the stored string).
88 *VAR is a malloc'd string, or NULL if the string is empty. */
90 /* String which stores what the user types verbatim.
91 *VAR is a malloc'd string, or NULL if the string is empty. */
93 /* String which stores a filename. (*VAR) is a malloc'd string,
94 or "" if the string was empty. */
95 var_optional_filename,
96 /* String which stores a filename. (*VAR) is a malloc'd
99 /* ZeroableInteger. *VAR is an int. Like var_integer except
100 that zero really means zero. */
102 /* ZeroableUnsignedInteger. *VAR is an unsigned int. Zero really
105 /* ZeroableUnsignedInteger with unlimited value. *VAR is an int,
106 but its range is [0, INT_MAX]. -1 stands for unlimited and
107 other negative numbers are not allowed. */
108 var_zuinteger_unlimited,
109 /* Enumerated type. Can only have one of the specified values.
110 *VAR is a char pointer to the name of the element that we
116 /* This structure records one command'd definition. */
117 struct cmd_list_element;
119 typedef void cmd_cfunc_ftype (char *args, int from_tty);
121 /* This structure specifies notifications to be suppressed by a cli
122 command interpreter. */
124 struct cli_suppress_notification
126 /* Inferior, thread, frame selected notification suppressed? */
127 int user_selected_context;
130 extern struct cli_suppress_notification cli_suppress_notification;
132 /* Forward-declarations of the entry-points of cli/cli-decode.c. */
134 /* API to the manipulation of command lists. */
136 extern int valid_user_defined_cmd_name_p (const char *name);
138 extern struct cmd_list_element *add_cmd (const char *, enum command_class,
139 cmd_cfunc_ftype *fun,
141 struct cmd_list_element **);
143 extern struct cmd_list_element *add_alias_cmd (const char *, const char *,
144 enum command_class, int,
145 struct cmd_list_element **);
147 extern struct cmd_list_element *add_alias_cmd (const char *,
149 enum command_class, int,
150 struct cmd_list_element **);
153 extern struct cmd_list_element *add_prefix_cmd (const char *, enum command_class,
154 cmd_cfunc_ftype *fun,
156 struct cmd_list_element **,
158 struct cmd_list_element **);
160 extern struct cmd_list_element *add_abbrev_prefix_cmd (const char *,
162 cmd_cfunc_ftype *fun,
164 struct cmd_list_element
165 **, const char *, int,
166 struct cmd_list_element
169 /* Set the commands corresponding callback. */
171 extern void set_cmd_cfunc (struct cmd_list_element *cmd,
172 cmd_cfunc_ftype *cfunc);
174 typedef void cmd_sfunc_ftype (char *args, int from_tty,
175 struct cmd_list_element *c);
176 extern void set_cmd_sfunc (struct cmd_list_element *cmd,
177 cmd_sfunc_ftype *sfunc);
179 /* A completion routine. Add possible completions to tracker.
181 TEXT is the text beyond what was matched for the command itself
182 (leading whitespace is skipped). It stops where we are supposed to
183 stop completing (rl_point) and is '\0' terminated. WORD points in
184 the same buffer as TEXT, and completions should be returned
185 relative to this position. For example, suppose TEXT is "foo" and
186 we want to complete to "foobar". If WORD is "oo", return "oobar";
187 if WORD is "baz/foo", return "baz/foobar". */
188 typedef void completer_ftype (struct cmd_list_element *,
189 completion_tracker &tracker,
190 const char *text, const char *word);
192 /* Same, but for set_cmd_completer_handle_brkchars. */
193 typedef void completer_handle_brkchars_ftype (struct cmd_list_element *,
194 completion_tracker &tracker,
195 const char *text, const char *word);
197 extern void set_cmd_completer (struct cmd_list_element *, completer_ftype *);
199 /* Set the completer_handle_brkchars callback. */
201 extern void set_cmd_completer_handle_brkchars (struct cmd_list_element *,
202 completer_handle_brkchars_ftype *);
204 /* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs
205 around in cmd objects to test the value of the commands sfunc(). */
206 extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
207 cmd_cfunc_ftype *cfun);
209 /* Each command object has a local context attached to it. */
210 extern void set_cmd_context (struct cmd_list_element *cmd,
212 extern void *get_cmd_context (struct cmd_list_element *cmd);
215 /* Execute CMD's pre/post hook. Throw an error if the command fails.
216 If already executing this pre/post hook, or there is no pre/post
217 hook, the call is silently ignored. */
218 extern void execute_cmd_pre_hook (struct cmd_list_element *cmd);
219 extern void execute_cmd_post_hook (struct cmd_list_element *cmd);
221 /* Return the type of the command. */
222 extern enum cmd_types cmd_type (struct cmd_list_element *cmd);
224 /* Flag for an ambiguous cmd_list result. */
225 #define CMD_LIST_AMBIGUOUS ((struct cmd_list_element *) -1)
227 extern struct cmd_list_element *lookup_cmd (const char **,
228 struct cmd_list_element *,
232 extern struct cmd_list_element *lookup_cmd_1 (const char **,
233 struct cmd_list_element *,
234 struct cmd_list_element **,
237 extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *,
240 extern void deprecated_cmd_warning (const char *);
242 extern int lookup_cmd_composition (const char *text,
243 struct cmd_list_element **alias,
244 struct cmd_list_element **prefix_cmd,
245 struct cmd_list_element **cmd);
247 extern struct cmd_list_element *add_com (const char *, enum command_class,
248 cmd_cfunc_ftype *fun,
251 extern struct cmd_list_element *add_com_alias (const char *, const char *,
252 enum command_class, int);
254 extern struct cmd_list_element *add_com_suppress_notification
255 (const char *name, enum command_class theclass,
256 cmd_cfunc_ftype *fun, const char *doc,
257 int *supress_notification);
259 extern struct cmd_list_element *add_info (const char *,
260 cmd_cfunc_ftype *fun,
263 extern struct cmd_list_element *add_info_alias (const char *, const char *,
266 extern void complete_on_cmdlist (struct cmd_list_element *,
267 completion_tracker &tracker,
268 const char *, const char *, int);
270 extern void complete_on_enum (completion_tracker &tracker,
271 const char *const *enumlist,
272 const char *, const char *);
274 /* Functions that implement commands about CLI commands. */
276 extern void help_list (struct cmd_list_element *, const char *,
277 enum command_class, struct ui_file *);
279 /* Method for show a set/show variable's VALUE on FILE. If this
280 method isn't supplied deprecated_show_value_hack() is called (which
282 typedef void (show_value_ftype) (struct ui_file *file,
284 struct cmd_list_element *cmd,
286 /* NOTE: i18n: This function is not i18n friendly. Callers should
287 instead print the value out directly. */
288 extern show_value_ftype deprecated_show_value_hack;
290 extern void add_setshow_enum_cmd (const char *name,
291 enum command_class theclass,
292 const char *const *enumlist,
295 const char *show_doc,
296 const char *help_doc,
297 cmd_sfunc_ftype *set_func,
298 show_value_ftype *show_func,
299 struct cmd_list_element **set_list,
300 struct cmd_list_element **show_list);
302 extern void add_setshow_auto_boolean_cmd (const char *name,
303 enum command_class theclass,
304 enum auto_boolean *var,
306 const char *show_doc,
307 const char *help_doc,
308 cmd_sfunc_ftype *set_func,
309 show_value_ftype *show_func,
310 struct cmd_list_element **set_list,
311 struct cmd_list_element **show_list);
313 extern void add_setshow_boolean_cmd (const char *name,
314 enum command_class theclass,
316 const char *set_doc, const char *show_doc,
317 const char *help_doc,
318 cmd_sfunc_ftype *set_func,
319 show_value_ftype *show_func,
320 struct cmd_list_element **set_list,
321 struct cmd_list_element **show_list);
323 extern void add_setshow_filename_cmd (const char *name,
324 enum command_class theclass,
327 const char *show_doc,
328 const char *help_doc,
329 cmd_sfunc_ftype *set_func,
330 show_value_ftype *show_func,
331 struct cmd_list_element **set_list,
332 struct cmd_list_element **show_list);
334 extern void add_setshow_string_cmd (const char *name,
335 enum command_class theclass,
338 const char *show_doc,
339 const char *help_doc,
340 cmd_sfunc_ftype *set_func,
341 show_value_ftype *show_func,
342 struct cmd_list_element **set_list,
343 struct cmd_list_element **show_list);
345 extern struct cmd_list_element *add_setshow_string_noescape_cmd
347 enum command_class theclass,
350 const char *show_doc,
351 const char *help_doc,
352 cmd_sfunc_ftype *set_func,
353 show_value_ftype *show_func,
354 struct cmd_list_element **set_list,
355 struct cmd_list_element **show_list);
357 extern void add_setshow_optional_filename_cmd (const char *name,
358 enum command_class theclass,
361 const char *show_doc,
362 const char *help_doc,
363 cmd_sfunc_ftype *set_func,
364 show_value_ftype *show_func,
365 struct cmd_list_element **set_list,
366 struct cmd_list_element **show_list);
368 extern void add_setshow_integer_cmd (const char *name,
369 enum command_class theclass,
372 const char *show_doc,
373 const char *help_doc,
374 cmd_sfunc_ftype *set_func,
375 show_value_ftype *show_func,
376 struct cmd_list_element **set_list,
377 struct cmd_list_element **show_list);
379 extern void add_setshow_uinteger_cmd (const char *name,
380 enum command_class theclass,
383 const char *show_doc,
384 const char *help_doc,
385 cmd_sfunc_ftype *set_func,
386 show_value_ftype *show_func,
387 struct cmd_list_element **set_list,
388 struct cmd_list_element **show_list);
390 extern void add_setshow_zinteger_cmd (const char *name,
391 enum command_class theclass,
394 const char *show_doc,
395 const char *help_doc,
396 cmd_sfunc_ftype *set_func,
397 show_value_ftype *show_func,
398 struct cmd_list_element **set_list,
399 struct cmd_list_element **show_list);
401 extern void add_setshow_zuinteger_cmd (const char *name,
402 enum command_class theclass,
405 const char *show_doc,
406 const char *help_doc,
407 cmd_sfunc_ftype *set_func,
408 show_value_ftype *show_func,
409 struct cmd_list_element **set_list,
410 struct cmd_list_element **show_list);
413 add_setshow_zuinteger_unlimited_cmd (const char *name,
414 enum command_class theclass,
417 const char *show_doc,
418 const char *help_doc,
419 cmd_sfunc_ftype *set_func,
420 show_value_ftype *show_func,
421 struct cmd_list_element **set_list,
422 struct cmd_list_element **show_list);
424 /* Do a "show" command for each thing on a command list. */
426 extern void cmd_show_list (struct cmd_list_element *, int, const char *);
428 /* Used everywhere whenever at least one parameter is required and
429 none is specified. */
431 extern void error_no_arg (const char *) ATTRIBUTE_NORETURN;
433 extern void dont_repeat (void);
435 extern scoped_restore_tmpl<int> prevent_dont_repeat (void);
437 /* Used to mark commands that don't do anything. If we just leave the
438 function field NULL, the command is interpreted as a help topic, or
439 as a class of commands. */
441 extern void not_just_help_class_command (char *, int);
443 /* Check function pointer. */
444 extern int cmd_func_p (struct cmd_list_element *cmd);
446 /* Call the command function. */
447 extern void cmd_func (struct cmd_list_element *cmd,
448 char *args, int from_tty);
450 #endif /* !defined (COMMAND_H) */