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 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 start the
475 lookup. When it returns it will have incremented the text pointer past
476 the section of text it matched, set *RESULT_LIST to point to the list in
477 which the last word was matched, and will return a pointer to the cmd
478 list element which the text matches. It will return NULL if no match at
479 all was possible. It will return -1 (cast appropriately, ick) if ambigous
480 matches are possible; in this case *RESULT_LIST will be set to point to
481 the list in which there are ambiguous choices (and *TEXT will be set to
482 the ambiguous text string).
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 point
488 at the prefix_command (ie. the best match) *or* (special case) will be NULL
489 if no prefix command was ever found. For example, in the case of "info a",
490 "info" matches without ambiguity, but "a" could be "args" or "address", so
491 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
492 RESULT_LIST should not be interpeted as a pointer to the beginning of a
493 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 elements which
501 are actually help classes rather than commands (i.e. the function field of
502 the struct cmd_list_element is NULL). */
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] = isupper(x) ? tolower(x) : 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. */
788 while (*p == '-' || isalnum(*p))
791 /* Look up the command name.
792 If exact match, keep that.
793 Otherwise, take command abbreviated, if unique. Note that (in my
794 opinion) a null string does *not* indicate ambiguity; simply the
795 end of the argument. */
800 error ("Lack of needed %scommand", cmdtype);
804 /* Copy over to a local buffer, converting to lowercase on the way.
805 This is in case the command being parsed is a subcommand which
806 doesn't match anything, and that's ok. We want the original
807 untouched for the routine of the original command. */
809 processed_cmd = (char *) alloca (p - *line + 1);
810 for (cmd_len = 0; cmd_len < p - *line; cmd_len++)
812 char x = (*line)[cmd_len];
814 processed_cmd[cmd_len] = tolower(x);
816 processed_cmd[cmd_len] = x;
818 processed_cmd[cmd_len] = '\0';
820 /* Check all possibilities in the current command list. */
823 for (c = list; c; c = c->next)
825 if (!strncmp (processed_cmd, c->name, cmd_len))
829 if (c->name[cmd_len] == 0)
837 /* Report error for undefined command name. */
841 if (nfound > 1 && allow_unknown >= 0)
844 for (c = list; c; c = c->next)
845 if (!strncmp (processed_cmd, c->name, cmd_len))
847 if (strlen (ambbuf) + strlen (c->name) + 6 < sizeof ambbuf)
850 strcat (ambbuf, ", ");
851 strcat (ambbuf, c->name);
855 strcat (ambbuf, "..");
859 error ("Ambiguous %scommand \"%s\": %s.", cmdtype,
860 processed_cmd, ambbuf);
862 else if (!allow_unknown)
863 error ("Undefined %scommand: \"%s\".", cmdtype, processed_cmd);
867 /* Skip whitespace before the argument. */
869 while (*p == ' ' || *p == '\t') p++;
872 if (found->prefixlist && *p)
874 c = lookup_cmd (line, *found->prefixlist, found->prefixname,
875 found->allow_unknown);
884 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
886 /* Return a vector of char pointers which point to the different
887 possible completions in LIST of TEXT. */
890 complete_on_cmdlist (list, text)
891 struct cmd_list_element *list;
894 struct cmd_list_element *ptr;
896 int sizeof_matchlist;
898 int textlen = strlen (text);
900 sizeof_matchlist = 10;
901 matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
904 for (ptr = list; ptr; ptr = ptr->next)
905 if (!strncmp (ptr->name, text, textlen)
907 && (ptr->function.cfunc
910 if (matches == sizeof_matchlist)
912 sizeof_matchlist *= 2;
913 matchlist = (char **) xrealloc ((char *)matchlist,
918 matchlist[matches] = (char *)
919 xmalloc (strlen (ptr->name) + 1);
920 strcpy (matchlist[matches++], ptr->name);
925 free ((PTR)matchlist);
930 matchlist = (char **) xrealloc ((char *)matchlist, ((matches + 1)
932 matchlist[matches] = (char *) 0;
939 parse_binary_operation (arg)
947 length = strlen (arg);
949 while (arg[length - 1] == ' ' || arg[length - 1] == '\t')
952 if (!strncmp (arg, "on", length)
953 || !strncmp (arg, "1", length)
954 || !strncmp (arg, "yes", length))
957 if (!strncmp (arg, "off", length)
958 || !strncmp (arg, "0", length)
959 || !strncmp (arg, "no", length))
963 error ("\"on\" or \"off\" expected.");
968 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
969 of the argument, and FROM_TTY is nonzero if this command is being entered
970 directly by the user (i.e. these are just like any other
971 command). C is the command list element for the command. */
973 do_setshow_command (arg, from_tty, c)
976 struct cmd_list_element *c;
978 if (c->type == set_cmd)
991 new = (char *) xmalloc (strlen (arg) + 2);
993 while ((ch = *p++) != '\000')
997 /* \ at end of argument is used after spaces
998 so they won't be lost. */
1001 ch = parse_escape (&p);
1003 break; /* C loses */
1010 if (*(p - 1) != '\\')
1013 new = (char *) xrealloc (new, q - new);
1014 if (*(char **)c->var != NULL)
1015 free (*(char **)c->var);
1016 *(char **) c->var = new;
1019 case var_string_noescape:
1022 if (*(char **)c->var != NULL)
1023 free (*(char **)c->var);
1024 *(char **) c->var = savestring (arg, strlen (arg));
1028 error_no_arg ("filename to set it to.");
1029 if (*(char **)c->var != NULL)
1030 free (*(char **)c->var);
1031 *(char **)c->var = tilde_expand (arg);
1034 *(int *) c->var = parse_binary_operation (arg);
1038 error_no_arg ("integer to set it to.");
1039 *(int *) c->var = parse_and_eval_address (arg);
1040 if (*(int *) c->var == 0)
1041 *(int *) c->var = UINT_MAX;
1045 error_no_arg ("integer to set it to.");
1046 *(int *) c->var = parse_and_eval_address (arg);
1049 error ("gdb internal error: bad var_type in do_setshow_command");
1052 else if (c->type == show_cmd)
1054 /* Print doc minus "show" at start. */
1055 print_doc_line (stdout, c->doc + 5);
1057 fputs_filtered (" is ", stdout);
1059 switch (c->var_type)
1064 fputs_filtered ("\"", stdout);
1065 for (p = *(unsigned char **) c->var; *p != '\0'; p++)
1066 printchar (*p, stdout, '"');
1067 fputs_filtered ("\"", stdout);
1070 case var_string_noescape:
1072 fputs_filtered ("\"", stdout);
1073 fputs_filtered (*(char **) c->var, stdout);
1074 fputs_filtered ("\"", stdout);
1077 fputs_filtered (*(int *) c->var ? "on" : "off", stdout);
1080 if (*(unsigned int *) c->var == UINT_MAX) {
1081 fputs_filtered ("unlimited", stdout);
1084 /* else fall through */
1086 fprintf_filtered (stdout, "%d", *(unsigned int *) c->var);
1089 error ("gdb internal error: bad var_type in do_setshow_command");
1091 fputs_filtered (".\n", stdout);
1094 error ("gdb internal error: bad cmd_type in do_setshow_command");
1095 (*c->function.sfunc) (NULL, from_tty, c);
1098 /* Show all the settings in a list of show commands. */
1101 cmd_show_list (list, from_tty, prefix)
1102 struct cmd_list_element *list;
1106 for (; list != NULL; list = list->next) {
1107 /* If we find a prefix, run its list, prefixing our output by its
1108 prefix (with "show " skipped). */
1109 if (list->prefixlist && !list->abbrev_flag)
1110 cmd_show_list (*list->prefixlist, from_tty, list->prefixname + 5);
1111 if (list->type == show_cmd)
1113 fputs_filtered (prefix, stdout);
1114 fputs_filtered (list->name, stdout);
1115 fputs_filtered (": ", stdout);
1116 do_setshow_command ((char *)NULL, from_tty, list);
1123 shell_escape (arg, from_tty)
1127 int rc, status, pid;
1128 char *p, *user_shell;
1130 if ((user_shell = (char *) getenv ("SHELL")) == NULL)
1131 user_shell = "/bin/sh";
1133 /* Get the name of the shell for arg0 */
1134 if ((p = strrchr (user_shell, '/')) == NULL)
1137 p++; /* Get past '/' */
1139 if ((pid = fork()) == 0)
1142 execl (user_shell, p, 0);
1144 execl (user_shell, p, "-c", arg, 0);
1146 fprintf (stderr, "Exec of shell failed\n");
1151 while ((rc = wait (&status)) != pid && rc != -1)
1154 error ("Fork failed");
1158 make_command (arg, from_tty)
1168 p = xmalloc (sizeof("make ") + strlen(arg));
1169 strcpy (p, "make ");
1170 strcpy (p + sizeof("make ")-1, arg);
1173 shell_escape (p, from_tty);
1177 show_user_1 (c, stream)
1178 struct cmd_list_element *c;
1181 register struct command_line *cmdlines;
1183 cmdlines = c->user_commands;
1186 fprintf_filtered (stream, "User command %s:\n", c->name);
1189 fprintf_filtered (stream, "%s\n", cmdlines->line);
1190 cmdlines = cmdlines->next;
1192 fputs_filtered ("\n", stream);
1197 show_user (args, from_tty)
1201 struct cmd_list_element *c;
1202 extern struct cmd_list_element *cmdlist;
1206 c = lookup_cmd (&args, cmdlist, "", 0, 1);
1207 if (c->class != class_user)
1208 error ("Not a user command.");
1209 show_user_1 (c, stdout);
1213 for (c = cmdlist; c; c = c->next)
1215 if (c->class == class_user)
1216 show_user_1 (c, stdout);
1222 _initialize_command ()
1224 add_com ("shell", class_support, shell_escape,
1225 "Execute the rest of the line as a shell command. \n\
1226 With no arguments, run an inferior shell.");
1228 add_com ("make", class_support, make_command,
1229 "Run the ``make'' program using the rest of the line as arguments.");
1231 add_cmd ("user", no_class, show_user,
1232 "Show definitions of user defined commands.\n\
1233 Argument is the name of the user defined command.\n\
1234 With no argument, show definitions of all user defined commands.", &showlist);