aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli/cli-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/cli/cli-utils.c')
-rw-r--r--gdb/cli/cli-utils.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index a68b67d..0946db0 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -134,7 +134,21 @@ init_number_or_range (struct get_number_or_range_state *state,
int
get_number_or_range (struct get_number_or_range_state *state)
{
- if (*state->string != '-')
+ if (state->in_range)
+ {
+ /* All number-parsing has already been done. Return the next
+ integer value (one greater than the saved previous value).
+ Do not advance the token pointer until the end of range is
+ reached. */
+
+ if (++state->last_retval == state->end_value)
+ {
+ /* End of range reached; advance token pointer. */
+ state->string = state->end_ptr;
+ state->in_range = 0;
+ }
+ }
+ else if (*state->string != '-')
{
/* Default case: state->string is pointing either to a solo
number, or to the first number of a range. */
@@ -165,27 +179,26 @@ get_number_or_range (struct get_number_or_range_state *state)
state->in_range = 1;
}
}
- else if (! state->in_range)
- error (_("negative value"));
else
- {
- /* state->string points to the '-' that betokens a range. All
- number-parsing has already been done. Return the next
- integer value (one greater than the saved previous value).
- Do not advance the token pointer until the end of range
- is reached. */
-
- if (++state->last_retval == state->end_value)
- {
- /* End of range reached; advance token pointer. */
- state->string = state->end_ptr;
- state->in_range = 0;
- }
- }
+ error (_("negative value"));
state->finished = *state->string == '\0';
return state->last_retval;
}
+/* See documentation in cli-utils.h. */
+
+void
+number_range_setup_range (struct get_number_or_range_state *state,
+ int start_value, int end_value, const char *end_ptr)
+{
+ gdb_assert (start_value > 0);
+
+ state->in_range = 1;
+ state->end_ptr = end_ptr;
+ state->last_retval = start_value - 1;
+ state->end_value = end_value;
+}
+
/* Accept a number and a string-form list of numbers such as is
accepted by get_number_or_range. Return TRUE if the number is
in the list.