1 /* Handle lists of commands, their decoding and documentation, for GDB.
2 Copyright 1986, 1989, 1990, 1991 Free Software Foundation, Inc.
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 /* Prototypes for local functions */
28 undef_cmd_error
PARAMS ((char *, char *));
31 show_user
PARAMS ((char *, int));
34 show_user_1
PARAMS ((struct cmd_list_element
*, FILE *));
37 make_command
PARAMS ((char *, int));
40 shell_escape
PARAMS ((char *, int));
43 parse_binary_operation
PARAMS ((char *));
46 print_doc_line
PARAMS ((FILE *, char *));
49 not_just_help_class_command
PARAMS ((char *, int));
51 /* Add element named NAME to command list *LIST.
52 FUN should be the function to execute the command;
53 it will get a character string as argument, with leading
54 and trailing blanks already eliminated.
56 DOC is a documentation string for the command.
57 Its first line should be a complete sentence.
58 It should start with ? for a command that is an abbreviation
59 or with * for a command that most users don't need to know about. */
61 struct cmd_list_element
*
62 add_cmd (name
, class, fun
, doc
, list
)
64 enum command_class
class;
65 void (*fun
) PARAMS ((char *, int));
67 struct cmd_list_element
**list
;
69 register struct cmd_list_element
*c
70 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
72 delete_cmd (name
, list
);
76 c
->function
.cfunc
= fun
;
79 c
->prefixname
= (char *)NULL
;
85 c
->type
= not_set_cmd
;
86 c
->completer
= make_symbol_completion_list
;
88 c
->var_type
= var_boolean
;
94 /* Same as above, except that the abbrev_flag is set. */
96 #if 0 /* Currently unused */
98 struct cmd_list_element
*
99 add_abbrev_cmd (name
, class, fun
, doc
, list
)
101 enum command_class
class;
102 void (*fun
) PARAMS ((char *, int));
104 struct cmd_list_element
**list
;
106 register struct cmd_list_element
*c
107 = add_cmd (name
, class, fun
, doc
, list
);
115 struct cmd_list_element
*
116 add_alias_cmd (name
, oldname
, class, abbrev_flag
, list
)
119 enum command_class
class;
121 struct cmd_list_element
**list
;
123 /* Must do this since lookup_cmd tries to side-effect its first arg */
125 register struct cmd_list_element
*old
;
126 register struct cmd_list_element
*c
;
127 copied_name
= (char *) alloca (strlen (oldname
) + 1);
128 strcpy (copied_name
, oldname
);
129 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
133 delete_cmd (name
, list
);
137 c
= add_cmd (name
, class, old
->function
.cfunc
, old
->doc
, list
);
138 c
->prefixlist
= old
->prefixlist
;
139 c
->prefixname
= old
->prefixname
;
140 c
->allow_unknown
= old
->allow_unknown
;
141 c
->abbrev_flag
= abbrev_flag
;
142 c
->cmd_pointer
= old
;
146 /* Like add_cmd but adds an element for a command prefix:
147 a name that should be followed by a subcommand to be looked up
148 in another command list. PREFIXLIST should be the address
149 of the variable containing that list. */
151 struct cmd_list_element
*
152 add_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
155 enum command_class
class;
156 void (*fun
) PARAMS ((char *, int));
158 struct cmd_list_element
**prefixlist
;
161 struct cmd_list_element
**list
;
163 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
164 c
->prefixlist
= prefixlist
;
165 c
->prefixname
= prefixname
;
166 c
->allow_unknown
= allow_unknown
;
170 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
172 struct cmd_list_element
*
173 add_abbrev_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
176 enum command_class
class;
177 void (*fun
) PARAMS ((char *, int));
179 struct cmd_list_element
**prefixlist
;
182 struct cmd_list_element
**list
;
184 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
185 c
->prefixlist
= prefixlist
;
186 c
->prefixname
= prefixname
;
187 c
->allow_unknown
= allow_unknown
;
194 not_just_help_class_command (args
, from_tty
)
200 /* Add element named NAME to command list LIST (the list for set
201 or some sublist thereof).
202 CLASS is as in add_cmd.
203 VAR_TYPE is the kind of thing we are setting.
204 VAR is address of the variable being controlled by this command.
205 DOC is the documentation string. */
207 struct cmd_list_element
*
208 add_set_cmd (name
, class, var_type
, var
, doc
, list
)
210 enum command_class
class;
214 struct cmd_list_element
**list
;
216 /* For set/show, we have to call do_setshow_command
217 differently than an ordinary function (take commandlist as
218 well as arg), so the function field isn't helpful. However,
219 function == NULL means that it's a help class, so set the function
220 to not_just_help_class_command. */
221 struct cmd_list_element
*c
222 = add_cmd (name
, class, not_just_help_class_command
, doc
, list
);
225 c
->var_type
= var_type
;
230 /* Where SETCMD has already been added, add the corresponding show
231 command to LIST and return a pointer to it. */
232 struct cmd_list_element
*
233 add_show_from_set (setcmd
, list
)
234 struct cmd_list_element
*setcmd
;
235 struct cmd_list_element
**list
;
237 struct cmd_list_element
*showcmd
=
238 (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
240 memcpy (showcmd
, setcmd
, sizeof (struct cmd_list_element
));
241 delete_cmd (showcmd
->name
, list
);
242 showcmd
->type
= show_cmd
;
244 /* Replace "set " at start of docstring with "show ". */
245 if (setcmd
->doc
[0] == 'S' && setcmd
->doc
[1] == 'e'
246 && setcmd
->doc
[2] == 't' && setcmd
->doc
[3] == ' ')
247 showcmd
->doc
= concat ("Show ", setcmd
->doc
+ 4, NULL
);
249 fprintf (stderr
, "GDB internal error: Bad docstring for set command\n");
251 showcmd
->next
= *list
;
256 /* Remove the command named NAME from the command list. */
259 delete_cmd (name
, list
)
261 struct cmd_list_element
**list
;
263 register struct cmd_list_element
*c
;
264 struct cmd_list_element
*p
;
266 while (*list
&& !strcmp ((*list
)->name
, name
))
269 (*list
)->hookee
->hook
= 0; /* Hook slips out of its mouth */
276 for (c
= *list
; c
->next
;)
278 if (!strcmp (c
->next
->name
, name
))
281 c
->next
->hookee
->hook
= 0; /* hooked cmd gets away. */
291 /* This command really has to deal with two things:
292 * 1) I want documentation on *this string* (usually called by
293 * "help commandname").
294 * 2) I want documentation on *this list* (usually called by
295 * giving a command that requires subcommands. Also called by saying
298 * I am going to split this into two seperate comamnds, help_cmd and
303 help_cmd (command
, stream
)
307 struct cmd_list_element
*c
;
308 extern struct cmd_list_element
*cmdlist
;
312 help_list (cmdlist
, "", all_classes
, stream
);
316 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
321 /* There are three cases here.
322 If c->prefixlist is nonzero, we have a prefix command.
323 Print its documentation, then list its subcommands.
325 If c->function is nonzero, we really have a command.
326 Print its documentation and return.
328 If c->function is zero, we have a class name.
329 Print its documentation (as if it were a command)
330 and then set class to the number of this class
331 so that the commands in the class will be listed. */
333 fputs_filtered (c
->doc
, stream
);
334 fputs_filtered ("\n", stream
);
336 if (c
->prefixlist
== 0 && c
->function
.cfunc
!= NULL
)
338 fprintf_filtered (stream
, "\n");
340 /* If this is a prefix command, print it's subcommands */
342 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
344 /* If this is a class name, print all of the commands in the class */
345 if (c
->function
.cfunc
== NULL
)
346 help_list (cmdlist
, "", c
->class, stream
);
349 fprintf_filtered (stream
, "\nThis command has a hook defined: %s\n",
354 * Get a specific kind of help on a command list.
357 * CMDTYPE is the prefix to use in the title string.
358 * CLASS is the class with which to list the nodes of this list (see
359 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
360 * everything, ALL_CLASSES for just classes, and non-negative for only things
361 * in a specific class.
362 * and STREAM is the output stream on which to print things.
363 * If you call this routine with a class >= 0, it recurses.
366 help_list (list
, cmdtype
, class, stream
)
367 struct cmd_list_element
*list
;
369 enum command_class
class;
373 char *cmdtype1
, *cmdtype2
;
375 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
376 len
= strlen (cmdtype
);
377 cmdtype1
= (char *) alloca (len
+ 1);
379 cmdtype2
= (char *) alloca (len
+ 4);
384 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
386 strncpy (cmdtype2
, cmdtype
, len
- 1);
387 strcpy (cmdtype2
+ len
- 1, " sub");
390 if (class == all_classes
)
391 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
393 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
395 help_cmd_list (list
, class, cmdtype
, (int)class >= 0, stream
);
397 if (class == all_classes
)
398 fprintf_filtered (stream
, "\n\
399 Type \"help%s\" followed by a class name for a list of commands in that class.",
402 fprintf_filtered (stream
, "\n\
403 Type \"help%s\" followed by %scommand name for full documentation.\n\
404 Command name abbreviations are allowed if unambiguous.\n",
408 /* Print only the first line of STR on STREAM. */
410 print_doc_line (stream
, str
)
414 static char *line_buffer
= 0;
415 static int line_size
;
421 line_buffer
= (char *) xmalloc (line_size
);
425 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
427 if (p
- str
> line_size
- 1)
429 line_size
= p
- str
+ 1;
430 free ((PTR
)line_buffer
);
431 line_buffer
= (char *) xmalloc (line_size
);
433 strncpy (line_buffer
, str
, p
- str
);
434 line_buffer
[p
- str
] = '\0';
435 if (islower (line_buffer
[0]))
436 line_buffer
[0] = toupper (line_buffer
[0]);
437 fputs_filtered (line_buffer
, stream
);
441 * Implement a help command on command list LIST.
442 * RECURSE should be non-zero if this should be done recursively on
443 * all sublists of LIST.
444 * PREFIX is the prefix to print before each command name.
445 * STREAM is the stream upon which the output should be written.
447 * A non-negative class number to list only commands in that
449 * ALL_COMMANDS to list all commands in list.
450 * ALL_CLASSES to list all classes in list.
452 * Note that RECURSE will be active on *all* sublists, not just the
453 * ones selected by the criteria above (ie. the selection mechanism
454 * is at the low level, not the high-level).
457 help_cmd_list (list
, class, prefix
, recurse
, stream
)
458 struct cmd_list_element
*list
;
459 enum command_class
class;
464 register struct cmd_list_element
*c
;
466 for (c
= list
; c
; c
= c
->next
)
468 if (c
->abbrev_flag
== 0 &&
469 (class == all_commands
470 || (class == all_classes
&& c
->function
.cfunc
== NULL
)
471 || (class == c
->class && c
->function
.cfunc
!= NULL
)))
473 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
474 print_doc_line (stream
, c
->doc
);
475 fputs_filtered ("\n", stream
);
478 && c
->prefixlist
!= 0
479 && c
->abbrev_flag
== 0)
480 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
484 /* This routine takes a line of TEXT and a CLIST in which to start the
485 lookup. When it returns it will have incremented the text pointer past
486 the section of text it matched, set *RESULT_LIST to point to the list in
487 which the last word was matched, and will return a pointer to the cmd
488 list element which the text matches. It will return NULL if no match at
489 all was possible. It will return -1 (cast appropriately, ick) if ambigous
490 matches are possible; in this case *RESULT_LIST will be set to point to
491 the list in which there are ambiguous choices (and *TEXT will be set to
492 the ambiguous text string).
494 If the located command was an abbreviation, this routine returns the base
495 command of the abbreviation.
497 It does no error reporting whatsoever; control will always return
498 to the superior routine.
500 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
501 at the prefix_command (ie. the best match) *or* (special case) will be NULL
502 if no prefix command was ever found. For example, in the case of "info a",
503 "info" matches without ambiguity, but "a" could be "args" or "address", so
504 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
505 RESULT_LIST should not be interpeted as a pointer to the beginning of a
506 list; it simply points to a specific command.
508 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
509 affect the operation).
511 This routine does *not* modify the text pointed to by TEXT.
513 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
514 are actually help classes rather than commands (i.e. the function field of
515 the struct cmd_list_element is NULL). */
517 struct cmd_list_element
*
518 lookup_cmd_1 (text
, clist
, result_list
, ignore_help_classes
)
520 struct cmd_list_element
*clist
, **result_list
;
521 int ignore_help_classes
;
524 int len
, tmp
, nfound
;
525 struct cmd_list_element
*found
, *c
;
527 while (**text
== ' ' || **text
== '\t')
530 /* Treating underscores as part of command words is important
531 so that "set args_foo()" doesn't get interpreted as
532 "set args _foo()". */
534 *p
&& (isalnum(*p
) || *p
== '-' || *p
== '_');
538 /* If nothing but whitespace, return 0. */
544 /* *text and p now bracket the first command word to lookup (and
545 it's length is len). We copy this into a local temporary,
546 converting to lower case as we go. */
548 command
= (char *) alloca (len
+ 1);
549 for (tmp
= 0; tmp
< len
; tmp
++)
551 char x
= (*text
)[tmp
];
552 command
[tmp
] = isupper(x
) ? tolower(x
) : x
;
559 for (c
= clist
; c
; c
= c
->next
)
560 if (!strncmp (command
, c
->name
, len
)
561 && (!ignore_help_classes
|| c
->function
.cfunc
))
565 if (c
->name
[len
] == '\0')
572 /* If nothing matches, we have a simple failure. */
578 if (result_list
!= NULL
)
579 /* Will be modified in calling routine
580 if we know what the prefix command is. */
582 return (struct cmd_list_element
*) -1; /* Ambiguous. */
585 /* We've matched something on this list. Move text pointer forward. */
589 /* If this was an abbreviation, use the base command instead. */
591 if (found
->cmd_pointer
)
592 found
= found
->cmd_pointer
;
594 /* If we found a prefix command, keep looking. */
596 if (found
->prefixlist
)
598 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
599 ignore_help_classes
);
602 /* Didn't find anything; this is as far as we got. */
603 if (result_list
!= NULL
)
604 *result_list
= clist
;
607 else if (c
== (struct cmd_list_element
*) -1)
609 /* We've gotten this far properley, but the next step
610 is ambiguous. We need to set the result list to the best
611 we've found (if an inferior hasn't already set it). */
612 if (result_list
!= NULL
)
614 /* This used to say *result_list = *found->prefixlist
615 If that was correct, need to modify the documentation
616 at the top of this function to clarify what is supposed
618 *result_list
= found
;
629 if (result_list
!= NULL
)
630 *result_list
= clist
;
635 /* All this hair to move the space to the front of cmdtype */
638 undef_cmd_error (cmdtype
, q
)
641 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
649 /* Look up the contents of *LINE as a command in the command list LIST.
650 LIST is a chain of struct cmd_list_element's.
651 If it is found, return the struct cmd_list_element for that command
652 and update *LINE to point after the command name, at the first argument.
653 If not found, call error if ALLOW_UNKNOWN is zero
654 otherwise (or if error returns) return zero.
655 Call error if specified command is ambiguous,
656 unless ALLOW_UNKNOWN is negative.
657 CMDTYPE precedes the word "command" in the error message.
659 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
660 elements which are actually help classes rather than commands (i.e.
661 the function field of the struct cmd_list_element is 0). */
663 struct cmd_list_element
*
664 lookup_cmd (line
, list
, cmdtype
, allow_unknown
, ignore_help_classes
)
666 struct cmd_list_element
*list
;
669 int ignore_help_classes
;
671 struct cmd_list_element
*last_list
= 0;
672 struct cmd_list_element
*c
=
673 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
674 char *ptr
= (*line
) + strlen (*line
) - 1;
676 /* Clear off trailing whitespace. */
677 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
686 error ("Lack of needed %scommand", cmdtype
);
691 while (isalnum(*p
) || *p
== '-')
694 q
= (char *) alloca (p
- *line
+ 1);
695 strncpy (q
, *line
, p
- *line
);
697 undef_cmd_error (cmdtype
, q
);
703 else if (c
== (struct cmd_list_element
*) -1)
705 /* Ambigous. Local values should be off prefixlist or called
707 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
709 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
710 struct cmd_list_element
*local_list
=
711 (last_list
? *(last_list
->prefixlist
) : list
);
713 if (local_allow_unknown
< 0)
716 return last_list
; /* Found something. */
718 return 0; /* Found nothing. */
722 /* Report as error. */
727 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
728 && (*line
)[amb_len
] != '\t');
733 for (c
= local_list
; c
; c
= c
->next
)
734 if (!strncmp (*line
, c
->name
, amb_len
))
736 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int)sizeof ambbuf
)
739 strcat (ambbuf
, ", ");
740 strcat (ambbuf
, c
->name
);
744 strcat (ambbuf
, "..");
748 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
755 /* We've got something. It may still not be what the caller
756 wants (if this command *needs* a subcommand). */
757 while (**line
== ' ' || **line
== '\t')
760 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
761 undef_cmd_error (c
->prefixname
, *line
);
763 /* Seems to be what he wants. Return it. */
770 /* Look up the contents of *LINE as a command in the command list LIST.
771 LIST is a chain of struct cmd_list_element's.
772 If it is found, return the struct cmd_list_element for that command
773 and update *LINE to point after the command name, at the first argument.
774 If not found, call error if ALLOW_UNKNOWN is zero
775 otherwise (or if error returns) return zero.
776 Call error if specified command is ambiguous,
777 unless ALLOW_UNKNOWN is negative.
778 CMDTYPE precedes the word "command" in the error message. */
780 struct cmd_list_element
*
781 lookup_cmd (line
, list
, cmdtype
, allow_unknown
)
783 struct cmd_list_element
*list
;
788 register struct cmd_list_element
*c
, *found
;
794 /* Skip leading whitespace. */
796 while (**line
== ' ' || **line
== '\t')
799 /* Clear out trailing whitespace. */
801 p
= *line
+ strlen (*line
);
802 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
806 /* Find end of command name. */
809 while (*p
== '-' || isalnum(*p
))
812 /* Look up the command name.
813 If exact match, keep that.
814 Otherwise, take command abbreviated, if unique. Note that (in my
815 opinion) a null string does *not* indicate ambiguity; simply the
816 end of the argument. */
821 error ("Lack of needed %scommand", cmdtype
);
825 /* Copy over to a local buffer, converting to lowercase on the way.
826 This is in case the command being parsed is a subcommand which
827 doesn't match anything, and that's ok. We want the original
828 untouched for the routine of the original command. */
830 processed_cmd
= (char *) alloca (p
- *line
+ 1);
831 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
833 char x
= (*line
)[cmd_len
];
835 processed_cmd
[cmd_len
] = tolower(x
);
837 processed_cmd
[cmd_len
] = x
;
839 processed_cmd
[cmd_len
] = '\0';
841 /* Check all possibilities in the current command list. */
844 for (c
= list
; c
; c
= c
->next
)
846 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
850 if (c
->name
[cmd_len
] == 0)
858 /* Report error for undefined command name. */
862 if (nfound
> 1 && allow_unknown
>= 0)
865 for (c
= list
; c
; c
= c
->next
)
866 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
868 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
871 strcat (ambbuf
, ", ");
872 strcat (ambbuf
, c
->name
);
876 strcat (ambbuf
, "..");
880 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
881 processed_cmd
, ambbuf
);
883 else if (!allow_unknown
)
884 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
888 /* Skip whitespace before the argument. */
890 while (*p
== ' ' || *p
== '\t') p
++;
893 if (found
->prefixlist
&& *p
)
895 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
896 found
->allow_unknown
);
905 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
907 /* Return a vector of char pointers which point to the different
908 possible completions in LIST of TEXT. */
911 complete_on_cmdlist (list
, text
)
912 struct cmd_list_element
*list
;
915 struct cmd_list_element
*ptr
;
917 int sizeof_matchlist
;
919 int textlen
= strlen (text
);
921 sizeof_matchlist
= 10;
922 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
925 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
926 if (!strncmp (ptr
->name
, text
, textlen
)
928 && (ptr
->function
.cfunc
931 if (matches
== sizeof_matchlist
)
933 sizeof_matchlist
*= 2;
934 matchlist
= (char **) xrealloc ((char *)matchlist
,
939 matchlist
[matches
] = (char *)
940 xmalloc (strlen (ptr
->name
) + 1);
941 strcpy (matchlist
[matches
++], ptr
->name
);
946 free ((PTR
)matchlist
);
951 matchlist
= (char **) xrealloc ((char *)matchlist
, ((matches
+ 1)
953 matchlist
[matches
] = (char *) 0;
960 parse_binary_operation (arg
)
968 length
= strlen (arg
);
970 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
973 if (!strncmp (arg
, "on", length
)
974 || !strncmp (arg
, "1", length
)
975 || !strncmp (arg
, "yes", length
))
978 if (!strncmp (arg
, "off", length
)
979 || !strncmp (arg
, "0", length
)
980 || !strncmp (arg
, "no", length
))
984 error ("\"on\" or \"off\" expected.");
989 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
990 of the argument, and FROM_TTY is nonzero if this command is being entered
991 directly by the user (i.e. these are just like any other
992 command). C is the command list element for the command. */
994 do_setshow_command (arg
, from_tty
, c
)
997 struct cmd_list_element
*c
;
999 if (c
->type
== set_cmd
)
1001 switch (c
->var_type
)
1012 new = (char *) xmalloc (strlen (arg
) + 2);
1014 while ((ch
= *p
++) != '\000')
1018 /* \ at end of argument is used after spaces
1019 so they won't be lost. */
1022 ch
= parse_escape (&p
);
1024 break; /* C loses */
1031 if (*(p
- 1) != '\\')
1034 new = (char *) xrealloc (new, q
- new);
1035 if (*(char **)c
->var
!= NULL
)
1036 free (*(char **)c
->var
);
1037 *(char **) c
->var
= new;
1040 case var_string_noescape
:
1043 if (*(char **)c
->var
!= NULL
)
1044 free (*(char **)c
->var
);
1045 *(char **) c
->var
= savestring (arg
, strlen (arg
));
1049 error_no_arg ("filename to set it to.");
1050 if (*(char **)c
->var
!= NULL
)
1051 free (*(char **)c
->var
);
1052 *(char **)c
->var
= tilde_expand (arg
);
1055 *(int *) c
->var
= parse_binary_operation (arg
);
1059 error_no_arg ("integer to set it to.");
1060 *(int *) c
->var
= parse_and_eval_address (arg
);
1061 if (*(int *) c
->var
== 0)
1062 *(int *) c
->var
= UINT_MAX
;
1066 error_no_arg ("integer to set it to.");
1067 *(int *) c
->var
= parse_and_eval_address (arg
);
1070 error ("gdb internal error: bad var_type in do_setshow_command");
1073 else if (c
->type
== show_cmd
)
1075 /* Print doc minus "show" at start. */
1076 print_doc_line (stdout
, c
->doc
+ 5);
1078 fputs_filtered (" is ", stdout
);
1080 switch (c
->var_type
)
1085 fputs_filtered ("\"", stdout
);
1086 for (p
= *(unsigned char **) c
->var
; *p
!= '\0'; p
++)
1087 printchar (*p
, stdout
, '"');
1088 fputs_filtered ("\"", stdout
);
1091 case var_string_noescape
:
1093 fputs_filtered ("\"", stdout
);
1094 fputs_filtered (*(char **) c
->var
, stdout
);
1095 fputs_filtered ("\"", stdout
);
1098 fputs_filtered (*(int *) c
->var
? "on" : "off", stdout
);
1101 if (*(unsigned int *) c
->var
== UINT_MAX
) {
1102 fputs_filtered ("unlimited", stdout
);
1105 /* else fall through */
1107 fprintf_filtered (stdout
, "%d", *(unsigned int *) c
->var
);
1110 error ("gdb internal error: bad var_type in do_setshow_command");
1112 fputs_filtered (".\n", stdout
);
1115 error ("gdb internal error: bad cmd_type in do_setshow_command");
1116 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
1119 /* Show all the settings in a list of show commands. */
1122 cmd_show_list (list
, from_tty
, prefix
)
1123 struct cmd_list_element
*list
;
1127 for (; list
!= NULL
; list
= list
->next
) {
1128 /* If we find a prefix, run its list, prefixing our output by its
1129 prefix (with "show " skipped). */
1130 if (list
->prefixlist
&& !list
->abbrev_flag
)
1131 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1132 if (list
->type
== show_cmd
)
1134 fputs_filtered (prefix
, stdout
);
1135 fputs_filtered (list
->name
, stdout
);
1136 fputs_filtered (": ", stdout
);
1137 do_setshow_command ((char *)NULL
, from_tty
, list
);
1144 shell_escape (arg
, from_tty
)
1148 int rc
, status
, pid
;
1149 char *p
, *user_shell
;
1151 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1152 user_shell
= "/bin/sh";
1154 /* Get the name of the shell for arg0 */
1155 if ((p
= strrchr (user_shell
, '/')) == NULL
)
1158 p
++; /* Get past '/' */
1160 if ((pid
= fork()) == 0)
1163 execl (user_shell
, p
, 0);
1165 execl (user_shell
, p
, "-c", arg
, 0);
1167 fprintf (stderr
, "Exec of shell failed\n");
1172 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1175 error ("Fork failed");
1179 make_command (arg
, from_tty
)
1189 p
= xmalloc (sizeof("make ") + strlen(arg
));
1190 strcpy (p
, "make ");
1191 strcpy (p
+ sizeof("make ")-1, arg
);
1194 shell_escape (p
, from_tty
);
1198 show_user_1 (c
, stream
)
1199 struct cmd_list_element
*c
;
1202 register struct command_line
*cmdlines
;
1204 cmdlines
= c
->user_commands
;
1207 fprintf_filtered (stream
, "User command %s:\n", c
->name
);
1210 fprintf_filtered (stream
, "%s\n", cmdlines
->line
);
1211 cmdlines
= cmdlines
->next
;
1213 fputs_filtered ("\n", stream
);
1218 show_user (args
, from_tty
)
1222 struct cmd_list_element
*c
;
1223 extern struct cmd_list_element
*cmdlist
;
1227 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
1228 if (c
->class != class_user
)
1229 error ("Not a user command.");
1230 show_user_1 (c
, stdout
);
1234 for (c
= cmdlist
; c
; c
= c
->next
)
1236 if (c
->class == class_user
)
1237 show_user_1 (c
, stdout
);
1243 _initialize_command ()
1245 add_com ("shell", class_support
, shell_escape
,
1246 "Execute the rest of the line as a shell command. \n\
1247 With no arguments, run an inferior shell.");
1249 add_com ("make", class_support
, make_command
,
1250 "Run the ``make'' program using the rest of the line as arguments.");
1252 add_cmd ("user", no_class
, show_user
,
1253 "Show definitions of user defined commands.\n\
1254 Argument is the name of the user defined command.\n\
1255 With no argument, show definitions of all user defined commands.", &showlist
);