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.
49 CLASS is the top level category into which commands are broken down
51 FUN should be the function to execute the command;
52 it will get a character string as argument, with leading
53 and trailing blanks already eliminated.
55 DOC is a documentation string for the command.
56 Its first line should be a complete sentence.
57 It should start with ? for a command that is an abbreviation
58 or with * for a command that most users don't need to know about.
60 Add this command to command list *LIST. */
62 struct cmd_list_element *
63 add_cmd (name, class, fun, doc, list)
65 enum command_class class;
66 void (*fun) PARAMS ((char *, int));
68 struct cmd_list_element **list;
70 register struct cmd_list_element *c
71 = (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
73 delete_cmd (name, list);
77 c->function.cfunc = fun;
80 c->prefixname = (char *)NULL;
86 c->type = not_set_cmd;
87 c->completer = make_symbol_completion_list;
89 c->var_type = var_boolean;
95 /* Same as above, except that the abbrev_flag is set. */
97 #if 0 /* Currently unused */
99 struct cmd_list_element *
100 add_abbrev_cmd (name, class, fun, doc, list)
102 enum command_class class;
103 void (*fun) PARAMS ((char *, int));
105 struct cmd_list_element **list;
107 register struct cmd_list_element *c
108 = add_cmd (name, class, fun, doc, list);
116 struct cmd_list_element *
117 add_alias_cmd (name, oldname, class, abbrev_flag, list)
120 enum command_class class;
122 struct cmd_list_element **list;
124 /* Must do this since lookup_cmd tries to side-effect its first arg */
126 register struct cmd_list_element *old;
127 register struct cmd_list_element *c;
128 copied_name = (char *) alloca (strlen (oldname) + 1);
129 strcpy (copied_name, oldname);
130 old = lookup_cmd (&copied_name, *list, "", 1, 1);
134 delete_cmd (name, list);
138 c = add_cmd (name, class, old->function.cfunc, old->doc, list);
139 c->prefixlist = old->prefixlist;
140 c->prefixname = old->prefixname;
141 c->allow_unknown = old->allow_unknown;
142 c->abbrev_flag = abbrev_flag;
143 c->cmd_pointer = old;
147 /* Like add_cmd but adds an element for a command prefix:
148 a name that should be followed by a subcommand to be looked up
149 in another command list. PREFIXLIST should be the address
150 of the variable containing that list. */
152 struct cmd_list_element *
153 add_prefix_cmd (name, class, fun, doc, prefixlist, prefixname,
156 enum command_class class;
157 void (*fun) PARAMS ((char *, int));
159 struct cmd_list_element **prefixlist;
162 struct cmd_list_element **list;
164 register struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);
165 c->prefixlist = prefixlist;
166 c->prefixname = prefixname;
167 c->allow_unknown = allow_unknown;
171 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
173 struct cmd_list_element *
174 add_abbrev_prefix_cmd (name, class, fun, doc, prefixlist, prefixname,
177 enum command_class class;
178 void (*fun) PARAMS ((char *, int));
180 struct cmd_list_element **prefixlist;
183 struct cmd_list_element **list;
185 register struct cmd_list_element *c = add_cmd (name, class, fun, doc, list);
186 c->prefixlist = prefixlist;
187 c->prefixname = prefixname;
188 c->allow_unknown = allow_unknown;
195 not_just_help_class_command (args, from_tty)
201 /* Add element named NAME to command list LIST (the list for set
202 or some sublist thereof).
203 CLASS is as in add_cmd.
204 VAR_TYPE is the kind of thing we are setting.
205 VAR is address of the variable being controlled by this command.
206 DOC is the documentation string. */
208 struct cmd_list_element *
209 add_set_cmd (name, class, var_type, var, doc, list)
211 enum command_class class;
215 struct cmd_list_element **list;
217 /* For set/show, we have to call do_setshow_command
218 differently than an ordinary function (take commandlist as
219 well as arg), so the function field isn't helpful. However,
220 function == NULL means that it's a help class, so set the function
221 to not_just_help_class_command. */
222 struct cmd_list_element *c
223 = add_cmd (name, class, not_just_help_class_command, doc, list);
226 c->var_type = var_type;
231 /* Where SETCMD has already been added, add the corresponding show
232 command to LIST and return a pointer to it. */
233 struct cmd_list_element *
234 add_show_from_set (setcmd, list)
235 struct cmd_list_element *setcmd;
236 struct cmd_list_element **list;
238 struct cmd_list_element *showcmd =
239 (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
241 memcpy (showcmd, setcmd, sizeof (struct cmd_list_element));
242 delete_cmd (showcmd->name, list);
243 showcmd->type = show_cmd;
245 /* Replace "set " at start of docstring with "show ". */
246 if (setcmd->doc[0] == 'S' && setcmd->doc[1] == 'e'
247 && setcmd->doc[2] == 't' && setcmd->doc[3] == ' ')
248 showcmd->doc = concat ("Show ", setcmd->doc + 4, NULL);
250 fprintf (stderr, "GDB internal error: Bad docstring for set command\n");
252 showcmd->next = *list;
257 /* Remove the command named NAME from the command list. */
260 delete_cmd (name, list)
262 struct cmd_list_element **list;
264 register struct cmd_list_element *c;
265 struct cmd_list_element *p;
267 while (*list && STREQ ((*list)->name, name))
270 (*list)->hookee->hook = 0; /* Hook slips out of its mouth */
277 for (c = *list; c->next;)
279 if (STREQ (c->next->name, name))
282 c->next->hookee->hook = 0; /* hooked cmd gets away. */
292 /* This command really has to deal with two things:
293 * 1) I want documentation on *this string* (usually called by
294 * "help commandname").
295 * 2) I want documentation on *this list* (usually called by
296 * giving a command that requires subcommands. Also called by saying
299 * I am going to split this into two seperate comamnds, help_cmd and
304 help_cmd (command, stream)
308 struct cmd_list_element *c;
309 extern struct cmd_list_element *cmdlist;
313 help_list (cmdlist, "", all_classes, stream);
317 c = lookup_cmd (&command, cmdlist, "", 0, 0);
322 /* There are three cases here.
323 If c->prefixlist is nonzero, we have a prefix command.
324 Print its documentation, then list its subcommands.
326 If c->function is nonzero, we really have a command.
327 Print its documentation and return.
329 If c->function is zero, we have a class name.
330 Print its documentation (as if it were a command)
331 and then set class to the number of this class
332 so that the commands in the class will be listed. */
334 fputs_filtered (c->doc, stream);
335 fputs_filtered ("\n", stream);
337 if (c->prefixlist == 0 && c->function.cfunc != NULL)
339 fprintf_filtered (stream, "\n");
341 /* If this is a prefix command, print it's subcommands */
343 help_list (*c->prefixlist, c->prefixname, all_commands, stream);
345 /* If this is a class name, print all of the commands in the class */
346 if (c->function.cfunc == NULL)
347 help_list (cmdlist, "", c->class, stream);
350 fprintf_filtered (stream, "\nThis command has a hook defined: %s\n",
355 * Get a specific kind of help on a command list.
358 * CMDTYPE is the prefix to use in the title string.
359 * CLASS is the class with which to list the nodes of this list (see
360 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
361 * everything, ALL_CLASSES for just classes, and non-negative for only things
362 * in a specific class.
363 * and STREAM is the output stream on which to print things.
364 * If you call this routine with a class >= 0, it recurses.
367 help_list (list, cmdtype, class, stream)
368 struct cmd_list_element *list;
370 enum command_class class;
374 char *cmdtype1, *cmdtype2;
376 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
377 len = strlen (cmdtype);
378 cmdtype1 = (char *) alloca (len + 1);
380 cmdtype2 = (char *) alloca (len + 4);
385 strncpy (cmdtype1 + 1, cmdtype, len - 1);
387 strncpy (cmdtype2, cmdtype, len - 1);
388 strcpy (cmdtype2 + len - 1, " sub");
391 if (class == all_classes)
392 fprintf_filtered (stream, "List of classes of %scommands:\n\n", cmdtype2);
394 fprintf_filtered (stream, "List of %scommands:\n\n", cmdtype2);
396 help_cmd_list (list, class, cmdtype, (int)class >= 0, stream);
398 if (class == all_classes)
399 fprintf_filtered (stream, "\n\
400 Type \"help%s\" followed by a class name for a list of commands in that class.",
403 fprintf_filtered (stream, "\n\
404 Type \"help%s\" followed by %scommand name for full documentation.\n\
405 Command name abbreviations are allowed if unambiguous.\n",
409 /* Print only the first line of STR on STREAM. */
411 print_doc_line (stream, str)
415 static char *line_buffer = 0;
416 static int line_size;
422 line_buffer = (char *) xmalloc (line_size);
426 while (*p && *p != '\n' && *p != '.' && *p != ',')
428 if (p - str > line_size - 1)
430 line_size = p - str + 1;
431 free ((PTR)line_buffer);
432 line_buffer = (char *) xmalloc (line_size);
434 strncpy (line_buffer, str, p - str);
435 line_buffer[p - str] = '\0';
436 if (islower (line_buffer[0]))
437 line_buffer[0] = toupper (line_buffer[0]);
438 fputs_filtered (line_buffer, stream);
442 * Implement a help command on command list LIST.
443 * RECURSE should be non-zero if this should be done recursively on
444 * all sublists of LIST.
445 * PREFIX is the prefix to print before each command name.
446 * STREAM is the stream upon which the output should be written.
448 * A non-negative class number to list only commands in that
450 * ALL_COMMANDS to list all commands in list.
451 * ALL_CLASSES to list all classes in list.
453 * Note that RECURSE will be active on *all* sublists, not just the
454 * ones selected by the criteria above (ie. the selection mechanism
455 * is at the low level, not the high-level).
458 help_cmd_list (list, class, prefix, recurse, stream)
459 struct cmd_list_element *list;
460 enum command_class class;
465 register struct cmd_list_element *c;
467 for (c = list; c; c = c->next)
469 if (c->abbrev_flag == 0 &&
470 (class == all_commands
471 || (class == all_classes && c->function.cfunc == NULL)
472 || (class == c->class && c->function.cfunc != NULL)))
474 fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
475 print_doc_line (stream, c->doc);
476 fputs_filtered ("\n", stream);
479 && c->prefixlist != 0
480 && c->abbrev_flag == 0)
481 help_cmd_list (*c->prefixlist, class, c->prefixname, 1, stream);
485 /* This routine takes a line of TEXT and a CLIST in which to start the
486 lookup. When it returns it will have incremented the text pointer past
487 the section of text it matched, set *RESULT_LIST to point to the list in
488 which the last word was matched, and will return a pointer to the cmd
489 list element which the text matches. It will return NULL if no match at
490 all was possible. It will return -1 (cast appropriately, ick) if ambigous
491 matches are possible; in this case *RESULT_LIST will be set to point to
492 the list in which there are ambiguous choices (and *TEXT will be set to
493 the ambiguous text string).
495 If the located command was an abbreviation, this routine returns the base
496 command of the abbreviation.
498 It does no error reporting whatsoever; control will always return
499 to the superior routine.
501 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
502 at the prefix_command (ie. the best match) *or* (special case) will be NULL
503 if no prefix command was ever found. For example, in the case of "info a",
504 "info" matches without ambiguity, but "a" could be "args" or "address", so
505 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
506 RESULT_LIST should not be interpeted as a pointer to the beginning of a
507 list; it simply points to a specific command.
509 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
510 affect the operation).
512 This routine does *not* modify the text pointed to by TEXT.
514 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
515 are actually help classes rather than commands (i.e. the function field of
516 the struct cmd_list_element is NULL). */
518 struct cmd_list_element *
519 lookup_cmd_1 (text, clist, result_list, ignore_help_classes)
521 struct cmd_list_element *clist, **result_list;
522 int ignore_help_classes;
525 int len, tmp, nfound;
526 struct cmd_list_element *found, *c;
528 while (**text == ' ' || **text == '\t')
531 /* Treating underscores as part of command words is important
532 so that "set args_foo()" doesn't get interpreted as
533 "set args _foo()". */
535 *p && (isalnum(*p) || *p == '-' || *p == '_');
539 /* If nothing but whitespace, return 0. */
545 /* *text and p now bracket the first command word to lookup (and
546 it's length is len). We copy this into a local temporary,
547 converting to lower case as we go. */
549 command = (char *) alloca (len + 1);
550 for (tmp = 0; tmp < len; tmp++)
552 char x = (*text)[tmp];
553 command[tmp] = isupper(x) ? tolower(x) : x;
560 for (c = clist; c; c = c->next)
561 if (!strncmp (command, c->name, len)
562 && (!ignore_help_classes || c->function.cfunc))
566 if (c->name[len] == '\0')
573 /* If nothing matches, we have a simple failure. */
579 if (result_list != NULL)
580 /* Will be modified in calling routine
581 if we know what the prefix command is. */
583 return (struct cmd_list_element *) -1; /* Ambiguous. */
586 /* We've matched something on this list. Move text pointer forward. */
590 /* If this was an abbreviation, use the base command instead. */
592 if (found->cmd_pointer)
593 found = found->cmd_pointer;
595 /* If we found a prefix command, keep looking. */
597 if (found->prefixlist)
599 c = lookup_cmd_1 (text, *found->prefixlist, result_list,
600 ignore_help_classes);
603 /* Didn't find anything; this is as far as we got. */
604 if (result_list != NULL)
605 *result_list = clist;
608 else if (c == (struct cmd_list_element *) -1)
610 /* We've gotten this far properley, but the next step
611 is ambiguous. We need to set the result list to the best
612 we've found (if an inferior hasn't already set it). */
613 if (result_list != NULL)
615 /* This used to say *result_list = *found->prefixlist
616 If that was correct, need to modify the documentation
617 at the top of this function to clarify what is supposed
619 *result_list = found;
630 if (result_list != NULL)
631 *result_list = clist;
636 /* All this hair to move the space to the front of cmdtype */
639 undef_cmd_error (cmdtype, q)
642 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
650 /* Look up the contents of *LINE as a command in the command list LIST.
651 LIST is a chain of struct cmd_list_element's.
652 If it is found, return the struct cmd_list_element for that command
653 and update *LINE to point after the command name, at the first argument.
654 If not found, call error if ALLOW_UNKNOWN is zero
655 otherwise (or if error returns) return zero.
656 Call error if specified command is ambiguous,
657 unless ALLOW_UNKNOWN is negative.
658 CMDTYPE precedes the word "command" in the error message.
660 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
661 elements which are actually help classes rather than commands (i.e.
662 the function field of the struct cmd_list_element is 0). */
664 struct cmd_list_element *
665 lookup_cmd (line, list, cmdtype, allow_unknown, ignore_help_classes)
667 struct cmd_list_element *list;
670 int ignore_help_classes;
672 struct cmd_list_element *last_list = 0;
673 struct cmd_list_element *c =
674 lookup_cmd_1 (line, list, &last_list, ignore_help_classes);
675 char *ptr = (*line) + strlen (*line) - 1;
677 /* Clear off trailing whitespace. */
678 while (ptr >= *line && (*ptr == ' ' || *ptr == '\t'))
687 error ("Lack of needed %scommand", cmdtype);
692 while (isalnum(*p) || *p == '-')
695 q = (char *) alloca (p - *line + 1);
696 strncpy (q, *line, p - *line);
698 undef_cmd_error (cmdtype, q);
704 else if (c == (struct cmd_list_element *) -1)
706 /* Ambigous. Local values should be off prefixlist or called
708 int local_allow_unknown = (last_list ? last_list->allow_unknown :
710 char *local_cmdtype = last_list ? last_list->prefixname : cmdtype;
711 struct cmd_list_element *local_list =
712 (last_list ? *(last_list->prefixlist) : list);
714 if (local_allow_unknown < 0)
717 return last_list; /* Found something. */
719 return 0; /* Found nothing. */
723 /* Report as error. */
728 ((*line)[amb_len] && (*line)[amb_len] != ' '
729 && (*line)[amb_len] != '\t');
734 for (c = local_list; c; c = c->next)
735 if (!strncmp (*line, c->name, amb_len))
737 if (strlen (ambbuf) + strlen (c->name) + 6 < (int)sizeof ambbuf)
740 strcat (ambbuf, ", ");
741 strcat (ambbuf, c->name);
745 strcat (ambbuf, "..");
749 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype,
756 /* We've got something. It may still not be what the caller
757 wants (if this command *needs* a subcommand). */
758 while (**line == ' ' || **line == '\t')
761 if (c->prefixlist && **line && !c->allow_unknown)
762 undef_cmd_error (c->prefixname, *line);
764 /* Seems to be what he wants. Return it. */
771 /* Look up the contents of *LINE as a command in the command list LIST.
772 LIST is a chain of struct cmd_list_element's.
773 If it is found, return the struct cmd_list_element for that command
774 and update *LINE to point after the command name, at the first argument.
775 If not found, call error if ALLOW_UNKNOWN is zero
776 otherwise (or if error returns) return zero.
777 Call error if specified command is ambiguous,
778 unless ALLOW_UNKNOWN is negative.
779 CMDTYPE precedes the word "command" in the error message. */
781 struct cmd_list_element *
782 lookup_cmd (line, list, cmdtype, allow_unknown)
784 struct cmd_list_element *list;
789 register struct cmd_list_element *c, *found;
795 /* Skip leading whitespace. */
797 while (**line == ' ' || **line == '\t')
800 /* Clear out trailing whitespace. */
802 p = *line + strlen (*line);
803 while (p != *line && (p[-1] == ' ' || p[-1] == '\t'))
807 /* Find end of command name. */
810 while (*p == '-' || isalnum(*p))
813 /* Look up the command name.
814 If exact match, keep that.
815 Otherwise, take command abbreviated, if unique. Note that (in my
816 opinion) a null string does *not* indicate ambiguity; simply the
817 end of the argument. */
822 error ("Lack of needed %scommand", cmdtype);
826 /* Copy over to a local buffer, converting to lowercase on the way.
827 This is in case the command being parsed is a subcommand which
828 doesn't match anything, and that's ok. We want the original
829 untouched for the routine of the original command. */
831 processed_cmd = (char *) alloca (p - *line + 1);
832 for (cmd_len = 0; cmd_len < p - *line; cmd_len++)
834 char x = (*line)[cmd_len];
836 processed_cmd[cmd_len] = tolower(x);
838 processed_cmd[cmd_len] = x;
840 processed_cmd[cmd_len] = '\0';
842 /* Check all possibilities in the current command list. */
845 for (c = list; c; c = c->next)
847 if (!strncmp (processed_cmd, c->name, cmd_len))
851 if (c->name[cmd_len] == 0)
859 /* Report error for undefined command name. */
863 if (nfound > 1 && allow_unknown >= 0)
866 for (c = list; c; c = c->next)
867 if (!strncmp (processed_cmd, c->name, cmd_len))
869 if (strlen (ambbuf) + strlen (c->name) + 6 < sizeof ambbuf)
872 strcat (ambbuf, ", ");
873 strcat (ambbuf, c->name);
877 strcat (ambbuf, "..");
881 error ("Ambiguous %scommand \"%s\": %s.", cmdtype,
882 processed_cmd, ambbuf);
884 else if (!allow_unknown)
885 error ("Undefined %scommand: \"%s\".", cmdtype, processed_cmd);
889 /* Skip whitespace before the argument. */
891 while (*p == ' ' || *p == '\t') p++;
894 if (found->prefixlist && *p)
896 c = lookup_cmd (line, *found->prefixlist, found->prefixname,
897 found->allow_unknown);
906 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
908 /* Return a vector of char pointers which point to the different
909 possible completions in LIST of TEXT. */
912 complete_on_cmdlist (list, text)
913 struct cmd_list_element *list;
916 struct cmd_list_element *ptr;
918 int sizeof_matchlist;
920 int textlen = strlen (text);
922 sizeof_matchlist = 10;
923 matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
926 for (ptr = list; ptr; ptr = ptr->next)
927 if (!strncmp (ptr->name, text, textlen)
929 && (ptr->function.cfunc
932 if (matches == sizeof_matchlist)
934 sizeof_matchlist *= 2;
935 matchlist = (char **) xrealloc ((char *)matchlist,
940 matchlist[matches] = (char *)
941 xmalloc (strlen (ptr->name) + 1);
942 strcpy (matchlist[matches++], ptr->name);
947 free ((PTR)matchlist);
952 matchlist = (char **) xrealloc ((char *)matchlist, ((matches + 1)
954 matchlist[matches] = (char *) 0;
961 parse_binary_operation (arg)
969 length = strlen (arg);
971 while (arg[length - 1] == ' ' || arg[length - 1] == '\t')
974 if (!strncmp (arg, "on", length)
975 || !strncmp (arg, "1", length)
976 || !strncmp (arg, "yes", length))
979 if (!strncmp (arg, "off", length)
980 || !strncmp (arg, "0", length)
981 || !strncmp (arg, "no", length))
985 error ("\"on\" or \"off\" expected.");
990 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
991 of the argument, and FROM_TTY is nonzero if this command is being entered
992 directly by the user (i.e. these are just like any other
993 command). C is the command list element for the command. */
995 do_setshow_command (arg, from_tty, c)
998 struct cmd_list_element *c;
1000 if (c->type == set_cmd)
1002 switch (c->var_type)
1013 new = (char *) xmalloc (strlen (arg) + 2);
1015 while ((ch = *p++) != '\000')
1019 /* \ at end of argument is used after spaces
1020 so they won't be lost. */
1023 ch = parse_escape (&p);
1025 break; /* C loses */
1032 if (*(p - 1) != '\\')
1035 new = (char *) xrealloc (new, q - new);
1036 if (*(char **)c->var != NULL)
1037 free (*(char **)c->var);
1038 *(char **) c->var = new;
1041 case var_string_noescape:
1044 if (*(char **)c->var != NULL)
1045 free (*(char **)c->var);
1046 *(char **) c->var = savestring (arg, strlen (arg));
1050 error_no_arg ("filename to set it to.");
1051 if (*(char **)c->var != NULL)
1052 free (*(char **)c->var);
1053 *(char **)c->var = tilde_expand (arg);
1056 *(int *) c->var = parse_binary_operation (arg);
1060 error_no_arg ("integer to set it to.");
1061 *(unsigned int *) c->var = parse_and_eval_address (arg);
1062 if (*(unsigned int *) c->var == 0)
1063 *(unsigned int *) c->var = UINT_MAX;
1069 error_no_arg ("integer to set it to.");
1070 val = parse_and_eval_address (arg);
1072 *(int *) c->var = INT_MAX;
1073 else if (val >= INT_MAX)
1074 error ("integer %u out of range", val);
1076 *(int *) c->var = val;
1081 error_no_arg ("integer to set it to.");
1082 *(int *) c->var = parse_and_eval_address (arg);
1085 error ("gdb internal error: bad var_type in do_setshow_command");
1088 else if (c->type == show_cmd)
1090 /* Print doc minus "show" at start. */
1091 print_doc_line (stdout, c->doc + 5);
1093 fputs_filtered (" is ", stdout);
1095 switch (c->var_type)
1100 fputs_filtered ("\"", stdout);
1101 for (p = *(unsigned char **) c->var; *p != '\0'; p++)
1102 gdb_printchar (*p, stdout, '"');
1103 fputs_filtered ("\"", stdout);
1106 case var_string_noescape:
1108 fputs_filtered ("\"", stdout);
1109 fputs_filtered (*(char **) c->var, stdout);
1110 fputs_filtered ("\"", stdout);
1113 fputs_filtered (*(int *) c->var ? "on" : "off", stdout);
1116 if (*(unsigned int *) c->var == UINT_MAX) {
1117 fputs_filtered ("unlimited", stdout);
1120 /* else fall through */
1122 fprintf_filtered (stdout, "%u", *(unsigned int *) c->var);
1125 if (*(int *) c->var == INT_MAX)
1127 fputs_filtered ("unlimited", stdout);
1130 fprintf_filtered (stdout, "%d", *(int *) c->var);
1134 error ("gdb internal error: bad var_type in do_setshow_command");
1136 fputs_filtered (".\n", stdout);
1139 error ("gdb internal error: bad cmd_type in do_setshow_command");
1140 (*c->function.sfunc) (NULL, from_tty, c);
1143 /* Show all the settings in a list of show commands. */
1146 cmd_show_list (list, from_tty, prefix)
1147 struct cmd_list_element *list;
1151 for (; list != NULL; list = list->next) {
1152 /* If we find a prefix, run its list, prefixing our output by its
1153 prefix (with "show " skipped). */
1154 if (list->prefixlist && !list->abbrev_flag)
1155 cmd_show_list (*list->prefixlist, from_tty, list->prefixname + 5);
1156 if (list->type == show_cmd)
1158 fputs_filtered (prefix, stdout);
1159 fputs_filtered (list->name, stdout);
1160 fputs_filtered (": ", stdout);
1161 do_setshow_command ((char *)NULL, from_tty, list);
1168 shell_escape (arg, from_tty)
1173 /* FIXME: what about errors (I don't know how GO32 system() handles
1176 #else /* Can fork. */
1177 int rc, status, pid;
1178 char *p, *user_shell;
1180 if ((user_shell = (char *) getenv ("SHELL")) == NULL)
1181 user_shell = "/bin/sh";
1183 /* Get the name of the shell for arg0 */
1184 if ((p = strrchr (user_shell, '/')) == NULL)
1187 p++; /* Get past '/' */
1189 if ((pid = fork()) == 0)
1192 execl (user_shell, p, 0);
1194 execl (user_shell, p, "-c", arg, 0);
1196 fprintf (stderr, "Exec of shell failed\n");
1201 while ((rc = wait (&status)) != pid && rc != -1)
1204 error ("Fork failed");
1205 #endif /* Can fork. */
1209 make_command (arg, from_tty)
1219 p = xmalloc (sizeof("make ") + strlen(arg));
1220 strcpy (p, "make ");
1221 strcpy (p + sizeof("make ")-1, arg);
1224 shell_escape (p, from_tty);
1228 show_user_1 (c, stream)
1229 struct cmd_list_element *c;
1232 register struct command_line *cmdlines;
1234 cmdlines = c->user_commands;
1237 fputs_filtered ("User command ", stream);
1238 fputs_filtered (c->name, stream);
1239 fputs_filtered (":\n", stream);
1242 fputs_filtered (cmdlines->line, stream);
1243 fputs_filtered ("\n", stream);
1244 cmdlines = cmdlines->next;
1246 fputs_filtered ("\n", stream);
1251 show_user (args, from_tty)
1255 struct cmd_list_element *c;
1256 extern struct cmd_list_element *cmdlist;
1260 c = lookup_cmd (&args, cmdlist, "", 0, 1);
1261 if (c->class != class_user)
1262 error ("Not a user command.");
1263 show_user_1 (c, stdout);
1267 for (c = cmdlist; c; c = c->next)
1269 if (c->class == class_user)
1270 show_user_1 (c, stdout);
1276 _initialize_command ()
1278 add_com ("shell", class_support, shell_escape,
1279 "Execute the rest of the line as a shell command. \n\
1280 With no arguments, run an inferior shell.");
1281 add_com ("make", class_support, make_command,
1282 "Run the ``make'' program using the rest of the line as arguments.");
1283 add_cmd ("user", no_class, show_user,
1284 "Show definitions of user defined commands.\n\
1285 Argument is the name of the user defined command.\n\
1286 With no argument, show definitions of all user defined commands.", &showlist);