- ret = invalid_control;
- break;
- }
- }
-
- if (child_tail)
- {
- child_tail->next = next;
- }
- else
- {
- body_ptr = current_cmd->body_list;
- for (i = 1; i < current_body; i++)
- body_ptr++;
-
- *body_ptr = next;
-
- }
-
- child_tail = next;
-
- /* If the latest line is another control structure, then recurse
- on it. */
- if (next->control_type == while_control
- || next->control_type == if_control)
- {
- control_level++;
- ret = recurse_read_control_structure (next);
- control_level--;
-
- if (ret != simple_control)
- break;
- }
- }
-
- dont_repeat ();
-
- return ret;
-}
-
-/* Read lines from the input stream and accumulate them in a chain of
- struct command_line's, which is then returned. For input from a
- terminal, the special command "end" is used to mark the end of the
- input, and is not included in the returned chain of commands. */
-
-#define END_MESSAGE "End with a line saying just \"end\"."
-
-struct command_line *
-read_command_lines (prompt, from_tty)
-char *prompt;
-int from_tty;
-{
- struct command_line *head, *tail, *next;
- struct cleanup *old_chain;
- enum command_control_type ret;
- enum misc_command_type val;
-
- if (readline_begin_hook)
- {
- /* Note - intentional to merge messages with no newline */
- (*readline_begin_hook) ("%s %s\n", prompt, END_MESSAGE);
- }
- else if (from_tty && input_from_terminal_p ())
- {
- printf_unfiltered ("%s\n%s\n", prompt, END_MESSAGE);
- gdb_flush (gdb_stdout);
- }
-
- head = tail = NULL;
- old_chain = NULL;
-
- while (1)
- {
- val = read_next_line (&next);
-
- /* Ignore blank lines or comments. */
- if (val == nop_command)
- continue;
-
- if (val == end_command)
- {
- ret = simple_control;
- break;
- }
-
- if (val != ok_command)
- {
- ret = invalid_control;
- break;
- }
-
- if (next->control_type == while_control
- || next->control_type == if_control)
- {
- control_level++;
- ret = recurse_read_control_structure (next);
- control_level--;
-
- if (ret == invalid_control)
- break;
- }
-
- if (tail)
- {
- tail->next = next;
- }
- else
- {
- head = next;
- old_chain = make_cleanup ((make_cleanup_func) free_command_lines,
- &head);
- }
- tail = next;
- }
-
- dont_repeat ();
-
- if (head)
- {
- if (ret != invalid_control)
- {
- discard_cleanups (old_chain);
- }
- else
- do_cleanups (old_chain);
- }
-
- if (readline_end_hook)
- {
- (*readline_end_hook) ();
- }
- return (head);
-}
-
-/* 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;
- struct command_line **blist;
- int i;
-
- while (l)
- {
- if (l->body_count > 0)
- {
- blist = l->body_list;
- for (i = 0; i < l->body_count; i++, blist++)
- free_command_lines (blist);
- }
- 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_unfiltered ("\"info\" must be followed by the name of an info command.\n");
- help_list (infolist, "info ", -1, gdb_stdout);
-}
-
-/* The "complete" command is used by Emacs to implement completion. */
-
-/* ARGSUSED */
-static void
-complete_command (arg, from_tty)
- char *arg;
- int from_tty;
-{
- int i;
- int argpoint;
- char *completion;
-
- dont_repeat ();
-
- if (arg == NULL)
- arg = "";
- argpoint = strlen (arg);
-
- for (completion = line_completion_function (arg, i = 0, arg, argpoint);
- completion;
- completion = line_completion_function (arg, ++i, arg, argpoint))
- {
- printf_unfiltered ("%s\n", completion);
- free (completion);
- }
-}
-
-/* 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, gdb_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 != '-' && *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;
- char tmpbuf[128];
-#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? "))
- 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);
-
- control_level = 0;
- sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname);
- cmds = read_command_lines (tmpbuf, from_tty);
-
- 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;
- char tmpbuf[128];
-
- validate_comname (comname);
-
- c = lookup_cmd (&tem, cmdlist, "", 0, 1);
-
- if (c->class != class_user)
- error ("Command \"%s\" is built-in.", comname);
-
- sprintf (tmpbuf, "Type documentation for \"%s\".", comname);
- doclines = read_command_lines (tmpbuf, from_tty);
-
- 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
-/* Print the GDB banner. */
-void
-print_gdb_version (stream)
- GDB_FILE *stream;
-{
- /* From GNU coding standards, first line is meant to be easy for a
- program to parse, and is just canonical program name and version
- number, which starts after last space. */