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 *));
48 /* Add element named NAME to command list *LIST.
49 FUN should be the function to execute the command;
50 it will get a character string as argument, with leading
51 and trailing blanks already eliminated.
53 DOC is a documentation string for the command.
54 Its first line should be a complete sentence.
55 It should start with ? for a command that is an abbreviation
56 or with * for a command that most users don't need to know about. */
58 struct cmd_list_element
*
59 add_cmd (name
, class, fun
, doc
, list
)
61 enum command_class
class;
62 void (*fun
) PARAMS ((char *, int));
64 struct cmd_list_element
**list
;
66 register struct cmd_list_element
*c
67 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
69 delete_cmd (name
, list
);
73 c
->function
.cfunc
= fun
;
76 c
->prefixname
= (char *)NULL
;
80 c
->type
= not_set_cmd
;
81 c
->completer
= make_symbol_completion_list
;
83 c
->var_type
= var_boolean
;
89 /* Same as above, except that the abbrev_flag is set. */
91 #if 0 /* Currently unused */
93 struct cmd_list_element
*
94 add_abbrev_cmd (name
, class, fun
, doc
, list
)
96 enum command_class
class;
97 void (*fun
) PARAMS ((char *, int));
99 struct cmd_list_element
**list
;
101 register struct cmd_list_element
*c
102 = add_cmd (name
, class, fun
, doc
, list
);
110 struct cmd_list_element
*
111 add_alias_cmd (name
, oldname
, class, abbrev_flag
, list
)
114 enum command_class
class;
116 struct cmd_list_element
**list
;
118 /* Must do this since lookup_cmd tries to side-effect its first arg */
120 register struct cmd_list_element
*old
;
121 register struct cmd_list_element
*c
;
122 copied_name
= (char *) alloca (strlen (oldname
) + 1);
123 strcpy (copied_name
, oldname
);
124 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
128 delete_cmd (name
, list
);
132 c
= add_cmd (name
, class, old
->function
.cfunc
, old
->doc
, list
);
133 c
->prefixlist
= old
->prefixlist
;
134 c
->prefixname
= old
->prefixname
;
135 c
->allow_unknown
= old
->allow_unknown
;
136 c
->abbrev_flag
= abbrev_flag
;
141 /* Like add_cmd but adds an element for a command prefix:
142 a name that should be followed by a subcommand to be looked up
143 in another command list. PREFIXLIST should be the address
144 of the variable containing that list. */
146 struct cmd_list_element
*
147 add_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
150 enum command_class
class;
151 void (*fun
) PARAMS ((char *, int));
153 struct cmd_list_element
**prefixlist
;
156 struct cmd_list_element
**list
;
158 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
159 c
->prefixlist
= prefixlist
;
160 c
->prefixname
= prefixname
;
161 c
->allow_unknown
= allow_unknown
;
165 /* Like add_prefix_cmd butsets the abbrev_flag on the new command. */
167 struct cmd_list_element
*
168 add_abbrev_prefix_cmd (name
, class, fun
, doc
, prefixlist
, prefixname
,
171 enum command_class
class;
172 void (*fun
) PARAMS ((char *, int));
174 struct cmd_list_element
**prefixlist
;
177 struct cmd_list_element
**list
;
179 register struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
180 c
->prefixlist
= prefixlist
;
181 c
->prefixname
= prefixname
;
182 c
->allow_unknown
= allow_unknown
;
189 not_just_help_class_command (args
, from_tty
, c
)
192 struct cmd_list_element
*c
;
196 /* Add element named NAME to command list LIST (the list for set
197 or some sublist thereof).
198 CLASS is as in add_cmd.
199 VAR_TYPE is the kind of thing we are setting.
200 VAR is address of the variable being controlled by this command.
201 DOC is the documentation string. */
203 struct cmd_list_element
*
204 add_set_cmd (name
, class, var_type
, var
, doc
, list
)
206 enum command_class
class;
210 struct cmd_list_element
**list
;
212 /* For set/show, we have to call do_setshow_command
213 differently than an ordinary function (take commandlist as
214 well as arg), so the function field isn't helpful. However,
215 function == NULL means that it's a help class, so set the function
216 to not_just_help_class_command. */
217 struct cmd_list_element
*c
218 = add_cmd (name
, class, not_just_help_class_command
, doc
, list
);
221 c
->var_type
= var_type
;
226 /* Where SETCMD has already been added, add the corresponding show
227 command to LIST and return a pointer to it. */
228 struct cmd_list_element
*
229 add_show_from_set (setcmd
, list
)
230 struct cmd_list_element
*setcmd
;
231 struct cmd_list_element
**list
;
233 struct cmd_list_element
*showcmd
=
234 (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
236 bcopy (setcmd
, showcmd
, sizeof (struct cmd_list_element
));
237 delete_cmd (showcmd
->name
, list
);
238 showcmd
->type
= show_cmd
;
240 /* Replace "set " at start of docstring with "show ". */
241 if (setcmd
->doc
[0] == 'S' && setcmd
->doc
[1] == 'e'
242 && setcmd
->doc
[2] == 't' && setcmd
->doc
[3] == ' ')
243 showcmd
->doc
= concat ("Show ", setcmd
->doc
+ 4, NULL
);
245 fprintf (stderr
, "GDB internal error: Bad docstring for set command\n");
247 showcmd
->next
= *list
;
252 /* Remove the command named NAME from the command list. */
255 delete_cmd (name
, list
)
257 struct cmd_list_element
**list
;
259 register struct cmd_list_element
*c
;
260 struct cmd_list_element
*p
;
262 while (*list
&& !strcmp ((*list
)->name
, name
))
270 for (c
= *list
; c
->next
;)
272 if (!strcmp (c
->next
->name
, name
))
283 /* This command really has to deal with two things:
284 * 1) I want documentation on *this string* (usually called by
285 * "help commandname").
286 * 2) I want documentation on *this list* (usually called by
287 * giving a command that requires subcommands. Also called by saying
290 * I am going to split this into two seperate comamnds, help_cmd and
295 help_cmd (command
, stream
)
299 struct cmd_list_element
*c
;
300 extern struct cmd_list_element
*cmdlist
;
304 help_list (cmdlist
, "", all_classes
, stream
);
308 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
313 /* There are three cases here.
314 If c->prefixlist is nonzero, we have a prefix command.
315 Print its documentation, then list its subcommands.
317 If c->function is nonzero, we really have a command.
318 Print its documentation and return.
320 If c->function is zero, we have a class name.
321 Print its documentation (as if it were a command)
322 and then set class to the number of this class
323 so that the commands in the class will be listed. */
325 fputs_filtered (c
->doc
, stream
);
326 fputs_filtered ("\n", stream
);
328 if (c
->prefixlist
== 0 && c
->function
.cfunc
!= NULL
)
330 fprintf_filtered (stream
, "\n");
332 /* If this is a prefix command, print it's subcommands */
334 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
336 /* If this is a class name, print all of the commands in the class */
337 if (c
->function
.cfunc
== NULL
)
338 help_list (cmdlist
, "", c
->class, stream
);
342 * Get a specific kind of help on a command list.
345 * CMDTYPE is the prefix to use in the title string.
346 * CLASS is the class with which to list the nodes of this list (see
347 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
348 * everything, ALL_CLASSES for just classes, and non-negative for only things
349 * in a specific class.
350 * and STREAM is the output stream on which to print things.
351 * If you call this routine with a class >= 0, it recurses.
354 help_list (list
, cmdtype
, class, stream
)
355 struct cmd_list_element
*list
;
357 enum command_class
class;
361 char *cmdtype1
, *cmdtype2
;
363 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
364 len
= strlen (cmdtype
);
365 cmdtype1
= (char *) alloca (len
+ 1);
367 cmdtype2
= (char *) alloca (len
+ 4);
372 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
374 strncpy (cmdtype2
, cmdtype
, len
- 1);
375 strcpy (cmdtype2
+ len
- 1, " sub");
378 if (class == all_classes
)
379 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
381 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
383 help_cmd_list (list
, class, cmdtype
, (int)class >= 0, stream
);
385 if (class == all_classes
)
386 fprintf_filtered (stream
, "\n\
387 Type \"help%s\" followed by a class name for a list of commands in that class.",
390 fprintf_filtered (stream
, "\n\
391 Type \"help%s\" followed by %scommand name for full documentation.\n\
392 Command name abbreviations are allowed if unambiguous.\n",
396 /* Print only the first line of STR on STREAM. */
398 print_doc_line (stream
, str
)
402 static char *line_buffer
= 0;
403 static int line_size
;
409 line_buffer
= (char *) xmalloc (line_size
);
413 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
415 if (p
- str
> line_size
- 1)
417 line_size
= p
- str
+ 1;
419 line_buffer
= (char *) xmalloc (line_size
);
421 strncpy (line_buffer
, str
, p
- str
);
422 line_buffer
[p
- str
] = '\0';
423 if (islower (line_buffer
[0]))
424 line_buffer
[0] = toupper (line_buffer
[0]);
425 fputs_filtered (line_buffer
, stream
);
429 * Implement a help command on command list LIST.
430 * RECURSE should be non-zero if this should be done recursively on
431 * all sublists of LIST.
432 * PREFIX is the prefix to print before each command name.
433 * STREAM is the stream upon which the output should be written.
435 * A non-negative class number to list only commands in that
437 * ALL_COMMANDS to list all commands in list.
438 * ALL_CLASSES to list all classes in list.
440 * Note that RECURSE will be active on *all* sublists, not just the
441 * ones selected by the criteria above (ie. the selection mechanism
442 * is at the low level, not the high-level).
445 help_cmd_list (list
, class, prefix
, recurse
, stream
)
446 struct cmd_list_element
*list
;
447 enum command_class
class;
452 register struct cmd_list_element
*c
;
454 for (c
= list
; c
; c
= c
->next
)
456 if (c
->abbrev_flag
== 0 &&
457 (class == all_commands
458 || (class == all_classes
&& c
->function
.cfunc
== NULL
)
459 || (class == c
->class && c
->function
.cfunc
!= NULL
)))
461 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
462 print_doc_line (stream
, c
->doc
);
463 fputs_filtered ("\n", stream
);
466 && c
->prefixlist
!= 0
467 && c
->abbrev_flag
== 0)
468 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, 1, stream
);
472 /* This routine takes a line of TEXT and a CLIST in which to
473 start the lookup. When it returns it will have incremented the text
474 pointer past the section of text it matched, set *RESULT_LIST to
475 the list in which the last word was matched, and will return the
476 cmd list element which the text matches. It will return 0 if no
477 match at all was possible. It will return -1 if ambigous matches are
478 possible; in this case *RESULT_LIST will be set to the list in which
479 there are ambiguous choices (and text will be set to the ambiguous
482 It does no error reporting whatsoever; control will always return
483 to the superior routine.
485 In the case of an ambiguous return (-1), *RESULT_LIST will be set to
486 point at the prefix_command (ie. the best match) *or* (special
487 case) will be 0 if no prefix command was ever found. For example,
488 in the case of "info a", "info" matches without ambiguity, but "a"
489 could be "args" or "address", so *RESULT_LIST is set to
490 the cmd_list_element for "info". So in this case
491 result list should not be interpeted as a pointer to the beginning
492 of a list; it simply points to a specific command.
494 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
495 affect the operation).
497 This routine does *not* modify the text pointed to by TEXT.
499 If IGNORE_HELP_CLASSES is nonzero, ignore any command list
500 elements which are actually help classes rather than commands (i.e.
501 the function field of the struct cmd_list_element is 0). */
503 struct cmd_list_element
*
504 lookup_cmd_1 (text
, clist
, result_list
, ignore_help_classes
)
506 struct cmd_list_element
*clist
, **result_list
;
507 int ignore_help_classes
;
510 int len
, tmp
, nfound
;
511 struct cmd_list_element
*found
, *c
;
513 while (**text
== ' ' || **text
== '\t')
516 /* Treating underscores as part of command words is important
517 so that "set args_foo()" doesn't get interpreted as
518 "set args _foo()". */
520 *p
&& (isalnum(*p
) || *p
== '-' || *p
== '_');
524 /* If nothing but whitespace, return 0. */
530 /* *text and p now bracket the first command word to lookup (and
531 it's length is len). We copy this into a local temporary,
532 converting to lower case as we go. */
534 command
= (char *) alloca (len
+ 1);
535 for (tmp
= 0; tmp
< len
; tmp
++)
537 char x
= (*text
)[tmp
];
538 command
[tmp
] = (x
>= 'A' && x
<= 'Z') ? x
- 'A' + 'a' : x
;
545 for (c
= clist
; c
; c
= c
->next
)
546 if (!strncmp (command
, c
->name
, len
)
547 && (!ignore_help_classes
|| c
->function
.cfunc
))
551 if (c
->name
[len
] == '\0')
558 /* If nothing matches, we have a simple failure. */
564 if (result_list
!= NULL
)
565 /* Will be modified in calling routine
566 if we know what the prefix command is. */
568 return (struct cmd_list_element
*) -1; /* Ambiguous. */
571 /* We've matched something on this list. Move text pointer forward. */
574 if (found
->prefixlist
)
576 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
577 ignore_help_classes
);
580 /* Didn't find anything; this is as far as we got. */
581 if (result_list
!= NULL
)
582 *result_list
= clist
;
585 else if (c
== (struct cmd_list_element
*) -1)
587 /* We've gotten this far properley, but the next step
588 is ambiguous. We need to set the result list to the best
589 we've found (if an inferior hasn't already set it). */
590 if (result_list
!= NULL
)
592 /* This used to say *result_list = *found->prefixlist
593 If that was correct, need to modify the documentation
594 at the top of this function to clarify what is supposed
596 *result_list
= found
;
607 if (result_list
!= NULL
)
608 *result_list
= clist
;
613 /* All this hair to move the space to the front of cmdtype */
616 undef_cmd_error (cmdtype
, q
)
619 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
627 /* Look up the contents of *LINE as a command in the command list LIST.
628 LIST is a chain of struct cmd_list_element's.
629 If it is found, return the struct cmd_list_element for that command
630 and update *LINE to point after the command name, at the first argument.
631 If not found, call error if ALLOW_UNKNOWN is zero
632 otherwise (or if error returns) return zero.
633 Call error if specified command is ambiguous,
634 unless ALLOW_UNKNOWN is negative.
635 CMDTYPE precedes the word "command" in the error message.
637 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
638 elements which are actually help classes rather than commands (i.e.
639 the function field of the struct cmd_list_element is 0). */
641 struct cmd_list_element
*
642 lookup_cmd (line
, list
, cmdtype
, allow_unknown
, ignore_help_classes
)
644 struct cmd_list_element
*list
;
647 int ignore_help_classes
;
649 struct cmd_list_element
*last_list
= 0;
650 struct cmd_list_element
*c
=
651 lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
652 char *ptr
= (*line
) + strlen (*line
) - 1;
654 /* Clear off trailing whitespace. */
655 while (ptr
>= *line
&& (*ptr
== ' ' || *ptr
== '\t'))
664 error ("Lack of needed %scommand", cmdtype
);
669 while (isalnum(*p
) || *p
== '-')
672 q
= (char *) alloca (p
- *line
+ 1);
673 strncpy (q
, *line
, p
- *line
);
675 undef_cmd_error (cmdtype
, q
);
681 else if (c
== (struct cmd_list_element
*) -1)
683 /* Ambigous. Local values should be off prefixlist or called
685 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
687 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
688 struct cmd_list_element
*local_list
=
689 (last_list
? *(last_list
->prefixlist
) : list
);
691 if (local_allow_unknown
< 0)
694 return last_list
; /* Found something. */
696 return 0; /* Found nothing. */
700 /* Report as error. */
705 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
706 && (*line
)[amb_len
] != '\t');
711 for (c
= local_list
; c
; c
= c
->next
)
712 if (!strncmp (*line
, c
->name
, amb_len
))
714 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int)sizeof ambbuf
)
717 strcat (ambbuf
, ", ");
718 strcat (ambbuf
, c
->name
);
722 strcat (ambbuf
, "..");
726 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype
,
733 /* We've got something. It may still not be what the caller
734 wants (if this command *needs* a subcommand). */
735 while (**line
== ' ' || **line
== '\t')
738 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
739 undef_cmd_error (c
->prefixname
, *line
);
741 /* Seems to be what he wants. Return it. */
748 /* Look up the contents of *LINE as a command in the command list LIST.
749 LIST is a chain of struct cmd_list_element's.
750 If it is found, return the struct cmd_list_element for that command
751 and update *LINE to point after the command name, at the first argument.
752 If not found, call error if ALLOW_UNKNOWN is zero
753 otherwise (or if error returns) return zero.
754 Call error if specified command is ambiguous,
755 unless ALLOW_UNKNOWN is negative.
756 CMDTYPE precedes the word "command" in the error message. */
758 struct cmd_list_element
*
759 lookup_cmd (line
, list
, cmdtype
, allow_unknown
)
761 struct cmd_list_element
*list
;
766 register struct cmd_list_element
*c
, *found
;
772 /* Skip leading whitespace. */
774 while (**line
== ' ' || **line
== '\t')
777 /* Clear out trailing whitespace. */
779 p
= *line
+ strlen (*line
);
780 while (p
!= *line
&& (p
[-1] == ' ' || p
[-1] == '\t'))
784 /* Find end of command name. */
788 || (*p
>= 'a' && *p
<= 'z')
789 || (*p
>= 'A' && *p
<= 'Z')
790 || (*p
>= '0' && *p
<= '9'))
793 /* Look up the command name.
794 If exact match, keep that.
795 Otherwise, take command abbreviated, if unique. Note that (in my
796 opinion) a null string does *not* indicate ambiguity; simply the
797 end of the argument. */
802 error ("Lack of needed %scommand", cmdtype
);
806 /* Copy over to a local buffer, converting to lowercase on the way.
807 This is in case the command being parsed is a subcommand which
808 doesn't match anything, and that's ok. We want the original
809 untouched for the routine of the original command. */
811 processed_cmd
= (char *) alloca (p
- *line
+ 1);
812 for (cmd_len
= 0; cmd_len
< p
- *line
; cmd_len
++)
814 char x
= (*line
)[cmd_len
];
815 if (x
>= 'A' && x
<= 'Z')
816 processed_cmd
[cmd_len
] = x
- 'A' + 'a';
818 processed_cmd
[cmd_len
] = x
;
820 processed_cmd
[cmd_len
] = '\0';
822 /* Check all possibilities in the current command list. */
825 for (c
= list
; c
; c
= c
->next
)
827 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
831 if (c
->name
[cmd_len
] == 0)
839 /* Report error for undefined command name. */
843 if (nfound
> 1 && allow_unknown
>= 0)
846 for (c
= list
; c
; c
= c
->next
)
847 if (!strncmp (processed_cmd
, c
->name
, cmd_len
))
849 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < sizeof ambbuf
)
852 strcat (ambbuf
, ", ");
853 strcat (ambbuf
, c
->name
);
857 strcat (ambbuf
, "..");
861 error ("Ambiguous %scommand \"%s\": %s.", cmdtype
,
862 processed_cmd
, ambbuf
);
864 else if (!allow_unknown
)
865 error ("Undefined %scommand: \"%s\".", cmdtype
, processed_cmd
);
869 /* Skip whitespace before the argument. */
871 while (*p
== ' ' || *p
== '\t') p
++;
874 if (found
->prefixlist
&& *p
)
876 c
= lookup_cmd (line
, *found
->prefixlist
, found
->prefixname
,
877 found
->allow_unknown
);
886 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
888 /* Return a vector of char pointers which point to the different
889 possible completions in LIST of TEXT. */
892 complete_on_cmdlist (list
, text
)
893 struct cmd_list_element
*list
;
896 struct cmd_list_element
*ptr
;
898 int sizeof_matchlist
;
900 int textlen
= strlen (text
);
902 sizeof_matchlist
= 10;
903 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
906 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
907 if (!strncmp (ptr
->name
, text
, textlen
)
909 && (ptr
->function
.cfunc
912 if (matches
== sizeof_matchlist
)
914 sizeof_matchlist
*= 2;
915 matchlist
= (char **) xrealloc ((char *)matchlist
,
920 matchlist
[matches
] = (char *)
921 xmalloc (strlen (ptr
->name
) + 1);
922 strcpy (matchlist
[matches
++], ptr
->name
);
932 matchlist
= (char **) xrealloc ((char *)matchlist
, ((matches
+ 1)
934 matchlist
[matches
] = (char *) 0;
941 parse_binary_operation (arg
)
949 length
= strlen (arg
);
951 while (arg
[length
- 1] == ' ' || arg
[length
- 1] == '\t')
954 if (!strncmp (arg
, "on", length
)
955 || !strncmp (arg
, "1", length
)
956 || !strncmp (arg
, "yes", length
))
959 if (!strncmp (arg
, "off", length
)
960 || !strncmp (arg
, "0", length
)
961 || !strncmp (arg
, "no", length
))
965 error ("\"on\" or \"off\" expected.");
970 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
971 of the argument, and FROM_TTY is nonzero if this command is being entered
972 directly by the user (i.e. these are just like any other
973 command). C is the command list element for the command. */
975 do_setshow_command (arg
, from_tty
, c
)
978 struct cmd_list_element
*c
;
980 if (c
->type
== set_cmd
)
993 new = (char *) xmalloc (strlen (arg
) + 2);
995 while ((ch
= *p
++) != '\000')
999 /* \ at end of argument is used after spaces
1000 so they won't be lost. */
1003 ch
= parse_escape (&p
);
1005 break; /* C loses */
1012 if (*(p
- 1) != '\\')
1015 new = (char *) xrealloc (new, q
- new);
1016 if (*(char **)c
->var
!= NULL
)
1017 free (*(char **)c
->var
);
1018 *(char **) c
->var
= new;
1021 case var_string_noescape
:
1024 if (*(char **)c
->var
!= NULL
)
1025 free (*(char **)c
->var
);
1026 *(char **) c
->var
= savestring (arg
, strlen (arg
));
1030 error_no_arg ("filename to set it to.");
1031 if (*(char **)c
->var
!= NULL
)
1032 free (*(char **)c
->var
);
1033 *(char **)c
->var
= tilde_expand (arg
);
1036 *(int *) c
->var
= parse_binary_operation (arg
);
1040 error_no_arg ("integer to set it to.");
1041 *(int *) c
->var
= parse_and_eval_address (arg
);
1042 if (*(int *) c
->var
== 0)
1043 *(int *) c
->var
= UINT_MAX
;
1047 error_no_arg ("integer to set it to.");
1048 *(int *) c
->var
= parse_and_eval_address (arg
);
1051 error ("gdb internal error: bad var_type in do_setshow_command");
1054 else if (c
->type
== show_cmd
)
1056 /* Print doc minus "show" at start. */
1057 print_doc_line (stdout
, c
->doc
+ 5);
1059 fputs_filtered (" is ", stdout
);
1061 switch (c
->var_type
)
1066 fputs_filtered ("\"", stdout
);
1067 for (p
= *(unsigned char **) c
->var
; *p
!= '\0'; p
++)
1068 printchar (*p
, stdout
, '"');
1069 fputs_filtered ("\"", stdout
);
1072 case var_string_noescape
:
1074 fputs_filtered ("\"", stdout
);
1075 fputs_filtered (*(char **) c
->var
, stdout
);
1076 fputs_filtered ("\"", stdout
);
1079 fputs_filtered (*(int *) c
->var
? "on" : "off", stdout
);
1082 if (*(unsigned int *) c
->var
== UINT_MAX
) {
1083 fputs_filtered ("unlimited", stdout
);
1086 /* else fall through */
1088 fprintf_filtered (stdout
, "%d", *(unsigned int *) c
->var
);
1091 error ("gdb internal error: bad var_type in do_setshow_command");
1093 fputs_filtered (".\n", stdout
);
1096 error ("gdb internal error: bad cmd_type in do_setshow_command");
1097 (*c
->function
.sfunc
) (NULL
, from_tty
, c
);
1100 /* Show all the settings in a list of show commands. */
1103 cmd_show_list (list
, from_tty
, prefix
)
1104 struct cmd_list_element
*list
;
1108 for (; list
!= NULL
; list
= list
->next
) {
1109 /* If we find a prefix, run its list, prefixing our output by its
1110 prefix (with "show " skipped). */
1111 if (list
->prefixlist
&& !list
->abbrev_flag
)
1112 cmd_show_list (*list
->prefixlist
, from_tty
, list
->prefixname
+ 5);
1113 if (list
->type
== show_cmd
)
1115 fputs_filtered (prefix
, stdout
);
1116 fputs_filtered (list
->name
, stdout
);
1117 fputs_filtered (": ", stdout
);
1118 do_setshow_command ((char *)NULL
, from_tty
, list
);
1125 shell_escape (arg
, from_tty
)
1129 int rc
, status
, pid
;
1130 char *p
, *user_shell
;
1132 if ((user_shell
= (char *) getenv ("SHELL")) == NULL
)
1133 user_shell
= "/bin/sh";
1135 /* Get the name of the shell for arg0 */
1136 if ((p
= strrchr (user_shell
, '/')) == NULL
)
1139 p
++; /* Get past '/' */
1141 if ((pid
= fork()) == 0)
1144 execl (user_shell
, p
, 0);
1146 execl (user_shell
, p
, "-c", arg
, 0);
1148 fprintf (stderr
, "Exec of shell failed\n");
1153 while ((rc
= wait (&status
)) != pid
&& rc
!= -1)
1156 error ("Fork failed");
1160 make_command (arg
, from_tty
)
1170 p
= xmalloc (sizeof("make ") + strlen(arg
));
1171 strcpy (p
, "make ");
1172 strcpy (p
+ sizeof("make ")-1, arg
);
1175 shell_escape (p
, from_tty
);
1179 show_user_1 (c
, stream
)
1180 struct cmd_list_element
*c
;
1183 register struct command_line
*cmdlines
;
1185 cmdlines
= c
->user_commands
;
1188 fprintf_filtered (stream
, "User command %s:\n", c
->name
);
1191 fprintf_filtered (stream
, "%s\n", cmdlines
->line
);
1192 cmdlines
= cmdlines
->next
;
1194 fputs_filtered ("\n", stream
);
1199 show_user (args
, from_tty
)
1203 struct cmd_list_element
*c
;
1204 extern struct cmd_list_element
*cmdlist
;
1208 c
= lookup_cmd (&args
, cmdlist
, "", 0, 1);
1209 if (c
->class != class_user
)
1210 error ("Not a user command.");
1211 show_user_1 (c
, stdout
);
1215 for (c
= cmdlist
; c
; c
= c
->next
)
1217 if (c
->class == class_user
)
1218 show_user_1 (c
, stdout
);
1224 _initialize_command ()
1226 add_com ("shell", class_support
, shell_escape
,
1227 "Execute the rest of the line as a shell command. \n\
1228 With no arguments, run an inferior shell.");
1230 add_com ("make", class_support
, make_command
,
1231 "Run the ``make'' program using the rest of the line as arguments.");
1233 add_cmd ("user", no_class
, show_user
,
1234 "Show definitions of user defined commands.\n\
1235 Argument is the name of the user defined command.\n\
1236 With no argument, show definitions of all user defined commands.", &showlist
);