From 242f1fd7ee29538968e32155c99a36c3d7604eb5 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Tue, 27 Aug 2013 03:04:45 +0000 Subject: Add mi_getopt_allow_unknown This patch is to add a new function mi_getopt_allow_unknown, which returns -1 silently (without throwing error) when unknown option is met, and use this function to parse options for command '-stack-list-arguments'. gdb/ * mi/mi-cmd-stack.c (parse_no_frames_option): Remove. (mi_cmd_stack_list_args): Use mi_getopt_silent to handle options. * mi/mi-getopt.c (mi_getopt): Remove. (mi_getopt_1): Renamed from mi_getopt. Add one parameter 'error_on_unknown'. (mi_getopt): Call mi_getopt_1. (mi_getopt_silent): New. * mi/mi-getopt.h (mi_getopt_silent): Declare. --- gdb/mi/mi-getopt.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'gdb/mi/mi-getopt.c') diff --git a/gdb/mi/mi-getopt.c b/gdb/mi/mi-getopt.c index a1e2ccc..f207249 100644 --- a/gdb/mi/mi-getopt.c +++ b/gdb/mi/mi-getopt.c @@ -21,11 +21,14 @@ #include "mi-getopt.h" #include "gdb_string.h" -int -mi_getopt (const char *prefix, - int argc, char **argv, - const struct mi_opt *opts, - int *oind, char **oarg) +/* See comments about mi_getopt and mi_getopt_silent in mi-getopt.h. + When there is an unknown option, if ERROR_ON_UNKNOWN is true, + throw an error, otherwise return -1. */ + +static int +mi_getopt_1 (const char *prefix, int argc, char **argv, + const struct mi_opt *opts, int *oind, char **oarg, + int error_on_unknown) { char *arg; const struct mi_opt *opt; @@ -71,7 +74,27 @@ mi_getopt (const char *prefix, return opt->index; } } - error (_("%s: Unknown option ``%s''"), prefix, arg + 1); + + if (error_on_unknown) + error (_("%s: Unknown option ``%s''"), prefix, arg + 1); + else + return -1; +} + +int +mi_getopt (const char *prefix, + int argc, char **argv, + const struct mi_opt *opts, + int *oind, char **oarg) +{ + return mi_getopt_1 (prefix, argc, argv, opts, oind, oarg, 1); +} + +int +mi_getopt_allow_unknown (const char *prefix, int argc, char **argv, + const struct mi_opt *opts, int *oind, char **oarg) +{ + return mi_getopt_1 (prefix, argc, argv, opts, oind, oarg, 0); } int -- cgit v1.1