1 |
gezelter |
1290 |
/* |
2 |
|
|
File autogenerated by gengetopt version 2.12.1 |
3 |
|
|
generated with the following command: |
4 |
|
|
gengetopt --file-name=visualizerCmd |
5 |
|
|
|
6 |
|
|
The developers of gengetopt consider the fixed text that goes in all |
7 |
|
|
gengetopt output files to be in the public domain: |
8 |
|
|
we make no copyright claims on it. |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
/* If we use autoconf. */ |
12 |
|
|
#ifdef HAVE_CONFIG_H |
13 |
|
|
#include "config.h" |
14 |
|
|
#endif |
15 |
|
|
|
16 |
|
|
#include <stdio.h> |
17 |
|
|
#include <stdlib.h> |
18 |
|
|
#include <string.h> |
19 |
|
|
|
20 |
|
|
#include "getopt.h" |
21 |
|
|
|
22 |
|
|
#include "visualizerCmd.h" |
23 |
|
|
|
24 |
|
|
static |
25 |
|
|
void clear_given (struct gengetopt_args_info *args_info); |
26 |
|
|
static |
27 |
|
|
void clear_args (struct gengetopt_args_info *args_info); |
28 |
|
|
|
29 |
|
|
static int |
30 |
|
|
cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error); |
31 |
|
|
|
32 |
|
|
static char * |
33 |
|
|
gengetopt_strdup (const char *s); |
34 |
|
|
|
35 |
|
|
static |
36 |
|
|
void clear_given (struct gengetopt_args_info *args_info) |
37 |
|
|
{ |
38 |
|
|
args_info->help_given = 0 ; |
39 |
|
|
args_info->version_given = 0 ; |
40 |
|
|
args_info->shape_given = 0 ; |
41 |
|
|
args_info->output_given = 0 ; |
42 |
|
|
args_info->grid_given = 0 ; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
static |
46 |
|
|
void clear_args (struct gengetopt_args_info *args_info) |
47 |
|
|
{ |
48 |
|
|
args_info->shape_arg = NULL; |
49 |
|
|
args_info->output_arg = NULL; |
50 |
gezelter |
1300 |
args_info->grid_arg = 101 ; |
51 |
gezelter |
1290 |
} |
52 |
|
|
|
53 |
|
|
void |
54 |
|
|
cmdline_parser_print_version (void) |
55 |
|
|
{ |
56 |
|
|
printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
void |
60 |
|
|
cmdline_parser_print_help (void) |
61 |
|
|
{ |
62 |
|
|
cmdline_parser_print_version (); |
63 |
|
|
printf("\n" |
64 |
|
|
"Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE); |
65 |
|
|
printf("\n"); |
66 |
|
|
printf("%s\n"," -h, --help Print help and exit"); |
67 |
|
|
printf("%s\n"," -V, --version Print version and exit"); |
68 |
|
|
printf("%s\n"," -s, --shape=filename shape file name"); |
69 |
|
|
printf("%s\n"," -o, --output=filename output file name"); |
70 |
gezelter |
1300 |
printf("%s\n"," -g, --grid=INT number of grid points in each coordinate (default=\n `101')"); |
71 |
gezelter |
1290 |
} |
72 |
|
|
|
73 |
|
|
void |
74 |
|
|
cmdline_parser_init (struct gengetopt_args_info *args_info) |
75 |
|
|
{ |
76 |
|
|
clear_given (args_info); |
77 |
|
|
clear_args (args_info); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
void |
81 |
|
|
cmdline_parser_free (struct gengetopt_args_info *args_info) |
82 |
|
|
{ |
83 |
|
|
|
84 |
|
|
if (args_info->shape_arg) |
85 |
|
|
{ |
86 |
|
|
free (args_info->shape_arg); /* free previous argument */ |
87 |
|
|
args_info->shape_arg = 0; |
88 |
|
|
} |
89 |
|
|
if (args_info->output_arg) |
90 |
|
|
{ |
91 |
|
|
free (args_info->output_arg); /* free previous argument */ |
92 |
|
|
args_info->output_arg = 0; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
clear_given (args_info); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
|
99 |
|
|
/* gengetopt_strdup() */ |
100 |
|
|
/* strdup.c replacement of strdup, which is not standard */ |
101 |
|
|
char * |
102 |
|
|
gengetopt_strdup (const char *s) |
103 |
|
|
{ |
104 |
|
|
char *result = NULL; |
105 |
|
|
if (!s) |
106 |
|
|
return result; |
107 |
|
|
|
108 |
|
|
result = (char*)malloc(strlen(s) + 1); |
109 |
|
|
if (result == (char*)0) |
110 |
|
|
return (char*)0; |
111 |
|
|
strcpy(result, s); |
112 |
|
|
return result; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
int |
116 |
|
|
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
117 |
|
|
{ |
118 |
|
|
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
int |
122 |
|
|
cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
123 |
|
|
{ |
124 |
|
|
int result; |
125 |
|
|
|
126 |
|
|
result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); |
127 |
|
|
|
128 |
|
|
if (result == EXIT_FAILURE) |
129 |
|
|
{ |
130 |
|
|
cmdline_parser_free (args_info); |
131 |
|
|
exit (EXIT_FAILURE); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
return result; |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
int |
138 |
|
|
cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error) |
139 |
|
|
{ |
140 |
|
|
int c; /* Character of the parsed option. */ |
141 |
|
|
int error = 0; |
142 |
|
|
struct gengetopt_args_info local_args_info; |
143 |
|
|
|
144 |
|
|
if (initialize) |
145 |
|
|
cmdline_parser_init (args_info); |
146 |
|
|
|
147 |
|
|
cmdline_parser_init (&local_args_info); |
148 |
|
|
|
149 |
|
|
optarg = 0; |
150 |
|
|
optind = 1; |
151 |
|
|
opterr = 1; |
152 |
|
|
optopt = '?'; |
153 |
|
|
|
154 |
|
|
while (1) |
155 |
|
|
{ |
156 |
|
|
int option_index = 0; |
157 |
|
|
char *stop_char; |
158 |
|
|
|
159 |
|
|
static struct option long_options[] = { |
160 |
|
|
{ "help", 0, NULL, 'h' }, |
161 |
|
|
{ "version", 0, NULL, 'V' }, |
162 |
|
|
{ "shape", 1, NULL, 's' }, |
163 |
|
|
{ "output", 1, NULL, 'o' }, |
164 |
|
|
{ "grid", 1, NULL, 'g' }, |
165 |
|
|
{ NULL, 0, NULL, 0 } |
166 |
|
|
}; |
167 |
|
|
|
168 |
|
|
stop_char = 0; |
169 |
|
|
c = getopt_long (argc, argv, "hVs:o:g:", long_options, &option_index); |
170 |
|
|
|
171 |
|
|
if (c == -1) break; /* Exit from `while (1)' loop. */ |
172 |
|
|
|
173 |
|
|
switch (c) |
174 |
|
|
{ |
175 |
|
|
case 'h': /* Print help and exit. */ |
176 |
|
|
cmdline_parser_print_help (); |
177 |
|
|
exit (EXIT_SUCCESS); |
178 |
|
|
|
179 |
|
|
case 'V': /* Print version and exit. */ |
180 |
|
|
cmdline_parser_print_version (); |
181 |
|
|
exit (EXIT_SUCCESS); |
182 |
|
|
|
183 |
|
|
case 's': /* shape file name. */ |
184 |
|
|
if (local_args_info.shape_given) |
185 |
|
|
{ |
186 |
|
|
fprintf (stderr, "%s: `--shape' (`-s') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
187 |
|
|
goto failure; |
188 |
|
|
} |
189 |
|
|
if (args_info->shape_given && ! override) |
190 |
|
|
continue; |
191 |
|
|
local_args_info.shape_given = 1; |
192 |
|
|
args_info->shape_given = 1; |
193 |
|
|
if (args_info->shape_arg) |
194 |
|
|
free (args_info->shape_arg); /* free previous string */ |
195 |
|
|
args_info->shape_arg = gengetopt_strdup (optarg); |
196 |
|
|
break; |
197 |
|
|
|
198 |
|
|
case 'o': /* output file name. */ |
199 |
|
|
if (local_args_info.output_given) |
200 |
|
|
{ |
201 |
|
|
fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
202 |
|
|
goto failure; |
203 |
|
|
} |
204 |
|
|
if (args_info->output_given && ! override) |
205 |
|
|
continue; |
206 |
|
|
local_args_info.output_given = 1; |
207 |
|
|
args_info->output_given = 1; |
208 |
|
|
if (args_info->output_arg) |
209 |
|
|
free (args_info->output_arg); /* free previous string */ |
210 |
|
|
args_info->output_arg = gengetopt_strdup (optarg); |
211 |
|
|
break; |
212 |
|
|
|
213 |
|
|
case 'g': /* number of grid points in each coordinate. */ |
214 |
|
|
if (local_args_info.grid_given) |
215 |
|
|
{ |
216 |
|
|
fprintf (stderr, "%s: `--grid' (`-g') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
217 |
|
|
goto failure; |
218 |
|
|
} |
219 |
|
|
if (args_info->grid_given && ! override) |
220 |
|
|
continue; |
221 |
|
|
local_args_info.grid_given = 1; |
222 |
|
|
args_info->grid_given = 1; |
223 |
|
|
args_info->grid_arg = strtol (optarg,&stop_char,0); |
224 |
|
|
break; |
225 |
|
|
|
226 |
|
|
|
227 |
|
|
case 0: /* Long option with no short option */ |
228 |
|
|
|
229 |
|
|
case '?': /* Invalid option. */ |
230 |
|
|
/* `getopt_long' already printed an error message. */ |
231 |
|
|
goto failure; |
232 |
|
|
|
233 |
|
|
default: /* bug: option not considered. */ |
234 |
|
|
fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
235 |
|
|
abort (); |
236 |
|
|
} /* switch */ |
237 |
|
|
} /* while */ |
238 |
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
|
|
if (check_required) |
242 |
|
|
{ |
243 |
|
|
if (! args_info->shape_given) |
244 |
|
|
{ |
245 |
|
|
fprintf (stderr, "%s: '--shape' ('-s') option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
246 |
|
|
error = 1; |
247 |
|
|
} |
248 |
|
|
if (! args_info->output_given) |
249 |
|
|
{ |
250 |
|
|
fprintf (stderr, "%s: '--output' ('-o') option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
251 |
|
|
error = 1; |
252 |
|
|
} |
253 |
|
|
} |
254 |
|
|
|
255 |
|
|
if ( error ) |
256 |
|
|
return (EXIT_FAILURE); |
257 |
|
|
|
258 |
|
|
return 0; |
259 |
|
|
|
260 |
|
|
failure: |
261 |
|
|
cmdline_parser_free (&local_args_info); |
262 |
|
|
return (EXIT_FAILURE); |
263 |
|
|
} |