1 |
gezelter |
1083 |
/* |
2 |
gezelter |
1390 |
File autogenerated by gengetopt version 2.22 |
3 |
gezelter |
1083 |
generated with the following command: |
4 |
gezelter |
1390 |
gengetopt -u -F thermalizerCmd |
5 |
gezelter |
1083 |
|
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 "thermalizerCmd.h" |
23 |
|
|
|
24 |
gezelter |
1390 |
const char *gengetopt_args_info_purpose = "Resamples the velocities for all the integrable objects in an OpenMD file from \na Maxwell-Boltzmann distribution."; |
25 |
gezelter |
1083 |
|
26 |
|
|
const char *gengetopt_args_info_usage = "Usage: thermalizer [OPTIONS]... [FILES]..."; |
27 |
|
|
|
28 |
gezelter |
1390 |
const char *gengetopt_args_info_description = ""; |
29 |
|
|
|
30 |
gezelter |
1083 |
const char *gengetopt_args_info_help[] = { |
31 |
|
|
" -h, --help Print help and exit", |
32 |
|
|
" -V, --version Print version and exit", |
33 |
|
|
" -o, --output=STRING Output file name", |
34 |
|
|
" -t, --temperature=DOUBLE temperature (K)", |
35 |
|
|
0 |
36 |
|
|
}; |
37 |
|
|
|
38 |
gezelter |
1390 |
typedef enum {ARG_NO |
39 |
|
|
, ARG_STRING |
40 |
|
|
, ARG_DOUBLE |
41 |
|
|
} cmdline_parser_arg_type; |
42 |
|
|
|
43 |
gezelter |
1083 |
static |
44 |
|
|
void clear_given (struct gengetopt_args_info *args_info); |
45 |
|
|
static |
46 |
|
|
void clear_args (struct gengetopt_args_info *args_info); |
47 |
|
|
|
48 |
|
|
static int |
49 |
gezelter |
1390 |
cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, |
50 |
|
|
struct cmdline_parser_params *params, const char *additional_error); |
51 |
gezelter |
1083 |
|
52 |
|
|
static int |
53 |
|
|
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); |
54 |
|
|
|
55 |
|
|
static char * |
56 |
|
|
gengetopt_strdup (const char *s); |
57 |
|
|
|
58 |
|
|
static |
59 |
|
|
void clear_given (struct gengetopt_args_info *args_info) |
60 |
|
|
{ |
61 |
|
|
args_info->help_given = 0 ; |
62 |
|
|
args_info->version_given = 0 ; |
63 |
|
|
args_info->output_given = 0 ; |
64 |
|
|
args_info->temperature_given = 0 ; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
static |
68 |
|
|
void clear_args (struct gengetopt_args_info *args_info) |
69 |
|
|
{ |
70 |
|
|
args_info->output_arg = NULL; |
71 |
|
|
args_info->output_orig = NULL; |
72 |
|
|
args_info->temperature_orig = NULL; |
73 |
|
|
|
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
static |
77 |
|
|
void init_args_info(struct gengetopt_args_info *args_info) |
78 |
|
|
{ |
79 |
gezelter |
1390 |
|
80 |
|
|
|
81 |
gezelter |
1083 |
args_info->help_help = gengetopt_args_info_help[0] ; |
82 |
|
|
args_info->version_help = gengetopt_args_info_help[1] ; |
83 |
|
|
args_info->output_help = gengetopt_args_info_help[2] ; |
84 |
|
|
args_info->temperature_help = gengetopt_args_info_help[3] ; |
85 |
|
|
|
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
void |
89 |
|
|
cmdline_parser_print_version (void) |
90 |
|
|
{ |
91 |
|
|
printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); |
92 |
|
|
} |
93 |
|
|
|
94 |
gezelter |
1390 |
static void print_help_common(void) { |
95 |
gezelter |
1083 |
cmdline_parser_print_version (); |
96 |
|
|
|
97 |
|
|
if (strlen(gengetopt_args_info_purpose) > 0) |
98 |
|
|
printf("\n%s\n", gengetopt_args_info_purpose); |
99 |
|
|
|
100 |
gezelter |
1390 |
if (strlen(gengetopt_args_info_usage) > 0) |
101 |
|
|
printf("\n%s\n", gengetopt_args_info_usage); |
102 |
|
|
|
103 |
|
|
printf("\n"); |
104 |
|
|
|
105 |
|
|
if (strlen(gengetopt_args_info_description) > 0) |
106 |
|
|
printf("%s\n", gengetopt_args_info_description); |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
void |
110 |
|
|
cmdline_parser_print_help (void) |
111 |
|
|
{ |
112 |
|
|
int i = 0; |
113 |
|
|
print_help_common(); |
114 |
gezelter |
1083 |
while (gengetopt_args_info_help[i]) |
115 |
|
|
printf("%s\n", gengetopt_args_info_help[i++]); |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
void |
119 |
|
|
cmdline_parser_init (struct gengetopt_args_info *args_info) |
120 |
|
|
{ |
121 |
|
|
clear_given (args_info); |
122 |
|
|
clear_args (args_info); |
123 |
|
|
init_args_info (args_info); |
124 |
|
|
|
125 |
|
|
args_info->inputs = NULL; |
126 |
|
|
args_info->inputs_num = 0; |
127 |
|
|
} |
128 |
|
|
|
129 |
gezelter |
1390 |
void |
130 |
|
|
cmdline_parser_params_init(struct cmdline_parser_params *params) |
131 |
|
|
{ |
132 |
|
|
if (params) |
133 |
|
|
{ |
134 |
|
|
params->override = 0; |
135 |
|
|
params->initialize = 1; |
136 |
|
|
params->check_required = 1; |
137 |
|
|
params->check_ambiguity = 0; |
138 |
|
|
params->print_errors = 1; |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
struct cmdline_parser_params * |
143 |
|
|
cmdline_parser_params_create(void) |
144 |
|
|
{ |
145 |
|
|
struct cmdline_parser_params *params = |
146 |
|
|
(struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); |
147 |
|
|
cmdline_parser_params_init(params); |
148 |
|
|
return params; |
149 |
|
|
} |
150 |
|
|
|
151 |
gezelter |
1083 |
static void |
152 |
gezelter |
1390 |
free_string_field (char **s) |
153 |
|
|
{ |
154 |
|
|
if (*s) |
155 |
|
|
{ |
156 |
|
|
free (*s); |
157 |
|
|
*s = 0; |
158 |
|
|
} |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
|
162 |
|
|
static void |
163 |
gezelter |
1083 |
cmdline_parser_release (struct gengetopt_args_info *args_info) |
164 |
|
|
{ |
165 |
|
|
unsigned int i; |
166 |
gezelter |
1390 |
free_string_field (&(args_info->output_arg)); |
167 |
|
|
free_string_field (&(args_info->output_orig)); |
168 |
|
|
free_string_field (&(args_info->temperature_orig)); |
169 |
gezelter |
1083 |
|
170 |
gezelter |
1390 |
|
171 |
gezelter |
1083 |
for (i = 0; i < args_info->inputs_num; ++i) |
172 |
|
|
free (args_info->inputs [i]); |
173 |
gezelter |
1390 |
|
174 |
gezelter |
1083 |
if (args_info->inputs_num) |
175 |
|
|
free (args_info->inputs); |
176 |
gezelter |
1390 |
|
177 |
gezelter |
1083 |
clear_given (args_info); |
178 |
|
|
} |
179 |
|
|
|
180 |
gezelter |
1390 |
|
181 |
|
|
static void |
182 |
|
|
write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) |
183 |
|
|
{ |
184 |
|
|
if (arg) { |
185 |
|
|
fprintf(outfile, "%s=\"%s\"\n", opt, arg); |
186 |
|
|
} else { |
187 |
|
|
fprintf(outfile, "%s\n", opt); |
188 |
|
|
} |
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
|
192 |
gezelter |
1083 |
int |
193 |
gezelter |
1390 |
cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) |
194 |
|
|
{ |
195 |
|
|
int i = 0; |
196 |
|
|
|
197 |
|
|
if (!outfile) |
198 |
|
|
{ |
199 |
|
|
fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); |
200 |
|
|
return EXIT_FAILURE; |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
if (args_info->help_given) |
204 |
|
|
write_into_file(outfile, "help", 0, 0 ); |
205 |
|
|
if (args_info->version_given) |
206 |
|
|
write_into_file(outfile, "version", 0, 0 ); |
207 |
|
|
if (args_info->output_given) |
208 |
|
|
write_into_file(outfile, "output", args_info->output_orig, 0); |
209 |
|
|
if (args_info->temperature_given) |
210 |
|
|
write_into_file(outfile, "temperature", args_info->temperature_orig, 0); |
211 |
|
|
|
212 |
|
|
|
213 |
|
|
i = EXIT_SUCCESS; |
214 |
|
|
return i; |
215 |
|
|
} |
216 |
|
|
|
217 |
|
|
int |
218 |
gezelter |
1083 |
cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) |
219 |
|
|
{ |
220 |
|
|
FILE *outfile; |
221 |
|
|
int i = 0; |
222 |
|
|
|
223 |
|
|
outfile = fopen(filename, "w"); |
224 |
|
|
|
225 |
|
|
if (!outfile) |
226 |
|
|
{ |
227 |
|
|
fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); |
228 |
|
|
return EXIT_FAILURE; |
229 |
|
|
} |
230 |
|
|
|
231 |
gezelter |
1390 |
i = cmdline_parser_dump(outfile, args_info); |
232 |
gezelter |
1083 |
fclose (outfile); |
233 |
|
|
|
234 |
|
|
return i; |
235 |
|
|
} |
236 |
|
|
|
237 |
|
|
void |
238 |
|
|
cmdline_parser_free (struct gengetopt_args_info *args_info) |
239 |
|
|
{ |
240 |
|
|
cmdline_parser_release (args_info); |
241 |
|
|
} |
242 |
|
|
|
243 |
gezelter |
1390 |
/** @brief replacement of strdup, which is not standard */ |
244 |
gezelter |
1083 |
char * |
245 |
|
|
gengetopt_strdup (const char *s) |
246 |
|
|
{ |
247 |
|
|
char *result = NULL; |
248 |
|
|
if (!s) |
249 |
|
|
return result; |
250 |
|
|
|
251 |
|
|
result = (char*)malloc(strlen(s) + 1); |
252 |
|
|
if (result == (char*)0) |
253 |
|
|
return (char*)0; |
254 |
|
|
strcpy(result, s); |
255 |
|
|
return result; |
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
int |
259 |
|
|
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
260 |
|
|
{ |
261 |
|
|
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
262 |
|
|
} |
263 |
|
|
|
264 |
|
|
int |
265 |
gezelter |
1390 |
cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *args_info, |
266 |
|
|
struct cmdline_parser_params *params) |
267 |
|
|
{ |
268 |
|
|
int result; |
269 |
|
|
result = cmdline_parser_internal (argc, argv, args_info, params, NULL); |
270 |
|
|
|
271 |
|
|
if (result == EXIT_FAILURE) |
272 |
|
|
{ |
273 |
|
|
cmdline_parser_free (args_info); |
274 |
|
|
exit (EXIT_FAILURE); |
275 |
|
|
} |
276 |
|
|
|
277 |
|
|
return result; |
278 |
|
|
} |
279 |
|
|
|
280 |
|
|
int |
281 |
gezelter |
1083 |
cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
282 |
|
|
{ |
283 |
|
|
int result; |
284 |
gezelter |
1390 |
struct cmdline_parser_params params; |
285 |
|
|
|
286 |
|
|
params.override = override; |
287 |
|
|
params.initialize = initialize; |
288 |
|
|
params.check_required = check_required; |
289 |
|
|
params.check_ambiguity = 0; |
290 |
|
|
params.print_errors = 1; |
291 |
gezelter |
1083 |
|
292 |
gezelter |
1390 |
result = cmdline_parser_internal (argc, argv, args_info, ¶ms, NULL); |
293 |
gezelter |
1083 |
|
294 |
|
|
if (result == EXIT_FAILURE) |
295 |
|
|
{ |
296 |
|
|
cmdline_parser_free (args_info); |
297 |
|
|
exit (EXIT_FAILURE); |
298 |
|
|
} |
299 |
|
|
|
300 |
|
|
return result; |
301 |
|
|
} |
302 |
|
|
|
303 |
|
|
int |
304 |
|
|
cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) |
305 |
|
|
{ |
306 |
|
|
int result = EXIT_SUCCESS; |
307 |
|
|
|
308 |
|
|
if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) |
309 |
|
|
result = EXIT_FAILURE; |
310 |
|
|
|
311 |
|
|
if (result == EXIT_FAILURE) |
312 |
|
|
{ |
313 |
|
|
cmdline_parser_free (args_info); |
314 |
|
|
exit (EXIT_FAILURE); |
315 |
|
|
} |
316 |
|
|
|
317 |
|
|
return result; |
318 |
|
|
} |
319 |
|
|
|
320 |
|
|
int |
321 |
|
|
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) |
322 |
|
|
{ |
323 |
|
|
int error = 0; |
324 |
|
|
|
325 |
|
|
/* checks for required options */ |
326 |
|
|
if (! args_info->output_given) |
327 |
|
|
{ |
328 |
|
|
fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); |
329 |
|
|
error = 1; |
330 |
|
|
} |
331 |
|
|
|
332 |
|
|
if (! args_info->temperature_given) |
333 |
|
|
{ |
334 |
|
|
fprintf (stderr, "%s: '--temperature' ('-t') option required%s\n", prog_name, (additional_error ? additional_error : "")); |
335 |
|
|
error = 1; |
336 |
|
|
} |
337 |
|
|
|
338 |
|
|
|
339 |
|
|
/* checks for dependences among options */ |
340 |
|
|
|
341 |
|
|
return error; |
342 |
|
|
} |
343 |
|
|
|
344 |
gezelter |
1390 |
|
345 |
|
|
static char *package_name = 0; |
346 |
|
|
|
347 |
|
|
/** |
348 |
|
|
* @brief updates an option |
349 |
|
|
* @param field the generic pointer to the field to update |
350 |
|
|
* @param orig_field the pointer to the orig field |
351 |
|
|
* @param field_given the pointer to the number of occurrence of this option |
352 |
|
|
* @param prev_given the pointer to the number of occurrence already seen |
353 |
|
|
* @param value the argument for this option (if null no arg was specified) |
354 |
|
|
* @param possible_values the possible values for this option (if specified) |
355 |
|
|
* @param default_value the default value (in case the option only accepts fixed values) |
356 |
|
|
* @param arg_type the type of this option |
357 |
|
|
* @param check_ambiguity @see cmdline_parser_params.check_ambiguity |
358 |
|
|
* @param override @see cmdline_parser_params.override |
359 |
|
|
* @param no_free whether to free a possible previous value |
360 |
|
|
* @param multiple_option whether this is a multiple option |
361 |
|
|
* @param long_opt the corresponding long option |
362 |
|
|
* @param short_opt the corresponding short option (or '-' if none) |
363 |
|
|
* @param additional_error possible further error specification |
364 |
|
|
*/ |
365 |
|
|
static |
366 |
|
|
int update_arg(void *field, char **orig_field, |
367 |
|
|
unsigned int *field_given, unsigned int *prev_given, |
368 |
|
|
char *value, char *possible_values[], const char *default_value, |
369 |
|
|
cmdline_parser_arg_type arg_type, |
370 |
|
|
int check_ambiguity, int override, |
371 |
|
|
int no_free, int multiple_option, |
372 |
|
|
const char *long_opt, char short_opt, |
373 |
|
|
const char *additional_error) |
374 |
|
|
{ |
375 |
|
|
char *stop_char = 0; |
376 |
|
|
const char *val = value; |
377 |
|
|
int found; |
378 |
|
|
char **string_field; |
379 |
|
|
|
380 |
|
|
stop_char = 0; |
381 |
|
|
found = 0; |
382 |
|
|
|
383 |
|
|
if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) |
384 |
|
|
{ |
385 |
|
|
if (short_opt != '-') |
386 |
|
|
fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", |
387 |
|
|
package_name, long_opt, short_opt, |
388 |
|
|
(additional_error ? additional_error : "")); |
389 |
|
|
else |
390 |
|
|
fprintf (stderr, "%s: `--%s' option given more than once%s\n", |
391 |
|
|
package_name, long_opt, |
392 |
|
|
(additional_error ? additional_error : "")); |
393 |
|
|
return 1; /* failure */ |
394 |
|
|
} |
395 |
|
|
|
396 |
|
|
|
397 |
|
|
if (field_given && *field_given && ! override) |
398 |
|
|
return 0; |
399 |
|
|
if (prev_given) |
400 |
|
|
(*prev_given)++; |
401 |
|
|
if (field_given) |
402 |
|
|
(*field_given)++; |
403 |
|
|
if (possible_values) |
404 |
|
|
val = possible_values[found]; |
405 |
|
|
|
406 |
|
|
switch(arg_type) { |
407 |
|
|
case ARG_DOUBLE: |
408 |
|
|
if (val) *((double *)field) = strtod (val, &stop_char); |
409 |
|
|
break; |
410 |
|
|
case ARG_STRING: |
411 |
|
|
if (val) { |
412 |
|
|
string_field = (char **)field; |
413 |
|
|
if (!no_free && *string_field) |
414 |
|
|
free (*string_field); /* free previous string */ |
415 |
|
|
*string_field = gengetopt_strdup (val); |
416 |
|
|
} |
417 |
|
|
break; |
418 |
|
|
default: |
419 |
|
|
break; |
420 |
|
|
}; |
421 |
|
|
|
422 |
|
|
/* check numeric conversion */ |
423 |
|
|
switch(arg_type) { |
424 |
|
|
case ARG_DOUBLE: |
425 |
|
|
if (val && !(stop_char && *stop_char == '\0')) { |
426 |
|
|
fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); |
427 |
|
|
return 1; /* failure */ |
428 |
|
|
} |
429 |
|
|
break; |
430 |
|
|
default: |
431 |
|
|
; |
432 |
|
|
}; |
433 |
|
|
|
434 |
|
|
/* store the original value */ |
435 |
|
|
switch(arg_type) { |
436 |
|
|
case ARG_NO: |
437 |
|
|
break; |
438 |
|
|
default: |
439 |
|
|
if (value && orig_field) { |
440 |
|
|
if (no_free) { |
441 |
|
|
*orig_field = value; |
442 |
|
|
} else { |
443 |
|
|
if (*orig_field) |
444 |
|
|
free (*orig_field); /* free previous string */ |
445 |
|
|
*orig_field = gengetopt_strdup (value); |
446 |
|
|
} |
447 |
|
|
} |
448 |
|
|
}; |
449 |
|
|
|
450 |
|
|
return 0; /* OK */ |
451 |
|
|
} |
452 |
|
|
|
453 |
|
|
|
454 |
gezelter |
1083 |
int |
455 |
gezelter |
1390 |
cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, |
456 |
|
|
struct cmdline_parser_params *params, const char *additional_error) |
457 |
gezelter |
1083 |
{ |
458 |
|
|
int c; /* Character of the parsed option. */ |
459 |
|
|
|
460 |
|
|
int error = 0; |
461 |
|
|
struct gengetopt_args_info local_args_info; |
462 |
gezelter |
1390 |
|
463 |
|
|
int override; |
464 |
|
|
int initialize; |
465 |
|
|
int check_required; |
466 |
|
|
int check_ambiguity; |
467 |
|
|
|
468 |
|
|
package_name = argv[0]; |
469 |
|
|
|
470 |
|
|
override = params->override; |
471 |
|
|
initialize = params->initialize; |
472 |
|
|
check_required = params->check_required; |
473 |
|
|
check_ambiguity = params->check_ambiguity; |
474 |
gezelter |
1083 |
|
475 |
|
|
if (initialize) |
476 |
|
|
cmdline_parser_init (args_info); |
477 |
|
|
|
478 |
|
|
cmdline_parser_init (&local_args_info); |
479 |
|
|
|
480 |
|
|
optarg = 0; |
481 |
|
|
optind = 0; |
482 |
gezelter |
1390 |
opterr = params->print_errors; |
483 |
gezelter |
1083 |
optopt = '?'; |
484 |
|
|
|
485 |
|
|
while (1) |
486 |
|
|
{ |
487 |
|
|
int option_index = 0; |
488 |
|
|
|
489 |
|
|
static struct option long_options[] = { |
490 |
|
|
{ "help", 0, NULL, 'h' }, |
491 |
|
|
{ "version", 0, NULL, 'V' }, |
492 |
|
|
{ "output", 1, NULL, 'o' }, |
493 |
|
|
{ "temperature", 1, NULL, 't' }, |
494 |
|
|
{ NULL, 0, NULL, 0 } |
495 |
|
|
}; |
496 |
|
|
|
497 |
|
|
c = getopt_long (argc, argv, "hVo:t:", long_options, &option_index); |
498 |
|
|
|
499 |
|
|
if (c == -1) break; /* Exit from `while (1)' loop. */ |
500 |
|
|
|
501 |
|
|
switch (c) |
502 |
|
|
{ |
503 |
|
|
case 'h': /* Print help and exit. */ |
504 |
|
|
cmdline_parser_print_help (); |
505 |
|
|
cmdline_parser_free (&local_args_info); |
506 |
|
|
exit (EXIT_SUCCESS); |
507 |
|
|
|
508 |
|
|
case 'V': /* Print version and exit. */ |
509 |
|
|
cmdline_parser_print_version (); |
510 |
|
|
cmdline_parser_free (&local_args_info); |
511 |
|
|
exit (EXIT_SUCCESS); |
512 |
|
|
|
513 |
|
|
case 'o': /* Output file name. */ |
514 |
gezelter |
1390 |
|
515 |
|
|
|
516 |
|
|
if (update_arg( (void *)&(args_info->output_arg), |
517 |
|
|
&(args_info->output_orig), &(args_info->output_given), |
518 |
|
|
&(local_args_info.output_given), optarg, 0, 0, ARG_STRING, |
519 |
|
|
check_ambiguity, override, 0, 0, |
520 |
|
|
"output", 'o', |
521 |
|
|
additional_error)) |
522 |
|
|
goto failure; |
523 |
|
|
|
524 |
gezelter |
1083 |
break; |
525 |
|
|
case 't': /* temperature (K). */ |
526 |
gezelter |
1390 |
|
527 |
|
|
|
528 |
|
|
if (update_arg( (void *)&(args_info->temperature_arg), |
529 |
|
|
&(args_info->temperature_orig), &(args_info->temperature_given), |
530 |
|
|
&(local_args_info.temperature_given), optarg, 0, 0, ARG_DOUBLE, |
531 |
|
|
check_ambiguity, override, 0, 0, |
532 |
|
|
"temperature", 't', |
533 |
|
|
additional_error)) |
534 |
gezelter |
1083 |
goto failure; |
535 |
gezelter |
1390 |
|
536 |
gezelter |
1083 |
break; |
537 |
|
|
|
538 |
|
|
case 0: /* Long option with no short option */ |
539 |
|
|
case '?': /* Invalid option. */ |
540 |
|
|
/* `getopt_long' already printed an error message. */ |
541 |
|
|
goto failure; |
542 |
|
|
|
543 |
|
|
default: /* bug: option not considered. */ |
544 |
|
|
fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
545 |
|
|
abort (); |
546 |
|
|
} /* switch */ |
547 |
|
|
} /* while */ |
548 |
|
|
|
549 |
|
|
|
550 |
|
|
|
551 |
|
|
if (check_required) |
552 |
|
|
{ |
553 |
|
|
error += cmdline_parser_required2 (args_info, argv[0], additional_error); |
554 |
|
|
} |
555 |
|
|
|
556 |
|
|
cmdline_parser_release (&local_args_info); |
557 |
|
|
|
558 |
|
|
if ( error ) |
559 |
|
|
return (EXIT_FAILURE); |
560 |
|
|
|
561 |
|
|
if (optind < argc) |
562 |
|
|
{ |
563 |
|
|
int i = 0 ; |
564 |
|
|
int found_prog_name = 0; |
565 |
|
|
/* whether program name, i.e., argv[0], is in the remaining args |
566 |
|
|
(this may happen with some implementations of getopt, |
567 |
|
|
but surely not with the one included by gengetopt) */ |
568 |
|
|
|
569 |
|
|
i = optind; |
570 |
|
|
while (i < argc) |
571 |
|
|
if (argv[i++] == argv[0]) { |
572 |
|
|
found_prog_name = 1; |
573 |
|
|
break; |
574 |
|
|
} |
575 |
|
|
i = 0; |
576 |
|
|
|
577 |
|
|
args_info->inputs_num = argc - optind - found_prog_name; |
578 |
|
|
args_info->inputs = |
579 |
|
|
(char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; |
580 |
|
|
while (optind < argc) |
581 |
|
|
if (argv[optind++] != argv[0]) |
582 |
|
|
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ; |
583 |
|
|
} |
584 |
|
|
|
585 |
|
|
return 0; |
586 |
|
|
|
587 |
|
|
failure: |
588 |
|
|
|
589 |
|
|
cmdline_parser_release (&local_args_info); |
590 |
|
|
return (EXIT_FAILURE); |
591 |
|
|
} |