OLD | NEW |
1 /* CLI utilities. | 1 /* CLI utilities. |
2 | 2 |
3 Copyright (c) 2011-2012 Free Software Foundation, Inc. | 3 Copyright (c) 2011-2012 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. |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 char * | 216 char * |
217 skip_spaces (char *chp) | 217 skip_spaces (char *chp) |
218 { | 218 { |
219 if (chp == NULL) | 219 if (chp == NULL) |
220 return NULL; | 220 return NULL; |
221 while (*chp && isspace (*chp)) | 221 while (*chp && isspace (*chp)) |
222 chp++; | 222 chp++; |
223 return chp; | 223 return chp; |
224 } | 224 } |
225 | 225 |
| 226 /* A const-correct version of the above. */ |
| 227 |
| 228 const char * |
| 229 skip_spaces_const (const char *chp) |
| 230 { |
| 231 if (chp == NULL) |
| 232 return NULL; |
| 233 while (*chp && isspace (*chp)) |
| 234 chp++; |
| 235 return chp; |
| 236 } |
| 237 |
226 /* See documentation in cli-utils.h. */ | 238 /* See documentation in cli-utils.h. */ |
227 | 239 |
228 char * | 240 char * |
229 skip_to_space (char *chp) | 241 skip_to_space (char *chp) |
230 { | 242 { |
231 if (chp == NULL) | 243 if (chp == NULL) |
232 return NULL; | 244 return NULL; |
233 while (*chp && !isspace (*chp)) | 245 while (*chp && !isspace (*chp)) |
234 chp++; | 246 chp++; |
235 return chp; | 247 return chp; |
236 } | 248 } |
237 | 249 |
238 /* See documentation in cli-utils.h. */ | 250 /* See documentation in cli-utils.h. */ |
239 | 251 |
240 char * | 252 char * |
241 remove_trailing_whitespace (const char *start, char *s) | 253 remove_trailing_whitespace (const char *start, char *s) |
242 { | 254 { |
243 while (s > start && isspace (*(s - 1))) | 255 while (s > start && isspace (*(s - 1))) |
244 --s; | 256 --s; |
245 | 257 |
246 return s; | 258 return s; |
247 } | 259 } |
| 260 |
| 261 /* See documentation in cli-utils.h. */ |
| 262 |
| 263 char * |
| 264 extract_arg (char **arg) |
| 265 { |
| 266 char *result, *copy; |
| 267 |
| 268 if (!*arg) |
| 269 return NULL; |
| 270 |
| 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 } |
| 289 |
| 290 /* See documentation in cli-utils.h. */ |
| 291 |
| 292 int |
| 293 check_for_argument (char **str, char *arg, int arg_len) |
| 294 { |
| 295 if (strncmp (*str, arg, arg_len) == 0 |
| 296 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) |
| 297 { |
| 298 *str += arg_len; |
| 299 return 1; |
| 300 } |
| 301 return 0; |
| 302 } |
OLD | NEW |