1 |
|
/* |
2 |
< |
File autogenerated by gengetopt version 2.22 |
2 |
> |
File autogenerated by gengetopt version 2.22.4 |
3 |
|
generated with the following command: |
4 |
< |
gengetopt -u -F nanoparticleBuilderCmd |
4 |
> |
gengetopt -F nanoparticleBuilderCmd -u |
5 |
|
|
6 |
|
The developers of gengetopt consider the fixed text that goes in all |
7 |
|
gengetopt output files to be in the public domain: |
17 |
|
#include <stdlib.h> |
18 |
|
#include <string.h> |
19 |
|
|
20 |
< |
#include "getopt.h" |
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 "nanoparticleBuilderCmd.h" |
31 |
|
|
32 |
|
const char *gengetopt_args_info_purpose = "Builds spherical random or core-shell nanoparticles and outputs an OpenMD \nstartup file"; |
60 |
|
void clear_args (struct gengetopt_args_info *args_info); |
61 |
|
|
62 |
|
static int |
63 |
< |
cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, |
63 |
> |
cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, |
64 |
|
struct cmdline_parser_params *params, const char *additional_error); |
65 |
|
|
66 |
|
static int |
87 |
|
static |
88 |
|
void clear_args (struct gengetopt_args_info *args_info) |
89 |
|
{ |
90 |
+ |
FIX_UNUSED (args_info); |
91 |
|
args_info->output_arg = NULL; |
92 |
|
args_info->output_orig = NULL; |
93 |
|
args_info->latticeConstant_orig = NULL; |
113 |
|
args_info->latticeConstant_help = gengetopt_args_info_help[3] ; |
114 |
|
args_info->radius_help = gengetopt_args_info_help[4] ; |
115 |
|
args_info->shellRadius_help = gengetopt_args_info_help[5] ; |
116 |
< |
args_info->shellRadius_min = -1; |
117 |
< |
args_info->shellRadius_max = -1; |
116 |
> |
args_info->shellRadius_min = 0; |
117 |
> |
args_info->shellRadius_max = 0; |
118 |
|
args_info->molFraction_help = gengetopt_args_info_help[6] ; |
119 |
< |
args_info->molFraction_min = -1; |
120 |
< |
args_info->molFraction_max = -1; |
119 |
> |
args_info->molFraction_min = 0; |
120 |
> |
args_info->molFraction_max = 0; |
121 |
|
args_info->vacancyPercent_help = gengetopt_args_info_help[7] ; |
122 |
|
args_info->vacancyInnerRadius_help = gengetopt_args_info_help[8] ; |
123 |
|
args_info->vacancyOuterRadius_help = gengetopt_args_info_help[9] ; |
127 |
|
void |
128 |
|
cmdline_parser_print_version (void) |
129 |
|
{ |
130 |
< |
printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); |
130 |
> |
printf ("%s %s\n", |
131 |
> |
(strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), |
132 |
> |
CMDLINE_PARSER_VERSION); |
133 |
|
} |
134 |
|
|
135 |
|
static void print_help_common(void) { |
144 |
|
printf("\n"); |
145 |
|
|
146 |
|
if (strlen(gengetopt_args_info_description) > 0) |
147 |
< |
printf("%s\n", gengetopt_args_info_description); |
147 |
> |
printf("%s\n\n", gengetopt_args_info_description); |
148 |
|
} |
149 |
|
|
150 |
|
void |
163 |
|
clear_args (args_info); |
164 |
|
init_args_info (args_info); |
165 |
|
|
166 |
< |
args_info->inputs = NULL; |
166 |
> |
args_info->inputs = 0; |
167 |
|
args_info->inputs_num = 0; |
168 |
|
} |
169 |
|
|
203 |
|
union generic_value { |
204 |
|
double double_arg; |
205 |
|
char *string_arg; |
206 |
+ |
const char *default_string_arg; |
207 |
|
}; |
208 |
|
|
209 |
|
/** @brief holds temporary values for multiple options */ |
221 |
|
struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); |
222 |
|
new_node->next = *list; |
223 |
|
*list = new_node; |
224 |
< |
new_node->arg.string_arg = NULL; |
225 |
< |
new_node->orig = NULL; |
224 |
> |
new_node->arg.string_arg = 0; |
225 |
> |
new_node->orig = 0; |
226 |
|
} |
227 |
|
|
228 |
+ |
/** |
229 |
+ |
* The passed arg parameter is NOT set to 0 from this function |
230 |
+ |
*/ |
231 |
|
static void |
232 |
< |
free_multiple_field(unsigned int len, void **arg, char ***orig) |
232 |
> |
free_multiple_field(unsigned int len, void *arg, char ***orig) |
233 |
|
{ |
234 |
|
unsigned int i; |
235 |
< |
if (*arg) { |
235 |
> |
if (arg) { |
236 |
|
for (i = 0; i < len; ++i) |
237 |
|
{ |
238 |
|
free_string_field(&((*orig)[i])); |
239 |
|
} |
240 |
|
|
241 |
< |
free (*arg); |
227 |
< |
*arg = 0; |
241 |
> |
free (arg); |
242 |
|
free (*orig); |
243 |
|
*orig = 0; |
244 |
|
} |
253 |
|
free_string_field (&(args_info->output_orig)); |
254 |
|
free_string_field (&(args_info->latticeConstant_orig)); |
255 |
|
free_string_field (&(args_info->radius_orig)); |
256 |
< |
free_multiple_field (args_info->shellRadius_given, (void **)&(args_info->shellRadius_arg), &(args_info->shellRadius_orig)); |
257 |
< |
free_multiple_field (args_info->molFraction_given, (void **)&(args_info->molFraction_arg), &(args_info->molFraction_orig)); |
256 |
> |
free_multiple_field (args_info->shellRadius_given, (void *)(args_info->shellRadius_arg), &(args_info->shellRadius_orig)); |
257 |
> |
args_info->shellRadius_arg = 0; |
258 |
> |
free_multiple_field (args_info->molFraction_given, (void *)(args_info->molFraction_arg), &(args_info->molFraction_orig)); |
259 |
> |
args_info->molFraction_arg = 0; |
260 |
|
free_string_field (&(args_info->vacancyPercent_orig)); |
261 |
|
free_string_field (&(args_info->vacancyInnerRadius_orig)); |
262 |
|
free_string_field (&(args_info->vacancyOuterRadius_orig)); |
273 |
|
|
274 |
|
|
275 |
|
static void |
276 |
< |
write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) |
276 |
> |
write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) |
277 |
|
{ |
278 |
+ |
FIX_UNUSED (values); |
279 |
|
if (arg) { |
280 |
|
fprintf(outfile, "%s=\"%s\"\n", opt, arg); |
281 |
|
} else { |
284 |
|
} |
285 |
|
|
286 |
|
static void |
287 |
< |
write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[]) |
287 |
> |
write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[]) |
288 |
|
{ |
289 |
|
int i; |
290 |
|
|
357 |
|
char * |
358 |
|
gengetopt_strdup (const char *s) |
359 |
|
{ |
360 |
< |
char *result = NULL; |
360 |
> |
char *result = 0; |
361 |
|
if (!s) |
362 |
|
return result; |
363 |
|
|
371 |
|
static char * |
372 |
|
get_multiple_arg_token(const char *arg) |
373 |
|
{ |
374 |
< |
char *tok, *ret; |
374 |
> |
const char *tok; |
375 |
> |
char *ret; |
376 |
|
size_t len, num_of_escape, i, j; |
377 |
|
|
378 |
|
if (!arg) |
379 |
< |
return NULL; |
379 |
> |
return 0; |
380 |
|
|
381 |
|
tok = strchr (arg, ','); |
382 |
|
num_of_escape = 0; |
420 |
|
return ret; |
421 |
|
} |
422 |
|
|
423 |
< |
static char * |
423 |
> |
static const char * |
424 |
|
get_multiple_arg_token_next(const char *arg) |
425 |
|
{ |
426 |
< |
char *tok; |
426 |
> |
const char *tok; |
427 |
|
|
428 |
|
if (!arg) |
429 |
< |
return NULL; |
429 |
> |
return 0; |
430 |
|
|
431 |
|
tok = strchr (arg, ','); |
432 |
|
|
449 |
|
} |
450 |
|
|
451 |
|
static int |
452 |
< |
check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc); |
452 |
> |
check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc); |
453 |
|
|
454 |
|
int |
455 |
< |
check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc) |
455 |
> |
check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc) |
456 |
|
{ |
457 |
|
int error = 0; |
458 |
|
|
459 |
< |
if (option_given && ! (min < 0 && max < 0)) |
459 |
> |
if (option_given && (min > 0 || max > 0)) |
460 |
|
{ |
461 |
< |
if (min >= 0 && max >= 0) |
461 |
> |
if (min > 0 && max > 0) |
462 |
|
{ |
463 |
|
if (min == max) |
464 |
|
{ |
465 |
|
/* specific occurrences */ |
466 |
< |
if (option_given != min) |
466 |
> |
if (option_given != (unsigned int) min) |
467 |
|
{ |
468 |
|
fprintf (stderr, "%s: %s option occurrences must be %d\n", |
469 |
|
prog_name, option_desc, min); |
470 |
|
error = 1; |
471 |
|
} |
472 |
|
} |
473 |
< |
else if (option_given < min |
474 |
< |
|| option_given > max) |
473 |
> |
else if (option_given < (unsigned int) min |
474 |
> |
|| option_given > (unsigned int) max) |
475 |
|
{ |
476 |
|
/* range occurrences */ |
477 |
|
fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n", |
479 |
|
error = 1; |
480 |
|
} |
481 |
|
} |
482 |
< |
else if (min >= 0) |
482 |
> |
else if (min > 0) |
483 |
|
{ |
484 |
|
/* at least check */ |
485 |
|
if (option_given < min) |
489 |
|
error = 1; |
490 |
|
} |
491 |
|
} |
492 |
< |
else if (max >= 0) |
492 |
> |
else if (max > 0) |
493 |
|
{ |
494 |
|
/* at most check */ |
495 |
|
if (option_given > max) |
504 |
|
return error; |
505 |
|
} |
506 |
|
int |
507 |
< |
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
507 |
> |
cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) |
508 |
|
{ |
509 |
|
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
510 |
|
} |
511 |
|
|
512 |
|
int |
513 |
< |
cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *args_info, |
513 |
> |
cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, |
514 |
|
struct cmdline_parser_params *params) |
515 |
|
{ |
516 |
|
int result; |
517 |
< |
result = cmdline_parser_internal (argc, argv, args_info, params, NULL); |
517 |
> |
result = cmdline_parser_internal (argc, argv, args_info, params, 0); |
518 |
|
|
519 |
|
if (result == EXIT_FAILURE) |
520 |
|
{ |
526 |
|
} |
527 |
|
|
528 |
|
int |
529 |
< |
cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
529 |
> |
cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
530 |
|
{ |
531 |
|
int result; |
532 |
|
struct cmdline_parser_params params; |
537 |
|
params.check_ambiguity = 0; |
538 |
|
params.print_errors = 1; |
539 |
|
|
540 |
< |
result = cmdline_parser_internal (argc, argv, args_info, ¶ms, NULL); |
540 |
> |
result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); |
541 |
|
|
542 |
|
if (result == EXIT_FAILURE) |
543 |
|
{ |
553 |
|
{ |
554 |
|
int result = EXIT_SUCCESS; |
555 |
|
|
556 |
< |
if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) |
556 |
> |
if (cmdline_parser_required2(args_info, prog_name, 0) > 0) |
557 |
|
result = EXIT_FAILURE; |
558 |
|
|
559 |
|
if (result == EXIT_FAILURE) |
569 |
|
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) |
570 |
|
{ |
571 |
|
int error = 0; |
572 |
+ |
FIX_UNUSED (additional_error); |
573 |
|
|
574 |
|
/* checks for required options */ |
575 |
|
if (! args_info->output_given) |
626 |
|
static |
627 |
|
int update_arg(void *field, char **orig_field, |
628 |
|
unsigned int *field_given, unsigned int *prev_given, |
629 |
< |
char *value, char *possible_values[], const char *default_value, |
629 |
> |
char *value, const char *possible_values[], |
630 |
> |
const char *default_value, |
631 |
|
cmdline_parser_arg_type arg_type, |
632 |
|
int check_ambiguity, int override, |
633 |
|
int no_free, int multiple_option, |
638 |
|
const char *val = value; |
639 |
|
int found; |
640 |
|
char **string_field; |
641 |
+ |
FIX_UNUSED (field); |
642 |
|
|
643 |
|
stop_char = 0; |
644 |
|
found = 0; |
656 |
|
return 1; /* failure */ |
657 |
|
} |
658 |
|
|
659 |
+ |
FIX_UNUSED (default_value); |
660 |
|
|
661 |
|
if (field_given && *field_given && ! override) |
662 |
|
return 0; |
721 |
|
static |
722 |
|
int update_multiple_arg_temp(struct generic_list **list, |
723 |
|
unsigned int *prev_given, const char *val, |
724 |
< |
char *possible_values[], const char *default_value, |
724 |
> |
const char *possible_values[], const char *default_value, |
725 |
|
cmdline_parser_arg_type arg_type, |
726 |
|
const char *long_opt, char short_opt, |
727 |
|
const char *additional_error) |
728 |
|
{ |
729 |
< |
char *multi_token, *multi_next; /* store single arguments */ |
729 |
> |
/* store single arguments */ |
730 |
> |
char *multi_token; |
731 |
> |
const char *multi_next; |
732 |
|
|
733 |
|
if (arg_type == ARG_NO) { |
734 |
|
(*prev_given)++; |
840 |
|
} |
841 |
|
if (!(*orig_field)) { |
842 |
|
*orig_field = (char **) malloc (sizeof (char *)); |
843 |
< |
(*orig_field)[0] = NULL; |
843 |
> |
(*orig_field)[0] = 0; |
844 |
|
} |
845 |
|
} |
846 |
|
} |
847 |
|
} |
848 |
|
|
849 |
|
int |
850 |
< |
cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, |
850 |
> |
cmdline_parser_internal ( |
851 |
> |
int argc, char **argv, struct gengetopt_args_info *args_info, |
852 |
|
struct cmdline_parser_params *params, const char *additional_error) |
853 |
|
{ |
854 |
|
int c; /* Character of the parsed option. */ |
895 |
|
{ "vacancyPercent", 1, NULL, 0 }, |
896 |
|
{ "vacancyInnerRadius", 1, NULL, 0 }, |
897 |
|
{ "vacancyOuterRadius", 1, NULL, 0 }, |
898 |
< |
{ NULL, 0, NULL, 0 } |
898 |
> |
{ 0, 0, 0, 0 } |
899 |
|
}; |
900 |
|
|
901 |
|
c = getopt_long (argc, argv, "hVo:", long_options, &option_index); |
1035 |
|
|
1036 |
|
update_multiple_arg((void *)&(args_info->shellRadius_arg), |
1037 |
|
&(args_info->shellRadius_orig), args_info->shellRadius_given, |
1038 |
< |
local_args_info.shellRadius_given, 0 , |
1038 |
> |
local_args_info.shellRadius_given, 0, |
1039 |
|
ARG_DOUBLE, shellRadius_list); |
1040 |
|
update_multiple_arg((void *)&(args_info->molFraction_arg), |
1041 |
|
&(args_info->molFraction_orig), args_info->molFraction_given, |
1042 |
< |
local_args_info.molFraction_given, 0 , |
1042 |
> |
local_args_info.molFraction_given, 0, |
1043 |
|
ARG_DOUBLE, molFraction_list); |
1044 |
|
|
1045 |
|
args_info->shellRadius_given += local_args_info.shellRadius_given; |