21#define FIX_UNUSED(X) (void) (X)
27const char *gengetopt_args_info_purpose =
"Builds fcc or pentagonal nanorods and outputs an OpenMD startup file";
29const char *gengetopt_args_info_usage =
"Usage: nanorod_pentBuilder [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 " --shellRadius=DOUBLE Radius containing within it only molecules of a\n specific component. Specified for each\n component > 1 in the template file.",
43 " --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.",
44 " --vacancyPercent=DOUBLE Percentage of atoms to remove from within\n vacancy range",
45 " --vacancyInnerRadius=DOUBLE\n Radius arround core-shell where vacancies\n should be located.",
46 " --vacancyOuterRadius=DOUBLE\n Radius arround core-shell where vacancies\n should be located.",
53} cmdline_parser_arg_type;
65cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error);
69 struct line_list * next;
72static struct line_list *cmd_line_list = 0;
73static struct line_list *cmd_line_list_tmp = 0;
81 while (cmd_line_list) {
82 cmd_line_list_tmp = cmd_line_list;
83 cmd_line_list = cmd_line_list->next;
84 free (cmd_line_list_tmp->string_arg);
85 free (cmd_line_list_tmp);
92gengetopt_strdup (
const char *s);
113 FIX_UNUSED (args_info);
134 args_info->
help_help = gengetopt_args_info_help[0] ;
136 args_info->
output_help = gengetopt_args_info_help[2] ;
138 args_info->
radius_help = gengetopt_args_info_help[4] ;
139 args_info->
length_help = gengetopt_args_info_help[5] ;
153cmdline_parser_print_version (
void)
159 if (strlen(gengetopt_args_info_versiontext) > 0)
160 printf(
"\n%s\n", gengetopt_args_info_versiontext);
163static void print_help_common(
void) {
164 cmdline_parser_print_version ();
166 if (strlen(gengetopt_args_info_purpose) > 0)
167 printf(
"\n%s\n", gengetopt_args_info_purpose);
169 if (strlen(gengetopt_args_info_usage) > 0)
170 printf(
"\n%s\n", gengetopt_args_info_usage);
174 if (strlen(gengetopt_args_info_description) > 0)
175 printf(
"%s\n\n", gengetopt_args_info_description);
179cmdline_parser_print_help (
void)
183 while (gengetopt_args_info_help[i])
184 printf(
"%s\n", gengetopt_args_info_help[i++]);
190 clear_given (args_info);
191 clear_args (args_info);
192 init_args_info (args_info);
221free_string_field (
char **s)
234 const char *default_string_arg;
240 union generic_value arg;
242 struct generic_list *next;
248static void add_node(
struct generic_list **list) {
249 struct generic_list *new_node = (
struct generic_list *) malloc (
sizeof (
struct generic_list));
250 new_node->next = *list;
252 new_node->arg.string_arg = 0;
260free_multiple_field(
unsigned int len,
void *arg,
char ***orig)
264 for (i = 0; i < len; ++i)
266 free_string_field(&((*orig)[i]));
295 free (args_info->
inputs [i]);
300 clear_given (args_info);
305write_into_file(FILE *outfile,
const char *opt,
const char *arg,
const char *values[])
309 fprintf(outfile,
"%s=\"%s\"\n", opt, arg);
311 fprintf(outfile,
"%s\n", opt);
316write_multiple_into_file(FILE *outfile,
int len,
const char *opt,
char **arg,
const char *values[])
320 for (i = 0; i < len; ++i)
321 write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
336 write_into_file(outfile,
"help", 0, 0 );
338 write_into_file(outfile,
"version", 0, 0 );
340 write_into_file(outfile,
"output", args_info->
output_orig, 0);
344 write_into_file(outfile,
"radius", args_info->
radius_orig, 0);
346 write_into_file(outfile,
"length", args_info->
length_orig, 0);
367 outfile = fopen(filename,
"w");
375 i = cmdline_parser_dump(outfile, args_info);
384 cmdline_parser_release (args_info);
389gengetopt_strdup (
const char *s)
395 result = (
char*)malloc(strlen(s) + 1);
396 if (result == (
char*)0)
403get_multiple_arg_token(
const char *arg)
407 size_t len, num_of_escape, i, j;
412 tok = strchr (arg,
',');
418 if (*(tok-1) ==
'\\')
421 tok = strchr (tok+1,
',');
429 len = (size_t)(tok - arg + 1);
431 len = strlen (arg) + 1;
433 len -= num_of_escape;
435 ret = (
char *) malloc (len);
439 while (arg[i] && (j < len-1))
441 if (arg[i] ==
'\\' &&
455get_multiple_arg_token_next(
const char *arg)
462 tok = strchr (arg,
',');
467 if (*(tok-1) ==
'\\')
470 tok = strchr (tok+1,
',');
476 if (! tok || strlen(tok) == 1)
483check_multiple_option_occurrences(
const char *prog_name,
unsigned int option_given,
unsigned int min,
unsigned int max,
const char *option_desc);
486check_multiple_option_occurrences(
const char *prog_name,
unsigned int option_given,
unsigned int min,
unsigned int max,
const char *option_desc)
488 int error_occurred = 0;
490 if (option_given && (min > 0 || max > 0))
492 if (min > 0 && max > 0)
497 if (option_given != (
unsigned int) min)
499 fprintf (stderr,
"%s: %s option occurrences must be %d\n",
500 prog_name, option_desc, min);
504 else if (option_given < (
unsigned int) min
505 || option_given > (
unsigned int) max)
508 fprintf (stderr,
"%s: %s option occurrences must be between %d and %d\n",
509 prog_name, option_desc, min, max);
516 if (option_given < min)
518 fprintf (stderr,
"%s: %s option occurrences must be at least %d\n",
519 prog_name, option_desc, min);
526 if (option_given > max)
528 fprintf (stderr,
"%s: %s option occurrences must be at most %d\n",
529 prog_name, option_desc, max);
535 return error_occurred;
540 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
548 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
554cmdline_parser2 (
int argc,
char **argv,
struct gengetopt_args_info *args_info,
int override,
int initialize,
int check_required)
565 result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
573 int result = EXIT_SUCCESS;
575 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
576 result = EXIT_FAILURE;
582cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error)
584 int error_occurred = 0;
585 FIX_UNUSED (additional_error);
590 fprintf (stderr,
"%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error :
""));
596 fprintf (stderr,
"%s: '--latticeConstant' option required%s\n", prog_name, (additional_error ? additional_error :
""));
602 fprintf (stderr,
"%s: '--radius' option required%s\n", prog_name, (additional_error ? additional_error :
""));
608 fprintf (stderr,
"%s: '--length' option required%s\n", prog_name, (additional_error ? additional_error :
""));
621 return error_occurred;
679#ifndef required_argument
680#define required_argument 1
683#ifndef optional_argument
684#define optional_argument 2
687struct custom_getopt_data {
729static char *custom_optarg;
746static int custom_optind = 1;
752static int custom_opterr = 1;
758static int custom_optopt =
'?';
768static void exchange(
char **argv,
struct custom_getopt_data *d)
770 int bottom = d->first_nonopt;
771 int middle = d->last_nonopt;
772 int top = d->custom_optind;
781 while (top > middle && middle > bottom) {
782 if (top - middle > middle - bottom) {
784 int len = middle - bottom;
788 for (i = 0; i < len; i++) {
789 tem = argv[bottom + i];
791 argv[top - (middle - bottom) + i];
792 argv[top - (middle - bottom) + i] = tem;
798 int len = top - middle;
802 for (i = 0; i < len; i++) {
803 tem = argv[bottom + i];
804 argv[bottom + i] = argv[middle + i];
805 argv[middle + i] = tem;
812 d->first_nonopt += (d->custom_optind - d->last_nonopt);
813 d->last_nonopt = d->custom_optind;
817static void custom_getopt_initialize(
struct custom_getopt_data *d)
824 d->first_nonopt = d->last_nonopt = d->custom_optind;
829#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
832static int shuffle_argv(
int argc,
char *
const *argv,
const struct option *longopts,
833 struct custom_getopt_data *d)
839 if (d->last_nonopt > d->custom_optind)
840 d->last_nonopt = d->custom_optind;
841 if (d->first_nonopt > d->custom_optind)
842 d->first_nonopt = d->custom_optind;
847 if (d->first_nonopt != d->last_nonopt &&
848 d->last_nonopt != d->custom_optind)
849 exchange((
char **) argv, d);
850 else if (d->last_nonopt != d->custom_optind)
851 d->first_nonopt = d->custom_optind;
856 while (d->custom_optind < argc && NONOPTION_P)
858 d->last_nonopt = d->custom_optind;
864 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind],
"--")) {
866 if (d->first_nonopt != d->last_nonopt
867 && d->last_nonopt != d->custom_optind)
868 exchange((
char **) argv, d);
869 else if (d->first_nonopt == d->last_nonopt)
870 d->first_nonopt = d->custom_optind;
871 d->last_nonopt = argc;
872 d->custom_optind = argc;
878 if (d->custom_optind == argc) {
883 if (d->first_nonopt != d->last_nonopt)
884 d->custom_optind = d->first_nonopt;
892 d->custom_optarg = argv[d->custom_optind++];
899 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] ==
'-'));
913static int check_long_opt(
int argc,
char *
const *argv,
const char *optstring,
914 const struct option *longopts,
int *longind,
915 int print_errors,
struct custom_getopt_data *d)
918 const struct option *p;
919 const struct option *pfound = NULL;
925 for (nameend = d->nextchar; *nameend && *nameend !=
'='; nameend++)
929 for (p = longopts, option_index = 0; p->name; p++, option_index++)
930 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
931 if ((
unsigned int) (nameend - d->nextchar)
932 == (
unsigned int) strlen(p->name)) {
935 indfound = option_index;
938 }
else if (pfound == NULL) {
941 indfound = option_index;
942 }
else if (pfound->has_arg != p->has_arg
943 || pfound->flag != p->flag
944 || pfound->val != p->val)
948 if (ambig && !exact) {
951 "%s: option `%s' is ambiguous\n",
952 argv[0], argv[d->custom_optind]);
954 d->nextchar += strlen(d->nextchar);
956 d->custom_optopt = 0;
960 option_index = indfound;
963 if (pfound->has_arg != no_argument)
964 d->custom_optarg = nameend + 1;
967 if (argv[d->custom_optind - 1][1] ==
'-') {
969 fprintf(stderr,
"%s: option `--%s' doesn't allow an argument\n",
970 argv[0], pfound->name);
973 fprintf(stderr,
"%s: option `%c%s' doesn't allow an argument\n",
974 argv[0], argv[d->custom_optind - 1][0], pfound->name);
978 d->nextchar += strlen(d->nextchar);
979 d->custom_optopt = pfound->val;
982 }
else if (pfound->has_arg == required_argument) {
983 if (d->custom_optind < argc)
984 d->custom_optarg = argv[d->custom_optind++];
988 "%s: option `%s' requires an argument\n",
990 argv[d->custom_optind - 1]);
992 d->nextchar += strlen(d->nextchar);
993 d->custom_optopt = pfound->val;
994 return optstring[0] ==
':' ?
':' :
'?';
997 d->nextchar += strlen(d->nextchar);
999 *longind = option_index;
1001 *(pfound->flag) = pfound->val;
1012 if (argv[d->custom_optind][1] ==
'-') {
1015 "%s: unrecognized option `--%s'\n",
1016 argv[0], d->nextchar);
1020 "%s: unrecognized option `%c%s'\n",
1021 argv[0], argv[d->custom_optind][0],
1025 d->nextchar = (
char *)
"";
1027 d->custom_optopt = 0;
1031static int check_short_opt(
int argc,
char *
const *argv,
const char *optstring,
1032 int print_errors,
struct custom_getopt_data *d)
1034 char c = *d->nextchar++;
1035 const char *temp = strchr(optstring, c);
1038 if (*d->nextchar ==
'\0')
1040 if (!temp || c ==
':') {
1042 fprintf(stderr,
"%s: invalid option -- %c\n", argv[0], c);
1044 d->custom_optopt = c;
1047 if (temp[1] ==
':') {
1048 if (temp[2] ==
':') {
1050 if (*d->nextchar !=
'\0') {
1051 d->custom_optarg = d->nextchar;
1054 d->custom_optarg = NULL;
1058 if (*d->nextchar !=
'\0') {
1059 d->custom_optarg = d->nextchar;
1066 }
else if (d->custom_optind == argc) {
1069 "%s: option requires an argument -- %c\n",
1072 d->custom_optopt = c;
1073 if (optstring[0] ==
':')
1083 d->custom_optarg = argv[d->custom_optind++];
1160static int getopt_internal_r(
int argc,
char *
const *argv,
const char *optstring,
1161 const struct option *longopts,
int *longind,
1162 struct custom_getopt_data *d)
1164 int ret, print_errors = d->custom_opterr;
1166 if (optstring[0] ==
':')
1170 d->custom_optarg = NULL;
1176 if (d->custom_optind == 0 || !d->initialized) {
1177 if (d->custom_optind == 0)
1178 d->custom_optind = 1;
1179 custom_getopt_initialize(d);
1181 if (d->nextchar == NULL || *d->nextchar ==
'\0') {
1182 ret = shuffle_argv(argc, argv, longopts, d);
1186 if (longopts && (argv[d->custom_optind][1] ==
'-' ))
1187 return check_long_opt(argc, argv, optstring, longopts,
1188 longind, print_errors, d);
1189 return check_short_opt(argc, argv, optstring, print_errors, d);
1192static int custom_getopt_internal(
int argc,
char *
const *argv,
const char *optstring,
1193 const struct option *longopts,
int *longind)
1197 static struct custom_getopt_data d;
1199 d.custom_optind = custom_optind;
1200 d.custom_opterr = custom_opterr;
1201 result = getopt_internal_r(argc, argv, optstring, longopts,
1203 custom_optind = d.custom_optind;
1204 custom_optarg = d.custom_optarg;
1205 custom_optopt = d.custom_optopt;
1209static int custom_getopt_long (
int argc,
char *
const *argv,
const char *options,
1210 const struct option *long_options,
int *opt_index)
1212 return custom_getopt_internal(argc, argv, options, long_options,
1217static char *package_name = 0;
1238int update_arg(
void *field,
char **orig_field,
1239 unsigned int *field_given,
unsigned int *prev_given,
1240 char *value,
const char *possible_values[],
1241 const char *default_value,
1242 cmdline_parser_arg_type arg_type,
1243 int check_ambiguity,
int override,
1244 int no_free,
int multiple_option,
1245 const char *long_opt,
char short_opt,
1246 const char *additional_error)
1248 char *stop_char = 0;
1249 const char *val = value;
1251 char **string_field;
1257 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1259 if (short_opt !=
'-')
1260 fprintf (stderr,
"%s: `--%s' (`-%c') option given more than once%s\n",
1261 package_name, long_opt, short_opt,
1262 (additional_error ? additional_error :
""));
1264 fprintf (stderr,
"%s: `--%s' option given more than once%s\n",
1265 package_name, long_opt,
1266 (additional_error ? additional_error :
""));
1270 FIX_UNUSED (default_value);
1272 if (field_given && *field_given && !
override)
1278 if (possible_values)
1279 val = possible_values[found];
1283 if (val) *((
double *)field) = strtod (val, &stop_char);
1287 string_field = (
char **)field;
1288 if (!no_free && *string_field)
1289 free (*string_field);
1290 *string_field = gengetopt_strdup (val);
1300 if (val && !(stop_char && *stop_char ==
'\0')) {
1301 fprintf(stderr,
"%s: invalid numeric value: %s\n", package_name, val);
1314 if (value && orig_field) {
1316 *orig_field = value;
1320 *orig_field = gengetopt_strdup (value);
1333int update_multiple_arg_temp(
struct generic_list **list,
1334 unsigned int *prev_given,
const char *val,
1335 const char *possible_values[],
const char *default_value,
1336 cmdline_parser_arg_type arg_type,
1337 const char *long_opt,
char short_opt,
1338 const char *additional_error)
1342 const char *multi_next;
1344 if (arg_type == ARG_NO) {
1349 multi_token = get_multiple_arg_token(val);
1350 multi_next = get_multiple_arg_token_next (val);
1355 if (update_arg((
void *)&((*list)->arg), &((*list)->orig), 0,
1356 prev_given, multi_token, possible_values, default_value,
1357 arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
1358 if (multi_token) free(multi_token);
1364 multi_token = get_multiple_arg_token(multi_next);
1365 multi_next = get_multiple_arg_token_next (multi_next);
1378void free_list(
struct generic_list *list,
short string_arg)
1381 struct generic_list *tmp;
1385 if (string_arg && list->arg.string_arg)
1386 free (list->arg.string_arg);
1399void update_multiple_arg(
void *field,
char ***orig_field,
1400 unsigned int field_given,
unsigned int prev_given,
union generic_value *default_value,
1401 cmdline_parser_arg_type arg_type,
1402 struct generic_list *list)
1405 struct generic_list *tmp;
1407 if (prev_given && list) {
1408 *orig_field = (
char **) realloc (*orig_field, (field_given + prev_given) *
sizeof (
char *));
1412 *((
double **)field) = (
double *)realloc (*((
double **)field), (field_given + prev_given) *
sizeof (double));
break;
1414 *((
char ***)field) = (
char **)realloc (*((
char ***)field), (field_given + prev_given) *
sizeof (
char *));
break;
1419 for (i = (prev_given - 1); i >= 0; --i)
1425 (*((
double **)field))[i + field_given] = tmp->arg.double_arg;
break;
1427 (*((
char ***)field))[i + field_given] = tmp->arg.string_arg;
break;
1431 (*orig_field) [i + field_given] = list->orig;
1436 if (default_value && ! field_given) {
1439 if (! *((
double **)field)) {
1440 *((
double **)field) = (
double *)malloc (
sizeof (
double));
1441 (*((
double **)field))[0] = default_value->double_arg;
1445 if (! *((
char ***)field)) {
1446 *((
char ***)field) = (
char **)malloc (
sizeof (
char *));
1447 (*((
char ***)field))[0] = gengetopt_strdup(default_value->string_arg);
1452 if (!(*orig_field)) {
1453 *orig_field = (
char **) malloc (
sizeof (
char *));
1454 (*orig_field)[0] = 0;
1461cmdline_parser_internal (
1467 struct generic_list * shellRadius_list = NULL;
1468 struct generic_list * molFraction_list = NULL;
1469 int error_occurred = 0;
1475 int check_ambiguity;
1482 package_name = argv[0];
1501 int option_index = 0;
1503 static struct option long_options[] = {
1504 {
"help", 0, NULL,
'h' },
1505 {
"version", 0, NULL,
'V' },
1506 {
"output", 1, NULL,
'o' },
1507 {
"latticeConstant", 1, NULL, 0 },
1508 {
"radius", 1, NULL, 0 },
1509 {
"length", 1, NULL, 0 },
1510 {
"shellRadius", 1, NULL, 0 },
1511 {
"molFraction", 1, NULL, 0 },
1512 {
"vacancyPercent", 1, NULL, 0 },
1513 {
"vacancyInnerRadius", 1, NULL, 0 },
1514 {
"vacancyOuterRadius", 1, NULL, 0 },
1518 custom_optarg = optarg;
1519 custom_optind = optind;
1520 custom_opterr = opterr;
1521 custom_optopt = optopt;
1523 c = custom_getopt_long (argc, argv,
"hVo:", long_options, &option_index);
1525 optarg = custom_optarg;
1526 optind = custom_optind;
1527 opterr = custom_opterr;
1528 optopt = custom_optopt;
1535 cmdline_parser_print_help ();
1536 cmdline_parser_free (&local_args_info);
1537 exit (EXIT_SUCCESS);
1540 cmdline_parser_print_version ();
1541 cmdline_parser_free (&local_args_info);
1542 exit (EXIT_SUCCESS);
1547 if (update_arg( (
void *)&(args_info->
output_arg),
1549 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1550 check_ambiguity,
override, 0, 0,
1559 if (strcmp (long_options[option_index].name,
"latticeConstant") == 0)
1565 &(local_args_info.latticeConstant_given), optarg, 0, 0, ARG_DOUBLE,
1566 check_ambiguity,
override, 0, 0,
1567 "latticeConstant",
'-',
1573 else if (strcmp (long_options[option_index].name,
"radius") == 0)
1577 if (update_arg( (
void *)&(args_info->
radius_arg),
1579 &(local_args_info.radius_given), optarg, 0, 0, ARG_DOUBLE,
1580 check_ambiguity,
override, 0, 0,
1587 else if (strcmp (long_options[option_index].name,
"length") == 0)
1591 if (update_arg( (
void *)&(args_info->
length_arg),
1593 &(local_args_info.length_given), optarg, 0, 0, ARG_DOUBLE,
1594 check_ambiguity,
override, 0, 0,
1601 else if (strcmp (long_options[option_index].name,
"shellRadius") == 0)
1604 if (update_multiple_arg_temp(&shellRadius_list,
1605 &(local_args_info.shellRadius_given), optarg, 0, 0, ARG_DOUBLE,
1612 else if (strcmp (long_options[option_index].name,
"molFraction") == 0)
1615 if (update_multiple_arg_temp(&molFraction_list,
1616 &(local_args_info.molFraction_given), optarg, 0, 0, ARG_DOUBLE,
1623 else if (strcmp (long_options[option_index].name,
"vacancyPercent") == 0)
1629 &(local_args_info.vacancyPercent_given), optarg, 0, 0, ARG_DOUBLE,
1630 check_ambiguity,
override, 0, 0,
1631 "vacancyPercent",
'-',
1637 else if (strcmp (long_options[option_index].name,
"vacancyInnerRadius") == 0)
1643 &(local_args_info.vacancyInnerRadius_given), optarg, 0, 0, ARG_DOUBLE,
1644 check_ambiguity,
override, 0, 0,
1645 "vacancyInnerRadius",
'-',
1651 else if (strcmp (long_options[option_index].name,
"vacancyOuterRadius") == 0)
1657 &(local_args_info.vacancyOuterRadius_given), optarg, 0, 0, ARG_DOUBLE,
1658 check_ambiguity,
override, 0, 0,
1659 "vacancyOuterRadius",
'-',
1671 fprintf (stderr,
"%s: option unknown: %c%s\n",
CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error :
""));
1679 local_args_info.shellRadius_given, 0,
1680 ARG_DOUBLE, shellRadius_list);
1683 local_args_info.molFraction_given, 0,
1684 ARG_DOUBLE, molFraction_list);
1687 local_args_info.shellRadius_given = 0;
1689 local_args_info.molFraction_given = 0;
1693 error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error);
1696 cmdline_parser_release (&local_args_info);
1698 if ( error_occurred )
1699 return (EXIT_FAILURE);
1704 int found_prog_name = 0;
1710 args_info->
inputs_num = argc - optind - found_prog_name;
1712 (
char **)(malloc ((args_info->
inputs_num)*
sizeof(
char *))) ;
1713 while (optind < argc)
1714 args_info->
inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1720 free_list (shellRadius_list, 0 );
1721 free_list (molFraction_list, 0 );
1723 cmdline_parser_release (&local_args_info);
1724 return (EXIT_FAILURE);
1727#ifndef CONFIG_FILE_LINE_SIZE
1728#define CONFIG_FILE_LINE_SIZE 2048
1730#define ADDITIONAL_ERROR " in configuration file "
1732#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1736_cmdline_parser_configfile (
const char *filename,
int *my_argc)
1739 char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
1740 char linebuf[CONFIG_FILE_LINE_SIZE];
1742 int result = 0,
equal;
1745 size_t len, next_token;
1748 if ((file = fopen(filename,
"r")) == 0)
1750 fprintf (stderr,
"%s: Error opening configuration file '%s'\n",
1752 return EXIT_FAILURE;
1755 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0)
1759 len = strlen(linebuf);
1760 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
1762 fprintf (stderr,
"%s:%s:%d: Line too long in configuration file\n",
1764 result = EXIT_FAILURE;
1769 next_token = strspn (linebuf,
" \t\r\n");
1770 str_index = linebuf + next_token;
1772 if ( str_index[0] ==
'\0' || str_index[0] ==
'#')
1778 next_token = strcspn (fopt,
" \t\r\n=");
1780 if (fopt[next_token] ==
'\0')
1788 equal = (fopt[next_token] ==
'=');
1789 fopt[next_token++] =
'\0';
1792 next_token += strspn (fopt + next_token,
" \t\r\n");
1796 if ((equal = (fopt[next_token] ==
'=')))
1799 next_token += strspn (fopt + next_token,
" \t\r\n");
1801 str_index += next_token;
1805 if ( farg[0] ==
'\"' || farg[0] ==
'\'' )
1807 str_index = strchr (++farg, str_index[0] );
1812 "%s:%s:%d: unterminated string in configuration file\n",
1814 result = EXIT_FAILURE;
1820 next_token = strcspn (farg,
" \t\r\n#\'\"");
1821 str_index += next_token;
1825 delimiter = *str_index, *str_index++ =
'\0';
1828 if (delimiter !=
'\0' && delimiter !=
'#')
1830 str_index += strspn(str_index,
" \t\r\n");
1831 if (*str_index !=
'\0' && *str_index !=
'#')
1835 "%s:%s:%d: malformed string in configuration file\n",
1837 result = EXIT_FAILURE;
1843 if (!strcmp(fopt,
"include")) {
1844 if (farg && *farg) {
1845 result = _cmdline_parser_configfile(farg, my_argc);
1847 fprintf(stderr,
"%s:%s:%d: include requires a filename argument.\n",
1853 strcat (my_argv, len > 1 ?
"--" :
"-");
1854 strcat (my_argv, fopt);
1855 if (len > 1 && ((farg && *farg) || equal))
1856 strcat (my_argv,
"=");
1858 strcat (my_argv, farg);
1861 cmd_line_list_tmp = (
struct line_list *) malloc (
sizeof (
struct line_list));
1862 cmd_line_list_tmp->next = cmd_line_list;
1863 cmd_line_list = cmd_line_list_tmp;
1864 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
1873cmdline_parser_configfile (
1874 const char *filename,
1876 int override,
int initialize,
int check_required)
1886 return cmdline_parser_config_file (filename, args_info, ¶ms);
1890cmdline_parser_config_file (
const char *filename,
1897 char *additional_error;
1900 cmd_line_list_tmp = (
struct line_list *) malloc (
sizeof (
struct line_list));
1901 cmd_line_list_tmp->next = cmd_line_list;
1902 cmd_line_list = cmd_line_list_tmp;
1905 result = _cmdline_parser_configfile(filename, &my_argc);
1907 if (result != EXIT_FAILURE) {
1908 my_argv_arg = (
char **) malloc((my_argc+1) *
sizeof(
char *));
1909 cmd_line_list_tmp = cmd_line_list;
1911 for (i = my_argc - 1; i >= 0; --i) {
1912 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
1913 cmd_line_list_tmp = cmd_line_list_tmp->next;
1916 my_argv_arg[my_argc] = 0;
1918 additional_error = (
char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
1919 strcpy (additional_error, ADDITIONAL_ERROR);
1920 strcat (additional_error, filename);
1922 cmdline_parser_internal (my_argc, my_argv_arg, args_info,
1926 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.
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.
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.
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.