21#define FIX_UNUSED(X) (void) (X)
27const char *gengetopt_args_info_purpose =
"Computes the general elastic constants that relate stress and strain for a\ngiven input configuration";
29const char *gengetopt_args_info_usage =
"Usage: elasticConstants [-h|--help] [-V|--version] [-iSTRING|--input=STRING]\n [-b|--box] [-mSTRING|--method=STRING] [-nINT|--npoints=INT]\n [-dDOUBLE|--delta=DOUBLE] [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 " -i, --input=STRING Input file name",
39 " -b, --box Optimize box geometry before performing calculation\n (default=off)",
40 " -m, --method=STRING Calculation Method (possible values=\"energy\",\n \"stress\")",
41 " -n, --npoints=INT number of points for fitting\n stress-strain relationship (default=`25')",
42 " -d, --delta=DOUBLE size of relative volume changes for strains",
51} cmdline_parser_arg_type;
63const char *cmdline_parser_method_values[] = {
"energy",
"stress", 0};
66gengetopt_strdup (
const char *s);
83 FIX_UNUSED (args_info);
100 args_info->
help_help = gengetopt_args_info_help[0] ;
102 args_info->
input_help = gengetopt_args_info_help[2] ;
103 args_info->
box_help = gengetopt_args_info_help[3] ;
104 args_info->
method_help = gengetopt_args_info_help[4] ;
106 args_info->
delta_help = gengetopt_args_info_help[6] ;
111cmdline_parser_print_version (
void)
117 if (strlen(gengetopt_args_info_versiontext) > 0)
118 printf(
"\n%s\n", gengetopt_args_info_versiontext);
121static void print_help_common(
void) {
122 cmdline_parser_print_version ();
124 if (strlen(gengetopt_args_info_purpose) > 0)
125 printf(
"\n%s\n", gengetopt_args_info_purpose);
127 if (strlen(gengetopt_args_info_usage) > 0)
128 printf(
"\n%s\n", gengetopt_args_info_usage);
132 if (strlen(gengetopt_args_info_description) > 0)
133 printf(
"%s\n\n", gengetopt_args_info_description);
137cmdline_parser_print_help (
void)
141 while (gengetopt_args_info_help[i])
142 printf(
"%s\n", gengetopt_args_info_help[i++]);
148 clear_given (args_info);
149 clear_args (args_info);
150 init_args_info (args_info);
179free_string_field (
char **s)
193 free_string_field (&(args_info->
input_arg));
202 free (args_info->
inputs [i]);
207 clear_given (args_info);
218check_possible_values(
const char *val,
const char *values[])
228 for (i = 0, len = strlen(val); values[i]; ++i)
230 if (strncmp(val, values[i], len) == 0)
234 if (strlen(values[i]) == len)
242 return (found ? -2 : -1);
247write_into_file(FILE *outfile,
const char *opt,
const char *arg,
const char *values[])
252 found = check_possible_values(arg, values);
255 fprintf(outfile,
"%s=\"%s\" # %s\n", opt, arg, values[found]);
257 fprintf(outfile,
"%s=\"%s\"\n", opt, arg);
259 fprintf(outfile,
"%s\n", opt);
276 write_into_file(outfile,
"help", 0, 0 );
278 write_into_file(outfile,
"version", 0, 0 );
280 write_into_file(outfile,
"input", args_info->
input_orig, 0);
282 write_into_file(outfile,
"box", 0, 0 );
284 write_into_file(outfile,
"method", args_info->
method_orig, cmdline_parser_method_values);
286 write_into_file(outfile,
"npoints", args_info->
npoints_orig, 0);
288 write_into_file(outfile,
"delta", args_info->
delta_orig, 0);
301 outfile = fopen(filename,
"w");
318 cmdline_parser_release (args_info);
323gengetopt_strdup (
const char *s)
329 result = (
char*)malloc(strlen(s) + 1);
330 if (result == (
char*)0)
347 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
349 if (result == EXIT_FAILURE)
370 result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
372 if (result == EXIT_FAILURE)
384 FIX_UNUSED (args_info);
385 FIX_UNUSED (prog_name);
444#ifndef required_argument
445#define required_argument 1
448#ifndef optional_argument
449#define optional_argument 2
452struct custom_getopt_data {
494static char *custom_optarg;
511static int custom_optind = 1;
517static int custom_opterr = 1;
523static int custom_optopt =
'?';
533static void exchange(
char **argv,
struct custom_getopt_data *d)
535 int bottom = d->first_nonopt;
536 int middle = d->last_nonopt;
537 int top = d->custom_optind;
546 while (top > middle && middle > bottom) {
547 if (top - middle > middle - bottom) {
549 int len = middle - bottom;
553 for (i = 0; i < len; i++) {
554 tem = argv[bottom + i];
556 argv[top - (middle - bottom) + i];
557 argv[top - (middle - bottom) + i] = tem;
563 int len = top - middle;
567 for (i = 0; i < len; i++) {
568 tem = argv[bottom + i];
569 argv[bottom + i] = argv[middle + i];
570 argv[middle + i] = tem;
577 d->first_nonopt += (d->custom_optind - d->last_nonopt);
578 d->last_nonopt = d->custom_optind;
582static void custom_getopt_initialize(
struct custom_getopt_data *d)
589 d->first_nonopt = d->last_nonopt = d->custom_optind;
594#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
597static int shuffle_argv(
int argc,
char *
const *argv,
const struct option *longopts,
598 struct custom_getopt_data *d)
604 if (d->last_nonopt > d->custom_optind)
605 d->last_nonopt = d->custom_optind;
606 if (d->first_nonopt > d->custom_optind)
607 d->first_nonopt = d->custom_optind;
612 if (d->first_nonopt != d->last_nonopt &&
613 d->last_nonopt != d->custom_optind)
614 exchange((
char **) argv, d);
615 else if (d->last_nonopt != d->custom_optind)
616 d->first_nonopt = d->custom_optind;
621 while (d->custom_optind < argc && NONOPTION_P)
623 d->last_nonopt = d->custom_optind;
629 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind],
"--")) {
631 if (d->first_nonopt != d->last_nonopt
632 && d->last_nonopt != d->custom_optind)
633 exchange((
char **) argv, d);
634 else if (d->first_nonopt == d->last_nonopt)
635 d->first_nonopt = d->custom_optind;
636 d->last_nonopt = argc;
637 d->custom_optind = argc;
643 if (d->custom_optind == argc) {
648 if (d->first_nonopt != d->last_nonopt)
649 d->custom_optind = d->first_nonopt;
657 d->custom_optarg = argv[d->custom_optind++];
664 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] ==
'-'));
678static int check_long_opt(
int argc,
char *
const *argv,
const char *optstring,
679 const struct option *longopts,
int *longind,
680 int print_errors,
struct custom_getopt_data *d)
683 const struct option *p;
684 const struct option *pfound = NULL;
690 for (nameend = d->nextchar; *nameend && *nameend !=
'='; nameend++)
694 for (p = longopts, option_index = 0; p->name; p++, option_index++)
695 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
696 if ((
unsigned int) (nameend - d->nextchar)
697 == (
unsigned int) strlen(p->name)) {
700 indfound = option_index;
703 }
else if (pfound == NULL) {
706 indfound = option_index;
707 }
else if (pfound->has_arg != p->has_arg
708 || pfound->flag != p->flag
709 || pfound->val != p->val)
713 if (ambig && !exact) {
716 "%s: option `%s' is ambiguous\n",
717 argv[0], argv[d->custom_optind]);
719 d->nextchar += strlen(d->nextchar);
721 d->custom_optopt = 0;
725 option_index = indfound;
728 if (pfound->has_arg != no_argument)
729 d->custom_optarg = nameend + 1;
732 if (argv[d->custom_optind - 1][1] ==
'-') {
734 fprintf(stderr,
"%s: option `--%s' doesn't allow an argument\n",
735 argv[0], pfound->name);
738 fprintf(stderr,
"%s: option `%c%s' doesn't allow an argument\n",
739 argv[0], argv[d->custom_optind - 1][0], pfound->name);
743 d->nextchar += strlen(d->nextchar);
744 d->custom_optopt = pfound->val;
747 }
else if (pfound->has_arg == required_argument) {
748 if (d->custom_optind < argc)
749 d->custom_optarg = argv[d->custom_optind++];
753 "%s: option `%s' requires an argument\n",
755 argv[d->custom_optind - 1]);
757 d->nextchar += strlen(d->nextchar);
758 d->custom_optopt = pfound->val;
759 return optstring[0] ==
':' ?
':' :
'?';
762 d->nextchar += strlen(d->nextchar);
764 *longind = option_index;
766 *(pfound->flag) = pfound->val;
777 if (argv[d->custom_optind][1] ==
'-') {
780 "%s: unrecognized option `--%s'\n",
781 argv[0], d->nextchar);
785 "%s: unrecognized option `%c%s'\n",
786 argv[0], argv[d->custom_optind][0],
790 d->nextchar = (
char *)
"";
792 d->custom_optopt = 0;
796static int check_short_opt(
int argc,
char *
const *argv,
const char *optstring,
797 int print_errors,
struct custom_getopt_data *d)
799 char c = *d->nextchar++;
800 const char *temp = strchr(optstring, c);
803 if (*d->nextchar ==
'\0')
805 if (!temp || c ==
':') {
807 fprintf(stderr,
"%s: invalid option -- %c\n", argv[0], c);
809 d->custom_optopt = c;
812 if (temp[1] ==
':') {
813 if (temp[2] ==
':') {
815 if (*d->nextchar !=
'\0') {
816 d->custom_optarg = d->nextchar;
819 d->custom_optarg = NULL;
823 if (*d->nextchar !=
'\0') {
824 d->custom_optarg = d->nextchar;
831 }
else if (d->custom_optind == argc) {
834 "%s: option requires an argument -- %c\n",
837 d->custom_optopt = c;
838 if (optstring[0] ==
':')
848 d->custom_optarg = argv[d->custom_optind++];
925static int getopt_internal_r(
int argc,
char *
const *argv,
const char *optstring,
926 const struct option *longopts,
int *longind,
927 struct custom_getopt_data *d)
929 int ret, print_errors = d->custom_opterr;
931 if (optstring[0] ==
':')
935 d->custom_optarg = NULL;
941 if (d->custom_optind == 0 || !d->initialized) {
942 if (d->custom_optind == 0)
943 d->custom_optind = 1;
944 custom_getopt_initialize(d);
946 if (d->nextchar == NULL || *d->nextchar ==
'\0') {
947 ret = shuffle_argv(argc, argv, longopts, d);
951 if (longopts && (argv[d->custom_optind][1] ==
'-' ))
952 return check_long_opt(argc, argv, optstring, longopts,
953 longind, print_errors, d);
954 return check_short_opt(argc, argv, optstring, print_errors, d);
957static int custom_getopt_internal(
int argc,
char *
const *argv,
const char *optstring,
958 const struct option *longopts,
int *longind)
962 static struct custom_getopt_data d;
964 d.custom_optind = custom_optind;
965 d.custom_opterr = custom_opterr;
966 result = getopt_internal_r(argc, argv, optstring, longopts,
968 custom_optind = d.custom_optind;
969 custom_optarg = d.custom_optarg;
970 custom_optopt = d.custom_optopt;
974static int custom_getopt_long (
int argc,
char *
const *argv,
const char *options,
975 const struct option *long_options,
int *opt_index)
977 return custom_getopt_internal(argc, argv, options, long_options,
982static char *package_name = 0;
1003int update_arg(
void *field,
char **orig_field,
1004 unsigned int *field_given,
unsigned int *prev_given,
1005 char *value,
const char *possible_values[],
1006 const char *default_value,
1007 cmdline_parser_arg_type arg_type,
1008 int check_ambiguity,
int override,
1009 int no_free,
int multiple_option,
1010 const char *long_opt,
char short_opt,
1011 const char *additional_error)
1013 char *stop_char = 0;
1014 const char *val = value;
1016 char **string_field;
1022 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1024 if (short_opt !=
'-')
1025 fprintf (stderr,
"%s: `--%s' (`-%c') option given more than once%s\n",
1026 package_name, long_opt, short_opt,
1027 (additional_error ? additional_error :
""));
1029 fprintf (stderr,
"%s: `--%s' option given more than once%s\n",
1030 package_name, long_opt,
1031 (additional_error ? additional_error :
""));
1035 if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0)
1037 if (short_opt !=
'-')
1038 fprintf (stderr,
"%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n",
1039 package_name, (found == -2) ?
"ambiguous" :
"invalid", value, long_opt, short_opt,
1040 (additional_error ? additional_error :
""));
1042 fprintf (stderr,
"%s: %s argument, \"%s\", for option `--%s'%s\n",
1043 package_name, (found == -2) ?
"ambiguous" :
"invalid", value, long_opt,
1044 (additional_error ? additional_error :
""));
1048 if (field_given && *field_given && !
override)
1054 if (possible_values)
1055 val = possible_values[found];
1059 *((
int *)field) = !*((
int *)field);
1062 if (val) *((
int *)field) = strtol (val, &stop_char, 0);
1065 if (val) *((
double *)field) = strtod (val, &stop_char);
1069 string_field = (
char **)field;
1070 if (!no_free && *string_field)
1071 free (*string_field);
1072 *string_field = gengetopt_strdup (val);
1083 if (val && !(stop_char && *stop_char ==
'\0')) {
1084 fprintf(stderr,
"%s: invalid numeric value: %s\n", package_name, val);
1098 if (value && orig_field) {
1100 *orig_field = value;
1104 *orig_field = gengetopt_strdup (value);
1114cmdline_parser_internal (
1120 int error_occurred = 0;
1126 int check_ambiguity;
1133 package_name = argv[0];
1138 FIX_UNUSED(check_required);
1153 int option_index = 0;
1155 static struct option long_options[] = {
1156 {
"help", 0, NULL,
'h' },
1157 {
"version", 0, NULL,
'V' },
1158 {
"input", 1, NULL,
'i' },
1159 {
"box", 0, NULL,
'b' },
1160 {
"method", 1, NULL,
'm' },
1161 {
"npoints", 1, NULL,
'n' },
1162 {
"delta", 1, NULL,
'd' },
1166 custom_optarg = optarg;
1167 custom_optind = optind;
1168 custom_opterr = opterr;
1169 custom_optopt = optopt;
1171 c = custom_getopt_long (argc, argv,
"hVi:bm:n:d:", long_options, &option_index);
1173 optarg = custom_optarg;
1174 optind = custom_optind;
1175 opterr = custom_opterr;
1176 optopt = custom_optopt;
1183 cmdline_parser_print_help ();
1184 cmdline_parser_free (&local_args_info);
1185 exit (EXIT_SUCCESS);
1188 cmdline_parser_print_version ();
1189 cmdline_parser_free (&local_args_info);
1190 exit (EXIT_SUCCESS);
1195 if (update_arg( (
void *)&(args_info->
input_arg),
1197 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1198 check_ambiguity,
override, 0, 0,
1208 &(local_args_info.box_given), optarg, 0, 0, ARG_FLAG,
1209 check_ambiguity,
override, 1, 0,
"box",
'b',
1217 if (update_arg( (
void *)&(args_info->
method_arg),
1219 &(local_args_info.method_given), optarg, cmdline_parser_method_values, 0, ARG_STRING,
1220 check_ambiguity,
override, 0, 0,
1230 if (update_arg( (
void *)&(args_info->
npoints_arg),
1232 &(local_args_info.npoints_given), optarg, 0,
"25", ARG_INT,
1233 check_ambiguity,
override, 0, 0,
1242 if (update_arg( (
void *)&(args_info->
delta_arg),
1244 &(local_args_info.delta_given), optarg, 0, 0, ARG_DOUBLE,
1245 check_ambiguity,
override, 0, 0,
1258 fprintf (stderr,
"%s: option unknown: %c%s\n",
CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error :
""));
1266 cmdline_parser_release (&local_args_info);
1268 if ( error_occurred )
1269 return (EXIT_FAILURE);
1274 int found_prog_name = 0;
1280 args_info->
inputs_num = argc - optind - found_prog_name;
1282 (
char **)(malloc ((args_info->
inputs_num)*
sizeof(
char *))) ;
1283 while (optind < argc)
1284 args_info->
inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1291 cmdline_parser_release (&local_args_info);
1292 return (EXIT_FAILURE);
#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)
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 npoints_given
Whether npoints was given.
char * npoints_orig
number of points for fitting stress-strain relationship original value given at command line.
unsigned inputs_num
unamed options number
unsigned int box_given
Whether box was given.
const char * help_help
Print help and exit help description.
char ** inputs
unamed options (options without names)
char * input_arg
input dump file.
unsigned int method_given
Whether method was given.
const char * method_help
Calculation Method help description.
int npoints_arg
number of points for fitting stress-strain relationship (default='25').
const char * delta_help
size of relative volume changes for strains help description.
char * delta_orig
size of relative volume changes for strains original value given at command line.
unsigned int delta_given
Whether delta was given.
double delta_arg
size of relative volume changes for strains.
char * method_orig
Calculation Method original value given at command line.
unsigned int help_given
Whether help was given.
int box_flag
Optimize box geometry before performing calculation (default=off).
unsigned int input_given
Whether input was given.
unsigned int version_given
Whether version was given.
const char * npoints_help
number of points for fitting stress-strain relationship help description.
const char * version_help
Print version and exit help description.
char * input_orig
input dump file original value given at command line.
const char * box_help
Optimize box geometry before performing calculation help description.
char * method_arg
Calculation Method.
const char * input_help
input dump file help description.
int cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
Save the contents of the option struct into an already open FILE stream.
int cmdline_parser(int argc, char **argv, struct gengetopt_args_info *args_info)
The command line parser.
int cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
Save the contents of the option struct into a (text) file.
int cmdline_parser2(int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
The command line parser (version with additional parameters - deprecated)
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...
int cmdline_parser_ext(int argc, char **argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params)
The command line parser (version with additional parameters)
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_free(struct gengetopt_args_info *args_info)
Deallocates the string fields of the gengetopt_args_info structure (but does not deallocate the struc...
void cmdline_parser_params_init(struct cmdline_parser_params *params)
Initializes all the fields a cmdline_parser_params structure to their default values.