* cli/cli-script.c (process_next_line): Recognize 'end'

even when the line has leading space and we're not parsing
	commands.
This commit is contained in:
Vladimir Prus 2009-11-18 20:42:38 +00:00
parent f0ae4a24b0
commit 3630a92dd7
2 changed files with 21 additions and 10 deletions

View file

@ -1,3 +1,9 @@
2009-11-18 Vladimir Prus <vladimir@codesourcery.com>
* cli/cli-script.c (process_next_line): Recognize 'end'
even when the line has leading space and we're not parsing
commands.
2009-11-18 Tom Tromey <tromey@redhat.com> 2009-11-18 Tom Tromey <tromey@redhat.com>
* symtab.c (symbol_set_names): Correctly set 'name' on symbol when * symtab.c (symbol_set_names): Correctly set 'name' on symbol when

View file

@ -879,30 +879,35 @@ static enum misc_command_type
process_next_line (char *p, struct command_line **command, int parse_commands) process_next_line (char *p, struct command_line **command, int parse_commands)
{ {
char *p1; char *p1;
char *p2;
int not_handled = 0; int not_handled = 0;
/* Not sure what to do here. */ /* Not sure what to do here. */
if (p == NULL) if (p == NULL)
return end_command; return end_command;
if (parse_commands)
{
/* Strip leading whitespace. */
while (*p == ' ' || *p == '\t')
p++;
}
/* Strip trailing whitespace. */ /* Strip trailing whitespace. */
p1 = p + strlen (p); p1 = p + strlen (p);
while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t')) while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t'))
p1--; p1--;
/* Is this the end of a simple, while, or if control structure? */ p2 = p;
if (p1 - p == 3 && !strncmp (p, "end", 3)) /* Strip leading whitespace. */
return end_command; while (*p2 == ' ' || *p2 == '\t')
p2++;
/* 'end' is always recognized, regardless of parse_commands value.
We also permit whitespace before end and after. */
if (p1 - p2 == 3 && !strncmp (p2, "end", 3))
return end_command;
if (parse_commands) if (parse_commands)
{ {
/* If commands are parsed, we skip initial spaces. Otherwise,
which is the case for Python commands and documentation
(see the 'document' command), spaces are preserved. */
p = p2;
/* Blanks and comments don't really do anything, but we need to /* Blanks and comments don't really do anything, but we need to
distinguish them from else, end and other commands which can be distinguish them from else, end and other commands which can be
executed. */ executed. */