1 /* MI Command Set - MI parser.
3 Copyright 2000, 2001, 2002 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 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. */
29 #include "gdb_string.h"
32 mi_parse_argv (char *args
, struct mi_parse
*parse
)
36 char **argv
= xmalloc ((argc
+ 1) * sizeof (char *));
41 /* skip leading white space */
42 while (isspace (*chp
))
44 /* Three possibilities: EOF, quoted string, or other text. */
53 /* A quoted string. */
55 char *start
= chp
+ 1;
56 /* Determine the buffer size. */
59 while (*chp
!= '\0' && *chp
!= '"')
64 if (parse_escape (&chp
) <= 0)
66 /* Do not allow split lines or "\000" */
75 /* Insist on a closing quote. */
81 /* Insist on trailing white space. */
82 if (chp
[1] != '\0' && !isspace (chp
[1]))
87 /* create the buffer. */
88 arg
= xmalloc ((len
+ 1) * sizeof (char));
89 /* And copy the characters in. */
92 while (*chp
!= '\0' && *chp
!= '"')
97 arg
[len
] = parse_escape (&chp
);
104 chp
++; /* that closing quote. */
109 /* An unquoted string. Accumulate all non blank
110 characters into a buffer. */
113 while (*chp
!= '\0' && !isspace (*chp
))
118 arg
= xmalloc ((len
+ 1) * sizeof (char));
119 strncpy (arg
, start
, len
);
124 /* Append arg to argv. */
125 argv
= xrealloc (argv
, (argc
+ 2) * sizeof (char *));
133 mi_parse_free (struct mi_parse
*parse
)
137 if (parse
->command
!= NULL
)
138 xfree (parse
->command
);
139 if (parse
->token
!= NULL
)
140 xfree (parse
->token
);
141 if (parse
->args
!= NULL
)
143 if (parse
->argv
!= NULL
)
144 freeargv (parse
->argv
);
153 struct mi_parse
*parse
= XMALLOC (struct mi_parse
);
154 memset (parse
, 0, sizeof (*parse
));
156 /* Before starting, skip leading white space. */
157 while (isspace (*cmd
))
160 /* Find/skip any token and then extract it. */
161 for (chp
= cmd
; *chp
>= '0' && *chp
<= '9'; chp
++)
163 parse
->token
= xmalloc ((chp
- cmd
+ 1) * sizeof (char *));
164 memcpy (parse
->token
, cmd
, (chp
- cmd
));
165 parse
->token
[chp
- cmd
] = '\0';
167 /* This wasn't a real MI command. Return it as a CLI_COMMAND. */
170 while (isspace (*chp
))
172 parse
->command
= xstrdup (chp
);
173 parse
->op
= CLI_COMMAND
;
177 /* Extract the command. */
179 char *tmp
= chp
+ 1; /* discard ``-'' */
180 for (; *chp
&& !isspace (*chp
); chp
++)
182 parse
->command
= xmalloc ((chp
- tmp
+ 1) * sizeof (char *));
183 memcpy (parse
->command
, tmp
, chp
- tmp
);
184 parse
->command
[chp
- tmp
] = '\0';
187 /* Find the command in the MI table. */
188 parse
->cmd
= mi_lookup (parse
->command
);
189 if (parse
->cmd
== NULL
)
191 /* FIXME: This should be a function call. */
194 "%s^error,msg=\"Undefined MI command: %s\"\n",
195 parse
->token
, parse
->command
);
196 mi_parse_free (parse
);
200 /* Skip white space following the command. */
201 while (isspace (*chp
))
204 /* For new argv commands, attempt to return the parsed argument
206 if (parse
->cmd
->argv_func
!= NULL
)
208 mi_parse_argv (chp
, parse
);
209 if (parse
->argv
== NULL
)
211 /* FIXME: This should be a function call. */
214 "%s^error,msg=\"Problem parsing arguments: %s %s\"\n",
215 parse
->token
, parse
->command
, chp
);
216 mi_parse_free (parse
);
221 /* FIXME: DELETE THIS */
222 /* For CLI and old ARGS commands, also return the remainder of the
223 command line as a single string. */
224 if (parse
->cmd
->args_func
!= NULL
225 || parse
->cmd
->cli
.cmd
!= NULL
)
227 parse
->args
= xstrdup (chp
);
231 parse
->op
= MI_COMMAND
;
This page took 0.036441 seconds and 4 git commands to generate.