15796c8dcSSimon Schubert /* Header file for command-reading library command.c. 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 4*cf7f2e2dSJohn Marino 2002, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 75796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 85796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 95796c8dcSSimon Schubert (at your option) any later version. 105796c8dcSSimon Schubert 115796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 125796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 135796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 145796c8dcSSimon Schubert GNU General Public License for more details. 155796c8dcSSimon Schubert 165796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 175796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert #if !defined (COMMAND_H) 205796c8dcSSimon Schubert #define COMMAND_H 1 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert /* Command classes are top-level categories into which commands are broken 235796c8dcSSimon Schubert down for "help" purposes. 245796c8dcSSimon Schubert Notes on classes: class_alias is for alias commands which are not 255796c8dcSSimon Schubert abbreviations of the original command. class-pseudo is for 265796c8dcSSimon Schubert commands which are not really commands nor help topics ("stop"). */ 275796c8dcSSimon Schubert 285796c8dcSSimon Schubert enum command_class 295796c8dcSSimon Schubert { 305796c8dcSSimon Schubert /* Special args to help_list */ 315796c8dcSSimon Schubert class_deprecated = -3, all_classes = -2, all_commands = -1, 325796c8dcSSimon Schubert /* Classes of commands */ 335796c8dcSSimon Schubert no_class = -1, class_run = 0, class_vars, class_stack, 345796c8dcSSimon Schubert class_files, class_support, class_info, class_breakpoint, class_trace, 35*cf7f2e2dSJohn Marino class_alias, class_bookmark, class_obscure, class_maintenance, 36*cf7f2e2dSJohn Marino class_pseudo, class_tui, class_user, class_xdb 375796c8dcSSimon Schubert }; 385796c8dcSSimon Schubert 395796c8dcSSimon Schubert /* FIXME: cagney/2002-03-17: Once cmd_type() has been removed, ``enum 405796c8dcSSimon Schubert cmd_types'' can be moved from "command.h" to "cli-decode.h". */ 415796c8dcSSimon Schubert /* Not a set/show command. Note that some commands which begin with 425796c8dcSSimon Schubert "set" or "show" might be in this category, if their syntax does 435796c8dcSSimon Schubert not fall into one of the following categories. */ 445796c8dcSSimon Schubert typedef enum cmd_types 455796c8dcSSimon Schubert { 465796c8dcSSimon Schubert not_set_cmd, 475796c8dcSSimon Schubert set_cmd, 485796c8dcSSimon Schubert show_cmd 495796c8dcSSimon Schubert } 505796c8dcSSimon Schubert cmd_types; 515796c8dcSSimon Schubert 525796c8dcSSimon Schubert /* Types of "set" or "show" command. */ 535796c8dcSSimon Schubert typedef enum var_types 545796c8dcSSimon Schubert { 555796c8dcSSimon Schubert /* "on" or "off". *VAR is an integer which is nonzero for on, 565796c8dcSSimon Schubert zero for off. */ 575796c8dcSSimon Schubert var_boolean, 585796c8dcSSimon Schubert 595796c8dcSSimon Schubert /* "on" / "true" / "enable" or "off" / "false" / "disable" or 605796c8dcSSimon Schubert "auto. *VAR is an ``enum auto_boolean''. NOTE: In general a 615796c8dcSSimon Schubert custom show command will need to be implemented - one that for 625796c8dcSSimon Schubert "auto" prints both the "auto" and the current auto-selected 635796c8dcSSimon Schubert value. */ 645796c8dcSSimon Schubert var_auto_boolean, 655796c8dcSSimon Schubert 665796c8dcSSimon Schubert /* Unsigned Integer. *VAR is an unsigned int. The user can type 0 675796c8dcSSimon Schubert to mean "unlimited", which is stored in *VAR as UINT_MAX. */ 685796c8dcSSimon Schubert var_uinteger, 695796c8dcSSimon Schubert 705796c8dcSSimon Schubert /* Like var_uinteger but signed. *VAR is an int. The user can type 0 715796c8dcSSimon Schubert to mean "unlimited", which is stored in *VAR as INT_MAX. */ 725796c8dcSSimon Schubert var_integer, 735796c8dcSSimon Schubert 745796c8dcSSimon Schubert /* String which the user enters with escapes (e.g. the user types \n and 755796c8dcSSimon Schubert it is a real newline in the stored string). 765796c8dcSSimon Schubert *VAR is a malloc'd string, or NULL if the string is empty. */ 775796c8dcSSimon Schubert var_string, 785796c8dcSSimon Schubert /* String which stores what the user types verbatim. 795796c8dcSSimon Schubert *VAR is a malloc'd string, or NULL if the string is empty. */ 805796c8dcSSimon Schubert var_string_noescape, 815796c8dcSSimon Schubert /* String which stores a filename. (*VAR) is a malloc'd string, 825796c8dcSSimon Schubert or "" if the string was empty. */ 835796c8dcSSimon Schubert var_optional_filename, 845796c8dcSSimon Schubert /* String which stores a filename. (*VAR) is a malloc'd 855796c8dcSSimon Schubert string. */ 865796c8dcSSimon Schubert var_filename, 875796c8dcSSimon Schubert /* ZeroableInteger. *VAR is an int. Like Unsigned Integer except 885796c8dcSSimon Schubert that zero really means zero. */ 895796c8dcSSimon Schubert var_zinteger, 905796c8dcSSimon Schubert /* ZeroableUnsignedInteger. *VAR is an unsigned int. Zero really 915796c8dcSSimon Schubert means zero. */ 925796c8dcSSimon Schubert var_zuinteger, 935796c8dcSSimon Schubert /* Enumerated type. Can only have one of the specified values. *VAR is a 945796c8dcSSimon Schubert char pointer to the name of the element that we find. */ 955796c8dcSSimon Schubert var_enum 965796c8dcSSimon Schubert } 975796c8dcSSimon Schubert var_types; 985796c8dcSSimon Schubert 995796c8dcSSimon Schubert /* This structure records one command'd definition. */ 1005796c8dcSSimon Schubert struct cmd_list_element; 1015796c8dcSSimon Schubert 1025796c8dcSSimon Schubert /* Forward-declarations of the entry-points of cli/cli-decode.c. */ 1035796c8dcSSimon Schubert 1045796c8dcSSimon Schubert extern struct cmd_list_element *add_cmd (char *, enum command_class, 1055796c8dcSSimon Schubert void (*fun) (char *, int), char *, 1065796c8dcSSimon Schubert struct cmd_list_element **); 1075796c8dcSSimon Schubert 1085796c8dcSSimon Schubert extern struct cmd_list_element *add_alias_cmd (char *, char *, 1095796c8dcSSimon Schubert enum command_class, int, 1105796c8dcSSimon Schubert struct cmd_list_element **); 1115796c8dcSSimon Schubert 1125796c8dcSSimon Schubert extern struct cmd_list_element *add_prefix_cmd (char *, enum command_class, 1135796c8dcSSimon Schubert void (*fun) (char *, int), 1145796c8dcSSimon Schubert char *, 1155796c8dcSSimon Schubert struct cmd_list_element **, 1165796c8dcSSimon Schubert char *, int, 1175796c8dcSSimon Schubert struct cmd_list_element **); 1185796c8dcSSimon Schubert 1195796c8dcSSimon Schubert extern struct cmd_list_element *add_abbrev_prefix_cmd (char *, 1205796c8dcSSimon Schubert enum command_class, 1215796c8dcSSimon Schubert void (*fun) (char *, 1225796c8dcSSimon Schubert int), 1235796c8dcSSimon Schubert char *, 1245796c8dcSSimon Schubert struct cmd_list_element 1255796c8dcSSimon Schubert **, char *, int, 1265796c8dcSSimon Schubert struct cmd_list_element 1275796c8dcSSimon Schubert **); 1285796c8dcSSimon Schubert 1295796c8dcSSimon Schubert /* Set the commands corresponding callback. */ 1305796c8dcSSimon Schubert 1315796c8dcSSimon Schubert typedef void cmd_cfunc_ftype (char *args, int from_tty); 1325796c8dcSSimon Schubert extern void set_cmd_cfunc (struct cmd_list_element *cmd, 1335796c8dcSSimon Schubert cmd_cfunc_ftype *cfunc); 1345796c8dcSSimon Schubert 1355796c8dcSSimon Schubert typedef void cmd_sfunc_ftype (char *args, int from_tty, 1365796c8dcSSimon Schubert struct cmd_list_element *c); 1375796c8dcSSimon Schubert extern void set_cmd_sfunc (struct cmd_list_element *cmd, 1385796c8dcSSimon Schubert cmd_sfunc_ftype *sfunc); 1395796c8dcSSimon Schubert 1405796c8dcSSimon Schubert extern void set_cmd_completer (struct cmd_list_element *cmd, 1415796c8dcSSimon Schubert char **(*completer) (struct cmd_list_element *cmd, 1425796c8dcSSimon Schubert char *text, char *word)); 1435796c8dcSSimon Schubert 1445796c8dcSSimon Schubert /* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs 1455796c8dcSSimon Schubert around in cmd objects to test the value of the commands sfunc(). */ 1465796c8dcSSimon Schubert extern int cmd_cfunc_eq (struct cmd_list_element *cmd, 1475796c8dcSSimon Schubert void (*cfunc) (char *args, int from_tty)); 1485796c8dcSSimon Schubert 1495796c8dcSSimon Schubert /* Each command object has a local context attached to it. . */ 1505796c8dcSSimon Schubert extern void set_cmd_context (struct cmd_list_element *cmd, void *context); 1515796c8dcSSimon Schubert extern void *get_cmd_context (struct cmd_list_element *cmd); 1525796c8dcSSimon Schubert 1535796c8dcSSimon Schubert 1545796c8dcSSimon Schubert /* Execute CMD's pre/post hook. Throw an error if the command fails. 1555796c8dcSSimon Schubert If already executing this pre/post hook, or there is no pre/post 1565796c8dcSSimon Schubert hook, the call is silently ignored. */ 1575796c8dcSSimon Schubert extern void execute_cmd_pre_hook (struct cmd_list_element *cmd); 1585796c8dcSSimon Schubert extern void execute_cmd_post_hook (struct cmd_list_element *cmd); 1595796c8dcSSimon Schubert 1605796c8dcSSimon Schubert /* Return the type of the command. */ 1615796c8dcSSimon Schubert extern enum cmd_types cmd_type (struct cmd_list_element *cmd); 1625796c8dcSSimon Schubert 1635796c8dcSSimon Schubert 1645796c8dcSSimon Schubert extern struct cmd_list_element *lookup_cmd (char **, 1655796c8dcSSimon Schubert struct cmd_list_element *, char *, 1665796c8dcSSimon Schubert int, int); 1675796c8dcSSimon Schubert 1685796c8dcSSimon Schubert extern struct cmd_list_element *lookup_cmd_1 (char **, 1695796c8dcSSimon Schubert struct cmd_list_element *, 1705796c8dcSSimon Schubert struct cmd_list_element **, 1715796c8dcSSimon Schubert int); 1725796c8dcSSimon Schubert 1735796c8dcSSimon Schubert extern struct cmd_list_element * 1745796c8dcSSimon Schubert deprecate_cmd (struct cmd_list_element *, char * ); 1755796c8dcSSimon Schubert 1765796c8dcSSimon Schubert extern void 1775796c8dcSSimon Schubert deprecated_cmd_warning (char **); 1785796c8dcSSimon Schubert 1795796c8dcSSimon Schubert extern int 1805796c8dcSSimon Schubert lookup_cmd_composition (char *text, 1815796c8dcSSimon Schubert struct cmd_list_element **alias, 1825796c8dcSSimon Schubert struct cmd_list_element **prefix_cmd, 1835796c8dcSSimon Schubert struct cmd_list_element **cmd); 1845796c8dcSSimon Schubert 1855796c8dcSSimon Schubert extern struct cmd_list_element *add_com (char *, enum command_class, 1865796c8dcSSimon Schubert void (*fun) (char *, int), char *); 1875796c8dcSSimon Schubert 1885796c8dcSSimon Schubert extern struct cmd_list_element *add_com_alias (char *, char *, 1895796c8dcSSimon Schubert enum command_class, int); 1905796c8dcSSimon Schubert 1915796c8dcSSimon Schubert extern struct cmd_list_element *add_info (char *, void (*fun) (char *, int), 1925796c8dcSSimon Schubert char *); 1935796c8dcSSimon Schubert 1945796c8dcSSimon Schubert extern struct cmd_list_element *add_info_alias (char *, char *, int); 1955796c8dcSSimon Schubert 1965796c8dcSSimon Schubert extern char **complete_on_cmdlist (struct cmd_list_element *, char *, char *); 1975796c8dcSSimon Schubert 1985796c8dcSSimon Schubert extern char **complete_on_enum (const char *enumlist[], char *, char *); 1995796c8dcSSimon Schubert 2005796c8dcSSimon Schubert extern void help_cmd (char *, struct ui_file *); 2015796c8dcSSimon Schubert 2025796c8dcSSimon Schubert extern void help_list (struct cmd_list_element *, char *, 2035796c8dcSSimon Schubert enum command_class, struct ui_file *); 2045796c8dcSSimon Schubert 2055796c8dcSSimon Schubert extern void help_cmd_list (struct cmd_list_element *, enum command_class, 2065796c8dcSSimon Schubert char *, int, struct ui_file *); 2075796c8dcSSimon Schubert 2085796c8dcSSimon Schubert /* Method for show a set/show variable's VALUE on FILE. If this 2095796c8dcSSimon Schubert method isn't supplied deprecated_show_value_hack() is called (which 2105796c8dcSSimon Schubert is not good). */ 2115796c8dcSSimon Schubert typedef void (show_value_ftype) (struct ui_file *file, 2125796c8dcSSimon Schubert int from_tty, 2135796c8dcSSimon Schubert struct cmd_list_element *cmd, 2145796c8dcSSimon Schubert const char *value); 2155796c8dcSSimon Schubert /* NOTE: i18n: This function is not i18n friendly. Callers should 2165796c8dcSSimon Schubert instead print the value out directly. */ 2175796c8dcSSimon Schubert extern show_value_ftype deprecated_show_value_hack; 2185796c8dcSSimon Schubert 2195796c8dcSSimon Schubert extern void add_setshow_enum_cmd (char *name, 2205796c8dcSSimon Schubert enum command_class class, 2215796c8dcSSimon Schubert const char *enumlist[], 2225796c8dcSSimon Schubert const char **var, 2235796c8dcSSimon Schubert const char *set_doc, 2245796c8dcSSimon Schubert const char *show_doc, 2255796c8dcSSimon Schubert const char *help_doc, 2265796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 2275796c8dcSSimon Schubert show_value_ftype *show_func, 2285796c8dcSSimon Schubert struct cmd_list_element **set_list, 2295796c8dcSSimon Schubert struct cmd_list_element **show_list); 2305796c8dcSSimon Schubert 2315796c8dcSSimon Schubert extern void add_setshow_auto_boolean_cmd (char *name, 2325796c8dcSSimon Schubert enum command_class class, 2335796c8dcSSimon Schubert enum auto_boolean *var, 2345796c8dcSSimon Schubert const char *set_doc, 2355796c8dcSSimon Schubert const char *show_doc, 2365796c8dcSSimon Schubert const char *help_doc, 2375796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 2385796c8dcSSimon Schubert show_value_ftype *show_func, 2395796c8dcSSimon Schubert struct cmd_list_element **set_list, 2405796c8dcSSimon Schubert struct cmd_list_element **show_list); 2415796c8dcSSimon Schubert 2425796c8dcSSimon Schubert extern void add_setshow_boolean_cmd (char *name, 2435796c8dcSSimon Schubert enum command_class class, 2445796c8dcSSimon Schubert int *var, 2455796c8dcSSimon Schubert const char *set_doc, const char *show_doc, 2465796c8dcSSimon Schubert const char *help_doc, 2475796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 2485796c8dcSSimon Schubert show_value_ftype *show_func, 2495796c8dcSSimon Schubert struct cmd_list_element **set_list, 2505796c8dcSSimon Schubert struct cmd_list_element **show_list); 2515796c8dcSSimon Schubert 2525796c8dcSSimon Schubert extern void add_setshow_filename_cmd (char *name, 2535796c8dcSSimon Schubert enum command_class class, 2545796c8dcSSimon Schubert char **var, 2555796c8dcSSimon Schubert const char *set_doc, 2565796c8dcSSimon Schubert const char *show_doc, 2575796c8dcSSimon Schubert const char *help_doc, 2585796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 2595796c8dcSSimon Schubert show_value_ftype *show_func, 2605796c8dcSSimon Schubert struct cmd_list_element **set_list, 2615796c8dcSSimon Schubert struct cmd_list_element **show_list); 2625796c8dcSSimon Schubert 2635796c8dcSSimon Schubert extern void add_setshow_string_cmd (char *name, 2645796c8dcSSimon Schubert enum command_class class, 2655796c8dcSSimon Schubert char **var, 2665796c8dcSSimon Schubert const char *set_doc, 2675796c8dcSSimon Schubert const char *show_doc, 2685796c8dcSSimon Schubert const char *help_doc, 2695796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 2705796c8dcSSimon Schubert show_value_ftype *show_func, 2715796c8dcSSimon Schubert struct cmd_list_element **set_list, 2725796c8dcSSimon Schubert struct cmd_list_element **show_list); 2735796c8dcSSimon Schubert 2745796c8dcSSimon Schubert extern void add_setshow_string_noescape_cmd (char *name, 2755796c8dcSSimon Schubert enum command_class class, 2765796c8dcSSimon Schubert char **var, 2775796c8dcSSimon Schubert const char *set_doc, 2785796c8dcSSimon Schubert const char *show_doc, 2795796c8dcSSimon Schubert const char *help_doc, 2805796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 2815796c8dcSSimon Schubert show_value_ftype *show_func, 2825796c8dcSSimon Schubert struct cmd_list_element **set_list, 2835796c8dcSSimon Schubert struct cmd_list_element **show_list); 2845796c8dcSSimon Schubert 2855796c8dcSSimon Schubert extern void add_setshow_optional_filename_cmd (char *name, 2865796c8dcSSimon Schubert enum command_class class, 2875796c8dcSSimon Schubert char **var, 2885796c8dcSSimon Schubert const char *set_doc, 2895796c8dcSSimon Schubert const char *show_doc, 2905796c8dcSSimon Schubert const char *help_doc, 2915796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 2925796c8dcSSimon Schubert show_value_ftype *show_func, 2935796c8dcSSimon Schubert struct cmd_list_element **set_list, 2945796c8dcSSimon Schubert struct cmd_list_element **show_list); 2955796c8dcSSimon Schubert 2965796c8dcSSimon Schubert extern void add_setshow_integer_cmd (char *name, 2975796c8dcSSimon Schubert enum command_class class, 2985796c8dcSSimon Schubert int *var, 2995796c8dcSSimon Schubert const char *set_doc, 3005796c8dcSSimon Schubert const char *show_doc, 3015796c8dcSSimon Schubert const char *help_doc, 3025796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 3035796c8dcSSimon Schubert show_value_ftype *show_func, 3045796c8dcSSimon Schubert struct cmd_list_element **set_list, 3055796c8dcSSimon Schubert struct cmd_list_element **show_list); 3065796c8dcSSimon Schubert 3075796c8dcSSimon Schubert extern void add_setshow_uinteger_cmd (char *name, 3085796c8dcSSimon Schubert enum command_class class, 3095796c8dcSSimon Schubert unsigned int *var, 3105796c8dcSSimon Schubert const char *set_doc, 3115796c8dcSSimon Schubert const char *show_doc, 3125796c8dcSSimon Schubert const char *help_doc, 3135796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 3145796c8dcSSimon Schubert show_value_ftype *show_func, 3155796c8dcSSimon Schubert struct cmd_list_element **set_list, 3165796c8dcSSimon Schubert struct cmd_list_element **show_list); 3175796c8dcSSimon Schubert 3185796c8dcSSimon Schubert extern void add_setshow_zinteger_cmd (char *name, 3195796c8dcSSimon Schubert enum command_class class, 3205796c8dcSSimon Schubert int *var, 3215796c8dcSSimon Schubert const char *set_doc, 3225796c8dcSSimon Schubert const char *show_doc, 3235796c8dcSSimon Schubert const char *help_doc, 3245796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 3255796c8dcSSimon Schubert show_value_ftype *show_func, 3265796c8dcSSimon Schubert struct cmd_list_element **set_list, 3275796c8dcSSimon Schubert struct cmd_list_element **show_list); 3285796c8dcSSimon Schubert 3295796c8dcSSimon Schubert extern void add_setshow_zuinteger_cmd (char *name, 3305796c8dcSSimon Schubert enum command_class class, 3315796c8dcSSimon Schubert unsigned int *var, 3325796c8dcSSimon Schubert const char *set_doc, 3335796c8dcSSimon Schubert const char *show_doc, 3345796c8dcSSimon Schubert const char *help_doc, 3355796c8dcSSimon Schubert cmd_sfunc_ftype *set_func, 3365796c8dcSSimon Schubert show_value_ftype *show_func, 3375796c8dcSSimon Schubert struct cmd_list_element **set_list, 3385796c8dcSSimon Schubert struct cmd_list_element **show_list); 3395796c8dcSSimon Schubert 3405796c8dcSSimon Schubert /* Do a "show" command for each thing on a command list. */ 3415796c8dcSSimon Schubert 3425796c8dcSSimon Schubert extern void cmd_show_list (struct cmd_list_element *, int, char *); 3435796c8dcSSimon Schubert 344*cf7f2e2dSJohn Marino /* Used everywhere whenever at least one parameter is required and 345*cf7f2e2dSJohn Marino none is specified. */ 346*cf7f2e2dSJohn Marino 347*cf7f2e2dSJohn Marino extern void error_no_arg (char *) ATTRIBUTE_NORETURN; 3485796c8dcSSimon Schubert 3495796c8dcSSimon Schubert extern void dont_repeat (void); 3505796c8dcSSimon Schubert 3515796c8dcSSimon Schubert /* Used to mark commands that don't do anything. If we just leave the 3525796c8dcSSimon Schubert function field NULL, the command is interpreted as a help topic, or 3535796c8dcSSimon Schubert as a class of commands. */ 3545796c8dcSSimon Schubert 3555796c8dcSSimon Schubert extern void not_just_help_class_command (char *, int); 3565796c8dcSSimon Schubert 3575796c8dcSSimon Schubert /* check function pointer */ 3585796c8dcSSimon Schubert extern int cmd_func_p (struct cmd_list_element *cmd); 3595796c8dcSSimon Schubert 3605796c8dcSSimon Schubert /* call the command function */ 3615796c8dcSSimon Schubert extern void cmd_func (struct cmd_list_element *cmd, char *args, int from_tty); 3625796c8dcSSimon Schubert 3635796c8dcSSimon Schubert #endif /* !defined (COMMAND_H) */ 364