Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: gdb/cli/cli-utils.c

Issue 124383005: GDB 7.6.50 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@upstream
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/cli/cli-utils.h ('k') | gdb/coff-pe-read.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* CLI utilities. 1 /* CLI utilities.
2 2
3 Copyright (c) 2011-2012 Free Software Foundation, Inc. 3 Copyright (C) 2011-2013 Free Software Foundation, Inc.
4 4
5 This file is part of GDB. 5 This file is part of GDB.
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or 9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 19
20 #include "defs.h" 20 #include "defs.h"
21 #include "cli/cli-utils.h" 21 #include "cli/cli-utils.h"
22 #include "gdb_string.h" 22 #include <string.h>
23 #include "value.h" 23 #include "value.h"
24 #include "gdb_assert.h" 24 #include "gdb_assert.h"
25 25
26 #include <ctype.h> 26 #include <ctype.h>
27 27
28 /* *PP is a string denoting a number. Get the number of the. Advance 28 /* *PP is a string denoting a number. Get the number of the. Advance
29 *PP after the string and any trailing whitespace. 29 *PP after the string and any trailing whitespace.
30 30
31 Currently the string can either be a number, or "$" followed by the 31 Currently the string can either be a number, or "$" followed by the
32 name of a convenience variable, or ("$" or "$$") followed by digits. 32 name of a convenience variable, or ("$" or "$$") followed by digits.
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 { 230 {
231 if (chp == NULL) 231 if (chp == NULL)
232 return NULL; 232 return NULL;
233 while (*chp && isspace (*chp)) 233 while (*chp && isspace (*chp))
234 chp++; 234 chp++;
235 return chp; 235 return chp;
236 } 236 }
237 237
238 /* See documentation in cli-utils.h. */ 238 /* See documentation in cli-utils.h. */
239 239
240 char * 240 const char *
241 skip_to_space (char *chp) 241 skip_to_space_const (const char *chp)
242 { 242 {
243 if (chp == NULL) 243 if (chp == NULL)
244 return NULL; 244 return NULL;
245 while (*chp && !isspace (*chp)) 245 while (*chp && !isspace (*chp))
246 chp++; 246 chp++;
247 return chp; 247 return chp;
248 } 248 }
249 249
250 /* See documentation in cli-utils.h. */ 250 /* See documentation in cli-utils.h. */
251 251
252 char * 252 char *
253 remove_trailing_whitespace (const char *start, char *s) 253 remove_trailing_whitespace (const char *start, char *s)
254 { 254 {
255 while (s > start && isspace (*(s - 1))) 255 while (s > start && isspace (*(s - 1)))
256 --s; 256 --s;
257 257
258 return s; 258 return s;
259 } 259 }
260 260
261 /* See documentation in cli-utils.h. */ 261 /* See documentation in cli-utils.h. */
262 262
263 char * 263 char *
264 extract_arg_const (const char **arg)
265 {
266 const char *result;
267
268 if (!*arg)
269 return NULL;
270
271 /* Find the start of the argument. */
272 *arg = skip_spaces_const (*arg);
273 if (!**arg)
274 return NULL;
275 result = *arg;
276
277 /* Find the end of the argument. */
278 *arg = skip_to_space_const (*arg + 1);
279
280 if (result == *arg)
281 return NULL;
282
283 return savestring (result, *arg - result);
284 }
285
286 /* See documentation in cli-utils.h. */
287
288 char *
264 extract_arg (char **arg) 289 extract_arg (char **arg)
265 { 290 {
266 char *result, *copy; 291 const char *arg_const = *arg;
292 char *result;
267 293
268 if (!*arg) 294 result = extract_arg_const (&arg_const);
269 return NULL; 295 *arg += arg_const - *arg;
270 296 return result;
271 /* Find the start of the argument. */
272 *arg = skip_spaces (*arg);
273 if (!**arg)
274 return NULL;
275 result = *arg;
276
277 /* Find the end of the argument. */
278 *arg = skip_to_space (*arg + 1);
279
280 if (result == *arg)
281 return NULL;
282
283 copy = xmalloc (*arg - result + 1);
284 memcpy (copy, result, *arg - result);
285 copy[*arg - result] = '\0';
286
287 return copy;
288 } 297 }
289 298
290 /* See documentation in cli-utils.h. */ 299 /* See documentation in cli-utils.h. */
291 300
292 int 301 int
293 check_for_argument (char **str, char *arg, int arg_len) 302 check_for_argument (char **str, char *arg, int arg_len)
294 { 303 {
295 if (strncmp (*str, arg, arg_len) == 0 304 if (strncmp (*str, arg, arg_len) == 0
296 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) 305 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
297 { 306 {
298 *str += arg_len; 307 *str += arg_len;
299 return 1; 308 return 1;
300 } 309 }
301 return 0; 310 return 0;
302 } 311 }
OLDNEW
« no previous file with comments | « gdb/cli/cli-utils.h ('k') | gdb/coff-pe-read.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698