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;
82 c->type = not_set_cmd;
83 c->completer = make_symbol_completion_list;
85 c->var_type = var_boolean;
91 /* Same as above, except that the abbrev_flag is set. */
93 #if 0 /* Currently unused */
95 struct cmd_list_element *
96 add_abbrev_cmd (name, class, fun, doc, list)
98 enum command_class class;
99 void (*fun) PARAMS ((char *, int));
101 struct cmd_list_element **list;
103 register struct cmd_list_element *c
104 = add_cmd (name, class, fun, doc, list);
112 struct cmd_list_element *
113 add_alias_cmd (name, oldname, class, abbrev_flag, list)
116 enum command_class class;
118 struct cmd_list_element **list;
120 /* Must do this since lookup_cmd tries to side-effect its first arg */
122 register struct cmd_list_element *old;
123 register struct cmd_list_element *c;
124 copied_name = (char *) alloca (strlen (oldname) + 1);
125 strcpy (copied_name, oldname);
126 old = lookup_cmd (&copied_name, *list, "", 1, 1);
130 delete_cmd (name, list);
134 c = add_cmd (name, class, old->function.cfunc, old->doc, list);
135 c->prefixlist = old->prefixlist;
136 c->prefixname = old->prefixname;
137 c->allow_unknown = old->allow_unknown;
138 c->abbrev_flag = abbrev_flag;
139 c->cmd_pointer = old;
143 /* Like add_cmd but adds an element for a command prefix:
144 a name that should be followed by a subcommand to be looked up
145 in another command list. PREFIXLIST should be the address
146 of the variable containing that list. */
148 struct cmd_list_element *
149 add_prefix_cmd (name, class, fun, doc, prefixlist, prefixname,
152 enum command_class class;
153 void (*fun) PARAMS ((char *, int));
155 struct cmd_list_element **prefixlist;
158 struct cmd_list_element **list;
160 register struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);
161 c->prefixlist = prefixlist;
162 c->prefixname = prefixname;
163 c->allow_unknown = allow_unknown;
167 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
169 struct cmd_list_element *
170 add_abbrev_prefix_cmd (name, class, fun, doc, prefixlist, prefixname,
173 enum command_class class;
174 void (*fun) PARAMS ((char *, int));
176 struct cmd_list_element **prefixlist;
179 struct cmd_list_element **list;
181 register struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);
182 c->prefixlist = prefixlist;
183 c->prefixname = prefixname;
184 c->allow_unknown = allow_unknown;
191 not_just_help_class_command (args, from_tty)
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 memcpy (showcmd, setcmd, 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 && STREQ ((*list)->name, name))
266 (*list)->hookee->hook = 0; /* Hook slips out of its mouth */
273 for (c = *list; c->next;)
275 if (STREQ (c->next->name, name))
278 c->next->hookee->hook = 0; /* hooked cmd gets away. */
288 /* This command really has to deal with two things:
289 * 1) I want documentation on *this string* (usually called by
290 * "help commandname").
291 * 2) I want documentation on *this list* (usually called by
292 * giving a command that requires subcommands. Also called by saying
295 * I am going to split this into two seperate comamnds, help_cmd and
300 help_cmd (command, stream)
304 struct cmd_list_element *c;
305 extern struct cmd_list_element *cmdlist;
309 help_list (cmdlist, "", all_classes, stream);
313 c = lookup_cmd (&command, cmdlist, "", 0, 0);
318 /* There are three cases here.
319 If c->prefixlist is nonzero, we have a prefix command.
320 Print its documentation, then list its subcommands.
322 If c->function is nonzero, we really have a command.
323 Print its documentation and return.
325 If c->function is zero, we have a class name.
326 Print its documentation (as if it were a command)
327 and then set class to the number of this class
328 so that the commands in the class will be listed. */
330 fputs_filtered (c->doc, stream);
331 fputs_filtered ("\n", stream);
333 if (c->prefixlist == 0 && c->function.cfunc != NULL)
335 fprintf_filtered (stream, "\n");
337 /* If this is a prefix command, print it's subcommands */
339 help_list (*c->prefixlist, c->prefixname, all_commands, stream);
341 /* If this is a class name, print all of the commands in the class */
342 if (c->function.cfunc == NULL)
343 help_list (cmdlist, "", c->class, stream);
346 fprintf_filtered (stream, "\nThis command has a hook defined: %s\n",
351 * Get a specific kind of help on a command list.
354 * CMDTYPE is the prefix to use in the title string.
355 * CLASS is the class with which to list the nodes of this list (see
356 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
357 * everything, ALL_CLASSES for just classes, and non-negative for only things
358 * in a specific class.
359 * and STREAM is the output stream on which to print things.
360 * If you call this routine with a class >= 0, it recurses.
363 help_list (list, cmdtype, class, stream)
364 struct cmd_list_element *list;
366 enum command_class class;
370 char *cmdtype1, *cmdtype2;
372 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
373 len = strlen (cmdtype);
374 cmdtype1 = (char *) alloca (len + 1);
376 cmdtype2 = (char *) alloca (len + 4);
381 strncpy (cmdtype1 + 1, cmdtype, len - 1);
383 strncpy (cmdtype2, cmdtype, len - 1);
384 strcpy (cmdtype2 + len - 1, " sub");
387 if (class == all_classes)
388 fprintf_filtered (stream, "List of classes of %scommands:\n\n", cmdtype2);
390 fprintf_filtered (stream, "List of %scommands:\n\n", cmdtype2);
392 help_cmd_list (list, class, cmdtype, (int)class >= 0, stream);
394 if (class == all_classes)
395 fprintf_filtered (stream, "\n\
396 Type \"help%s\" followed by a class name for a list of commands in that class.",
399 fprintf_filtered (stream, "\n\
400 Type \"help%s\" followed by %scommand name for full documentation.\n\
401 Command name abbreviations are allowed if unambiguous.\n",
405 /* Print only the first line of STR on STREAM. */
407 print_doc_line (stream, str)
411 static char *line_buffer = 0;
412 static int line_size;
418 line_buffer = (char *) xmalloc (line_size);
422 while (*p && *p != '\n' && *p != '.' && *p != ',')
424 if (p - str > line_size - 1)
426 line_size = p - str + 1;
427 free ((PTR)line_buffer);
428 line_buffer = (char *) xmalloc (line_size);
430 strncpy (line_buffer, str, p - str);
431 line_buffer[p - str] = '\0';
432 if (islower (line_buffer[0]))
433 line_buffer[0] = toupper (line_buffer[0]);
434 fputs_filtered (line_buffer, stream);
438 * Implement a help command on command list LIST.
439 * RECURSE should be non-zero if this should be done recursively on
440 * all sublists of LIST.
441 * PREFIX is the prefix to print before each command name.
442 * STREAM is the stream upon which the output should be written.
444 * A non-negative class number to list only commands in that
446 * ALL_COMMANDS to list all commands in list.
447 * ALL_CLASSES to list all classes in list.
449 * Note that RECURSE will be active on *all* sublists, not just the
450 * ones selected by the criteria above (ie. the selection mechanism
451 * is at the low level, not the high-level).
454 help_cmd_list (list, class, prefix, recurse, stream)
455 struct cmd_list_element *list;
456 enum command_class class;
461 register struct cmd_list_element *c;
463 for (c = list; c; c = c->next)
465 if (c->abbrev_flag == 0 &&
466 (class == all_commands
467 || (class == all_classes && c->function.cfunc == NULL)
468 || (class == c->class && c->function.cfunc != NULL)))
470 fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
471 print_doc_line (stream, c->doc);
472 fputs_filtered ("\n", stream);
475 && c->prefixlist != 0
476 && c->abbrev_flag == 0)
477 help_cmd_list (*c->prefixlist, class, c->prefixname, 1, stream);
481 /* This routine takes a line of TEXT and a CLIST in which to start the
482 lookup. When it returns it will have incremented the text pointer past
483 the section of text it matched, set *RESULT_LIST to point to the list in
484 which the last word was matched, and will return a pointer to the cmd
485 list element which the text matches. It will return NULL if no match at
486 all was possible. It will return -1 (cast appropriately, ick) if ambigous
487 matches are possible; in this case *RESULT_LIST will be set to point to
488 the list in which there are ambiguous choices (and *TEXT will be set to
489 the ambiguous text string).
491 If the located command was an abbreviation, this routine returns the base
492 command of the abbreviation.
494 It does no error reporting whatsoever; control will always return
495 to the superior routine.
497 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
498 at the prefix_command (ie. the best match) *or* (special case) will be NULL
499 if no prefix command was ever found. For example, in the case of "info a",
500 "info" matches without ambiguity, but "a" could be "args" or "address", so
501 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
502 RESULT_LIST should not be interpeted as a pointer to the beginning of a
503 list; it simply points to a specific command.
505 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
506 affect the operation).
508 This routine does *not* modify the text pointed to by TEXT.
510 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
511 are actually help classes rather than commands (i.e. the function field of
512 the struct cmd_list_element is NULL). */
514 struct cmd_list_element *
515 lookup_cmd_1 (text, clist, result_list, ignore_help_classes)
517 struct cmd_list_element *clist, **result_list;
518 int ignore_help_classes;
521 int len, tmp, nfound;
522 struct cmd_list_element *found, *c;
524 while (**text == ' ' || **text == '\t')
527 /* Treating underscores as part of command words is important
528 so that "set args_foo()" doesn't get interpreted as
529 "set args _foo()". */
531 *p && (isalnum(*p) || *p == '-' || *p == '_');
535 /* If nothing but whitespace, return 0. */
541 /* *text and p now bracket the first command word to lookup (and
542 it's length is len). We copy this into a local temporary,
543 converting to lower case as we go. */
545 command = (char *) alloca (len + 1);
546 for (tmp = 0; tmp < len; tmp++)
548 char x = (*text)[tmp];
549 command[tmp] = isupper(x) ? tolower(x) : x;
556 for (c = clist; c; c = c->next)
557 if (!strncmp (command, c->name, len)
558 && (!ignore_help_classes || c->function.cfunc))
562 if (c->name[len] == '\0')
569 /* If nothing matches, we have a simple failure. */
575 if (result_list != NULL)
576 /* Will be modified in calling routine
577 if we know what the prefix command is. */
579 return (struct cmd_list_element *) -1; /* Ambiguous. */
582 /* We've matched something on this list. Move text pointer forward. */
586 /* If this was an abbreviation, use the base command instead. */
588 if (found->cmd_pointer)
589 found = found->cmd_pointer;
591 /* If we found a prefix command, keep looking. */
593 if (found->prefixlist)
595 c = lookup_cmd_1 (text, *found->prefixlist, result_list,
596 ignore_help_classes);
599 /* Didn't find anything; this is as far as we got. */
600 if (result_list != NULL)
601 *result_list = clist;
604 else if (c == (struct cmd_list_element *) -1)
606 /* We've gotten this far properley, but the next step
607 is ambiguous. We need to set the result list to the best
608 we've found (if an inferior hasn't already set it). */
609 if (result_list != NULL)
611 /* This used to say *result_list = *found->prefixlist
612 If that was correct, need to modify the documentation
613 at the top of this function to clarify what is supposed
615 *result_list = found;
626 if (result_list != NULL)
627 *result_list = clist;
632 /* All this hair to move the space to the front of cmdtype */
635 undef_cmd_error (cmdtype, q)
638 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
646 /* Look up the contents of *LINE as a command in the command list LIST.
647 LIST is a chain of struct cmd_list_element's.
648 If it is found, return the struct cmd_list_element for that command
649 and update *LINE to point after the command name, at the first argument.
650 If not found, call error if ALLOW_UNKNOWN is zero
651 otherwise (or if error returns) return zero.
652 Call error if specified command is ambiguous,
653 unless ALLOW_UNKNOWN is negative.
654 CMDTYPE precedes the word "command" in the error message.
656 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
657 elements which are actually help classes rather than commands (i.e.
658 the function field of the struct cmd_list_element is 0). */
660 struct cmd_list_element *
661 lookup_cmd (line, list, cmdtype, allow_unknown, ignore_help_classes)
663 struct cmd_list_element *list;
666 int ignore_help_classes;
668 struct cmd_list_element *last_list = 0;
669 struct cmd_list_element *c =
670 lookup_cmd_1 (line, list, &last_list, ignore_help_classes);
671 char *ptr = (*line) + strlen (*line) - 1;
673 /* Clear off trailing whitespace. */
674 while (ptr >= *line && (*ptr == ' ' || *ptr == '\t'))
683 error ("Lack of needed %scommand", cmdtype);
688 while (isalnum(*p) || *p == '-')
691 q = (char *) alloca (p - *line + 1);
692 strncpy (q, *line, p - *line);
694 undef_cmd_error (cmdtype, q);
700 else if (c == (struct cmd_list_element *) -1)
702 /* Ambigous. Local values should be off prefixlist or called
704 int local_allow_unknown = (last_list ? last_list->allow_unknown :
706 char *local_cmdtype = last_list ? last_list->prefixname : cmdtype;
707 struct cmd_list_element *local_list =
708 (last_list ? *(last_list->prefixlist) : list);
710 if (local_allow_unknown < 0)
713 return last_list; /* Found something. */
715 return 0; /* Found nothing. */
719 /* Report as error. */
724 ((*line)[amb_len] && (*line)[amb_len] != ' '
725 && (*line)[amb_len] != '\t');
730 for (c = local_list; c; c = c->next)
731 if (!strncmp (*line, c->name, amb_len))
733 if (strlen (ambbuf) + strlen (c->name) + 6 < (int)sizeof ambbuf)
736 strcat (ambbuf, ", ");
737 strcat (ambbuf, c->name);
741 strcat (ambbuf, "..");
745 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype,
752 /* We've got something. It may still not be what the caller
753 wants (if this command *needs* a subcommand). */
754 while (**line == ' ' || **line == '\t')
757 if (c->prefixlist && **line && !c->allow_unknown)
758 undef_cmd_error (c->prefixname, *line);
760 /* Seems to be what he wants. Return it. */
767 /* Look up the contents of *LINE as a command in the command list LIST.
768 LIST is a chain of struct cmd_list_element's.
769 If it is found, return the struct cmd_list_element for that command
770 and update *LINE to point after the command name, at the first argument.
771 If not found, call error if ALLOW_UNKNOWN is zero
772 otherwise (or if error returns) return zero.
773 Call error if specified command is ambiguous,
774 unless ALLOW_UNKNOWN is negative.
775 CMDTYPE precedes the word "command" in the error message. */
777 struct cmd_list_element *
778 lookup_cmd (line, list, cmdtype, allow_unknown)
780 struct cmd_list_element *list;
785 register struct cmd_list_element *c, *found;
791 /* Skip leading whitespace. */
793 while (**line == ' ' || **line == '\t')
796 /* Clear out trailing whitespace. */
798 p = *line + strlen (*line);
799 while (p != *line && (p[-1] == ' ' || p[-1] == '\t'))
803 /* Find end of command name. */
806 while (*p == '-' || isalnum(*p))
809 /* Look up the command name.
810 If exact match, keep that.
811 Otherwise, take command abbreviated, if unique. Note that (in my
812 opinion) a null string does *not* indicate ambiguity; simply the
813 end of the argument. */
818 error ("Lack of needed %scommand", cmdtype);
822 /* Copy over to a local buffer, converting to lowercase on the way.
823 This is in case the command being parsed is a subcommand which
824 doesn't match anything, and that's ok. We want the original
825 untouched for the routine of the original command. */
827 processed_cmd = (char *) alloca (p - *line + 1);
828 for (cmd_len = 0; cmd_len < p - *line; cmd_len++)
830 char x = (*line)[cmd_len];
832 processed_cmd[cmd_len] = tolower(x);
834 processed_cmd[cmd_len] = x;
836 processed_cmd[cmd_len] = '\0';
838 /* Check all possibilities in the current command list. */
841 for (c = list; c; c = c->next)
843 if (!strncmp (processed_cmd, c->name, cmd_len))
847 if (c->name[cmd_len] == 0)
855 /* Report error for undefined command name. */
859 if (nfound > 1 && allow_unknown >= 0)
862 for (c = list; c; c = c->next)
863 if (!strncmp (processed_cmd, c->name, cmd_len))
865 if (strlen (ambbuf) + strlen (c->name) + 6 < sizeof ambbuf)
868 strcat (ambbuf, ", ");
869 strcat (ambbuf, c->name);
873 strcat (ambbuf, "..");
877 error ("Ambiguous %scommand \"%s\": %s.", cmdtype,
878 processed_cmd, ambbuf);
880 else if (!allow_unknown)
881 error ("Undefined %scommand: \"%s\".", cmdtype, processed_cmd);
885 /* Skip whitespace before the argument. */
887 while (*p == ' ' || *p == '\t') p++;
890 if (found->prefixlist && *p)
892 c = lookup_cmd (line, *found->prefixlist, found->prefixname,
893 found->allow_unknown);
902 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
904 /* Return a vector of char pointers which point to the different
905 possible completions in LIST of TEXT. */
908 complete_on_cmdlist (list, text)
909 struct cmd_list_element *list;
912 struct cmd_list_element *ptr;
914 int sizeof_matchlist;
916 int textlen = strlen (text);
918 sizeof_matchlist = 10;
919 matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
922 for (ptr = list; ptr; ptr = ptr->next)
923 if (!strncmp (ptr->name, text, textlen)
925 && (ptr->function.cfunc
928 if (matches == sizeof_matchlist)
930 sizeof_matchlist *= 2;
931 matchlist = (char **) xrealloc ((char *)matchlist,
936 matchlist[matches] = (char *)
937 xmalloc (strlen (ptr->name) + 1);
938 strcpy (matchlist[matches++], ptr->name);
943 free ((PTR)matchlist);
948 matchlist = (char **) xrealloc ((char *)matchlist, ((matches + 1)
950 matchlist[matches] = (char *) 0;
957 parse_binary_operation (arg)
965 length = strlen (arg);
967 while (arg[length - 1] == ' ' || arg[length - 1] == '\t')
970 if (!strncmp (arg, "on", length)
971 || !strncmp (arg, "1", length)
972 || !strncmp (arg, "yes", length))
975 if (!strncmp (arg, "off", length)
976 || !strncmp (arg, "0", length)
977 || !strncmp (arg, "no", length))
981 error ("\"on\" or \"off\" expected.");
986 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
987 of the argument, and FROM_TTY is nonzero if this command is being entered
988 directly by the user (i.e. these are just like any other
989 command). C is the command list element for the command. */
991 do_setshow_command (arg, from_tty, c)
994 struct cmd_list_element *c;
996 if (c->type == set_cmd)
1009 new = (char *) xmalloc (strlen (arg) + 2);
1011 while ((ch = *p++) != '\000')
1015 /* \ at end of argument is used after spaces
1016 so they won't be lost. */
1019 ch = parse_escape (&p);
1021 break; /* C loses */
1028 if (*(p - 1) != '\\')
1031 new = (char *) xrealloc (new, q - new);
1032 if (*(char **)c->var != NULL)
1033 free (*(char **)c->var);
1034 *(char **) c->var = new;
1037 case var_string_noescape:
1040 if (*(char **)c->var != NULL)
1041 free (*(char **)c->var);
1042 *(char **) c->var = savestring (arg, strlen (arg));
1046 error_no_arg ("filename to set it to.");
1047 if (*(char **)c->var != NULL)
1048 free (*(char **)c->var);
1049 *(char **)c->var = tilde_expand (arg);
1052 *(int *) c->var = parse_binary_operation (arg);
1056 error_no_arg ("integer to set it to.");
1057 *(unsigned int *) c->var = parse_and_eval_address (arg);
1058 if (*(unsigned int *) c->var == 0)
1059 *(unsigned int *) c->var = UINT_MAX;
1065 error_no_arg ("integer to set it to.");
1066 val = parse_and_eval_address (arg);
1068 *(int *) c->var = INT_MAX;
1069 else if (val >= INT_MAX)
1070 error ("integer %u out of range", val);
1072 *(int *) c->var = val;
1077 error_no_arg ("integer to set it to.");
1078 *(int *) c->var = parse_and_eval_address (arg);
1081 error ("gdb internal error: bad var_type in do_setshow_command");
1084 else if (c->type == show_cmd)
1086 /* Print doc minus "show" at start. */
1087 print_doc_line (stdout, c->doc + 5);
1089 fputs_filtered (" is ", stdout);
1091 switch (c->var_type)
1096 fputs_filtered ("\"", stdout);
1097 for (p = *(unsigned char **) c->var; *p != '\0'; p++)
1098 gdb_printchar (*p, stdout, '"');
1099 fputs_filtered ("\"", stdout);
1102 case var_string_noescape:
1104 fputs_filtered ("\"", stdout);
1105 fputs_filtered (*(char **) c->var, stdout);
1106 fputs_filtered ("\"", stdout);
1109 fputs_filtered (*(int *) c->var ? "on" : "off", stdout);
1112 if (*(unsigned int *) c->var == UINT_MAX) {
1113 fputs_filtered ("unlimited", stdout);
1116 /* else fall through */
1118 fprintf_filtered (stdout, "%u", *(unsigned int *) c->var);
1121 if (*(int *) c->var == INT_MAX)
1123 fputs_filtered ("unlimited", stdout);
1126 fprintf_filtered (stdout, "%d", *(int *) c->var);
1130 error ("gdb internal error: bad var_type in do_setshow_command");
1132 fputs_filtered (".\n", stdout);
1135 error ("gdb internal error: bad cmd_type in do_setshow_command");
1136 (*c->function.sfunc) (NULL, from_tty, c);
1139 /* Show all the settings in a list of show commands. */
1142 cmd_show_list (list, from_tty, prefix)
1143 struct cmd_list_element *list;
1147 for (; list != NULL; list = list->next) {
1148 /* If we find a prefix, run its list, prefixing our output by its
1149 prefix (with "show " skipped). */
1150 if (list->prefixlist && !list->abbrev_flag)
1151 cmd_show_list (*list->prefixlist, from_tty, list->prefixname + 5);
1152 if (list->type == show_cmd)
1154 fputs_filtered (prefix, stdout);
1155 fputs_filtered (list->name, stdout);
1156 fputs_filtered (": ", stdout);
1157 do_setshow_command ((char *)NULL, from_tty, list);
1165 shell_escape (arg, from_tty)
1169 int rc, status, pid;
1170 char *p, *user_shell;
1172 if ((user_shell = (char *) getenv ("SHELL")) == NULL)
1173 user_shell = "/bin/sh";
1175 /* Get the name of the shell for arg0 */
1176 if ((p = strrchr (user_shell, '/')) == NULL)
1179 p++; /* Get past '/' */
1181 if ((pid = fork()) == 0)
1184 execl (user_shell, p, 0);
1186 execl (user_shell, p, "-c", arg, 0);
1188 fprintf (stderr, "Exec of shell failed\n");
1193 while ((rc = wait (&status)) != pid && rc != -1)
1196 error ("Fork failed");
1202 make_command (arg, from_tty)
1212 p = xmalloc (sizeof("make ") + strlen(arg));
1213 strcpy (p, "make ");
1214 strcpy (p + sizeof("make ")-1, arg);
1217 shell_escape (p, from_tty);
1222 show_user_1 (c, stream)
1223 struct cmd_list_element *c;
1226 register struct command_line *cmdlines;
1228 cmdlines = c->user_commands;
1231 fputs_filtered ("User command ", stream);
1232 fputs_filtered (c->name, stream);
1233 fputs_filtered (":\n", stream);
1236 fputs_filtered (cmdlines->line, stream);
1237 fputs_filtered ("\n", stream);
1238 cmdlines = cmdlines->next;
1240 fputs_filtered ("\n", stream);
1245 show_user (args, from_tty)
1249 struct cmd_list_element *c;
1250 extern struct cmd_list_element *cmdlist;
1254 c = lookup_cmd (&args, cmdlist, "", 0, 1);
1255 if (c->class != class_user)
1256 error ("Not a user command.");
1257 show_user_1 (c, stdout);
1261 for (c = cmdlist; c; c = c->next)
1263 if (c->class == class_user)
1264 show_user_1 (c, stdout);
1270 _initialize_command ()
1273 add_com ("shell", class_support, shell_escape,
1274 "Execute the rest of the line as a shell command. \n\
1275 With no arguments, run an inferior shell.");
1278 add_com ("make", class_support, make_command,
1279 "Run the ``make'' program using the rest of the line as arguments.");
1281 add_cmd ("user", no_class, show_user,
1282 "Show definitions of user defined commands.\n\
1283 Argument is the name of the user defined command.\n\
1284 With no argument, show definitions of all user defined commands.", &showlist);