Fri Nov 21 02:19:57 1997 Geoffrey Noer <noer@cygnus.com>
[deliverable/binutils-gdb.git] / gdb / command.c
CommitLineData
7d9884b9
JG
1/* Handle lists of commands, their decoding and documentation, for GDB.
2 Copyright 1986, 1989, 1990, 1991 Free Software Foundation, Inc.
dd3b648e 3
99a7de40
JG
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
dd3b648e 8
99a7de40
JG
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
dd3b648e 13
99a7de40
JG
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
6c9638b4 16Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
dd3b648e
RP
17
18#include "defs.h"
4369a140 19#include "gdbcmd.h"
dd3b648e
RP
20#include "symtab.h"
21#include "value.h"
b52cac6b 22#include "wait.h"
dd3b648e 23#include <ctype.h>
2b576293 24#include "gdb_string.h"
1a494973
C
25#ifdef HAVE_UNISTD_H
26#include <unistd.h>
27#endif
dd3b648e 28
1ab3bf1b
JG
29/* Prototypes for local functions */
30
31static void
32undef_cmd_error PARAMS ((char *, char *));
33
34static void
35show_user PARAMS ((char *, int));
36
37static void
199b2450 38show_user_1 PARAMS ((struct cmd_list_element *, GDB_FILE *));
1ab3bf1b
JG
39
40static void
41make_command PARAMS ((char *, int));
42
43static void
44shell_escape PARAMS ((char *, int));
45
46static int
47parse_binary_operation PARAMS ((char *));
48
49static void
199b2450 50print_doc_line PARAMS ((GDB_FILE *, char *));
dd3b648e 51
f936e20d
RP
52/* Add element named NAME.
53 CLASS is the top level category into which commands are broken down
54 for "help" purposes.
dd3b648e
RP
55 FUN should be the function to execute the command;
56 it will get a character string as argument, with leading
57 and trailing blanks already eliminated.
58
59 DOC is a documentation string for the command.
60 Its first line should be a complete sentence.
61 It should start with ? for a command that is an abbreviation
f936e20d
RP
62 or with * for a command that most users don't need to know about.
63
36ad9bd5
JM
64 Add this command to command list *LIST.
65
66 Returns a pointer to the added command (not necessarily the head
67 of *LIST). */
dd3b648e
RP
68
69struct cmd_list_element *
70add_cmd (name, class, fun, doc, list)
71 char *name;
72 enum command_class class;
1ab3bf1b 73 void (*fun) PARAMS ((char *, int));
dd3b648e
RP
74 char *doc;
75 struct cmd_list_element **list;
76{
77 register struct cmd_list_element *c
78 = (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
36ad9bd5 79 struct cmd_list_element *p;
dd3b648e
RP
80
81 delete_cmd (name, list);
36ad9bd5
JM
82
83 if (*list == NULL || STRCMP ((*list)->name, name) >= 0)
84 {
85 c->next = *list;
86 *list = c;
87 }
88 else
89 {
90 p = *list;
91 while (p->next && STRCMP (p->next->name, name) <= 0)
92 {
93 p = p->next;
94 }
95 c->next = p->next;
96 p->next = c;
97 }
98
dd3b648e
RP
99 c->name = name;
100 c->class = class;
1ab3bf1b 101 c->function.cfunc = fun;
dd3b648e 102 c->doc = doc;
f56cc4e7
FF
103 c->hook = NULL;
104 c->prefixlist = NULL;
105 c->prefixname = NULL;
dd3b648e
RP
106 c->allow_unknown = 0;
107 c->abbrev_flag = 0;
dd3b648e 108 c->completer = make_symbol_completion_list;
f56cc4e7
FF
109 c->type = not_set_cmd;
110 c->var = NULL;
dd3b648e 111 c->var_type = var_boolean;
f56cc4e7
FF
112 c->enums = NULL;
113 c->user_commands = NULL;
114 c->hookee = NULL;
115 c->cmd_pointer = NULL;
36ad9bd5 116
dd3b648e
RP
117 return c;
118}
119
120/* Same as above, except that the abbrev_flag is set. */
121
1ab3bf1b
JG
122#if 0 /* Currently unused */
123
dd3b648e
RP
124struct cmd_list_element *
125add_abbrev_cmd (name, class, fun, doc, list)
126 char *name;
127 enum command_class class;
1ab3bf1b 128 void (*fun) PARAMS ((char *, int));
dd3b648e
RP
129 char *doc;
130 struct cmd_list_element **list;
131{
132 register struct cmd_list_element *c
133 = add_cmd (name, class, fun, doc, list);
134
135 c->abbrev_flag = 1;
136 return c;
137}
138
1ab3bf1b
JG
139#endif
140
dd3b648e
RP
141struct cmd_list_element *
142add_alias_cmd (name, oldname, class, abbrev_flag, list)
143 char *name;
144 char *oldname;
145 enum command_class class;
146 int abbrev_flag;
147 struct cmd_list_element **list;
148{
149 /* Must do this since lookup_cmd tries to side-effect its first arg */
150 char *copied_name;
151 register struct cmd_list_element *old;
152 register struct cmd_list_element *c;
153 copied_name = (char *) alloca (strlen (oldname) + 1);
154 strcpy (copied_name, oldname);
155 old = lookup_cmd (&copied_name, *list, "", 1, 1);
156
157 if (old == 0)
158 {
159 delete_cmd (name, list);
160 return 0;
161 }
162
1ab3bf1b 163 c = add_cmd (name, class, old->function.cfunc, old->doc, list);
dd3b648e
RP
164 c->prefixlist = old->prefixlist;
165 c->prefixname = old->prefixname;
166 c->allow_unknown = old->allow_unknown;
167 c->abbrev_flag = abbrev_flag;
a65841d7 168 c->cmd_pointer = old;
dd3b648e
RP
169 return c;
170}
171
172/* Like add_cmd but adds an element for a command prefix:
173 a name that should be followed by a subcommand to be looked up
174 in another command list. PREFIXLIST should be the address
175 of the variable containing that list. */
176
177struct cmd_list_element *
178add_prefix_cmd (name, class, fun, doc, prefixlist, prefixname,
179 allow_unknown, list)
180 char *name;
181 enum command_class class;
1ab3bf1b 182 void (*fun) PARAMS ((char *, int));
dd3b648e
RP
183 char *doc;
184 struct cmd_list_element **prefixlist;
185 char *prefixname;
186 int allow_unknown;
187 struct cmd_list_element **list;
188{
189 register struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);
190 c->prefixlist = prefixlist;
191 c->prefixname = prefixname;
192 c->allow_unknown = allow_unknown;
193 return c;
194}
195
0efe20a6 196/* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
dd3b648e
RP
197
198struct cmd_list_element *
199add_abbrev_prefix_cmd (name, class, fun, doc, prefixlist, prefixname,
1ab3bf1b 200 allow_unknown, list)
dd3b648e
RP
201 char *name;
202 enum command_class class;
1ab3bf1b 203 void (*fun) PARAMS ((char *, int));
dd3b648e
RP
204 char *doc;
205 struct cmd_list_element **prefixlist;
206 char *prefixname;
207 int allow_unknown;
208 struct cmd_list_element **list;
209{
210 register struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);
211 c->prefixlist = prefixlist;
212 c->prefixname = prefixname;
213 c->allow_unknown = allow_unknown;
214 c->abbrev_flag = 1;
215 return c;
216}
217
e6357967 218/* This is an empty "cfunc". */
dd3b648e 219void
e6357967
JK
220not_just_help_class_command (args, from_tty)
221 char *args;
222 int from_tty;
223{
224}
225
226/* This is an empty "sfunc". */
227static void empty_sfunc PARAMS ((char *, int, struct cmd_list_element *));
228
229static void
230empty_sfunc (args, from_tty, c)
dd3b648e
RP
231 char *args;
232 int from_tty;
719d9abb 233 struct cmd_list_element *c;
dd3b648e
RP
234{
235}
236
237/* Add element named NAME to command list LIST (the list for set
238 or some sublist thereof).
239 CLASS is as in add_cmd.
240 VAR_TYPE is the kind of thing we are setting.
241 VAR is address of the variable being controlled by this command.
242 DOC is the documentation string. */
1ab3bf1b 243
dd3b648e
RP
244struct cmd_list_element *
245add_set_cmd (name, class, var_type, var, doc, list)
246 char *name;
247 enum command_class class;
248 var_types var_type;
249 char *var;
250 char *doc;
251 struct cmd_list_element **list;
252{
dd3b648e 253 struct cmd_list_element *c
719d9abb 254 = add_cmd (name, class, NO_FUNCTION, doc, list);
dd3b648e
RP
255
256 c->type = set_cmd;
257 c->var_type = var_type;
258 c->var = var;
719d9abb
JK
259 /* This needs to be something besides NO_FUNCTION so that this isn't
260 treated as a help class. */
e6357967 261 c->function.sfunc = empty_sfunc;
dd3b648e
RP
262 return c;
263}
264
236274b9
SG
265/* Add element named NAME to command list LIST (the list for set
266 or some sublist thereof).
267 CLASS is as in add_cmd.
268 ENUMLIST is a list of strings which may follow NAME.
269 VAR is address of the variable which will contain the matching string
270 (from ENUMLIST).
271 DOC is the documentation string. */
272
273struct cmd_list_element *
274add_set_enum_cmd (name, class, enumlist, var, doc, list)
275 char *name;
276 enum command_class class;
277 char *enumlist[];
278 char *var;
279 char *doc;
280 struct cmd_list_element **list;
281{
282 struct cmd_list_element *c
283 = add_set_cmd (name, class, var_enum, var, doc, list);
284
285 c->enums = enumlist;
286
287 return c;
288}
289
dd3b648e 290/* Where SETCMD has already been added, add the corresponding show
36ad9bd5
JM
291 command to LIST and return a pointer to the added command (not
292 necessarily the head of LIST). */
dd3b648e
RP
293struct cmd_list_element *
294add_show_from_set (setcmd, list)
295 struct cmd_list_element *setcmd;
296 struct cmd_list_element **list;
297{
298 struct cmd_list_element *showcmd =
299 (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
36ad9bd5 300 struct cmd_list_element *p;
dd3b648e 301
4ed3a9ea 302 memcpy (showcmd, setcmd, sizeof (struct cmd_list_element));
dd3b648e
RP
303 delete_cmd (showcmd->name, list);
304 showcmd->type = show_cmd;
305
306 /* Replace "set " at start of docstring with "show ". */
307 if (setcmd->doc[0] == 'S' && setcmd->doc[1] == 'e'
308 && setcmd->doc[2] == 't' && setcmd->doc[3] == ' ')
58ae87f6 309 showcmd->doc = concat ("Show ", setcmd->doc + 4, NULL);
dd3b648e 310 else
199b2450 311 fprintf_unfiltered (gdb_stderr, "GDB internal error: Bad docstring for set command\n");
dd3b648e 312
36ad9bd5
JM
313 if (*list == NULL || STRCMP ((*list)->name, showcmd->name) >= 0)
314 {
315 showcmd->next = *list;
316 *list = showcmd;
317 }
318 else
319 {
320 p = *list;
321 while (p->next && STRCMP (p->next->name, showcmd->name) <= 0)
322 {
323 p = p->next;
324 }
325 showcmd->next = p->next;
326 p->next = showcmd;
327 }
328
dd3b648e
RP
329 return showcmd;
330}
331
332/* Remove the command named NAME from the command list. */
333
334void
335delete_cmd (name, list)
336 char *name;
337 struct cmd_list_element **list;
338{
339 register struct cmd_list_element *c;
340 struct cmd_list_element *p;
341
2e4964ad 342 while (*list && STREQ ((*list)->name, name))
dd3b648e 343 {
a65841d7
JG
344 if ((*list)->hookee)
345 (*list)->hookee->hook = 0; /* Hook slips out of its mouth */
dd3b648e 346 p = (*list)->next;
be772100 347 free ((PTR)*list);
dd3b648e
RP
348 *list = p;
349 }
350
351 if (*list)
352 for (c = *list; c->next;)
353 {
2e4964ad 354 if (STREQ (c->next->name, name))
dd3b648e 355 {
a65841d7
JG
356 if (c->next->hookee)
357 c->next->hookee->hook = 0; /* hooked cmd gets away. */
dd3b648e 358 p = c->next->next;
be772100 359 free ((PTR)c->next);
dd3b648e
RP
360 c->next = p;
361 }
362 else
363 c = c->next;
364 }
365}
366
dd3b648e
RP
367/* This command really has to deal with two things:
368 * 1) I want documentation on *this string* (usually called by
369 * "help commandname").
370 * 2) I want documentation on *this list* (usually called by
371 * giving a command that requires subcommands. Also called by saying
372 * just "help".)
373 *
374 * I am going to split this into two seperate comamnds, help_cmd and
375 * help_list.
376 */
377
378void
379help_cmd (command, stream)
380 char *command;
199b2450 381 GDB_FILE *stream;
dd3b648e
RP
382{
383 struct cmd_list_element *c;
384 extern struct cmd_list_element *cmdlist;
385
386 if (!command)
387 {
388 help_list (cmdlist, "", all_classes, stream);
389 return;
390 }
391
392 c = lookup_cmd (&command, cmdlist, "", 0, 0);
393
394 if (c == 0)
395 return;
396
397 /* There are three cases here.
398 If c->prefixlist is nonzero, we have a prefix command.
399 Print its documentation, then list its subcommands.
400
401 If c->function is nonzero, we really have a command.
402 Print its documentation and return.
403
404 If c->function is zero, we have a class name.
405 Print its documentation (as if it were a command)
406 and then set class to the number of this class
407 so that the commands in the class will be listed. */
408
409 fputs_filtered (c->doc, stream);
410 fputs_filtered ("\n", stream);
411
1ab3bf1b 412 if (c->prefixlist == 0 && c->function.cfunc != NULL)
dd3b648e
RP
413 return;
414 fprintf_filtered (stream, "\n");
415
416 /* If this is a prefix command, print it's subcommands */
417 if (c->prefixlist)
418 help_list (*c->prefixlist, c->prefixname, all_commands, stream);
419
420 /* If this is a class name, print all of the commands in the class */
1ab3bf1b 421 if (c->function.cfunc == NULL)
dd3b648e 422 help_list (cmdlist, "", c->class, stream);
a65841d7
JG
423
424 if (c->hook)
425 fprintf_filtered (stream, "\nThis command has a hook defined: %s\n",
426 c->hook->name);
dd3b648e
RP
427}
428
429/*
430 * Get a specific kind of help on a command list.
431 *
432 * LIST is the list.
433 * CMDTYPE is the prefix to use in the title string.
434 * CLASS is the class with which to list the nodes of this list (see
435 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
436 * everything, ALL_CLASSES for just classes, and non-negative for only things
437 * in a specific class.
438 * and STREAM is the output stream on which to print things.
439 * If you call this routine with a class >= 0, it recurses.
440 */
441void
442help_list (list, cmdtype, class, stream)
443 struct cmd_list_element *list;
444 char *cmdtype;
445 enum command_class class;
199b2450 446 GDB_FILE *stream;
dd3b648e
RP
447{
448 int len;
449 char *cmdtype1, *cmdtype2;
450
451 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
452 len = strlen (cmdtype);
453 cmdtype1 = (char *) alloca (len + 1);
454 cmdtype1[0] = 0;
455 cmdtype2 = (char *) alloca (len + 4);
456 cmdtype2[0] = 0;
457 if (len)
458 {
459 cmdtype1[0] = ' ';
460 strncpy (cmdtype1 + 1, cmdtype, len - 1);
461 cmdtype1[len] = 0;
462 strncpy (cmdtype2, cmdtype, len - 1);
463 strcpy (cmdtype2 + len - 1, " sub");
464 }
465
466 if (class == all_classes)
467 fprintf_filtered (stream, "List of classes of %scommands:\n\n", cmdtype2);
468 else
469 fprintf_filtered (stream, "List of %scommands:\n\n", cmdtype2);
470
471 help_cmd_list (list, class, cmdtype, (int)class >= 0, stream);
472
473 if (class == all_classes)
474 fprintf_filtered (stream, "\n\
475Type \"help%s\" followed by a class name for a list of commands in that class.",
476 cmdtype1);
477
478 fprintf_filtered (stream, "\n\
479Type \"help%s\" followed by %scommand name for full documentation.\n\
480Command name abbreviations are allowed if unambiguous.\n",
481 cmdtype1, cmdtype2);
482}
483
484/* Print only the first line of STR on STREAM. */
485static void
486print_doc_line (stream, str)
199b2450 487 GDB_FILE *stream;
dd3b648e
RP
488 char *str;
489{
490 static char *line_buffer = 0;
491 static int line_size;
492 register char *p;
493
494 if (!line_buffer)
495 {
496 line_size = 80;
497 line_buffer = (char *) xmalloc (line_size);
498 }
499
500 p = str;
501 while (*p && *p != '\n' && *p != '.' && *p != ',')
502 p++;
503 if (p - str > line_size - 1)
504 {
505 line_size = p - str + 1;
be772100 506 free ((PTR)line_buffer);
dd3b648e
RP
507 line_buffer = (char *) xmalloc (line_size);
508 }
509 strncpy (line_buffer, str, p - str);
510 line_buffer[p - str] = '\0';
511 if (islower (line_buffer[0]))
512 line_buffer[0] = toupper (line_buffer[0]);
513 fputs_filtered (line_buffer, stream);
514}
515
516/*
517 * Implement a help command on command list LIST.
518 * RECURSE should be non-zero if this should be done recursively on
519 * all sublists of LIST.
520 * PREFIX is the prefix to print before each command name.
521 * STREAM is the stream upon which the output should be written.
522 * CLASS should be:
523 * A non-negative class number to list only commands in that
524 * class.
525 * ALL_COMMANDS to list all commands in list.
526 * ALL_CLASSES to list all classes in list.
527 *
528 * Note that RECURSE will be active on *all* sublists, not just the
1ab3bf1b 529 * ones selected by the criteria above (ie. the selection mechanism
dd3b648e
RP
530 * is at the low level, not the high-level).
531 */
532void
533help_cmd_list (list, class, prefix, recurse, stream)
534 struct cmd_list_element *list;
535 enum command_class class;
536 char *prefix;
537 int recurse;
199b2450 538 GDB_FILE *stream;
dd3b648e
RP
539{
540 register struct cmd_list_element *c;
541
542 for (c = list; c; c = c->next)
543 {
544 if (c->abbrev_flag == 0 &&
545 (class == all_commands
1ab3bf1b
JG
546 || (class == all_classes && c->function.cfunc == NULL)
547 || (class == c->class && c->function.cfunc != NULL)))
dd3b648e
RP
548 {
549 fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
550 print_doc_line (stream, c->doc);
551 fputs_filtered ("\n", stream);
552 }
553 if (recurse
554 && c->prefixlist != 0
555 && c->abbrev_flag == 0)
556 help_cmd_list (*c->prefixlist, class, c->prefixname, 1, stream);
557 }
558}
559\f
311592ff
FF
560/* This routine takes a line of TEXT and a CLIST in which to start the
561 lookup. When it returns it will have incremented the text pointer past
562 the section of text it matched, set *RESULT_LIST to point to the list in
563 which the last word was matched, and will return a pointer to the cmd
564 list element which the text matches. It will return NULL if no match at
565 all was possible. It will return -1 (cast appropriately, ick) if ambigous
566 matches are possible; in this case *RESULT_LIST will be set to point to
567 the list in which there are ambiguous choices (and *TEXT will be set to
568 the ambiguous text string).
dd3b648e 569
a65841d7
JG
570 If the located command was an abbreviation, this routine returns the base
571 command of the abbreviation.
572
dd3b648e
RP
573 It does no error reporting whatsoever; control will always return
574 to the superior routine.
575
311592ff
FF
576 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
577 at the prefix_command (ie. the best match) *or* (special case) will be NULL
578 if no prefix command was ever found. For example, in the case of "info a",
579 "info" matches without ambiguity, but "a" could be "args" or "address", so
580 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
581 RESULT_LIST should not be interpeted as a pointer to the beginning of a
a32ebcfd
JK
582 list; it simply points to a specific command. In the case of an ambiguous
583 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
584 "info t" can be "info types" or "info target"; upon return *TEXT has been
585 advanced past "info ").
dd3b648e
RP
586
587 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
588 affect the operation).
589
590 This routine does *not* modify the text pointed to by TEXT.
591
311592ff
FF
592 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
593 are actually help classes rather than commands (i.e. the function field of
594 the struct cmd_list_element is NULL). */
dd3b648e
RP
595
596struct cmd_list_element *
597lookup_cmd_1 (text, clist, result_list, ignore_help_classes)
598 char **text;
599 struct cmd_list_element *clist, **result_list;
600 int ignore_help_classes;
601{
602 char *p, *command;
603 int len, tmp, nfound;
604 struct cmd_list_element *found, *c;
605
606 while (**text == ' ' || **text == '\t')
607 (*text)++;
608
609 /* Treating underscores as part of command words is important
610 so that "set args_foo()" doesn't get interpreted as
611 "set args _foo()". */
612 for (p = *text;
613 *p && (isalnum(*p) || *p == '-' || *p == '_');
614 p++)
615 ;
616
617 /* If nothing but whitespace, return 0. */
618 if (p == *text)
619 return 0;
620
621 len = p - *text;
622
623 /* *text and p now bracket the first command word to lookup (and
624 it's length is len). We copy this into a local temporary,
625 converting to lower case as we go. */
626
627 command = (char *) alloca (len + 1);
628 for (tmp = 0; tmp < len; tmp++)
629 {
630 char x = (*text)[tmp];
5c71cf23 631 command[tmp] = isupper(x) ? tolower(x) : x;
dd3b648e
RP
632 }
633 command[len] = '\0';
634
635 /* Look it up. */
636 found = 0;
637 nfound = 0;
638 for (c = clist; c; c = c->next)
639 if (!strncmp (command, c->name, len)
1ab3bf1b 640 && (!ignore_help_classes || c->function.cfunc))
dd3b648e
RP
641 {
642 found = c;
643 nfound++;
644 if (c->name[len] == '\0')
645 {
646 nfound = 1;
647 break;
648 }
649 }
650
651 /* If nothing matches, we have a simple failure. */
652 if (nfound == 0)
653 return 0;
654
655 if (nfound > 1)
656 {
657 if (result_list != NULL)
658 /* Will be modified in calling routine
659 if we know what the prefix command is. */
660 *result_list = 0;
661 return (struct cmd_list_element *) -1; /* Ambiguous. */
662 }
663
664 /* We've matched something on this list. Move text pointer forward. */
665
666 *text = p;
a65841d7
JG
667
668 /* If this was an abbreviation, use the base command instead. */
669
670 if (found->cmd_pointer)
671 found = found->cmd_pointer;
672
673 /* If we found a prefix command, keep looking. */
674
dd3b648e
RP
675 if (found->prefixlist)
676 {
677 c = lookup_cmd_1 (text, *found->prefixlist, result_list,
678 ignore_help_classes);
679 if (!c)
680 {
681 /* Didn't find anything; this is as far as we got. */
682 if (result_list != NULL)
683 *result_list = clist;
684 return found;
685 }
686 else if (c == (struct cmd_list_element *) -1)
687 {
36ad9bd5 688 /* We've gotten this far properly, but the next step
dd3b648e
RP
689 is ambiguous. We need to set the result list to the best
690 we've found (if an inferior hasn't already set it). */
691 if (result_list != NULL)
692 if (!*result_list)
693 /* This used to say *result_list = *found->prefixlist
694 If that was correct, need to modify the documentation
695 at the top of this function to clarify what is supposed
696 to be going on. */
697 *result_list = found;
698 return c;
699 }
700 else
701 {
702 /* We matched! */
703 return c;
704 }
705 }
706 else
707 {
708 if (result_list != NULL)
709 *result_list = clist;
710 return found;
711 }
712}
713
81066208
JG
714/* All this hair to move the space to the front of cmdtype */
715
1ab3bf1b 716static void
81066208
JG
717undef_cmd_error (cmdtype, q)
718 char *cmdtype, *q;
719{
720 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
721 cmdtype,
722 q,
723 *cmdtype? " ": "",
724 strlen(cmdtype)-1,
725 cmdtype);
726}
727
dd3b648e
RP
728/* Look up the contents of *LINE as a command in the command list LIST.
729 LIST is a chain of struct cmd_list_element's.
730 If it is found, return the struct cmd_list_element for that command
731 and update *LINE to point after the command name, at the first argument.
732 If not found, call error if ALLOW_UNKNOWN is zero
733 otherwise (or if error returns) return zero.
734 Call error if specified command is ambiguous,
735 unless ALLOW_UNKNOWN is negative.
736 CMDTYPE precedes the word "command" in the error message.
737
738 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
739 elements which are actually help classes rather than commands (i.e.
740 the function field of the struct cmd_list_element is 0). */
741
742struct cmd_list_element *
743lookup_cmd (line, list, cmdtype, allow_unknown, ignore_help_classes)
744 char **line;
745 struct cmd_list_element *list;
746 char *cmdtype;
747 int allow_unknown;
748 int ignore_help_classes;
749{
750 struct cmd_list_element *last_list = 0;
751 struct cmd_list_element *c =
752 lookup_cmd_1 (line, list, &last_list, ignore_help_classes);
09973223
JK
753#if 0
754 /* This is wrong for complete_command. */
dd3b648e
RP
755 char *ptr = (*line) + strlen (*line) - 1;
756
757 /* Clear off trailing whitespace. */
758 while (ptr >= *line && (*ptr == ' ' || *ptr == '\t'))
759 ptr--;
760 *(ptr + 1) = '\0';
09973223 761#endif
dd3b648e
RP
762
763 if (!c)
764 {
765 if (!allow_unknown)
766 {
767 if (!*line)
768 error ("Lack of needed %scommand", cmdtype);
769 else
770 {
771 char *p = *line, *q;
772
773 while (isalnum(*p) || *p == '-')
774 p++;
775
776 q = (char *) alloca (p - *line + 1);
777 strncpy (q, *line, p - *line);
36ad9bd5 778 q[p - *line] = '\0';
81066208 779 undef_cmd_error (cmdtype, q);
dd3b648e
RP
780 }
781 }
782 else
783 return 0;
784 }
785 else if (c == (struct cmd_list_element *) -1)
786 {
787 /* Ambigous. Local values should be off prefixlist or called
788 values. */
789 int local_allow_unknown = (last_list ? last_list->allow_unknown :
790 allow_unknown);
791 char *local_cmdtype = last_list ? last_list->prefixname : cmdtype;
792 struct cmd_list_element *local_list =
793 (last_list ? *(last_list->prefixlist) : list);
794
795 if (local_allow_unknown < 0)
796 {
797 if (last_list)
798 return last_list; /* Found something. */
799 else
800 return 0; /* Found nothing. */
801 }
802 else
803 {
804 /* Report as error. */
805 int amb_len;
806 char ambbuf[100];
807
808 for (amb_len = 0;
809 ((*line)[amb_len] && (*line)[amb_len] != ' '
810 && (*line)[amb_len] != '\t');
811 amb_len++)
812 ;
813
814 ambbuf[0] = 0;
815 for (c = local_list; c; c = c->next)
816 if (!strncmp (*line, c->name, amb_len))
817 {
818 if (strlen (ambbuf) + strlen (c->name) + 6 < (int)sizeof ambbuf)
819 {
820 if (strlen (ambbuf))
821 strcat (ambbuf, ", ");
822 strcat (ambbuf, c->name);
823 }
824 else
825 {
826 strcat (ambbuf, "..");
827 break;
828 }
829 }
830 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype,
831 *line, ambbuf);
832 return 0; /* lint */
833 }
834 }
835 else
836 {
837 /* We've got something. It may still not be what the caller
838 wants (if this command *needs* a subcommand). */
839 while (**line == ' ' || **line == '\t')
840 (*line)++;
841
842 if (c->prefixlist && **line && !c->allow_unknown)
81066208 843 undef_cmd_error (c->prefixname, *line);
dd3b648e
RP
844
845 /* Seems to be what he wants. Return it. */
846 return c;
847 }
848 return 0;
849}
850
851#if 0
852/* Look up the contents of *LINE as a command in the command list LIST.
853 LIST is a chain of struct cmd_list_element's.
854 If it is found, return the struct cmd_list_element for that command
855 and update *LINE to point after the command name, at the first argument.
856 If not found, call error if ALLOW_UNKNOWN is zero
857 otherwise (or if error returns) return zero.
858 Call error if specified command is ambiguous,
859 unless ALLOW_UNKNOWN is negative.
860 CMDTYPE precedes the word "command" in the error message. */
861
862struct cmd_list_element *
863lookup_cmd (line, list, cmdtype, allow_unknown)
864 char **line;
865 struct cmd_list_element *list;
866 char *cmdtype;
867 int allow_unknown;
868{
869 register char *p;
870 register struct cmd_list_element *c, *found;
871 int nfound;
872 char ambbuf[100];
873 char *processed_cmd;
874 int i, cmd_len;
875
876 /* Skip leading whitespace. */
877
878 while (**line == ' ' || **line == '\t')
879 (*line)++;
880
881 /* Clear out trailing whitespace. */
882
883 p = *line + strlen (*line);
884 while (p != *line && (p[-1] == ' ' || p[-1] == '\t'))
885 p--;
886 *p = 0;
887
888 /* Find end of command name. */
889
890 p = *line;
5c71cf23 891 while (*p == '-' || isalnum(*p))
dd3b648e
RP
892 p++;
893
894 /* Look up the command name.
895 If exact match, keep that.
896 Otherwise, take command abbreviated, if unique. Note that (in my
897 opinion) a null string does *not* indicate ambiguity; simply the
898 end of the argument. */
899
900 if (p == *line)
901 {
902 if (!allow_unknown)
903 error ("Lack of needed %scommand", cmdtype);
904 return 0;
905 }
906
907 /* Copy over to a local buffer, converting to lowercase on the way.
908 This is in case the command being parsed is a subcommand which
909 doesn't match anything, and that's ok. We want the original
910 untouched for the routine of the original command. */
911
912 processed_cmd = (char *) alloca (p - *line + 1);
913 for (cmd_len = 0; cmd_len < p - *line; cmd_len++)
914 {
915 char x = (*line)[cmd_len];
5c71cf23
PB
916 if (isupper(x))
917 processed_cmd[cmd_len] = tolower(x);
dd3b648e
RP
918 else
919 processed_cmd[cmd_len] = x;
920 }
921 processed_cmd[cmd_len] = '\0';
922
923 /* Check all possibilities in the current command list. */
924 found = 0;
925 nfound = 0;
926 for (c = list; c; c = c->next)
927 {
928 if (!strncmp (processed_cmd, c->name, cmd_len))
929 {
930 found = c;
931 nfound++;
932 if (c->name[cmd_len] == 0)
933 {
934 nfound = 1;
935 break;
936 }
937 }
938 }
939
940 /* Report error for undefined command name. */
941
942 if (nfound != 1)
943 {
944 if (nfound > 1 && allow_unknown >= 0)
945 {
946 ambbuf[0] = 0;
947 for (c = list; c; c = c->next)
948 if (!strncmp (processed_cmd, c->name, cmd_len))
949 {
950 if (strlen (ambbuf) + strlen (c->name) + 6 < sizeof ambbuf)
951 {
952 if (strlen (ambbuf))
953 strcat (ambbuf, ", ");
954 strcat (ambbuf, c->name);
955 }
956 else
957 {
958 strcat (ambbuf, "..");
959 break;
960 }
961 }
962 error ("Ambiguous %scommand \"%s\": %s.", cmdtype,
963 processed_cmd, ambbuf);
964 }
965 else if (!allow_unknown)
966 error ("Undefined %scommand: \"%s\".", cmdtype, processed_cmd);
967 return 0;
968 }
969
970 /* Skip whitespace before the argument. */
971
972 while (*p == ' ' || *p == '\t') p++;
973 *line = p;
974
975 if (found->prefixlist && *p)
976 {
977 c = lookup_cmd (line, *found->prefixlist, found->prefixname,
978 found->allow_unknown);
979 if (c)
980 return c;
981 }
982
983 return found;
984}
985#endif
986
987/* Helper function for SYMBOL_COMPLETION_FUNCTION. */
988
989/* Return a vector of char pointers which point to the different
a32ebcfd
JK
990 possible completions in LIST of TEXT.
991
992 WORD points in the same buffer as TEXT, and completions should be
993 returned relative to this position. For example, suppose TEXT is "foo"
994 and we want to complete to "foobar". If WORD is "oo", return
995 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
dd3b648e
RP
996
997char **
a32ebcfd 998complete_on_cmdlist (list, text, word)
dd3b648e
RP
999 struct cmd_list_element *list;
1000 char *text;
a32ebcfd 1001 char *word;
dd3b648e
RP
1002{
1003 struct cmd_list_element *ptr;
1004 char **matchlist;
1005 int sizeof_matchlist;
1006 int matches;
1007 int textlen = strlen (text);
1008
1009 sizeof_matchlist = 10;
1010 matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
1011 matches = 0;
1012
1013 for (ptr = list; ptr; ptr = ptr->next)
1014 if (!strncmp (ptr->name, text, textlen)
1015 && !ptr->abbrev_flag
1ab3bf1b 1016 && (ptr->function.cfunc
dd3b648e
RP
1017 || ptr->prefixlist))
1018 {
1019 if (matches == sizeof_matchlist)
1020 {
1021 sizeof_matchlist *= 2;
1022 matchlist = (char **) xrealloc ((char *)matchlist,
1023 (sizeof_matchlist
1024 * sizeof (char *)));
1025 }
1026
1027 matchlist[matches] = (char *)
a32ebcfd
JK
1028 xmalloc (strlen (word) + strlen (ptr->name) + 1);
1029 if (word == text)
1030 strcpy (matchlist[matches], ptr->name);
1031 else if (word > text)
1032 {
1033 /* Return some portion of ptr->name. */
1034 strcpy (matchlist[matches], ptr->name + (word - text));
1035 }
1036 else
1037 {
1038 /* Return some of text plus ptr->name. */
1039 strncpy (matchlist[matches], word, text - word);
1040 matchlist[matches][text - word] = '\0';
1041 strcat (matchlist[matches], ptr->name);
1042 }
1043 ++matches;
dd3b648e
RP
1044 }
1045
1046 if (matches == 0)
1047 {
be772100 1048 free ((PTR)matchlist);
dd3b648e
RP
1049 matchlist = 0;
1050 }
1051 else
1052 {
1053 matchlist = (char **) xrealloc ((char *)matchlist, ((matches + 1)
1054 * sizeof (char *)));
1055 matchlist[matches] = (char *) 0;
1056 }
1057
1058 return matchlist;
1059}
1060
236274b9
SG
1061/* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1062
1063/* Return a vector of char pointers which point to the different
1064 possible completions in CMD of TEXT.
1065
1066 WORD points in the same buffer as TEXT, and completions should be
1067 returned relative to this position. For example, suppose TEXT is "foo"
1068 and we want to complete to "foobar". If WORD is "oo", return
1069 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1070
1071char **
1072complete_on_enum (enumlist, text, word)
1073 char **enumlist;
1074 char *text;
1075 char *word;
1076{
1077 char **matchlist;
1078 int sizeof_matchlist;
1079 int matches;
1080 int textlen = strlen (text);
1081 int i;
1082 char *name;
1083
1084 sizeof_matchlist = 10;
1085 matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
1086 matches = 0;
1087
b52cac6b 1088 for (i = 0; (name = enumlist[i]) != NULL; i++)
236274b9
SG
1089 if (strncmp (name, text, textlen) == 0)
1090 {
1091 if (matches == sizeof_matchlist)
1092 {
1093 sizeof_matchlist *= 2;
1094 matchlist = (char **) xrealloc ((char *)matchlist,
1095 (sizeof_matchlist
1096 * sizeof (char *)));
1097 }
1098
1099 matchlist[matches] = (char *)
1100 xmalloc (strlen (word) + strlen (name) + 1);
1101 if (word == text)
1102 strcpy (matchlist[matches], name);
1103 else if (word > text)
1104 {
1105 /* Return some portion of name. */
1106 strcpy (matchlist[matches], name + (word - text));
1107 }
1108 else
1109 {
1110 /* Return some of text plus name. */
1111 strncpy (matchlist[matches], word, text - word);
1112 matchlist[matches][text - word] = '\0';
1113 strcat (matchlist[matches], name);
1114 }
1115 ++matches;
1116 }
1117
1118 if (matches == 0)
1119 {
1120 free ((PTR)matchlist);
1121 matchlist = 0;
1122 }
1123 else
1124 {
1125 matchlist = (char **) xrealloc ((char *)matchlist, ((matches + 1)
1126 * sizeof (char *)));
1127 matchlist[matches] = (char *) 0;
1128 }
1129
1130 return matchlist;
1131}
1132
dd3b648e
RP
1133static int
1134parse_binary_operation (arg)
1135 char *arg;
1136{
1137 int length;
1138
1139 if (!arg || !*arg)
1140 return 1;
1141
1142 length = strlen (arg);
1143
1144 while (arg[length - 1] == ' ' || arg[length - 1] == '\t')
1145 length--;
1146
1147 if (!strncmp (arg, "on", length)
1148 || !strncmp (arg, "1", length)
1149 || !strncmp (arg, "yes", length))
1150 return 1;
1151 else
1152 if (!strncmp (arg, "off", length)
1153 || !strncmp (arg, "0", length)
1154 || !strncmp (arg, "no", length))
1155 return 0;
1156 else
1157 {
1158 error ("\"on\" or \"off\" expected.");
1159 return 0;
1160 }
1161}
1162
1163/* Do a "set" or "show" command. ARG is NULL if no argument, or the text
1164 of the argument, and FROM_TTY is nonzero if this command is being entered
1165 directly by the user (i.e. these are just like any other
1166 command). C is the command list element for the command. */
1167void
1168do_setshow_command (arg, from_tty, c)
1169 char *arg;
1170 int from_tty;
1171 struct cmd_list_element *c;
1172{
1173 if (c->type == set_cmd)
1174 {
1175 switch (c->var_type)
1176 {
1177 case var_string:
1178 {
1179 char *new;
1180 char *p;
1181 char *q;
1182 int ch;
1183
1184 if (arg == NULL)
1185 arg = "";
1186 new = (char *) xmalloc (strlen (arg) + 2);
1187 p = arg; q = new;
1ab3bf1b 1188 while ((ch = *p++) != '\000')
dd3b648e
RP
1189 {
1190 if (ch == '\\')
1191 {
1192 /* \ at end of argument is used after spaces
1193 so they won't be lost. */
72e35288
JK
1194 /* This is obsolete now that we no longer strip
1195 trailing whitespace and actually, the backslash
1196 didn't get here in my test, readline or
1197 something did something funky with a backslash
1198 right before a newline. */
dd3b648e
RP
1199 if (*p == 0)
1200 break;
1201 ch = parse_escape (&p);
1202 if (ch == 0)
1203 break; /* C loses */
1204 else if (ch > 0)
1205 *q++ = ch;
1206 }
1207 else
1208 *q++ = ch;
1209 }
72e35288 1210#if 0
dd3b648e
RP
1211 if (*(p - 1) != '\\')
1212 *q++ = ' ';
72e35288 1213#endif
dd3b648e
RP
1214 *q++ = '\0';
1215 new = (char *) xrealloc (new, q - new);
1216 if (*(char **)c->var != NULL)
1217 free (*(char **)c->var);
1218 *(char **) c->var = new;
1219 }
1220 break;
1221 case var_string_noescape:
1222 if (arg == NULL)
1223 arg = "";
1224 if (*(char **)c->var != NULL)
1225 free (*(char **)c->var);
1226 *(char **) c->var = savestring (arg, strlen (arg));
1227 break;
1228 case var_filename:
1229 if (arg == NULL)
1230 error_no_arg ("filename to set it to.");
1231 if (*(char **)c->var != NULL)
1232 free (*(char **)c->var);
1233 *(char **)c->var = tilde_expand (arg);
1234 break;
1235 case var_boolean:
1236 *(int *) c->var = parse_binary_operation (arg);
1237 break;
1238 case var_uinteger:
1239 if (arg == NULL)
1240 error_no_arg ("integer to set it to.");
4966c17c
JG
1241 *(unsigned int *) c->var = parse_and_eval_address (arg);
1242 if (*(unsigned int *) c->var == 0)
1243 *(unsigned int *) c->var = UINT_MAX;
dd3b648e 1244 break;
359a097f
JK
1245 case var_integer:
1246 {
1247 unsigned int val;
1248 if (arg == NULL)
1249 error_no_arg ("integer to set it to.");
1250 val = parse_and_eval_address (arg);
1251 if (val == 0)
1252 *(int *) c->var = INT_MAX;
1253 else if (val >= INT_MAX)
1254 error ("integer %u out of range", val);
1255 else
1256 *(int *) c->var = val;
1257 break;
1258 }
dd3b648e
RP
1259 case var_zinteger:
1260 if (arg == NULL)
1261 error_no_arg ("integer to set it to.");
1262 *(int *) c->var = parse_and_eval_address (arg);
1263 break;
236274b9
SG
1264 case var_enum:
1265 {
1266 int i;
1267 int len;
1268 int nmatches;
efaf2b58 1269 char *match = NULL;
236274b9
SG
1270 char *p;
1271
1272 p = strchr (arg, ' ');
1273
1274 if (p)
1275 len = p - arg;
1276 else
1277 len = strlen (arg);
1278
1279 nmatches = 0;
1280 for (i = 0; c->enums[i]; i++)
1281 if (strncmp (arg, c->enums[i], len) == 0)
1282 {
1283 match = c->enums[i];
1284 nmatches++;
1285 }
1286
1287 if (nmatches <= 0)
1288 error ("Undefined item: \"%s\".", arg);
1289
1290 if (nmatches > 1)
1291 error ("Ambiguous item \"%s\".", arg);
1292
1293 *(char **)c->var = match;
1294 }
1295 break;
dd3b648e
RP
1296 default:
1297 error ("gdb internal error: bad var_type in do_setshow_command");
1298 }
1299 }
1300 else if (c->type == show_cmd)
1301 {
1302 /* Print doc minus "show" at start. */
199b2450 1303 print_doc_line (gdb_stdout, c->doc + 5);
dd3b648e 1304
199b2450 1305 fputs_filtered (" is ", gdb_stdout);
dd3b648e
RP
1306 wrap_here (" ");
1307 switch (c->var_type)
1308 {
1309 case var_string:
1310 {
1311 unsigned char *p;
76420d46 1312
199b2450 1313 fputs_filtered ("\"", gdb_stdout);
76420d46
SG
1314 if (*(unsigned char **)c->var)
1315 for (p = *(unsigned char **) c->var; *p != '\0'; p++)
1316 gdb_printchar (*p, gdb_stdout, '"');
199b2450 1317 fputs_filtered ("\"", gdb_stdout);
dd3b648e
RP
1318 }
1319 break;
1320 case var_string_noescape:
1321 case var_filename:
236274b9 1322 case var_enum:
199b2450 1323 fputs_filtered ("\"", gdb_stdout);
76420d46
SG
1324 if (*(char **)c->var)
1325 fputs_filtered (*(char **) c->var, gdb_stdout);
199b2450 1326 fputs_filtered ("\"", gdb_stdout);
dd3b648e
RP
1327 break;
1328 case var_boolean:
199b2450 1329 fputs_filtered (*(int *) c->var ? "on" : "off", gdb_stdout);
dd3b648e
RP
1330 break;
1331 case var_uinteger:
1332 if (*(unsigned int *) c->var == UINT_MAX) {
199b2450 1333 fputs_filtered ("unlimited", gdb_stdout);
dd3b648e
RP
1334 break;
1335 }
1336 /* else fall through */
1337 case var_zinteger:
199b2450 1338 fprintf_filtered (gdb_stdout, "%u", *(unsigned int *) c->var);
dd3b648e 1339 break;
359a097f
JK
1340 case var_integer:
1341 if (*(int *) c->var == INT_MAX)
1342 {
199b2450 1343 fputs_filtered ("unlimited", gdb_stdout);
359a097f
JK
1344 }
1345 else
199b2450 1346 fprintf_filtered (gdb_stdout, "%d", *(int *) c->var);
359a097f
JK
1347 break;
1348
dd3b648e
RP
1349 default:
1350 error ("gdb internal error: bad var_type in do_setshow_command");
1351 }
199b2450 1352 fputs_filtered (".\n", gdb_stdout);
dd3b648e
RP
1353 }
1354 else
1355 error ("gdb internal error: bad cmd_type in do_setshow_command");
1ab3bf1b 1356 (*c->function.sfunc) (NULL, from_tty, c);
dd3b648e
RP
1357}
1358
1359/* Show all the settings in a list of show commands. */
1360
1361void
1362cmd_show_list (list, from_tty, prefix)
1363 struct cmd_list_element *list;
1364 int from_tty;
1365 char *prefix;
1366{
1367 for (; list != NULL; list = list->next) {
1368 /* If we find a prefix, run its list, prefixing our output by its
1369 prefix (with "show " skipped). */
1370 if (list->prefixlist && !list->abbrev_flag)
1371 cmd_show_list (*list->prefixlist, from_tty, list->prefixname + 5);
1372 if (list->type == show_cmd)
1373 {
199b2450
TL
1374 fputs_filtered (prefix, gdb_stdout);
1375 fputs_filtered (list->name, gdb_stdout);
1376 fputs_filtered (": ", gdb_stdout);
dd3b648e
RP
1377 do_setshow_command ((char *)NULL, from_tty, list);
1378 }
1379 }
1380}
1381
e1ce8aa5 1382/* ARGSUSED */
dd3b648e
RP
1383static void
1384shell_escape (arg, from_tty)
1385 char *arg;
1386 int from_tty;
1387{
87237c52
JK
1388#ifdef CANT_FORK
1389 /* FIXME: what about errors (I don't know how GO32 system() handles
1390 them)? */
1391 system (arg);
1392#else /* Can fork. */
dd3b648e
RP
1393 int rc, status, pid;
1394 char *p, *user_shell;
dd3b648e
RP
1395
1396 if ((user_shell = (char *) getenv ("SHELL")) == NULL)
1397 user_shell = "/bin/sh";
1398
1399 /* Get the name of the shell for arg0 */
1ab3bf1b 1400 if ((p = strrchr (user_shell, '/')) == NULL)
dd3b648e
RP
1401 p = user_shell;
1402 else
1403 p++; /* Get past '/' */
1404
1405 if ((pid = fork()) == 0)
1406 {
1407 if (!arg)
1408 execl (user_shell, p, 0);
1409 else
1410 execl (user_shell, p, "-c", arg, 0);
1411
5b3591ab
JK
1412 fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell,
1413 safe_strerror (errno));
1414 gdb_flush (gdb_stderr);
1415 _exit (0177);
dd3b648e
RP
1416 }
1417
1418 if (pid != -1)
1419 while ((rc = wait (&status)) != pid && rc != -1)
1420 ;
1421 else
1422 error ("Fork failed");
87237c52 1423#endif /* Can fork. */
dd3b648e
RP
1424}
1425
1426static void
1427make_command (arg, from_tty)
1428 char *arg;
1429 int from_tty;
1430{
1431 char *p;
1432
1433 if (arg == 0)
1434 p = "make";
1435 else
1436 {
1437 p = xmalloc (sizeof("make ") + strlen(arg));
1438 strcpy (p, "make ");
1439 strcpy (p + sizeof("make ")-1, arg);
1440 }
1441
1442 shell_escape (p, from_tty);
1443}
1444
3f2e006b 1445static void
4369a140 1446show_user_1 (c, stream)
3f2e006b 1447 struct cmd_list_element *c;
199b2450 1448 GDB_FILE *stream;
3f2e006b
JG
1449{
1450 register struct command_line *cmdlines;
1451
1452 cmdlines = c->user_commands;
1453 if (!cmdlines)
1454 return;
3021c40d
JG
1455 fputs_filtered ("User command ", stream);
1456 fputs_filtered (c->name, stream);
1457 fputs_filtered (":\n", stream);
59528079 1458
3f2e006b
JG
1459 while (cmdlines)
1460 {
59528079 1461 print_command_line (cmdlines, 4);
3f2e006b
JG
1462 cmdlines = cmdlines->next;
1463 }
1464 fputs_filtered ("\n", stream);
1465}
1466
1467/* ARGSUSED */
1468static void
4369a140 1469show_user (args, from_tty)
3f2e006b
JG
1470 char *args;
1471 int from_tty;
1472{
1473 struct cmd_list_element *c;
1474 extern struct cmd_list_element *cmdlist;
1475
1476 if (args)
1477 {
1478 c = lookup_cmd (&args, cmdlist, "", 0, 1);
1479 if (c->class != class_user)
1480 error ("Not a user command.");
199b2450 1481 show_user_1 (c, gdb_stdout);
3f2e006b
JG
1482 }
1483 else
1484 {
1485 for (c = cmdlist; c; c = c->next)
1486 {
1487 if (c->class == class_user)
199b2450 1488 show_user_1 (c, gdb_stdout);
3f2e006b
JG
1489 }
1490 }
1491}
1492
dd3b648e
RP
1493void
1494_initialize_command ()
1495{
1496 add_com ("shell", class_support, shell_escape,
1497 "Execute the rest of the line as a shell command. \n\
1498With no arguments, run an inferior shell.");
dd3b648e
RP
1499 add_com ("make", class_support, make_command,
1500 "Run the ``make'' program using the rest of the line as arguments.");
4369a140
JG
1501 add_cmd ("user", no_class, show_user,
1502 "Show definitions of user defined commands.\n\
3f2e006b 1503Argument is the name of the user defined command.\n\
4369a140 1504With no argument, show definitions of all user defined commands.", &showlist);
dd3b648e 1505}
This page took 0.328514 seconds and 4 git commands to generate.