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. In the case of an ambiguous
508 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
509 "info t" can be "info types" or "info target"; upon return *TEXT has been
510 advanced past "info ").
512 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
513 affect the operation).
515 This routine does *not* modify the text pointed to by TEXT.
517 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
518 are actually help classes rather than commands (i.e. the function field of
519 the struct cmd_list_element is NULL). */
521 struct cmd_list_element *
522 lookup_cmd_1 (text, clist, result_list, ignore_help_classes)
524 struct cmd_list_element *clist, **result_list;
525 int ignore_help_classes;
528 int len, tmp, nfound;
529 struct cmd_list_element *found, *c;
531 while (**text == ' ' || **text == '\t')
534 /* Treating underscores as part of command words is important
535 so that "set args_foo()" doesn't get interpreted as
536 "set args _foo()". */
538 *p && (isalnum(*p) || *p == '-' || *p == '_');
542 /* If nothing but whitespace, return 0. */
548 /* *text and p now bracket the first command word to lookup (and
549 it's length is len). We copy this into a local temporary,
550 converting to lower case as we go. */
552 command = (char *) alloca (len + 1);
553 for (tmp = 0; tmp < len; tmp++)
555 char x = (*text)[tmp];
556 command[tmp] = isupper(x) ? tolower(x) : x;
563 for (c = clist; c; c = c->next)
564 if (!strncmp (command, c->name, len)
565 && (!ignore_help_classes || c->function.cfunc))
569 if (c->name[len] == '\0')
576 /* If nothing matches, we have a simple failure. */
582 if (result_list != NULL)
583 /* Will be modified in calling routine
584 if we know what the prefix command is. */
586 return (struct cmd_list_element *) -1; /* Ambiguous. */
589 /* We've matched something on this list. Move text pointer forward. */
593 /* If this was an abbreviation, use the base command instead. */
595 if (found->cmd_pointer)
596 found = found->cmd_pointer;
598 /* If we found a prefix command, keep looking. */
600 if (found->prefixlist)
602 c = lookup_cmd_1 (text, *found->prefixlist, result_list,
603 ignore_help_classes);
606 /* Didn't find anything; this is as far as we got. */
607 if (result_list != NULL)
608 *result_list = clist;
611 else if (c == (struct cmd_list_element *) -1)
613 /* We've gotten this far properley, but the next step
614 is ambiguous. We need to set the result list to the best
615 we've found (if an inferior hasn't already set it). */
616 if (result_list != NULL)
618 /* This used to say *result_list = *found->prefixlist
619 If that was correct, need to modify the documentation
620 at the top of this function to clarify what is supposed
622 *result_list = found;
633 if (result_list != NULL)
634 *result_list = clist;
639 /* All this hair to move the space to the front of cmdtype */
642 undef_cmd_error (cmdtype, q)
645 error ("Undefined %scommand: \"%s\". Try \"help%s%.*s\".",
653 /* Look up the contents of *LINE as a command in the command list LIST.
654 LIST is a chain of struct cmd_list_element's.
655 If it is found, return the struct cmd_list_element for that command
656 and update *LINE to point after the command name, at the first argument.
657 If not found, call error if ALLOW_UNKNOWN is zero
658 otherwise (or if error returns) return zero.
659 Call error if specified command is ambiguous,
660 unless ALLOW_UNKNOWN is negative.
661 CMDTYPE precedes the word "command" in the error message.
663 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
664 elements which are actually help classes rather than commands (i.e.
665 the function field of the struct cmd_list_element is 0). */
667 struct cmd_list_element *
668 lookup_cmd (line, list, cmdtype, allow_unknown, ignore_help_classes)
670 struct cmd_list_element *list;
673 int ignore_help_classes;
675 struct cmd_list_element *last_list = 0;
676 struct cmd_list_element *c =
677 lookup_cmd_1 (line, list, &last_list, ignore_help_classes);
678 char *ptr = (*line) + strlen (*line) - 1;
680 /* Clear off trailing whitespace. */
681 while (ptr >= *line && (*ptr == ' ' || *ptr == '\t'))
690 error ("Lack of needed %scommand", cmdtype);
695 while (isalnum(*p) || *p == '-')
698 q = (char *) alloca (p - *line + 1);
699 strncpy (q, *line, p - *line);
701 undef_cmd_error (cmdtype, q);
707 else if (c == (struct cmd_list_element *) -1)
709 /* Ambigous. Local values should be off prefixlist or called
711 int local_allow_unknown = (last_list ? last_list->allow_unknown :
713 char *local_cmdtype = last_list ? last_list->prefixname : cmdtype;
714 struct cmd_list_element *local_list =
715 (last_list ? *(last_list->prefixlist) : list);
717 if (local_allow_unknown < 0)
720 return last_list; /* Found something. */
722 return 0; /* Found nothing. */
726 /* Report as error. */
731 ((*line)[amb_len] && (*line)[amb_len] != ' '
732 && (*line)[amb_len] != '\t');
737 for (c = local_list; c; c = c->next)
738 if (!strncmp (*line, c->name, amb_len))
740 if (strlen (ambbuf) + strlen (c->name) + 6 < (int)sizeof ambbuf)
743 strcat (ambbuf, ", ");
744 strcat (ambbuf, c->name);
748 strcat (ambbuf, "..");
752 error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype,
759 /* We've got something. It may still not be what the caller
760 wants (if this command *needs* a subcommand). */
761 while (**line == ' ' || **line == '\t')
764 if (c->prefixlist && **line && !c->allow_unknown)
765 undef_cmd_error (c->prefixname, *line);
767 /* Seems to be what he wants. Return it. */
774 /* Look up the contents of *LINE as a command in the command list LIST.
775 LIST is a chain of struct cmd_list_element's.
776 If it is found, return the struct cmd_list_element for that command
777 and update *LINE to point after the command name, at the first argument.
778 If not found, call error if ALLOW_UNKNOWN is zero
779 otherwise (or if error returns) return zero.
780 Call error if specified command is ambiguous,
781 unless ALLOW_UNKNOWN is negative.
782 CMDTYPE precedes the word "command" in the error message. */
784 struct cmd_list_element *
785 lookup_cmd (line, list, cmdtype, allow_unknown)
787 struct cmd_list_element *list;
792 register struct cmd_list_element *c, *found;
798 /* Skip leading whitespace. */
800 while (**line == ' ' || **line == '\t')
803 /* Clear out trailing whitespace. */
805 p = *line + strlen (*line);
806 while (p != *line && (p[-1] == ' ' || p[-1] == '\t'))
810 /* Find end of command name. */
813 while (*p == '-' || isalnum(*p))
816 /* Look up the command name.
817 If exact match, keep that.
818 Otherwise, take command abbreviated, if unique. Note that (in my
819 opinion) a null string does *not* indicate ambiguity; simply the
820 end of the argument. */
825 error ("Lack of needed %scommand", cmdtype);
829 /* Copy over to a local buffer, converting to lowercase on the way.
830 This is in case the command being parsed is a subcommand which
831 doesn't match anything, and that's ok. We want the original
832 untouched for the routine of the original command. */
834 processed_cmd = (char *) alloca (p - *line + 1);
835 for (cmd_len = 0; cmd_len < p - *line; cmd_len++)
837 char x = (*line)[cmd_len];
839 processed_cmd[cmd_len] = tolower(x);
841 processed_cmd[cmd_len] = x;
843 processed_cmd[cmd_len] = '\0';
845 /* Check all possibilities in the current command list. */
848 for (c = list; c; c = c->next)
850 if (!strncmp (processed_cmd, c->name, cmd_len))
854 if (c->name[cmd_len] == 0)
862 /* Report error for undefined command name. */
866 if (nfound > 1 && allow_unknown >= 0)
869 for (c = list; c; c = c->next)
870 if (!strncmp (processed_cmd, c->name, cmd_len))
872 if (strlen (ambbuf) + strlen (c->name) + 6 < sizeof ambbuf)
875 strcat (ambbuf, ", ");
876 strcat (ambbuf, c->name);
880 strcat (ambbuf, "..");
884 error ("Ambiguous %scommand \"%s\": %s.", cmdtype,
885 processed_cmd, ambbuf);
887 else if (!allow_unknown)
888 error ("Undefined %scommand: \"%s\".", cmdtype, processed_cmd);
892 /* Skip whitespace before the argument. */
894 while (*p == ' ' || *p == '\t') p++;
897 if (found->prefixlist && *p)
899 c = lookup_cmd (line, *found->prefixlist, found->prefixname,
900 found->allow_unknown);
909 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
911 /* Return a vector of char pointers which point to the different
912 possible completions in LIST of TEXT.
914 WORD points in the same buffer as TEXT, and completions should be
915 returned relative to this position. For example, suppose TEXT is "foo"
916 and we want to complete to "foobar". If WORD is "oo", return
917 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
920 complete_on_cmdlist (list, text, word)
921 struct cmd_list_element *list;
925 struct cmd_list_element *ptr;
927 int sizeof_matchlist;
929 int textlen = strlen (text);
931 sizeof_matchlist = 10;
932 matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *));
935 for (ptr = list; ptr; ptr = ptr->next)
936 if (!strncmp (ptr->name, text, textlen)
938 && (ptr->function.cfunc
941 if (matches == sizeof_matchlist)
943 sizeof_matchlist *= 2;
944 matchlist = (char **) xrealloc ((char *)matchlist,
949 matchlist[matches] = (char *)
950 xmalloc (strlen (word) + strlen (ptr->name) + 1);
952 strcpy (matchlist[matches], ptr->name);
953 else if (word > text)
955 /* Return some portion of ptr->name. */
956 strcpy (matchlist[matches], ptr->name + (word - text));
960 /* Return some of text plus ptr->name. */
961 strncpy (matchlist[matches], word, text - word);
962 matchlist[matches][text - word] = '\0';
963 strcat (matchlist[matches], ptr->name);
970 free ((PTR)matchlist);
975 matchlist = (char **) xrealloc ((char *)matchlist, ((matches + 1)
977 matchlist[matches] = (char *) 0;
984 parse_binary_operation (arg)
992 length = strlen (arg);
994 while (arg[length - 1] == ' ' || arg[length - 1] == '\t')
997 if (!strncmp (arg, "on", length)
998 || !strncmp (arg, "1", length)
999 || !strncmp (arg, "yes", length))
1002 if (!strncmp (arg, "off", length)
1003 || !strncmp (arg, "0", length)
1004 || !strncmp (arg, "no", length))
1008 error ("\"on\" or \"off\" expected.");
1013 /* Do a "set" or "show" command. ARG is NULL if no argument, or the text
1014 of the argument, and FROM_TTY is nonzero if this command is being entered
1015 directly by the user (i.e. these are just like any other
1016 command). C is the command list element for the command. */
1018 do_setshow_command (arg, from_tty, c)
1021 struct cmd_list_element *c;
1023 if (c->type == set_cmd)
1025 switch (c->var_type)
1036 new = (char *) xmalloc (strlen (arg) + 2);
1038 while ((ch = *p++) != '\000')
1042 /* \ at end of argument is used after spaces
1043 so they won't be lost. */
1046 ch = parse_escape (&p);
1048 break; /* C loses */
1055 if (*(p - 1) != '\\')
1058 new = (char *) xrealloc (new, q - new);
1059 if (*(char **)c->var != NULL)
1060 free (*(char **)c->var);
1061 *(char **) c->var = new;
1064 case var_string_noescape:
1067 if (*(char **)c->var != NULL)
1068 free (*(char **)c->var);
1069 *(char **) c->var = savestring (arg, strlen (arg));
1073 error_no_arg ("filename to set it to.");
1074 if (*(char **)c->var != NULL)
1075 free (*(char **)c->var);
1076 *(char **)c->var = tilde_expand (arg);
1079 *(int *) c->var = parse_binary_operation (arg);
1083 error_no_arg ("integer to set it to.");
1084 *(unsigned int *) c->var = parse_and_eval_address (arg);
1085 if (*(unsigned int *) c->var == 0)
1086 *(unsigned int *) c->var = UINT_MAX;
1092 error_no_arg ("integer to set it to.");
1093 val = parse_and_eval_address (arg);
1095 *(int *) c->var = INT_MAX;
1096 else if (val >= INT_MAX)
1097 error ("integer %u out of range", val);
1099 *(int *) c->var = val;
1104 error_no_arg ("integer to set it to.");
1105 *(int *) c->var = parse_and_eval_address (arg);
1108 error ("gdb internal error: bad var_type in do_setshow_command");
1111 else if (c->type == show_cmd)
1113 /* Print doc minus "show" at start. */
1114 print_doc_line (stdout, c->doc + 5);
1116 fputs_filtered (" is ", stdout);
1118 switch (c->var_type)
1123 fputs_filtered ("\"", stdout);
1124 for (p = *(unsigned char **) c->var; *p != '\0'; p++)
1125 gdb_printchar (*p, stdout, '"');
1126 fputs_filtered ("\"", stdout);
1129 case var_string_noescape:
1131 fputs_filtered ("\"", stdout);
1132 fputs_filtered (*(char **) c->var, stdout);
1133 fputs_filtered ("\"", stdout);
1136 fputs_filtered (*(int *) c->var ? "on" : "off", stdout);
1139 if (*(unsigned int *) c->var == UINT_MAX) {
1140 fputs_filtered ("unlimited", stdout);
1143 /* else fall through */
1145 fprintf_filtered (stdout, "%u", *(unsigned int *) c->var);
1148 if (*(int *) c->var == INT_MAX)
1150 fputs_filtered ("unlimited", stdout);
1153 fprintf_filtered (stdout, "%d", *(int *) c->var);
1157 error ("gdb internal error: bad var_type in do_setshow_command");
1159 fputs_filtered (".\n", stdout);
1162 error ("gdb internal error: bad cmd_type in do_setshow_command");
1163 (*c->function.sfunc) (NULL, from_tty, c);
1166 /* Show all the settings in a list of show commands. */
1169 cmd_show_list (list, from_tty, prefix)
1170 struct cmd_list_element *list;
1174 for (; list != NULL; list = list->next) {
1175 /* If we find a prefix, run its list, prefixing our output by its
1176 prefix (with "show " skipped). */
1177 if (list->prefixlist && !list->abbrev_flag)
1178 cmd_show_list (*list->prefixlist, from_tty, list->prefixname + 5);
1179 if (list->type == show_cmd)
1181 fputs_filtered (prefix, stdout);
1182 fputs_filtered (list->name, stdout);
1183 fputs_filtered (": ", stdout);
1184 do_setshow_command ((char *)NULL, from_tty, list);
1191 shell_escape (arg, from_tty)
1196 /* FIXME: what about errors (I don't know how GO32 system() handles
1199 #else /* Can fork. */
1200 int rc, status, pid;
1201 char *p, *user_shell;
1203 if ((user_shell = (char *) getenv ("SHELL")) == NULL)
1204 user_shell = "/bin/sh";
1206 /* Get the name of the shell for arg0 */
1207 if ((p = strrchr (user_shell, '/')) == NULL)
1210 p++; /* Get past '/' */
1212 if ((pid = fork()) == 0)
1215 execl (user_shell, p, 0);
1217 execl (user_shell, p, "-c", arg, 0);
1219 fprintf (stderr, "Exec of shell failed\n");
1224 while ((rc = wait (&status)) != pid && rc != -1)
1227 error ("Fork failed");
1228 #endif /* Can fork. */
1232 make_command (arg, from_tty)
1242 p = xmalloc (sizeof("make ") + strlen(arg));
1243 strcpy (p, "make ");
1244 strcpy (p + sizeof("make ")-1, arg);
1247 shell_escape (p, from_tty);
1251 show_user_1 (c, stream)
1252 struct cmd_list_element *c;
1255 register struct command_line *cmdlines;
1257 cmdlines = c->user_commands;
1260 fputs_filtered ("User command ", stream);
1261 fputs_filtered (c->name, stream);
1262 fputs_filtered (":\n", stream);
1265 fputs_filtered (cmdlines->line, stream);
1266 fputs_filtered ("\n", stream);
1267 cmdlines = cmdlines->next;
1269 fputs_filtered ("\n", stream);
1274 show_user (args, from_tty)
1278 struct cmd_list_element *c;
1279 extern struct cmd_list_element *cmdlist;
1283 c = lookup_cmd (&args, cmdlist, "", 0, 1);
1284 if (c->class != class_user)
1285 error ("Not a user command.");
1286 show_user_1 (c, stdout);
1290 for (c = cmdlist; c; c = c->next)
1292 if (c->class == class_user)
1293 show_user_1 (c, stdout);
1299 _initialize_command ()
1301 add_com ("shell", class_support, shell_escape,
1302 "Execute the rest of the line as a shell command. \n\
1303 With no arguments, run an inferior shell.");
1304 add_com ("make", class_support, make_command,
1305 "Run the ``make'' program using the rest of the line as arguments.");
1306 add_cmd ("user", no_class, show_user,
1307 "Show definitions of user defined commands.\n\
1308 Argument is the name of the user defined command.\n\
1309 With no argument, show definitions of all user defined commands.", &showlist);