21#define FIX_UNUSED(X) (void) (X)
27const char *gengetopt_args_info_purpose =
"Builds pill-shaped, ellipsoidal, or pentagonal nanoparticles and outputs an\nOpenMD startup file";
29const char *gengetopt_args_info_usage =
"Usage: nanorodBuilder [OPTIONS]... [FILES]...";
31const char *gengetopt_args_info_versiontext =
"";
33const char *gengetopt_args_info_description =
"";
35const char *gengetopt_args_info_help[] = {
36 " -h, --help Print help and exit",
37 " -V, --version Print version and exit",
38 " -o, --output=STRING Output file name (mandatory)",
39 " --latticeConstant=DOUBLE Lattice spacing in Angstroms for cubic lattice.\n (mandatory)",
40 " --radius=DOUBLE Nanorod radius in Angstroms (mandatory)",
41 " --length=DOUBLE Nanorod length in Angstroms (mandatory)",
42 " -e, --ellipsoid Build an Ellipsoid instead of a rod.\n (default=off)",
43 " --shellRadius=DOUBLE Radius containing within it only molecules of a\n specific component. Specified for each\n component > 1 in the template file.",
44 " --molFraction=DOUBLE Builds a multi-component random alloy\n nanoparticle. A mole Fraction must be\n specified for each component > 1 in the\n template file.",
45 " --vacancyPercent=DOUBLE Percentage of atoms to remove from within\n vacancy range",
46 " --vacancyInnerRadius=DOUBLE\n Radius arround core-shell where vacancies\n should be located.",
47 " --vacancyOuterRadius=DOUBLE\n Radius arround core-shell where vacancies\n should be located.",
55} cmdline_parser_arg_type;
67cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error);
71 struct line_list * next;
74static struct line_list *cmd_line_list = 0;
75static struct line_list *cmd_line_list_tmp = 0;
83 while (cmd_line_list) {
84 cmd_line_list_tmp = cmd_line_list;
85 cmd_line_list = cmd_line_list->next;
86 free (cmd_line_list_tmp->string_arg);
87 free (cmd_line_list_tmp);
94gengetopt_strdup (
const char *s);
116 FIX_UNUSED (args_info);
138 args_info->
help_help = gengetopt_args_info_help[0] ;
140 args_info->
output_help = gengetopt_args_info_help[2] ;
142 args_info->
radius_help = gengetopt_args_info_help[4] ;
143 args_info->
length_help = gengetopt_args_info_help[5] ;
158cmdline_parser_print_version (
void)
164 if (strlen(gengetopt_args_info_versiontext) > 0)
165 printf(
"\n%s\n", gengetopt_args_info_versiontext);
168static void print_help_common(
void) {
169 cmdline_parser_print_version ();
171 if (strlen(gengetopt_args_info_purpose) > 0)
172 printf(
"\n%s\n", gengetopt_args_info_purpose);
174 if (strlen(gengetopt_args_info_usage) > 0)
175 printf(
"\n%s\n", gengetopt_args_info_usage);
179 if (strlen(gengetopt_args_info_description) > 0)
180 printf(
"%s\n\n", gengetopt_args_info_description);
184cmdline_parser_print_help (
void)
188 while (gengetopt_args_info_help[i])
189 printf(
"%s\n", gengetopt_args_info_help[i++]);
195 clear_given (args_info);
196 clear_args (args_info);
197 init_args_info (args_info);
226free_string_field (
char **s)
239 const char *default_string_arg;
245 union generic_value arg;
247 struct generic_list *next;
253static void add_node(
struct generic_list **list) {
254 struct generic_list *new_node = (
struct generic_list *) malloc (
sizeof (
struct generic_list));
255 new_node->next = *list;
257 new_node->arg.string_arg = 0;
265free_multiple_field(
unsigned int len,
void *arg,
char ***orig)
269 for (i = 0; i < len; ++i)
271 free_string_field(&((*orig)[i]));
300 free (args_info->
inputs [i]);
305 clear_given (args_info);
310write_into_file(FILE *outfile,
const char *opt,
const char *arg,
const char *values[])
314 fprintf(outfile,
"%s=\"%s\"\n", opt, arg);
316 fprintf(outfile,
"%s\n", opt);
321write_multiple_into_file(FILE *outfile,
int len,
const char *opt,
char **arg,
const char *values[])
325 for (i = 0; i < len; ++i)
326 write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
341 write_into_file(outfile,
"help", 0, 0 );
343 write_into_file(outfile,
"version", 0, 0 );
345 write_into_file(outfile,
"output", args_info->
output_orig, 0);
349 write_into_file(outfile,
"radius", args_info->
radius_orig, 0);
351 write_into_file(outfile,
"length", args_info->
length_orig, 0);
353 write_into_file(outfile,
"ellipsoid", 0, 0 );
374 outfile = fopen(filename,
"w");
382 i = cmdline_parser_dump(outfile, args_info);
391 cmdline_parser_release (args_info);
396gengetopt_strdup (
const char *s)
402 result = (
char*)malloc(strlen(s) + 1);
403 if (result == (
char*)0)
410get_multiple_arg_token(
const char *arg)
414 size_t len, num_of_escape, i, j;
419 tok = strchr (arg,
',');
425 if (*(tok-1) ==
'\\')
428 tok = strchr (tok+1,
',');
436 len = (size_t)(tok - arg + 1);
438 len = strlen (arg) + 1;
440 len -= num_of_escape;
442 ret = (
char *) malloc (len);
446 while (arg[i] && (j < len-1))
448 if (arg[i] ==
'\\' &&
462get_multiple_arg_token_next(
const char *arg)
469 tok = strchr (arg,
',');
474 if (*(tok-1) ==
'\\')
477 tok = strchr (tok+1,
',');
483 if (! tok || strlen(tok) == 1)
490check_multiple_option_occurrences(
const char *prog_name,
unsigned int option_given,
unsigned int min,
unsigned int max,
const char *option_desc);
493check_multiple_option_occurrences(
const char *prog_name,
unsigned int option_given,
unsigned int min,
unsigned int max,
const char *option_desc)
495 int error_occurred = 0;
497 if (option_given && (min > 0 || max > 0))
499 if (min > 0 && max > 0)
504 if (option_given != (
unsigned int) min)
506 fprintf (stderr,
"%s: %s option occurrences must be %d\n",
507 prog_name, option_desc, min);
511 else if (option_given < (
unsigned int) min
512 || option_given > (
unsigned int) max)
515 fprintf (stderr,
"%s: %s option occurrences must be between %d and %d\n",
516 prog_name, option_desc, min, max);
523 if (option_given < min)
525 fprintf (stderr,
"%s: %s option occurrences must be at least %d\n",
526 prog_name, option_desc, min);
533 if (option_given > max)
535 fprintf (stderr,
"%s: %s option occurrences must be at most %d\n",
536 prog_name, option_desc, max);
542 return error_occurred;
547 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
555 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
561cmdline_parser2 (
int argc,
char **argv,
struct gengetopt_args_info *args_info,
int override,
int initialize,
int check_required)
572 result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
580 int result = EXIT_SUCCESS;
582 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
583 result = EXIT_FAILURE;
589cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error)
591 int error_occurred = 0;
592 FIX_UNUSED (additional_error);
597 fprintf (stderr,
"%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error :
""));
603 fprintf (stderr,
"%s: '--latticeConstant' option required%s\n", prog_name, (additional_error ? additional_error :
""));
609 fprintf (stderr,
"%s: '--radius' option required%s\n", prog_name, (additional_error ? additional_error :
""));
615 fprintf (stderr,
"%s: '--length' option required%s\n", prog_name, (additional_error ? additional_error :
""));
628 return error_occurred;
686#ifndef required_argument
687#define required_argument 1
690#ifndef optional_argument
691#define optional_argument 2
694struct custom_getopt_data {
736static char *custom_optarg;
753static int custom_optind = 1;
759static int custom_opterr = 1;
765static int custom_optopt =
'?';
775static void exchange(
char **argv,
struct custom_getopt_data *d)
777 int bottom = d->first_nonopt;
778 int middle = d->last_nonopt;
779 int top = d->custom_optind;
788 while (top > middle && middle > bottom) {
789 if (top - middle > middle - bottom) {
791 int len = middle - bottom;
795 for (i = 0; i < len; i++) {
796 tem = argv[bottom + i];
798 argv[top - (middle - bottom) + i];
799 argv[top - (middle - bottom) + i] = tem;
805 int len = top - middle;
809 for (i = 0; i < len; i++) {
810 tem = argv[bottom + i];
811 argv[bottom + i] = argv[middle + i];
812 argv[middle + i] = tem;
819 d->first_nonopt += (d->custom_optind - d->last_nonopt);
820 d->last_nonopt = d->custom_optind;
824static void custom_getopt_initialize(
struct custom_getopt_data *d)
831 d->first_nonopt = d->last_nonopt = d->custom_optind;
836#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
839static int shuffle_argv(
int argc,
char *
const *argv,
const struct option *longopts,
840 struct custom_getopt_data *d)
846 if (d->last_nonopt > d->custom_optind)
847 d->last_nonopt = d->custom_optind;
848 if (d->first_nonopt > d->custom_optind)
849 d->first_nonopt = d->custom_optind;
854 if (d->first_nonopt != d->last_nonopt &&
855 d->last_nonopt != d->custom_optind)
856 exchange((
char **) argv, d);
857 else if (d->last_nonopt != d->custom_optind)
858 d->first_nonopt = d->custom_optind;
863 while (d->custom_optind < argc && NONOPTION_P)
865 d->last_nonopt = d->custom_optind;
871 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind],
"--")) {
873 if (d->first_nonopt != d->last_nonopt
874 && d->last_nonopt != d->custom_optind)
875 exchange((
char **) argv, d);
876 else if (d->first_nonopt == d->last_nonopt)
877 d->first_nonopt = d->custom_optind;
878 d->last_nonopt = argc;
879 d->custom_optind = argc;
885 if (d->custom_optind == argc) {
890 if (d->first_nonopt != d->last_nonopt)
891 d->custom_optind = d->first_nonopt;
899 d->custom_optarg = argv[d->custom_optind++];
906 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] ==
'-'));
920static int check_long_opt(
int argc,
char *
const *argv,
const char *optstring,
921 const struct option *longopts,
int *longind,
922 int print_errors,
struct custom_getopt_data *d)
925 const struct option *p;
926 const struct option *pfound = NULL;
932 for (nameend = d->nextchar; *nameend && *nameend !=
'='; nameend++)
936 for (p = longopts, option_index = 0; p->name; p++, option_index++)
937 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
938 if ((
unsigned int) (nameend - d->nextchar)
939 == (
unsigned int) strlen(p->name)) {
942 indfound = option_index;
945 }
else if (pfound == NULL) {
948 indfound = option_index;
949 }
else if (pfound->has_arg != p->has_arg
950 || pfound->flag != p->flag
951 || pfound->val != p->val)
955 if (ambig && !exact) {
958 "%s: option `%s' is ambiguous\n",
959 argv[0], argv[d->custom_optind]);
961 d->nextchar += strlen(d->nextchar);
963 d->custom_optopt = 0;
967 option_index = indfound;
970 if (pfound->has_arg != no_argument)
971 d->custom_optarg = nameend + 1;
974 if (argv[d->custom_optind - 1][1] ==
'-') {
976 fprintf(stderr,
"%s: option `--%s' doesn't allow an argument\n",
977 argv[0], pfound->name);
980 fprintf(stderr,
"%s: option `%c%s' doesn't allow an argument\n",
981 argv[0], argv[d->custom_optind - 1][0], pfound->name);
985 d->nextchar += strlen(d->nextchar);
986 d->custom_optopt = pfound->val;
989 }
else if (pfound->has_arg == required_argument) {
990 if (d->custom_optind < argc)
991 d->custom_optarg = argv[d->custom_optind++];
995 "%s: option `%s' requires an argument\n",
997 argv[d->custom_optind - 1]);
999 d->nextchar += strlen(d->nextchar);
1000 d->custom_optopt = pfound->val;
1001 return optstring[0] ==
':' ?
':' :
'?';
1004 d->nextchar += strlen(d->nextchar);
1005 if (longind != NULL)
1006 *longind = option_index;
1008 *(pfound->flag) = pfound->val;
1019 if (argv[d->custom_optind][1] ==
'-') {
1022 "%s: unrecognized option `--%s'\n",
1023 argv[0], d->nextchar);
1027 "%s: unrecognized option `%c%s'\n",
1028 argv[0], argv[d->custom_optind][0],
1032 d->nextchar = (
char *)
"";
1034 d->custom_optopt = 0;
1038static int check_short_opt(
int argc,
char *
const *argv,
const char *optstring,
1039 int print_errors,
struct custom_getopt_data *d)
1041 char c = *d->nextchar++;
1042 const char *temp = strchr(optstring, c);
1045 if (*d->nextchar ==
'\0')
1047 if (!temp || c ==
':') {
1049 fprintf(stderr,
"%s: invalid option -- %c\n", argv[0], c);
1051 d->custom_optopt = c;
1054 if (temp[1] ==
':') {
1055 if (temp[2] ==
':') {
1057 if (*d->nextchar !=
'\0') {
1058 d->custom_optarg = d->nextchar;
1061 d->custom_optarg = NULL;
1065 if (*d->nextchar !=
'\0') {
1066 d->custom_optarg = d->nextchar;
1073 }
else if (d->custom_optind == argc) {
1076 "%s: option requires an argument -- %c\n",
1079 d->custom_optopt = c;
1080 if (optstring[0] ==
':')
1090 d->custom_optarg = argv[d->custom_optind++];
1167static int getopt_internal_r(
int argc,
char *
const *argv,
const char *optstring,
1168 const struct option *longopts,
int *longind,
1169 struct custom_getopt_data *d)
1171 int ret, print_errors = d->custom_opterr;
1173 if (optstring[0] ==
':')
1177 d->custom_optarg = NULL;
1183 if (d->custom_optind == 0 || !d->initialized) {
1184 if (d->custom_optind == 0)
1185 d->custom_optind = 1;
1186 custom_getopt_initialize(d);
1188 if (d->nextchar == NULL || *d->nextchar ==
'\0') {
1189 ret = shuffle_argv(argc, argv, longopts, d);
1193 if (longopts && (argv[d->custom_optind][1] ==
'-' ))
1194 return check_long_opt(argc, argv, optstring, longopts,
1195 longind, print_errors, d);
1196 return check_short_opt(argc, argv, optstring, print_errors, d);
1199static int custom_getopt_internal(
int argc,
char *
const *argv,
const char *optstring,
1200 const struct option *longopts,
int *longind)
1204 static struct custom_getopt_data d;
1206 d.custom_optind = custom_optind;
1207 d.custom_opterr = custom_opterr;
1208 result = getopt_internal_r(argc, argv, optstring, longopts,
1210 custom_optind = d.custom_optind;
1211 custom_optarg = d.custom_optarg;
1212 custom_optopt = d.custom_optopt;
1216static int custom_getopt_long (
int argc,
char *
const *argv,
const char *options,
1217 const struct option *long_options,
int *opt_index)
1219 return custom_getopt_internal(argc, argv, options, long_options,
1224static char *package_name = 0;
1245int update_arg(
void *field,
char **orig_field,
1246 unsigned int *field_given,
unsigned int *prev_given,
1247 char *value,
const char *possible_values[],
1248 const char *default_value,
1249 cmdline_parser_arg_type arg_type,
1250 int check_ambiguity,
int override,
1251 int no_free,
int multiple_option,
1252 const char *long_opt,
char short_opt,
1253 const char *additional_error)
1255 char *stop_char = 0;
1256 const char *val = value;
1258 char **string_field;
1264 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1266 if (short_opt !=
'-')
1267 fprintf (stderr,
"%s: `--%s' (`-%c') option given more than once%s\n",
1268 package_name, long_opt, short_opt,
1269 (additional_error ? additional_error :
""));
1271 fprintf (stderr,
"%s: `--%s' option given more than once%s\n",
1272 package_name, long_opt,
1273 (additional_error ? additional_error :
""));
1277 FIX_UNUSED (default_value);
1279 if (field_given && *field_given && !
override)
1285 if (possible_values)
1286 val = possible_values[found];
1290 *((
int *)field) = !*((
int *)field);
1293 if (val) *((
double *)field) = strtod (val, &stop_char);
1297 string_field = (
char **)field;
1298 if (!no_free && *string_field)
1299 free (*string_field);
1300 *string_field = gengetopt_strdup (val);
1310 if (val && !(stop_char && *stop_char ==
'\0')) {
1311 fprintf(stderr,
"%s: invalid numeric value: %s\n", package_name, val);
1325 if (value && orig_field) {
1327 *orig_field = value;
1331 *orig_field = gengetopt_strdup (value);
1344int update_multiple_arg_temp(
struct generic_list **list,
1345 unsigned int *prev_given,
const char *val,
1346 const char *possible_values[],
const char *default_value,
1347 cmdline_parser_arg_type arg_type,
1348 const char *long_opt,
char short_opt,
1349 const char *additional_error)
1353 const char *multi_next;
1355 if (arg_type == ARG_NO) {
1360 multi_token = get_multiple_arg_token(val);
1361 multi_next = get_multiple_arg_token_next (val);
1366 if (update_arg((
void *)&((*list)->arg), &((*list)->orig), 0,
1367 prev_given, multi_token, possible_values, default_value,
1368 arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
1369 if (multi_token) free(multi_token);
1375 multi_token = get_multiple_arg_token(multi_next);
1376 multi_next = get_multiple_arg_token_next (multi_next);
1389void free_list(
struct generic_list *list,
short string_arg)
1392 struct generic_list *tmp;
1396 if (string_arg && list->arg.string_arg)
1397 free (list->arg.string_arg);
1410void update_multiple_arg(
void *field,
char ***orig_field,
1411 unsigned int field_given,
unsigned int prev_given,
union generic_value *default_value,
1412 cmdline_parser_arg_type arg_type,
1413 struct generic_list *list)
1416 struct generic_list *tmp;
1418 if (prev_given && list) {
1419 *orig_field = (
char **) realloc (*orig_field, (field_given + prev_given) *
sizeof (
char *));
1423 *((
double **)field) = (
double *)realloc (*((
double **)field), (field_given + prev_given) *
sizeof (double));
break;
1425 *((
char ***)field) = (
char **)realloc (*((
char ***)field), (field_given + prev_given) *
sizeof (
char *));
break;
1430 for (i = (prev_given - 1); i >= 0; --i)
1436 (*((
double **)field))[i + field_given] = tmp->arg.double_arg;
break;
1438 (*((
char ***)field))[i + field_given] = tmp->arg.string_arg;
break;
1442 (*orig_field) [i + field_given] = list->orig;
1447 if (default_value && ! field_given) {
1450 if (! *((
double **)field)) {
1451 *((
double **)field) = (
double *)malloc (
sizeof (
double));
1452 (*((
double **)field))[0] = default_value->double_arg;
1456 if (! *((
char ***)field)) {
1457 *((
char ***)field) = (
char **)malloc (
sizeof (
char *));
1458 (*((
char ***)field))[0] = gengetopt_strdup(default_value->string_arg);
1463 if (!(*orig_field)) {
1464 *orig_field = (
char **) malloc (
sizeof (
char *));
1465 (*orig_field)[0] = 0;
1472cmdline_parser_internal (
1478 struct generic_list * shellRadius_list = NULL;
1479 struct generic_list * molFraction_list = NULL;
1480 int error_occurred = 0;
1486 int check_ambiguity;
1493 package_name = argv[0];
1512 int option_index = 0;
1514 static struct option long_options[] = {
1515 {
"help", 0, NULL,
'h' },
1516 {
"version", 0, NULL,
'V' },
1517 {
"output", 1, NULL,
'o' },
1518 {
"latticeConstant", 1, NULL, 0 },
1519 {
"radius", 1, NULL, 0 },
1520 {
"length", 1, NULL, 0 },
1521 {
"ellipsoid", 0, NULL,
'e' },
1522 {
"shellRadius", 1, NULL, 0 },
1523 {
"molFraction", 1, NULL, 0 },
1524 {
"vacancyPercent", 1, NULL, 0 },
1525 {
"vacancyInnerRadius", 1, NULL, 0 },
1526 {
"vacancyOuterRadius", 1, NULL, 0 },
1530 custom_optarg = optarg;
1531 custom_optind = optind;
1532 custom_opterr = opterr;
1533 custom_optopt = optopt;
1535 c = custom_getopt_long (argc, argv,
"hVo:e", long_options, &option_index);
1537 optarg = custom_optarg;
1538 optind = custom_optind;
1539 opterr = custom_opterr;
1540 optopt = custom_optopt;
1547 cmdline_parser_print_help ();
1548 cmdline_parser_free (&local_args_info);
1549 exit (EXIT_SUCCESS);
1552 cmdline_parser_print_version ();
1553 cmdline_parser_free (&local_args_info);
1554 exit (EXIT_SUCCESS);
1559 if (update_arg( (
void *)&(args_info->
output_arg),
1561 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1562 check_ambiguity,
override, 0, 0,
1572 &(local_args_info.ellipsoid_given), optarg, 0, 0, ARG_FLAG,
1573 check_ambiguity,
override, 1, 0,
"ellipsoid",
'e',
1581 if (strcmp (long_options[option_index].name,
"latticeConstant") == 0)
1587 &(local_args_info.latticeConstant_given), optarg, 0, 0, ARG_DOUBLE,
1588 check_ambiguity,
override, 0, 0,
1589 "latticeConstant",
'-',
1595 else if (strcmp (long_options[option_index].name,
"radius") == 0)
1599 if (update_arg( (
void *)&(args_info->
radius_arg),
1601 &(local_args_info.radius_given), optarg, 0, 0, ARG_DOUBLE,
1602 check_ambiguity,
override, 0, 0,
1609 else if (strcmp (long_options[option_index].name,
"length") == 0)
1613 if (update_arg( (
void *)&(args_info->
length_arg),
1615 &(local_args_info.length_given), optarg, 0, 0, ARG_DOUBLE,
1616 check_ambiguity,
override, 0, 0,
1623 else if (strcmp (long_options[option_index].name,
"shellRadius") == 0)
1626 if (update_multiple_arg_temp(&shellRadius_list,
1627 &(local_args_info.shellRadius_given), optarg, 0, 0, ARG_DOUBLE,
1634 else if (strcmp (long_options[option_index].name,
"molFraction") == 0)
1637 if (update_multiple_arg_temp(&molFraction_list,
1638 &(local_args_info.molFraction_given), optarg, 0, 0, ARG_DOUBLE,
1645 else if (strcmp (long_options[option_index].name,
"vacancyPercent") == 0)
1651 &(local_args_info.vacancyPercent_given), optarg, 0, 0, ARG_DOUBLE,
1652 check_ambiguity,
override, 0, 0,
1653 "vacancyPercent",
'-',
1659 else if (strcmp (long_options[option_index].name,
"vacancyInnerRadius") == 0)
1665 &(local_args_info.vacancyInnerRadius_given), optarg, 0, 0, ARG_DOUBLE,
1666 check_ambiguity,
override, 0, 0,
1667 "vacancyInnerRadius",
'-',
1673 else if (strcmp (long_options[option_index].name,
"vacancyOuterRadius") == 0)
1679 &(local_args_info.vacancyOuterRadius_given), optarg, 0, 0, ARG_DOUBLE,
1680 check_ambiguity,
override, 0, 0,
1681 "vacancyOuterRadius",
'-',
1693 fprintf (stderr,
"%s: option unknown: %c%s\n",
CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error :
""));
1701 local_args_info.shellRadius_given, 0,
1702 ARG_DOUBLE, shellRadius_list);
1705 local_args_info.molFraction_given, 0,
1706 ARG_DOUBLE, molFraction_list);
1709 local_args_info.shellRadius_given = 0;
1711 local_args_info.molFraction_given = 0;
1715 error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error);
1718 cmdline_parser_release (&local_args_info);
1720 if ( error_occurred )
1721 return (EXIT_FAILURE);
1726 int found_prog_name = 0;
1732 args_info->
inputs_num = argc - optind - found_prog_name;
1734 (
char **)(malloc ((args_info->
inputs_num)*
sizeof(
char *))) ;
1735 while (optind < argc)
1736 args_info->
inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1742 free_list (shellRadius_list, 0 );
1743 free_list (molFraction_list, 0 );
1745 cmdline_parser_release (&local_args_info);
1746 return (EXIT_FAILURE);
1749#ifndef CONFIG_FILE_LINE_SIZE
1750#define CONFIG_FILE_LINE_SIZE 2048
1752#define ADDITIONAL_ERROR " in configuration file "
1754#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1758_cmdline_parser_configfile (
const char *filename,
int *my_argc)
1761 char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
1762 char linebuf[CONFIG_FILE_LINE_SIZE];
1764 int result = 0,
equal;
1767 size_t len, next_token;
1770 if ((file = fopen(filename,
"r")) == 0)
1772 fprintf (stderr,
"%s: Error opening configuration file '%s'\n",
1774 return EXIT_FAILURE;
1777 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0)
1781 len = strlen(linebuf);
1782 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
1784 fprintf (stderr,
"%s:%s:%d: Line too long in configuration file\n",
1786 result = EXIT_FAILURE;
1791 next_token = strspn (linebuf,
" \t\r\n");
1792 str_index = linebuf + next_token;
1794 if ( str_index[0] ==
'\0' || str_index[0] ==
'#')
1800 next_token = strcspn (fopt,
" \t\r\n=");
1802 if (fopt[next_token] ==
'\0')
1810 equal = (fopt[next_token] ==
'=');
1811 fopt[next_token++] =
'\0';
1814 next_token += strspn (fopt + next_token,
" \t\r\n");
1818 if ((equal = (fopt[next_token] ==
'=')))
1821 next_token += strspn (fopt + next_token,
" \t\r\n");
1823 str_index += next_token;
1827 if ( farg[0] ==
'\"' || farg[0] ==
'\'' )
1829 str_index = strchr (++farg, str_index[0] );
1834 "%s:%s:%d: unterminated string in configuration file\n",
1836 result = EXIT_FAILURE;
1842 next_token = strcspn (farg,
" \t\r\n#\'\"");
1843 str_index += next_token;
1847 delimiter = *str_index, *str_index++ =
'\0';
1850 if (delimiter !=
'\0' && delimiter !=
'#')
1852 str_index += strspn(str_index,
" \t\r\n");
1853 if (*str_index !=
'\0' && *str_index !=
'#')
1857 "%s:%s:%d: malformed string in configuration file\n",
1859 result = EXIT_FAILURE;
1865 if (!strcmp(fopt,
"include")) {
1866 if (farg && *farg) {
1867 result = _cmdline_parser_configfile(farg, my_argc);
1869 fprintf(stderr,
"%s:%s:%d: include requires a filename argument.\n",
1875 strcat (my_argv, len > 1 ?
"--" :
"-");
1876 strcat (my_argv, fopt);
1877 if (len > 1 && ((farg && *farg) || equal))
1878 strcat (my_argv,
"=");
1880 strcat (my_argv, farg);
1883 cmd_line_list_tmp = (
struct line_list *) malloc (
sizeof (
struct line_list));
1884 cmd_line_list_tmp->next = cmd_line_list;
1885 cmd_line_list = cmd_line_list_tmp;
1886 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
1895cmdline_parser_configfile (
1896 const char *filename,
1898 int override,
int initialize,
int check_required)
1908 return cmdline_parser_config_file (filename, args_info, ¶ms);
1912cmdline_parser_config_file (
const char *filename,
1919 char *additional_error;
1922 cmd_line_list_tmp = (
struct line_list *) malloc (
sizeof (
struct line_list));
1923 cmd_line_list_tmp->next = cmd_line_list;
1924 cmd_line_list = cmd_line_list_tmp;
1927 result = _cmdline_parser_configfile(filename, &my_argc);
1929 if (result != EXIT_FAILURE) {
1930 my_argv_arg = (
char **) malloc((my_argc+1) *
sizeof(
char *));
1931 cmd_line_list_tmp = cmd_line_list;
1933 for (i = my_argc - 1; i >= 0; --i) {
1934 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
1935 cmd_line_list_tmp = cmd_line_list_tmp->next;
1938 my_argv_arg[my_argc] = 0;
1940 additional_error = (
char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
1941 strcpy (additional_error, ADDITIONAL_ERROR);
1942 strcat (additional_error, filename);
1944 cmdline_parser_internal (my_argc, my_argv_arg, args_info,
1948 free (additional_error);
#define CMDLINE_PARSER_VERSION
the program version
#define CMDLINE_PARSER_PACKAGE_NAME
the complete program name (used for help and version)
#define CMDLINE_PARSER_PACKAGE
the program name (used for printing errors)
bool equal(const Polynomial< Real > &p1, const Polynomial< Real > &p2)
Tests if two polynomial have the same exponents.
The header file for the command line option parser generated by GNU Gengetopt version 2....
The additional parameters to pass to parser functions.
int print_errors
whether getopt_long should print an error message for a bad option (default 1)
int check_required
whether to check that all required options were provided (default 1)
int check_ambiguity
whether to check for options already specified in the option structure gengetopt_args_info (default 0...
int initialize
whether to initialize the option structure gengetopt_args_info (default 1)
int override
whether to override possibly already present options (default 0)
Where the command line options are stored.
unsigned int vacancyInnerRadius_given
Whether vacancyInnerRadius was given.
unsigned int output_given
Whether output was given.
const char * ellipsoid_help
Build an Ellipsoid instead of a rod.
char ** molFraction_orig
Builds a multi-component random alloy nanoparticle.
unsigned int latticeConstant_given
Whether latticeConstant was given.
double vacancyPercent_arg
Percentage of atoms to remove from within vacancy range.
const char * radius_help
Nanoparticle radius in Angstroms help description.
char * output_orig
output file name original value given at command line.
const char * output_help
output file name help description.
double vacancyOuterRadius_arg
Radius arround core-shell where vacancies should be located.
const char * molFraction_help
Builds a multi-component random alloy nanoparticle.
unsigned inputs_num
unamed options number
char * vacancyInnerRadius_orig
Radius arround core-shell where vacancies should be located.
const char * vacancyInnerRadius_help
Radius arround core-shell where vacancies should be located.
const char * latticeConstant_help
Lattice spacing in Angstroms for cubic lattice.
unsigned int molFraction_given
Whether molFraction was given.
int ellipsoid_flag
Build an Ellipsoid instead of a rod.
const char * vacancyPercent_help
Percentage of atoms to remove from within vacancy range help description.
double length_arg
maximum length (default='100').
const char * help_help
Print help and exit help description.
double * molFraction_arg
Builds a multi-component random alloy nanoparticle.
char * vacancyPercent_orig
Percentage of atoms to remove from within vacancy range original value given at command line.
char * output_arg
output file name.
char ** inputs
unamed options (options without names)
double * shellRadius_arg
Radius containing within it only molecules of a specific component.
unsigned int molFraction_min
Builds a multi-component random alloy nanoparticle.
unsigned int shellRadius_given
Whether shellRadius was given.
const char * vacancyOuterRadius_help
Radius arround core-shell where vacancies should be located.
char * latticeConstant_orig
Lattice spacing in Angstroms for cubic lattice.
unsigned int length_given
Whether length was given.
unsigned int molFraction_max
Builds a multi-component random alloy nanoparticle.
char * length_orig
maximum length original value given at command line.
double radius_arg
Nanoparticle radius in Angstroms.
unsigned int help_given
Whether help was given.
const char * shellRadius_help
Radius containing within it only molecules of a specific component.
unsigned int ellipsoid_given
Whether ellipsoid was given.
char * vacancyOuterRadius_orig
Radius arround core-shell where vacancies should be located.
unsigned int radius_given
Whether radius was given.
double vacancyInnerRadius_arg
Radius arround core-shell where vacancies should be located.
char * radius_orig
Nanoparticle radius in Angstroms original value given at command line.
unsigned int version_given
Whether version was given.
const char * length_help
maximum length help description.
unsigned int shellRadius_min
Radius containing within it only molecules of a specific component.
const char * version_help
Print version and exit help description.
unsigned int vacancyPercent_given
Whether vacancyPercent was given.
double latticeConstant_arg
Lattice spacing in Angstroms for cubic lattice.
char ** shellRadius_orig
Radius containing within it only molecules of a specific component.
unsigned int shellRadius_max
Radius containing within it only molecules of a specific component.
unsigned int vacancyOuterRadius_given
Whether vacancyOuterRadius was given.
int cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name)
Checks that all the required options were specified.
struct cmdline_parser_params * cmdline_parser_params_create(void)
Allocates dynamically a cmdline_parser_params structure and initializes all its fields to their defau...
void cmdline_parser_init(struct gengetopt_args_info *args_info)
Initializes the passed gengetopt_args_info structure's fields (also set default values for options th...
void cmdline_parser_params_init(struct cmdline_parser_params *params)
Initializes all the fields a cmdline_parser_params structure to their default values.