]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/SWIG/getopt.cxx
Since I have made several changes to SWIG over the years to accomodate
[wxWidgets.git] / wxPython / wxSWIG / SWIG / getopt.cxx
1 /*******************************************************************************
2 * Simplified Wrapper and Interface Generator (SWIG)
3 *
4 * Author : David Beazley
5 *
6 * Department of Computer Science
7 * University of Chicago
8 * 1100 E 58th Street
9 * Chicago, IL 60637
10 * beazley@cs.uchicago.edu
11 *
12 * Please read the file LICENSE for the copyright and terms by which SWIG
13 * can be used and distributed.
14 *******************************************************************************/
15
16 #include "internal.h"
17
18 /*******************************************************************************
19 * $Header$
20 *
21 * File : getopt.cxx
22 *
23 * This file defines a few functions for handling command line arguments.
24 * C++ makes this really funky---especially since each language module
25 * may want to extract it's own command line arguments.
26 *
27 * My own special version of getopt. This is a bit weird, because we
28 * don't know what the options are in advance (they could be determined
29 * by a language module).
30 *******************************************************************************/
31
32 static char **args;
33 static int numargs;
34 static int *marked;
35
36 // -----------------------------------------------------------------------------
37 // void init_args(int argc, char **argv)
38 //
39 // Initializes the argument list.
40 //
41 // Inputs :
42 // argc = Argument count
43 // argv = Argument array
44 //
45 // Output : None
46 //
47 // Side Effects : Saves local copy of argc and argv
48 // -----------------------------------------------------------------------------
49
50 void
51 init_args(int argc, char **argv)
52 {
53 int i;
54 numargs = argc;
55 args = argv;
56 marked = new int[numargs];
57 for (i = 0; i < argc; i++) {
58 marked[i] = 0;
59 }
60 marked[0] = 1;
61 }
62
63 // -----------------------------------------------------------------------------
64 // void mark_arg(int n)
65 //
66 // Marks an argument as being parsed. All modules should do this whenever they
67 // parse a command line option.
68 //
69 // Inputs : n = Argument number
70 //
71 // Output : None
72 //
73 // Side Effects : Sets a status bit internally
74 // -----------------------------------------------------------------------------
75
76 void
77 mark_arg(int n) {
78 if (marked)
79 marked[n] = 1;
80 }
81
82 // -----------------------------------------------------------------------------
83 // void check_options()
84 //
85 // Checks for unparsed command line options. If so, issues an error and exits.
86 //
87 // Inputs : None
88 //
89 // Output : None
90 //
91 // Side Effects : exits if there are unparsed options
92 // -----------------------------------------------------------------------------
93
94 void check_options() {
95
96 int error = 0;
97 int i;
98
99 if (!marked) {
100 fprintf(stderr,"Must specify an input file. Use -help for available options.\n");
101 SWIG_exit(1);
102 }
103 for (i = 1; i < numargs-1; i++) {
104 if (!marked[i]) {
105 fprintf(stderr,"swig error : Unrecognized option %s\n", args[i]);
106 error=1;
107 }
108 }
109
110 if (error) {
111 fprintf(stderr,"Use 'swig -help' for available options.\n");
112 SWIG_exit(1);
113 }
114
115 if (marked[numargs-1]) {
116 fprintf(stderr,"Must specify an input file. Use -help for available options.\n");
117 SWIG_exit(1);
118 }
119 }
120
121 // -----------------------------------------------------------------------------
122 // void arg_error()
123 //
124 // Generates a generic error message and exits.
125 //
126 // Inputs : None
127 //
128 // Output : None
129 //
130 // Side Effects : Exits
131 // -----------------------------------------------------------------------------
132
133 void arg_error() {
134 fprintf(stderr,"SWIG : Unable to parse command line options.\n");
135 fprintf(stderr,"Use 'swig -help' for available options.\n");
136 SWIG_exit(1);
137 }
138
139
140
141