1 |
/* |
2 |
File autogenerated by gengetopt version 2.22.4 |
3 |
generated with the following command: |
4 |
gengetopt --file-name=SequentialPropsCmd --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 |
/* 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 |
#ifndef FIX_UNUSED |
21 |
#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ |
22 |
#endif |
23 |
|
24 |
#ifdef WIN32 |
25 |
#include "utils/wingetopt.h" |
26 |
#else |
27 |
#include <getopt.h> |
28 |
#endif |
29 |
|
30 |
#include "SequentialPropsCmd.h" |
31 |
|
32 |
const char *gengetopt_args_info_purpose = ""; |
33 |
|
34 |
const char *gengetopt_args_info_usage = "Usage: SequentialProps [OPTIONS]... [FILES]..."; |
35 |
|
36 |
const char *gengetopt_args_info_description = ""; |
37 |
|
38 |
const char *gengetopt_args_info_help[] = { |
39 |
" -h, --help Print help and exit", |
40 |
" -V, --version Print version and exit", |
41 |
" -i, --input=filename input dump file", |
42 |
" -o, --output=filename output file name", |
43 |
" --sele1=selection script select first stuntdouble set", |
44 |
" --sele2=selection script select second stuntdouble set (if sele2 is not \n set, use script from sele1)", |
45 |
" -b, --nbins=INT number of bins (general purpose) \n (default=`100')", |
46 |
" --nbins_z=INT number of bins in z axis (default=`100')", |
47 |
" -z, --referenceZ=DOUBLE Reference z-height of solid surface", |
48 |
" -r, --dropletR=DOUBLE Droplet radius in angstroms", |
49 |
" --threshDens=DOUBLE Threshold Density in g/cm^3", |
50 |
" --bufferLength=DOUBLE Buffer length in angstroms", |
51 |
"\n Group: sequentialProps\n an option of this group is required", |
52 |
" -c, --com selection center of mass", |
53 |
" --ca1 contact angle of selection (using center of \n mass)", |
54 |
" --ca2 contact angle of selection (using density \n profile)", |
55 |
0 |
56 |
}; |
57 |
|
58 |
typedef enum {ARG_NO |
59 |
, ARG_STRING |
60 |
, ARG_INT |
61 |
, ARG_DOUBLE |
62 |
} cmdline_parser_arg_type; |
63 |
|
64 |
static |
65 |
void clear_given (struct gengetopt_args_info *args_info); |
66 |
static |
67 |
void clear_args (struct gengetopt_args_info *args_info); |
68 |
|
69 |
static int |
70 |
cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, |
71 |
struct cmdline_parser_params *params, const char *additional_error); |
72 |
|
73 |
static int |
74 |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); |
75 |
|
76 |
static char * |
77 |
gengetopt_strdup (const char *s); |
78 |
|
79 |
static |
80 |
void clear_given (struct gengetopt_args_info *args_info) |
81 |
{ |
82 |
args_info->help_given = 0 ; |
83 |
args_info->version_given = 0 ; |
84 |
args_info->input_given = 0 ; |
85 |
args_info->output_given = 0 ; |
86 |
args_info->sele1_given = 0 ; |
87 |
args_info->sele2_given = 0 ; |
88 |
args_info->nbins_given = 0 ; |
89 |
args_info->nbins_z_given = 0 ; |
90 |
args_info->referenceZ_given = 0 ; |
91 |
args_info->dropletR_given = 0 ; |
92 |
args_info->threshDens_given = 0 ; |
93 |
args_info->bufferLength_given = 0 ; |
94 |
args_info->com_given = 0 ; |
95 |
args_info->ca1_given = 0 ; |
96 |
args_info->ca2_given = 0 ; |
97 |
args_info->sequentialProps_group_counter = 0 ; |
98 |
} |
99 |
|
100 |
static |
101 |
void clear_args (struct gengetopt_args_info *args_info) |
102 |
{ |
103 |
FIX_UNUSED (args_info); |
104 |
args_info->input_arg = NULL; |
105 |
args_info->input_orig = NULL; |
106 |
args_info->output_arg = NULL; |
107 |
args_info->output_orig = NULL; |
108 |
args_info->sele1_arg = NULL; |
109 |
args_info->sele1_orig = NULL; |
110 |
args_info->sele2_arg = NULL; |
111 |
args_info->sele2_orig = NULL; |
112 |
args_info->nbins_arg = 100; |
113 |
args_info->nbins_orig = NULL; |
114 |
args_info->nbins_z_arg = 100; |
115 |
args_info->nbins_z_orig = NULL; |
116 |
args_info->referenceZ_orig = NULL; |
117 |
args_info->dropletR_orig = NULL; |
118 |
args_info->threshDens_orig = NULL; |
119 |
args_info->bufferLength_orig = NULL; |
120 |
|
121 |
} |
122 |
|
123 |
static |
124 |
void init_args_info(struct gengetopt_args_info *args_info) |
125 |
{ |
126 |
|
127 |
|
128 |
args_info->help_help = gengetopt_args_info_help[0] ; |
129 |
args_info->version_help = gengetopt_args_info_help[1] ; |
130 |
args_info->input_help = gengetopt_args_info_help[2] ; |
131 |
args_info->output_help = gengetopt_args_info_help[3] ; |
132 |
args_info->sele1_help = gengetopt_args_info_help[4] ; |
133 |
args_info->sele2_help = gengetopt_args_info_help[5] ; |
134 |
args_info->nbins_help = gengetopt_args_info_help[6] ; |
135 |
args_info->nbins_z_help = gengetopt_args_info_help[7] ; |
136 |
args_info->referenceZ_help = gengetopt_args_info_help[8] ; |
137 |
args_info->dropletR_help = gengetopt_args_info_help[9] ; |
138 |
args_info->threshDens_help = gengetopt_args_info_help[10] ; |
139 |
args_info->bufferLength_help = gengetopt_args_info_help[11] ; |
140 |
args_info->com_help = gengetopt_args_info_help[13] ; |
141 |
args_info->ca1_help = gengetopt_args_info_help[14] ; |
142 |
args_info->ca2_help = gengetopt_args_info_help[15] ; |
143 |
|
144 |
} |
145 |
|
146 |
void |
147 |
cmdline_parser_print_version (void) |
148 |
{ |
149 |
printf ("%s %s\n", |
150 |
(strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), |
151 |
CMDLINE_PARSER_VERSION); |
152 |
} |
153 |
|
154 |
static void print_help_common(void) { |
155 |
cmdline_parser_print_version (); |
156 |
|
157 |
if (strlen(gengetopt_args_info_purpose) > 0) |
158 |
printf("\n%s\n", gengetopt_args_info_purpose); |
159 |
|
160 |
if (strlen(gengetopt_args_info_usage) > 0) |
161 |
printf("\n%s\n", gengetopt_args_info_usage); |
162 |
|
163 |
printf("\n"); |
164 |
|
165 |
if (strlen(gengetopt_args_info_description) > 0) |
166 |
printf("%s\n\n", gengetopt_args_info_description); |
167 |
} |
168 |
|
169 |
void |
170 |
cmdline_parser_print_help (void) |
171 |
{ |
172 |
int i = 0; |
173 |
print_help_common(); |
174 |
while (gengetopt_args_info_help[i]) |
175 |
printf("%s\n", gengetopt_args_info_help[i++]); |
176 |
} |
177 |
|
178 |
void |
179 |
cmdline_parser_init (struct gengetopt_args_info *args_info) |
180 |
{ |
181 |
clear_given (args_info); |
182 |
clear_args (args_info); |
183 |
init_args_info (args_info); |
184 |
|
185 |
args_info->inputs = 0; |
186 |
args_info->inputs_num = 0; |
187 |
} |
188 |
|
189 |
void |
190 |
cmdline_parser_params_init(struct cmdline_parser_params *params) |
191 |
{ |
192 |
if (params) |
193 |
{ |
194 |
params->override = 0; |
195 |
params->initialize = 1; |
196 |
params->check_required = 1; |
197 |
params->check_ambiguity = 0; |
198 |
params->print_errors = 1; |
199 |
} |
200 |
} |
201 |
|
202 |
struct cmdline_parser_params * |
203 |
cmdline_parser_params_create(void) |
204 |
{ |
205 |
struct cmdline_parser_params *params = |
206 |
(struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); |
207 |
cmdline_parser_params_init(params); |
208 |
return params; |
209 |
} |
210 |
|
211 |
static void |
212 |
free_string_field (char **s) |
213 |
{ |
214 |
if (*s) |
215 |
{ |
216 |
free (*s); |
217 |
*s = 0; |
218 |
} |
219 |
} |
220 |
|
221 |
|
222 |
static void |
223 |
cmdline_parser_release (struct gengetopt_args_info *args_info) |
224 |
{ |
225 |
unsigned int i; |
226 |
free_string_field (&(args_info->input_arg)); |
227 |
free_string_field (&(args_info->input_orig)); |
228 |
free_string_field (&(args_info->output_arg)); |
229 |
free_string_field (&(args_info->output_orig)); |
230 |
free_string_field (&(args_info->sele1_arg)); |
231 |
free_string_field (&(args_info->sele1_orig)); |
232 |
free_string_field (&(args_info->sele2_arg)); |
233 |
free_string_field (&(args_info->sele2_orig)); |
234 |
free_string_field (&(args_info->nbins_orig)); |
235 |
free_string_field (&(args_info->nbins_z_orig)); |
236 |
free_string_field (&(args_info->referenceZ_orig)); |
237 |
free_string_field (&(args_info->dropletR_orig)); |
238 |
free_string_field (&(args_info->threshDens_orig)); |
239 |
free_string_field (&(args_info->bufferLength_orig)); |
240 |
|
241 |
|
242 |
for (i = 0; i < args_info->inputs_num; ++i) |
243 |
free (args_info->inputs [i]); |
244 |
|
245 |
if (args_info->inputs_num) |
246 |
free (args_info->inputs); |
247 |
|
248 |
clear_given (args_info); |
249 |
} |
250 |
|
251 |
|
252 |
static void |
253 |
write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) |
254 |
{ |
255 |
FIX_UNUSED (values); |
256 |
if (arg) { |
257 |
fprintf(outfile, "%s=\"%s\"\n", opt, arg); |
258 |
} else { |
259 |
fprintf(outfile, "%s\n", opt); |
260 |
} |
261 |
} |
262 |
|
263 |
|
264 |
int |
265 |
cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) |
266 |
{ |
267 |
int i = 0; |
268 |
|
269 |
if (!outfile) |
270 |
{ |
271 |
fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); |
272 |
return EXIT_FAILURE; |
273 |
} |
274 |
|
275 |
if (args_info->help_given) |
276 |
write_into_file(outfile, "help", 0, 0 ); |
277 |
if (args_info->version_given) |
278 |
write_into_file(outfile, "version", 0, 0 ); |
279 |
if (args_info->input_given) |
280 |
write_into_file(outfile, "input", args_info->input_orig, 0); |
281 |
if (args_info->output_given) |
282 |
write_into_file(outfile, "output", args_info->output_orig, 0); |
283 |
if (args_info->sele1_given) |
284 |
write_into_file(outfile, "sele1", args_info->sele1_orig, 0); |
285 |
if (args_info->sele2_given) |
286 |
write_into_file(outfile, "sele2", args_info->sele2_orig, 0); |
287 |
if (args_info->nbins_given) |
288 |
write_into_file(outfile, "nbins", args_info->nbins_orig, 0); |
289 |
if (args_info->nbins_z_given) |
290 |
write_into_file(outfile, "nbins_z", args_info->nbins_z_orig, 0); |
291 |
if (args_info->referenceZ_given) |
292 |
write_into_file(outfile, "referenceZ", args_info->referenceZ_orig, 0); |
293 |
if (args_info->dropletR_given) |
294 |
write_into_file(outfile, "dropletR", args_info->dropletR_orig, 0); |
295 |
if (args_info->threshDens_given) |
296 |
write_into_file(outfile, "threshDens", args_info->threshDens_orig, 0); |
297 |
if (args_info->bufferLength_given) |
298 |
write_into_file(outfile, "bufferLength", args_info->bufferLength_orig, 0); |
299 |
if (args_info->com_given) |
300 |
write_into_file(outfile, "com", 0, 0 ); |
301 |
if (args_info->ca1_given) |
302 |
write_into_file(outfile, "ca1", 0, 0 ); |
303 |
if (args_info->ca2_given) |
304 |
write_into_file(outfile, "ca2", 0, 0 ); |
305 |
|
306 |
|
307 |
i = EXIT_SUCCESS; |
308 |
return i; |
309 |
} |
310 |
|
311 |
int |
312 |
cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) |
313 |
{ |
314 |
FILE *outfile; |
315 |
int i = 0; |
316 |
|
317 |
outfile = fopen(filename, "w"); |
318 |
|
319 |
if (!outfile) |
320 |
{ |
321 |
fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); |
322 |
return EXIT_FAILURE; |
323 |
} |
324 |
|
325 |
i = cmdline_parser_dump(outfile, args_info); |
326 |
fclose (outfile); |
327 |
|
328 |
return i; |
329 |
} |
330 |
|
331 |
void |
332 |
cmdline_parser_free (struct gengetopt_args_info *args_info) |
333 |
{ |
334 |
cmdline_parser_release (args_info); |
335 |
} |
336 |
|
337 |
/** @brief replacement of strdup, which is not standard */ |
338 |
char * |
339 |
gengetopt_strdup (const char *s) |
340 |
{ |
341 |
char *result = 0; |
342 |
if (!s) |
343 |
return result; |
344 |
|
345 |
result = (char*)malloc(strlen(s) + 1); |
346 |
if (result == (char*)0) |
347 |
return (char*)0; |
348 |
strcpy(result, s); |
349 |
return result; |
350 |
} |
351 |
|
352 |
static void |
353 |
reset_group_sequentialProps(struct gengetopt_args_info *args_info) |
354 |
{ |
355 |
if (! args_info->sequentialProps_group_counter) |
356 |
return; |
357 |
|
358 |
args_info->com_given = 0 ; |
359 |
args_info->ca1_given = 0 ; |
360 |
args_info->ca2_given = 0 ; |
361 |
|
362 |
args_info->sequentialProps_group_counter = 0; |
363 |
} |
364 |
|
365 |
int |
366 |
cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) |
367 |
{ |
368 |
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
369 |
} |
370 |
|
371 |
int |
372 |
cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, |
373 |
struct cmdline_parser_params *params) |
374 |
{ |
375 |
int result; |
376 |
result = cmdline_parser_internal (argc, argv, args_info, params, 0); |
377 |
|
378 |
if (result == EXIT_FAILURE) |
379 |
{ |
380 |
cmdline_parser_free (args_info); |
381 |
exit (EXIT_FAILURE); |
382 |
} |
383 |
|
384 |
return result; |
385 |
} |
386 |
|
387 |
int |
388 |
cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
389 |
{ |
390 |
int result; |
391 |
struct cmdline_parser_params params; |
392 |
|
393 |
params.override = override; |
394 |
params.initialize = initialize; |
395 |
params.check_required = check_required; |
396 |
params.check_ambiguity = 0; |
397 |
params.print_errors = 1; |
398 |
|
399 |
result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); |
400 |
|
401 |
if (result == EXIT_FAILURE) |
402 |
{ |
403 |
cmdline_parser_free (args_info); |
404 |
exit (EXIT_FAILURE); |
405 |
} |
406 |
|
407 |
return result; |
408 |
} |
409 |
|
410 |
int |
411 |
cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) |
412 |
{ |
413 |
int result = EXIT_SUCCESS; |
414 |
|
415 |
if (cmdline_parser_required2(args_info, prog_name, 0) > 0) |
416 |
result = EXIT_FAILURE; |
417 |
|
418 |
if (result == EXIT_FAILURE) |
419 |
{ |
420 |
cmdline_parser_free (args_info); |
421 |
exit (EXIT_FAILURE); |
422 |
} |
423 |
|
424 |
return result; |
425 |
} |
426 |
|
427 |
int |
428 |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) |
429 |
{ |
430 |
int error = 0; |
431 |
FIX_UNUSED (additional_error); |
432 |
|
433 |
/* checks for required options */ |
434 |
if (! args_info->input_given) |
435 |
{ |
436 |
fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); |
437 |
error = 1; |
438 |
} |
439 |
|
440 |
if (args_info->sequentialProps_group_counter == 0) |
441 |
{ |
442 |
fprintf (stderr, "%s: %d options of group sequentialProps were given. One is required%s.\n", prog_name, args_info->sequentialProps_group_counter, (additional_error ? additional_error : "")); |
443 |
error = 1; |
444 |
} |
445 |
|
446 |
|
447 |
/* checks for dependences among options */ |
448 |
|
449 |
return error; |
450 |
} |
451 |
|
452 |
|
453 |
static char *package_name = 0; |
454 |
|
455 |
/** |
456 |
* @brief updates an option |
457 |
* @param field the generic pointer to the field to update |
458 |
* @param orig_field the pointer to the orig field |
459 |
* @param field_given the pointer to the number of occurrence of this option |
460 |
* @param prev_given the pointer to the number of occurrence already seen |
461 |
* @param value the argument for this option (if null no arg was specified) |
462 |
* @param possible_values the possible values for this option (if specified) |
463 |
* @param default_value the default value (in case the option only accepts fixed values) |
464 |
* @param arg_type the type of this option |
465 |
* @param check_ambiguity @see cmdline_parser_params.check_ambiguity |
466 |
* @param override @see cmdline_parser_params.override |
467 |
* @param no_free whether to free a possible previous value |
468 |
* @param multiple_option whether this is a multiple option |
469 |
* @param long_opt the corresponding long option |
470 |
* @param short_opt the corresponding short option (or '-' if none) |
471 |
* @param additional_error possible further error specification |
472 |
*/ |
473 |
static |
474 |
int update_arg(void *field, char **orig_field, |
475 |
unsigned int *field_given, unsigned int *prev_given, |
476 |
char *value, const char *possible_values[], |
477 |
const char *default_value, |
478 |
cmdline_parser_arg_type arg_type, |
479 |
int check_ambiguity, int override, |
480 |
int no_free, int multiple_option, |
481 |
const char *long_opt, char short_opt, |
482 |
const char *additional_error) |
483 |
{ |
484 |
char *stop_char = 0; |
485 |
const char *val = value; |
486 |
int found; |
487 |
char **string_field; |
488 |
FIX_UNUSED (field); |
489 |
|
490 |
stop_char = 0; |
491 |
found = 0; |
492 |
|
493 |
if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) |
494 |
{ |
495 |
if (short_opt != '-') |
496 |
fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", |
497 |
package_name, long_opt, short_opt, |
498 |
(additional_error ? additional_error : "")); |
499 |
else |
500 |
fprintf (stderr, "%s: `--%s' option given more than once%s\n", |
501 |
package_name, long_opt, |
502 |
(additional_error ? additional_error : "")); |
503 |
return 1; /* failure */ |
504 |
} |
505 |
|
506 |
FIX_UNUSED (default_value); |
507 |
|
508 |
if (field_given && *field_given && ! override) |
509 |
return 0; |
510 |
if (prev_given) |
511 |
(*prev_given)++; |
512 |
if (field_given) |
513 |
(*field_given)++; |
514 |
if (possible_values) |
515 |
val = possible_values[found]; |
516 |
|
517 |
switch(arg_type) { |
518 |
case ARG_INT: |
519 |
if (val) *((int *)field) = strtol (val, &stop_char, 0); |
520 |
break; |
521 |
case ARG_DOUBLE: |
522 |
if (val) *((double *)field) = strtod (val, &stop_char); |
523 |
break; |
524 |
case ARG_STRING: |
525 |
if (val) { |
526 |
string_field = (char **)field; |
527 |
if (!no_free && *string_field) |
528 |
free (*string_field); /* free previous string */ |
529 |
*string_field = gengetopt_strdup (val); |
530 |
} |
531 |
break; |
532 |
default: |
533 |
break; |
534 |
}; |
535 |
|
536 |
/* check numeric conversion */ |
537 |
switch(arg_type) { |
538 |
case ARG_INT: |
539 |
case ARG_DOUBLE: |
540 |
if (val && !(stop_char && *stop_char == '\0')) { |
541 |
fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); |
542 |
return 1; /* failure */ |
543 |
} |
544 |
break; |
545 |
default: |
546 |
; |
547 |
}; |
548 |
|
549 |
/* store the original value */ |
550 |
switch(arg_type) { |
551 |
case ARG_NO: |
552 |
break; |
553 |
default: |
554 |
if (value && orig_field) { |
555 |
if (no_free) { |
556 |
*orig_field = value; |
557 |
} else { |
558 |
if (*orig_field) |
559 |
free (*orig_field); /* free previous string */ |
560 |
*orig_field = gengetopt_strdup (value); |
561 |
} |
562 |
} |
563 |
}; |
564 |
|
565 |
return 0; /* OK */ |
566 |
} |
567 |
|
568 |
|
569 |
int |
570 |
cmdline_parser_internal ( |
571 |
int argc, char **argv, struct gengetopt_args_info *args_info, |
572 |
struct cmdline_parser_params *params, const char *additional_error) |
573 |
{ |
574 |
int c; /* Character of the parsed option. */ |
575 |
|
576 |
int error = 0; |
577 |
struct gengetopt_args_info local_args_info; |
578 |
|
579 |
int override; |
580 |
int initialize; |
581 |
int check_required; |
582 |
int check_ambiguity; |
583 |
|
584 |
package_name = argv[0]; |
585 |
|
586 |
override = params->override; |
587 |
initialize = params->initialize; |
588 |
check_required = params->check_required; |
589 |
check_ambiguity = params->check_ambiguity; |
590 |
|
591 |
if (initialize) |
592 |
cmdline_parser_init (args_info); |
593 |
|
594 |
cmdline_parser_init (&local_args_info); |
595 |
|
596 |
optarg = 0; |
597 |
optind = 0; |
598 |
opterr = params->print_errors; |
599 |
optopt = '?'; |
600 |
|
601 |
while (1) |
602 |
{ |
603 |
int option_index = 0; |
604 |
|
605 |
static struct option long_options[] = { |
606 |
{ "help", 0, NULL, 'h' }, |
607 |
{ "version", 0, NULL, 'V' }, |
608 |
{ "input", 1, NULL, 'i' }, |
609 |
{ "output", 1, NULL, 'o' }, |
610 |
{ "sele1", 1, NULL, 0 }, |
611 |
{ "sele2", 1, NULL, 0 }, |
612 |
{ "nbins", 1, NULL, 'b' }, |
613 |
{ "nbins_z", 1, NULL, 0 }, |
614 |
{ "referenceZ", 1, NULL, 'z' }, |
615 |
{ "dropletR", 1, NULL, 'r' }, |
616 |
{ "threshDens", 1, NULL, 0 }, |
617 |
{ "bufferLength", 1, NULL, 0 }, |
618 |
{ "com", 0, NULL, 'c' }, |
619 |
{ "ca1", 0, NULL, 0 }, |
620 |
{ "ca2", 0, NULL, 0 }, |
621 |
{ 0, 0, 0, 0 } |
622 |
}; |
623 |
|
624 |
c = getopt_long (argc, argv, "hVi:o:b:z:r:c", long_options, &option_index); |
625 |
|
626 |
if (c == -1) break; /* Exit from `while (1)' loop. */ |
627 |
|
628 |
switch (c) |
629 |
{ |
630 |
case 'h': /* Print help and exit. */ |
631 |
cmdline_parser_print_help (); |
632 |
cmdline_parser_free (&local_args_info); |
633 |
exit (EXIT_SUCCESS); |
634 |
|
635 |
case 'V': /* Print version and exit. */ |
636 |
cmdline_parser_print_version (); |
637 |
cmdline_parser_free (&local_args_info); |
638 |
exit (EXIT_SUCCESS); |
639 |
|
640 |
case 'i': /* input dump file. */ |
641 |
|
642 |
|
643 |
if (update_arg( (void *)&(args_info->input_arg), |
644 |
&(args_info->input_orig), &(args_info->input_given), |
645 |
&(local_args_info.input_given), optarg, 0, 0, ARG_STRING, |
646 |
check_ambiguity, override, 0, 0, |
647 |
"input", 'i', |
648 |
additional_error)) |
649 |
goto failure; |
650 |
|
651 |
break; |
652 |
case 'o': /* output file name. */ |
653 |
|
654 |
|
655 |
if (update_arg( (void *)&(args_info->output_arg), |
656 |
&(args_info->output_orig), &(args_info->output_given), |
657 |
&(local_args_info.output_given), optarg, 0, 0, ARG_STRING, |
658 |
check_ambiguity, override, 0, 0, |
659 |
"output", 'o', |
660 |
additional_error)) |
661 |
goto failure; |
662 |
|
663 |
break; |
664 |
case 'b': /* number of bins (general purpose). */ |
665 |
|
666 |
|
667 |
if (update_arg( (void *)&(args_info->nbins_arg), |
668 |
&(args_info->nbins_orig), &(args_info->nbins_given), |
669 |
&(local_args_info.nbins_given), optarg, 0, "100", ARG_INT, |
670 |
check_ambiguity, override, 0, 0, |
671 |
"nbins", 'b', |
672 |
additional_error)) |
673 |
goto failure; |
674 |
|
675 |
break; |
676 |
case 'z': /* Reference z-height of solid surface. */ |
677 |
|
678 |
|
679 |
if (update_arg( (void *)&(args_info->referenceZ_arg), |
680 |
&(args_info->referenceZ_orig), &(args_info->referenceZ_given), |
681 |
&(local_args_info.referenceZ_given), optarg, 0, 0, ARG_DOUBLE, |
682 |
check_ambiguity, override, 0, 0, |
683 |
"referenceZ", 'z', |
684 |
additional_error)) |
685 |
goto failure; |
686 |
|
687 |
break; |
688 |
case 'r': /* Droplet radius in angstroms. */ |
689 |
|
690 |
|
691 |
if (update_arg( (void *)&(args_info->dropletR_arg), |
692 |
&(args_info->dropletR_orig), &(args_info->dropletR_given), |
693 |
&(local_args_info.dropletR_given), optarg, 0, 0, ARG_DOUBLE, |
694 |
check_ambiguity, override, 0, 0, |
695 |
"dropletR", 'r', |
696 |
additional_error)) |
697 |
goto failure; |
698 |
|
699 |
break; |
700 |
case 'c': /* selection center of mass. */ |
701 |
|
702 |
if (args_info->sequentialProps_group_counter && override) |
703 |
reset_group_sequentialProps (args_info); |
704 |
args_info->sequentialProps_group_counter += 1; |
705 |
|
706 |
if (update_arg( 0 , |
707 |
0 , &(args_info->com_given), |
708 |
&(local_args_info.com_given), optarg, 0, 0, ARG_NO, |
709 |
check_ambiguity, override, 0, 0, |
710 |
"com", 'c', |
711 |
additional_error)) |
712 |
goto failure; |
713 |
|
714 |
break; |
715 |
|
716 |
case 0: /* Long option with no short option */ |
717 |
/* select first stuntdouble set. */ |
718 |
if (strcmp (long_options[option_index].name, "sele1") == 0) |
719 |
{ |
720 |
|
721 |
|
722 |
if (update_arg( (void *)&(args_info->sele1_arg), |
723 |
&(args_info->sele1_orig), &(args_info->sele1_given), |
724 |
&(local_args_info.sele1_given), optarg, 0, 0, ARG_STRING, |
725 |
check_ambiguity, override, 0, 0, |
726 |
"sele1", '-', |
727 |
additional_error)) |
728 |
goto failure; |
729 |
|
730 |
} |
731 |
/* select second stuntdouble set (if sele2 is not set, use script from sele1). */ |
732 |
else if (strcmp (long_options[option_index].name, "sele2") == 0) |
733 |
{ |
734 |
|
735 |
|
736 |
if (update_arg( (void *)&(args_info->sele2_arg), |
737 |
&(args_info->sele2_orig), &(args_info->sele2_given), |
738 |
&(local_args_info.sele2_given), optarg, 0, 0, ARG_STRING, |
739 |
check_ambiguity, override, 0, 0, |
740 |
"sele2", '-', |
741 |
additional_error)) |
742 |
goto failure; |
743 |
|
744 |
} |
745 |
/* number of bins in z axis. */ |
746 |
else if (strcmp (long_options[option_index].name, "nbins_z") == 0) |
747 |
{ |
748 |
|
749 |
|
750 |
if (update_arg( (void *)&(args_info->nbins_z_arg), |
751 |
&(args_info->nbins_z_orig), &(args_info->nbins_z_given), |
752 |
&(local_args_info.nbins_z_given), optarg, 0, "100", ARG_INT, |
753 |
check_ambiguity, override, 0, 0, |
754 |
"nbins_z", '-', |
755 |
additional_error)) |
756 |
goto failure; |
757 |
|
758 |
} |
759 |
/* Threshold Density in g/cm^3. */ |
760 |
else if (strcmp (long_options[option_index].name, "threshDens") == 0) |
761 |
{ |
762 |
|
763 |
|
764 |
if (update_arg( (void *)&(args_info->threshDens_arg), |
765 |
&(args_info->threshDens_orig), &(args_info->threshDens_given), |
766 |
&(local_args_info.threshDens_given), optarg, 0, 0, ARG_DOUBLE, |
767 |
check_ambiguity, override, 0, 0, |
768 |
"threshDens", '-', |
769 |
additional_error)) |
770 |
goto failure; |
771 |
|
772 |
} |
773 |
/* Buffer length in angstroms. */ |
774 |
else if (strcmp (long_options[option_index].name, "bufferLength") == 0) |
775 |
{ |
776 |
|
777 |
|
778 |
if (update_arg( (void *)&(args_info->bufferLength_arg), |
779 |
&(args_info->bufferLength_orig), &(args_info->bufferLength_given), |
780 |
&(local_args_info.bufferLength_given), optarg, 0, 0, ARG_DOUBLE, |
781 |
check_ambiguity, override, 0, 0, |
782 |
"bufferLength", '-', |
783 |
additional_error)) |
784 |
goto failure; |
785 |
|
786 |
} |
787 |
/* contact angle of selection (using center of mass). */ |
788 |
else if (strcmp (long_options[option_index].name, "ca1") == 0) |
789 |
{ |
790 |
|
791 |
if (args_info->sequentialProps_group_counter && override) |
792 |
reset_group_sequentialProps (args_info); |
793 |
args_info->sequentialProps_group_counter += 1; |
794 |
|
795 |
if (update_arg( 0 , |
796 |
0 , &(args_info->ca1_given), |
797 |
&(local_args_info.ca1_given), optarg, 0, 0, ARG_NO, |
798 |
check_ambiguity, override, 0, 0, |
799 |
"ca1", '-', |
800 |
additional_error)) |
801 |
goto failure; |
802 |
|
803 |
} |
804 |
/* contact angle of selection (using density profile). */ |
805 |
else if (strcmp (long_options[option_index].name, "ca2") == 0) |
806 |
{ |
807 |
|
808 |
if (args_info->sequentialProps_group_counter && override) |
809 |
reset_group_sequentialProps (args_info); |
810 |
args_info->sequentialProps_group_counter += 1; |
811 |
|
812 |
if (update_arg( 0 , |
813 |
0 , &(args_info->ca2_given), |
814 |
&(local_args_info.ca2_given), optarg, 0, 0, ARG_NO, |
815 |
check_ambiguity, override, 0, 0, |
816 |
"ca2", '-', |
817 |
additional_error)) |
818 |
goto failure; |
819 |
|
820 |
} |
821 |
|
822 |
break; |
823 |
case '?': /* Invalid option. */ |
824 |
/* `getopt_long' already printed an error message. */ |
825 |
goto failure; |
826 |
|
827 |
default: /* bug: option not considered. */ |
828 |
fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
829 |
abort (); |
830 |
} /* switch */ |
831 |
} /* while */ |
832 |
|
833 |
if (args_info->sequentialProps_group_counter > 1) |
834 |
{ |
835 |
fprintf (stderr, "%s: %d options of group sequentialProps were given. One is required%s.\n", argv[0], args_info->sequentialProps_group_counter, (additional_error ? additional_error : "")); |
836 |
error = 1; |
837 |
} |
838 |
|
839 |
|
840 |
|
841 |
if (check_required) |
842 |
{ |
843 |
error += cmdline_parser_required2 (args_info, argv[0], additional_error); |
844 |
} |
845 |
|
846 |
cmdline_parser_release (&local_args_info); |
847 |
|
848 |
if ( error ) |
849 |
return (EXIT_FAILURE); |
850 |
|
851 |
if (optind < argc) |
852 |
{ |
853 |
int i = 0 ; |
854 |
int found_prog_name = 0; |
855 |
/* whether program name, i.e., argv[0], is in the remaining args |
856 |
(this may happen with some implementations of getopt, |
857 |
but surely not with the one included by gengetopt) */ |
858 |
|
859 |
i = optind; |
860 |
while (i < argc) |
861 |
if (argv[i++] == argv[0]) { |
862 |
found_prog_name = 1; |
863 |
break; |
864 |
} |
865 |
i = 0; |
866 |
|
867 |
args_info->inputs_num = argc - optind - found_prog_name; |
868 |
args_info->inputs = |
869 |
(char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; |
870 |
while (optind < argc) |
871 |
if (argv[optind++] != argv[0]) |
872 |
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ; |
873 |
} |
874 |
|
875 |
return 0; |
876 |
|
877 |
failure: |
878 |
|
879 |
cmdline_parser_release (&local_args_info); |
880 |
return (EXIT_FAILURE); |
881 |
} |