1 /* Library for reading command lines and decoding commands.
2 Copyright (C) 1986, 1989, 1990 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 1, or (at your option)
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. */
26 extern char *getenv ();
28 /* Add element named NAME to command list *LIST.
29 FUN should be the function to execute the command;
30 it will get a character string as argument, with leading
31 and trailing blanks already eliminated.
33 DOC is a documentation string for the command.
34 Its first line should be a complete sentence.
35 It should start with ? for a command that is an abbreviation
36 or with * for a command that most users don't need to know about. */
38 struct cmd_list_element
*
39 add_cmd (name
, class, fun
, doc
, list
)
41 enum command_class
class;
44 struct cmd_list_element
**list
;
46 register struct cmd_list_element
*c
47 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
49 delete_cmd (name
, list
);
56 c
->prefixname
= (char *)NULL
;
60 c
->type
= not_set_cmd
;
61 c
->completer
= make_symbol_completion_list
;
63 c
->var_type
= var_boolean
;
69 /* Same as above, except that the abbrev_flag is set. */
71 struct cmd_list_element
*
72 add_abbrev_cmd (name
, class, fun
, doc
, list
)
74 enum command_class
class;
77 struct cmd_list_element
**list
;
79 register struct cmd_list_element
*c
80 = add_cmd (name
, class, fun
, doc
, list
);
86 struct cmd_list_element
*
87 add_alias_cmd (name
, oldname
, class, abbrev_flag
, list
)
90 enum command_class
class;
92 struct cmd_list_element
**list
;
94 /* Must do this since lookup_cmd tries to side-effect its first arg */
96 register struct cmd_list_element
*old
;
97 register struct cmd_list_element
*c
;
98 copied_name
= (char *) alloca (strlen (oldname
) + 1);
99 strcpy (copied_name
, oldname
);
100 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
104 delete_cmd (name
, list
);
108 c
= add_cmd (name
, class, old
->function
, old
->doc
, list
);
109 c
->prefixlist
= old
->prefixlist
;
110 c
->prefixname
= old
->prefixname
;
111 c
->allow_unknown
= old
->allow_unknown
;
112 c
->abbrev_flag
= abbrev_flag
;
117 /* Like add_cmd but adds an element for a command prefix:
118 a name that should be followed by a subcommand to be looked up
119 in another command list. PREFIXLIST should be the address
120 of the variable containing that list. */
122 struct cmd_list_element
*
123 add_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
126 enum command_class
class;
129 struct cmd_list_element
**prefixlist
;
132 struct cmd_list_element
**list
;
134 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
135 c
->prefixlist
= prefixlist
;
136 c
->prefixname
= prefixname
;
137 c
->allow_unknown
= allow_unknown
;
141 /* Like add_prefix_cmd butsets the abbrev_flag on the new command. */
143 struct cmd_list_element
*
144 add_abbrev_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
147 enum command_class
class;
150 struct cmd_list_element
**prefixlist
;
153 struct cmd_list_element
**list
;
155 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
156 c
->prefixlist
= prefixlist
;
157 c
->prefixname
= prefixname
;
158 c
->allow_unknown
= allow_unknown
;
164 not_just_help_class_command (args
, from_tty
, c
)
167 struct cmd_list_element
*c
;
171 /* Add element named NAME to command list LIST (the list for set
172 or some sublist thereof).
173 CLASS is as in add_cmd.
174 VAR_TYPE is the kind of thing we are setting.
175 VAR is address of the variable being controlled by this command.
176 DOC is the documentation string. */
177 struct cmd_list_element
*
178 add_set_cmd (name
, class, var_type
, var
, doc
, list
)
180 enum command_class
class;
184 struct cmd_list_element
**list
;
186 /* For set/show, we have to call do_setshow_command
187 differently than an ordinary function (take commandlist as
188 well as arg), so the function field isn't helpful. However,
189 function == NULL means that it's a help class, so set the function
190 to not_just_help_class_command. */
191 struct cmd_list_element
*c
192 = add_cmd (name
, class, not_just_help_class_command
, doc
, list
);
195 c
->var_type
= var_type
;
200 /* Where SETCMD has already been added, add the corresponding show
201 command to LIST and return a pointer to it. */
202 struct cmd_list_element
*
203 add_show_from_set (setcmd
, list
)
204 struct cmd_list_element
*setcmd
;
205 struct cmd_list_element
**list
;
207 struct cmd_list_element
*showcmd
=
208 (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
210 bcopy (setcmd
, showcmd
, sizeof (struct cmd_list_element
));
211 delete_cmd (showcmd
->name
, list
);
212 showcmd
->type
= show_cmd
;
214 /* Replace "set " at start of docstring with "show ". */
215 if (setcmd
->doc
[0] == 'S' && setcmd
->doc
[1] == 'e'
216 && setcmd
->doc
[2] == 't' && setcmd
->doc
[3] == ' ')
217 showcmd
->doc
= concat ("Show ", setcmd
->doc
+ 4, "");
219 fprintf (stderr
, "GDB internal error: Bad docstring for set command\n");
221 showcmd
->next
= *list
;
226 /* Remove the command named NAME from the command list. */
229 delete_cmd (name
, list
)
231 struct cmd_list_element
**list
;
233 register struct cmd_list_element
*c
;
234 struct cmd_list_element
*p
;
236 while (*list
&& !strcmp ((*list
)->name
, name
))
244 for (c
= *list
; c
->next
;)
246 if (!strcmp (c
->next
->name
, name
))
257 void help_cmd (), help_list (), help_cmd_list ();
259 /* This command really has to deal with two things:
260 * 1) I want documentation on *this string* (usually called by
261 * "help commandname").
262 * 2) I want documentation on *this list* (usually called by
263 * giving a command that requires subcommands. Also called by saying
266 * I am going to split this into two seperate comamnds, help_cmd and
271 help_cmd (command
, stream
)
275 struct cmd_list_element
*c
;
276 extern struct cmd_list_element
*cmdlist
;
280 help_list (cmdlist
, "", all_classes
, stream
);
284 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
289 /* There are three cases here.
290 If c->prefixlist is nonzero, we have a prefix command.
291 Print its documentation, then list its subcommands.
293 If c->function is nonzero, we really have a command.
294 Print its documentation and return.
296 If c->function is zero, we have a class name.
297 Print its documentation (as if it were a command)
298 and then set class to the number of this class
299 so that the commands in the class will be listed. */
301 fputs_filtered (c
->doc
, stream
);
302 fputs_filtered ("\n", stream
);
304 if (c
->prefixlist
== 0 && c
->function
!= 0)
306 fprintf_filtered (stream
, "\n");
308 /* If this is a prefix command, print it's subcommands */
310 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
312 /* If this is a class name, print all of the commands in the class */
313 if (c
->function
== 0)
314 help_list (cmdlist
, "", c
->class, stream
);
318 * Get a specific kind of help on a command list.
321 * CMDTYPE is the prefix to use in the title string.
322 * CLASS is the class with which to list the nodes of this list (see
323 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
324 * everything, ALL_CLASSES for just classes, and non-negative for only things
325 * in a specific class.
326 * and STREAM is the output stream on which to print things.
327 * If you call this routine with a class >= 0, it recurses.
330 help_list (list
, cmdtype
, class, stream
)
331 struct cmd_list_element
*list
;
333 enum command_class
class;
337 char *cmdtype1
, *cmdtype2
;
339 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
340 len
= strlen (cmdtype
);
341 cmdtype1
= (char *) alloca (len
+ 1);
343 cmdtype2
= (char *) alloca (len
+ 4);
348 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
350 strncpy (cmdtype2
, cmdtype
, len
- 1);
351 strcpy (cmdtype2
+ len
- 1, " sub");
354 if (class == all_classes
)
355 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
357 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
359 help_cmd_list (list
, class, cmdtype
, (int)class >= 0, stream
);
361 if (class == all_classes
)
362 fprintf_filtered (stream
, "\n\
363 Type \"help%s\" followed by a class name for a list of commands in that class.",
366 fprintf_filtered (stream
, "\n\
367 Type \"help%s\" followed by %scommand name for full documentation.\n\
368 Command name abbreviations are allowed if unambiguous.\n",
372 /* Print only the first line of STR on STREAM. */
374 print_doc_line (stream
, str
)
378 static char *line_buffer
= 0;
379 static int line_size
;
385 line_buffer
= (char *) xmalloc (line_size
);
389 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
391 if (p
- str
> line_size
- 1)
393 line_size
= p
- str
+ 1;
395 line_buffer
= (char *) xmalloc (line_size
);
397 strncpy (line_buffer
, str
, p
- str
);
398 line_buffer
[p
- str
] = '\0';
399 if (islower (line_buffer
[0]))
400 line_buffer
[0] = toupper (line_buffer
[0]);
401 fputs_filtered (line_buffer
, stream
);
405 * Implement a help command on command list LIST.
406 * RECURSE should be non-zero if this should be done recursively on
407 * all sublists of LIST.
408 * PREFIX is the prefix to print before each command name.
409 * STREAM is the stream upon which the output should be written.
411 * A non-negative class number to list only commands in that
413 * ALL_COMMANDS to list all commands in list.
414 * ALL_CLASSES to list all classes in list.
416 * Note that RECURSE will be active on *all* sublists, not just the
417 * ones seclected by the criteria above (ie. the selection mechanism
418 * is at the low level, not the high-level).
421 help_cmd_list (list
, class, prefix
, recurse
, stream
)
422 struct cmd_list_element
*list
;
423 enum command_class
class;
428 register struct cmd_list_element
*c
;
430 for (c
= list
; c
; c
= c
->next
)
432 if (c
->abbrev_flag
== 0 &&
433 (class == all_commands
434 || (class == all_classes
&& c
->function
== 0)
435 || (class == c
->class && c
->function
!= 0)))
437 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
438 print_doc_line (stream
, c
->doc
);
439 fputs_filtered ("\n", stream
);
442 && c
->prefixlist
!= 0
443 && c
->abbrev_flag
== 0)
444 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
448 /* This routine takes a line of TEXT and a CLIST in which to
449 start the lookup. When it returns it will have incremented the text
450 pointer past the section of text it matched, set *RESULT_LIST to
451 the list in which the last word was matched, and will return the
452 cmd list element which the text matches. It will return 0 if no
453 match at all was possible. It will return -1 if ambigous matches are
454 possible; in this case *RESULT_LIST will be set to the list in which
455 there are ambiguous choices (and text will be set to the ambiguous
458 It does no error reporting whatsoever; control will always return
459 to the superior routine.
461 In the case of an ambiguous return (-1), *RESULT_LIST will be set to
462 point at the prefix_command (ie. the best match) *or* (special
463 case) will be 0 if no prefix command was ever found. For example,
464 in the case of "info a", "info" matches without ambiguity, but "a"
465 could be "args" or "address", so *RESULT_LIST is set to
466 the cmd_list_element for "info". So in this case
467 result list should not be interpeted as a pointer to the beginning
468 of a list; it simply points to a specific command.
470 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
471 affect the operation).
473 This routine does *not* modify the text pointed to by TEXT.
475 If IGNORE_HELP_CLASSES is nonzero, ignore any command list
476 elements which are actually help classes rather than commands (i.e.
477 the function field of the struct cmd_list_element is 0). */
479 struct cmd_list_element
*
480 lookup_cmd_1 (text
, clist
, result_list
, ignore_help_classes
)
482 struct cmd_list_element
*clist
, **result_list
;
483 int ignore_help_classes
;
486 int len
, tmp
, nfound
;
487 struct cmd_list_element
*found
, *c
;
489 while (**text
== ' ' || **text
== '\t')
492 /* Treating underscores as part of command words is important
493 so that "set args_foo()" doesn't get interpreted as
494 "set args _foo()". */
496 *p
&& (isalnum(*p
) || *p
== '-' || *p
== '_');
500 /* If nothing but whitespace, return 0. */
506 /* *text and p now bracket the first command word to lookup (and
507 it's length is len). We copy this into a local temporary,
508 converting to lower case as we go. */
510 command
= (char *) alloca (len
+ 1);
511 for (tmp
= 0; tmp
< len
; tmp
++)
513 char x
= (*text
)[tmp
];
514 command
[tmp
] = (x
>= 'A' && x
<= 'Z') ? x
- 'A' + 'a' : x
;
521 for (c
= clist
; c
; c
= c
->next
)
522 if (!strncmp (command
, c
->name
, len
)
523 && (!ignore_help_classes
|| c
->function
))
527 if (c
->name
[len
] == '\0')
534 /* If nothing matches, we have a simple failure. */
540 if (result_list
!= NULL
)
541 /* Will be modified in calling routine
542 if we know what the prefix command is. */
544 return (struct cmd_list_element
*) -1; /* Ambiguous. */
547 /* We've matched something on this list. Move text pointer forward. */
550 if (found
->prefixlist
)
552 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
553 ignore_help_classes
);
556 /* Didn't find anything; this is as far as we got. */
557 if (result_list
!= NULL
)
558 *result_list
= clist
;
561 else if (c
== (struct cmd_list_element
*) -1)
563 /* We've gotten this far properley, but the next step
564 is ambiguous. We need to set the result list to the best
565 we've found (if an inferior hasn't already set it). */
566 if (result_list
!= NULL
)
568 /* This used to say *result_list = *found->prefixlist
569 If that was correct, need to modify the documentation
570 at the top of this function to clarify what is supposed
572 *result_list
= found
;
583 if (result_list
!= NULL
)
584 *result_list
= clist
;
589 /* Look up the contents of *LINE as a command in the command list LIST.
590 LIST is a chain of struct cmd_list_element's.
591 If it is found, return the struct cmd_list_element for that command
592 and update *LINE to point after the command name, at the first argument.
593 If not found, call error if ALLOW_UNKNOWN is zero
594 otherwise (or if error returns) return zero.
595 Call error if specified command is ambiguous,
596 unless ALLOW_UNKNOWN is negative.
597 CMDTYPE precedes the word "command" in the error message.
599 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
600 elements which are actually help classes rather than commands (i.e.
601 the function field of the struct cmd_list_element is 0). */
603 struct cmd_list_element
*
604 lookup_cmd (line
, list
, cmdtype
, allow_unknown
, ignore_help_classes
)
606 struct cmd_list_element
*list
;
609 int ignore_help_classes
;
611 struct cmd_list_element
*last_list
= 0;
612 struct cmd_list_element
*c
=
613 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
614 char *ptr
= (*line
) + strlen (*line
) - 1;
616 /* Clear off trailing whitespace. */
617 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
626 error ("Lack of needed %scommand", cmdtype
);
631 while (isalnum(*p
) || *p
== '-')
634 q
= (char *) alloca (p
- *line
+ 1);
635 strncpy (q
, *line
, p
- *line
);
638 error ("Undefined %scommand: \"%s\".", cmdtype
, q
);
644 else if (c
== (struct cmd_list_element
*) -1)
646 /* Ambigous. Local values should be off prefixlist or called
648 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
650 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
651 struct cmd_list_element
*local_list
=
652 (last_list
? *(last_list
->prefixlist
) : list
);
654 if (local_allow_unknown
< 0)
657 return last_list
; /* Found something. */
659 return 0; /* Found nothing. */
663 /* Report as error. */
668 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
669 && (*line
)[amb_len
] != '\t');
674 for (c
= local_list
; c
; c
= c
->next
)
675 if (!strncmp (*line
, c
->name
, amb_len
))
677 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int)sizeof ambbuf
)
680 strcat (ambbuf
, ", ");
681 strcat (ambbuf
, c
->name
);
685 strcat (ambbuf
, "..");
689 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
696 /* We've got something. It may still not be what the caller
697 wants (if this command *needs* a subcommand). */
698 while (**line
== ' ' || **line
== '\t')
701 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
702 error ("Undefined %scommand: \"%s\".", c
->prefixname
, *line
);
704 /* Seems to be what he wants. Return it. */
711 /* Look up the contents of *LINE as a command in the command list LIST.
712 LIST is a chain of struct cmd_list_element's.
713 If it is found, return the struct cmd_list_element for that command
714 and update *LINE to point after the command name, at the first argument.
715 If not found, call error if ALLOW_UNKNOWN is zero
716 otherwise (or if error returns) return zero.
717 Call error if specified command is ambiguous,
718 unless ALLOW_UNKNOWN is negative.
719 CMDTYPE precedes the word "command" in the error message. */
721 struct cmd_list_element
*
722 lookup_cmd (line
, list
, cmdtype
, allow_unknown
)
724 struct cmd_list_element
*list
;
729 register struct cmd_list_element
*c
, *found
;
735 /* Skip leading whitespace. */
737 while (**line
== ' ' || **line
== '\t')
740 /* Clear out trailing whitespace. */
742 p
= *line
+ strlen (*line
);
743 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
747 /* Find end of command name. */
751 || (*p
>= 'a' && *p
<= 'z')
752 || (*p
>= 'A' && *p
<= 'Z')
753 || (*p
>= '0' && *p
<= '9'))
756 /* Look up the command name.
757 If exact match, keep that.
758 Otherwise, take command abbreviated, if unique. Note that (in my
759 opinion) a null string does *not* indicate ambiguity; simply the
760 end of the argument. */
765 error ("Lack of needed %scommand", cmdtype
);
769 /* Copy over to a local buffer, converting to lowercase on the way.
770 This is in case the command being parsed is a subcommand which
771 doesn't match anything, and that's ok. We want the original
772 untouched for the routine of the original command. */
774 processed_cmd
= (char *) alloca (p
- *line
+ 1);
775 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
777 char x
= (*line
)[cmd_len
];
778 if (x
>= 'A' && x
<= 'Z')
779 processed_cmd
[cmd_len
] = x
- 'A' + 'a';
781 processed_cmd
[cmd_len
] = x
;
783 processed_cmd
[cmd_len
] = '\0';
785 /* Check all possibilities in the current command list. */
788 for (c
= list
; c
; c
= c
->next
)
790 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
794 if (c
->name
[cmd_len
] == 0)
802 /* Report error for undefined command name. */
806 if (nfound
> 1 && allow_unknown
>= 0)
809 for (c
= list
; c
; c
= c
->next
)
810 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
812 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
815 strcat (ambbuf
, ", ");
816 strcat (ambbuf
, c
->name
);
820 strcat (ambbuf
, "..");
824 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
825 processed_cmd
, ambbuf
);
827 else if (!allow_unknown
)
828 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
832 /* Skip whitespace before the argument. */
834 while (*p
== ' ' || *p
== '\t') p
++;
837 if (found
->prefixlist
&& *p
)
839 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
840 found
->allow_unknown
);
849 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
851 /* Return a vector of char pointers which point to the different
852 possible completions in LIST of TEXT. */
855 complete_on_cmdlist (list
, text
)
856 struct cmd_list_element
*list
;
859 struct cmd_list_element
*ptr
;
861 int sizeof_matchlist
;
863 int textlen
= strlen (text
);
865 sizeof_matchlist
= 10;
866 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
869 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
870 if (!strncmp (ptr
->name
, text
, textlen
)
875 if (matches
== sizeof_matchlist
)
877 sizeof_matchlist
*= 2;
878 matchlist
= (char **) xrealloc ((char *)matchlist
,
883 matchlist
[matches
] = (char *)
884 xmalloc (strlen (ptr
->name
) + 1);
885 strcpy (matchlist
[matches
++], ptr
->name
);
895 matchlist
= (char **) xrealloc ((char *)matchlist
, ((matches
+ 1)
897 matchlist
[matches
] = (char *) 0;
904 parse_binary_operation (arg
)
912 length
= strlen (arg
);
914 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
917 if (!strncmp (arg
, "on", length
)
918 || !strncmp (arg
, "1", length
)
919 || !strncmp (arg
, "yes", length
))
922 if (!strncmp (arg
, "off", length
)
923 || !strncmp (arg
, "0", length
)
924 || !strncmp (arg
, "no", length
))
928 error ("\"on\" or \"off\" expected.");
933 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
934 of the argument, and FROM_TTY is nonzero if this command is being entered
935 directly by the user (i.e. these are just like any other
936 command). C is the command list element for the command. */
938 do_setshow_command (arg
, from_tty
, c
)
941 struct cmd_list_element
*c
;
943 if (c
->type
== set_cmd
)
956 new = (char *) xmalloc (strlen (arg
) + 2);
962 /* \ at end of argument is used after spaces
963 so they won't be lost. */
966 ch
= parse_escape (&p
);
975 if (*(p
- 1) != '\\')
978 new = (char *) xrealloc (new, q
- new);
979 if (*(char **)c
->var
!= NULL
)
980 free (*(char **)c
->var
);
981 *(char **) c
->var
= new;
984 case var_string_noescape
:
987 if (*(char **)c
->var
!= NULL
)
988 free (*(char **)c
->var
);
989 *(char **) c
->var
= savestring (arg
, strlen (arg
));
993 error_no_arg ("filename to set it to.");
994 if (*(char **)c
->var
!= NULL
)
995 free (*(char **)c
->var
);
996 *(char **)c
->var
= tilde_expand (arg
);
999 *(int *) c
->var
= parse_binary_operation (arg
);
1003 error_no_arg ("integer to set it to.");
1004 *(int *) c
->var
= parse_and_eval_address (arg
);
1005 if (*(int *) c
->var
== 0)
1006 *(int *) c
->var
= UINT_MAX
;
1010 error_no_arg ("integer to set it to.");
1011 *(int *) c
->var
= parse_and_eval_address (arg
);
1014 error ("gdb internal error: bad var_type in do_setshow_command");
1017 else if (c
->type
== show_cmd
)
1019 /* Print doc minus "show" at start. */
1020 print_doc_line (stdout
, c
->doc
+ 5);
1022 fputs_filtered (" is ", stdout
);
1024 switch (c
->var_type
)
1029 fputs_filtered ("\"", stdout
);
1030 for (p
= *(unsigned char **) c
->var
; *p
!= '\0'; p
++)
1031 printchar (*p
, stdout
, '"');
1032 fputs_filtered ("\"", stdout
);
1035 case var_string_noescape
:
1037 fputs_filtered ("\"", stdout
);
1038 fputs_filtered (*(char **) c
->var
, stdout
);
1039 fputs_filtered ("\"", stdout
);
1042 fputs_filtered (*(int *) c
->var
? "on" : "off", stdout
);
1045 if (*(unsigned int *) c
->var
== UINT_MAX
) {
1046 fputs_filtered ("unlimited", stdout
);
1049 /* else fall through */
1051 fprintf_filtered (stdout
, "%d", *(unsigned int *) c
->var
);
1054 error ("gdb internal error: bad var_type in do_setshow_command");
1056 fputs_filtered (".\n", stdout
);
1059 error ("gdb internal error: bad cmd_type in do_setshow_command");
1060 (*c
->function
) (NULL
, from_tty
, c
);
1063 /* Show all the settings in a list of show commands. */
1066 cmd_show_list (list
, from_tty
, prefix
)
1067 struct cmd_list_element
*list
;
1071 for (; list
!= NULL
; list
= list
->next
) {
1072 /* If we find a prefix, run its list, prefixing our output by its
1073 prefix (with "show " skipped). */
1074 if (list
->prefixlist
&& !list
->abbrev_flag
)
1075 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1076 if (list
->type
== show_cmd
)
1078 fputs_filtered (prefix
, stdout
);
1079 fputs_filtered (list
->name
, stdout
);
1080 fputs_filtered (": ", stdout
);
1081 do_setshow_command ((char *)NULL
, from_tty
, list
);
1087 shell_escape (arg
, from_tty
)
1091 int rc
, status
, pid
;
1092 char *p
, *user_shell
;
1093 extern char *rindex ();
1095 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1096 user_shell
= "/bin/sh";
1098 /* Get the name of the shell for arg0 */
1099 if ((p
= rindex (user_shell
, '/')) == NULL
)
1102 p
++; /* Get past '/' */
1104 if ((pid
= fork()) == 0)
1107 execl (user_shell
, p
, 0);
1109 execl (user_shell
, p
, "-c", arg
, 0);
1111 fprintf (stderr
, "Exec of shell failed\n");
1116 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1119 error ("Fork failed");
1123 make_command (arg
, from_tty
)
1133 p
= xmalloc (sizeof("make ") + strlen(arg
));
1134 strcpy (p
, "make ");
1135 strcpy (p
+ sizeof("make ")-1, arg
);
1138 shell_escape (p
, from_tty
);
1142 user_info_1 (c
, stream
)
1143 struct cmd_list_element
*c
;
1146 register struct command_line
*cmdlines
;
1148 cmdlines
= c
->user_commands
;
1151 fprintf_filtered (stream
, "User command %s:\n", c
->name
);
1154 fprintf_filtered (stream
, "%s\n", cmdlines
->line
);
1155 cmdlines
= cmdlines
->next
;
1157 fputs_filtered ("\n", stream
);
1162 user_info (args
, from_tty
)
1166 struct cmd_list_element
*c
;
1167 extern struct cmd_list_element
*cmdlist
;
1171 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
1172 if (c
->class != class_user
)
1173 error ("Not a user command.");
1174 user_info_1 (c
, stdout
);
1178 for (c
= cmdlist
; c
; c
= c
->next
)
1180 if (c
->class == class_user
)
1181 user_info_1 (c
, stdout
);
1187 _initialize_command ()
1189 add_com ("shell", class_support
, shell_escape
,
1190 "Execute the rest of the line as a shell command. \n\
1191 With no arguments, run an inferior shell.");
1193 add_com ("make", class_support
, make_command
,
1194 "Run the ``make'' program using the rest of the line as arguments.");
1196 add_info ("user", user_info
, "Show definitions of user defined commands.\n\
1197 Argument is the name of the user defined command.\n\
1198 With no argument, show definitions of all user defined commands.");