1 |
|
/* |
2 |
< |
File autogenerated by gengetopt version 2.11 |
2 |
> |
File autogenerated by gengetopt version 2.16 |
3 |
|
generated with the following command: |
4 |
< |
/home/maul/gezelter/tim/program/gengetopt-2.11/src/gengetopt -F simpleBuilderCmd -u |
4 |
> |
gengetopt -F simpleBuilderCmd --unamed-opts |
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 |
– |
|
12 |
– |
#include <stdio.h> |
13 |
– |
#include <stdlib.h> |
14 |
– |
#include <string.h> |
15 |
– |
|
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 "applications/simpleBuilder/simpleBuilderCmd.h" |
22 |
> |
#include "simpleBuilderCmd.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 int |
33 |
+ |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); |
34 |
+ |
|
35 |
+ |
static char * |
36 |
+ |
gengetopt_strdup (const char *s); |
37 |
+ |
|
38 |
+ |
static |
39 |
+ |
void clear_given (struct gengetopt_args_info *args_info) |
40 |
+ |
{ |
41 |
+ |
args_info->help_given = 0 ; |
42 |
+ |
args_info->version_given = 0 ; |
43 |
+ |
args_info->output_given = 0 ; |
44 |
+ |
args_info->density_given = 0 ; |
45 |
+ |
args_info->nx_given = 0 ; |
46 |
+ |
args_info->ny_given = 0 ; |
47 |
+ |
args_info->nz_given = 0 ; |
48 |
+ |
} |
49 |
+ |
|
50 |
+ |
static |
51 |
+ |
void clear_args (struct gengetopt_args_info *args_info) |
52 |
+ |
{ |
53 |
+ |
args_info->output_arg = NULL; |
54 |
+ |
args_info->output_orig = NULL; |
55 |
+ |
args_info->density_orig = NULL; |
56 |
+ |
args_info->nx_orig = NULL; |
57 |
+ |
args_info->ny_orig = NULL; |
58 |
+ |
args_info->nz_orig = NULL; |
59 |
+ |
|
60 |
+ |
} |
61 |
+ |
|
62 |
|
void |
63 |
|
cmdline_parser_print_version (void) |
64 |
|
{ |
69 |
|
cmdline_parser_print_help (void) |
70 |
|
{ |
71 |
|
cmdline_parser_print_version (); |
72 |
< |
printf("\n" |
73 |
< |
"Usage: %s [OPTIONS]... [FILES]...\n", CMDLINE_PARSER_PACKAGE); |
74 |
< |
printf("\n"); |
75 |
< |
printf(" -h, --help Print help and exit\n"); |
76 |
< |
printf(" -V, --version Print version and exit\n"); |
77 |
< |
printf(" -o, --output=STRING Output file name\n"); |
78 |
< |
printf(" --latticetype=STRING Lattice type string. Valid types are fcc,hcp,bcc \n and hcp-water. (default=`fcc')\n"); |
79 |
< |
printf(" --density=DOUBLE density (g/cm^3)\n"); |
80 |
< |
printf(" --nx=INT number of unit cells in x\n"); |
44 |
< |
printf(" --ny=INT number of unit cells in y\n"); |
45 |
< |
printf(" --nz=INT number of unit cells in z\n"); |
72 |
> |
printf("\nUsage: simpleBuilder [OPTIONS]... [FILES]...\n\n"); |
73 |
> |
printf("%s\n"," -h, --help Print help and exit"); |
74 |
> |
printf("%s\n"," -V, --version Print version and exit"); |
75 |
> |
printf("%s\n"," -o, --output=STRING Output file name"); |
76 |
> |
printf("%s\n"," --density=DOUBLE density (g/cm^3)"); |
77 |
> |
printf("%s\n"," --nx=INT number of unit cells in x"); |
78 |
> |
printf("%s\n"," --ny=INT number of unit cells in y"); |
79 |
> |
printf("%s\n"," --nz=INT number of unit cells in z"); |
80 |
> |
|
81 |
|
} |
82 |
|
|
83 |
+ |
void |
84 |
+ |
cmdline_parser_init (struct gengetopt_args_info *args_info) |
85 |
+ |
{ |
86 |
+ |
clear_given (args_info); |
87 |
+ |
clear_args (args_info); |
88 |
|
|
89 |
< |
static char *gengetopt_strdup (const char *s); |
89 |
> |
args_info->inputs = NULL; |
90 |
> |
args_info->inputs_num = 0; |
91 |
> |
} |
92 |
|
|
93 |
+ |
static void |
94 |
+ |
cmdline_parser_release (struct gengetopt_args_info *args_info) |
95 |
+ |
{ |
96 |
+ |
|
97 |
+ |
unsigned int i; |
98 |
+ |
if (args_info->output_arg) |
99 |
+ |
{ |
100 |
+ |
free (args_info->output_arg); /* free previous argument */ |
101 |
+ |
args_info->output_arg = 0; |
102 |
+ |
} |
103 |
+ |
if (args_info->output_orig) |
104 |
+ |
{ |
105 |
+ |
free (args_info->output_orig); /* free previous argument */ |
106 |
+ |
args_info->output_orig = 0; |
107 |
+ |
} |
108 |
+ |
if (args_info->density_orig) |
109 |
+ |
{ |
110 |
+ |
free (args_info->density_orig); /* free previous argument */ |
111 |
+ |
args_info->density_orig = 0; |
112 |
+ |
} |
113 |
+ |
if (args_info->nx_orig) |
114 |
+ |
{ |
115 |
+ |
free (args_info->nx_orig); /* free previous argument */ |
116 |
+ |
args_info->nx_orig = 0; |
117 |
+ |
} |
118 |
+ |
if (args_info->ny_orig) |
119 |
+ |
{ |
120 |
+ |
free (args_info->ny_orig); /* free previous argument */ |
121 |
+ |
args_info->ny_orig = 0; |
122 |
+ |
} |
123 |
+ |
if (args_info->nz_orig) |
124 |
+ |
{ |
125 |
+ |
free (args_info->nz_orig); /* free previous argument */ |
126 |
+ |
args_info->nz_orig = 0; |
127 |
+ |
} |
128 |
+ |
|
129 |
+ |
for (i = 0; i < args_info->inputs_num; ++i) |
130 |
+ |
free (args_info->inputs [i]); |
131 |
+ |
|
132 |
+ |
if (args_info->inputs_num) |
133 |
+ |
free (args_info->inputs); |
134 |
+ |
|
135 |
+ |
clear_given (args_info); |
136 |
+ |
} |
137 |
+ |
|
138 |
+ |
int |
139 |
+ |
cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) |
140 |
+ |
{ |
141 |
+ |
FILE *outfile; |
142 |
+ |
int i = 0; |
143 |
+ |
|
144 |
+ |
outfile = fopen(filename, "w"); |
145 |
+ |
|
146 |
+ |
if (!outfile) |
147 |
+ |
{ |
148 |
+ |
fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); |
149 |
+ |
return EXIT_FAILURE; |
150 |
+ |
} |
151 |
+ |
|
152 |
+ |
if (args_info->help_given) { |
153 |
+ |
fprintf(outfile, "%s\n", "help"); |
154 |
+ |
} |
155 |
+ |
if (args_info->version_given) { |
156 |
+ |
fprintf(outfile, "%s\n", "version"); |
157 |
+ |
} |
158 |
+ |
if (args_info->output_given) { |
159 |
+ |
if (args_info->output_orig) { |
160 |
+ |
fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig); |
161 |
+ |
} else { |
162 |
+ |
fprintf(outfile, "%s\n", "output"); |
163 |
+ |
} |
164 |
+ |
} |
165 |
+ |
if (args_info->density_given) { |
166 |
+ |
if (args_info->density_orig) { |
167 |
+ |
fprintf(outfile, "%s=\"%s\"\n", "density", args_info->density_orig); |
168 |
+ |
} else { |
169 |
+ |
fprintf(outfile, "%s\n", "density"); |
170 |
+ |
} |
171 |
+ |
} |
172 |
+ |
if (args_info->nx_given) { |
173 |
+ |
if (args_info->nx_orig) { |
174 |
+ |
fprintf(outfile, "%s=\"%s\"\n", "nx", args_info->nx_orig); |
175 |
+ |
} else { |
176 |
+ |
fprintf(outfile, "%s\n", "nx"); |
177 |
+ |
} |
178 |
+ |
} |
179 |
+ |
if (args_info->ny_given) { |
180 |
+ |
if (args_info->ny_orig) { |
181 |
+ |
fprintf(outfile, "%s=\"%s\"\n", "ny", args_info->ny_orig); |
182 |
+ |
} else { |
183 |
+ |
fprintf(outfile, "%s\n", "ny"); |
184 |
+ |
} |
185 |
+ |
} |
186 |
+ |
if (args_info->nz_given) { |
187 |
+ |
if (args_info->nz_orig) { |
188 |
+ |
fprintf(outfile, "%s=\"%s\"\n", "nz", args_info->nz_orig); |
189 |
+ |
} else { |
190 |
+ |
fprintf(outfile, "%s\n", "nz"); |
191 |
+ |
} |
192 |
+ |
} |
193 |
+ |
|
194 |
+ |
fclose (outfile); |
195 |
+ |
|
196 |
+ |
i = EXIT_SUCCESS; |
197 |
+ |
return i; |
198 |
+ |
} |
199 |
+ |
|
200 |
+ |
void |
201 |
+ |
cmdline_parser_free (struct gengetopt_args_info *args_info) |
202 |
+ |
{ |
203 |
+ |
cmdline_parser_release (args_info); |
204 |
+ |
} |
205 |
+ |
|
206 |
+ |
|
207 |
|
/* gengetopt_strdup() */ |
208 |
|
/* strdup.c replacement of strdup, which is not standard */ |
209 |
|
char * |
210 |
|
gengetopt_strdup (const char *s) |
211 |
|
{ |
212 |
< |
char *result = (char*)malloc(strlen(s) + 1); |
212 |
> |
char *result = NULL; |
213 |
> |
if (!s) |
214 |
> |
return result; |
215 |
> |
|
216 |
> |
result = (char*)malloc(strlen(s) + 1); |
217 |
|
if (result == (char*)0) |
218 |
|
return (char*)0; |
219 |
|
strcpy(result, s); |
223 |
|
int |
224 |
|
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
225 |
|
{ |
226 |
< |
int c; /* Character of the parsed option. */ |
227 |
< |
int missing_required_options = 0; |
226 |
> |
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
227 |
> |
} |
228 |
|
|
229 |
< |
args_info->help_given = 0 ; |
230 |
< |
args_info->version_given = 0 ; |
231 |
< |
args_info->output_given = 0 ; |
232 |
< |
args_info->latticetype_given = 0 ; |
233 |
< |
args_info->density_given = 0 ; |
234 |
< |
args_info->nx_given = 0 ; |
235 |
< |
args_info->ny_given = 0 ; |
236 |
< |
args_info->nz_given = 0 ; |
237 |
< |
#define clear_args() { \ |
238 |
< |
args_info->output_arg = NULL; \ |
239 |
< |
args_info->latticetype_arg = gengetopt_strdup("fcc") ;\ |
229 |
> |
int |
230 |
> |
cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
231 |
> |
{ |
232 |
> |
int result; |
233 |
> |
|
234 |
> |
result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); |
235 |
> |
|
236 |
> |
if (result == EXIT_FAILURE) |
237 |
> |
{ |
238 |
> |
cmdline_parser_free (args_info); |
239 |
> |
exit (EXIT_FAILURE); |
240 |
> |
} |
241 |
> |
|
242 |
> |
return result; |
243 |
|
} |
244 |
|
|
245 |
< |
clear_args(); |
245 |
> |
int |
246 |
> |
cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) |
247 |
> |
{ |
248 |
> |
int result = EXIT_SUCCESS; |
249 |
|
|
250 |
< |
args_info->inputs = NULL; |
251 |
< |
args_info->inputs_num = 0; |
250 |
> |
if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) |
251 |
> |
result = EXIT_FAILURE; |
252 |
> |
|
253 |
> |
if (result == EXIT_FAILURE) |
254 |
> |
{ |
255 |
> |
cmdline_parser_free (args_info); |
256 |
> |
exit (EXIT_FAILURE); |
257 |
> |
} |
258 |
> |
|
259 |
> |
return result; |
260 |
> |
} |
261 |
|
|
262 |
+ |
int |
263 |
+ |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) |
264 |
+ |
{ |
265 |
+ |
int error = 0; |
266 |
+ |
|
267 |
+ |
if (! args_info->output_given) |
268 |
+ |
{ |
269 |
+ |
fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); |
270 |
+ |
error = 1; |
271 |
+ |
} |
272 |
+ |
if (! args_info->density_given) |
273 |
+ |
{ |
274 |
+ |
fprintf (stderr, "%s: '--density' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
275 |
+ |
error = 1; |
276 |
+ |
} |
277 |
+ |
if (! args_info->nx_given) |
278 |
+ |
{ |
279 |
+ |
fprintf (stderr, "%s: '--nx' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
280 |
+ |
error = 1; |
281 |
+ |
} |
282 |
+ |
if (! args_info->ny_given) |
283 |
+ |
{ |
284 |
+ |
fprintf (stderr, "%s: '--ny' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
285 |
+ |
error = 1; |
286 |
+ |
} |
287 |
+ |
if (! args_info->nz_given) |
288 |
+ |
{ |
289 |
+ |
fprintf (stderr, "%s: '--nz' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
290 |
+ |
error = 1; |
291 |
+ |
} |
292 |
+ |
|
293 |
+ |
return error; |
294 |
+ |
} |
295 |
+ |
|
296 |
+ |
int |
297 |
+ |
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) |
298 |
+ |
{ |
299 |
+ |
int c; /* Character of the parsed option. */ |
300 |
+ |
|
301 |
+ |
int error = 0; |
302 |
+ |
struct gengetopt_args_info local_args_info; |
303 |
+ |
|
304 |
+ |
if (initialize) |
305 |
+ |
cmdline_parser_init (args_info); |
306 |
+ |
|
307 |
+ |
cmdline_parser_init (&local_args_info); |
308 |
+ |
|
309 |
|
optarg = 0; |
310 |
< |
optind = 1; |
310 |
> |
optind = 0; |
311 |
|
opterr = 1; |
312 |
|
optopt = '?'; |
313 |
|
|
320 |
|
{ "help", 0, NULL, 'h' }, |
321 |
|
{ "version", 0, NULL, 'V' }, |
322 |
|
{ "output", 1, NULL, 'o' }, |
101 |
– |
{ "latticetype", 1, NULL, 0 }, |
323 |
|
{ "density", 1, NULL, 0 }, |
324 |
|
{ "nx", 1, NULL, 0 }, |
325 |
|
{ "ny", 1, NULL, 0 }, |
335 |
|
switch (c) |
336 |
|
{ |
337 |
|
case 'h': /* Print help and exit. */ |
117 |
– |
clear_args (); |
338 |
|
cmdline_parser_print_help (); |
339 |
+ |
cmdline_parser_free (&local_args_info); |
340 |
|
exit (EXIT_SUCCESS); |
341 |
|
|
342 |
|
case 'V': /* Print version and exit. */ |
122 |
– |
clear_args (); |
343 |
|
cmdline_parser_print_version (); |
344 |
+ |
cmdline_parser_free (&local_args_info); |
345 |
|
exit (EXIT_SUCCESS); |
346 |
|
|
347 |
|
case 'o': /* Output file name. */ |
348 |
< |
if (args_info->output_given) |
348 |
> |
if (local_args_info.output_given) |
349 |
|
{ |
350 |
< |
fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
351 |
< |
clear_args (); |
131 |
< |
exit (EXIT_FAILURE); |
350 |
> |
fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
351 |
> |
goto failure; |
352 |
|
} |
353 |
+ |
if (args_info->output_given && ! override) |
354 |
+ |
continue; |
355 |
+ |
local_args_info.output_given = 1; |
356 |
|
args_info->output_given = 1; |
357 |
+ |
if (args_info->output_arg) |
358 |
+ |
free (args_info->output_arg); /* free previous string */ |
359 |
|
args_info->output_arg = gengetopt_strdup (optarg); |
360 |
+ |
if (args_info->output_orig) |
361 |
+ |
free (args_info->output_orig); /* free previous string */ |
362 |
+ |
args_info->output_orig = gengetopt_strdup (optarg); |
363 |
|
break; |
364 |
|
|
365 |
|
|
366 |
|
case 0: /* Long option with no short option */ |
139 |
– |
/* Lattice type string. Valid types are fcc,hcp,bcc and hcp-water.. */ |
140 |
– |
if (strcmp (long_options[option_index].name, "latticetype") == 0) |
141 |
– |
{ |
142 |
– |
if (args_info->latticetype_given) |
143 |
– |
{ |
144 |
– |
fprintf (stderr, "%s: `--latticetype' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
145 |
– |
clear_args (); |
146 |
– |
exit (EXIT_FAILURE); |
147 |
– |
} |
148 |
– |
args_info->latticetype_given = 1; |
149 |
– |
if (args_info->latticetype_arg) |
150 |
– |
free (args_info->latticetype_arg); /* free default string */ |
151 |
– |
args_info->latticetype_arg = gengetopt_strdup (optarg); |
152 |
– |
break; |
153 |
– |
} |
154 |
– |
|
367 |
|
/* density (g/cm^3). */ |
368 |
< |
else if (strcmp (long_options[option_index].name, "density") == 0) |
368 |
> |
if (strcmp (long_options[option_index].name, "density") == 0) |
369 |
|
{ |
370 |
< |
if (args_info->density_given) |
370 |
> |
if (local_args_info.density_given) |
371 |
|
{ |
372 |
< |
fprintf (stderr, "%s: `--density' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
373 |
< |
clear_args (); |
162 |
< |
exit (EXIT_FAILURE); |
372 |
> |
fprintf (stderr, "%s: `--density' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
373 |
> |
goto failure; |
374 |
|
} |
375 |
+ |
if (args_info->density_given && ! override) |
376 |
+ |
continue; |
377 |
+ |
local_args_info.density_given = 1; |
378 |
|
args_info->density_given = 1; |
379 |
< |
args_info->density_arg = strtod (optarg, NULL); |
380 |
< |
break; |
379 |
> |
args_info->density_arg = strtod (optarg, &stop_char); |
380 |
> |
if (!(stop_char && *stop_char == '\0')) { |
381 |
> |
fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); |
382 |
> |
goto failure; |
383 |
> |
} |
384 |
> |
if (args_info->density_orig) |
385 |
> |
free (args_info->density_orig); /* free previous string */ |
386 |
> |
args_info->density_orig = gengetopt_strdup (optarg); |
387 |
|
} |
168 |
– |
|
388 |
|
/* number of unit cells in x. */ |
389 |
|
else if (strcmp (long_options[option_index].name, "nx") == 0) |
390 |
|
{ |
391 |
< |
if (args_info->nx_given) |
391 |
> |
if (local_args_info.nx_given) |
392 |
|
{ |
393 |
< |
fprintf (stderr, "%s: `--nx' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
394 |
< |
clear_args (); |
176 |
< |
exit (EXIT_FAILURE); |
393 |
> |
fprintf (stderr, "%s: `--nx' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
394 |
> |
goto failure; |
395 |
|
} |
396 |
+ |
if (args_info->nx_given && ! override) |
397 |
+ |
continue; |
398 |
+ |
local_args_info.nx_given = 1; |
399 |
|
args_info->nx_given = 1; |
400 |
< |
args_info->nx_arg = strtol (optarg,&stop_char,0); |
401 |
< |
break; |
400 |
> |
args_info->nx_arg = strtol (optarg, &stop_char, 0); |
401 |
> |
if (!(stop_char && *stop_char == '\0')) { |
402 |
> |
fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); |
403 |
> |
goto failure; |
404 |
> |
} |
405 |
> |
if (args_info->nx_orig) |
406 |
> |
free (args_info->nx_orig); /* free previous string */ |
407 |
> |
args_info->nx_orig = gengetopt_strdup (optarg); |
408 |
|
} |
182 |
– |
|
409 |
|
/* number of unit cells in y. */ |
410 |
|
else if (strcmp (long_options[option_index].name, "ny") == 0) |
411 |
|
{ |
412 |
< |
if (args_info->ny_given) |
412 |
> |
if (local_args_info.ny_given) |
413 |
|
{ |
414 |
< |
fprintf (stderr, "%s: `--ny' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
415 |
< |
clear_args (); |
190 |
< |
exit (EXIT_FAILURE); |
414 |
> |
fprintf (stderr, "%s: `--ny' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
415 |
> |
goto failure; |
416 |
|
} |
417 |
+ |
if (args_info->ny_given && ! override) |
418 |
+ |
continue; |
419 |
+ |
local_args_info.ny_given = 1; |
420 |
|
args_info->ny_given = 1; |
421 |
< |
args_info->ny_arg = strtol (optarg,&stop_char,0); |
422 |
< |
break; |
421 |
> |
args_info->ny_arg = strtol (optarg, &stop_char, 0); |
422 |
> |
if (!(stop_char && *stop_char == '\0')) { |
423 |
> |
fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); |
424 |
> |
goto failure; |
425 |
> |
} |
426 |
> |
if (args_info->ny_orig) |
427 |
> |
free (args_info->ny_orig); /* free previous string */ |
428 |
> |
args_info->ny_orig = gengetopt_strdup (optarg); |
429 |
|
} |
196 |
– |
|
430 |
|
/* number of unit cells in z. */ |
431 |
|
else if (strcmp (long_options[option_index].name, "nz") == 0) |
432 |
|
{ |
433 |
< |
if (args_info->nz_given) |
433 |
> |
if (local_args_info.nz_given) |
434 |
|
{ |
435 |
< |
fprintf (stderr, "%s: `--nz' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
436 |
< |
clear_args (); |
204 |
< |
exit (EXIT_FAILURE); |
435 |
> |
fprintf (stderr, "%s: `--nz' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
436 |
> |
goto failure; |
437 |
|
} |
438 |
+ |
if (args_info->nz_given && ! override) |
439 |
+ |
continue; |
440 |
+ |
local_args_info.nz_given = 1; |
441 |
|
args_info->nz_given = 1; |
442 |
< |
args_info->nz_arg = strtol (optarg,&stop_char,0); |
443 |
< |
break; |
442 |
> |
args_info->nz_arg = strtol (optarg, &stop_char, 0); |
443 |
> |
if (!(stop_char && *stop_char == '\0')) { |
444 |
> |
fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); |
445 |
> |
goto failure; |
446 |
> |
} |
447 |
> |
if (args_info->nz_orig) |
448 |
> |
free (args_info->nz_orig); /* free previous string */ |
449 |
> |
args_info->nz_orig = gengetopt_strdup (optarg); |
450 |
|
} |
451 |
|
|
452 |
< |
|
452 |
> |
break; |
453 |
|
case '?': /* Invalid option. */ |
454 |
|
/* `getopt_long' already printed an error message. */ |
455 |
< |
exit (EXIT_FAILURE); |
455 |
> |
goto failure; |
456 |
|
|
457 |
|
default: /* bug: option not considered. */ |
458 |
< |
fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); |
458 |
> |
fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
459 |
|
abort (); |
460 |
|
} /* switch */ |
461 |
|
} /* while */ |
462 |
|
|
463 |
|
|
464 |
< |
if (! args_info->density_given) |
464 |
> |
|
465 |
> |
if (check_required) |
466 |
|
{ |
467 |
< |
fprintf (stderr, "%s: '--density' option required\n", CMDLINE_PARSER_PACKAGE); |
226 |
< |
missing_required_options = 1; |
467 |
> |
error += cmdline_parser_required2 (args_info, argv[0], additional_error); |
468 |
|
} |
228 |
– |
if (! args_info->nx_given) |
229 |
– |
{ |
230 |
– |
fprintf (stderr, "%s: '--nx' option required\n", CMDLINE_PARSER_PACKAGE); |
231 |
– |
missing_required_options = 1; |
232 |
– |
} |
233 |
– |
if (! args_info->ny_given) |
234 |
– |
{ |
235 |
– |
fprintf (stderr, "%s: '--ny' option required\n", CMDLINE_PARSER_PACKAGE); |
236 |
– |
missing_required_options = 1; |
237 |
– |
} |
238 |
– |
if (! args_info->nz_given) |
239 |
– |
{ |
240 |
– |
fprintf (stderr, "%s: '--nz' option required\n", CMDLINE_PARSER_PACKAGE); |
241 |
– |
missing_required_options = 1; |
242 |
– |
} |
243 |
– |
if ( missing_required_options ) |
244 |
– |
exit (EXIT_FAILURE); |
469 |
|
|
470 |
+ |
cmdline_parser_release (&local_args_info); |
471 |
+ |
|
472 |
+ |
if ( error ) |
473 |
+ |
return (EXIT_FAILURE); |
474 |
+ |
|
475 |
|
if (optind < argc) |
476 |
|
{ |
477 |
|
int i = 0 ; |
478 |
< |
|
478 |
> |
|
479 |
|
args_info->inputs_num = argc - optind ; |
480 |
< |
args_info->inputs = |
480 |
> |
args_info->inputs = |
481 |
|
(char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; |
482 |
|
while (optind < argc) |
483 |
< |
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; |
483 |
> |
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; |
484 |
|
} |
485 |
< |
|
485 |
> |
|
486 |
|
return 0; |
487 |
+ |
|
488 |
+ |
failure: |
489 |
+ |
|
490 |
+ |
cmdline_parser_release (&local_args_info); |
491 |
+ |
return (EXIT_FAILURE); |
492 |
|
} |