| 1 | /* CLI utilities. |
| 2 | |
| 3 | Copyright (C) 2011-2015 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 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 |
| 9 | the Free Software Foundation; either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 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/>. */ |
| 19 | |
| 20 | #ifndef CLI_UTILS_H |
| 21 | #define CLI_UTILS_H |
| 22 | |
| 23 | /* *PP is a string denoting a number. Get the number of the. Advance |
| 24 | *PP after the string and any trailing whitespace. |
| 25 | |
| 26 | Currently the string can either be a number, or "$" followed by the |
| 27 | name of a convenience variable, or ("$" or "$$") followed by digits. */ |
| 28 | |
| 29 | extern int get_number_const (const char **); |
| 30 | |
| 31 | /* Like get_number_const, but takes a non-const "char **". */ |
| 32 | |
| 33 | extern int get_number (char **); |
| 34 | |
| 35 | /* An object of this type is passed to get_number_or_range. It must |
| 36 | be initialized by calling init_number_or_range. This type is |
| 37 | defined here so that it can be stack-allocated, but all members |
| 38 | other than `finished' and `string' should be treated as opaque. */ |
| 39 | |
| 40 | struct get_number_or_range_state |
| 41 | { |
| 42 | /* Non-zero if parsing has completed. */ |
| 43 | int finished; |
| 44 | |
| 45 | /* The string being parsed. When parsing has finished, this points |
| 46 | past the last parsed token. */ |
| 47 | const char *string; |
| 48 | |
| 49 | /* Last value returned. */ |
| 50 | int last_retval; |
| 51 | |
| 52 | /* When parsing a range, the final value in the range. */ |
| 53 | int end_value; |
| 54 | |
| 55 | /* When parsing a range, a pointer past the final token in the |
| 56 | range. */ |
| 57 | const char *end_ptr; |
| 58 | |
| 59 | /* Non-zero when parsing a range. */ |
| 60 | int in_range; |
| 61 | }; |
| 62 | |
| 63 | /* Initialize a get_number_or_range_state for use with |
| 64 | get_number_or_range_state. STRING is the string to be parsed. */ |
| 65 | |
| 66 | extern void init_number_or_range (struct get_number_or_range_state *state, |
| 67 | const char *string); |
| 68 | |
| 69 | /* Parse a number or a range. |
| 70 | A number will be of the form handled by get_number. |
| 71 | A range will be of the form <number1> - <number2>, and |
| 72 | will represent all the integers between number1 and number2, |
| 73 | inclusive. |
| 74 | |
| 75 | While processing a range, this fuction is called iteratively; |
| 76 | At each call it will return the next value in the range. |
| 77 | |
| 78 | At the beginning of parsing a range, the char pointer STATE->string will |
| 79 | be advanced past <number1> and left pointing at the '-' token. |
| 80 | Subsequent calls will not advance the pointer until the range |
| 81 | is completed. The call that completes the range will advance |
| 82 | the pointer past <number2>. */ |
| 83 | |
| 84 | extern int get_number_or_range (struct get_number_or_range_state *state); |
| 85 | |
| 86 | /* Accept a number and a string-form list of numbers such as is |
| 87 | accepted by get_number_or_range. Return TRUE if the number is |
| 88 | in the list. |
| 89 | |
| 90 | By definition, an empty list includes all numbers. This is to |
| 91 | be interpreted as typing a command such as "delete break" with |
| 92 | no arguments. */ |
| 93 | |
| 94 | extern int number_is_in_list (const char *list, int number); |
| 95 | |
| 96 | /* Reverse S to the last non-whitespace character without skipping past |
| 97 | START. */ |
| 98 | |
| 99 | extern char *remove_trailing_whitespace (const char *start, char *s); |
| 100 | |
| 101 | /* A helper function to extract an argument from *ARG. An argument is |
| 102 | delimited by whitespace. The return value is either NULL if no |
| 103 | argument was found, or an xmalloc'd string. */ |
| 104 | |
| 105 | extern char *extract_arg (char **arg); |
| 106 | |
| 107 | /* A const-correct version of "extract_arg". |
| 108 | |
| 109 | Since the returned value is xmalloc'd, it eventually needs to be |
| 110 | xfree'ed, which prevents us from making it const as well. */ |
| 111 | |
| 112 | extern char *extract_arg_const (const char **arg); |
| 113 | |
| 114 | /* A helper function that looks for an argument at the start of a |
| 115 | string. The argument must also either be at the end of the string, |
| 116 | or be followed by whitespace. Returns 1 if it finds the argument, |
| 117 | 0 otherwise. If the argument is found, it updates *STR. */ |
| 118 | extern int check_for_argument (char **str, char *arg, int arg_len); |
| 119 | |
| 120 | #endif /* CLI_UTILS_H */ |