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
;
83 c
->type
= not_set_cmd
;
84 c
->completer
= make_symbol_completion_list
;
86 c
->var_type
= var_boolean
;
92 /* Same as above, except that the abbrev_flag is set. */
94 #if 0 /* Currently unused */
96 struct cmd_list_element
*
97 add_abbrev_cmd (name
, class, fun
, doc
, list
)
99 enum command_class
class;
100 void (*fun
) PARAMS ((char *, int));
102 struct cmd_list_element
**list
;
104 register struct cmd_list_element
*c
105 = add_cmd (name
, class, fun
, doc
, list
);
113 struct cmd_list_element
*
114 add_alias_cmd (name
, oldname
, class, abbrev_flag
, list
)
117 enum command_class
class;
119 struct cmd_list_element
**list
;
121 /* Must do this since lookup_cmd tries to side-effect its first arg */
123 register struct cmd_list_element
*old
;
124 register struct cmd_list_element
*c
;
125 copied_name
= (char *) alloca (strlen (oldname
) + 1);
126 strcpy (copied_name
, oldname
);
127 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
131 delete_cmd (name
, list
);
135 c
= add_cmd (name
, class, old
->function
.cfunc
, old
->doc
, list
);
136 c
->prefixlist
= old
->prefixlist
;
137 c
->prefixname
= old
->prefixname
;
138 c
->allow_unknown
= old
->allow_unknown
;
139 c
->abbrev_flag
= abbrev_flag
;
144 /* Like add_cmd but adds an element for a command prefix:
145 a name that should be followed by a subcommand to be looked up
146 in another command list. PREFIXLIST should be the address
147 of the variable containing that list. */
149 struct cmd_list_element
*
150 add_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
153 enum command_class
class;
154 void (*fun
) PARAMS ((char *, int));
156 struct cmd_list_element
**prefixlist
;
159 struct cmd_list_element
**list
;
161 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
162 c
->prefixlist
= prefixlist
;
163 c
->prefixname
= prefixname
;
164 c
->allow_unknown
= allow_unknown
;
168 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
170 struct cmd_list_element
*
171 add_abbrev_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
174 enum command_class
class;
175 void (*fun
) PARAMS ((char *, int));
177 struct cmd_list_element
**prefixlist
;
180 struct cmd_list_element
**list
;
182 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
183 c
->prefixlist
= prefixlist
;
184 c
->prefixname
= prefixname
;
185 c
->allow_unknown
= allow_unknown
;
192 not_just_help_class_command (args
, from_tty
)
198 /* Add element named NAME to command list LIST (the list for set
199 or some sublist thereof).
200 CLASS is as in add_cmd.
201 VAR_TYPE is the kind of thing we are setting.
202 VAR is address of the variable being controlled by this command.
203 DOC is the documentation string. */
205 struct cmd_list_element
*
206 add_set_cmd (name
, class, var_type
, var
, doc
, list
)
208 enum command_class
class;
212 struct cmd_list_element
**list
;
214 /* For set/show, we have to call do_setshow_command
215 differently than an ordinary function (take commandlist as
216 well as arg), so the function field isn't helpful. However,
217 function == NULL means that it's a help class, so set the function
218 to not_just_help_class_command. */
219 struct cmd_list_element
*c
220 = add_cmd (name
, class, not_just_help_class_command
, doc
, list
);
223 c
->var_type
= var_type
;
228 /* Where SETCMD has already been added, add the corresponding show
229 command to LIST and return a pointer to it. */
230 struct cmd_list_element
*
231 add_show_from_set (setcmd
, list
)
232 struct cmd_list_element
*setcmd
;
233 struct cmd_list_element
**list
;
235 struct cmd_list_element
*showcmd
=
236 (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
238 (void) memcpy (showcmd
, setcmd
, sizeof (struct cmd_list_element
));
239 delete_cmd (showcmd
->name
, list
);
240 showcmd
->type
= show_cmd
;
242 /* Replace "set " at start of docstring with "show ". */
243 if (setcmd
->doc
[0] == 'S' && setcmd
->doc
[1] == 'e'
244 && setcmd
->doc
[2] == 't' && setcmd
->doc
[3] == ' ')
245 showcmd
->doc
= concat ("Show ", setcmd
->doc
+ 4, NULL
);
247 fprintf (stderr
, "GDB internal error: Bad docstring for set command\n");
249 showcmd
->next
= *list
;
254 /* Remove the command named NAME from the command list. */
257 delete_cmd (name
, list
)
259 struct cmd_list_element
**list
;
261 register struct cmd_list_element
*c
;
262 struct cmd_list_element
*p
;
264 while (*list
&& !strcmp ((*list
)->name
, name
))
272 for (c
= *list
; c
->next
;)
274 if (!strcmp (c
->next
->name
, name
))
285 /* This command really has to deal with two things:
286 * 1) I want documentation on *this string* (usually called by
287 * "help commandname").
288 * 2) I want documentation on *this list* (usually called by
289 * giving a command that requires subcommands. Also called by saying
292 * I am going to split this into two seperate comamnds, help_cmd and
297 help_cmd (command
, stream
)
301 struct cmd_list_element
*c
;
302 extern struct cmd_list_element
*cmdlist
;
306 help_list (cmdlist
, "", all_classes
, stream
);
310 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
315 /* There are three cases here.
316 If c->prefixlist is nonzero, we have a prefix command.
317 Print its documentation, then list its subcommands.
319 If c->function is nonzero, we really have a command.
320 Print its documentation and return.
322 If c->function is zero, we have a class name.
323 Print its documentation (as if it were a command)
324 and then set class to the number of this class
325 so that the commands in the class will be listed. */
327 fputs_filtered (c
->doc
, stream
);
328 fputs_filtered ("\n", stream
);
330 if (c
->prefixlist
== 0 && c
->function
.cfunc
!= NULL
)
332 fprintf_filtered (stream
, "\n");
334 /* If this is a prefix command, print it's subcommands */
336 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
338 /* If this is a class name, print all of the commands in the class */
339 if (c
->function
.cfunc
== NULL
)
340 help_list (cmdlist
, "", c
->class, stream
);
344 * Get a specific kind of help on a command list.
347 * CMDTYPE is the prefix to use in the title string.
348 * CLASS is the class with which to list the nodes of this list (see
349 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
350 * everything, ALL_CLASSES for just classes, and non-negative for only things
351 * in a specific class.
352 * and STREAM is the output stream on which to print things.
353 * If you call this routine with a class >= 0, it recurses.
356 help_list (list
, cmdtype
, class, stream
)
357 struct cmd_list_element
*list
;
359 enum command_class
class;
363 char *cmdtype1
, *cmdtype2
;
365 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
366 len
= strlen (cmdtype
);
367 cmdtype1
= (char *) alloca (len
+ 1);
369 cmdtype2
= (char *) alloca (len
+ 4);
374 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
376 strncpy (cmdtype2
, cmdtype
, len
- 1);
377 strcpy (cmdtype2
+ len
- 1, " sub");
380 if (class == all_classes
)
381 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
383 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
385 help_cmd_list (list
, class, cmdtype
, (int)class >= 0, stream
);
387 if (class == all_classes
)
388 fprintf_filtered (stream
, "\n\
389 Type \"help%s\" followed by a class name for a list of commands in that class.",
392 fprintf_filtered (stream
, "\n\
393 Type \"help%s\" followed by %scommand name for full documentation.\n\
394 Command name abbreviations are allowed if unambiguous.\n",
398 /* Print only the first line of STR on STREAM. */
400 print_doc_line (stream
, str
)
404 static char *line_buffer
= 0;
405 static int line_size
;
411 line_buffer
= (char *) xmalloc (line_size
);
415 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
417 if (p
- str
> line_size
- 1)
419 line_size
= p
- str
+ 1;
420 free ((PTR
)line_buffer
);
421 line_buffer
= (char *) xmalloc (line_size
);
423 strncpy (line_buffer
, str
, p
- str
);
424 line_buffer
[p
- str
] = '\0';
425 if (islower (line_buffer
[0]))
426 line_buffer
[0] = toupper (line_buffer
[0]);
427 fputs_filtered (line_buffer
, stream
);
431 * Implement a help command on command list LIST.
432 * RECURSE should be non-zero if this should be done recursively on
433 * all sublists of LIST.
434 * PREFIX is the prefix to print before each command name.
435 * STREAM is the stream upon which the output should be written.
437 * A non-negative class number to list only commands in that
439 * ALL_COMMANDS to list all commands in list.
440 * ALL_CLASSES to list all classes in list.
442 * Note that RECURSE will be active on *all* sublists, not just the
443 * ones selected by the criteria above (ie. the selection mechanism
444 * is at the low level, not the high-level).
447 help_cmd_list (list
, class, prefix
, recurse
, stream
)
448 struct cmd_list_element
*list
;
449 enum command_class
class;
454 register struct cmd_list_element
*c
;
456 for (c
= list
; c
; c
= c
->next
)
458 if (c
->abbrev_flag
== 0 &&
459 (class == all_commands
460 || (class == all_classes
&& c
->function
.cfunc
== NULL
)
461 || (class == c
->class && c
->function
.cfunc
!= NULL
)))
463 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
464 print_doc_line (stream
, c
->doc
);
465 fputs_filtered ("\n", stream
);
468 && c
->prefixlist
!= 0
469 && c
->abbrev_flag
== 0)
470 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
474 /* This routine takes a line of TEXT and a CLIST in which to
475 start the lookup. When it returns it will have incremented the text
476 pointer past the section of text it matched, set *RESULT_LIST to
477 the list in which the last word was matched, and will return the
478 cmd list element which the text matches. It will return 0 if no
479 match at all was possible. It will return -1 if ambigous matches are
480 possible; in this case *RESULT_LIST will be set to the list in which
481 there are ambiguous choices (and text will be set to the ambiguous
484 It does no error reporting whatsoever; control will always return
485 to the superior routine.
487 In the case of an ambiguous return (-1), *RESULT_LIST will be set to
488 point at the prefix_command (ie. the best match) *or* (special
489 case) will be 0 if no prefix command was ever found. For example,
490 in the case of "info a", "info" matches without ambiguity, but "a"
491 could be "args" or "address", so *RESULT_LIST is set to
492 the cmd_list_element for "info". So in this case
493 result list should not be interpeted as a pointer to the beginning
494 of a list; it simply points to a specific command.
496 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
497 affect the operation).
499 This routine does *not* modify the text pointed to by TEXT.
501 If IGNORE_HELP_CLASSES is nonzero, ignore any command list
502 elements which are actually help classes rather than commands (i.e.
503 the function field of the struct cmd_list_element is 0). */
505 struct cmd_list_element
*
506 lookup_cmd_1 (text
, clist
, result_list
, ignore_help_classes
)
508 struct cmd_list_element
*clist
, **result_list
;
509 int ignore_help_classes
;
512 int len
, tmp
, nfound
;
513 struct cmd_list_element
*found
, *c
;
515 while (**text
== ' ' || **text
== '\t')
518 /* Treating underscores as part of command words is important
519 so that "set args_foo()" doesn't get interpreted as
520 "set args _foo()". */
522 *p
&& (isalnum(*p
) || *p
== '-' || *p
== '_');
526 /* If nothing but whitespace, return 0. */
532 /* *text and p now bracket the first command word to lookup (and
533 it's length is len). We copy this into a local temporary,
534 converting to lower case as we go. */
536 command
= (char *) alloca (len
+ 1);
537 for (tmp
= 0; tmp
< len
; tmp
++)
539 char x
= (*text
)[tmp
];
540 command
[tmp
] = isupper(x
) ? tolower(x
) : x
;
547 for (c
= clist
; c
; c
= c
->next
)
548 if (!strncmp (command
, c
->name
, len
)
549 && (!ignore_help_classes
|| c
->function
.cfunc
))
553 if (c
->name
[len
] == '\0')
560 /* If nothing matches, we have a simple failure. */
566 if (result_list
!= NULL
)
567 /* Will be modified in calling routine
568 if we know what the prefix command is. */
570 return (struct cmd_list_element
*) -1; /* Ambiguous. */
573 /* We've matched something on this list. Move text pointer forward. */
576 if (found
->prefixlist
)
578 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
579 ignore_help_classes
);
582 /* Didn't find anything; this is as far as we got. */
583 if (result_list
!= NULL
)
584 *result_list
= clist
;
587 else if (c
== (struct cmd_list_element
*) -1)
589 /* We've gotten this far properley, but the next step
590 is ambiguous. We need to set the result list to the best
591 we've found (if an inferior hasn't already set it). */
592 if (result_list
!= NULL
)
594 /* This used to say *result_list = *found->prefixlist
595 If that was correct, need to modify the documentation
596 at the top of this function to clarify what is supposed
598 *result_list
= found
;
609 if (result_list
!= NULL
)
610 *result_list
= clist
;
615 /* All this hair to move the space to the front of cmdtype */
618 undef_cmd_error (cmdtype
, q
)
621 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
629 /* Look up the contents of *LINE as a command in the command list LIST.
630 LIST is a chain of struct cmd_list_element's.
631 If it is found, return the struct cmd_list_element for that command
632 and update *LINE to point after the command name, at the first argument.
633 If not found, call error if ALLOW_UNKNOWN is zero
634 otherwise (or if error returns) return zero.
635 Call error if specified command is ambiguous,
636 unless ALLOW_UNKNOWN is negative.
637 CMDTYPE precedes the word "command" in the error message.
639 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
640 elements which are actually help classes rather than commands (i.e.
641 the function field of the struct cmd_list_element is 0). */
643 struct cmd_list_element
*
644 lookup_cmd (line
, list
, cmdtype
, allow_unknown
, ignore_help_classes
)
646 struct cmd_list_element
*list
;
649 int ignore_help_classes
;
651 struct cmd_list_element
*last_list
= 0;
652 struct cmd_list_element
*c
=
653 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
654 char *ptr
= (*line
) + strlen (*line
) - 1;
656 /* Clear off trailing whitespace. */
657 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
666 error ("Lack of needed %scommand", cmdtype
);
671 while (isalnum(*p
) || *p
== '-')
674 q
= (char *) alloca (p
- *line
+ 1);
675 strncpy (q
, *line
, p
- *line
);
677 undef_cmd_error (cmdtype
, q
);
683 else if (c
== (struct cmd_list_element
*) -1)
685 /* Ambigous. Local values should be off prefixlist or called
687 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
689 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
690 struct cmd_list_element
*local_list
=
691 (last_list
? *(last_list
->prefixlist
) : list
);
693 if (local_allow_unknown
< 0)
696 return last_list
; /* Found something. */
698 return 0; /* Found nothing. */
702 /* Report as error. */
707 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
708 && (*line
)[amb_len
] != '\t');
713 for (c
= local_list
; c
; c
= c
->next
)
714 if (!strncmp (*line
, c
->name
, amb_len
))
716 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int)sizeof ambbuf
)
719 strcat (ambbuf
, ", ");
720 strcat (ambbuf
, c
->name
);
724 strcat (ambbuf
, "..");
728 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
735 /* We've got something. It may still not be what the caller
736 wants (if this command *needs* a subcommand). */
737 while (**line
== ' ' || **line
== '\t')
740 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
741 undef_cmd_error (c
->prefixname
, *line
);
743 /* Seems to be what he wants. Return it. */
750 /* Look up the contents of *LINE as a command in the command list LIST.
751 LIST is a chain of struct cmd_list_element's.
752 If it is found, return the struct cmd_list_element for that command
753 and update *LINE to point after the command name, at the first argument.
754 If not found, call error if ALLOW_UNKNOWN is zero
755 otherwise (or if error returns) return zero.
756 Call error if specified command is ambiguous,
757 unless ALLOW_UNKNOWN is negative.
758 CMDTYPE precedes the word "command" in the error message. */
760 struct cmd_list_element
*
761 lookup_cmd (line
, list
, cmdtype
, allow_unknown
)
763 struct cmd_list_element
*list
;
768 register struct cmd_list_element
*c
, *found
;
774 /* Skip leading whitespace. */
776 while (**line
== ' ' || **line
== '\t')
779 /* Clear out trailing whitespace. */
781 p
= *line
+ strlen (*line
);
782 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
786 /* Find end of command name. */
789 while (*p
== '-' || isalnum(*p
))
792 /* Look up the command name.
793 If exact match, keep that.
794 Otherwise, take command abbreviated, if unique. Note that (in my
795 opinion) a null string does *not* indicate ambiguity; simply the
796 end of the argument. */
801 error ("Lack of needed %scommand", cmdtype
);
805 /* Copy over to a local buffer, converting to lowercase on the way.
806 This is in case the command being parsed is a subcommand which
807 doesn't match anything, and that's ok. We want the original
808 untouched for the routine of the original command. */
810 processed_cmd
= (char *) alloca (p
- *line
+ 1);
811 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
813 char x
= (*line
)[cmd_len
];
815 processed_cmd
[cmd_len
] = tolower(x
);
817 processed_cmd
[cmd_len
] = x
;
819 processed_cmd
[cmd_len
] = '\0';
821 /* Check all possibilities in the current command list. */
824 for (c
= list
; c
; c
= c
->next
)
826 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
830 if (c
->name
[cmd_len
] == 0)
838 /* Report error for undefined command name. */
842 if (nfound
> 1 && allow_unknown
>= 0)
845 for (c
= list
; c
; c
= c
->next
)
846 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
848 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
851 strcat (ambbuf
, ", ");
852 strcat (ambbuf
, c
->name
);
856 strcat (ambbuf
, "..");
860 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
861 processed_cmd
, ambbuf
);
863 else if (!allow_unknown
)
864 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
868 /* Skip whitespace before the argument. */
870 while (*p
== ' ' || *p
== '\t') p
++;
873 if (found
->prefixlist
&& *p
)
875 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
876 found
->allow_unknown
);
885 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
887 /* Return a vector of char pointers which point to the different
888 possible completions in LIST of TEXT. */
891 complete_on_cmdlist (list
, text
)
892 struct cmd_list_element
*list
;
895 struct cmd_list_element
*ptr
;
897 int sizeof_matchlist
;
899 int textlen
= strlen (text
);
901 sizeof_matchlist
= 10;
902 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
905 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
906 if (!strncmp (ptr
->name
, text
, textlen
)
908 && (ptr
->function
.cfunc
911 if (matches
== sizeof_matchlist
)
913 sizeof_matchlist
*= 2;
914 matchlist
= (char **) xrealloc ((char *)matchlist
,
919 matchlist
[matches
] = (char *)
920 xmalloc (strlen (ptr
->name
) + 1);
921 strcpy (matchlist
[matches
++], ptr
->name
);
926 free ((PTR
)matchlist
);
931 matchlist
= (char **) xrealloc ((char *)matchlist
, ((matches
+ 1)
933 matchlist
[matches
] = (char *) 0;
940 parse_binary_operation (arg
)
948 length
= strlen (arg
);
950 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
953 if (!strncmp (arg
, "on", length
)
954 || !strncmp (arg
, "1", length
)
955 || !strncmp (arg
, "yes", length
))
958 if (!strncmp (arg
, "off", length
)
959 || !strncmp (arg
, "0", length
)
960 || !strncmp (arg
, "no", length
))
964 error ("\"on\" or \"off\" expected.");
969 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
970 of the argument, and FROM_TTY is nonzero if this command is being entered
971 directly by the user (i.e. these are just like any other
972 command). C is the command list element for the command. */
974 do_setshow_command (arg
, from_tty
, c
)
977 struct cmd_list_element
*c
;
979 if (c
->type
== set_cmd
)
992 new = (char *) xmalloc (strlen (arg
) + 2);
994 while ((ch
= *p
++) != '\000')
998 /* \ at end of argument is used after spaces
999 so they won't be lost. */
1002 ch
= parse_escape (&p
);
1004 break; /* C loses */
1011 if (*(p
- 1) != '\\')
1014 new = (char *) xrealloc (new, q
- new);
1015 if (*(char **)c
->var
!= NULL
)
1016 free (*(char **)c
->var
);
1017 *(char **) c
->var
= new;
1020 case var_string_noescape
:
1023 if (*(char **)c
->var
!= NULL
)
1024 free (*(char **)c
->var
);
1025 *(char **) c
->var
= savestring (arg
, strlen (arg
));
1029 error_no_arg ("filename to set it to.");
1030 if (*(char **)c
->var
!= NULL
)
1031 free (*(char **)c
->var
);
1032 *(char **)c
->var
= tilde_expand (arg
);
1035 *(int *) c
->var
= parse_binary_operation (arg
);
1039 error_no_arg ("integer to set it to.");
1040 *(int *) c
->var
= parse_and_eval_address (arg
);
1041 if (*(int *) c
->var
== 0)
1042 *(int *) c
->var
= UINT_MAX
;
1046 error_no_arg ("integer to set it to.");
1047 *(int *) c
->var
= parse_and_eval_address (arg
);
1050 error ("gdb internal error: bad var_type in do_setshow_command");
1053 else if (c
->type
== show_cmd
)
1055 /* Print doc minus "show" at start. */
1056 print_doc_line (stdout
, c
->doc
+ 5);
1058 fputs_filtered (" is ", stdout
);
1060 switch (c
->var_type
)
1065 fputs_filtered ("\"", stdout
);
1066 for (p
= *(unsigned char **) c
->var
; *p
!= '\0'; p
++)
1067 printchar (*p
, stdout
, '"');
1068 fputs_filtered ("\"", stdout
);
1071 case var_string_noescape
:
1073 fputs_filtered ("\"", stdout
);
1074 fputs_filtered (*(char **) c
->var
, stdout
);
1075 fputs_filtered ("\"", stdout
);
1078 fputs_filtered (*(int *) c
->var
? "on" : "off", stdout
);
1081 if (*(unsigned int *) c
->var
== UINT_MAX
) {
1082 fputs_filtered ("unlimited", stdout
);
1085 /* else fall through */
1087 fprintf_filtered (stdout
, "%d", *(unsigned int *) c
->var
);
1090 error ("gdb internal error: bad var_type in do_setshow_command");
1092 fputs_filtered (".\n", stdout
);
1095 error ("gdb internal error: bad cmd_type in do_setshow_command");
1096 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
1099 /* Show all the settings in a list of show commands. */
1102 cmd_show_list (list
, from_tty
, prefix
)
1103 struct cmd_list_element
*list
;
1107 for (; list
!= NULL
; list
= list
->next
) {
1108 /* If we find a prefix, run its list, prefixing our output by its
1109 prefix (with "show " skipped). */
1110 if (list
->prefixlist
&& !list
->abbrev_flag
)
1111 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1112 if (list
->type
== show_cmd
)
1114 fputs_filtered (prefix
, stdout
);
1115 fputs_filtered (list
->name
, stdout
);
1116 fputs_filtered (": ", stdout
);
1117 do_setshow_command ((char *)NULL
, from_tty
, list
);
1124 shell_escape (arg
, from_tty
)
1128 int rc
, status
, pid
;
1129 char *p
, *user_shell
;
1131 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1132 user_shell
= "/bin/sh";
1134 /* Get the name of the shell for arg0 */
1135 if ((p
= strrchr (user_shell
, '/')) == NULL
)
1138 p
++; /* Get past '/' */
1140 if ((pid
= fork()) == 0)
1143 execl (user_shell
, p
, 0);
1145 execl (user_shell
, p
, "-c", arg
, 0);
1147 fprintf (stderr
, "Exec of shell failed\n");
1152 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1155 error ("Fork failed");
1159 make_command (arg
, from_tty
)
1169 p
= xmalloc (sizeof("make ") + strlen(arg
));
1170 strcpy (p
, "make ");
1171 strcpy (p
+ sizeof("make ")-1, arg
);
1174 shell_escape (p
, from_tty
);
1178 show_user_1 (c
, stream
)
1179 struct cmd_list_element
*c
;
1182 register struct command_line
*cmdlines
;
1184 cmdlines
= c
->user_commands
;
1187 fprintf_filtered (stream
, "User command %s:\n", c
->name
);
1190 fprintf_filtered (stream
, "%s\n", cmdlines
->line
);
1191 cmdlines
= cmdlines
->next
;
1193 fputs_filtered ("\n", stream
);
1198 show_user (args
, from_tty
)
1202 struct cmd_list_element
*c
;
1203 extern struct cmd_list_element
*cmdlist
;
1207 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
1208 if (c
->class != class_user
)
1209 error ("Not a user command.");
1210 show_user_1 (c
, stdout
);
1214 for (c
= cmdlist
; c
; c
= c
->next
)
1216 if (c
->class == class_user
)
1217 show_user_1 (c
, stdout
);
1223 _initialize_command ()
1225 add_com ("shell", class_support
, shell_escape
,
1226 "Execute the rest of the line as a shell command. \n\
1227 With no arguments, run an inferior shell.");
1229 add_com ("make", class_support
, make_command
,
1230 "Run the ``make'' program using the rest of the line as arguments.");
1232 add_cmd ("user", no_class
, show_user
,
1233 "Show definitions of user defined commands.\n\
1234 Argument is the name of the user defined command.\n\
1235 With no argument, show definitions of all user defined commands.", &showlist
);