1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * Handles the parsing of command line options. This is particularly nasty
8 * compared to other utilities given that command line options can potentially
9 * be read by many different modules within SWIG. Thus, in order to make sure
10 * there are no unrecognized options, each module is required to "mark"
11 * the options that it uses. Afterwards, we can make a quick scan to make
12 * sure there are no unmarked options.
15 * - This module needs to be modified so that it doesn't call exit().
16 * Should have cleaner error handling in general.
17 * ----------------------------------------------------------------------------- */
19 char cvsroot_getopt_c[] = "$Id: getopt.c 10926 2008-11-11 22:17:40Z wsfulton $";
27 /* -----------------------------------------------------------------------------
30 * Initialize the argument list handler.
31 * ----------------------------------------------------------------------------- */
33 void Swig_init_args(int argc, char **argv) {
40 marked = (int *) malloc(numargs * sizeof(int));
41 for (i = 0; i < argc; i++) {
47 /* -----------------------------------------------------------------------------
50 * Marks an argument as being parsed.
51 * ----------------------------------------------------------------------------- */
53 void Swig_mark_arg(int n) {
55 assert((n >= 0) && (n < numargs));
59 /* -----------------------------------------------------------------------------
62 * Checks to see if argument has been picked up.
63 * ----------------------------------------------------------------------------- */
65 int Swig_check_marked(int n) {
66 assert((n >= 0) && (n < numargs));
70 /* -----------------------------------------------------------------------------
71 * Swig_check_options()
73 * Checkers for unprocessed command line options and errors.
74 * ----------------------------------------------------------------------------- */
76 void Swig_check_options(int check_input) {
79 int max = check_input ? numargs - 1 : numargs;
81 for (i = 1; i < max; i++) {
83 Printf(stderr, "swig error : Unrecognized option %s\n", args[i]);
88 Printf(stderr, "Use 'swig -help' for available options.\n");
91 if (check_input && marked[numargs - 1]) {
92 Printf(stderr, "Must specify an input file. Use -help for available options.\n");
97 /* -----------------------------------------------------------------------------
100 * Generates a generic error message and exits.
101 * ----------------------------------------------------------------------------- */
103 void Swig_arg_error(void) {
104 Printf(stderr, "SWIG : Unable to parse command line options.\n");
105 Printf(stderr, "Use 'swig -help' for available options.\n");