21#define FIX_UNUSED(X) (void) (X)
27const char *gengetopt_args_info_purpose =
"Builds spherical random or core-shell nanoparticles and outputs an OpenMD\nstartup file";
29const char *gengetopt_args_info_usage =
"Usage: nanoparticleBuilder [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 Nanoparticle radius in Angstroms (mandatory)",
41 " --shellRadius=DOUBLE Radius containing within it only molecules of a\n specific component. Specified for each\n component > 1 in the template file.",
42 " --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.",
43 " --vacancyPercent=DOUBLE Percentage of atoms to remove from within\n vacancy range",
44 " --vacancyInnerRadius=DOUBLE\n Radius arround core-shell where vacancies\n should be located.",
45 " --vacancyOuterRadius=DOUBLE\n Radius arround core-shell where vacancies\n should be located.",
52} cmdline_parser_arg_type;
64cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error);
68 struct line_list * next;
71static struct line_list *cmd_line_list = 0;
72static struct line_list *cmd_line_list_tmp = 0;
80 while (cmd_line_list) {
81 cmd_line_list_tmp = cmd_line_list;
82 cmd_line_list = cmd_line_list->next;
83 free (cmd_line_list_tmp->string_arg);
84 free (cmd_line_list_tmp);
91gengetopt_strdup (
const char *s);
111 FIX_UNUSED (args_info);
131 args_info->
help_help = gengetopt_args_info_help[0] ;
133 args_info->
output_help = gengetopt_args_info_help[2] ;
135 args_info->
radius_help = gengetopt_args_info_help[4] ;
149cmdline_parser_print_version (
void)
155 if (strlen(gengetopt_args_info_versiontext) > 0)
156 printf(
"\n%s\n", gengetopt_args_info_versiontext);
159static void print_help_common(
void) {
160 cmdline_parser_print_version ();
162 if (strlen(gengetopt_args_info_purpose) > 0)
163 printf(
"\n%s\n", gengetopt_args_info_purpose);
165 if (strlen(gengetopt_args_info_usage) > 0)
166 printf(
"\n%s\n", gengetopt_args_info_usage);
170 if (strlen(gengetopt_args_info_description) > 0)
171 printf(
"%s\n\n", gengetopt_args_info_description);
175cmdline_parser_print_help (
void)
179 while (gengetopt_args_info_help[i])
180 printf(
"%s\n", gengetopt_args_info_help[i++]);
186 clear_given (args_info);
187 clear_args (args_info);
188 init_args_info (args_info);
217free_string_field (
char **s)
230 const char *default_string_arg;
236 union generic_value arg;
238 struct generic_list *next;
244static void add_node(
struct generic_list **list) {
245 struct generic_list *new_node = (
struct generic_list *) malloc (
sizeof (
struct generic_list));
246 new_node->next = *list;
248 new_node->arg.string_arg = 0;
256free_multiple_field(
unsigned int len,
void *arg,
char ***orig)
260 for (i = 0; i < len; ++i)
262 free_string_field(&((*orig)[i]));
290 free (args_info->
inputs [i]);
295 clear_given (args_info);
300write_into_file(FILE *outfile,
const char *opt,
const char *arg,
const char *values[])
304 fprintf(outfile,
"%s=\"%s\"\n", opt, arg);
306 fprintf(outfile,
"%s\n", opt);
311write_multiple_into_file(FILE *outfile,
int len,
const char *opt,
char **arg,
const char *values[])
315 for (i = 0; i < len; ++i)
316 write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
331 write_into_file(outfile,
"help", 0, 0 );
333 write_into_file(outfile,
"version", 0, 0 );
335 write_into_file(outfile,
"output", args_info->
output_orig, 0);
339 write_into_file(outfile,
"radius", args_info->
radius_orig, 0);
360 outfile = fopen(filename,
"w");
368 i = cmdline_parser_dump(outfile, args_info);
377 cmdline_parser_release (args_info);
382gengetopt_strdup (
const char *s)
388 result = (
char*)malloc(strlen(s) + 1);
389 if (result == (
char*)0)
396get_multiple_arg_token(
const char *arg)
400 size_t len, num_of_escape, i, j;
405 tok = strchr (arg,
',');
411 if (*(tok-1) ==
'\\')
414 tok = strchr (tok+1,
',');
422 len = (size_t)(tok - arg + 1);
424 len = strlen (arg) + 1;
426 len -= num_of_escape;
428 ret = (
char *) malloc (len);
432 while (arg[i] && (j < len-1))
434 if (arg[i] ==
'\\' &&
448get_multiple_arg_token_next(
const char *arg)
455 tok = strchr (arg,
',');
460 if (*(tok-1) ==
'\\')
463 tok = strchr (tok+1,
',');
469 if (! tok || strlen(tok) == 1)
476check_multiple_option_occurrences(
const char *prog_name,
unsigned int option_given,
unsigned int min,
unsigned int max,
const char *option_desc);
479check_multiple_option_occurrences(
const char *prog_name,
unsigned int option_given,
unsigned int min,
unsigned int max,
const char *option_desc)
481 int error_occurred = 0;
483 if (option_given && (min > 0 || max > 0))
485 if (min > 0 && max > 0)
490 if (option_given != (
unsigned int) min)
492 fprintf (stderr,
"%s: %s option occurrences must be %d\n",
493 prog_name, option_desc, min);
497 else if (option_given < (
unsigned int) min
498 || option_given > (
unsigned int) max)
501 fprintf (stderr,
"%s: %s option occurrences must be between %d and %d\n",
502 prog_name, option_desc, min, max);
509 if (option_given < min)
511 fprintf (stderr,
"%s: %s option occurrences must be at least %d\n",
512 prog_name, option_desc, min);
519 if (option_given > max)
521 fprintf (stderr,
"%s: %s option occurrences must be at most %d\n",
522 prog_name, option_desc, max);
528 return error_occurred;
533 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
541 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
547cmdline_parser2 (
int argc,
char **argv,
struct gengetopt_args_info *args_info,
int override,
int initialize,
int check_required)
558 result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
566 int result = EXIT_SUCCESS;
568 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
569 result = EXIT_FAILURE;
575cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error)
577 int error_occurred = 0;
578 FIX_UNUSED (additional_error);
583 fprintf (stderr,
"%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error :
""));
589 fprintf (stderr,
"%s: '--latticeConstant' option required%s\n", prog_name, (additional_error ? additional_error :
""));
595 fprintf (stderr,
"%s: '--radius' option required%s\n", prog_name, (additional_error ? additional_error :
""));
608 return error_occurred;
666#ifndef required_argument
667#define required_argument 1
670#ifndef optional_argument
671#define optional_argument 2
674struct custom_getopt_data {
716static char *custom_optarg;
733static int custom_optind = 1;
739static int custom_opterr = 1;
745static int custom_optopt =
'?';
755static void exchange(
char **argv,
struct custom_getopt_data *d)
757 int bottom = d->first_nonopt;
758 int middle = d->last_nonopt;
759 int top = d->custom_optind;
768 while (top > middle && middle > bottom) {
769 if (top - middle > middle - bottom) {
771 int len = middle - bottom;
775 for (i = 0; i < len; i++) {
776 tem = argv[bottom + i];
778 argv[top - (middle - bottom) + i];
779 argv[top - (middle - bottom) + i] = tem;
785 int len = top - middle;
789 for (i = 0; i < len; i++) {
790 tem = argv[bottom + i];
791 argv[bottom + i] = argv[middle + i];
792 argv[middle + i] = tem;
799 d->first_nonopt += (d->custom_optind - d->last_nonopt);
800 d->last_nonopt = d->custom_optind;
804static void custom_getopt_initialize(
struct custom_getopt_data *d)
811 d->first_nonopt = d->last_nonopt = d->custom_optind;
816#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
819static int shuffle_argv(
int argc,
char *
const *argv,
const struct option *longopts,
820 struct custom_getopt_data *d)
826 if (d->last_nonopt > d->custom_optind)
827 d->last_nonopt = d->custom_optind;
828 if (d->first_nonopt > d->custom_optind)
829 d->first_nonopt = d->custom_optind;
834 if (d->first_nonopt != d->last_nonopt &&
835 d->last_nonopt != d->custom_optind)
836 exchange((
char **) argv, d);
837 else if (d->last_nonopt != d->custom_optind)
838 d->first_nonopt = d->custom_optind;
843 while (d->custom_optind < argc && NONOPTION_P)
845 d->last_nonopt = d->custom_optind;
851 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind],
"--")) {
853 if (d->first_nonopt != d->last_nonopt
854 && d->last_nonopt != d->custom_optind)
855 exchange((
char **) argv, d);
856 else if (d->first_nonopt == d->last_nonopt)
857 d->first_nonopt = d->custom_optind;
858 d->last_nonopt = argc;
859 d->custom_optind = argc;
865 if (d->custom_optind == argc) {
870 if (d->first_nonopt != d->last_nonopt)
871 d->custom_optind = d->first_nonopt;
879 d->custom_optarg = argv[d->custom_optind++];
886 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] ==
'-'));
900static int check_long_opt(
int argc,
char *
const *argv,
const char *optstring,
901 const struct option *longopts,
int *longind,
902 int print_errors,
struct custom_getopt_data *d)
905 const struct option *p;
906 const struct option *pfound = NULL;
912 for (nameend = d->nextchar; *nameend && *nameend !=
'='; nameend++)
916 for (p = longopts, option_index = 0; p->name; p++, option_index++)
917 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
918 if ((
unsigned int) (nameend - d->nextchar)
919 == (
unsigned int) strlen(p->name)) {
922 indfound = option_index;
925 }
else if (pfound == NULL) {
928 indfound = option_index;
929 }
else if (pfound->has_arg != p->has_arg
930 || pfound->flag != p->flag
931 || pfound->val != p->val)
935 if (ambig && !exact) {
938 "%s: option `%s' is ambiguous\n",
939 argv[0], argv[d->custom_optind]);
941 d->nextchar += strlen(d->nextchar);
943 d->custom_optopt = 0;
947 option_index = indfound;
950 if (pfound->has_arg != no_argument)
951 d->custom_optarg = nameend + 1;
954 if (argv[d->custom_optind - 1][1] ==
'-') {
956 fprintf(stderr,
"%s: option `--%s' doesn't allow an argument\n",
957 argv[0], pfound->name);
960 fprintf(stderr,
"%s: option `%c%s' doesn't allow an argument\n",
961 argv[0], argv[d->custom_optind - 1][0], pfound->name);
965 d->nextchar += strlen(d->nextchar);
966 d->custom_optopt = pfound->val;
969 }
else if (pfound->has_arg == required_argument) {
970 if (d->custom_optind < argc)
971 d->custom_optarg = argv[d->custom_optind++];
975 "%s: option `%s' requires an argument\n",
977 argv[d->custom_optind - 1]);
979 d->nextchar += strlen(d->nextchar);
980 d->custom_optopt = pfound->val;
981 return optstring[0] ==
':' ?
':' :
'?';
984 d->nextchar += strlen(d->nextchar);
986 *longind = option_index;
988 *(pfound->flag) = pfound->val;
999 if (argv[d->custom_optind][1] ==
'-') {
1002 "%s: unrecognized option `--%s'\n",
1003 argv[0], d->nextchar);
1007 "%s: unrecognized option `%c%s'\n",
1008 argv[0], argv[d->custom_optind][0],
1012 d->nextchar = (
char *)
"";
1014 d->custom_optopt = 0;
1018static int check_short_opt(
int argc,
char *
const *argv,
const char *optstring,
1019 int print_errors,
struct custom_getopt_data *d)
1021 char c = *d->nextchar++;
1022 const char *temp = strchr(optstring, c);
1025 if (*d->nextchar ==
'\0')
1027 if (!temp || c ==
':') {
1029 fprintf(stderr,
"%s: invalid option -- %c\n", argv[0], c);
1031 d->custom_optopt = c;
1034 if (temp[1] ==
':') {
1035 if (temp[2] ==
':') {
1037 if (*d->nextchar !=
'\0') {
1038 d->custom_optarg = d->nextchar;
1041 d->custom_optarg = NULL;
1045 if (*d->nextchar !=
'\0') {
1046 d->custom_optarg = d->nextchar;
1053 }
else if (d->custom_optind == argc) {
1056 "%s: option requires an argument -- %c\n",
1059 d->custom_optopt = c;
1060 if (optstring[0] ==
':')
1070 d->custom_optarg = argv[d->custom_optind++];
1147static int getopt_internal_r(
int argc,
char *
const *argv,
const char *optstring,
1148 const struct option *longopts,
int *longind,
1149 struct custom_getopt_data *d)
1151 int ret, print_errors = d->custom_opterr;
1153 if (optstring[0] ==
':')
1157 d->custom_optarg = NULL;
1163 if (d->custom_optind == 0 || !d->initialized) {
1164 if (d->custom_optind == 0)
1165 d->custom_optind = 1;
1166 custom_getopt_initialize(d);
1168 if (d->nextchar == NULL || *d->nextchar ==
'\0') {
1169 ret = shuffle_argv(argc, argv, longopts, d);
1173 if (longopts && (argv[d->custom_optind][1] ==
'-' ))
1174 return check_long_opt(argc, argv, optstring, longopts,
1175 longind, print_errors, d);
1176 return check_short_opt(argc, argv, optstring, print_errors, d);
1179static int custom_getopt_internal(
int argc,
char *
const *argv,
const char *optstring,
1180 const struct option *longopts,
int *longind)
1184 static struct custom_getopt_data d;
1186 d.custom_optind = custom_optind;
1187 d.custom_opterr = custom_opterr;
1188 result = getopt_internal_r(argc, argv, optstring, longopts,
1190 custom_optind = d.custom_optind;
1191 custom_optarg = d.custom_optarg;
1192 custom_optopt = d.custom_optopt;
1196static int custom_getopt_long (
int argc,
char *
const *argv,
const char *options,
1197 const struct option *long_options,
int *opt_index)
1199 return custom_getopt_internal(argc, argv, options, long_options,
1204static char *package_name = 0;
1225int update_arg(
void *field,
char **orig_field,
1226 unsigned int *field_given,
unsigned int *prev_given,
1227 char *value,
const char *possible_values[],
1228 const char *default_value,
1229 cmdline_parser_arg_type arg_type,
1230 int check_ambiguity,
int override,
1231 int no_free,
int multiple_option,
1232 const char *long_opt,
char short_opt,
1233 const char *additional_error)
1235 char *stop_char = 0;
1236 const char *val = value;
1238 char **string_field;
1244 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1246 if (short_opt !=
'-')
1247 fprintf (stderr,
"%s: `--%s' (`-%c') option given more than once%s\n",
1248 package_name, long_opt, short_opt,
1249 (additional_error ? additional_error :
""));
1251 fprintf (stderr,
"%s: `--%s' option given more than once%s\n",
1252 package_name, long_opt,
1253 (additional_error ? additional_error :
""));
1257 FIX_UNUSED (default_value);
1259 if (field_given && *field_given && !
override)
1265 if (possible_values)
1266 val = possible_values[found];
1270 if (val) *((
double *)field) = strtod (val, &stop_char);
1274 string_field = (
char **)field;
1275 if (!no_free && *string_field)
1276 free (*string_field);
1277 *string_field = gengetopt_strdup (val);
1287 if (val && !(stop_char && *stop_char ==
'\0')) {
1288 fprintf(stderr,
"%s: invalid numeric value: %s\n", package_name, val);
1301 if (value && orig_field) {
1303 *orig_field = value;
1307 *orig_field = gengetopt_strdup (value);
1320int update_multiple_arg_temp(
struct generic_list **list,
1321 unsigned int *prev_given,
const char *val,
1322 const char *possible_values[],
const char *default_value,
1323 cmdline_parser_arg_type arg_type,
1324 const char *long_opt,
char short_opt,
1325 const char *additional_error)
1329 const char *multi_next;
1331 if (arg_type == ARG_NO) {
1336 multi_token = get_multiple_arg_token(val);
1337 multi_next = get_multiple_arg_token_next (val);
1342 if (update_arg((
void *)&((*list)->arg), &((*list)->orig), 0,
1343 prev_given, multi_token, possible_values, default_value,
1344 arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
1345 if (multi_token) free(multi_token);
1351 multi_token = get_multiple_arg_token(multi_next);
1352 multi_next = get_multiple_arg_token_next (multi_next);
1365void free_list(
struct generic_list *list,
short string_arg)
1368 struct generic_list *tmp;
1372 if (string_arg && list->arg.string_arg)
1373 free (list->arg.string_arg);
1386void update_multiple_arg(
void *field,
char ***orig_field,
1387 unsigned int field_given,
unsigned int prev_given,
union generic_value *default_value,
1388 cmdline_parser_arg_type arg_type,
1389 struct generic_list *list)
1392 struct generic_list *tmp;
1394 if (prev_given && list) {
1395 *orig_field = (
char **) realloc (*orig_field, (field_given + prev_given) *
sizeof (
char *));
1399 *((
double **)field) = (
double *)realloc (*((
double **)field), (field_given + prev_given) *
sizeof (double));
break;
1401 *((
char ***)field) = (
char **)realloc (*((
char ***)field), (field_given + prev_given) *
sizeof (
char *));
break;
1406 for (i = (prev_given - 1); i >= 0; --i)
1412 (*((
double **)field))[i + field_given] = tmp->arg.double_arg;
break;
1414 (*((
char ***)field))[i + field_given] = tmp->arg.string_arg;
break;
1418 (*orig_field) [i + field_given] = list->orig;
1423 if (default_value && ! field_given) {
1426 if (! *((
double **)field)) {
1427 *((
double **)field) = (
double *)malloc (
sizeof (
double));
1428 (*((
double **)field))[0] = default_value->double_arg;
1432 if (! *((
char ***)field)) {
1433 *((
char ***)field) = (
char **)malloc (
sizeof (
char *));
1434 (*((
char ***)field))[0] = gengetopt_strdup(default_value->string_arg);
1439 if (!(*orig_field)) {
1440 *orig_field = (
char **) malloc (
sizeof (
char *));
1441 (*orig_field)[0] = 0;
1448cmdline_parser_internal (
1454 struct generic_list * shellRadius_list = NULL;
1455 struct generic_list * molFraction_list = NULL;
1456 int error_occurred = 0;
1462 int check_ambiguity;
1469 package_name = argv[0];
1488 int option_index = 0;
1490 static struct option long_options[] = {
1491 {
"help", 0, NULL,
'h' },
1492 {
"version", 0, NULL,
'V' },
1493 {
"output", 1, NULL,
'o' },
1494 {
"latticeConstant", 1, NULL, 0 },
1495 {
"radius", 1, NULL, 0 },
1496 {
"shellRadius", 1, NULL, 0 },
1497 {
"molFraction", 1, NULL, 0 },
1498 {
"vacancyPercent", 1, NULL, 0 },
1499 {
"vacancyInnerRadius", 1, NULL, 0 },
1500 {
"vacancyOuterRadius", 1, NULL, 0 },
1504 custom_optarg = optarg;
1505 custom_optind = optind;
1506 custom_opterr = opterr;
1507 custom_optopt = optopt;
1509 c = custom_getopt_long (argc, argv,
"hVo:", long_options, &option_index);
1511 optarg = custom_optarg;
1512 optind = custom_optind;
1513 opterr = custom_opterr;
1514 optopt = custom_optopt;
1521 cmdline_parser_print_help ();
1522 cmdline_parser_free (&local_args_info);
1523 exit (EXIT_SUCCESS);
1526 cmdline_parser_print_version ();
1527 cmdline_parser_free (&local_args_info);
1528 exit (EXIT_SUCCESS);
1533 if (update_arg( (
void *)&(args_info->
output_arg),
1535 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1536 check_ambiguity,
override, 0, 0,
1545 if (strcmp (long_options[option_index].name,
"latticeConstant") == 0)
1551 &(local_args_info.latticeConstant_given), optarg, 0, 0, ARG_DOUBLE,
1552 check_ambiguity,
override, 0, 0,
1553 "latticeConstant",
'-',
1559 else if (strcmp (long_options[option_index].name,
"radius") == 0)
1563 if (update_arg( (
void *)&(args_info->
radius_arg),
1565 &(local_args_info.radius_given), optarg, 0, 0, ARG_DOUBLE,
1566 check_ambiguity,
override, 0, 0,
1573 else if (strcmp (long_options[option_index].name,
"shellRadius") == 0)
1576 if (update_multiple_arg_temp(&shellRadius_list,
1577 &(local_args_info.shellRadius_given), optarg, 0, 0, ARG_DOUBLE,
1584 else if (strcmp (long_options[option_index].name,
"molFraction") == 0)
1587 if (update_multiple_arg_temp(&molFraction_list,
1588 &(local_args_info.molFraction_given), optarg, 0, 0, ARG_DOUBLE,
1595 else if (strcmp (long_options[option_index].name,
"vacancyPercent") == 0)
1601 &(local_args_info.vacancyPercent_given), optarg, 0, 0, ARG_DOUBLE,
1602 check_ambiguity,
override, 0, 0,
1603 "vacancyPercent",
'-',
1609 else if (strcmp (long_options[option_index].name,
"vacancyInnerRadius") == 0)
1615 &(local_args_info.vacancyInnerRadius_given), optarg, 0, 0, ARG_DOUBLE,
1616 check_ambiguity,
override, 0, 0,
1617 "vacancyInnerRadius",
'-',
1623 else if (strcmp (long_options[option_index].name,
"vacancyOuterRadius") == 0)
1629 &(local_args_info.vacancyOuterRadius_given), optarg, 0, 0, ARG_DOUBLE,
1630 check_ambiguity,
override, 0, 0,
1631 "vacancyOuterRadius",
'-',
1643 fprintf (stderr,
"%s: option unknown: %c%s\n",
CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error :
""));
1651 local_args_info.shellRadius_given, 0,
1652 ARG_DOUBLE, shellRadius_list);
1655 local_args_info.molFraction_given, 0,
1656 ARG_DOUBLE, molFraction_list);
1659 local_args_info.shellRadius_given = 0;
1661 local_args_info.molFraction_given = 0;
1665 error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error);
1668 cmdline_parser_release (&local_args_info);
1670 if ( error_occurred )
1671 return (EXIT_FAILURE);
1676 int found_prog_name = 0;
1682 args_info->
inputs_num = argc - optind - found_prog_name;
1684 (
char **)(malloc ((args_info->
inputs_num)*
sizeof(
char *))) ;
1685 while (optind < argc)
1686 args_info->
inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1692 free_list (shellRadius_list, 0 );
1693 free_list (molFraction_list, 0 );
1695 cmdline_parser_release (&local_args_info);
1696 return (EXIT_FAILURE);
1699#ifndef CONFIG_FILE_LINE_SIZE
1700#define CONFIG_FILE_LINE_SIZE 2048
1702#define ADDITIONAL_ERROR " in configuration file "
1704#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1708_cmdline_parser_configfile (
const char *filename,
int *my_argc)
1711 char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
1712 char linebuf[CONFIG_FILE_LINE_SIZE];
1714 int result = 0,
equal;
1717 size_t len, next_token;
1720 if ((file = fopen(filename,
"r")) == 0)
1722 fprintf (stderr,
"%s: Error opening configuration file '%s'\n",
1724 return EXIT_FAILURE;
1727 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0)
1731 len = strlen(linebuf);
1732 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
1734 fprintf (stderr,
"%s:%s:%d: Line too long in configuration file\n",
1736 result = EXIT_FAILURE;
1741 next_token = strspn (linebuf,
" \t\r\n");
1742 str_index = linebuf + next_token;
1744 if ( str_index[0] ==
'\0' || str_index[0] ==
'#')
1750 next_token = strcspn (fopt,
" \t\r\n=");
1752 if (fopt[next_token] ==
'\0')
1760 equal = (fopt[next_token] ==
'=');
1761 fopt[next_token++] =
'\0';
1764 next_token += strspn (fopt + next_token,
" \t\r\n");
1768 if ((equal = (fopt[next_token] ==
'=')))
1771 next_token += strspn (fopt + next_token,
" \t\r\n");
1773 str_index += next_token;
1777 if ( farg[0] ==
'\"' || farg[0] ==
'\'' )
1779 str_index = strchr (++farg, str_index[0] );
1784 "%s:%s:%d: unterminated string in configuration file\n",
1786 result = EXIT_FAILURE;
1792 next_token = strcspn (farg,
" \t\r\n#\'\"");
1793 str_index += next_token;
1797 delimiter = *str_index, *str_index++ =
'\0';
1800 if (delimiter !=
'\0' && delimiter !=
'#')
1802 str_index += strspn(str_index,
" \t\r\n");
1803 if (*str_index !=
'\0' && *str_index !=
'#')
1807 "%s:%s:%d: malformed string in configuration file\n",
1809 result = EXIT_FAILURE;
1815 if (!strcmp(fopt,
"include")) {
1816 if (farg && *farg) {
1817 result = _cmdline_parser_configfile(farg, my_argc);
1819 fprintf(stderr,
"%s:%s:%d: include requires a filename argument.\n",
1825 strcat (my_argv, len > 1 ?
"--" :
"-");
1826 strcat (my_argv, fopt);
1827 if (len > 1 && ((farg && *farg) || equal))
1828 strcat (my_argv,
"=");
1830 strcat (my_argv, farg);
1833 cmd_line_list_tmp = (
struct line_list *) malloc (
sizeof (
struct line_list));
1834 cmd_line_list_tmp->next = cmd_line_list;
1835 cmd_line_list = cmd_line_list_tmp;
1836 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
1845cmdline_parser_configfile (
1846 const char *filename,
1848 int override,
int initialize,
int check_required)
1858 return cmdline_parser_config_file (filename, args_info, ¶ms);
1862cmdline_parser_config_file (
const char *filename,
1869 char *additional_error;
1872 cmd_line_list_tmp = (
struct line_list *) malloc (
sizeof (
struct line_list));
1873 cmd_line_list_tmp->next = cmd_line_list;
1874 cmd_line_list = cmd_line_list_tmp;
1877 result = _cmdline_parser_configfile(filename, &my_argc);
1879 if (result != EXIT_FAILURE) {
1880 my_argv_arg = (
char **) malloc((my_argc+1) *
sizeof(
char *));
1881 cmd_line_list_tmp = cmd_line_list;
1883 for (i = my_argc - 1; i >= 0; --i) {
1884 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
1885 cmd_line_list_tmp = cmd_line_list_tmp->next;
1888 my_argv_arg[my_argc] = 0;
1890 additional_error = (
char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
1891 strcpy (additional_error, ADDITIONAL_ERROR);
1892 strcat (additional_error, filename);
1894 cmdline_parser_internal (my_argc, my_argv_arg, args_info,
1898 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.
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 molFraction_max
Builds a multi-component random alloy nanoparticle.
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.
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.