- dont_repeat ();
- p = command_line_input ((char *) NULL, instream == stdin);
- if (p == NULL)
- /* Treat end of file like "end". */
- break;
-
- /* Remove leading and trailing blanks. */
- while (*p == ' ' || *p == '\t') p++;
- p1 = p + strlen (p);
- while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t')) p1--;
-
- /* Is this "end"? */
- if (p1 - p == 3 && !strncmp (p, "end", 3))
- break;
-
- /* No => add this line to the chain of command lines. */
- next = (struct command_line *) xmalloc (sizeof (struct command_line));
- next->line = savestring (p, p1 - p);
- next->next = 0;
- if (tail)
- {
- tail->next = next;
- }
- else
- {
- /* We just read the first line.
- From now on, arrange to throw away the lines we have
- if we quit or get an error while inside this function. */
- first = next;
- old_chain = make_cleanup (free_command_lines, &first);
- }
- tail = next;
- }
-
- dont_repeat ();
-
- /* Now we are about to return the chain to our caller,
- so freeing it becomes his responsibility. */
- if (first)
- discard_cleanups (old_chain);
- return first;
-}
-
-/* Free a chain of struct command_line's. */
-
-void
-free_command_lines (lptr)
- struct command_line **lptr;
-{
- register struct command_line *l = *lptr;
- register struct command_line *next;
-
- while (l)
- {
- next = l->next;
- free (l->line);
- free ((PTR)l);
- l = next;
- }
-}
-\f
-/* Add an element to the list of info subcommands. */
-
-void
-add_info (name, fun, doc)
- char *name;
- void (*fun) PARAMS ((char *, int));
- char *doc;
-{
- add_cmd (name, no_class, fun, doc, &infolist);
-}
-
-/* Add an alias to the list of info subcommands. */
-
-void
-add_info_alias (name, oldname, abbrev_flag)
- char *name;
- char *oldname;
- int abbrev_flag;
-{
- add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
-}
-
-/* The "info" command is defined as a prefix, with allow_unknown = 0.
- Therefore, its own definition is called only for "info" with no args. */
-
-/* ARGSUSED */
-static void
-info_command (arg, from_tty)
- char *arg;
- int from_tty;
-{
- printf ("\"info\" must be followed by the name of an info command.\n");
- help_list (infolist, "info ", -1, stdout);
-}
-
-/* The "show" command with no arguments shows all the settings. */
-
-/* ARGSUSED */
-static void
-show_command (arg, from_tty)
- char *arg;
- int from_tty;
-{
- cmd_show_list (showlist, from_tty, "");
-}
-\f
-/* Add an element to the list of commands. */
-
-void
-add_com (name, class, fun, doc)
- char *name;
- enum command_class class;
- void (*fun) PARAMS ((char *, int));
- char *doc;
-{
- add_cmd (name, class, fun, doc, &cmdlist);
-}
-
-/* Add an alias or abbreviation command to the list of commands. */
-
-void
-add_com_alias (name, oldname, class, abbrev_flag)
- char *name;
- char *oldname;
- enum command_class class;
- int abbrev_flag;
-{
- add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
-}
-
-void
-error_no_arg (why)
- char *why;
-{
- error ("Argument required (%s).", why);
-}
-
-/* ARGSUSED */
-static void
-help_command (command, from_tty)
- char *command;
- int from_tty; /* Ignored */
-{
- help_cmd (command, stdout);
-}
-\f
-static void
-validate_comname (comname)
- char *comname;
-{
- register char *p;
-
- if (comname == 0)
- error_no_arg ("name of command to define");
-
- p = comname;
- while (*p)
- {
- if (!isalnum(*p) && *p != '-')
- error ("Junk in argument list: \"%s\"", p);
- p++;
- }
-}
-
-/* This is just a placeholder in the command data structures. */
-static void
-user_defined_command (ignore, from_tty)
- char *ignore;
- int from_tty;
-{
-}
-
-static void
-define_command (comname, from_tty)
- char *comname;
- int from_tty;
-{
- register struct command_line *cmds;
- register struct cmd_list_element *c, *newc, *hookc = 0;
- char *tem = comname;
-#define HOOK_STRING "hook-"
-#define HOOK_LEN 5
-
- validate_comname (comname);
-
- /* Look it up, and verify that we got an exact match. */
- c = lookup_cmd (&tem, cmdlist, "", -1, 1);
- if (c && !STREQ (comname, c->name))
- c = 0;
-
- if (c)
- {
- if (c->class == class_user || c->class == class_alias)
- tem = "Redefine command \"%s\"? ";
- else
- tem = "Really redefine built-in command \"%s\"? ";
- if (!query (tem, c->name))
- error ("Command \"%s\" not redefined.", c->name);
- }
-
- /* If this new command is a hook, then mark the command which it
- is hooking. Note that we allow hooking `help' commands, so that
- we can hook the `stop' pseudo-command. */
-
- if (!strncmp (comname, HOOK_STRING, HOOK_LEN))
- {
- /* Look up cmd it hooks, and verify that we got an exact match. */
- tem = comname+HOOK_LEN;
- hookc = lookup_cmd (&tem, cmdlist, "", -1, 0);
- if (hookc && !STREQ (comname+HOOK_LEN, hookc->name))
- hookc = 0;
- if (!hookc)
- {
- warning ("Your new `%s' command does not hook any existing command.",
- comname);
- if (!query ("Proceed? ", (char *)0))
- error ("Not confirmed.");
- }
- }
-
- comname = savestring (comname, strlen (comname));
-
- /* If the rest of the commands will be case insensitive, this one
- should behave in the same manner. */
- for (tem = comname; *tem; tem++)
- if (isupper(*tem)) *tem = tolower(*tem);
-
- if (from_tty)
- {
- printf ("Type commands for definition of \"%s\".\n\
-End with a line saying just \"end\".\n", comname);
- fflush (stdout);
- }
-
- cmds = read_command_lines ();
-
- if (c && c->class == class_user)
- free_command_lines (&c->user_commands);
-
- newc = add_cmd (comname, class_user, user_defined_command,
- (c && c->class == class_user)
- ? c->doc : savestring ("User-defined.", 13), &cmdlist);
- newc->user_commands = cmds;
-
- /* If this new command is a hook, then mark both commands as being
- tied. */
- if (hookc)
- {
- hookc->hook = newc; /* Target gets hooked. */
- newc->hookee = hookc; /* We are marked as hooking target cmd. */
- }
-}
-
-static void
-document_command (comname, from_tty)
- char *comname;
- int from_tty;
-{
- struct command_line *doclines;
- register struct cmd_list_element *c;
- char *tem = comname;
-
- validate_comname (comname);
-
- c = lookup_cmd (&tem, cmdlist, "", 0, 1);
-
- if (c->class != class_user)
- error ("Command \"%s\" is built-in.", comname);
-
- if (from_tty)
- printf ("Type documentation for \"%s\".\n\
-End with a line saying just \"end\".\n", comname);
-
- doclines = read_command_lines ();
-
- if (c->doc) free (c->doc);
-
- {
- register struct command_line *cl1;
- register int len = 0;
-
- for (cl1 = doclines; cl1; cl1 = cl1->next)
- len += strlen (cl1->line) + 1;
-
- c->doc = (char *) xmalloc (len + 1);
- *c->doc = 0;
-
- for (cl1 = doclines; cl1; cl1 = cl1->next)
- {
- strcat (c->doc, cl1->line);
- if (cl1->next)
- strcat (c->doc, "\n");
- }
- }
-
- free_command_lines (&doclines);
-}
-\f
-static void
-print_gnu_advertisement()
-{
- printf ("\
-GDB is free software and you are welcome to distribute copies of it\n\
- under certain conditions; type \"show copying\" to see the conditions.\n\
-There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
-");
-}
-
-static void
-print_gdb_version (stream)
- FILE *stream;
-{
- fprintf_filtered (stream, "\
-GDB %s (%s", version, host_canonical);
-
- if (strcmp(host_canonical, target_canonical))
- fprintf_filtered (stream, " --target %s", target_canonical);
-
- fprintf_filtered (stream, "), ");
- wrap_here("");
- fprintf_filtered (stream, "Copyright 1993 Free Software Foundation, Inc.");
-}
-
-/* ARGSUSED */
-static void
-show_version (args, from_tty)
- char *args;
- int from_tty;
-{
- immediate_quit++;
- print_gnu_advertisement ();
- print_gdb_version (stdout);
- printf_filtered ("\n");
- immediate_quit--;
-}
-\f
-/* xgdb calls this to reprint the usual GDB prompt. */
-
-void
-print_prompt ()
-{
- printf ("%s", prompt);
- fflush (stdout);
-}
-\f
-static void
-quit_command (args, from_tty)
- char *args;
- int from_tty;
-{
- if (inferior_pid != 0 && target_has_execution)
- {
- if (attach_flag)
- {
- if (query ("The program is running. Quit anyway (and detach it)? "))
- target_detach (args, from_tty);
- else
- error ("Not confirmed.");
- }
- else
- {
- if (query ("The program is running. Quit anyway (and kill it)? "))
- target_kill ();
- else
- error ("Not confirmed.");
- }
- }
- /* Save the history information if it is appropriate to do so. */
- if (write_history_p && history_filename)
- write_history (history_filename);
- exit (0);
-}
-
-/* Returns whether GDB is running on a terminal and whether the user
- desires that questions be asked of them on that terminal. */
-
-int
-input_from_terminal_p ()
-{
- return gdb_has_a_terminal () && (instream == stdin) & caution;
-}
-\f
-/* ARGSUSED */
-static void
-pwd_command (args, from_tty)
- char *args;
- int from_tty;
-{
- if (args) error ("The \"pwd\" command does not take an argument: %s", args);
- getcwd (dirbuf, sizeof (dirbuf));
-
- if (!STREQ (dirbuf, current_directory))
- printf ("Working directory %s\n (canonically %s).\n",
- current_directory, dirbuf);
- else
- printf ("Working directory %s.\n", current_directory);
-}
-
-static void
-cd_command (dir, from_tty)
- char *dir;
- int from_tty;
-{
- int len;
- /* Found something other than leading repetitions of "/..". */
- int found_real_path;
- char *p;
-
- /* If the new directory is absolute, repeat is a no-op; if relative,
- repeat might be useful but is more likely to be a mistake. */
- dont_repeat ();
-
- if (dir == 0)
- error_no_arg ("new working directory");
-
- dir = tilde_expand (dir);
- make_cleanup (free, dir);
-
- if (chdir (dir) < 0)
- perror_with_name (dir);
-
- len = strlen (dir);
- dir = savestring (dir, len - (len > 1 && dir[len-1] == '/'));
- if (dir[0] == '/')
- current_directory = dir;
- else
- {
- if (current_directory[0] == '/' && current_directory[1] == '\0')
- current_directory = concat (current_directory, dir, NULL);
- else
- current_directory = concat (current_directory, "/", dir, NULL);
- free (dir);
- }
-
- /* Now simplify any occurrences of `.' and `..' in the pathname. */
-
- found_real_path = 0;
- for (p = current_directory; *p;)
- {
- if (p[0] == '/' && p[1] == '.' && (p[2] == 0 || p[2] == '/'))
- strcpy (p, p + 2);
- else if (p[0] == '/' && p[1] == '.' && p[2] == '.'
- && (p[3] == 0 || p[3] == '/'))
- {
- if (found_real_path)
- {
- /* Search backwards for the directory just before the "/.."
- and obliterate it and the "/..". */
- char *q = p;
- while (q != current_directory && q[-1] != '/')
- --q;
-
- if (q == current_directory)
- /* current_directory is
- a relative pathname ("can't happen"--leave it alone). */
- ++p;
- else
- {
- strcpy (q - 1, p + 3);
- p = q - 1;
- }
- }
- else
- /* We are dealing with leading repetitions of "/..", for example
- "/../..", which is the Mach super-root. */
- p += 3;
- }
- else
- {
- found_real_path = 1;
- ++p;
- }
- }
-
- forget_cached_source_info ();
-
- if (from_tty)
- pwd_command ((char *) 0, 1);
-}
-\f
-/* ARGSUSED */
-static void
-source_command (args, from_tty)
- char *args;
- int from_tty;
-{
- FILE *stream;
- struct cleanup *cleanups;
- char *file = args;
-
- if (file == NULL)
- {
- error ("source command requires pathname of file to source.");
- }
-
- file = tilde_expand (file);
- make_cleanup (free, file);
-
- stream = fopen (file, FOPEN_RT);
- if (stream == 0)
- perror_with_name (file);
-
- cleanups = make_cleanup (fclose, stream);
-
- read_command_file (stream);
-
- do_cleanups (cleanups);
-}
-
-/* ARGSUSED */
-static void
-echo_command (text, from_tty)
- char *text;
- int from_tty;
-{
- char *p = text;
- register int c;
-
- if (text)
- while ((c = *p++) != '\0')
- {
- if (c == '\\')
- {
- /* \ at end of argument is used after spaces
- so they won't be lost. */
- if (*p == 0)
- return;
-
- c = parse_escape (&p);
- if (c >= 0)
- printf_filtered ("%c", c);
- }
- else
- printf_filtered ("%c", c);
- }
-
- /* Force this output to appear now. */
- wrap_here ("");
- fflush (stdout);
-}
-
-\f
-/* Functions to manipulate command line editing control variables. */
-
-/* Number of commands to print in each call to show_commands. */
-#define Hist_print 10
-static void
-show_commands (args, from_tty)
- char *args;
- int from_tty;
-{
- /* Index for history commands. Relative to history_base. */
- int offset;
-
- /* Number of the history entry which we are planning to display next.
- Relative to history_base. */
- static int num = 0;
-
- /* The first command in the history which doesn't exist (i.e. one more
- than the number of the last command). Relative to history_base. */
- int hist_len;
-
- extern struct _hist_entry *history_get PARAMS ((int));
- extern int history_base;
-
- /* Print out some of the commands from the command history. */
- /* First determine the length of the history list. */
- hist_len = history_size;
- for (offset = 0; offset < history_size; offset++)
- {
- if (!history_get (history_base + offset))
- {
- hist_len = offset;
- break;
- }
- }
-
- if (args)
- {
- if (args[0] == '+' && args[1] == '\0')
- /* "info editing +" should print from the stored position. */
- ;
- else
- /* "info editing <exp>" should print around command number <exp>. */
- num = (parse_and_eval_address (args) - history_base) - Hist_print / 2;
- }
- /* "show commands" means print the last Hist_print commands. */
- else
- {
- num = hist_len - Hist_print;
- }
-
- if (num < 0)
- num = 0;
-
- /* If there are at least Hist_print commands, we want to display the last
- Hist_print rather than, say, the last 6. */
- if (hist_len - num < Hist_print)
- {
- num = hist_len - Hist_print;
- if (num < 0)
- num = 0;
- }
-
- for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
- {
- printf_filtered ("%5d %s\n", history_base + offset,
- (history_get (history_base + offset))->line);
- }
-
- /* The next command we want to display is the next one that we haven't
- displayed yet. */
- num += Hist_print;
-
- /* If the user repeats this command with return, it should do what
- "show commands +" does. This is unnecessary if arg is null,
- because "show commands +" is not useful after "show commands". */
- if (from_tty && args)
- {
- args[0] = '+';
- args[1] = '\0';
- }
-}
-
-/* Called by do_setshow_command. */
-/* ARGSUSED */
-static void
-set_history_size_command (args, from_tty, c)
- char *args;
- int from_tty;
- struct cmd_list_element *c;
-{
- if (history_size == INT_MAX)
- unstifle_history ();
- else if (history_size >= 0)
- stifle_history (history_size);
- else
- {
- history_size = INT_MAX;
- error ("History size must be non-negative");
- }
-}
-
-/* ARGSUSED */
-static void
-set_history (args, from_tty)
- char *args;
- int from_tty;
-{
- printf ("\"set history\" must be followed by the name of a history subcommand.\n");
- help_list (sethistlist, "set history ", -1, stdout);
-}
-
-/* ARGSUSED */
-static void
-show_history (args, from_tty)
- char *args;
- int from_tty;
-{
- cmd_show_list (showhistlist, from_tty, "");
-}
-
-int info_verbose = 0; /* Default verbose msgs off */
-
-/* Called by do_setshow_command. An elaborate joke. */
-/* ARGSUSED */
-static void
-set_verbose (args, from_tty, c)
- char *args;
- int from_tty;
- struct cmd_list_element *c;
-{
- char *cmdname = "verbose";
- struct cmd_list_element *showcmd;
-
- showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
-
- if (info_verbose)
- {
- c->doc = "Set verbose printing of informational messages.";
- showcmd->doc = "Show verbose printing of informational messages.";