21#define FIX_UNUSED(X) (void) (X)
27const char *gengetopt_args_info_purpose =
"This takes an OpenMD (.omd) file and generates equation of state for a \ncrystal. The periodic box is affine-scaled between starting and ending \nratios of the original box geometry, the energy is calculated at each \nscaled geometry, and the energy vs. scaling data is put into a\nspecified output file.\n\nExample:\n equationofstate -i Al2O3.omd -o Al2O3.eos -s 0.5 -e 1.5 -n 50";
29const char *gengetopt_args_info_usage =
"Usage: equationofstate [OPTION]... [FILE]...";
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=filename use specified input (.omd) file (mandatory)",
39 " -o, --output=filename use specified output file (mandatory)",
40 " -s, --start=DOUBLE starting affine scale (default=`0.8')",
41 " -e, --end=DOUBLE ending affine scale (default=`1.2')",
42 " -n, --number=INT number of data points (default=`50')",
50} cmdline_parser_arg_type;
62cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error);
65gengetopt_strdup (
const char *s);
82 FIX_UNUSED (args_info);
101 args_info->
help_help = gengetopt_args_info_help[0] ;
103 args_info->
input_help = gengetopt_args_info_help[2] ;
104 args_info->
output_help = gengetopt_args_info_help[3] ;
105 args_info->
start_help = gengetopt_args_info_help[4] ;
106 args_info->
end_help = gengetopt_args_info_help[5] ;
107 args_info->
number_help = gengetopt_args_info_help[6] ;
112cmdline_parser_print_version (
void)
118 if (strlen(gengetopt_args_info_versiontext) > 0)
119 printf(
"\n%s\n", gengetopt_args_info_versiontext);
122static void print_help_common(
void)
124 size_t len_purpose = strlen(gengetopt_args_info_purpose);
125 size_t len_usage = strlen(gengetopt_args_info_usage);
128 printf(
"%s\n", gengetopt_args_info_usage);
130 if (len_purpose > 0) {
131 printf(
"%s\n", gengetopt_args_info_purpose);
134 if (len_usage || len_purpose) {
138 if (strlen(gengetopt_args_info_description) > 0) {
139 printf(
"%s\n\n", gengetopt_args_info_description);
144cmdline_parser_print_help (
void)
148 while (gengetopt_args_info_help[i])
149 printf(
"%s\n", gengetopt_args_info_help[i++]);
155 clear_given (args_info);
156 clear_args (args_info);
157 init_args_info (args_info);
186free_string_field (
char **s)
200 free_string_field (&(args_info->
input_arg));
205 free_string_field (&(args_info->
end_orig));
210 free (args_info->
inputs [i]);
215 clear_given (args_info);
220write_into_file(FILE *outfile,
const char *opt,
const char *arg,
const char *values[])
224 fprintf(outfile,
"%s=\"%s\"\n", opt, arg);
226 fprintf(outfile,
"%s\n", opt);
243 write_into_file(outfile,
"help", 0, 0 );
245 write_into_file(outfile,
"version", 0, 0 );
247 write_into_file(outfile,
"input", args_info->
input_orig, 0);
249 write_into_file(outfile,
"output", args_info->
output_orig, 0);
251 write_into_file(outfile,
"start", args_info->
start_orig, 0);
253 write_into_file(outfile,
"end", args_info->
end_orig, 0);
255 write_into_file(outfile,
"number", args_info->
number_orig, 0);
268 outfile = fopen(filename,
"w");
285 cmdline_parser_release (args_info);
290gengetopt_strdup (
const char *s)
296 result = (
char*)malloc(strlen(s) + 1);
297 if (result == (
char*)0)
314 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
331 result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
339 int result = EXIT_SUCCESS;
341 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
342 result = EXIT_FAILURE;
348cmdline_parser_required2 (
struct gengetopt_args_info *args_info,
const char *prog_name,
const char *additional_error)
350 int error_occurred = 0;
351 FIX_UNUSED (additional_error);
356 fprintf (stderr,
"%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error :
""));
362 fprintf (stderr,
"%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error :
""));
369 return error_occurred;
427#ifndef required_argument
428#define required_argument 1
431#ifndef optional_argument
432#define optional_argument 2
435struct custom_getopt_data {
477static char *custom_optarg;
494static int custom_optind = 1;
500static int custom_opterr = 1;
506static int custom_optopt =
'?';
516static void exchange(
char **argv,
struct custom_getopt_data *d)
518 int bottom = d->first_nonopt;
519 int middle = d->last_nonopt;
520 int top = d->custom_optind;
529 while (top > middle && middle > bottom) {
530 if (top - middle > middle - bottom) {
532 int len = middle - bottom;
536 for (i = 0; i < len; i++) {
537 tem = argv[bottom + i];
539 argv[top - (middle - bottom) + i];
540 argv[top - (middle - bottom) + i] = tem;
546 int len = top - middle;
550 for (i = 0; i < len; i++) {
551 tem = argv[bottom + i];
552 argv[bottom + i] = argv[middle + i];
553 argv[middle + i] = tem;
560 d->first_nonopt += (d->custom_optind - d->last_nonopt);
561 d->last_nonopt = d->custom_optind;
565static void custom_getopt_initialize(
struct custom_getopt_data *d)
572 d->first_nonopt = d->last_nonopt = d->custom_optind;
577#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
580static int shuffle_argv(
int argc,
char *
const *argv,
const struct option *longopts,
581 struct custom_getopt_data *d)
587 if (d->last_nonopt > d->custom_optind)
588 d->last_nonopt = d->custom_optind;
589 if (d->first_nonopt > d->custom_optind)
590 d->first_nonopt = d->custom_optind;
595 if (d->first_nonopt != d->last_nonopt &&
596 d->last_nonopt != d->custom_optind)
597 exchange((
char **) argv, d);
598 else if (d->last_nonopt != d->custom_optind)
599 d->first_nonopt = d->custom_optind;
604 while (d->custom_optind < argc && NONOPTION_P)
606 d->last_nonopt = d->custom_optind;
612 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind],
"--")) {
614 if (d->first_nonopt != d->last_nonopt
615 && d->last_nonopt != d->custom_optind)
616 exchange((
char **) argv, d);
617 else if (d->first_nonopt == d->last_nonopt)
618 d->first_nonopt = d->custom_optind;
619 d->last_nonopt = argc;
620 d->custom_optind = argc;
626 if (d->custom_optind == argc) {
631 if (d->first_nonopt != d->last_nonopt)
632 d->custom_optind = d->first_nonopt;
640 d->custom_optarg = argv[d->custom_optind++];
647 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] ==
'-'));
661static int check_long_opt(
int argc,
char *
const *argv,
const char *optstring,
662 const struct option *longopts,
int *longind,
663 int print_errors,
struct custom_getopt_data *d)
666 const struct option *p;
667 const struct option *pfound = NULL;
673 for (nameend = d->nextchar; *nameend && *nameend !=
'='; nameend++)
677 for (p = longopts, option_index = 0; p->name; p++, option_index++)
678 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
679 if ((
unsigned int) (nameend - d->nextchar)
680 == (
unsigned int) strlen(p->name)) {
683 indfound = option_index;
686 }
else if (pfound == NULL) {
689 indfound = option_index;
690 }
else if (pfound->has_arg != p->has_arg
691 || pfound->flag != p->flag
692 || pfound->val != p->val)
696 if (ambig && !exact) {
699 "%s: option `%s' is ambiguous\n",
700 argv[0], argv[d->custom_optind]);
702 d->nextchar += strlen(d->nextchar);
704 d->custom_optopt = 0;
708 option_index = indfound;
711 if (pfound->has_arg != no_argument)
712 d->custom_optarg = nameend + 1;
715 if (argv[d->custom_optind - 1][1] ==
'-') {
717 fprintf(stderr,
"%s: option `--%s' doesn't allow an argument\n",
718 argv[0], pfound->name);
721 fprintf(stderr,
"%s: option `%c%s' doesn't allow an argument\n",
722 argv[0], argv[d->custom_optind - 1][0], pfound->name);
726 d->nextchar += strlen(d->nextchar);
727 d->custom_optopt = pfound->val;
730 }
else if (pfound->has_arg == required_argument) {
731 if (d->custom_optind < argc)
732 d->custom_optarg = argv[d->custom_optind++];
736 "%s: option `%s' requires an argument\n",
738 argv[d->custom_optind - 1]);
740 d->nextchar += strlen(d->nextchar);
741 d->custom_optopt = pfound->val;
742 return optstring[0] ==
':' ?
':' :
'?';
745 d->nextchar += strlen(d->nextchar);
747 *longind = option_index;
749 *(pfound->flag) = pfound->val;
760 if (argv[d->custom_optind][1] ==
'-') {
763 "%s: unrecognized option `--%s'\n",
764 argv[0], d->nextchar);
768 "%s: unrecognized option `%c%s'\n",
769 argv[0], argv[d->custom_optind][0],
773 d->nextchar = (
char *)
"";
775 d->custom_optopt = 0;
779static int check_short_opt(
int argc,
char *
const *argv,
const char *optstring,
780 int print_errors,
struct custom_getopt_data *d)
782 char c = *d->nextchar++;
783 const char *temp = strchr(optstring, c);
786 if (*d->nextchar ==
'\0')
788 if (!temp || c ==
':') {
790 fprintf(stderr,
"%s: invalid option -- %c\n", argv[0], c);
792 d->custom_optopt = c;
795 if (temp[1] ==
':') {
796 if (temp[2] ==
':') {
798 if (*d->nextchar !=
'\0') {
799 d->custom_optarg = d->nextchar;
802 d->custom_optarg = NULL;
806 if (*d->nextchar !=
'\0') {
807 d->custom_optarg = d->nextchar;
814 }
else if (d->custom_optind == argc) {
817 "%s: option requires an argument -- %c\n",
820 d->custom_optopt = c;
821 if (optstring[0] ==
':')
831 d->custom_optarg = argv[d->custom_optind++];
908static int getopt_internal_r(
int argc,
char *
const *argv,
const char *optstring,
909 const struct option *longopts,
int *longind,
910 struct custom_getopt_data *d)
912 int ret, print_errors = d->custom_opterr;
914 if (optstring[0] ==
':')
918 d->custom_optarg = NULL;
924 if (d->custom_optind == 0 || !d->initialized) {
925 if (d->custom_optind == 0)
926 d->custom_optind = 1;
927 custom_getopt_initialize(d);
929 if (d->nextchar == NULL || *d->nextchar ==
'\0') {
930 ret = shuffle_argv(argc, argv, longopts, d);
934 if (longopts && (argv[d->custom_optind][1] ==
'-' ))
935 return check_long_opt(argc, argv, optstring, longopts,
936 longind, print_errors, d);
937 return check_short_opt(argc, argv, optstring, print_errors, d);
940static int custom_getopt_internal(
int argc,
char *
const *argv,
const char *optstring,
941 const struct option *longopts,
int *longind)
945 static struct custom_getopt_data d;
947 d.custom_optind = custom_optind;
948 d.custom_opterr = custom_opterr;
949 result = getopt_internal_r(argc, argv, optstring, longopts,
951 custom_optind = d.custom_optind;
952 custom_optarg = d.custom_optarg;
953 custom_optopt = d.custom_optopt;
957static int custom_getopt_long (
int argc,
char *
const *argv,
const char *options,
958 const struct option *long_options,
int *opt_index)
960 return custom_getopt_internal(argc, argv, options, long_options,
965static char *package_name = 0;
986int update_arg(
void *field,
char **orig_field,
987 unsigned int *field_given,
unsigned int *prev_given,
988 char *value,
const char *possible_values[],
989 const char *default_value,
990 cmdline_parser_arg_type arg_type,
991 int check_ambiguity,
int override,
992 int no_free,
int multiple_option,
993 const char *long_opt,
char short_opt,
994 const char *additional_error)
997 const char *val = value;
1005 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1007 if (short_opt !=
'-')
1008 fprintf (stderr,
"%s: `--%s' (`-%c') option given more than once%s\n",
1009 package_name, long_opt, short_opt,
1010 (additional_error ? additional_error :
""));
1012 fprintf (stderr,
"%s: `--%s' option given more than once%s\n",
1013 package_name, long_opt,
1014 (additional_error ? additional_error :
""));
1018 FIX_UNUSED (default_value);
1020 if (field_given && *field_given && !
override)
1026 if (possible_values)
1027 val = possible_values[found];
1031 if (val) *((
int *)field) = strtol (val, &stop_char, 0);
1034 if (val) *((
double *)field) = strtod (val, &stop_char);
1038 string_field = (
char **)field;
1039 if (!no_free && *string_field)
1040 free (*string_field);
1041 *string_field = gengetopt_strdup (val);
1052 if (val && !(stop_char && *stop_char ==
'\0')) {
1053 fprintf(stderr,
"%s: invalid numeric value: %s\n", package_name, val);
1066 if (value && orig_field) {
1068 *orig_field = value;
1072 *orig_field = gengetopt_strdup (value);
1082cmdline_parser_internal (
1088 int error_occurred = 0;
1094 int check_ambiguity;
1101 package_name = argv[0];
1105 FIX_UNUSED(
override);
1112 FIX_UNUSED(check_ambiguity);
1126 int option_index = 0;
1128 static struct option long_options[] = {
1129 {
"help", 0, NULL,
'h' },
1130 {
"version", 0, NULL,
'V' },
1131 {
"input", 1, NULL,
'i' },
1132 {
"output", 1, NULL,
'o' },
1133 {
"start", 1, NULL,
's' },
1134 {
"end", 1, NULL,
'e' },
1135 {
"number", 1, NULL,
'n' },
1139 custom_optarg = optarg;
1140 custom_optind = optind;
1141 custom_opterr = opterr;
1142 custom_optopt = optopt;
1144 c = custom_getopt_long (argc, argv,
"hVi:o:s:e:n:", long_options, &option_index);
1146 optarg = custom_optarg;
1147 optind = custom_optind;
1148 opterr = custom_opterr;
1149 optopt = custom_optopt;
1156 cmdline_parser_print_help ();
1157 cmdline_parser_free (&local_args_info);
1158 exit (EXIT_SUCCESS);
1161 cmdline_parser_print_version ();
1162 cmdline_parser_free (&local_args_info);
1163 exit (EXIT_SUCCESS);
1168 if (update_arg( (
void *)&(args_info->
input_arg),
1170 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1171 check_ambiguity,
override, 0, 0,
1180 if (update_arg( (
void *)&(args_info->
output_arg),
1182 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1183 check_ambiguity,
override, 0, 0,
1192 if (update_arg( (
void *)&(args_info->
start_arg),
1194 &(local_args_info.start_given), optarg, 0,
"0.8", ARG_DOUBLE,
1195 check_ambiguity,
override, 0, 0,
1204 if (update_arg( (
void *)&(args_info->
end_arg),
1206 &(local_args_info.end_given), optarg, 0,
"1.2", ARG_DOUBLE,
1207 check_ambiguity,
override, 0, 0,
1216 if (update_arg( (
void *)&(args_info->
number_arg),
1218 &(local_args_info.number_given), optarg, 0,
"50", ARG_INT,
1219 check_ambiguity,
override, 0, 0,
1232 fprintf (stderr,
"%s: option unknown: %c%s\n",
CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error :
""));
1241 error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error);
1244 cmdline_parser_release (&local_args_info);
1246 if ( error_occurred )
1247 return (EXIT_FAILURE);
1252 int found_prog_name = 0;
1258 args_info->
inputs_num = argc - optind - found_prog_name;
1260 (
char **)(malloc ((args_info->
inputs_num)*
sizeof(
char *))) ;
1261 while (optind < argc)
1262 args_info->
inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1269 cmdline_parser_release (&local_args_info);
1270 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 output_given
Whether output was given.
char * output_orig
output file name original value given at command line.
const char * output_help
output file name help description.
const char * number_help
number of data points help description.
unsigned int end_given
Whether end was given.
char * start_orig
starting affine scale original value given at command line.
unsigned inputs_num
unamed options number
unsigned int number_given
Whether number was given.
const char * help_help
Print help and exit help description.
unsigned int start_given
Whether start was given.
char * output_arg
output file name.
char ** inputs
unamed options (options without names)
int number_arg
number of data points (default='50').
char * input_arg
input dump file.
double start_arg
starting affine scale (default='0.8').
const char * end_help
ending affine scale help description.
char * end_orig
ending affine scale original value given at command line.
unsigned int help_given
Whether help was given.
unsigned int input_given
Whether input was given.
unsigned int version_given
Whether version was given.
double end_arg
ending affine scale (default='1.2').
const char * version_help
Print version and exit help description.
const char * start_help
starting affine scale help description.
char * input_orig
input dump file original value given at command line.
char * number_orig
number of data points original value given at command line.
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.