Fix for PR gdb/209, PR gdb/156:
[external/binutils.git] / gdb / cli / cli-decode.h
1 /* Header file for GDB command decoding library.
2    Copyright 2000 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18
19 #if !defined (CLI_DECODE_H)
20 #define CLI_DECODE_H 1
21
22 #include "gdb_regex.h"          /* Needed by apropos_cmd.  */
23
24 /* Command classes are top-level categories into which commands are broken
25    down for "help" purposes.  
26    Notes on classes: class_alias is for alias commands which are not
27    abbreviations of the original command.  class-pseudo is for
28    commands which are not really commands nor help topics ("stop").  */
29
30 enum command_class
31 {
32   /* Special args to help_list */
33   class_deprecated, all_classes = -2, all_commands = -1,
34   /* Classes of commands */
35   no_class = -1, class_run = 0, class_vars, class_stack,
36   class_files, class_support, class_info, class_breakpoint, class_trace,
37   class_alias, class_obscure, class_user, class_maintenance,
38   class_pseudo, class_tui, class_xdb
39 };
40
41 /* Not a set/show command.  Note that some commands which begin with
42    "set" or "show" might be in this category, if their syntax does
43    not fall into one of the following categories.  */
44 typedef enum cmd_types
45   {
46     not_set_cmd,
47     set_cmd,
48     show_cmd
49   }
50 cmd_types;
51
52 /* Reasonable values for an AUTO_BOOLEAN variable. */
53 enum cmd_auto_boolean
54 {
55   CMD_AUTO_BOOLEAN_TRUE,
56   CMD_AUTO_BOOLEAN_FALSE,
57   CMD_AUTO_BOOLEAN_AUTO
58 };
59
60 /* Types of "set" or "show" command.  */
61 typedef enum var_types
62   {
63     /* "on" or "off".  *VAR is an integer which is nonzero for on,
64        zero for off.  */
65     var_boolean,
66
67     /* "on" / "true" / "enable" or "off" / "false" / "disable" or
68        "auto.  *VAR is an ``enum cmd_auto_boolean''.  NOTE: In general
69        a custom show command will need to be implemented - one that
70        for "auto" prints both the "auto" and the current auto-selected
71        value. */
72     var_auto_boolean,
73
74     /* Unsigned Integer.  *VAR is an unsigned int.  The user can type 0
75        to mean "unlimited", which is stored in *VAR as UINT_MAX.  */
76     var_uinteger,
77
78     /* Like var_uinteger but signed.  *VAR is an int.  The user can type 0
79        to mean "unlimited", which is stored in *VAR as INT_MAX.  */
80     var_integer,
81
82     /* String which the user enters with escapes (e.g. the user types \n and
83        it is a real newline in the stored string).
84        *VAR is a malloc'd string, or NULL if the string is empty.  */
85     var_string,
86     /* String which stores what the user types verbatim.
87        *VAR is a malloc'd string, or NULL if the string is empty.  */
88     var_string_noescape,
89     /* String which stores a filename.
90        *VAR is a malloc'd string, or NULL if the string is empty.  */
91     var_filename,
92     /* ZeroableInteger.  *VAR is an int.  Like Unsigned Integer except
93        that zero really means zero.  */
94     var_zinteger,
95     /* Enumerated type.  Can only have one of the specified values.  *VAR is a
96        char pointer to the name of the element that we find.  */
97     var_enum
98   }
99 var_types;
100
101 /* This structure records one command'd definition.  */
102
103
104 /* This flag is used by the code executing commands to warn the user 
105    the first time a deprecated command is used, see the 'flags' field in
106    the following struct.
107 */
108 #define CMD_DEPRECATED            0x1
109 #define DEPRECATED_WARN_USER      0x2
110 #define MALLOCED_REPLACEMENT      0x4
111
112 struct cmd_list_element
113   {
114     /* Points to next command in this list.  */
115     struct cmd_list_element *next;
116
117     /* Name of this command.  */
118     char *name;
119
120     /* Command class; class values are chosen by application program.  */
121     enum command_class class;
122
123     /* Function definition of this command.
124        NO_FUNCTION for command class names and for help topics that
125        are not really commands.  */
126     union
127       {
128         /* If type is not_set_cmd, call it like this:  */
129         void (*cfunc) (char *args, int from_tty);
130
131         /* If type is set_cmd or show_cmd, first set the variables, and
132            then call this.  */
133         void (*sfunc) (char *args, int from_tty, struct cmd_list_element * c);
134       }
135     function;
136 #define NO_FUNCTION ((void (*) (char *args, int from_tty)) 0)
137
138     /* Documentation of this command (or help topic).
139        First line is brief documentation; remaining lines form, with it,
140        the full documentation.  First line should end with a period.
141        Entire string should also end with a period, not a newline.  */
142     char *doc;
143
144     /* flags : a bitfield 
145        
146        bit 0: (LSB) CMD_DEPRECATED, when 1 indicated that this command
147        is deprecated. It may be removed from gdb's command set in the
148        future.
149
150        bit 1: DEPRECATED_WARN_USER, the user needs to be warned that
151        this is a deprecated command.  The user should only be warned
152        the first time a command is used.
153         
154        bit 2: MALLOCED_REPLACEMENT, when functions are deprecated at
155        compile time (this is the way it should, in general, be done)
156        the memory containing the replacement string is statically
157        allocated.  In some cases it makes sense to deprecate commands
158        at runtime (the testsuite is one example).  In this case the
159        memory for replacement is malloc'ed.  When a command is
160        undeprecated or re-deprecated at runtime we don't want to risk
161        calling free on statically allocated memory, so we check this
162        flag.  
163      */
164     int flags;
165
166     /* if this command is deprecated, this is the replacement name */
167     char *replacement;
168
169     /* If this command represents a show command, then this function
170        is called before the variable's value is examined.  */
171     void (*pre_show_hook) (struct cmd_list_element *c);
172
173     /* Hook for another command to be executed before this command.  */
174     struct cmd_list_element *hook_pre;
175
176     /* Hook for another command to be executed after this command.  */
177     struct cmd_list_element *hook_post;
178
179     /* Flag that specifies if this command is already running it's hook. */
180     /* Prevents the possibility of hook recursion. */
181     int hook_in;
182
183     /* Nonzero identifies a prefix command.  For them, the address
184        of the variable containing the list of subcommands.  */
185     struct cmd_list_element **prefixlist;
186
187     /* For prefix commands only:
188        String containing prefix commands to get here: this one
189        plus any others needed to get to it.  Should end in a space.
190        It is used before the word "command" in describing the
191        commands reached through this prefix.  */
192     char *prefixname;
193
194     /* For prefix commands only:
195        nonzero means do not get an error if subcommand is not
196        recognized; call the prefix's own function in that case.  */
197     char allow_unknown;
198
199     /* Nonzero says this is an abbreviation, and should not
200        be mentioned in lists of commands.
201        This allows "br<tab>" to complete to "break", which it
202        otherwise wouldn't.  */
203     char abbrev_flag;
204
205     /* Completion routine for this command.  TEXT is the text beyond
206        what was matched for the command itself (leading whitespace is
207        skipped).  It stops where we are supposed to stop completing
208        (rl_point) and is '\0' terminated.
209
210        Return value is a malloc'd vector of pointers to possible completions
211        terminated with NULL.  If there are no completions, returning a pointer
212        to a NULL would work but returning NULL itself is also valid.
213        WORD points in the same buffer as TEXT, and completions should be
214        returned relative to this position.  For example, suppose TEXT is "foo"
215        and we want to complete to "foobar".  If WORD is "oo", return
216        "oobar"; if WORD is "baz/foo", return "baz/foobar".  */
217     char **(*completer) (char *text, char *word);
218
219     /* Type of "set" or "show" command (or SET_NOT_SET if not "set"
220        or "show").  */
221     cmd_types type;
222
223     /* Pointer to variable affected by "set" and "show".  Doesn't matter
224        if type is not_set.  */
225     void *var;
226
227     /* What kind of variable is *VAR?  */
228     var_types var_type;
229
230     /* Pointer to NULL terminated list of enumerated values (like argv).  */
231     const char **enums;
232
233     /* Pointer to command strings of user-defined commands */
234     struct command_line *user_commands;
235
236     /* Pointer to command that is hooked by this one, (by hook_pre)
237        so the hook can be removed when this one is deleted.  */
238     struct cmd_list_element *hookee_pre;
239
240     /* Pointer to command that is hooked by this one, (by hook_post)
241        so the hook can be removed when this one is deleted.  */
242     struct cmd_list_element *hookee_post;
243
244     /* Pointer to command that is aliased by this one, so the
245        aliased command can be located in case it has been hooked.  */
246     struct cmd_list_element *cmd_pointer;
247   };
248
249 /* API to the manipulation of command lists.  */
250
251 extern struct cmd_list_element *add_cmd (char *, enum command_class,
252                                          void (*fun) (char *, int), char *,
253                                          struct cmd_list_element **);
254
255 extern struct cmd_list_element *add_alias_cmd (char *, char *,
256                                                enum command_class, int,
257                                                struct cmd_list_element **);
258
259 extern struct cmd_list_element *add_prefix_cmd (char *, enum command_class,
260                                                 void (*fun) (char *, int),
261                                                 char *,
262                                                 struct cmd_list_element **,
263                                                 char *, int,
264                                                 struct cmd_list_element **);
265
266 extern struct cmd_list_element *add_abbrev_prefix_cmd (char *,
267                                                        enum command_class,
268                                                        void (*fun) (char *,
269                                                                     int),
270                                                        char *,
271                                                        struct cmd_list_element
272                                                        **, char *, int,
273                                                        struct cmd_list_element
274                                                        **);
275
276 extern struct cmd_list_element *lookup_cmd (char **,
277                                             struct cmd_list_element *, char *,
278                                             int, int);
279
280 extern struct cmd_list_element *lookup_cmd_1 (char **,
281                                               struct cmd_list_element *,
282                                               struct cmd_list_element **,
283                                               int);
284
285 extern struct cmd_list_element *
286   deprecate_cmd (struct cmd_list_element *, char * );
287
288 extern void
289   deprecated_cmd_warning (char **);
290
291 extern int
292   lookup_cmd_composition (char *text,
293                         struct cmd_list_element **alias,
294                         struct cmd_list_element **prefix_cmd,
295                         struct cmd_list_element **cmd);
296
297 extern struct cmd_list_element *add_com (char *, enum command_class,
298                                          void (*fun) (char *, int), char *);
299
300 extern struct cmd_list_element *add_com_alias (char *, char *,
301                                                enum command_class, int);
302
303 extern struct cmd_list_element *add_info (char *, void (*fun) (char *, int),
304                                           char *);
305
306 extern struct cmd_list_element *add_info_alias (char *, char *, int);
307
308 extern char **complete_on_cmdlist (struct cmd_list_element *, char *, char *);
309
310 extern char **complete_on_enum (const char *enumlist[], char *, char *);
311
312 extern void delete_cmd (char *, struct cmd_list_element **);
313
314 extern void help_cmd_list (struct cmd_list_element *, enum command_class,
315                            char *, int, struct ui_file *);
316
317 extern struct cmd_list_element *add_set_cmd (char *name, enum
318                                              command_class class,
319                                              var_types var_type, void *var,
320                                              char *doc,
321                                              struct cmd_list_element **list);
322
323 extern struct cmd_list_element *add_set_enum_cmd (char *name,
324                                                   enum command_class class,
325                                                   const char *enumlist[],
326                                                   const char **var,
327                                                   char *doc,
328                                                   struct cmd_list_element **list);
329
330 extern struct cmd_list_element *add_set_auto_boolean_cmd (char *name,
331                                                           enum command_class class,
332                                                           enum cmd_auto_boolean *var,
333                                                           char *doc,
334                                                           struct cmd_list_element **list);
335
336 extern struct cmd_list_element *add_set_boolean_cmd (char *name,
337                                                      enum command_class class,
338                                                      int *var,
339                                                      char *doc,
340                                                      struct cmd_list_element **list);
341
342 extern struct cmd_list_element *add_show_from_set (struct cmd_list_element *,
343                                                    struct cmd_list_element
344                                                    **);
345
346 /* Functions that implement commands about CLI commands. */
347
348 extern void help_cmd (char *, struct ui_file *);
349
350 extern void help_list (struct cmd_list_element *, char *,
351                        enum command_class, struct ui_file *);
352
353 extern void apropos_cmd (struct ui_file *, struct cmd_list_element *,
354                          struct re_pattern_buffer *, char *);
355
356 /* Used to mark commands that don't do anything.  If we just leave the
357    function field NULL, the command is interpreted as a help topic, or
358    as a class of commands.  */
359
360 extern void not_just_help_class_command (char *arg, int from_tty);
361
362 /* Exported to cli/cli-setshow.c */
363
364 extern void print_doc_line (struct ui_file *, char *);
365
366
367 #endif /* !defined (CLI_DECODE_H) */