1 |
/* |
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 |
args_info->range_given = 0 ; |
44 |
} |
45 |
|
46 |
static |
47 |
void clear_args (struct gengetopt_args_info *args_info) |
48 |
{ |
49 |
args_info->shape_arg = NULL; |
50 |
args_info->output_arg = NULL; |
51 |
args_info->grid_arg = 101 ; |
52 |
args_info->range_arg = 10 ; |
53 |
} |
54 |
|
55 |
void |
56 |
cmdline_parser_print_version (void) |
57 |
{ |
58 |
printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); |
59 |
} |
60 |
|
61 |
void |
62 |
cmdline_parser_print_help (void) |
63 |
{ |
64 |
cmdline_parser_print_version (); |
65 |
printf("\n" |
66 |
"Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE); |
67 |
printf("\n"); |
68 |
printf("%s\n"," -h, --help Print help and exit"); |
69 |
printf("%s\n"," -V, --version Print version and exit"); |
70 |
printf("%s\n"," -s, --shape=filename shape file name"); |
71 |
printf("%s\n"," -o, --output=filename output file name"); |
72 |
printf("%s\n"," -g, --grid=INT number of grid points in each coordinate (default=\n `101')"); |
73 |
printf("%s\n"," -r, --range=DOUBLE the sample range for the points in Angstroms (Ex: 10 =\n -10 to 10) (default=`10')"); |
74 |
} |
75 |
|
76 |
void |
77 |
cmdline_parser_init (struct gengetopt_args_info *args_info) |
78 |
{ |
79 |
clear_given (args_info); |
80 |
clear_args (args_info); |
81 |
} |
82 |
|
83 |
void |
84 |
cmdline_parser_free (struct gengetopt_args_info *args_info) |
85 |
{ |
86 |
|
87 |
if (args_info->shape_arg) |
88 |
{ |
89 |
free (args_info->shape_arg); /* free previous argument */ |
90 |
args_info->shape_arg = 0; |
91 |
} |
92 |
if (args_info->output_arg) |
93 |
{ |
94 |
free (args_info->output_arg); /* free previous argument */ |
95 |
args_info->output_arg = 0; |
96 |
} |
97 |
|
98 |
clear_given (args_info); |
99 |
} |
100 |
|
101 |
|
102 |
/* gengetopt_strdup() */ |
103 |
/* strdup.c replacement of strdup, which is not standard */ |
104 |
char * |
105 |
gengetopt_strdup (const char *s) |
106 |
{ |
107 |
char *result = NULL; |
108 |
if (!s) |
109 |
return result; |
110 |
|
111 |
result = (char*)malloc(strlen(s) + 1); |
112 |
if (result == (char*)0) |
113 |
return (char*)0; |
114 |
strcpy(result, s); |
115 |
return result; |
116 |
} |
117 |
|
118 |
int |
119 |
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
120 |
{ |
121 |
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
122 |
} |
123 |
|
124 |
int |
125 |
cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
126 |
{ |
127 |
int result; |
128 |
|
129 |
result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); |
130 |
|
131 |
if (result == EXIT_FAILURE) |
132 |
{ |
133 |
cmdline_parser_free (args_info); |
134 |
exit (EXIT_FAILURE); |
135 |
} |
136 |
|
137 |
return result; |
138 |
} |
139 |
|
140 |
int |
141 |
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) |
142 |
{ |
143 |
int c; /* Character of the parsed option. */ |
144 |
int error = 0; |
145 |
struct gengetopt_args_info local_args_info; |
146 |
|
147 |
if (initialize) |
148 |
cmdline_parser_init (args_info); |
149 |
|
150 |
cmdline_parser_init (&local_args_info); |
151 |
|
152 |
optarg = 0; |
153 |
optind = 1; |
154 |
opterr = 1; |
155 |
optopt = '?'; |
156 |
|
157 |
while (1) |
158 |
{ |
159 |
int option_index = 0; |
160 |
char *stop_char; |
161 |
|
162 |
static struct option long_options[] = { |
163 |
{ "help", 0, NULL, 'h' }, |
164 |
{ "version", 0, NULL, 'V' }, |
165 |
{ "shape", 1, NULL, 's' }, |
166 |
{ "output", 1, NULL, 'o' }, |
167 |
{ "grid", 1, NULL, 'g' }, |
168 |
{ "range", 1, NULL, 'r' }, |
169 |
{ NULL, 0, NULL, 0 } |
170 |
}; |
171 |
|
172 |
stop_char = 0; |
173 |
c = getopt_long (argc, argv, "hVs:o:g:r:", long_options, &option_index); |
174 |
|
175 |
if (c == -1) break; /* Exit from `while (1)' loop. */ |
176 |
|
177 |
switch (c) |
178 |
{ |
179 |
case 'h': /* Print help and exit. */ |
180 |
cmdline_parser_print_help (); |
181 |
exit (EXIT_SUCCESS); |
182 |
|
183 |
case 'V': /* Print version and exit. */ |
184 |
cmdline_parser_print_version (); |
185 |
exit (EXIT_SUCCESS); |
186 |
|
187 |
case 's': /* shape file name. */ |
188 |
if (local_args_info.shape_given) |
189 |
{ |
190 |
fprintf (stderr, "%s: `--shape' (`-s') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
191 |
goto failure; |
192 |
} |
193 |
if (args_info->shape_given && ! override) |
194 |
continue; |
195 |
local_args_info.shape_given = 1; |
196 |
args_info->shape_given = 1; |
197 |
if (args_info->shape_arg) |
198 |
free (args_info->shape_arg); /* free previous string */ |
199 |
args_info->shape_arg = gengetopt_strdup (optarg); |
200 |
break; |
201 |
|
202 |
case 'o': /* output file name. */ |
203 |
if (local_args_info.output_given) |
204 |
{ |
205 |
fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
206 |
goto failure; |
207 |
} |
208 |
if (args_info->output_given && ! override) |
209 |
continue; |
210 |
local_args_info.output_given = 1; |
211 |
args_info->output_given = 1; |
212 |
if (args_info->output_arg) |
213 |
free (args_info->output_arg); /* free previous string */ |
214 |
args_info->output_arg = gengetopt_strdup (optarg); |
215 |
break; |
216 |
|
217 |
case 'g': /* number of grid points in each coordinate. */ |
218 |
if (local_args_info.grid_given) |
219 |
{ |
220 |
fprintf (stderr, "%s: `--grid' (`-g') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
221 |
goto failure; |
222 |
} |
223 |
if (args_info->grid_given && ! override) |
224 |
continue; |
225 |
local_args_info.grid_given = 1; |
226 |
args_info->grid_given = 1; |
227 |
args_info->grid_arg = strtol (optarg,&stop_char,0); |
228 |
break; |
229 |
|
230 |
case 'r': /* the sample range for the points in Angstroms (Ex: 10 = -10 to 10). */ |
231 |
if (local_args_info.range_given) |
232 |
{ |
233 |
fprintf (stderr, "%s: `--range' (`-r') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
234 |
goto failure; |
235 |
} |
236 |
if (args_info->range_given && ! override) |
237 |
continue; |
238 |
local_args_info.range_given = 1; |
239 |
args_info->range_given = 1; |
240 |
args_info->range_arg = strtod (optarg, NULL); |
241 |
break; |
242 |
|
243 |
|
244 |
case 0: /* Long option with no short option */ |
245 |
|
246 |
case '?': /* Invalid option. */ |
247 |
/* `getopt_long' already printed an error message. */ |
248 |
goto failure; |
249 |
|
250 |
default: /* bug: option not considered. */ |
251 |
fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
252 |
abort (); |
253 |
} /* switch */ |
254 |
} /* while */ |
255 |
|
256 |
|
257 |
|
258 |
if (check_required) |
259 |
{ |
260 |
if (! args_info->shape_given) |
261 |
{ |
262 |
fprintf (stderr, "%s: '--shape' ('-s') option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
263 |
error = 1; |
264 |
} |
265 |
if (! args_info->output_given) |
266 |
{ |
267 |
fprintf (stderr, "%s: '--output' ('-o') option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
268 |
error = 1; |
269 |
} |
270 |
} |
271 |
|
272 |
if ( error ) |
273 |
return (EXIT_FAILURE); |
274 |
|
275 |
return 0; |
276 |
|
277 |
failure: |
278 |
cmdline_parser_free (&local_args_info); |
279 |
return (EXIT_FAILURE); |
280 |
} |