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. */
26 /* Prototypes for local functions */
29 undef_cmd_error
PARAMS ((char *, char *));
32 show_user
PARAMS ((char *, int));
35 show_user_1
PARAMS ((struct cmd_list_element
*, FILE *));
38 make_command
PARAMS ((char *, int));
41 shell_escape
PARAMS ((char *, int));
44 parse_binary_operation
PARAMS ((char *));
47 print_doc_line
PARAMS ((FILE *, char *));
49 /* Add element named NAME to command list *LIST.
50 FUN should be the function to execute the command;
51 it will get a character string as argument, with leading
52 and trailing blanks already eliminated.
54 DOC is a documentation string for the command.
55 Its first line should be a complete sentence.
56 It should start with ? for a command that is an abbreviation
57 or with * for a command that most users don't need to know about. */
59 struct cmd_list_element
*
60 add_cmd (name
, class, fun
, doc
, list
)
62 enum command_class
class;
63 void (*fun
) PARAMS ((char *, int));
65 struct cmd_list_element
**list
;
67 register struct cmd_list_element
*c
68 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
70 delete_cmd (name
, list
);
74 c
->function
.cfunc
= fun
;
77 c
->prefixname
= (char *)NULL
;
81 c
->type
= not_set_cmd
;
82 c
->completer
= make_symbol_completion_list
;
84 c
->var_type
= var_boolean
;
90 /* Same as above, except that the abbrev_flag is set. */
92 #if 0 /* Currently unused */
94 struct cmd_list_element
*
95 add_abbrev_cmd (name
, class, fun
, doc
, list
)
97 enum command_class
class;
98 void (*fun
) PARAMS ((char *, int));
100 struct cmd_list_element
**list
;
102 register struct cmd_list_element
*c
103 = add_cmd (name
, class, fun
, doc
, list
);
111 struct cmd_list_element
*
112 add_alias_cmd (name
, oldname
, class, abbrev_flag
, list
)
115 enum command_class
class;
117 struct cmd_list_element
**list
;
119 /* Must do this since lookup_cmd tries to side-effect its first arg */
121 register struct cmd_list_element
*old
;
122 register struct cmd_list_element
*c
;
123 copied_name
= (char *) alloca (strlen (oldname
) + 1);
124 strcpy (copied_name
, oldname
);
125 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
129 delete_cmd (name
, list
);
133 c
= add_cmd (name
, class, old
->function
.cfunc
, old
->doc
, list
);
134 c
->prefixlist
= old
->prefixlist
;
135 c
->prefixname
= old
->prefixname
;
136 c
->allow_unknown
= old
->allow_unknown
;
137 c
->abbrev_flag
= abbrev_flag
;
142 /* Like add_cmd but adds an element for a command prefix:
143 a name that should be followed by a subcommand to be looked up
144 in another command list. PREFIXLIST should be the address
145 of the variable containing that list. */
147 struct cmd_list_element
*
148 add_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
151 enum command_class
class;
152 void (*fun
) PARAMS ((char *, int));
154 struct cmd_list_element
**prefixlist
;
157 struct cmd_list_element
**list
;
159 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
160 c
->prefixlist
= prefixlist
;
161 c
->prefixname
= prefixname
;
162 c
->allow_unknown
= allow_unknown
;
166 /* Like add_prefix_cmd butsets the abbrev_flag on the new command. */
168 struct cmd_list_element
*
169 add_abbrev_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
172 enum command_class
class;
173 void (*fun
) PARAMS ((char *, int));
175 struct cmd_list_element
**prefixlist
;
178 struct cmd_list_element
**list
;
180 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
181 c
->prefixlist
= prefixlist
;
182 c
->prefixname
= prefixname
;
183 c
->allow_unknown
= allow_unknown
;
190 not_just_help_class_command (args
, from_tty
, c
)
193 struct cmd_list_element
*c
;
197 /* Add element named NAME to command list LIST (the list for set
198 or some sublist thereof).
199 CLASS is as in add_cmd.
200 VAR_TYPE is the kind of thing we are setting.
201 VAR is address of the variable being controlled by this command.
202 DOC is the documentation string. */
204 struct cmd_list_element
*
205 add_set_cmd (name
, class, var_type
, var
, doc
, list
)
207 enum command_class
class;
211 struct cmd_list_element
**list
;
213 /* For set/show, we have to call do_setshow_command
214 differently than an ordinary function (take commandlist as
215 well as arg), so the function field isn't helpful. However,
216 function == NULL means that it's a help class, so set the function
217 to not_just_help_class_command. */
218 struct cmd_list_element
*c
219 = add_cmd (name
, class, not_just_help_class_command
, doc
, list
);
222 c
->var_type
= var_type
;
227 /* Where SETCMD has already been added, add the corresponding show
228 command to LIST and return a pointer to it. */
229 struct cmd_list_element
*
230 add_show_from_set (setcmd
, list
)
231 struct cmd_list_element
*setcmd
;
232 struct cmd_list_element
**list
;
234 struct cmd_list_element
*showcmd
=
235 (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
237 bcopy (setcmd
, showcmd
, sizeof (struct cmd_list_element
));
238 delete_cmd (showcmd
->name
, list
);
239 showcmd
->type
= show_cmd
;
241 /* Replace "set " at start of docstring with "show ". */
242 if (setcmd
->doc
[0] == 'S' && setcmd
->doc
[1] == 'e'
243 && setcmd
->doc
[2] == 't' && setcmd
->doc
[3] == ' ')
244 showcmd
->doc
= concat ("Show ", setcmd
->doc
+ 4, NULL
);
246 fprintf (stderr
, "GDB internal error: Bad docstring for set command\n");
248 showcmd
->next
= *list
;
253 /* Remove the command named NAME from the command list. */
256 delete_cmd (name
, list
)
258 struct cmd_list_element
**list
;
260 register struct cmd_list_element
*c
;
261 struct cmd_list_element
*p
;
263 while (*list
&& !strcmp ((*list
)->name
, name
))
271 for (c
= *list
; c
->next
;)
273 if (!strcmp (c
->next
->name
, name
))
284 /* This command really has to deal with two things:
285 * 1) I want documentation on *this string* (usually called by
286 * "help commandname").
287 * 2) I want documentation on *this list* (usually called by
288 * giving a command that requires subcommands. Also called by saying
291 * I am going to split this into two seperate comamnds, help_cmd and
296 help_cmd (command
, stream
)
300 struct cmd_list_element
*c
;
301 extern struct cmd_list_element
*cmdlist
;
305 help_list (cmdlist
, "", all_classes
, stream
);
309 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
314 /* There are three cases here.
315 If c->prefixlist is nonzero, we have a prefix command.
316 Print its documentation, then list its subcommands.
318 If c->function is nonzero, we really have a command.
319 Print its documentation and return.
321 If c->function is zero, we have a class name.
322 Print its documentation (as if it were a command)
323 and then set class to the number of this class
324 so that the commands in the class will be listed. */
326 fputs_filtered (c
->doc
, stream
);
327 fputs_filtered ("\n", stream
);
329 if (c
->prefixlist
== 0 && c
->function
.cfunc
!= NULL
)
331 fprintf_filtered (stream
, "\n");
333 /* If this is a prefix command, print it's subcommands */
335 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
337 /* If this is a class name, print all of the commands in the class */
338 if (c
->function
.cfunc
== NULL
)
339 help_list (cmdlist
, "", c
->class, stream
);
343 * Get a specific kind of help on a command list.
346 * CMDTYPE is the prefix to use in the title string.
347 * CLASS is the class with which to list the nodes of this list (see
348 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
349 * everything, ALL_CLASSES for just classes, and non-negative for only things
350 * in a specific class.
351 * and STREAM is the output stream on which to print things.
352 * If you call this routine with a class >= 0, it recurses.
355 help_list (list
, cmdtype
, class, stream
)
356 struct cmd_list_element
*list
;
358 enum command_class
class;
362 char *cmdtype1
, *cmdtype2
;
364 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
365 len
= strlen (cmdtype
);
366 cmdtype1
= (char *) alloca (len
+ 1);
368 cmdtype2
= (char *) alloca (len
+ 4);
373 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
375 strncpy (cmdtype2
, cmdtype
, len
- 1);
376 strcpy (cmdtype2
+ len
- 1, " sub");
379 if (class == all_classes
)
380 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
382 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
384 help_cmd_list (list
, class, cmdtype
, (int)class >= 0, stream
);
386 if (class == all_classes
)
387 fprintf_filtered (stream
, "\n\
388 Type \"help%s\" followed by a class name for a list of commands in that class.",
391 fprintf_filtered (stream
, "\n\
392 Type \"help%s\" followed by %scommand name for full documentation.\n\
393 Command name abbreviations are allowed if unambiguous.\n",
397 /* Print only the first line of STR on STREAM. */
399 print_doc_line (stream
, str
)
403 static char *line_buffer
= 0;
404 static int line_size
;
410 line_buffer
= (char *) xmalloc (line_size
);
414 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
416 if (p
- str
> line_size
- 1)
418 line_size
= p
- str
+ 1;
420 line_buffer
= (char *) xmalloc (line_size
);
422 strncpy (line_buffer
, str
, p
- str
);
423 line_buffer
[p
- str
] = '\0';
424 if (islower (line_buffer
[0]))
425 line_buffer
[0] = toupper (line_buffer
[0]);
426 fputs_filtered (line_buffer
, stream
);
430 * Implement a help command on command list LIST.
431 * RECURSE should be non-zero if this should be done recursively on
432 * all sublists of LIST.
433 * PREFIX is the prefix to print before each command name.
434 * STREAM is the stream upon which the output should be written.
436 * A non-negative class number to list only commands in that
438 * ALL_COMMANDS to list all commands in list.
439 * ALL_CLASSES to list all classes in list.
441 * Note that RECURSE will be active on *all* sublists, not just the
442 * ones selected by the criteria above (ie. the selection mechanism
443 * is at the low level, not the high-level).
446 help_cmd_list (list
, class, prefix
, recurse
, stream
)
447 struct cmd_list_element
*list
;
448 enum command_class
class;
453 register struct cmd_list_element
*c
;
455 for (c
= list
; c
; c
= c
->next
)
457 if (c
->abbrev_flag
== 0 &&
458 (class == all_commands
459 || (class == all_classes
&& c
->function
.cfunc
== NULL
)
460 || (class == c
->class && c
->function
.cfunc
!= NULL
)))
462 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
463 print_doc_line (stream
, c
->doc
);
464 fputs_filtered ("\n", stream
);
467 && c
->prefixlist
!= 0
468 && c
->abbrev_flag
== 0)
469 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
473 /* This routine takes a line of TEXT and a CLIST in which to
474 start the lookup. When it returns it will have incremented the text
475 pointer past the section of text it matched, set *RESULT_LIST to
476 the list in which the last word was matched, and will return the
477 cmd list element which the text matches. It will return 0 if no
478 match at all was possible. It will return -1 if ambigous matches are
479 possible; in this case *RESULT_LIST will be set to the list in which
480 there are ambiguous choices (and text will be set to the ambiguous
483 It does no error reporting whatsoever; control will always return
484 to the superior routine.
486 In the case of an ambiguous return (-1), *RESULT_LIST will be set to
487 point at the prefix_command (ie. the best match) *or* (special
488 case) will be 0 if no prefix command was ever found. For example,
489 in the case of "info a", "info" matches without ambiguity, but "a"
490 could be "args" or "address", so *RESULT_LIST is set to
491 the cmd_list_element for "info". So in this case
492 result list should not be interpeted as a pointer to the beginning
493 of a list; it simply points to a specific command.
495 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
496 affect the operation).
498 This routine does *not* modify the text pointed to by TEXT.
500 If IGNORE_HELP_CLASSES is nonzero, ignore any command list
501 elements which are actually help classes rather than commands (i.e.
502 the function field of the struct cmd_list_element is 0). */
504 struct cmd_list_element
*
505 lookup_cmd_1 (text
, clist
, result_list
, ignore_help_classes
)
507 struct cmd_list_element
*clist
, **result_list
;
508 int ignore_help_classes
;
511 int len
, tmp
, nfound
;
512 struct cmd_list_element
*found
, *c
;
514 while (**text
== ' ' || **text
== '\t')
517 /* Treating underscores as part of command words is important
518 so that "set args_foo()" doesn't get interpreted as
519 "set args _foo()". */
521 *p
&& (isalnum(*p
) || *p
== '-' || *p
== '_');
525 /* If nothing but whitespace, return 0. */
531 /* *text and p now bracket the first command word to lookup (and
532 it's length is len). We copy this into a local temporary,
533 converting to lower case as we go. */
535 command
= (char *) alloca (len
+ 1);
536 for (tmp
= 0; tmp
< len
; tmp
++)
538 char x
= (*text
)[tmp
];
539 command
[tmp
] = (x
>= 'A' && x
<= 'Z') ? x
- 'A' + 'a' : x
;
546 for (c
= clist
; c
; c
= c
->next
)
547 if (!strncmp (command
, c
->name
, len
)
548 && (!ignore_help_classes
|| c
->function
.cfunc
))
552 if (c
->name
[len
] == '\0')
559 /* If nothing matches, we have a simple failure. */
565 if (result_list
!= NULL
)
566 /* Will be modified in calling routine
567 if we know what the prefix command is. */
569 return (struct cmd_list_element
*) -1; /* Ambiguous. */
572 /* We've matched something on this list. Move text pointer forward. */
575 if (found
->prefixlist
)
577 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
578 ignore_help_classes
);
581 /* Didn't find anything; this is as far as we got. */
582 if (result_list
!= NULL
)
583 *result_list
= clist
;
586 else if (c
== (struct cmd_list_element
*) -1)
588 /* We've gotten this far properley, but the next step
589 is ambiguous. We need to set the result list to the best
590 we've found (if an inferior hasn't already set it). */
591 if (result_list
!= NULL
)
593 /* This used to say *result_list = *found->prefixlist
594 If that was correct, need to modify the documentation
595 at the top of this function to clarify what is supposed
597 *result_list
= found
;
608 if (result_list
!= NULL
)
609 *result_list
= clist
;
614 /* All this hair to move the space to the front of cmdtype */
617 undef_cmd_error (cmdtype
, q
)
620 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
628 /* Look up the contents of *LINE as a command in the command list LIST.
629 LIST is a chain of struct cmd_list_element's.
630 If it is found, return the struct cmd_list_element for that command
631 and update *LINE to point after the command name, at the first argument.
632 If not found, call error if ALLOW_UNKNOWN is zero
633 otherwise (or if error returns) return zero.
634 Call error if specified command is ambiguous,
635 unless ALLOW_UNKNOWN is negative.
636 CMDTYPE precedes the word "command" in the error message.
638 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
639 elements which are actually help classes rather than commands (i.e.
640 the function field of the struct cmd_list_element is 0). */
642 struct cmd_list_element
*
643 lookup_cmd (line
, list
, cmdtype
, allow_unknown
, ignore_help_classes
)
645 struct cmd_list_element
*list
;
648 int ignore_help_classes
;
650 struct cmd_list_element
*last_list
= 0;
651 struct cmd_list_element
*c
=
652 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
653 char *ptr
= (*line
) + strlen (*line
) - 1;
655 /* Clear off trailing whitespace. */
656 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
665 error ("Lack of needed %scommand", cmdtype
);
670 while (isalnum(*p
) || *p
== '-')
673 q
= (char *) alloca (p
- *line
+ 1);
674 strncpy (q
, *line
, p
- *line
);
676 undef_cmd_error (cmdtype
, q
);
682 else if (c
== (struct cmd_list_element
*) -1)
684 /* Ambigous. Local values should be off prefixlist or called
686 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
688 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
689 struct cmd_list_element
*local_list
=
690 (last_list
? *(last_list
->prefixlist
) : list
);
692 if (local_allow_unknown
< 0)
695 return last_list
; /* Found something. */
697 return 0; /* Found nothing. */
701 /* Report as error. */
706 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
707 && (*line
)[amb_len
] != '\t');
712 for (c
= local_list
; c
; c
= c
->next
)
713 if (!strncmp (*line
, c
->name
, amb_len
))
715 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int)sizeof ambbuf
)
718 strcat (ambbuf
, ", ");
719 strcat (ambbuf
, c
->name
);
723 strcat (ambbuf
, "..");
727 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
734 /* We've got something. It may still not be what the caller
735 wants (if this command *needs* a subcommand). */
736 while (**line
== ' ' || **line
== '\t')
739 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
740 undef_cmd_error (c
->prefixname
, *line
);
742 /* Seems to be what he wants. Return it. */
749 /* Look up the contents of *LINE as a command in the command list LIST.
750 LIST is a chain of struct cmd_list_element's.
751 If it is found, return the struct cmd_list_element for that command
752 and update *LINE to point after the command name, at the first argument.
753 If not found, call error if ALLOW_UNKNOWN is zero
754 otherwise (or if error returns) return zero.
755 Call error if specified command is ambiguous,
756 unless ALLOW_UNKNOWN is negative.
757 CMDTYPE precedes the word "command" in the error message. */
759 struct cmd_list_element
*
760 lookup_cmd (line
, list
, cmdtype
, allow_unknown
)
762 struct cmd_list_element
*list
;
767 register struct cmd_list_element
*c
, *found
;
773 /* Skip leading whitespace. */
775 while (**line
== ' ' || **line
== '\t')
778 /* Clear out trailing whitespace. */
780 p
= *line
+ strlen (*line
);
781 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
785 /* Find end of command name. */
789 || (*p
>= 'a' && *p
<= 'z')
790 || (*p
>= 'A' && *p
<= 'Z')
791 || (*p
>= '0' && *p
<= '9'))
794 /* Look up the command name.
795 If exact match, keep that.
796 Otherwise, take command abbreviated, if unique. Note that (in my
797 opinion) a null string does *not* indicate ambiguity; simply the
798 end of the argument. */
803 error ("Lack of needed %scommand", cmdtype
);
807 /* Copy over to a local buffer, converting to lowercase on the way.
808 This is in case the command being parsed is a subcommand which
809 doesn't match anything, and that's ok. We want the original
810 untouched for the routine of the original command. */
812 processed_cmd
= (char *) alloca (p
- *line
+ 1);
813 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
815 char x
= (*line
)[cmd_len
];
816 if (x
>= 'A' && x
<= 'Z')
817 processed_cmd
[cmd_len
] = x
- 'A' + 'a';
819 processed_cmd
[cmd_len
] = x
;
821 processed_cmd
[cmd_len
] = '\0';
823 /* Check all possibilities in the current command list. */
826 for (c
= list
; c
; c
= c
->next
)
828 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
832 if (c
->name
[cmd_len
] == 0)
840 /* Report error for undefined command name. */
844 if (nfound
> 1 && allow_unknown
>= 0)
847 for (c
= list
; c
; c
= c
->next
)
848 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
850 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
853 strcat (ambbuf
, ", ");
854 strcat (ambbuf
, c
->name
);
858 strcat (ambbuf
, "..");
862 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
863 processed_cmd
, ambbuf
);
865 else if (!allow_unknown
)
866 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
870 /* Skip whitespace before the argument. */
872 while (*p
== ' ' || *p
== '\t') p
++;
875 if (found
->prefixlist
&& *p
)
877 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
878 found
->allow_unknown
);
887 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
889 /* Return a vector of char pointers which point to the different
890 possible completions in LIST of TEXT. */
893 complete_on_cmdlist (list
, text
)
894 struct cmd_list_element
*list
;
897 struct cmd_list_element
*ptr
;
899 int sizeof_matchlist
;
901 int textlen
= strlen (text
);
903 sizeof_matchlist
= 10;
904 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
907 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
908 if (!strncmp (ptr
->name
, text
, textlen
)
910 && (ptr
->function
.cfunc
913 if (matches
== sizeof_matchlist
)
915 sizeof_matchlist
*= 2;
916 matchlist
= (char **) xrealloc ((char *)matchlist
,
921 matchlist
[matches
] = (char *)
922 xmalloc (strlen (ptr
->name
) + 1);
923 strcpy (matchlist
[matches
++], ptr
->name
);
933 matchlist
= (char **) xrealloc ((char *)matchlist
, ((matches
+ 1)
935 matchlist
[matches
] = (char *) 0;
942 parse_binary_operation (arg
)
950 length
= strlen (arg
);
952 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
955 if (!strncmp (arg
, "on", length
)
956 || !strncmp (arg
, "1", length
)
957 || !strncmp (arg
, "yes", length
))
960 if (!strncmp (arg
, "off", length
)
961 || !strncmp (arg
, "0", length
)
962 || !strncmp (arg
, "no", length
))
966 error ("\"on\" or \"off\" expected.");
971 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
972 of the argument, and FROM_TTY is nonzero if this command is being entered
973 directly by the user (i.e. these are just like any other
974 command). C is the command list element for the command. */
976 do_setshow_command (arg
, from_tty
, c
)
979 struct cmd_list_element
*c
;
981 if (c
->type
== set_cmd
)
994 new = (char *) xmalloc (strlen (arg
) + 2);
996 while ((ch
= *p
++) != '\000')
1000 /* \ at end of argument is used after spaces
1001 so they won't be lost. */
1004 ch
= parse_escape (&p
);
1006 break; /* C loses */
1013 if (*(p
- 1) != '\\')
1016 new = (char *) xrealloc (new, q
- new);
1017 if (*(char **)c
->var
!= NULL
)
1018 free (*(char **)c
->var
);
1019 *(char **) c
->var
= new;
1022 case var_string_noescape
:
1025 if (*(char **)c
->var
!= NULL
)
1026 free (*(char **)c
->var
);
1027 *(char **) c
->var
= savestring (arg
, strlen (arg
));
1031 error_no_arg ("filename to set it to.");
1032 if (*(char **)c
->var
!= NULL
)
1033 free (*(char **)c
->var
);
1034 *(char **)c
->var
= tilde_expand (arg
);
1037 *(int *) c
->var
= parse_binary_operation (arg
);
1041 error_no_arg ("integer to set it to.");
1042 *(int *) c
->var
= parse_and_eval_address (arg
);
1043 if (*(int *) c
->var
== 0)
1044 *(int *) c
->var
= UINT_MAX
;
1048 error_no_arg ("integer to set it to.");
1049 *(int *) c
->var
= parse_and_eval_address (arg
);
1052 error ("gdb internal error: bad var_type in do_setshow_command");
1055 else if (c
->type
== show_cmd
)
1057 /* Print doc minus "show" at start. */
1058 print_doc_line (stdout
, c
->doc
+ 5);
1060 fputs_filtered (" is ", stdout
);
1062 switch (c
->var_type
)
1067 fputs_filtered ("\"", stdout
);
1068 for (p
= *(unsigned char **) c
->var
; *p
!= '\0'; p
++)
1069 printchar (*p
, stdout
, '"');
1070 fputs_filtered ("\"", stdout
);
1073 case var_string_noescape
:
1075 fputs_filtered ("\"", stdout
);
1076 fputs_filtered (*(char **) c
->var
, stdout
);
1077 fputs_filtered ("\"", stdout
);
1080 fputs_filtered (*(int *) c
->var
? "on" : "off", stdout
);
1083 if (*(unsigned int *) c
->var
== UINT_MAX
) {
1084 fputs_filtered ("unlimited", stdout
);
1087 /* else fall through */
1089 fprintf_filtered (stdout
, "%d", *(unsigned int *) c
->var
);
1092 error ("gdb internal error: bad var_type in do_setshow_command");
1094 fputs_filtered (".\n", stdout
);
1097 error ("gdb internal error: bad cmd_type in do_setshow_command");
1098 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
1101 /* Show all the settings in a list of show commands. */
1104 cmd_show_list (list
, from_tty
, prefix
)
1105 struct cmd_list_element
*list
;
1109 for (; list
!= NULL
; list
= list
->next
) {
1110 /* If we find a prefix, run its list, prefixing our output by its
1111 prefix (with "show " skipped). */
1112 if (list
->prefixlist
&& !list
->abbrev_flag
)
1113 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1114 if (list
->type
== show_cmd
)
1116 fputs_filtered (prefix
, stdout
);
1117 fputs_filtered (list
->name
, stdout
);
1118 fputs_filtered (": ", stdout
);
1119 do_setshow_command ((char *)NULL
, from_tty
, list
);
1126 shell_escape (arg
, from_tty
)
1130 int rc
, status
, pid
;
1131 char *p
, *user_shell
;
1133 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1134 user_shell
= "/bin/sh";
1136 /* Get the name of the shell for arg0 */
1137 if ((p
= strrchr (user_shell
, '/')) == NULL
)
1140 p
++; /* Get past '/' */
1142 if ((pid
= fork()) == 0)
1145 execl (user_shell
, p
, 0);
1147 execl (user_shell
, p
, "-c", arg
, 0);
1149 fprintf (stderr
, "Exec of shell failed\n");
1154 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1157 error ("Fork failed");
1161 make_command (arg
, from_tty
)
1171 p
= xmalloc (sizeof("make ") + strlen(arg
));
1172 strcpy (p
, "make ");
1173 strcpy (p
+ sizeof("make ")-1, arg
);
1176 shell_escape (p
, from_tty
);
1180 show_user_1 (c
, stream
)
1181 struct cmd_list_element
*c
;
1184 register struct command_line
*cmdlines
;
1186 cmdlines
= c
->user_commands
;
1189 fprintf_filtered (stream
, "User command %s:\n", c
->name
);
1192 fprintf_filtered (stream
, "%s\n", cmdlines
->line
);
1193 cmdlines
= cmdlines
->next
;
1195 fputs_filtered ("\n", stream
);
1200 show_user (args
, from_tty
)
1204 struct cmd_list_element
*c
;
1205 extern struct cmd_list_element
*cmdlist
;
1209 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
1210 if (c
->class != class_user
)
1211 error ("Not a user command.");
1212 show_user_1 (c
, stdout
);
1216 for (c
= cmdlist
; c
; c
= c
->next
)
1218 if (c
->class == class_user
)
1219 show_user_1 (c
, stdout
);
1225 _initialize_command ()
1227 add_com ("shell", class_support
, shell_escape
,
1228 "Execute the rest of the line as a shell command. \n\
1229 With no arguments, run an inferior shell.");
1231 add_com ("make", class_support
, make_command
,
1232 "Run the ``make'' program using the rest of the line as arguments.");
1234 add_cmd ("user", no_class
, show_user
,
1235 "Show definitions of user defined commands.\n\
1236 Argument is the name of the user defined command.\n\
1237 With no argument, show definitions of all user defined commands.", &showlist
);