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 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 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;
165 not_just_help_class_command (args, from_tty, c)
168 struct cmd_list_element *c;
172 /* Add element named NAME to command list LIST (the list for set
173 or some sublist thereof).
174 CLASS is as in add_cmd.
175 VAR_TYPE is the kind of thing we are setting.
176 VAR is address of the variable being controlled by this command.
177 DOC is the documentation string. */
178 struct cmd_list_element *
179 add_set_cmd (name, class, var_type, var, doc, list)
181 enum command_class class;
185 struct cmd_list_element **list;
187 /* For set/show, we have to call do_setshow_command
188 differently than an ordinary function (take commandlist as
189 well as arg), so the function field isn't helpful. However,
190 function == NULL means that it's a help class, so set the function
191 to not_just_help_class_command. */
192 struct cmd_list_element *c
193 = add_cmd (name, class, not_just_help_class_command, doc, list);
196 c->var_type = var_type;
201 /* Where SETCMD has already been added, add the corresponding show
202 command to LIST and return a pointer to it. */
203 struct cmd_list_element *
204 add_show_from_set (setcmd, list)
205 struct cmd_list_element *setcmd;
206 struct cmd_list_element **list;
208 struct cmd_list_element *showcmd =
209 (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
211 bcopy (setcmd, showcmd, sizeof (struct cmd_list_element));
212 delete_cmd (showcmd->name, list);
213 showcmd->type = show_cmd;
215 /* Replace "set " at start of docstring with "show ". */
216 if (setcmd->doc[0] == 'S' && setcmd->doc[1] == 'e'
217 && setcmd->doc[2] == 't' && setcmd->doc[3] == ' ')
218 showcmd->doc = concat ("Show ", setcmd->doc + 4, "");
220 fprintf (stderr, "GDB internal error: Bad docstring for set command\n");
222 showcmd->next = *list;
227 /* Remove the command named NAME from the command list. */
230 delete_cmd (name, list)
232 struct cmd_list_element **list;
234 register struct cmd_list_element *c;
235 struct cmd_list_element *p;
237 while (*list && !strcmp ((*list)->name, name))
245 for (c = *list; c->next;)
247 if (!strcmp (c->next->name, name))
258 /* This command really has to deal with two things:
259 * 1) I want documentation on *this string* (usually called by
260 * "help commandname").
261 * 2) I want documentation on *this list* (usually called by
262 * giving a command that requires subcommands. Also called by saying
265 * I am going to split this into two seperate comamnds, help_cmd and
270 help_cmd (command, stream)
274 struct cmd_list_element *c;
275 extern struct cmd_list_element *cmdlist;
279 help_list (cmdlist, "", all_classes, stream);
283 c = lookup_cmd (&command, cmdlist, "", 0, 0);
288 /* There are three cases here.
289 If c->prefixlist is nonzero, we have a prefix command.
290 Print its documentation, then list its subcommands.
292 If c->function is nonzero, we really have a command.
293 Print its documentation and return.
295 If c->function is zero, we have a class name.
296 Print its documentation (as if it were a command)
297 and then set class to the number of this class
298 so that the commands in the class will be listed. */
300 fputs_filtered (c->doc, stream);
301 fputs_filtered ("\n", stream);
303 if (c->prefixlist == 0 && c->function != 0)
305 fprintf_filtered (stream, "\n");
307 /* If this is a prefix command, print it's subcommands */
309 help_list (*c->prefixlist, c->prefixname, all_commands, stream);
311 /* If this is a class name, print all of the commands in the class */
312 if (c->function == 0)
313 help_list (cmdlist, "", c->class, stream);
317 * Get a specific kind of help on a command list.
320 * CMDTYPE is the prefix to use in the title string.
321 * CLASS is the class with which to list the nodes of this list (see
322 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
323 * everything, ALL_CLASSES for just classes, and non-negative for only things
324 * in a specific class.
325 * and STREAM is the output stream on which to print things.
326 * If you call this routine with a class >= 0, it recurses.
329 help_list (list, cmdtype, class, stream)
330 struct cmd_list_element *list;
332 enum command_class class;
336 char *cmdtype1, *cmdtype2;
338 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
339 len = strlen (cmdtype);
340 cmdtype1 = (char *) alloca (len + 1);
342 cmdtype2 = (char *) alloca (len + 4);
347 strncpy (cmdtype1 + 1, cmdtype, len - 1);
349 strncpy (cmdtype2, cmdtype, len - 1);
350 strcpy (cmdtype2 + len - 1, " sub");
353 if (class == all_classes)
354 fprintf_filtered (stream, "List of classes of %scommands:\n\n", cmdtype2);
356 fprintf_filtered (stream, "List of %scommands:\n\n", cmdtype2);
358 help_cmd_list (list, class, cmdtype, (int)class >= 0, stream);
360 if (class == all_classes)
361 fprintf_filtered (stream, "\n\
362 Type \"help%s\" followed by a class name for a list of commands in that class.",
365 fprintf_filtered (stream, "\n\
366 Type \"help%s\" followed by %scommand name for full documentation.\n\
367 Command name abbreviations are allowed if unambiguous.\n",
371 /* Print only the first line of STR on STREAM. */
373 print_doc_line (stream, str)
377 static char *line_buffer = 0;
378 static int line_size;
384 line_buffer = (char *) xmalloc (line_size);
388 while (*p && *p != '\n' && *p != '.' && *p != ',')
390 if (p - str > line_size - 1)
392 line_size = p - str + 1;
394 line_buffer = (char *) xmalloc (line_size);
396 strncpy (line_buffer, str, p - str);
397 line_buffer[p - str] = '\0';
398 if (islower (line_buffer[0]))
399 line_buffer[0] = toupper (line_buffer[0]);
400 fputs_filtered (line_buffer, stream);
404 * Implement a help command on command list LIST.
405 * RECURSE should be non-zero if this should be done recursively on
406 * all sublists of LIST.
407 * PREFIX is the prefix to print before each command name.
408 * STREAM is the stream upon which the output should be written.
410 * A non-negative class number to list only commands in that
412 * ALL_COMMANDS to list all commands in list.
413 * ALL_CLASSES to list all classes in list.
415 * Note that RECURSE will be active on *all* sublists, not just the
416 * ones seclected by the criteria above (ie. the selection mechanism
417 * is at the low level, not the high-level).
420 help_cmd_list (list, class, prefix, recurse, stream)
421 struct cmd_list_element *list;
422 enum command_class class;
427 register struct cmd_list_element *c;
429 for (c = list; c; c = c->next)
431 if (c->abbrev_flag == 0 &&
432 (class == all_commands
433 || (class == all_classes && c->function == 0)
434 || (class == c->class && c->function != 0)))
436 fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
437 print_doc_line (stream, c->doc);
438 fputs_filtered ("\n", stream);
441 && c->prefixlist != 0
442 && c->abbrev_flag == 0)
443 help_cmd_list (*c->prefixlist, class, c->prefixname, 1, stream);
447 /* This routine takes a line of TEXT and a CLIST in which to
448 start the lookup. When it returns it will have incremented the text
449 pointer past the section of text it matched, set *RESULT_LIST to
450 the list in which the last word was matched, and will return the
451 cmd list element which the text matches. It will return 0 if no
452 match at all was possible. It will return -1 if ambigous matches are
453 possible; in this case *RESULT_LIST will be set to the list in which
454 there are ambiguous choices (and text will be set to the ambiguous
457 It does no error reporting whatsoever; control will always return
458 to the superior routine.
460 In the case of an ambiguous return (-1), *RESULT_LIST will be set to
461 point at the prefix_command (ie. the best match) *or* (special
462 case) will be 0 if no prefix command was ever found. For example,
463 in the case of "info a", "info" matches without ambiguity, but "a"
464 could be "args" or "address", so *RESULT_LIST is set to
465 the cmd_list_element for "info". So in this case
466 result list should not be interpeted as a pointer to the beginning
467 of a list; it simply points to a specific command.
469 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
470 affect the operation).
472 This routine does *not* modify the text pointed to by TEXT.
474 If IGNORE_HELP_CLASSES is nonzero, ignore any command list
475 elements which are actually help classes rather than commands (i.e.
476 the function field of the struct cmd_list_element is 0). */
478 struct cmd_list_element *
479 lookup_cmd_1 (text, clist, result_list, ignore_help_classes)
481 struct cmd_list_element *clist, **result_list;
482 int ignore_help_classes;
485 int len, tmp, nfound;
486 struct cmd_list_element *found, *c;
488 while (**text == ' ' || **text == '\t')
491 /* Treating underscores as part of command words is important
492 so that "set args_foo()" doesn't get interpreted as
493 "set args _foo()". */
495 *p && (isalnum(*p) || *p == '-' || *p == '_');
499 /* If nothing but whitespace, return 0. */
505 /* *text and p now bracket the first command word to lookup (and
506 it's length is len). We copy this into a local temporary,
507 converting to lower case as we go. */
509 command = (char *) alloca (len + 1);
510 for (tmp = 0; tmp < len; tmp++)
512 char x = (*text)[tmp];
513 command[tmp] = (x >= 'A' && x <= 'Z') ? x - 'A' + 'a' : x;
520 for (c = clist; c; c = c->next)
521 if (!strncmp (command, c->name, len)
522 && (!ignore_help_classes || c->function))
526 if (c->name[len] == '\0')
533 /* If nothing matches, we have a simple failure. */
539 if (result_list != NULL)
540 /* Will be modified in calling routine
541 if we know what the prefix command is. */
543 return (struct cmd_list_element *) -1; /* Ambiguous. */
546 /* We've matched something on this list. Move text pointer forward. */
549 if (found->prefixlist)
551 c = lookup_cmd_1 (text, *found->prefixlist, result_list,
552 ignore_help_classes);
555 /* Didn't find anything; this is as far as we got. */
556 if (result_list != NULL)
557 *result_list = clist;
560 else if (c == (struct cmd_list_element *) -1)
562 /* We've gotten this far properley, but the next step
563 is ambiguous. We need to set the result list to the best
564 we've found (if an inferior hasn't already set it). */
565 if (result_list != NULL)
567 /* This used to say *result_list = *found->prefixlist
568 If that was correct, need to modify the documentation
569 at the top of this function to clarify what is supposed
571 *result_list = found;
582 if (result_list != NULL)
583 *result_list = clist;
588 /* Look up the contents of *LINE as a command in the command list LIST.
589 LIST is a chain of struct cmd_list_element's.
590 If it is found, return the struct cmd_list_element for that command
591 and update *LINE to point after the command name, at the first argument.
592 If not found, call error if ALLOW_UNKNOWN is zero
593 otherwise (or if error returns) return zero.
594 Call error if specified command is ambiguous,
595 unless ALLOW_UNKNOWN is negative.
596 CMDTYPE precedes the word "command" in the error message.
598 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
599 elements which are actually help classes rather than commands (i.e.
600 the function field of the struct cmd_list_element is 0). */
602 struct cmd_list_element *
603 lookup_cmd (line, list, cmdtype, allow_unknown, ignore_help_classes)
605 struct cmd_list_element *list;
608 int ignore_help_classes;
610 struct cmd_list_element *last_list = 0;
611 struct cmd_list_element *c =
612 lookup_cmd_1 (line, list, &last_list, ignore_help_classes);
613 char *ptr = (*line) + strlen (*line) - 1;
615 /* Clear off trailing whitespace. */
616 while (ptr >= *line && (*ptr == ' ' || *ptr == '\t'))
625 error ("Lack of needed %scommand", cmdtype);
630 while (isalnum(*p) || *p == '-')
633 q = (char *) alloca (p - *line + 1);
634 strncpy (q, *line, p - *line);
637 error ("Undefined %scommand: \"%s\".", cmdtype, q);
643 else if (c == (struct cmd_list_element *) -1)
645 /* Ambigous. Local values should be off prefixlist or called
647 int local_allow_unknown = (last_list ? last_list->allow_unknown :
649 char *local_cmdtype = last_list ? last_list->prefixname : cmdtype;
650 struct cmd_list_element *local_list =
651 (last_list ? *(last_list->prefixlist) : list);
653 if (local_allow_unknown < 0)
656 return last_list; /* Found something. */
658 return 0; /* Found nothing. */
662 /* Report as error. */
667 ((*line)[amb_len] && (*line)[amb_len] != ' '
668 && (*line)[amb_len] != '\t');
673 for (c = local_list; c; c = c->next)
674 if (!strncmp (*line, c->name, amb_len))
676 if (strlen (ambbuf) + strlen (c->name) + 6 < (int)sizeof ambbuf)
679 strcat (ambbuf, ", ");
680 strcat (ambbuf, c->name);
684 strcat (ambbuf, "..");
688 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype,
695 /* We've got something. It may still not be what the caller
696 wants (if this command *needs* a subcommand). */
697 while (**line == ' ' || **line == '\t')
700 if (c->prefixlist && **line && !c->allow_unknown)
701 error ("Undefined %scommand: \"%s\".", c->prefixname, *line);
703 /* Seems to be what he wants. Return it. */
710 /* Look up the contents of *LINE as a command in the command list LIST.
711 LIST is a chain of struct cmd_list_element's.
712 If it is found, return the struct cmd_list_element for that command
713 and update *LINE to point after the command name, at the first argument.
714 If not found, call error if ALLOW_UNKNOWN is zero
715 otherwise (or if error returns) return zero.
716 Call error if specified command is ambiguous,
717 unless ALLOW_UNKNOWN is negative.
718 CMDTYPE precedes the word "command" in the error message. */
720 struct cmd_list_element *
721 lookup_cmd (line, list, cmdtype, allow_unknown)
723 struct cmd_list_element *list;
728 register struct cmd_list_element *c, *found;
734 /* Skip leading whitespace. */
736 while (**line == ' ' || **line == '\t')
739 /* Clear out trailing whitespace. */
741 p = *line + strlen (*line);
742 while (p != *line && (p[-1] == ' ' || p[-1] == '\t'))
746 /* Find end of command name. */
750 || (*p >= 'a' && *p <= 'z')
751 || (*p >= 'A' && *p <= 'Z')
752 || (*p >= '0' && *p <= '9'))
755 /* Look up the command name.
756 If exact match, keep that.
757 Otherwise, take command abbreviated, if unique. Note that (in my
758 opinion) a null string does *not* indicate ambiguity; simply the
759 end of the argument. */
764 error ("Lack of needed %scommand", cmdtype);
768 /* Copy over to a local buffer, converting to lowercase on the way.
769 This is in case the command being parsed is a subcommand which
770 doesn't match anything, and that's ok. We want the original
771 untouched for the routine of the original command. */
773 processed_cmd = (char *) alloca (p - *line + 1);
774 for (cmd_len = 0; cmd_len < p - *line; cmd_len++)
776 char x = (*line)[cmd_len];
777 if (x >= 'A' && x <= 'Z')
778 processed_cmd[cmd_len] = x - 'A' + 'a';
780 processed_cmd[cmd_len] = x;
782 processed_cmd[cmd_len] = '\0';
784 /* Check all possibilities in the current command list. */
787 for (c = list; c; c = c->next)
789 if (!strncmp (processed_cmd, c->name, cmd_len))
793 if (c->name[cmd_len] == 0)
801 /* Report error for undefined command name. */
805 if (nfound > 1 && allow_unknown >= 0)
808 for (c = list; c; c = c->next)
809 if (!strncmp (processed_cmd, c->name, cmd_len))
811 if (strlen (ambbuf) + strlen (c->name) + 6 < sizeof ambbuf)
814 strcat (ambbuf, ", ");
815 strcat (ambbuf, c->name);
819 strcat (ambbuf, "..");
823 error ("Ambiguous %scommand \"%s\": %s.", cmdtype,
824 processed_cmd, ambbuf);
826 else if (!allow_unknown)
827 error ("Undefined %scommand: \"%s\".", cmdtype, processed_cmd);
831 /* Skip whitespace before the argument. */
833 while (*p == ' ' || *p == '\t') p++;
836 if (found->prefixlist && *p)
838 c = lookup_cmd (line, *found->prefixlist, found->prefixname,
839 found->allow_unknown);
848 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
850 /* Return a vector of char pointers which point to the different
851 possible completions in LIST of TEXT. */
854 complete_on_cmdlist (list, text)
855 struct cmd_list_element *list;
858 struct cmd_list_element *ptr;
860 int sizeof_matchlist;
862 int textlen = strlen (text);
864 sizeof_matchlist = 10;
865 matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
868 for (ptr = list; ptr; ptr = ptr->next)
869 if (!strncmp (ptr->name, text, textlen)
874 if (matches == sizeof_matchlist)
876 sizeof_matchlist *= 2;
877 matchlist = (char **) xrealloc ((char *)matchlist,
882 matchlist[matches] = (char *)
883 xmalloc (strlen (ptr->name) + 1);
884 strcpy (matchlist[matches++], ptr->name);
894 matchlist = (char **) xrealloc ((char *)matchlist, ((matches + 1)
896 matchlist[matches] = (char *) 0;
903 parse_binary_operation (arg)
911 length = strlen (arg);
913 while (arg[length - 1] == ' ' || arg[length - 1] == '\t')
916 if (!strncmp (arg, "on", length)
917 || !strncmp (arg, "1", length)
918 || !strncmp (arg, "yes", length))
921 if (!strncmp (arg, "off", length)
922 || !strncmp (arg, "0", length)
923 || !strncmp (arg, "no", length))
927 error ("\"on\" or \"off\" expected.");
932 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
933 of the argument, and FROM_TTY is nonzero if this command is being entered
934 directly by the user (i.e. these are just like any other
935 command). C is the command list element for the command. */
937 do_setshow_command (arg, from_tty, c)
940 struct cmd_list_element *c;
942 if (c->type == set_cmd)
955 new = (char *) xmalloc (strlen (arg) + 2);
961 /* \ at end of argument is used after spaces
962 so they won't be lost. */
965 ch = parse_escape (&p);
974 if (*(p - 1) != '\\')
977 new = (char *) xrealloc (new, q - new);
978 if (*(char **)c->var != NULL)
979 free (*(char **)c->var);
980 *(char **) c->var = new;
983 case var_string_noescape:
986 if (*(char **)c->var != NULL)
987 free (*(char **)c->var);
988 *(char **) c->var = savestring (arg, strlen (arg));
992 error_no_arg ("filename to set it to.");
993 if (*(char **)c->var != NULL)
994 free (*(char **)c->var);
995 *(char **)c->var = tilde_expand (arg);
998 *(int *) c->var = parse_binary_operation (arg);
1002 error_no_arg ("integer to set it to.");
1003 *(int *) c->var = parse_and_eval_address (arg);
1004 if (*(int *) c->var == 0)
1005 *(int *) c->var = UINT_MAX;
1009 error_no_arg ("integer to set it to.");
1010 *(int *) c->var = parse_and_eval_address (arg);
1013 error ("gdb internal error: bad var_type in do_setshow_command");
1016 else if (c->type == show_cmd)
1018 /* Print doc minus "show" at start. */
1019 print_doc_line (stdout, c->doc + 5);
1021 fputs_filtered (" is ", stdout);
1023 switch (c->var_type)
1028 fputs_filtered ("\"", stdout);
1029 for (p = *(unsigned char **) c->var; *p != '\0'; p++)
1030 printchar (*p, stdout, '"');
1031 fputs_filtered ("\"", stdout);
1034 case var_string_noescape:
1036 fputs_filtered ("\"", stdout);
1037 fputs_filtered (*(char **) c->var, stdout);
1038 fputs_filtered ("\"", stdout);
1041 fputs_filtered (*(int *) c->var ? "on" : "off", stdout);
1044 if (*(unsigned int *) c->var == UINT_MAX) {
1045 fputs_filtered ("unlimited", stdout);
1048 /* else fall through */
1050 fprintf_filtered (stdout, "%d", *(unsigned int *) c->var);
1053 error ("gdb internal error: bad var_type in do_setshow_command");
1055 fputs_filtered (".\n", stdout);
1058 error ("gdb internal error: bad cmd_type in do_setshow_command");
1059 (*c->function) (NULL, from_tty, c);
1062 /* Show all the settings in a list of show commands. */
1065 cmd_show_list (list, from_tty, prefix)
1066 struct cmd_list_element *list;
1070 for (; list != NULL; list = list->next) {
1071 /* If we find a prefix, run its list, prefixing our output by its
1072 prefix (with "show " skipped). */
1073 if (list->prefixlist && !list->abbrev_flag)
1074 cmd_show_list (*list->prefixlist, from_tty, list->prefixname + 5);
1075 if (list->type == show_cmd)
1077 fputs_filtered (prefix, stdout);
1078 fputs_filtered (list->name, stdout);
1079 fputs_filtered (": ", stdout);
1080 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.");