3
3
Copyright (c) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4
4
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008,
5
2009 Free Software Foundation, Inc.
5
2009, 2010 Free Software Foundation, Inc.
7
7
This file is part of GDB.
878
878
static enum misc_command_type
879
879
process_next_line (char *p, struct command_line **command, int parse_commands)
882
883
int not_handled = 0;
884
885
/* Not sure what to do here. */
886
887
return end_command;
890
/* Strip leading whitespace. */
891
while (*p == ' ' || *p == '\t')
895
889
/* Strip trailing whitespace. */
897
while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t'))
900
/* Is this the end of a simple, while, or if control structure? */
901
if (p1 - p == 3 && !strncmp (p, "end", 3))
890
p_end = p + strlen (p);
891
while (p_end > p && (p_end[-1] == ' ' || p_end[-1] == '\t'))
895
/* Strip leading whitespace. */
896
while (p_start < p_end && (*p_start == ' ' || *p_start == '\t'))
899
/* 'end' is always recognized, regardless of parse_commands value.
900
We also permit whitespace before end and after. */
901
if (p_end - p_start == 3 && !strncmp (p_start, "end", 3))
902
902
return end_command;
904
904
if (parse_commands)
906
/* If commands are parsed, we skip initial spaces. Otherwise,
907
which is the case for Python commands and documentation
908
(see the 'document' command), spaces are preserved. */
906
911
/* Blanks and comments don't really do anything, but we need to
907
912
distinguish them from else, end and other commands which can be
909
if (p1 == p || p[0] == '#')
914
if (p_end == p || p[0] == '#')
910
915
return nop_command;
912
917
/* Is the else clause of an if control structure? */
913
if (p1 - p == 4 && !strncmp (p, "else", 4))
918
if (p_end - p == 4 && !strncmp (p, "else", 4))
914
919
return else_command;
916
921
/* Check for while, if, break, continue, etc and build a new command
917
922
line structure for them. */
918
if (p1 - p > 5 && !strncmp (p, "while", 5))
923
if (p_end - p > 5 && !strncmp (p, "while", 5))
921
926
first_arg = p + 5;
922
while (first_arg < p1 && isspace (*first_arg))
927
while (first_arg < p_end && isspace (*first_arg))
924
929
*command = build_command_line (while_control, first_arg);
926
else if (p1 - p > 2 && !strncmp (p, "if", 2))
931
else if (p_end - p > 2 && !strncmp (p, "if", 2))
929
934
first_arg = p + 2;
930
while (first_arg < p1 && isspace (*first_arg))
935
while (first_arg < p_end && isspace (*first_arg))
932
937
*command = build_command_line (if_control, first_arg);
934
else if (p1 - p >= 8 && !strncmp (p, "commands", 8))
939
else if (p_end - p >= 8 && !strncmp (p, "commands", 8))
937
942
first_arg = p + 8;
938
while (first_arg < p1 && isspace (*first_arg))
943
while (first_arg < p_end && isspace (*first_arg))
940
945
*command = build_command_line (commands_control, first_arg);
942
else if (p1 - p == 6 && !strncmp (p, "python", 6))
947
else if (p_end - p == 6 && !strncmp (p, "python", 6))
944
949
/* Note that we ignore the inline "python command" form
946
951
*command = build_command_line (python_control, "");
948
else if (p1 - p == 10 && !strncmp (p, "loop_break", 10))
953
else if (p_end - p == 10 && !strncmp (p, "loop_break", 10))
950
955
*command = (struct command_line *)
951
956
xmalloc (sizeof (struct command_line));