1 /* Header file for command creation.
3 Copyright (C) 1986, 1989-1995, 1999-2000, 2002, 2004, 2007-2012 Free
4 Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #if !defined (COMMAND_H)
22 /* This file defines the public interface for any code wanting to
25 /* Command classes are top-level categories into which commands are
26 broken down for "help" purposes.
28 Notes on classes: class_alias is for alias commands which are not
29 abbreviations of the original command. class-pseudo is for
30 commands which are not really commands nor help topics ("stop"). */
34 /* Special args to help_list */
35 class_deprecated = -3, all_classes = -2, all_commands = -1,
36 /* Classes of commands */
37 no_class = -1, class_run = 0, class_vars, class_stack, class_files,
38 class_support, class_info, class_breakpoint, class_trace,
39 class_alias, class_bookmark, class_obscure, class_maintenance,
40 class_pseudo, class_tui, class_user, class_xdb,
41 no_set_class /* Used for "show" commands that have no corresponding
45 /* FIXME: cagney/2002-03-17: Once cmd_type() has been removed, ``enum
46 cmd_types'' can be moved from "command.h" to "cli-decode.h". */
47 /* Not a set/show command. Note that some commands which begin with
48 "set" or "show" might be in this category, if their syntax does
49 not fall into one of the following categories. */
50 typedef enum cmd_types
58 /* Types of "set" or "show" command. */
59 typedef enum var_types
61 /* "on" or "off". *VAR is an integer which is nonzero for on,
65 /* "on" / "true" / "enable" or "off" / "false" / "disable" or
66 "auto. *VAR is an ``enum auto_boolean''. NOTE: In general a
67 custom show command will need to be implemented - one that for
68 "auto" prints both the "auto" and the current auto-selected
72 /* Unsigned Integer. *VAR is an unsigned int. The user can type
73 0 to mean "unlimited", which is stored in *VAR as UINT_MAX. */
76 /* Like var_uinteger but signed. *VAR is an int. The user can
77 type 0 to mean "unlimited", which is stored in *VAR as
81 /* String which the user enters with escapes (e.g. the user types
82 \n and it is a real newline in the stored string).
83 *VAR is a malloc'd string, or NULL if the string is empty. */
85 /* String which stores what the user types verbatim.
86 *VAR is a malloc'd string, or NULL if the string is empty. */
88 /* String which stores a filename. (*VAR) is a malloc'd string,
89 or "" if the string was empty. */
90 var_optional_filename,
91 /* String which stores a filename. (*VAR) is a malloc'd
94 /* ZeroableInteger. *VAR is an int. Like Unsigned Integer except
95 that zero really means zero. */
97 /* ZeroableUnsignedInteger. *VAR is an unsigned int. Zero really
100 /* Enumerated type. Can only have one of the specified values.
101 *VAR is a char pointer to the name of the element that we
107 /* This structure records one command'd definition. */
108 struct cmd_list_element;
110 /* Forward-declarations of the entry-points of cli/cli-decode.c. */
112 /* API to the manipulation of command lists. */
114 extern int valid_user_defined_cmd_name_p (const char *name);
116 extern struct cmd_list_element *add_cmd (char *, enum command_class,
117 void (*fun) (char *, int), char *,
118 struct cmd_list_element **);
120 extern struct cmd_list_element *add_alias_cmd (char *, char *,
121 enum command_class, int,
122 struct cmd_list_element **);
124 extern struct cmd_list_element *add_prefix_cmd (char *, enum command_class,
125 void (*fun) (char *, int),
127 struct cmd_list_element **,
129 struct cmd_list_element **);
131 extern struct cmd_list_element *add_abbrev_prefix_cmd (char *,
136 struct cmd_list_element
138 struct cmd_list_element
141 /* Set the commands corresponding callback. */
143 typedef void cmd_cfunc_ftype (char *args, int from_tty);
144 extern void set_cmd_cfunc (struct cmd_list_element *cmd,
145 cmd_cfunc_ftype *cfunc);
147 typedef void cmd_sfunc_ftype (char *args, int from_tty,
148 struct cmd_list_element *c);
149 extern void set_cmd_sfunc (struct cmd_list_element *cmd,
150 cmd_sfunc_ftype *sfunc);
152 extern void set_cmd_completer (struct cmd_list_element *,
153 char **(*completer) (struct cmd_list_element *,
156 /* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs
157 around in cmd objects to test the value of the commands sfunc(). */
158 extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
159 void (*cfunc) (char *args, int from_tty));
161 /* Each command object has a local context attached to it. */
162 extern void set_cmd_context (struct cmd_list_element *cmd,
164 extern void *get_cmd_context (struct cmd_list_element *cmd);
167 /* Execute CMD's pre/post hook. Throw an error if the command fails.
168 If already executing this pre/post hook, or there is no pre/post
169 hook, the call is silently ignored. */
170 extern void execute_cmd_pre_hook (struct cmd_list_element *cmd);
171 extern void execute_cmd_post_hook (struct cmd_list_element *cmd);
173 /* Return the type of the command. */
174 extern enum cmd_types cmd_type (struct cmd_list_element *cmd);
176 /* Flag for an ambiguous cmd_list result. */
177 #define CMD_LIST_AMBIGUOUS ((struct cmd_list_element *) -1)
179 extern struct cmd_list_element *lookup_cmd (char **,
180 struct cmd_list_element *, char *,
183 extern struct cmd_list_element *lookup_cmd_1 (char **,
184 struct cmd_list_element *,
185 struct cmd_list_element **,
188 extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *,
191 extern void deprecated_cmd_warning (char **);
193 extern int lookup_cmd_composition (char *text,
194 struct cmd_list_element **alias,
195 struct cmd_list_element **prefix_cmd,
196 struct cmd_list_element **cmd);
198 extern struct cmd_list_element *add_com (char *, enum command_class,
199 void (*fun) (char *, int),
202 extern struct cmd_list_element *add_com_alias (char *, char *,
203 enum command_class, int);
205 extern struct cmd_list_element *add_info (char *,
206 void (*fun) (char *, int),
209 extern struct cmd_list_element *add_info_alias (char *, char *, int);
211 extern char **complete_on_cmdlist (struct cmd_list_element *,
214 extern char **complete_on_enum (const char *const *enumlist,
217 /* Functions that implement commands about CLI commands. */
219 extern void help_list (struct cmd_list_element *, char *,
220 enum command_class, struct ui_file *);
222 /* Method for show a set/show variable's VALUE on FILE. If this
223 method isn't supplied deprecated_show_value_hack() is called (which
225 typedef void (show_value_ftype) (struct ui_file *file,
227 struct cmd_list_element *cmd,
229 /* NOTE: i18n: This function is not i18n friendly. Callers should
230 instead print the value out directly. */
231 extern show_value_ftype deprecated_show_value_hack;
233 extern void add_setshow_enum_cmd (char *name,
234 enum command_class class,
235 const char *const *enumlist,
238 const char *show_doc,
239 const char *help_doc,
240 cmd_sfunc_ftype *set_func,
241 show_value_ftype *show_func,
242 struct cmd_list_element **set_list,
243 struct cmd_list_element **show_list);
245 extern void add_setshow_auto_boolean_cmd (char *name,
246 enum command_class class,
247 enum auto_boolean *var,
249 const char *show_doc,
250 const char *help_doc,
251 cmd_sfunc_ftype *set_func,
252 show_value_ftype *show_func,
253 struct cmd_list_element **set_list,
254 struct cmd_list_element **show_list);
256 extern void add_setshow_boolean_cmd (char *name,
257 enum command_class class,
259 const char *set_doc, const char *show_doc,
260 const char *help_doc,
261 cmd_sfunc_ftype *set_func,
262 show_value_ftype *show_func,
263 struct cmd_list_element **set_list,
264 struct cmd_list_element **show_list);
266 extern void add_setshow_filename_cmd (char *name,
267 enum command_class class,
270 const char *show_doc,
271 const char *help_doc,
272 cmd_sfunc_ftype *set_func,
273 show_value_ftype *show_func,
274 struct cmd_list_element **set_list,
275 struct cmd_list_element **show_list);
277 extern void add_setshow_string_cmd (char *name,
278 enum command_class class,
281 const char *show_doc,
282 const char *help_doc,
283 cmd_sfunc_ftype *set_func,
284 show_value_ftype *show_func,
285 struct cmd_list_element **set_list,
286 struct cmd_list_element **show_list);
288 extern void add_setshow_string_noescape_cmd (char *name,
289 enum command_class class,
292 const char *show_doc,
293 const char *help_doc,
294 cmd_sfunc_ftype *set_func,
295 show_value_ftype *show_func,
296 struct cmd_list_element **set_list,
297 struct cmd_list_element **show_list);
299 extern void add_setshow_optional_filename_cmd (char *name,
300 enum command_class class,
303 const char *show_doc,
304 const char *help_doc,
305 cmd_sfunc_ftype *set_func,
306 show_value_ftype *show_func,
307 struct cmd_list_element **set_list,
308 struct cmd_list_element **show_list);
310 extern void add_setshow_integer_cmd (char *name,
311 enum command_class class,
314 const char *show_doc,
315 const char *help_doc,
316 cmd_sfunc_ftype *set_func,
317 show_value_ftype *show_func,
318 struct cmd_list_element **set_list,
319 struct cmd_list_element **show_list);
321 extern void add_setshow_uinteger_cmd (char *name,
322 enum command_class class,
325 const char *show_doc,
326 const char *help_doc,
327 cmd_sfunc_ftype *set_func,
328 show_value_ftype *show_func,
329 struct cmd_list_element **set_list,
330 struct cmd_list_element **show_list);
332 extern void add_setshow_zinteger_cmd (char *name,
333 enum command_class class,
336 const char *show_doc,
337 const char *help_doc,
338 cmd_sfunc_ftype *set_func,
339 show_value_ftype *show_func,
340 struct cmd_list_element **set_list,
341 struct cmd_list_element **show_list);
343 extern void add_setshow_zuinteger_cmd (char *name,
344 enum command_class class,
347 const char *show_doc,
348 const char *help_doc,
349 cmd_sfunc_ftype *set_func,
350 show_value_ftype *show_func,
351 struct cmd_list_element **set_list,
352 struct cmd_list_element **show_list);
354 /* Do a "show" command for each thing on a command list. */
356 extern void cmd_show_list (struct cmd_list_element *, int, char *);
358 /* Used everywhere whenever at least one parameter is required and
359 none is specified. */
361 extern void error_no_arg (char *) ATTRIBUTE_NORETURN;
363 extern void dont_repeat (void);
365 extern struct cleanup *prevent_dont_repeat (void);
367 /* Used to mark commands that don't do anything. If we just leave the
368 function field NULL, the command is interpreted as a help topic, or
369 as a class of commands. */
371 extern void not_just_help_class_command (char *, int);
373 /* Check function pointer. */
374 extern int cmd_func_p (struct cmd_list_element *cmd);
376 /* Call the command function. */
377 extern void cmd_func (struct cmd_list_element *cmd,
378 char *args, int from_tty);
380 #endif /* !defined (COMMAND_H) */