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 /* Execute the command in CMD. */
219 execute_user_command (struct cmd_list_element
*c
, char *args
)
221 register struct command_line
*cmdlines
;
222 struct cleanup
*old_chain
;
223 enum command_control_type ret
;
225 old_chain
= setup_user_args (args
);
227 cmdlines
= c
->user_commands
;
232 /* Set the instream to 0, indicating execution of a
233 user-defined function. */
234 old_chain
= make_cleanup (do_restore_instream_cleanup
, instream
);
235 instream
= (FILE *) 0;
238 ret
= execute_control_command (cmdlines
);
239 if (ret
!= simple_control
&& ret
!= break_control
)
241 warning ("Error in control structure.\n");
244 cmdlines
= cmdlines
->next
;
246 do_cleanups (old_chain
);
249 enum command_control_type
250 execute_control_command (struct command_line
*cmd
)
252 struct expression
*expr
;
253 struct command_line
*current
;
254 struct cleanup
*old_chain
= 0;
256 struct value
*val_mark
;
258 enum command_control_type ret
;
261 switch (cmd
->control_type
)
264 /* A simple command, execute it and return. */
265 new_line
= insert_args (cmd
->line
);
267 return invalid_control
;
268 old_chain
= make_cleanup (free_current_contents
, &new_line
);
269 execute_command (new_line
, 0);
270 ret
= cmd
->control_type
;
273 case continue_control
:
275 /* Return for "continue", and "break" so we can either
276 continue the loop at the top, or break out. */
277 ret
= cmd
->control_type
;
282 /* Parse the loop control expression for the while statement. */
283 new_line
= insert_args (cmd
->line
);
285 return invalid_control
;
286 old_chain
= make_cleanup (free_current_contents
, &new_line
);
287 expr
= parse_expression (new_line
);
288 make_cleanup (free_current_contents
, &expr
);
290 ret
= simple_control
;
293 /* Keep iterating so long as the expression is true. */
300 /* Evaluate the expression. */
301 val_mark
= value_mark ();
302 val
= evaluate_expression (expr
);
303 cond_result
= value_true (val
);
304 value_free_to_mark (val_mark
);
306 /* If the value is false, then break out of the loop. */
310 /* Execute the body of the while statement. */
311 current
= *cmd
->body_list
;
314 ret
= execute_control_command (current
);
316 /* If we got an error, or a "break" command, then stop
318 if (ret
== invalid_control
|| ret
== break_control
)
324 /* If we got a "continue" command, then restart the loop
326 if (ret
== continue_control
)
329 /* Get the next statement. */
330 current
= current
->next
;
334 /* Reset RET so that we don't recurse the break all the way down. */
335 if (ret
== break_control
)
336 ret
= simple_control
;
343 new_line
= insert_args (cmd
->line
);
345 return invalid_control
;
346 old_chain
= make_cleanup (free_current_contents
, &new_line
);
347 /* Parse the conditional for the if statement. */
348 expr
= parse_expression (new_line
);
349 make_cleanup (free_current_contents
, &expr
);
352 ret
= simple_control
;
354 /* Evaluate the conditional. */
355 val_mark
= value_mark ();
356 val
= evaluate_expression (expr
);
358 /* Choose which arm to take commands from based on the value of the
359 conditional expression. */
360 if (value_true (val
))
361 current
= *cmd
->body_list
;
362 else if (cmd
->body_count
== 2)
363 current
= *(cmd
->body_list
+ 1);
364 value_free_to_mark (val_mark
);
366 /* Execute commands in the given arm. */
369 ret
= execute_control_command (current
);
371 /* If we got an error, get out. */
372 if (ret
!= simple_control
)
375 /* Get the next statement in the body. */
376 current
= current
->next
;
383 warning ("Invalid control type in command structure.");
384 return invalid_control
;
388 do_cleanups (old_chain
);
393 /* "while" command support. Executes a body of statements while the
394 loop condition is nonzero. */
397 while_command (char *arg
, int from_tty
)
399 struct command_line
*command
= NULL
;
402 command
= get_command_line (while_control
, arg
);
407 execute_control_command (command
);
408 free_command_lines (&command
);
411 /* "if" command support. Execute either the true or false arm depending
412 on the value of the if conditional. */
415 if_command (char *arg
, int from_tty
)
417 struct command_line
*command
= NULL
;
420 command
= get_command_line (if_control
, arg
);
425 execute_control_command (command
);
426 free_command_lines (&command
);
431 arg_cleanup (void *ignore
)
433 struct user_args
*oargs
= user_args
;
435 internal_error (__FILE__
, __LINE__
,
436 "arg_cleanup called with no user args.\n");
438 user_args
= user_args
->next
;
442 /* Bind the incomming arguments for a user defined command to
443 $arg0, $arg1 ... $argMAXUSERARGS. */
445 static struct cleanup
*
446 setup_user_args (char *p
)
448 struct user_args
*args
;
449 struct cleanup
*old_chain
;
450 unsigned int arg_count
= 0;
452 args
= (struct user_args
*) xmalloc (sizeof (struct user_args
));
453 memset (args
, 0, sizeof (struct user_args
));
455 args
->next
= user_args
;
458 old_chain
= make_cleanup (arg_cleanup
, 0/*ignored*/);
470 if (arg_count
>= MAXUSERARGS
)
472 error ("user defined function may only have %d arguments.\n",
477 /* Strip whitespace. */
478 while (*p
== ' ' || *p
== '\t')
481 /* P now points to an argument. */
483 user_args
->a
[arg_count
].arg
= p
;
485 /* Get to the end of this argument. */
488 if (((*p
== ' ' || *p
== '\t')) && !squote
&& !dquote
&& !bsquote
)
517 user_args
->a
[arg_count
].len
= p
- start_arg
;
524 /* Given character string P, return a point to the first argument ($arg),
525 or NULL if P contains no arguments. */
530 while ((p
= strchr (p
, '$')))
532 if (strncmp (p
, "$arg", 4) == 0 && isdigit (p
[4]))
539 /* Insert the user defined arguments stored in user_arg into the $arg
540 arguments found in line, with the updated copy being placed into nline. */
543 insert_args (char *line
)
545 char *p
, *save_line
, *new_line
;
548 /* First we need to know how much memory to allocate for the new line. */
551 while ((p
= locate_arg (line
)))
556 if (i
>= user_args
->count
)
558 error ("Missing argument %d in user function.\n", i
);
561 len
+= user_args
->a
[i
].len
;
565 /* Don't forget the tail. */
566 len
+= strlen (line
);
568 /* Allocate space for the new line and fill it in. */
569 new_line
= (char *) xmalloc (len
+ 1);
570 if (new_line
== NULL
)
573 /* Restore pointer to beginning of old line. */
576 /* Save pointer to beginning of new line. */
577 save_line
= new_line
;
579 while ((p
= locate_arg (line
)))
583 memcpy (new_line
, line
, p
- line
);
584 new_line
+= p
- line
;
587 len
= user_args
->a
[i
].len
;
590 memcpy (new_line
, user_args
->a
[i
].arg
, len
);
595 /* Don't forget the tail. */
596 strcpy (new_line
, line
);
598 /* Return a pointer to the beginning of the new line. */
603 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
604 code bodies. This is typically used when we encounter an "else"
605 clause for an "if" command. */
608 realloc_body_list (struct command_line
*command
, int new_length
)
611 struct command_line
**body_list
;
613 n
= command
->body_count
;
619 body_list
= (struct command_line
**)
620 xmalloc (sizeof (struct command_line
*) * new_length
);
622 memcpy (body_list
, command
->body_list
, sizeof (struct command_line
*) * n
);
624 xfree (command
->body_list
);
625 command
->body_list
= body_list
;
626 command
->body_count
= new_length
;
629 /* Read one line from the input stream. If the command is an "else" or
630 "end", return such an indication to the caller. */
632 static enum misc_command_type
633 read_next_line (struct command_line
**command
)
635 char *p
, *p1
, *prompt_ptr
, control_prompt
[256];
638 if (control_level
>= 254)
639 error ("Control nesting too deep!\n");
641 /* Set a prompt based on the nesting of the control commands. */
642 if (instream
== stdin
|| (instream
== 0 && readline_hook
!= NULL
))
644 for (i
= 0; i
< control_level
; i
++)
645 control_prompt
[i
] = ' ';
646 control_prompt
[i
] = '>';
647 control_prompt
[i
+ 1] = '\0';
648 prompt_ptr
= (char *) &control_prompt
[0];
653 p
= command_line_input (prompt_ptr
, instream
== stdin
, "commands");
655 /* Not sure what to do here. */
659 /* Strip leading and trailing whitespace. */
660 while (*p
== ' ' || *p
== '\t')
664 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t'))
667 /* Blanks and comments don't really do anything, but we need to
668 distinguish them from else, end and other commands which can be
670 if (p1
== p
|| p
[0] == '#')
673 /* Is this the end of a simple, while, or if control structure? */
674 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
677 /* Is the else clause of an if control structure? */
678 if (p1
- p
== 4 && !strncmp (p
, "else", 4))
681 /* Check for while, if, break, continue, etc and build a new command
682 line structure for them. */
683 if (p1
- p
> 5 && !strncmp (p
, "while", 5))
684 *command
= build_command_line (while_control
, p
+ 6);
685 else if (p1
- p
> 2 && !strncmp (p
, "if", 2))
686 *command
= build_command_line (if_control
, p
+ 3);
687 else if (p1
- p
== 10 && !strncmp (p
, "loop_break", 10))
689 *command
= (struct command_line
*)
690 xmalloc (sizeof (struct command_line
));
691 (*command
)->next
= NULL
;
692 (*command
)->line
= NULL
;
693 (*command
)->control_type
= break_control
;
694 (*command
)->body_count
= 0;
695 (*command
)->body_list
= NULL
;
697 else if (p1
- p
== 13 && !strncmp (p
, "loop_continue", 13))
699 *command
= (struct command_line
*)
700 xmalloc (sizeof (struct command_line
));
701 (*command
)->next
= NULL
;
702 (*command
)->line
= NULL
;
703 (*command
)->control_type
= continue_control
;
704 (*command
)->body_count
= 0;
705 (*command
)->body_list
= NULL
;
709 /* A normal command. */
710 *command
= (struct command_line
*)
711 xmalloc (sizeof (struct command_line
));
712 (*command
)->next
= NULL
;
713 (*command
)->line
= savestring (p
, p1
- p
);
714 (*command
)->control_type
= simple_control
;
715 (*command
)->body_count
= 0;
716 (*command
)->body_list
= NULL
;
719 /* Nothing special. */
723 /* Recursively read in the control structures and create a command_line
726 The parent_control parameter is the control structure in which the
727 following commands are nested. */
729 static enum command_control_type
730 recurse_read_control_structure (struct command_line
*current_cmd
)
733 enum misc_command_type val
;
734 enum command_control_type ret
;
735 struct command_line
**body_ptr
, *child_tail
, *next
;
741 if (current_cmd
->control_type
== simple_control
)
743 error ("Recursed on a simple control type\n");
744 return invalid_control
;
747 if (current_body
> current_cmd
->body_count
)
749 error ("Allocated body is smaller than this command type needs\n");
750 return invalid_control
;
753 /* Read lines from the input stream and build control structures. */
759 val
= read_next_line (&next
);
761 /* Just skip blanks and comments. */
762 if (val
== nop_command
)
765 if (val
== end_command
)
767 if (current_cmd
->control_type
== while_control
768 || current_cmd
->control_type
== if_control
)
770 /* Success reading an entire control structure. */
771 ret
= simple_control
;
776 ret
= invalid_control
;
781 /* Not the end of a control structure. */
782 if (val
== else_command
)
784 if (current_cmd
->control_type
== if_control
785 && current_body
== 1)
787 realloc_body_list (current_cmd
, 2);
794 ret
= invalid_control
;
801 child_tail
->next
= next
;
805 body_ptr
= current_cmd
->body_list
;
806 for (i
= 1; i
< current_body
; i
++)
815 /* If the latest line is another control structure, then recurse
817 if (next
->control_type
== while_control
818 || next
->control_type
== if_control
)
821 ret
= recurse_read_control_structure (next
);
824 if (ret
!= simple_control
)
834 /* Read lines from the input stream and accumulate them in a chain of
835 struct command_line's, which is then returned. For input from a
836 terminal, the special command "end" is used to mark the end of the
837 input, and is not included in the returned chain of commands. */
839 #define END_MESSAGE "End with a line saying just \"end\"."
841 struct command_line
*
842 read_command_lines (char *prompt_arg
, int from_tty
)
844 struct command_line
*head
, *tail
, *next
;
845 struct cleanup
*old_chain
;
846 enum command_control_type ret
;
847 enum misc_command_type val
;
850 if (readline_begin_hook
)
852 /* Note - intentional to merge messages with no newline */
853 (*readline_begin_hook
) ("%s %s\n", prompt_arg
, END_MESSAGE
);
855 else if (from_tty
&& input_from_terminal_p ())
857 printf_unfiltered ("%s\n%s\n", prompt_arg
, END_MESSAGE
);
858 gdb_flush (gdb_stdout
);
866 val
= read_next_line (&next
);
868 /* Ignore blank lines or comments. */
869 if (val
== nop_command
)
872 if (val
== end_command
)
874 ret
= simple_control
;
878 if (val
!= ok_command
)
880 ret
= invalid_control
;
884 if (next
->control_type
== while_control
885 || next
->control_type
== if_control
)
888 ret
= recurse_read_control_structure (next
);
891 if (ret
== invalid_control
)
902 old_chain
= make_cleanup_free_command_lines (&head
);
911 if (ret
!= invalid_control
)
913 discard_cleanups (old_chain
);
916 do_cleanups (old_chain
);
919 if (readline_end_hook
)
921 (*readline_end_hook
) ();
926 /* Free a chain of struct command_line's. */
929 free_command_lines (struct command_line
**lptr
)
931 register struct command_line
*l
= *lptr
;
932 register struct command_line
*next
;
933 struct command_line
**blist
;
938 if (l
->body_count
> 0)
940 blist
= l
->body_list
;
941 for (i
= 0; i
< l
->body_count
; i
++, blist
++)
942 free_command_lines (blist
);
953 do_free_command_lines_cleanup (void *arg
)
955 free_command_lines (arg
);
958 static struct cleanup
*
959 make_cleanup_free_command_lines (struct command_line
**arg
)
961 return make_cleanup (do_free_command_lines_cleanup
, arg
);
965 validate_comname (char *comname
)
970 error_no_arg ("name of command to define");
975 if (!isalnum (*p
) && *p
!= '-' && *p
!= '_')
976 error ("Junk in argument list: \"%s\"", p
);
981 /* This is just a placeholder in the command data structures. */
983 user_defined_command (char *ignore
, int from_tty
)
988 define_command (char *comname
, int from_tty
)
990 #define MAX_TMPBUF 128
997 register struct command_line
*cmds
;
998 register struct cmd_list_element
*c
, *newc
, *oldc
, *hookc
= 0;
1001 char tmpbuf
[MAX_TMPBUF
];
1002 int hook_type
= CMD_NO_HOOK
;
1003 int hook_name_size
= 0;
1005 #define HOOK_STRING "hook-"
1007 #define HOOK_POST_STRING "hookpost-"
1008 #define HOOK_POST_LEN 9
1010 validate_comname (comname
);
1012 /* Look it up, and verify that we got an exact match. */
1013 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
1014 if (c
&& !STREQ (comname
, c
->name
))
1019 if (c
->class == class_user
|| c
->class == class_alias
)
1020 tem
= "Redefine command \"%s\"? ";
1022 tem
= "Really redefine built-in command \"%s\"? ";
1023 if (!query (tem
, c
->name
))
1024 error ("Command \"%s\" not redefined.", c
->name
);
1027 /* If this new command is a hook, then mark the command which it
1028 is hooking. Note that we allow hooking `help' commands, so that
1029 we can hook the `stop' pseudo-command. */
1031 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
1033 hook_type
= CMD_PRE_HOOK
;
1034 hook_name_size
= HOOK_LEN
;
1036 else if (!strncmp (comname
, HOOK_POST_STRING
, HOOK_POST_LEN
))
1038 hook_type
= CMD_POST_HOOK
;
1039 hook_name_size
= HOOK_POST_LEN
;
1042 if (hook_type
!= CMD_NO_HOOK
)
1044 /* Look up cmd it hooks, and verify that we got an exact match. */
1045 tem
= comname
+ hook_name_size
;
1046 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
1047 if (hookc
&& !STREQ (comname
+ hook_name_size
, hookc
->name
))
1051 warning ("Your new `%s' command does not hook any existing command.",
1053 if (!query ("Proceed? "))
1054 error ("Not confirmed.");
1058 comname
= savestring (comname
, strlen (comname
));
1060 /* If the rest of the commands will be case insensitive, this one
1061 should behave in the same manner. */
1062 for (tem
= comname
; *tem
; tem
++)
1064 *tem
= tolower (*tem
);
1066 sprintf (tmpbuf
, "Type commands for definition of \"%s\".", comname
);
1067 cmds
= read_command_lines (tmpbuf
, from_tty
);
1069 if (c
&& c
->class == class_user
)
1070 free_command_lines (&c
->user_commands
);
1072 newc
= add_cmd (comname
, class_user
, user_defined_command
,
1073 (c
&& c
->class == class_user
)
1074 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
1075 newc
->user_commands
= cmds
;
1077 /* If this new command is a hook, then mark both commands as being
1084 hookc
->hook_pre
= newc
; /* Target gets hooked. */
1085 newc
->hookee_pre
= hookc
; /* We are marked as hooking target cmd. */
1088 hookc
->hook_post
= newc
; /* Target gets hooked. */
1089 newc
->hookee_post
= hookc
; /* We are marked as hooking target cmd. */
1092 /* Should never come here as hookc would be 0. */
1093 internal_error (__FILE__
, __LINE__
, "bad switch");
1099 document_command (char *comname
, int from_tty
)
1101 struct command_line
*doclines
;
1102 register struct cmd_list_element
*c
;
1103 char *tem
= comname
;
1106 validate_comname (comname
);
1108 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
1110 if (c
->class != class_user
)
1111 error ("Command \"%s\" is built-in.", comname
);
1113 sprintf (tmpbuf
, "Type documentation for \"%s\".", comname
);
1114 doclines
= read_command_lines (tmpbuf
, from_tty
);
1120 register struct command_line
*cl1
;
1121 register int len
= 0;
1123 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
1124 len
+= strlen (cl1
->line
) + 1;
1126 c
->doc
= (char *) xmalloc (len
+ 1);
1129 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
1131 strcat (c
->doc
, cl1
->line
);
1133 strcat (c
->doc
, "\n");
1137 free_command_lines (&doclines
);
1140 struct source_cleanup_lines_args
1144 char *old_pre_error
;
1145 char *old_error_pre_print
;
1149 source_cleanup_lines (PTR args
)
1151 struct source_cleanup_lines_args
*p
=
1152 (struct source_cleanup_lines_args
*) args
;
1153 source_line_number
= p
->old_line
;
1154 source_file_name
= p
->old_file
;
1155 source_pre_error
= p
->old_pre_error
;
1156 error_pre_print
= p
->old_error_pre_print
;
1161 do_fclose_cleanup (void *stream
)
1166 /* Used to implement source_command */
1169 script_from_file (FILE *stream
, char *file
)
1171 struct cleanup
*old_cleanups
;
1172 struct source_cleanup_lines_args old_lines
;
1177 internal_error (__FILE__
, __LINE__
, "called with NULL file pointer!");
1180 old_cleanups
= make_cleanup (do_fclose_cleanup
, stream
);
1182 old_lines
.old_line
= source_line_number
;
1183 old_lines
.old_file
= source_file_name
;
1184 old_lines
.old_pre_error
= source_pre_error
;
1185 old_lines
.old_error_pre_print
= error_pre_print
;
1186 make_cleanup (source_cleanup_lines
, &old_lines
);
1187 source_line_number
= 0;
1188 source_file_name
= file
;
1189 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
1190 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
1191 make_cleanup (xfree
, source_pre_error
);
1192 /* This will get set every time we read a line. So it won't stay "" for
1194 error_pre_print
= "";
1196 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
1197 if (source_error_allocated
< needed_length
)
1199 source_error_allocated
*= 2;
1200 if (source_error_allocated
< needed_length
)
1201 source_error_allocated
= needed_length
;
1202 if (source_error
== NULL
)
1203 source_error
= xmalloc (source_error_allocated
);
1205 source_error
= xrealloc (source_error
, source_error_allocated
);
1208 read_command_file (stream
);
1210 do_cleanups (old_cleanups
);
1214 show_user_1 (struct cmd_list_element
*c
, struct ui_file
*stream
)
1216 register struct command_line
*cmdlines
;
1218 cmdlines
= c
->user_commands
;
1221 fputs_filtered ("User command ", stream
);
1222 fputs_filtered (c
->name
, stream
);
1223 fputs_filtered (":\n", stream
);
1225 print_command_lines (uiout
, cmdlines
, 1);
1226 fputs_filtered ("\n", stream
);