1 /* GDB CLI command scripting.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
26 #include "language.h" /* For value_true */
32 #include "cli/cli-cmds.h"
33 #include "cli/cli-decode.h"
34 #include "cli/cli-script.h"
38 extern void dont_repeat (void);
40 extern void do_restore_instream_cleanup (void *stream);
42 /* Prototypes for local functions */
44 static struct cleanup *
45 make_cleanup_free_command_lines (struct command_line **arg);
47 static enum command_control_type
48 recurse_read_control_structure (struct command_line *current_cmd);
50 static char *insert_args (char *line);
52 static struct cleanup * setup_user_args (char *p);
54 static void validate_comname (char *);
56 /* Level of control structure. */
57 static int control_level;
59 /* Source command state variable. */
60 static int source_error_allocated;
62 /* Structure for arguments to user defined functions. */
63 #define MAXUSERARGS 10
66 struct user_args *next;
78 /* Allocate, initialize a new command line structure for one of the
79 control commands (if/while). */
81 static struct command_line *
82 build_command_line (enum command_control_type type, char *args)
84 struct command_line *cmd;
87 error ("if/while commands require arguments.\n");
89 cmd = (struct command_line *) xmalloc (sizeof (struct command_line));
91 cmd->control_type = type;
95 = (struct command_line **) xmalloc (sizeof (struct command_line *)
97 memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count);
98 cmd->line = savestring (args, strlen (args));
102 /* Build and return a new command structure for the control commands
103 such as "if" and "while". */
105 static struct command_line *
106 get_command_line (enum command_control_type type, char *arg)
108 struct command_line *cmd;
109 struct cleanup *old_chain = NULL;
111 /* Allocate and build a new command line structure. */
112 cmd = build_command_line (type, arg);
114 old_chain = make_cleanup_free_command_lines (&cmd);
116 /* Read in the body of this command. */
117 if (recurse_read_control_structure (cmd) == invalid_control)
119 warning ("error reading in control structure\n");
120 do_cleanups (old_chain);
124 discard_cleanups (old_chain);
128 /* Recursively print a command (including full control structures). */
131 print_command_lines (struct ui_out *uiout, struct command_line *cmd,
134 struct command_line *list;
141 ui_out_spaces (uiout, 2 * depth);
143 /* A simple command, print it and continue. */
144 if (list->control_type == simple_control)
146 ui_out_field_string (uiout, NULL, list->line);
147 ui_out_text (uiout, "\n");
152 /* loop_continue to jump to the start of a while loop, print it
154 if (list->control_type == continue_control)
156 ui_out_field_string (uiout, NULL, "loop_continue");
157 ui_out_text (uiout, "\n");
162 /* loop_break to break out of a while loop, print it and continue. */
163 if (list->control_type == break_control)
165 ui_out_field_string (uiout, NULL, "loop_break");
166 ui_out_text (uiout, "\n");
171 /* A while command. Recursively print its subcommands and continue. */
172 if (list->control_type == while_control)
174 ui_out_field_fmt (uiout, NULL, "while %s", list->line);
175 ui_out_text (uiout, "\n");
176 print_command_lines (uiout, *list->body_list, depth + 1);
178 ui_out_spaces (uiout, 2 * depth);
179 ui_out_field_string (uiout, NULL, "end");
180 ui_out_text (uiout, "\n");
185 /* An if command. Recursively print both arms before continueing. */
186 if (list->control_type == if_control)
188 ui_out_field_fmt (uiout, NULL, "if %s", list->line);
189 ui_out_text (uiout, "\n");
191 print_command_lines (uiout, list->body_list[0], depth + 1);
193 /* Show the false arm if it exists. */
194 if (list->body_count == 2)
197 ui_out_spaces (uiout, 2 * depth);
198 ui_out_field_string (uiout, NULL, "else");
199 ui_out_text (uiout, "\n");
200 print_command_lines (uiout, list->body_list[1], depth + 1);
204 ui_out_spaces (uiout, 2 * depth);
205 ui_out_field_string (uiout, NULL, "end");
206 ui_out_text (uiout, "\n");
211 /* ignore illegal command type and try next */
216 /* Handle pre-post hooks. */
219 clear_hook_in_cleanup (void *data)
221 struct cmd_list_element *c = data;
222 c->hook_in = 0; /* Allow hook to work again once it is complete */
226 execute_cmd_pre_hook (struct cmd_list_element *c)
228 if ((c->hook_pre) && (!c->hook_in))
230 struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c);
231 c->hook_in = 1; /* Prevent recursive hooking */
232 execute_user_command (c->hook_pre, (char *) 0);
233 do_cleanups (cleanups);
238 execute_cmd_post_hook (struct cmd_list_element *c)
240 if ((c->hook_post) && (!c->hook_in))
242 struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c);
243 c->hook_in = 1; /* Prevent recursive hooking */
244 execute_user_command (c->hook_post, (char *) 0);
245 do_cleanups (cleanups);
249 /* Execute the command in CMD. */
252 execute_user_command (struct cmd_list_element *c, char *args)
254 register struct command_line *cmdlines;
255 struct cleanup *old_chain;
256 enum command_control_type ret;
258 old_chain = setup_user_args (args);
260 cmdlines = c->user_commands;
265 /* Set the instream to 0, indicating execution of a
266 user-defined function. */
267 old_chain = make_cleanup (do_restore_instream_cleanup, instream);
268 instream = (FILE *) 0;
271 ret = execute_control_command (cmdlines);
272 if (ret != simple_control && ret != break_control)
274 warning ("Error in control structure.\n");
277 cmdlines = cmdlines->next;
279 do_cleanups (old_chain);
282 enum command_control_type
283 execute_control_command (struct command_line *cmd)
285 struct expression *expr;
286 struct command_line *current;
287 struct cleanup *old_chain = 0;
289 struct value *val_mark;
291 enum command_control_type ret;
294 switch (cmd->control_type)
297 /* A simple command, execute it and return. */
298 new_line = insert_args (cmd->line);
300 return invalid_control;
301 old_chain = make_cleanup (free_current_contents, &new_line);
302 execute_command (new_line, 0);
303 ret = cmd->control_type;
306 case continue_control:
308 /* Return for "continue", and "break" so we can either
309 continue the loop at the top, or break out. */
310 ret = cmd->control_type;
315 /* Parse the loop control expression for the while statement. */
316 new_line = insert_args (cmd->line);
318 return invalid_control;
319 old_chain = make_cleanup (free_current_contents, &new_line);
320 expr = parse_expression (new_line);
321 make_cleanup (free_current_contents, &expr);
323 ret = simple_control;
326 /* Keep iterating so long as the expression is true. */
333 /* Evaluate the expression. */
334 val_mark = value_mark ();
335 val = evaluate_expression (expr);
336 cond_result = value_true (val);
337 value_free_to_mark (val_mark);
339 /* If the value is false, then break out of the loop. */
343 /* Execute the body of the while statement. */
344 current = *cmd->body_list;
347 ret = execute_control_command (current);
349 /* If we got an error, or a "break" command, then stop
351 if (ret == invalid_control || ret == break_control)
357 /* If we got a "continue" command, then restart the loop
359 if (ret == continue_control)
362 /* Get the next statement. */
363 current = current->next;
367 /* Reset RET so that we don't recurse the break all the way down. */
368 if (ret == break_control)
369 ret = simple_control;
376 new_line = insert_args (cmd->line);
378 return invalid_control;
379 old_chain = make_cleanup (free_current_contents, &new_line);
380 /* Parse the conditional for the if statement. */
381 expr = parse_expression (new_line);
382 make_cleanup (free_current_contents, &expr);
385 ret = simple_control;
387 /* Evaluate the conditional. */
388 val_mark = value_mark ();
389 val = evaluate_expression (expr);
391 /* Choose which arm to take commands from based on the value of the
392 conditional expression. */
393 if (value_true (val))
394 current = *cmd->body_list;
395 else if (cmd->body_count == 2)
396 current = *(cmd->body_list + 1);
397 value_free_to_mark (val_mark);
399 /* Execute commands in the given arm. */
402 ret = execute_control_command (current);
404 /* If we got an error, get out. */
405 if (ret != simple_control)
408 /* Get the next statement in the body. */
409 current = current->next;
416 warning ("Invalid control type in command structure.");
417 return invalid_control;
421 do_cleanups (old_chain);
426 /* "while" command support. Executes a body of statements while the
427 loop condition is nonzero. */
430 while_command (char *arg, int from_tty)
432 struct command_line *command = NULL;
435 command = get_command_line (while_control, arg);
440 execute_control_command (command);
441 free_command_lines (&command);
444 /* "if" command support. Execute either the true or false arm depending
445 on the value of the if conditional. */
448 if_command (char *arg, int from_tty)
450 struct command_line *command = NULL;
453 command = get_command_line (if_control, arg);
458 execute_control_command (command);
459 free_command_lines (&command);
464 arg_cleanup (void *ignore)
466 struct user_args *oargs = user_args;
468 internal_error (__FILE__, __LINE__,
469 "arg_cleanup called with no user args.\n");
471 user_args = user_args->next;
475 /* Bind the incomming arguments for a user defined command to
476 $arg0, $arg1 ... $argMAXUSERARGS. */
478 static struct cleanup *
479 setup_user_args (char *p)
481 struct user_args *args;
482 struct cleanup *old_chain;
483 unsigned int arg_count = 0;
485 args = (struct user_args *) xmalloc (sizeof (struct user_args));
486 memset (args, 0, sizeof (struct user_args));
488 args->next = user_args;
491 old_chain = make_cleanup (arg_cleanup, 0/*ignored*/);
503 if (arg_count >= MAXUSERARGS)
505 error ("user defined function may only have %d arguments.\n",
510 /* Strip whitespace. */
511 while (*p == ' ' || *p == '\t')
514 /* P now points to an argument. */
516 user_args->a[arg_count].arg = p;
518 /* Get to the end of this argument. */
521 if (((*p == ' ' || *p == '\t')) && !squote && !dquote && !bsquote)
550 user_args->a[arg_count].len = p - start_arg;
557 /* Given character string P, return a point to the first argument ($arg),
558 or NULL if P contains no arguments. */
563 while ((p = strchr (p, '$')))
565 if (strncmp (p, "$arg", 4) == 0 && isdigit (p[4]))
572 /* Insert the user defined arguments stored in user_arg into the $arg
573 arguments found in line, with the updated copy being placed into nline. */
576 insert_args (char *line)
578 char *p, *save_line, *new_line;
581 /* First we need to know how much memory to allocate for the new line. */
584 while ((p = locate_arg (line)))
589 if (i >= user_args->count)
591 error ("Missing argument %d in user function.\n", i);
594 len += user_args->a[i].len;
598 /* Don't forget the tail. */
599 len += strlen (line);
601 /* Allocate space for the new line and fill it in. */
602 new_line = (char *) xmalloc (len + 1);
603 if (new_line == NULL)
606 /* Restore pointer to beginning of old line. */
609 /* Save pointer to beginning of new line. */
610 save_line = new_line;
612 while ((p = locate_arg (line)))
616 memcpy (new_line, line, p - line);
617 new_line += p - line;
620 len = user_args->a[i].len;
623 memcpy (new_line, user_args->a[i].arg, len);
628 /* Don't forget the tail. */
629 strcpy (new_line, line);
631 /* Return a pointer to the beginning of the new line. */
636 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
637 code bodies. This is typically used when we encounter an "else"
638 clause for an "if" command. */
641 realloc_body_list (struct command_line *command, int new_length)
644 struct command_line **body_list;
646 n = command->body_count;
652 body_list = (struct command_line **)
653 xmalloc (sizeof (struct command_line *) * new_length);
655 memcpy (body_list, command->body_list, sizeof (struct command_line *) * n);
657 xfree (command->body_list);
658 command->body_list = body_list;
659 command->body_count = new_length;
662 /* Read one line from the input stream. If the command is an "else" or
663 "end", return such an indication to the caller. */
665 static enum misc_command_type
666 read_next_line (struct command_line **command)
668 char *p, *p1, *prompt_ptr, control_prompt[256];
671 if (control_level >= 254)
672 error ("Control nesting too deep!\n");
674 /* Set a prompt based on the nesting of the control commands. */
675 if (instream == stdin || (instream == 0 && readline_hook != NULL))
677 for (i = 0; i < control_level; i++)
678 control_prompt[i] = ' ';
679 control_prompt[i] = '>';
680 control_prompt[i + 1] = '\0';
681 prompt_ptr = (char *) &control_prompt[0];
686 p = command_line_input (prompt_ptr, instream == stdin, "commands");
688 /* Not sure what to do here. */
692 /* Strip leading and trailing whitespace. */
693 while (*p == ' ' || *p == '\t')
697 while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t'))
700 /* Blanks and comments don't really do anything, but we need to
701 distinguish them from else, end and other commands which can be
703 if (p1 == p || p[0] == '#')
706 /* Is this the end of a simple, while, or if control structure? */
707 if (p1 - p == 3 && !strncmp (p, "end", 3))
710 /* Is the else clause of an if control structure? */
711 if (p1 - p == 4 && !strncmp (p, "else", 4))
714 /* Check for while, if, break, continue, etc and build a new command
715 line structure for them. */
716 if (p1 - p > 5 && !strncmp (p, "while", 5))
717 *command = build_command_line (while_control, p + 6);
718 else if (p1 - p > 2 && !strncmp (p, "if", 2))
719 *command = build_command_line (if_control, p + 3);
720 else if (p1 - p == 10 && !strncmp (p, "loop_break", 10))
722 *command = (struct command_line *)
723 xmalloc (sizeof (struct command_line));
724 (*command)->next = NULL;
725 (*command)->line = NULL;
726 (*command)->control_type = break_control;
727 (*command)->body_count = 0;
728 (*command)->body_list = NULL;
730 else if (p1 - p == 13 && !strncmp (p, "loop_continue", 13))
732 *command = (struct command_line *)
733 xmalloc (sizeof (struct command_line));
734 (*command)->next = NULL;
735 (*command)->line = NULL;
736 (*command)->control_type = continue_control;
737 (*command)->body_count = 0;
738 (*command)->body_list = NULL;
742 /* A normal command. */
743 *command = (struct command_line *)
744 xmalloc (sizeof (struct command_line));
745 (*command)->next = NULL;
746 (*command)->line = savestring (p, p1 - p);
747 (*command)->control_type = simple_control;
748 (*command)->body_count = 0;
749 (*command)->body_list = NULL;
752 /* Nothing special. */
756 /* Recursively read in the control structures and create a command_line
759 The parent_control parameter is the control structure in which the
760 following commands are nested. */
762 static enum command_control_type
763 recurse_read_control_structure (struct command_line *current_cmd)
766 enum misc_command_type val;
767 enum command_control_type ret;
768 struct command_line **body_ptr, *child_tail, *next;
774 if (current_cmd->control_type == simple_control)
776 error ("Recursed on a simple control type\n");
777 return invalid_control;
780 if (current_body > current_cmd->body_count)
782 error ("Allocated body is smaller than this command type needs\n");
783 return invalid_control;
786 /* Read lines from the input stream and build control structures. */
792 val = read_next_line (&next);
794 /* Just skip blanks and comments. */
795 if (val == nop_command)
798 if (val == end_command)
800 if (current_cmd->control_type == while_control
801 || current_cmd->control_type == if_control)
803 /* Success reading an entire control structure. */
804 ret = simple_control;
809 ret = invalid_control;
814 /* Not the end of a control structure. */
815 if (val == else_command)
817 if (current_cmd->control_type == if_control
818 && current_body == 1)
820 realloc_body_list (current_cmd, 2);
827 ret = invalid_control;
834 child_tail->next = next;
838 body_ptr = current_cmd->body_list;
839 for (i = 1; i < current_body; i++)
848 /* If the latest line is another control structure, then recurse
850 if (next->control_type == while_control
851 || next->control_type == if_control)
854 ret = recurse_read_control_structure (next);
857 if (ret != simple_control)
867 /* Read lines from the input stream and accumulate them in a chain of
868 struct command_line's, which is then returned. For input from a
869 terminal, the special command "end" is used to mark the end of the
870 input, and is not included in the returned chain of commands. */
872 #define END_MESSAGE "End with a line saying just \"end\"."
874 struct command_line *
875 read_command_lines (char *prompt_arg, int from_tty)
877 struct command_line *head, *tail, *next;
878 struct cleanup *old_chain;
879 enum command_control_type ret;
880 enum misc_command_type val;
883 if (readline_begin_hook)
885 /* Note - intentional to merge messages with no newline */
886 (*readline_begin_hook) ("%s %s\n", prompt_arg, END_MESSAGE);
888 else if (from_tty && input_from_terminal_p ())
890 printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE);
891 gdb_flush (gdb_stdout);
899 val = read_next_line (&next);
901 /* Ignore blank lines or comments. */
902 if (val == nop_command)
905 if (val == end_command)
907 ret = simple_control;
911 if (val != ok_command)
913 ret = invalid_control;
917 if (next->control_type == while_control
918 || next->control_type == if_control)
921 ret = recurse_read_control_structure (next);
924 if (ret == invalid_control)
935 old_chain = make_cleanup_free_command_lines (&head);
944 if (ret != invalid_control)
946 discard_cleanups (old_chain);
949 do_cleanups (old_chain);
952 if (readline_end_hook)
954 (*readline_end_hook) ();
959 /* Free a chain of struct command_line's. */
962 free_command_lines (struct command_line **lptr)
964 register struct command_line *l = *lptr;
965 register struct command_line *next;
966 struct command_line **blist;
971 if (l->body_count > 0)
973 blist = l->body_list;
974 for (i = 0; i < l->body_count; i++, blist++)
975 free_command_lines (blist);
986 do_free_command_lines_cleanup (void *arg)
988 free_command_lines (arg);
991 static struct cleanup *
992 make_cleanup_free_command_lines (struct command_line **arg)
994 return make_cleanup (do_free_command_lines_cleanup, arg);
998 validate_comname (char *comname)
1003 error_no_arg ("name of command to define");
1008 if (!isalnum (*p) && *p != '-' && *p != '_')
1009 error ("Junk in argument list: \"%s\"", p);
1014 /* This is just a placeholder in the command data structures. */
1016 user_defined_command (char *ignore, int from_tty)
1021 define_command (char *comname, int from_tty)
1023 #define MAX_TMPBUF 128
1030 register struct command_line *cmds;
1031 register struct cmd_list_element *c, *newc, *oldc, *hookc = 0;
1032 char *tem = comname;
1034 char tmpbuf[MAX_TMPBUF];
1035 int hook_type = CMD_NO_HOOK;
1036 int hook_name_size = 0;
1038 #define HOOK_STRING "hook-"
1040 #define HOOK_POST_STRING "hookpost-"
1041 #define HOOK_POST_LEN 9
1043 validate_comname (comname);
1045 /* Look it up, and verify that we got an exact match. */
1046 c = lookup_cmd (&tem, cmdlist, "", -1, 1);
1047 if (c && !STREQ (comname, c->name))
1052 if (c->class == class_user || c->class == class_alias)
1053 tem = "Redefine command \"%s\"? ";
1055 tem = "Really redefine built-in command \"%s\"? ";
1056 if (!query (tem, c->name))
1057 error ("Command \"%s\" not redefined.", c->name);
1060 /* If this new command is a hook, then mark the command which it
1061 is hooking. Note that we allow hooking `help' commands, so that
1062 we can hook the `stop' pseudo-command. */
1064 if (!strncmp (comname, HOOK_STRING, HOOK_LEN))
1066 hook_type = CMD_PRE_HOOK;
1067 hook_name_size = HOOK_LEN;
1069 else if (!strncmp (comname, HOOK_POST_STRING, HOOK_POST_LEN))
1071 hook_type = CMD_POST_HOOK;
1072 hook_name_size = HOOK_POST_LEN;
1075 if (hook_type != CMD_NO_HOOK)
1077 /* Look up cmd it hooks, and verify that we got an exact match. */
1078 tem = comname + hook_name_size;
1079 hookc = lookup_cmd (&tem, cmdlist, "", -1, 0);
1080 if (hookc && !STREQ (comname + hook_name_size, hookc->name))
1084 warning ("Your new `%s' command does not hook any existing command.",
1086 if (!query ("Proceed? "))
1087 error ("Not confirmed.");
1091 comname = savestring (comname, strlen (comname));
1093 /* If the rest of the commands will be case insensitive, this one
1094 should behave in the same manner. */
1095 for (tem = comname; *tem; tem++)
1097 *tem = tolower (*tem);
1099 sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname);
1100 cmds = read_command_lines (tmpbuf, from_tty);
1102 if (c && c->class == class_user)
1103 free_command_lines (&c->user_commands);
1105 newc = add_cmd (comname, class_user, user_defined_command,
1106 (c && c->class == class_user)
1107 ? c->doc : savestring ("User-defined.", 13), &cmdlist);
1108 newc->user_commands = cmds;
1110 /* If this new command is a hook, then mark both commands as being
1117 hookc->hook_pre = newc; /* Target gets hooked. */
1118 newc->hookee_pre = hookc; /* We are marked as hooking target cmd. */
1121 hookc->hook_post = newc; /* Target gets hooked. */
1122 newc->hookee_post = hookc; /* We are marked as hooking target cmd. */
1125 /* Should never come here as hookc would be 0. */
1126 internal_error (__FILE__, __LINE__, "bad switch");
1132 document_command (char *comname, int from_tty)
1134 struct command_line *doclines;
1135 register struct cmd_list_element *c;
1136 char *tem = comname;
1139 validate_comname (comname);
1141 c = lookup_cmd (&tem, cmdlist, "", 0, 1);
1143 if (c->class != class_user)
1144 error ("Command \"%s\" is built-in.", comname);
1146 sprintf (tmpbuf, "Type documentation for \"%s\".", comname);
1147 doclines = read_command_lines (tmpbuf, from_tty);
1153 register struct command_line *cl1;
1154 register int len = 0;
1156 for (cl1 = doclines; cl1; cl1 = cl1->next)
1157 len += strlen (cl1->line) + 1;
1159 c->doc = (char *) xmalloc (len + 1);
1162 for (cl1 = doclines; cl1; cl1 = cl1->next)
1164 strcat (c->doc, cl1->line);
1166 strcat (c->doc, "\n");
1170 free_command_lines (&doclines);
1173 struct source_cleanup_lines_args
1177 char *old_pre_error;
1178 char *old_error_pre_print;
1182 source_cleanup_lines (PTR args)
1184 struct source_cleanup_lines_args *p =
1185 (struct source_cleanup_lines_args *) args;
1186 source_line_number = p->old_line;
1187 source_file_name = p->old_file;
1188 source_pre_error = p->old_pre_error;
1189 error_pre_print = p->old_error_pre_print;
1194 do_fclose_cleanup (void *stream)
1199 /* Used to implement source_command */
1202 script_from_file (FILE *stream, char *file)
1204 struct cleanup *old_cleanups;
1205 struct source_cleanup_lines_args old_lines;
1210 internal_error (__FILE__, __LINE__, "called with NULL file pointer!");
1213 old_cleanups = make_cleanup (do_fclose_cleanup, stream);
1215 old_lines.old_line = source_line_number;
1216 old_lines.old_file = source_file_name;
1217 old_lines.old_pre_error = source_pre_error;
1218 old_lines.old_error_pre_print = error_pre_print;
1219 make_cleanup (source_cleanup_lines, &old_lines);
1220 source_line_number = 0;
1221 source_file_name = file;
1222 source_pre_error = error_pre_print == NULL ? "" : error_pre_print;
1223 source_pre_error = savestring (source_pre_error, strlen (source_pre_error));
1224 make_cleanup (xfree, source_pre_error);
1225 /* This will get set every time we read a line. So it won't stay "" for
1227 error_pre_print = "";
1229 needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80;
1230 if (source_error_allocated < needed_length)
1232 source_error_allocated *= 2;
1233 if (source_error_allocated < needed_length)
1234 source_error_allocated = needed_length;
1235 if (source_error == NULL)
1236 source_error = xmalloc (source_error_allocated);
1238 source_error = xrealloc (source_error, source_error_allocated);
1241 read_command_file (stream);
1243 do_cleanups (old_cleanups);
1247 show_user_1 (struct cmd_list_element *c, struct ui_file *stream)
1249 register struct command_line *cmdlines;
1251 cmdlines = c->user_commands;
1254 fputs_filtered ("User command ", stream);
1255 fputs_filtered (c->name, stream);
1256 fputs_filtered (":\n", stream);
1258 print_command_lines (uiout, cmdlines, 1);
1259 fputs_filtered ("\n", stream);