1 /* MI Command Set - MI parser.
3 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
5 Contributed by Cygnus Solutions (a Red Hat company).
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 3 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, see <http://www.gnu.org/licenses/>. */
27 #include "gdb_string.h"
30 mi_parse_argv (char *args
, struct mi_parse
*parse
)
34 char **argv
= xmalloc ((argc
+ 1) * sizeof (char *));
39 /* skip leading white space */
40 while (isspace (*chp
))
42 /* Three possibilities: EOF, quoted string, or other text. */
51 /* A quoted string. */
53 char *start
= chp
+ 1;
54 /* Determine the buffer size. */
57 while (*chp
!= '\0' && *chp
!= '"')
62 if (parse_escape (&chp
) <= 0)
64 /* Do not allow split lines or "\000" */
73 /* Insist on a closing quote. */
79 /* Insist on trailing white space. */
80 if (chp
[1] != '\0' && !isspace (chp
[1]))
85 /* create the buffer. */
86 arg
= xmalloc ((len
+ 1) * sizeof (char));
87 /* And copy the characters in. */
90 while (*chp
!= '\0' && *chp
!= '"')
95 arg
[len
] = parse_escape (&chp
);
102 chp
++; /* that closing quote. */
107 /* An unquoted string. Accumulate all non blank
108 characters into a buffer. */
111 while (*chp
!= '\0' && !isspace (*chp
))
116 arg
= xmalloc ((len
+ 1) * sizeof (char));
117 strncpy (arg
, start
, len
);
122 /* Append arg to argv. */
123 argv
= xrealloc (argv
, (argc
+ 2) * sizeof (char *));
131 mi_parse_free (struct mi_parse
*parse
)
135 if (parse
->command
!= NULL
)
136 xfree (parse
->command
);
137 if (parse
->token
!= NULL
)
138 xfree (parse
->token
);
139 if (parse
->args
!= NULL
)
141 if (parse
->argv
!= NULL
)
142 freeargv (parse
->argv
);
151 struct mi_parse
*parse
= XMALLOC (struct mi_parse
);
152 memset (parse
, 0, sizeof (*parse
));
154 /* Before starting, skip leading white space. */
155 while (isspace (*cmd
))
158 /* Find/skip any token and then extract it. */
159 for (chp
= cmd
; *chp
>= '0' && *chp
<= '9'; chp
++)
161 parse
->token
= xmalloc ((chp
- cmd
+ 1) * sizeof (char *));
162 memcpy (parse
->token
, cmd
, (chp
- cmd
));
163 parse
->token
[chp
- cmd
] = '\0';
165 /* This wasn't a real MI command. Return it as a CLI_COMMAND. */
168 while (isspace (*chp
))
170 parse
->command
= xstrdup (chp
);
171 parse
->op
= CLI_COMMAND
;
175 /* Extract the command. */
177 char *tmp
= chp
+ 1; /* discard ``-'' */
178 for (; *chp
&& !isspace (*chp
); chp
++)
180 parse
->command
= xmalloc ((chp
- tmp
+ 1) * sizeof (char *));
181 memcpy (parse
->command
, tmp
, chp
- tmp
);
182 parse
->command
[chp
- tmp
] = '\0';
185 /* Find the command in the MI table. */
186 parse
->cmd
= mi_lookup (parse
->command
);
187 if (parse
->cmd
== NULL
)
189 /* FIXME: This should be a function call. */
192 "%s^error,msg=\"Undefined MI command: %s\"\n",
193 parse
->token
, parse
->command
);
194 mi_parse_free (parse
);
198 /* Skip white space following the command. */
199 while (isspace (*chp
))
202 /* For new argv commands, attempt to return the parsed argument
204 if (parse
->cmd
->argv_func
!= NULL
)
206 mi_parse_argv (chp
, parse
);
207 if (parse
->argv
== NULL
)
209 /* FIXME: This should be a function call. */
212 "%s^error,msg=\"Problem parsing arguments: %s %s\"\n",
213 parse
->token
, parse
->command
, chp
);
214 mi_parse_free (parse
);
219 /* FIXME: DELETE THIS */
220 /* For CLI and old ARGS commands, also return the remainder of the
221 command line as a single string. */
222 if (parse
->cmd
->args_func
!= NULL
223 || parse
->cmd
->cli
.cmd
!= NULL
)
225 parse
->args
= xstrdup (chp
);
229 parse
->op
= MI_COMMAND
;
This page took 0.037645 seconds and 4 git commands to generate.