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 *, GDB_FILE *));
37 make_command PARAMS ((char *, int));
40 shell_escape PARAMS ((char *, int));
43 parse_binary_operation PARAMS ((char *));
46 print_doc_line PARAMS ((GDB_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;
193 /* This is an empty "cfunc". */
195 not_just_help_class_command (args, from_tty)
201 /* This is an empty "sfunc". */
202 static void empty_sfunc PARAMS ((char *, int, struct cmd_list_element *));
205 empty_sfunc (args, from_tty, c)
208 struct cmd_list_element *c;
212 /* Add element named NAME to command list LIST (the list for set
213 or some sublist thereof).
214 CLASS is as in add_cmd.
215 VAR_TYPE is the kind of thing we are setting.
216 VAR is address of the variable being controlled by this command.
217 DOC is the documentation string. */
219 struct cmd_list_element *
220 add_set_cmd (name, class, var_type, var, doc, list)
222 enum command_class class;
226 struct cmd_list_element **list;
228 struct cmd_list_element *c
229 = add_cmd (name, class, NO_FUNCTION, doc, list);
232 c->var_type = var_type;
234 /* This needs to be something besides NO_FUNCTION so that this isn't
235 treated as a help class. */
236 c->function.sfunc = empty_sfunc;
240 /* Where SETCMD has already been added, add the corresponding show
241 command to LIST and return a pointer to it. */
242 struct cmd_list_element *
243 add_show_from_set (setcmd, list)
244 struct cmd_list_element *setcmd;
245 struct cmd_list_element **list;
247 struct cmd_list_element *showcmd =
248 (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element));
250 memcpy (showcmd, setcmd, sizeof (struct cmd_list_element));
251 delete_cmd (showcmd->name, list);
252 showcmd->type = show_cmd;
254 /* Replace "set " at start of docstring with "show ". */
255 if (setcmd->doc[0] == 'S' && setcmd->doc[1] == 'e'
256 && setcmd->doc[2] == 't' && setcmd->doc[3] == ' ')
257 showcmd->doc = concat ("Show ", setcmd->doc + 4, NULL);
259 fprintf_unfiltered (gdb_stderr, "GDB internal error: Bad docstring for set command\n");
261 showcmd->next = *list;
266 /* Remove the command named NAME from the command list. */
269 delete_cmd (name, list)
271 struct cmd_list_element **list;
273 register struct cmd_list_element *c;
274 struct cmd_list_element *p;
276 while (*list && STREQ ((*list)->name, name))
279 (*list)->hookee->hook = 0; /* Hook slips out of its mouth */
286 for (c = *list; c->next;)
288 if (STREQ (c->next->name, name))
291 c->next->hookee->hook = 0; /* hooked cmd gets away. */
301 /* This command really has to deal with two things:
302 * 1) I want documentation on *this string* (usually called by
303 * "help commandname").
304 * 2) I want documentation on *this list* (usually called by
305 * giving a command that requires subcommands. Also called by saying
308 * I am going to split this into two seperate comamnds, help_cmd and
313 help_cmd (command, stream)
317 struct cmd_list_element *c;
318 extern struct cmd_list_element *cmdlist;
322 help_list (cmdlist, "", all_classes, stream);
326 c = lookup_cmd (&command, cmdlist, "", 0, 0);
331 /* There are three cases here.
332 If c->prefixlist is nonzero, we have a prefix command.
333 Print its documentation, then list its subcommands.
335 If c->function is nonzero, we really have a command.
336 Print its documentation and return.
338 If c->function is zero, we have a class name.
339 Print its documentation (as if it were a command)
340 and then set class to the number of this class
341 so that the commands in the class will be listed. */
343 fputs_filtered (c->doc, stream);
344 fputs_filtered ("\n", stream);
346 if (c->prefixlist == 0 && c->function.cfunc != NULL)
348 fprintf_filtered (stream, "\n");
350 /* If this is a prefix command, print it's subcommands */
352 help_list (*c->prefixlist, c->prefixname, all_commands, stream);
354 /* If this is a class name, print all of the commands in the class */
355 if (c->function.cfunc == NULL)
356 help_list (cmdlist, "", c->class, stream);
359 fprintf_filtered (stream, "\nThis command has a hook defined: %s\n",
364 * Get a specific kind of help on a command list.
367 * CMDTYPE is the prefix to use in the title string.
368 * CLASS is the class with which to list the nodes of this list (see
369 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
370 * everything, ALL_CLASSES for just classes, and non-negative for only things
371 * in a specific class.
372 * and STREAM is the output stream on which to print things.
373 * If you call this routine with a class >= 0, it recurses.
376 help_list (list, cmdtype, class, stream)
377 struct cmd_list_element *list;
379 enum command_class class;
383 char *cmdtype1, *cmdtype2;
385 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
386 len = strlen (cmdtype);
387 cmdtype1 = (char *) alloca (len + 1);
389 cmdtype2 = (char *) alloca (len + 4);
394 strncpy (cmdtype1 + 1, cmdtype, len - 1);
396 strncpy (cmdtype2, cmdtype, len - 1);
397 strcpy (cmdtype2 + len - 1, " sub");
400 if (class == all_classes)
401 fprintf_filtered (stream, "List of classes of %scommands:\n\n", cmdtype2);
403 fprintf_filtered (stream, "List of %scommands:\n\n", cmdtype2);
405 help_cmd_list (list, class, cmdtype, (int)class >= 0, stream);
407 if (class == all_classes)
408 fprintf_filtered (stream, "\n\
409 Type \"help%s\" followed by a class name for a list of commands in that class.",
412 fprintf_filtered (stream, "\n\
413 Type \"help%s\" followed by %scommand name for full documentation.\n\
414 Command name abbreviations are allowed if unambiguous.\n",
418 /* Print only the first line of STR on STREAM. */
420 print_doc_line (stream, str)
424 static char *line_buffer = 0;
425 static int line_size;
431 line_buffer = (char *) xmalloc (line_size);
435 while (*p && *p != '\n' && *p != '.' && *p != ',')
437 if (p - str > line_size - 1)
439 line_size = p - str + 1;
440 free ((PTR)line_buffer);
441 line_buffer = (char *) xmalloc (line_size);
443 strncpy (line_buffer, str, p - str);
444 line_buffer[p - str] = '\0';
445 if (islower (line_buffer[0]))
446 line_buffer[0] = toupper (line_buffer[0]);
447 fputs_filtered (line_buffer, stream);
451 * Implement a help command on command list LIST.
452 * RECURSE should be non-zero if this should be done recursively on
453 * all sublists of LIST.
454 * PREFIX is the prefix to print before each command name.
455 * STREAM is the stream upon which the output should be written.
457 * A non-negative class number to list only commands in that
459 * ALL_COMMANDS to list all commands in list.
460 * ALL_CLASSES to list all classes in list.
462 * Note that RECURSE will be active on *all* sublists, not just the
463 * ones selected by the criteria above (ie. the selection mechanism
464 * is at the low level, not the high-level).
467 help_cmd_list (list, class, prefix, recurse, stream)
468 struct cmd_list_element *list;
469 enum command_class class;
474 register struct cmd_list_element *c;
476 for (c = list; c; c = c->next)
478 if (c->abbrev_flag == 0 &&
479 (class == all_commands
480 || (class == all_classes && c->function.cfunc == NULL)
481 || (class == c->class && c->function.cfunc != NULL)))
483 fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
484 print_doc_line (stream, c->doc);
485 fputs_filtered ("\n", stream);
488 && c->prefixlist != 0
489 && c->abbrev_flag == 0)
490 help_cmd_list (*c->prefixlist, class, c->prefixname, 1, stream);
494 /* This routine takes a line of TEXT and a CLIST in which to start the
495 lookup. When it returns it will have incremented the text pointer past
496 the section of text it matched, set *RESULT_LIST to point to the list in
497 which the last word was matched, and will return a pointer to the cmd
498 list element which the text matches. It will return NULL if no match at
499 all was possible. It will return -1 (cast appropriately, ick) if ambigous
500 matches are possible; in this case *RESULT_LIST will be set to point to
501 the list in which there are ambiguous choices (and *TEXT will be set to
502 the ambiguous text string).
504 If the located command was an abbreviation, this routine returns the base
505 command of the abbreviation.
507 It does no error reporting whatsoever; control will always return
508 to the superior routine.
510 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
511 at the prefix_command (ie. the best match) *or* (special case) will be NULL
512 if no prefix command was ever found. For example, in the case of "info a",
513 "info" matches without ambiguity, but "a" could be "args" or "address", so
514 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
515 RESULT_LIST should not be interpeted as a pointer to the beginning of a
516 list; it simply points to a specific command. In the case of an ambiguous
517 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
518 "info t" can be "info types" or "info target"; upon return *TEXT has been
519 advanced past "info ").
521 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
522 affect the operation).
524 This routine does *not* modify the text pointed to by TEXT.
526 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
527 are actually help classes rather than commands (i.e. the function field of
528 the struct cmd_list_element is NULL). */
530 struct cmd_list_element *
531 lookup_cmd_1 (text, clist, result_list, ignore_help_classes)
533 struct cmd_list_element *clist, **result_list;
534 int ignore_help_classes;
537 int len, tmp, nfound;
538 struct cmd_list_element *found, *c;
540 while (**text == ' ' || **text == '\t')
543 /* Treating underscores as part of command words is important
544 so that "set args_foo()" doesn't get interpreted as
545 "set args _foo()". */
547 *p && (isalnum(*p) || *p == '-' || *p == '_');
551 /* If nothing but whitespace, return 0. */
557 /* *text and p now bracket the first command word to lookup (and
558 it's length is len). We copy this into a local temporary,
559 converting to lower case as we go. */
561 command = (char *) alloca (len + 1);
562 for (tmp = 0; tmp < len; tmp++)
564 char x = (*text)[tmp];
565 command[tmp] = isupper(x) ? tolower(x) : x;
572 for (c = clist; c; c = c->next)
573 if (!strncmp (command, c->name, len)
574 && (!ignore_help_classes || c->function.cfunc))
578 if (c->name[len] == '\0')
585 /* If nothing matches, we have a simple failure. */
591 if (result_list != NULL)
592 /* Will be modified in calling routine
593 if we know what the prefix command is. */
595 return (struct cmd_list_element *) -1; /* Ambiguous. */
598 /* We've matched something on this list. Move text pointer forward. */
602 /* If this was an abbreviation, use the base command instead. */
604 if (found->cmd_pointer)
605 found = found->cmd_pointer;
607 /* If we found a prefix command, keep looking. */
609 if (found->prefixlist)
611 c = lookup_cmd_1 (text, *found->prefixlist, result_list,
612 ignore_help_classes);
615 /* Didn't find anything; this is as far as we got. */
616 if (result_list != NULL)
617 *result_list = clist;
620 else if (c == (struct cmd_list_element *) -1)
622 /* We've gotten this far properley, but the next step
623 is ambiguous. We need to set the result list to the best
624 we've found (if an inferior hasn't already set it). */
625 if (result_list != NULL)
627 /* This used to say *result_list = *found->prefixlist
628 If that was correct, need to modify the documentation
629 at the top of this function to clarify what is supposed
631 *result_list = found;
642 if (result_list != NULL)
643 *result_list = clist;
648 /* All this hair to move the space to the front of cmdtype */
651 undef_cmd_error (cmdtype, q)
654 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
662 /* Look up the contents of *LINE as a command in the command list LIST.
663 LIST is a chain of struct cmd_list_element's.
664 If it is found, return the struct cmd_list_element for that command
665 and update *LINE to point after the command name, at the first argument.
666 If not found, call error if ALLOW_UNKNOWN is zero
667 otherwise (or if error returns) return zero.
668 Call error if specified command is ambiguous,
669 unless ALLOW_UNKNOWN is negative.
670 CMDTYPE precedes the word "command" in the error message.
672 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
673 elements which are actually help classes rather than commands (i.e.
674 the function field of the struct cmd_list_element is 0). */
676 struct cmd_list_element *
677 lookup_cmd (line, list, cmdtype, allow_unknown, ignore_help_classes)
679 struct cmd_list_element *list;
682 int ignore_help_classes;
684 struct cmd_list_element *last_list = 0;
685 struct cmd_list_element *c =
686 lookup_cmd_1 (line, list, &last_list, ignore_help_classes);
687 char *ptr = (*line) + strlen (*line) - 1;
689 /* Clear off trailing whitespace. */
690 while (ptr >= *line && (*ptr == ' ' || *ptr == '\t'))
699 error ("Lack of needed %scommand", cmdtype);
704 while (isalnum(*p) || *p == '-')
707 q = (char *) alloca (p - *line + 1);
708 strncpy (q, *line, p - *line);
710 undef_cmd_error (cmdtype, q);
716 else if (c == (struct cmd_list_element *) -1)
718 /* Ambigous. Local values should be off prefixlist or called
720 int local_allow_unknown = (last_list ? last_list->allow_unknown :
722 char *local_cmdtype = last_list ? last_list->prefixname : cmdtype;
723 struct cmd_list_element *local_list =
724 (last_list ? *(last_list->prefixlist) : list);
726 if (local_allow_unknown < 0)
729 return last_list; /* Found something. */
731 return 0; /* Found nothing. */
735 /* Report as error. */
740 ((*line)[amb_len] && (*line)[amb_len] != ' '
741 && (*line)[amb_len] != '\t');
746 for (c = local_list; c; c = c->next)
747 if (!strncmp (*line, c->name, amb_len))
749 if (strlen (ambbuf) + strlen (c->name) + 6 < (int)sizeof ambbuf)
752 strcat (ambbuf, ", ");
753 strcat (ambbuf, c->name);
757 strcat (ambbuf, "..");
761 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype,
768 /* We've got something. It may still not be what the caller
769 wants (if this command *needs* a subcommand). */
770 while (**line == ' ' || **line == '\t')
773 if (c->prefixlist && **line && !c->allow_unknown)
774 undef_cmd_error (c->prefixname, *line);
776 /* Seems to be what he wants. Return it. */
783 /* Look up the contents of *LINE as a command in the command list LIST.
784 LIST is a chain of struct cmd_list_element's.
785 If it is found, return the struct cmd_list_element for that command
786 and update *LINE to point after the command name, at the first argument.
787 If not found, call error if ALLOW_UNKNOWN is zero
788 otherwise (or if error returns) return zero.
789 Call error if specified command is ambiguous,
790 unless ALLOW_UNKNOWN is negative.
791 CMDTYPE precedes the word "command" in the error message. */
793 struct cmd_list_element *
794 lookup_cmd (line, list, cmdtype, allow_unknown)
796 struct cmd_list_element *list;
801 register struct cmd_list_element *c, *found;
807 /* Skip leading whitespace. */
809 while (**line == ' ' || **line == '\t')
812 /* Clear out trailing whitespace. */
814 p = *line + strlen (*line);
815 while (p != *line && (p[-1] == ' ' || p[-1] == '\t'))
819 /* Find end of command name. */
822 while (*p == '-' || isalnum(*p))
825 /* Look up the command name.
826 If exact match, keep that.
827 Otherwise, take command abbreviated, if unique. Note that (in my
828 opinion) a null string does *not* indicate ambiguity; simply the
829 end of the argument. */
834 error ("Lack of needed %scommand", cmdtype);
838 /* Copy over to a local buffer, converting to lowercase on the way.
839 This is in case the command being parsed is a subcommand which
840 doesn't match anything, and that's ok. We want the original
841 untouched for the routine of the original command. */
843 processed_cmd = (char *) alloca (p - *line + 1);
844 for (cmd_len = 0; cmd_len < p - *line; cmd_len++)
846 char x = (*line)[cmd_len];
848 processed_cmd[cmd_len] = tolower(x);
850 processed_cmd[cmd_len] = x;
852 processed_cmd[cmd_len] = '\0';
854 /* Check all possibilities in the current command list. */
857 for (c = list; c; c = c->next)
859 if (!strncmp (processed_cmd, c->name, cmd_len))
863 if (c->name[cmd_len] == 0)
871 /* Report error for undefined command name. */
875 if (nfound > 1 && allow_unknown >= 0)
878 for (c = list; c; c = c->next)
879 if (!strncmp (processed_cmd, c->name, cmd_len))
881 if (strlen (ambbuf) + strlen (c->name) + 6 < sizeof ambbuf)
884 strcat (ambbuf, ", ");
885 strcat (ambbuf, c->name);
889 strcat (ambbuf, "..");
893 error ("Ambiguous %scommand \"%s\": %s.", cmdtype,
894 processed_cmd, ambbuf);
896 else if (!allow_unknown)
897 error ("Undefined %scommand: \"%s\".", cmdtype, processed_cmd);
901 /* Skip whitespace before the argument. */
903 while (*p == ' ' || *p == '\t') p++;
906 if (found->prefixlist && *p)
908 c = lookup_cmd (line, *found->prefixlist, found->prefixname,
909 found->allow_unknown);
918 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
920 /* Return a vector of char pointers which point to the different
921 possible completions in LIST of TEXT.
923 WORD points in the same buffer as TEXT, and completions should be
924 returned relative to this position. For example, suppose TEXT is "foo"
925 and we want to complete to "foobar". If WORD is "oo", return
926 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
929 complete_on_cmdlist (list, text, word)
930 struct cmd_list_element *list;
934 struct cmd_list_element *ptr;
936 int sizeof_matchlist;
938 int textlen = strlen (text);
940 sizeof_matchlist = 10;
941 matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
944 for (ptr = list; ptr; ptr = ptr->next)
945 if (!strncmp (ptr->name, text, textlen)
947 && (ptr->function.cfunc
950 if (matches == sizeof_matchlist)
952 sizeof_matchlist *= 2;
953 matchlist = (char **) xrealloc ((char *)matchlist,
958 matchlist[matches] = (char *)
959 xmalloc (strlen (word) + strlen (ptr->name) + 1);
961 strcpy (matchlist[matches], ptr->name);
962 else if (word > text)
964 /* Return some portion of ptr->name. */
965 strcpy (matchlist[matches], ptr->name + (word - text));
969 /* Return some of text plus ptr->name. */
970 strncpy (matchlist[matches], word, text - word);
971 matchlist[matches][text - word] = '\0';
972 strcat (matchlist[matches], ptr->name);
979 free ((PTR)matchlist);
984 matchlist = (char **) xrealloc ((char *)matchlist, ((matches + 1)
986 matchlist[matches] = (char *) 0;
993 parse_binary_operation (arg)
1001 length = strlen (arg);
1003 while (arg[length - 1] == ' ' || arg[length - 1] == '\t')
1006 if (!strncmp (arg, "on", length)
1007 || !strncmp (arg, "1", length)
1008 || !strncmp (arg, "yes", length))
1011 if (!strncmp (arg, "off", length)
1012 || !strncmp (arg, "0", length)
1013 || !strncmp (arg, "no", length))
1017 error ("\"on\" or \"off\" expected.");
1022 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
1023 of the argument, and FROM_TTY is nonzero if this command is being entered
1024 directly by the user (i.e. these are just like any other
1025 command). C is the command list element for the command. */
1027 do_setshow_command (arg, from_tty, c)
1030 struct cmd_list_element *c;
1032 if (c->type == set_cmd)
1034 switch (c->var_type)
1045 new = (char *) xmalloc (strlen (arg) + 2);
1047 while ((ch = *p++) != '\000')
1051 /* \ at end of argument is used after spaces
1052 so they won't be lost. */
1055 ch = parse_escape (&p);
1057 break; /* C loses */
1064 if (*(p - 1) != '\\')
1067 new = (char *) xrealloc (new, q - new);
1068 if (*(char **)c->var != NULL)
1069 free (*(char **)c->var);
1070 *(char **) c->var = new;
1073 case var_string_noescape:
1076 if (*(char **)c->var != NULL)
1077 free (*(char **)c->var);
1078 *(char **) c->var = savestring (arg, strlen (arg));
1082 error_no_arg ("filename to set it to.");
1083 if (*(char **)c->var != NULL)
1084 free (*(char **)c->var);
1085 *(char **)c->var = tilde_expand (arg);
1088 *(int *) c->var = parse_binary_operation (arg);
1092 error_no_arg ("integer to set it to.");
1093 *(unsigned int *) c->var = parse_and_eval_address (arg);
1094 if (*(unsigned int *) c->var == 0)
1095 *(unsigned int *) c->var = UINT_MAX;
1101 error_no_arg ("integer to set it to.");
1102 val = parse_and_eval_address (arg);
1104 *(int *) c->var = INT_MAX;
1105 else if (val >= INT_MAX)
1106 error ("integer %u out of range", val);
1108 *(int *) c->var = val;
1113 error_no_arg ("integer to set it to.");
1114 *(int *) c->var = parse_and_eval_address (arg);
1117 error ("gdb internal error: bad var_type in do_setshow_command");
1120 else if (c->type == show_cmd)
1122 /* Print doc minus "show" at start. */
1123 print_doc_line (gdb_stdout, c->doc + 5);
1125 fputs_filtered (" is ", gdb_stdout);
1127 switch (c->var_type)
1132 fputs_filtered ("\"", gdb_stdout);
1133 for (p = *(unsigned char **) c->var; *p != '\0'; p++)
1134 gdb_printchar (*p, gdb_stdout, '"');
1135 fputs_filtered ("\"", gdb_stdout);
1138 case var_string_noescape:
1140 fputs_filtered ("\"", gdb_stdout);
1141 fputs_filtered (*(char **) c->var, gdb_stdout);
1142 fputs_filtered ("\"", gdb_stdout);
1145 fputs_filtered (*(int *) c->var ? "on" : "off", gdb_stdout);
1148 if (*(unsigned int *) c->var == UINT_MAX) {
1149 fputs_filtered ("unlimited", gdb_stdout);
1152 /* else fall through */
1154 fprintf_filtered (gdb_stdout, "%u", *(unsigned int *) c->var);
1157 if (*(int *) c->var == INT_MAX)
1159 fputs_filtered ("unlimited", gdb_stdout);
1162 fprintf_filtered (gdb_stdout, "%d", *(int *) c->var);
1166 error ("gdb internal error: bad var_type in do_setshow_command");
1168 fputs_filtered (".\n", gdb_stdout);
1171 error ("gdb internal error: bad cmd_type in do_setshow_command");
1172 (*c->function.sfunc) (NULL, from_tty, c);
1175 /* Show all the settings in a list of show commands. */
1178 cmd_show_list (list, from_tty, prefix)
1179 struct cmd_list_element *list;
1183 for (; list != NULL; list = list->next) {
1184 /* If we find a prefix, run its list, prefixing our output by its
1185 prefix (with "show " skipped). */
1186 if (list->prefixlist && !list->abbrev_flag)
1187 cmd_show_list (*list->prefixlist, from_tty, list->prefixname + 5);
1188 if (list->type == show_cmd)
1190 fputs_filtered (prefix, gdb_stdout);
1191 fputs_filtered (list->name, gdb_stdout);
1192 fputs_filtered (": ", gdb_stdout);
1193 do_setshow_command ((char *)NULL, from_tty, list);
1200 shell_escape (arg, from_tty)
1205 /* FIXME: what about errors (I don't know how GO32 system() handles
1208 #else /* Can fork. */
1209 int rc, status, pid;
1210 char *p, *user_shell;
1212 if ((user_shell = (char *) getenv ("SHELL")) == NULL)
1213 user_shell = "/bin/sh";
1215 /* Get the name of the shell for arg0 */
1216 if ((p = strrchr (user_shell, '/')) == NULL)
1219 p++; /* Get past '/' */
1221 if ((pid = fork()) == 0)
1224 execl (user_shell, p, 0);
1226 execl (user_shell, p, "-c", arg, 0);
1228 fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell,
1229 safe_strerror (errno));
1230 gdb_flush (gdb_stderr);
1235 while ((rc = wait (&status)) != pid && rc != -1)
1238 error ("Fork failed");
1239 #endif /* Can fork. */
1243 make_command (arg, from_tty)
1253 p = xmalloc (sizeof("make ") + strlen(arg));
1254 strcpy (p, "make ");
1255 strcpy (p + sizeof("make ")-1, arg);
1258 shell_escape (p, from_tty);
1262 show_user_1 (c, stream)
1263 struct cmd_list_element *c;
1266 register struct command_line *cmdlines;
1268 cmdlines = c->user_commands;
1271 fputs_filtered ("User command ", stream);
1272 fputs_filtered (c->name, stream);
1273 fputs_filtered (":\n", stream);
1276 fputs_filtered (cmdlines->line, stream);
1277 fputs_filtered ("\n", stream);
1278 cmdlines = cmdlines->next;
1280 fputs_filtered ("\n", stream);
1285 show_user (args, from_tty)
1289 struct cmd_list_element *c;
1290 extern struct cmd_list_element *cmdlist;
1294 c = lookup_cmd (&args, cmdlist, "", 0, 1);
1295 if (c->class != class_user)
1296 error ("Not a user command.");
1297 show_user_1 (c, gdb_stdout);
1301 for (c = cmdlist; c; c = c->next)
1303 if (c->class == class_user)
1304 show_user_1 (c, gdb_stdout);
1310 _initialize_command ()
1312 add_com ("shell", class_support, shell_escape,
1313 "Execute the rest of the line as a shell command. \n\
1314 With no arguments, run an inferior shell.");
1315 add_com ("make", class_support, make_command,
1316 "Run the ``make'' program using the rest of the line as arguments.");
1317 add_cmd ("user", no_class, show_user,
1318 "Show definitions of user defined commands.\n\
1319 Argument is the name of the user defined command.\n\
1320 With no argument, show definitions of all user defined commands.", &showlist);