GDB (API)
|
00001 /* CLI utilities. 00002 00003 Copyright (C) 2011-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #ifndef CLI_UTILS_H 00021 #define CLI_UTILS_H 00022 00023 /* *PP is a string denoting a number. Get the number of the. Advance 00024 *PP after the string and any trailing whitespace. 00025 00026 Currently the string can either be a number, or "$" followed by the 00027 name of a convenience variable, or ("$" or "$$") followed by digits. */ 00028 00029 extern int get_number (char **); 00030 00031 /* An object of this type is passed to get_number_or_range. It must 00032 be initialized by calling init_number_or_range. This type is 00033 defined here so that it can be stack-allocated, but all members 00034 other than `finished' and `string' should be treated as opaque. */ 00035 00036 struct get_number_or_range_state 00037 { 00038 /* Non-zero if parsing has completed. */ 00039 int finished; 00040 00041 /* The string being parsed. When parsing has finished, this points 00042 past the last parsed token. */ 00043 char *string; 00044 00045 /* Last value returned. */ 00046 int last_retval; 00047 00048 /* When parsing a range, the final value in the range. */ 00049 int end_value; 00050 00051 /* When parsing a range, a pointer past the final token in the 00052 range. */ 00053 char *end_ptr; 00054 00055 /* Non-zero when parsing a range. */ 00056 int in_range; 00057 }; 00058 00059 /* Initialize a get_number_or_range_state for use with 00060 get_number_or_range_state. STRING is the string to be parsed. */ 00061 00062 extern void init_number_or_range (struct get_number_or_range_state *state, 00063 char *string); 00064 00065 /* Parse a number or a range. 00066 A number will be of the form handled by get_number. 00067 A range will be of the form <number1> - <number2>, and 00068 will represent all the integers between number1 and number2, 00069 inclusive. 00070 00071 While processing a range, this fuction is called iteratively; 00072 At each call it will return the next value in the range. 00073 00074 At the beginning of parsing a range, the char pointer STATE->string will 00075 be advanced past <number1> and left pointing at the '-' token. 00076 Subsequent calls will not advance the pointer until the range 00077 is completed. The call that completes the range will advance 00078 the pointer past <number2>. */ 00079 00080 extern int get_number_or_range (struct get_number_or_range_state *state); 00081 00082 /* Accept a number and a string-form list of numbers such as is 00083 accepted by get_number_or_range. Return TRUE if the number is 00084 in the list. 00085 00086 By definition, an empty list includes all numbers. This is to 00087 be interpreted as typing a command such as "delete break" with 00088 no arguments. */ 00089 00090 extern int number_is_in_list (char *list, int number); 00091 00092 /* Skip leading whitespace characters in INP, returning an updated 00093 pointer. If INP is NULL, return NULL. */ 00094 00095 extern char *skip_spaces (char *inp); 00096 00097 /* A const-correct version of the above. */ 00098 00099 extern const char *skip_spaces_const (const char *inp); 00100 00101 /* Skip leading non-whitespace characters in INP, returning an updated 00102 pointer. If INP is NULL, return NULL. */ 00103 00104 #define skip_to_space(INP) ((char *) skip_to_space_const (INP)) 00105 00106 /* A const-correct version of the above. */ 00107 00108 extern const char *skip_to_space_const (const char *inp); 00109 00110 /* Reverse S to the last non-whitespace character without skipping past 00111 START. */ 00112 00113 extern char *remove_trailing_whitespace (const char *start, char *s); 00114 00115 /* A helper function to extract an argument from *ARG. An argument is 00116 delimited by whitespace. The return value is either NULL if no 00117 argument was found, or an xmalloc'd string. */ 00118 00119 extern char *extract_arg (char **arg); 00120 00121 /* A helper function that looks for an argument at the start of a 00122 string. The argument must also either be at the end of the string, 00123 or be followed by whitespace. Returns 1 if it finds the argument, 00124 0 otherwise. If the argument is found, it updates *STR. */ 00125 extern int check_for_argument (char **str, char *arg, int arg_len); 00126 00127 #endif /* CLI_UTILS_H */