1 /* MI Command Set - MI Option Parser.
2 Copyright (C) 2000-2013 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions (a Red Hat company).
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "mi-getopt.h"
22 #include "gdb_string.h"
24 /* See comments about mi_getopt and mi_getopt_silent in mi-getopt.h.
25 When there is an unknown option, if ERROR_ON_UNKNOWN is true,
26 throw an error, otherwise return -1. */
29 mi_getopt_1 (const char *prefix, int argc, char **argv,
30 const struct mi_opt *opts, int *oind, char **oarg,
34 const struct mi_opt *opt;
36 /* We assume that argv/argc are ok. */
37 if (*oind > argc || *oind < 0)
38 internal_error (__FILE__, __LINE__,
39 _("mi_getopt_long: oind out of bounds"));
44 if (strcmp (arg, "--") == 0)
50 /* End of option list. */
56 /* Look the option up. */
57 for (opt = opts; opt->name != NULL; opt++)
59 if (strcmp (opt->name, arg + 1) != 0)
63 /* A non-simple oarg option. */
65 error (_("%s: Option %s requires an argument"), prefix, arg);
66 *oarg = argv[(*oind) + 1];
79 error (_("%s: Unknown option ``%s''"), prefix, arg + 1);
85 mi_getopt (const char *prefix,
86 int argc, char **argv,
87 const struct mi_opt *opts,
88 int *oind, char **oarg)
90 return mi_getopt_1 (prefix, argc, argv, opts, oind, oarg, 1);
94 mi_getopt_allow_unknown (const char *prefix, int argc, char **argv,
95 const struct mi_opt *opts, int *oind, char **oarg)
97 return mi_getopt_1 (prefix, argc, argv, opts, oind, oarg, 0);
101 mi_valid_noargs (const char *prefix, int argc, char **argv)
105 static const struct mi_opt opts[] =
110 if (mi_getopt (prefix, argc, argv, opts, &oind, &oarg) == -1)