| OLD | NEW |
| 1 /* MI Command Set - MI Option Parser. | 1 /* MI Command Set - MI Option Parser. |
| 2 Copyright (C) 2000-2001, 2007-2012 Free Software Foundation, Inc. | 2 Copyright (C) 2000-2013 Free Software Foundation, Inc. |
| 3 Contributed by Cygnus Solutions (a Red Hat company). | 3 Contributed by Cygnus Solutions (a Red Hat company). |
| 4 | 4 |
| 5 This file is part of GDB. | 5 This file is part of GDB. |
| 6 | 6 |
| 7 This program is free software; you can redistribute it and/or modify | 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 | 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 | 9 the Free Software Foundation; either version 3 of the License, or |
| 10 (at your option) any later version. | 10 (at your option) any later version. |
| 11 | 11 |
| 12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
| 16 | 16 |
| 17 You should have received a copy of the GNU General Public License | 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/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | 19 |
| 20 #include "defs.h" | 20 #include "defs.h" |
| 21 #include "mi-getopt.h" | 21 #include "mi-getopt.h" |
| 22 #include "gdb_string.h" | 22 #include <string.h> |
| 23 | 23 |
| 24 int | 24 /* See comments about mi_getopt and mi_getopt_silent in mi-getopt.h. |
| 25 mi_getopt (const char *prefix, | 25 When there is an unknown option, if ERROR_ON_UNKNOWN is true, |
| 26 » int argc, char **argv, | 26 throw an error, otherwise return -1. */ |
| 27 » const struct mi_opt *opts, | 27 |
| 28 » int *oind, char **oarg) | 28 static int |
| 29 mi_getopt_1 (const char *prefix, int argc, char **argv, |
| 30 » const struct mi_opt *opts, int *oind, char **oarg, |
| 31 » int error_on_unknown) |
| 29 { | 32 { |
| 30 char *arg; | 33 char *arg; |
| 31 const struct mi_opt *opt; | 34 const struct mi_opt *opt; |
| 32 | 35 |
| 33 /* We assume that argv/argc are ok. */ | 36 /* We assume that argv/argc are ok. */ |
| 34 if (*oind > argc || *oind < 0) | 37 if (*oind > argc || *oind < 0) |
| 35 internal_error (__FILE__, __LINE__, | 38 internal_error (__FILE__, __LINE__, |
| 36 _("mi_getopt_long: oind out of bounds")); | 39 _("mi_getopt_long: oind out of bounds")); |
| 37 if (*oind == argc) | 40 if (*oind == argc) |
| 38 return -1; | 41 return -1; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 64 *oind = (*oind) + 2; | 67 *oind = (*oind) + 2; |
| 65 return opt->index; | 68 return opt->index; |
| 66 } | 69 } |
| 67 else | 70 else |
| 68 { | 71 { |
| 69 *oarg = NULL; | 72 *oarg = NULL; |
| 70 *oind = (*oind) + 1; | 73 *oind = (*oind) + 1; |
| 71 return opt->index; | 74 return opt->index; |
| 72 } | 75 } |
| 73 } | 76 } |
| 74 error (_("%s: Unknown option ``%s''"), prefix, arg + 1); | 77 |
| 78 if (error_on_unknown) |
| 79 error (_("%s: Unknown option ``%s''"), prefix, arg + 1); |
| 80 else |
| 81 return -1; |
| 82 } |
| 83 |
| 84 int |
| 85 mi_getopt (const char *prefix, |
| 86 » int argc, char **argv, |
| 87 » const struct mi_opt *opts, |
| 88 » int *oind, char **oarg) |
| 89 { |
| 90 return mi_getopt_1 (prefix, argc, argv, opts, oind, oarg, 1); |
| 91 } |
| 92 |
| 93 int |
| 94 mi_getopt_allow_unknown (const char *prefix, int argc, char **argv, |
| 95 » » » const struct mi_opt *opts, int *oind, char **oarg) |
| 96 { |
| 97 return mi_getopt_1 (prefix, argc, argv, opts, oind, oarg, 0); |
| 75 } | 98 } |
| 76 | 99 |
| 77 int | 100 int |
| 78 mi_valid_noargs (const char *prefix, int argc, char **argv) | 101 mi_valid_noargs (const char *prefix, int argc, char **argv) |
| 79 { | 102 { |
| 80 int oind = 0; | 103 int oind = 0; |
| 81 char *oarg; | 104 char *oarg; |
| 82 static const struct mi_opt opts[] = | 105 static const struct mi_opt opts[] = |
| 83 { | 106 { |
| 84 { 0, 0, 0 } | 107 { 0, 0, 0 } |
| 85 }; | 108 }; |
| 86 | 109 |
| 87 if (mi_getopt (prefix, argc, argv, opts, &oind, &oarg) == -1) | 110 if (mi_getopt (prefix, argc, argv, opts, &oind, &oarg) == -1) |
| 88 return 1; | 111 return 1; |
| 89 else | 112 else |
| 90 return 0; | 113 return 0; |
| 91 } | 114 } |
| OLD | NEW |