2 File autogenerated by gengetopt version 2.22.6
3 generated with the following command:
4 gengetopt --file-name=transop_ewald_cmdline
6 The developers of gengetopt consider the fixed text that goes in all
7 gengetopt output files to be in the public domain:
8 we make no copyright claims on it.
11 /* If we use autoconf. */
21 #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
26 #include "transop_ewald_cmdline.h"
28 const char *gengetopt_args_info_purpose
= "Computes Ewald-summed VSWF translation matrix elements in arbitrary 2D-periodic\ninfinite lattices.";
30 const char *gengetopt_args_info_usage
= "Usage: qpms-translations-ewald32 [OPTIONS]...";
32 const char *gengetopt_args_info_versiontext
= "";
34 const char *gengetopt_args_info_description
= "";
36 const char *gengetopt_args_info_detailed_help
[] = {
37 " -h, --help Print help and exit",
38 " --detailed-help Print help, including all details and hidden\n options, and exit",
39 " -V, --version Print version and exit",
40 " -o, --output=STRING Output file (default=`')",
41 " Path to the output file. If not specified, print to the standard output.",
42 " -b, --base-vector=X,Y Base vector",
43 " Single base vector (two numbers separated by comma)",
44 " -E, --error-estimate-output=STRING\n Path to the output with error estimates",
45 " -N, --normalisation=ENUM VSWF normalisation convention (possible\n values=\"Power\", \"None\", \"SH\"\n default=`Power')",
46 " -c, --csphase=INT Whether the Condon-Shortley phase is included\n in VSWF definition (-1) or not (+1)\n (possible values=\"+1\", \"-1\" default=`-1')",
47 " -e, --Ewald-parameter=DOUBLE The value of Ewald parameter η",
48 " -u, --frequency-unit=ENUM Specifies the frequency unit is used for\n inputs. (possible values=\"eV\", \"scuff\"\n default=`scuff')",
49 " -L, --lMax=INT Maximum spherical multipole order to which the\n translation operator elements are calculated",
50 " -n, --refractive-index=DOUBLE Medium refractive index",
51 " -p, --particle=X,Y Specify the x and y coordinates of a single\n particle; If not specified, one particle per\n unit cell is assumed.",
52 "\n Mode: k_omega_points\n Specifying each (ω, k) pair separately.",
53 " -T, --pointfile=STRING Path to a file containing frequency, k_x, k_y\n triples(separated by white spaces). If not\n specified, read them from stdin.\n (default=`-')",
54 " -t, --point=ω,k_x,k_y Specifies a frequency, k_x, k_y triple,\n separated by commas.",
55 "\n Mode: k_omega_meshgrid\n Specifying lists of ω and k, from which all possible pairs are generated.",
56 " -F, --omegafile=STRING Path to a file containing a list of\n frequenciesseparated by whitespaces.",
57 " -f, --omega=ω1[,ω2[,...]] Specifies frequency (or multiple frequencies\n separated by commas) on the command line.",
58 " -K, --kfile=STRING Path to a file containing a list of k_x, k_y\n pairs. (default=`-')",
59 " -k, --k=k1_x,k1_y[,k2_x,k2_y[,...]]\n Specifies pair(s) of k_x, k_y values",
66 gengetopt_args_info_help
[0] = gengetopt_args_info_detailed_help
[0];
67 gengetopt_args_info_help
[1] = gengetopt_args_info_detailed_help
[1];
68 gengetopt_args_info_help
[2] = gengetopt_args_info_detailed_help
[2];
69 gengetopt_args_info_help
[3] = gengetopt_args_info_detailed_help
[3];
70 gengetopt_args_info_help
[4] = gengetopt_args_info_detailed_help
[5];
71 gengetopt_args_info_help
[5] = gengetopt_args_info_detailed_help
[7];
72 gengetopt_args_info_help
[6] = gengetopt_args_info_detailed_help
[8];
73 gengetopt_args_info_help
[7] = gengetopt_args_info_detailed_help
[9];
74 gengetopt_args_info_help
[8] = gengetopt_args_info_detailed_help
[10];
75 gengetopt_args_info_help
[9] = gengetopt_args_info_detailed_help
[11];
76 gengetopt_args_info_help
[10] = gengetopt_args_info_detailed_help
[12];
77 gengetopt_args_info_help
[11] = gengetopt_args_info_detailed_help
[13];
78 gengetopt_args_info_help
[12] = gengetopt_args_info_detailed_help
[14];
79 gengetopt_args_info_help
[13] = gengetopt_args_info_detailed_help
[15];
80 gengetopt_args_info_help
[14] = gengetopt_args_info_detailed_help
[16];
81 gengetopt_args_info_help
[15] = gengetopt_args_info_detailed_help
[17];
82 gengetopt_args_info_help
[16] = gengetopt_args_info_detailed_help
[18];
83 gengetopt_args_info_help
[17] = gengetopt_args_info_detailed_help
[19];
84 gengetopt_args_info_help
[18] = gengetopt_args_info_detailed_help
[20];
85 gengetopt_args_info_help
[19] = gengetopt_args_info_detailed_help
[21];
86 gengetopt_args_info_help
[20] = gengetopt_args_info_detailed_help
[22];
87 gengetopt_args_info_help
[21] = 0;
91 const char *gengetopt_args_info_help
[22];
98 } cmdline_parser_arg_type
;
101 void clear_given (struct gengetopt_args_info
*args_info
);
103 void clear_args (struct gengetopt_args_info
*args_info
);
106 cmdline_parser_internal (int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
107 struct cmdline_parser_params
*params
, const char *additional_error
);
110 cmdline_parser_required2 (struct gengetopt_args_info
*args_info
, const char *prog_name
, const char *additional_error
);
112 const char *cmdline_parser_normalisation_values
[] = {"Power", "None", "SH", 0}; /*< Possible values for normalisation. */
113 const char *cmdline_parser_csphase_values
[] = {"+1", "-1", 0}; /*< Possible values for csphase. */
114 const char *cmdline_parser_frequency_unit_values
[] = {"eV", "scuff", 0}; /*< Possible values for frequency-unit. */
117 gengetopt_strdup (const char *s
);
120 void clear_given (struct gengetopt_args_info
*args_info
)
122 args_info
->help_given
= 0 ;
123 args_info
->detailed_help_given
= 0 ;
124 args_info
->version_given
= 0 ;
125 args_info
->output_given
= 0 ;
126 args_info
->base_vector_given
= 0 ;
127 args_info
->error_estimate_output_given
= 0 ;
128 args_info
->normalisation_given
= 0 ;
129 args_info
->csphase_given
= 0 ;
130 args_info
->Ewald_parameter_given
= 0 ;
131 args_info
->frequency_unit_given
= 0 ;
132 args_info
->lMax_given
= 0 ;
133 args_info
->refractive_index_given
= 0 ;
134 args_info
->particle_given
= 0 ;
135 args_info
->pointfile_given
= 0 ;
136 args_info
->point_given
= 0 ;
137 args_info
->omegafile_given
= 0 ;
138 args_info
->omega_given
= 0 ;
139 args_info
->kfile_given
= 0 ;
140 args_info
->k_given
= 0 ;
141 args_info
->k_omega_meshgrid_mode_counter
= 0 ;
142 args_info
->k_omega_points_mode_counter
= 0 ;
146 void clear_args (struct gengetopt_args_info
*args_info
)
148 FIX_UNUSED (args_info
);
149 args_info
->output_arg
= gengetopt_strdup ("");
150 args_info
->output_orig
= NULL
;
151 args_info
->base_vector_arg
= NULL
;
152 args_info
->base_vector_orig
= NULL
;
153 args_info
->error_estimate_output_arg
= NULL
;
154 args_info
->error_estimate_output_orig
= NULL
;
155 args_info
->normalisation_arg
= normalisation_arg_Power
;
156 args_info
->normalisation_orig
= NULL
;
157 args_info
->csphase_arg
= -1;
158 args_info
->csphase_orig
= NULL
;
159 args_info
->Ewald_parameter_orig
= NULL
;
160 args_info
->frequency_unit_arg
= frequency_unit_arg_scuff
;
161 args_info
->frequency_unit_orig
= NULL
;
162 args_info
->lMax_orig
= NULL
;
163 args_info
->refractive_index_orig
= NULL
;
164 args_info
->particle_arg
= NULL
;
165 args_info
->particle_orig
= NULL
;
166 args_info
->pointfile_arg
= NULL
;
167 args_info
->pointfile_orig
= NULL
;
168 args_info
->point_arg
= NULL
;
169 args_info
->point_orig
= NULL
;
170 args_info
->omegafile_arg
= NULL
;
171 args_info
->omegafile_orig
= NULL
;
172 args_info
->omega_arg
= NULL
;
173 args_info
->omega_orig
= NULL
;
174 args_info
->kfile_arg
= NULL
;
175 args_info
->kfile_orig
= NULL
;
176 args_info
->k_arg
= NULL
;
177 args_info
->k_orig
= NULL
;
182 void init_args_info(struct gengetopt_args_info
*args_info
)
186 args_info
->help_help
= gengetopt_args_info_detailed_help
[0] ;
187 args_info
->detailed_help_help
= gengetopt_args_info_detailed_help
[1] ;
188 args_info
->version_help
= gengetopt_args_info_detailed_help
[2] ;
189 args_info
->output_help
= gengetopt_args_info_detailed_help
[3] ;
190 args_info
->base_vector_help
= gengetopt_args_info_detailed_help
[5] ;
191 args_info
->base_vector_min
= 2;
192 args_info
->base_vector_max
= 2;
193 args_info
->error_estimate_output_help
= gengetopt_args_info_detailed_help
[7] ;
194 args_info
->normalisation_help
= gengetopt_args_info_detailed_help
[8] ;
195 args_info
->csphase_help
= gengetopt_args_info_detailed_help
[9] ;
196 args_info
->Ewald_parameter_help
= gengetopt_args_info_detailed_help
[10] ;
197 args_info
->frequency_unit_help
= gengetopt_args_info_detailed_help
[11] ;
198 args_info
->lMax_help
= gengetopt_args_info_detailed_help
[12] ;
199 args_info
->refractive_index_help
= gengetopt_args_info_detailed_help
[13] ;
200 args_info
->particle_help
= gengetopt_args_info_detailed_help
[14] ;
201 args_info
->particle_min
= 0;
202 args_info
->particle_max
= 0;
203 args_info
->pointfile_help
= gengetopt_args_info_detailed_help
[16] ;
204 args_info
->pointfile_min
= 0;
205 args_info
->pointfile_max
= 0;
206 args_info
->point_help
= gengetopt_args_info_detailed_help
[17] ;
207 args_info
->point_min
= 0;
208 args_info
->point_max
= 0;
209 args_info
->omegafile_help
= gengetopt_args_info_detailed_help
[19] ;
210 args_info
->omegafile_min
= 0;
211 args_info
->omegafile_max
= 0;
212 args_info
->omega_help
= gengetopt_args_info_detailed_help
[20] ;
213 args_info
->omega_min
= 0;
214 args_info
->omega_max
= 0;
215 args_info
->kfile_help
= gengetopt_args_info_detailed_help
[21] ;
216 args_info
->kfile_min
= 0;
217 args_info
->kfile_max
= 0;
218 args_info
->k_help
= gengetopt_args_info_detailed_help
[22] ;
219 args_info
->k_min
= 0;
220 args_info
->k_max
= 0;
225 cmdline_parser_print_version (void)
228 (strlen(CMDLINE_PARSER_PACKAGE_NAME
) ? CMDLINE_PARSER_PACKAGE_NAME
: CMDLINE_PARSER_PACKAGE
),
229 CMDLINE_PARSER_VERSION
);
231 if (strlen(gengetopt_args_info_versiontext
) > 0)
232 printf("\n%s\n", gengetopt_args_info_versiontext
);
235 static void print_help_common(void) {
236 cmdline_parser_print_version ();
238 if (strlen(gengetopt_args_info_purpose
) > 0)
239 printf("\n%s\n", gengetopt_args_info_purpose
);
241 if (strlen(gengetopt_args_info_usage
) > 0)
242 printf("\n%s\n", gengetopt_args_info_usage
);
246 if (strlen(gengetopt_args_info_description
) > 0)
247 printf("%s\n\n", gengetopt_args_info_description
);
251 cmdline_parser_print_help (void)
255 while (gengetopt_args_info_help
[i
])
256 printf("%s\n", gengetopt_args_info_help
[i
++]);
260 cmdline_parser_print_detailed_help (void)
264 while (gengetopt_args_info_detailed_help
[i
])
265 printf("%s\n", gengetopt_args_info_detailed_help
[i
++]);
269 cmdline_parser_init (struct gengetopt_args_info
*args_info
)
271 clear_given (args_info
);
272 clear_args (args_info
);
273 init_args_info (args_info
);
277 cmdline_parser_params_init(struct cmdline_parser_params
*params
)
281 params
->override
= 0;
282 params
->initialize
= 1;
283 params
->check_required
= 1;
284 params
->check_ambiguity
= 0;
285 params
->print_errors
= 1;
289 struct cmdline_parser_params
*
290 cmdline_parser_params_create(void)
292 struct cmdline_parser_params
*params
=
293 (struct cmdline_parser_params
*)malloc(sizeof(struct cmdline_parser_params
));
294 cmdline_parser_params_init(params
);
299 free_string_field (char **s
)
308 /** @brief generic value variable */
309 union generic_value
{
313 const char *default_string_arg
;
316 /** @brief holds temporary values for multiple options */
319 union generic_value arg
;
321 struct generic_list
*next
;
325 * @brief add a node at the head of the list
327 static void add_node(struct generic_list
**list
) {
328 struct generic_list
*new_node
= (struct generic_list
*) malloc (sizeof (struct generic_list
));
329 new_node
->next
= *list
;
331 new_node
->arg
.string_arg
= 0;
337 free_multiple_string_field(unsigned int len
, char ***arg
, char ***orig
)
341 for (i
= 0; i
< len
; ++i
)
343 free_string_field(&((*arg
)[i
]));
344 free_string_field(&((*orig
)[i
]));
346 free_string_field(&((*arg
)[0])); /* free default string */
356 cmdline_parser_release (struct gengetopt_args_info
*args_info
)
359 free_string_field (&(args_info
->output_arg
));
360 free_string_field (&(args_info
->output_orig
));
361 free_multiple_string_field (args_info
->base_vector_given
, &(args_info
->base_vector_arg
), &(args_info
->base_vector_orig
));
362 free_string_field (&(args_info
->error_estimate_output_arg
));
363 free_string_field (&(args_info
->error_estimate_output_orig
));
364 free_string_field (&(args_info
->normalisation_orig
));
365 free_string_field (&(args_info
->csphase_orig
));
366 free_string_field (&(args_info
->Ewald_parameter_orig
));
367 free_string_field (&(args_info
->frequency_unit_orig
));
368 free_string_field (&(args_info
->lMax_orig
));
369 free_string_field (&(args_info
->refractive_index_orig
));
370 free_multiple_string_field (args_info
->particle_given
, &(args_info
->particle_arg
), &(args_info
->particle_orig
));
371 free_multiple_string_field (args_info
->pointfile_given
, &(args_info
->pointfile_arg
), &(args_info
->pointfile_orig
));
372 free_multiple_string_field (args_info
->point_given
, &(args_info
->point_arg
), &(args_info
->point_orig
));
373 free_multiple_string_field (args_info
->omegafile_given
, &(args_info
->omegafile_arg
), &(args_info
->omegafile_orig
));
374 free_multiple_string_field (args_info
->omega_given
, &(args_info
->omega_arg
), &(args_info
->omega_orig
));
375 free_multiple_string_field (args_info
->kfile_given
, &(args_info
->kfile_arg
), &(args_info
->kfile_orig
));
376 free_multiple_string_field (args_info
->k_given
, &(args_info
->k_arg
), &(args_info
->k_orig
));
380 clear_given (args_info
);
384 * @param val the value to check
385 * @param values the possible values
386 * @return the index of the matched value:
387 * -1 if no value matched,
388 * -2 if more than one value has matched
391 check_possible_values(const char *val
, const char *values
[])
396 if (!val
) /* otherwise strlen() crashes below */
397 return -1; /* -1 means no argument for the option */
401 for (i
= 0, len
= strlen(val
); values
[i
]; ++i
)
403 if (strncmp(val
, values
[i
], len
) == 0)
407 if (strlen(values
[i
]) == len
)
408 return i
; /* exact macth no need to check more */
412 if (found
== 1) /* one match: OK */
415 return (found
? -2 : -1); /* return many values or none matched */
420 write_into_file(FILE *outfile
, const char *opt
, const char *arg
, const char *values
[])
425 found
= check_possible_values(arg
, values
);
428 fprintf(outfile
, "%s=\"%s\" # %s\n", opt
, arg
, values
[found
]);
430 fprintf(outfile
, "%s=\"%s\"\n", opt
, arg
);
432 fprintf(outfile
, "%s\n", opt
);
437 write_multiple_into_file(FILE *outfile
, int len
, const char *opt
, char **arg
, const char *values
[])
441 for (i
= 0; i
< len
; ++i
)
442 write_into_file(outfile
, opt
, (arg
? arg
[i
] : 0), values
);
446 cmdline_parser_dump(FILE *outfile
, struct gengetopt_args_info
*args_info
)
452 fprintf (stderr
, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE
);
456 if (args_info
->help_given
)
457 write_into_file(outfile
, "help", 0, 0 );
458 if (args_info
->detailed_help_given
)
459 write_into_file(outfile
, "detailed-help", 0, 0 );
460 if (args_info
->version_given
)
461 write_into_file(outfile
, "version", 0, 0 );
462 if (args_info
->output_given
)
463 write_into_file(outfile
, "output", args_info
->output_orig
, 0);
464 write_multiple_into_file(outfile
, args_info
->base_vector_given
, "base-vector", args_info
->base_vector_orig
, 0);
465 if (args_info
->error_estimate_output_given
)
466 write_into_file(outfile
, "error-estimate-output", args_info
->error_estimate_output_orig
, 0);
467 if (args_info
->normalisation_given
)
468 write_into_file(outfile
, "normalisation", args_info
->normalisation_orig
, cmdline_parser_normalisation_values
);
469 if (args_info
->csphase_given
)
470 write_into_file(outfile
, "csphase", args_info
->csphase_orig
, cmdline_parser_csphase_values
);
471 if (args_info
->Ewald_parameter_given
)
472 write_into_file(outfile
, "Ewald-parameter", args_info
->Ewald_parameter_orig
, 0);
473 if (args_info
->frequency_unit_given
)
474 write_into_file(outfile
, "frequency-unit", args_info
->frequency_unit_orig
, cmdline_parser_frequency_unit_values
);
475 if (args_info
->lMax_given
)
476 write_into_file(outfile
, "lMax", args_info
->lMax_orig
, 0);
477 if (args_info
->refractive_index_given
)
478 write_into_file(outfile
, "refractive-index", args_info
->refractive_index_orig
, 0);
479 write_multiple_into_file(outfile
, args_info
->particle_given
, "particle", args_info
->particle_orig
, 0);
480 write_multiple_into_file(outfile
, args_info
->pointfile_given
, "pointfile", args_info
->pointfile_orig
, 0);
481 write_multiple_into_file(outfile
, args_info
->point_given
, "point", args_info
->point_orig
, 0);
482 write_multiple_into_file(outfile
, args_info
->omegafile_given
, "omegafile", args_info
->omegafile_orig
, 0);
483 write_multiple_into_file(outfile
, args_info
->omega_given
, "omega", args_info
->omega_orig
, 0);
484 write_multiple_into_file(outfile
, args_info
->kfile_given
, "kfile", args_info
->kfile_orig
, 0);
485 write_multiple_into_file(outfile
, args_info
->k_given
, "k", args_info
->k_orig
, 0);
493 cmdline_parser_file_save(const char *filename
, struct gengetopt_args_info
*args_info
)
498 outfile
= fopen(filename
, "w");
502 fprintf (stderr
, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE
, filename
);
506 i
= cmdline_parser_dump(outfile
, args_info
);
513 cmdline_parser_free (struct gengetopt_args_info
*args_info
)
515 cmdline_parser_release (args_info
);
518 /** @brief replacement of strdup, which is not standard */
520 gengetopt_strdup (const char *s
)
526 result
= (char*)malloc(strlen(s
) + 1);
527 if (result
== (char*)0)
534 get_multiple_arg_token(const char *arg
)
538 size_t len
, num_of_escape
, i
, j
;
543 tok
= strchr (arg
, ',');
546 /* make sure it is not escaped */
549 if (*(tok
-1) == '\\')
551 /* find the next one */
552 tok
= strchr (tok
+1, ',');
560 len
= (size_t)(tok
- arg
+ 1);
562 len
= strlen (arg
) + 1;
564 len
-= num_of_escape
;
566 ret
= (char *) malloc (len
);
570 while (arg
[i
] && (j
< len
-1))
572 if (arg
[i
] == '\\' &&
586 get_multiple_arg_token_next(const char *arg
)
593 tok
= strchr (arg
, ',');
595 /* make sure it is not escaped */
598 if (*(tok
-1) == '\\')
600 /* find the next one */
601 tok
= strchr (tok
+1, ',');
607 if (! tok
|| strlen(tok
) == 1)
614 check_multiple_option_occurrences(const char *prog_name
, unsigned int option_given
, unsigned int min
, unsigned int max
, const char *option_desc
);
617 check_multiple_option_occurrences(const char *prog_name
, unsigned int option_given
, unsigned int min
, unsigned int max
, const char *option_desc
)
619 int error_occurred
= 0;
621 if (option_given
&& (min
> 0 || max
> 0))
623 if (min
> 0 && max
> 0)
627 /* specific occurrences */
628 if (option_given
!= (unsigned int) min
)
630 fprintf (stderr
, "%s: %s option occurrences must be %d\n",
631 prog_name
, option_desc
, min
);
635 else if (option_given
< (unsigned int) min
636 || option_given
> (unsigned int) max
)
638 /* range occurrences */
639 fprintf (stderr
, "%s: %s option occurrences must be between %d and %d\n",
640 prog_name
, option_desc
, min
, max
);
647 if (option_given
< min
)
649 fprintf (stderr
, "%s: %s option occurrences must be at least %d\n",
650 prog_name
, option_desc
, min
);
657 if (option_given
> max
)
659 fprintf (stderr
, "%s: %s option occurrences must be at most %d\n",
660 prog_name
, option_desc
, max
);
666 return error_occurred
;
669 cmdline_parser (int argc
, char **argv
, struct gengetopt_args_info
*args_info
)
671 return cmdline_parser2 (argc
, argv
, args_info
, 0, 1, 1);
675 cmdline_parser_ext (int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
676 struct cmdline_parser_params
*params
)
679 result
= cmdline_parser_internal (argc
, argv
, args_info
, params
, 0);
681 if (result
== EXIT_FAILURE
)
683 cmdline_parser_free (args_info
);
691 cmdline_parser2 (int argc
, char **argv
, struct gengetopt_args_info
*args_info
, int override
, int initialize
, int check_required
)
694 struct cmdline_parser_params params
;
696 params
.override
= override
;
697 params
.initialize
= initialize
;
698 params
.check_required
= check_required
;
699 params
.check_ambiguity
= 0;
700 params
.print_errors
= 1;
702 result
= cmdline_parser_internal (argc
, argv
, args_info
, ¶ms
, 0);
704 if (result
== EXIT_FAILURE
)
706 cmdline_parser_free (args_info
);
714 cmdline_parser_required (struct gengetopt_args_info
*args_info
, const char *prog_name
)
716 int result
= EXIT_SUCCESS
;
718 if (cmdline_parser_required2(args_info
, prog_name
, 0) > 0)
719 result
= EXIT_FAILURE
;
721 if (result
== EXIT_FAILURE
)
723 cmdline_parser_free (args_info
);
731 cmdline_parser_required2 (struct gengetopt_args_info
*args_info
, const char *prog_name
, const char *additional_error
)
733 int error_occurred
= 0;
734 FIX_UNUSED (additional_error
);
736 /* checks for required options */
737 if (! args_info
->base_vector_given
)
739 fprintf (stderr
, "%s: '--base-vector' ('-b') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
743 if (check_multiple_option_occurrences(prog_name
, args_info
->base_vector_given
, args_info
->base_vector_min
, args_info
->base_vector_max
, "'--base-vector' ('-b')"))
746 if (! args_info
->normalisation_given
)
748 fprintf (stderr
, "%s: '--normalisation' ('-N') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
752 if (! args_info
->csphase_given
)
754 fprintf (stderr
, "%s: '--csphase' ('-c') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
758 if (! args_info
->frequency_unit_given
)
760 fprintf (stderr
, "%s: '--frequency-unit' ('-u') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
764 if (! args_info
->lMax_given
)
766 fprintf (stderr
, "%s: '--lMax' ('-L') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
770 if (! args_info
->refractive_index_given
)
772 fprintf (stderr
, "%s: '--refractive-index' ('-n') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
776 if (check_multiple_option_occurrences(prog_name
, args_info
->particle_given
, args_info
->particle_min
, args_info
->particle_max
, "'--particle' ('-p')"))
779 if (args_info
->k_omega_points_mode_counter
&& ! args_info
->pointfile_given
)
781 fprintf (stderr
, "%s: '--pointfile' ('-T') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
785 if (args_info
->k_omega_points_mode_counter
&& check_multiple_option_occurrences(prog_name
, args_info
->pointfile_given
, args_info
->pointfile_min
, args_info
->pointfile_max
, "'--pointfile' ('-T')"))
788 if (args_info
->k_omega_points_mode_counter
&& check_multiple_option_occurrences(prog_name
, args_info
->point_given
, args_info
->point_min
, args_info
->point_max
, "'--point' ('-t')"))
791 if (args_info
->k_omega_meshgrid_mode_counter
&& check_multiple_option_occurrences(prog_name
, args_info
->omegafile_given
, args_info
->omegafile_min
, args_info
->omegafile_max
, "'--omegafile' ('-F')"))
794 if (args_info
->k_omega_meshgrid_mode_counter
&& check_multiple_option_occurrences(prog_name
, args_info
->omega_given
, args_info
->omega_min
, args_info
->omega_max
, "'--omega' ('-f')"))
797 if (args_info
->k_omega_meshgrid_mode_counter
&& check_multiple_option_occurrences(prog_name
, args_info
->kfile_given
, args_info
->kfile_min
, args_info
->kfile_max
, "'--kfile' ('-K')"))
800 if (args_info
->k_omega_meshgrid_mode_counter
&& check_multiple_option_occurrences(prog_name
, args_info
->k_given
, args_info
->k_min
, args_info
->k_max
, "'--k' ('-k')"))
804 /* checks for dependences among options */
806 return error_occurred
;
810 static char *package_name
= 0;
813 * @brief updates an option
814 * @param field the generic pointer to the field to update
815 * @param orig_field the pointer to the orig field
816 * @param field_given the pointer to the number of occurrence of this option
817 * @param prev_given the pointer to the number of occurrence already seen
818 * @param value the argument for this option (if null no arg was specified)
819 * @param possible_values the possible values for this option (if specified)
820 * @param default_value the default value (in case the option only accepts fixed values)
821 * @param arg_type the type of this option
822 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
823 * @param override @see cmdline_parser_params.override
824 * @param no_free whether to free a possible previous value
825 * @param multiple_option whether this is a multiple option
826 * @param long_opt the corresponding long option
827 * @param short_opt the corresponding short option (or '-' if none)
828 * @param additional_error possible further error specification
831 int update_arg(void *field
, char **orig_field
,
832 unsigned int *field_given
, unsigned int *prev_given
,
833 char *value
, const char *possible_values
[],
834 const char *default_value
,
835 cmdline_parser_arg_type arg_type
,
836 int check_ambiguity
, int override
,
837 int no_free
, int multiple_option
,
838 const char *long_opt
, char short_opt
,
839 const char *additional_error
)
842 const char *val
= value
;
850 if (!multiple_option
&& prev_given
&& (*prev_given
|| (check_ambiguity
&& *field_given
)))
852 if (short_opt
!= '-')
853 fprintf (stderr
, "%s: `--%s' (`-%c') option given more than once%s\n",
854 package_name
, long_opt
, short_opt
,
855 (additional_error
? additional_error
: ""));
857 fprintf (stderr
, "%s: `--%s' option given more than once%s\n",
858 package_name
, long_opt
,
859 (additional_error
? additional_error
: ""));
860 return 1; /* failure */
863 if (possible_values
&& (found
= check_possible_values((value
? value
: default_value
), possible_values
)) < 0)
865 if (short_opt
!= '-')
866 fprintf (stderr
, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n",
867 package_name
, (found
== -2) ? "ambiguous" : "invalid", value
, long_opt
, short_opt
,
868 (additional_error
? additional_error
: ""));
870 fprintf (stderr
, "%s: %s argument, \"%s\", for option `--%s'%s\n",
871 package_name
, (found
== -2) ? "ambiguous" : "invalid", value
, long_opt
,
872 (additional_error
? additional_error
: ""));
873 return 1; /* failure */
876 if (field_given
&& *field_given
&& ! override
)
883 val
= possible_values
[found
];
887 if (val
) *((int *)field
) = strtol (val
, &stop_char
, 0);
890 if (val
) *((double *)field
) = strtod (val
, &stop_char
);
893 if (val
) *((int *)field
) = found
;
897 string_field
= (char **)field
;
898 if (!no_free
&& *string_field
)
899 free (*string_field
); /* free previous string */
900 *string_field
= gengetopt_strdup (val
);
907 /* check numeric conversion */
911 if (val
&& !(stop_char
&& *stop_char
== '\0')) {
912 fprintf(stderr
, "%s: invalid numeric value: %s\n", package_name
, val
);
913 return 1; /* failure */
920 /* store the original value */
925 if (value
&& orig_field
) {
930 free (*orig_field
); /* free previous string */
931 *orig_field
= gengetopt_strdup (value
);
940 * @brief store information about a multiple option in a temporary list
941 * @param list where to (temporarily) store multiple options
944 int update_multiple_arg_temp(struct generic_list
**list
,
945 unsigned int *prev_given
, const char *val
,
946 const char *possible_values
[], const char *default_value
,
947 cmdline_parser_arg_type arg_type
,
948 const char *long_opt
, char short_opt
,
949 const char *additional_error
)
951 /* store single arguments */
953 const char *multi_next
;
955 if (arg_type
== ARG_NO
) {
960 multi_token
= get_multiple_arg_token(val
);
961 multi_next
= get_multiple_arg_token_next (val
);
966 if (update_arg((void *)&((*list
)->arg
), &((*list
)->orig
), 0,
967 prev_given
, multi_token
, possible_values
, default_value
,
968 arg_type
, 0, 1, 1, 1, long_opt
, short_opt
, additional_error
)) {
969 if (multi_token
) free(multi_token
);
970 return 1; /* failure */
975 multi_token
= get_multiple_arg_token(multi_next
);
976 multi_next
= get_multiple_arg_token_next (multi_next
);
986 * @brief free the passed list (including possible string argument)
989 void free_list(struct generic_list
*list
, short string_arg
)
992 struct generic_list
*tmp
;
996 if (string_arg
&& list
->arg
.string_arg
)
997 free (list
->arg
.string_arg
);
1007 * @brief updates a multiple option starting from the passed list
1010 void update_multiple_arg(void *field
, char ***orig_field
,
1011 unsigned int field_given
, unsigned int prev_given
, union generic_value
*default_value
,
1012 cmdline_parser_arg_type arg_type
,
1013 struct generic_list
*list
)
1016 struct generic_list
*tmp
;
1018 if (prev_given
&& list
) {
1019 *orig_field
= (char **) realloc (*orig_field
, (field_given
+ prev_given
) * sizeof (char *));
1024 *((int **)field
) = (int *)realloc (*((int **)field
), (field_given
+ prev_given
) * sizeof (int)); break;
1026 *((double **)field
) = (double *)realloc (*((double **)field
), (field_given
+ prev_given
) * sizeof (double)); break;
1028 *((char ***)field
) = (char **)realloc (*((char ***)field
), (field_given
+ prev_given
) * sizeof (char *)); break;
1033 for (i
= (prev_given
- 1); i
>= 0; --i
)
1039 (*((int **)field
))[i
+ field_given
] = tmp
->arg
.int_arg
; break;
1041 (*((double **)field
))[i
+ field_given
] = tmp
->arg
.double_arg
; break;
1043 (*((int **)field
))[i
+ field_given
] = tmp
->arg
.int_arg
; break;
1045 (*((char ***)field
))[i
+ field_given
] = tmp
->arg
.string_arg
; break;
1049 (*orig_field
) [i
+ field_given
] = list
->orig
;
1053 } else { /* set the default value */
1054 if (default_value
&& ! field_given
) {
1058 if (! *((int **)field
)) {
1059 *((int **)field
) = (int *)malloc (sizeof (int));
1060 (*((int **)field
))[0] = default_value
->int_arg
;
1064 if (! *((double **)field
)) {
1065 *((double **)field
) = (double *)malloc (sizeof (double));
1066 (*((double **)field
))[0] = default_value
->double_arg
;
1070 if (! *((char ***)field
)) {
1071 *((char ***)field
) = (char **)malloc (sizeof (char *));
1072 (*((char ***)field
))[0] = gengetopt_strdup(default_value
->string_arg
);
1077 if (!(*orig_field
)) {
1078 *orig_field
= (char **) malloc (sizeof (char *));
1079 (*orig_field
)[0] = 0;
1085 static int check_modes(
1086 int given1
[], const char *options1
[],
1087 int given2
[], const char *options2
[])
1089 int i
= 0, j
= 0, errors
= 0;
1091 while (given1
[i
] >= 0) {
1093 while (given2
[j
] >= 0) {
1096 fprintf(stderr
, "%s: option %s conflicts with option %s\n",
1097 package_name
, options1
[i
], options2
[j
]);
1109 cmdline_parser_internal (
1110 int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
1111 struct cmdline_parser_params
*params
, const char *additional_error
)
1113 int c
; /* Character of the parsed option. */
1114 union generic_value multiple_default_value
;
1116 struct generic_list
* base_vector_list
= NULL
;
1117 struct generic_list
* particle_list
= NULL
;
1118 struct generic_list
* pointfile_list
= NULL
;
1119 struct generic_list
* point_list
= NULL
;
1120 struct generic_list
* omegafile_list
= NULL
;
1121 struct generic_list
* omega_list
= NULL
;
1122 struct generic_list
* kfile_list
= NULL
;
1123 struct generic_list
* k_list
= NULL
;
1124 int error_occurred
= 0;
1125 struct gengetopt_args_info local_args_info
;
1130 int check_ambiguity
;
1132 package_name
= argv
[0];
1134 override
= params
->override
;
1135 initialize
= params
->initialize
;
1136 check_required
= params
->check_required
;
1137 check_ambiguity
= params
->check_ambiguity
;
1140 cmdline_parser_init (args_info
);
1142 cmdline_parser_init (&local_args_info
);
1146 opterr
= params
->print_errors
;
1151 int option_index
= 0;
1153 static struct option long_options
[] = {
1154 { "help", 0, NULL
, 'h' },
1155 { "detailed-help", 0, NULL
, 0 },
1156 { "version", 0, NULL
, 'V' },
1157 { "output", 1, NULL
, 'o' },
1158 { "base-vector", 1, NULL
, 'b' },
1159 { "error-estimate-output", 1, NULL
, 'E' },
1160 { "normalisation", 1, NULL
, 'N' },
1161 { "csphase", 1, NULL
, 'c' },
1162 { "Ewald-parameter", 1, NULL
, 'e' },
1163 { "frequency-unit", 1, NULL
, 'u' },
1164 { "lMax", 1, NULL
, 'L' },
1165 { "refractive-index", 1, NULL
, 'n' },
1166 { "particle", 1, NULL
, 'p' },
1167 { "pointfile", 1, NULL
, 'T' },
1168 { "point", 1, NULL
, 't' },
1169 { "omegafile", 1, NULL
, 'F' },
1170 { "omega", 1, NULL
, 'f' },
1171 { "kfile", 1, NULL
, 'K' },
1172 { "k", 1, NULL
, 'k' },
1176 c
= getopt_long (argc
, argv
, "hVo:b:E:N:c:e:u:L:n:p:T:t:F:f:K:k:", long_options
, &option_index
);
1178 if (c
== -1) break; /* Exit from `while (1)' loop. */
1182 case 'h': /* Print help and exit. */
1183 cmdline_parser_print_help ();
1184 cmdline_parser_free (&local_args_info
);
1185 exit (EXIT_SUCCESS
);
1187 case 'V': /* Print version and exit. */
1188 cmdline_parser_print_version ();
1189 cmdline_parser_free (&local_args_info
);
1190 exit (EXIT_SUCCESS
);
1192 case 'o': /* Output file. */
1195 if (update_arg( (void *)&(args_info
->output_arg
),
1196 &(args_info
->output_orig
), &(args_info
->output_given
),
1197 &(local_args_info
.output_given
), optarg
, 0, "", ARG_STRING
,
1198 check_ambiguity
, override
, 0, 0,
1204 case 'b': /* Base vector. */
1206 if (update_multiple_arg_temp(&base_vector_list
,
1207 &(local_args_info
.base_vector_given
), optarg
, 0, 0, ARG_STRING
,
1213 case 'E': /* Path to the output with error estimates. */
1216 if (update_arg( (void *)&(args_info
->error_estimate_output_arg
),
1217 &(args_info
->error_estimate_output_orig
), &(args_info
->error_estimate_output_given
),
1218 &(local_args_info
.error_estimate_output_given
), optarg
, 0, 0, ARG_STRING
,
1219 check_ambiguity
, override
, 0, 0,
1220 "error-estimate-output", 'E',
1225 case 'N': /* VSWF normalisation convention. */
1228 if (update_arg( (void *)&(args_info
->normalisation_arg
),
1229 &(args_info
->normalisation_orig
), &(args_info
->normalisation_given
),
1230 &(local_args_info
.normalisation_given
), optarg
, cmdline_parser_normalisation_values
, "Power", ARG_ENUM
,
1231 check_ambiguity
, override
, 0, 0,
1232 "normalisation", 'N',
1237 case 'c': /* Whether the Condon-Shortley phase is included in VSWF definition (-1) or not (+1). */
1240 if (update_arg( (void *)&(args_info
->csphase_arg
),
1241 &(args_info
->csphase_orig
), &(args_info
->csphase_given
),
1242 &(local_args_info
.csphase_given
), optarg
, cmdline_parser_csphase_values
, "-1", ARG_INT
,
1243 check_ambiguity
, override
, 0, 0,
1249 case 'e': /* The value of Ewald parameter η. */
1252 if (update_arg( (void *)&(args_info
->Ewald_parameter_arg
),
1253 &(args_info
->Ewald_parameter_orig
), &(args_info
->Ewald_parameter_given
),
1254 &(local_args_info
.Ewald_parameter_given
), optarg
, 0, 0, ARG_DOUBLE
,
1255 check_ambiguity
, override
, 0, 0,
1256 "Ewald-parameter", 'e',
1261 case 'u': /* Specifies the frequency unit is used for inputs.. */
1264 if (update_arg( (void *)&(args_info
->frequency_unit_arg
),
1265 &(args_info
->frequency_unit_orig
), &(args_info
->frequency_unit_given
),
1266 &(local_args_info
.frequency_unit_given
), optarg
, cmdline_parser_frequency_unit_values
, "scuff", ARG_ENUM
,
1267 check_ambiguity
, override
, 0, 0,
1268 "frequency-unit", 'u',
1273 case 'L': /* Maximum spherical multipole order to which the translation operator elements are calculated. */
1276 if (update_arg( (void *)&(args_info
->lMax_arg
),
1277 &(args_info
->lMax_orig
), &(args_info
->lMax_given
),
1278 &(local_args_info
.lMax_given
), optarg
, 0, 0, ARG_INT
,
1279 check_ambiguity
, override
, 0, 0,
1285 case 'n': /* Medium refractive index. */
1288 if (update_arg( (void *)&(args_info
->refractive_index_arg
),
1289 &(args_info
->refractive_index_orig
), &(args_info
->refractive_index_given
),
1290 &(local_args_info
.refractive_index_given
), optarg
, 0, 0, ARG_DOUBLE
,
1291 check_ambiguity
, override
, 0, 0,
1292 "refractive-index", 'n',
1297 case 'p': /* Specify the x and y coordinates of a single particle; If not specified, one particle per unit cell is assumed.. */
1299 if (update_multiple_arg_temp(&particle_list
,
1300 &(local_args_info
.particle_given
), optarg
, 0, 0, ARG_STRING
,
1306 case 'T': /* Path to a file containing frequency, k_x, k_y triples(separated by white spaces). If not specified, read them from stdin.. */
1307 args_info
->k_omega_points_mode_counter
+= 1;
1309 if (update_multiple_arg_temp(&pointfile_list
,
1310 &(local_args_info
.pointfile_given
), optarg
, 0, "-", ARG_STRING
,
1316 case 't': /* Specifies a frequency, k_x, k_y triple, separated by commas.. */
1317 args_info
->k_omega_points_mode_counter
+= 1;
1319 if (update_multiple_arg_temp(&point_list
,
1320 &(local_args_info
.point_given
), optarg
, 0, 0, ARG_STRING
,
1326 case 'F': /* Path to a file containing a list of frequenciesseparated by whitespaces.. */
1327 args_info
->k_omega_meshgrid_mode_counter
+= 1;
1329 if (update_multiple_arg_temp(&omegafile_list
,
1330 &(local_args_info
.omegafile_given
), optarg
, 0, 0, ARG_STRING
,
1336 case 'f': /* Specifies frequency (or multiple frequencies separated by commas) on the command line.. */
1337 args_info
->k_omega_meshgrid_mode_counter
+= 1;
1339 if (update_multiple_arg_temp(&omega_list
,
1340 &(local_args_info
.omega_given
), optarg
, 0, 0, ARG_STRING
,
1346 case 'K': /* Path to a file containing a list of k_x, k_y pairs.. */
1347 args_info
->k_omega_meshgrid_mode_counter
+= 1;
1349 if (update_multiple_arg_temp(&kfile_list
,
1350 &(local_args_info
.kfile_given
), optarg
, 0, "-", ARG_STRING
,
1356 case 'k': /* Specifies pair(s) of k_x, k_y values. */
1357 args_info
->k_omega_meshgrid_mode_counter
+= 1;
1359 if (update_multiple_arg_temp(&k_list
,
1360 &(local_args_info
.k_given
), optarg
, 0, 0, ARG_STRING
,
1367 case 0: /* Long option with no short option */
1368 if (strcmp (long_options
[option_index
].name
, "detailed-help") == 0) {
1369 cmdline_parser_print_detailed_help ();
1370 cmdline_parser_free (&local_args_info
);
1371 exit (EXIT_SUCCESS
);
1374 case '?': /* Invalid option. */
1375 /* `getopt_long' already printed an error message. */
1378 default: /* bug: option not considered. */
1379 fprintf (stderr
, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE
, c
, (additional_error
? additional_error
: ""));
1385 update_multiple_arg((void *)&(args_info
->base_vector_arg
),
1386 &(args_info
->base_vector_orig
), args_info
->base_vector_given
,
1387 local_args_info
.base_vector_given
, 0,
1388 ARG_STRING
, base_vector_list
);
1389 update_multiple_arg((void *)&(args_info
->particle_arg
),
1390 &(args_info
->particle_orig
), args_info
->particle_given
,
1391 local_args_info
.particle_given
, 0,
1392 ARG_STRING
, particle_list
);
1393 multiple_default_value
.default_string_arg
= "-";
1394 update_multiple_arg((void *)&(args_info
->pointfile_arg
),
1395 &(args_info
->pointfile_orig
), args_info
->pointfile_given
,
1396 local_args_info
.pointfile_given
, &multiple_default_value
,
1397 ARG_STRING
, pointfile_list
);
1398 update_multiple_arg((void *)&(args_info
->point_arg
),
1399 &(args_info
->point_orig
), args_info
->point_given
,
1400 local_args_info
.point_given
, 0,
1401 ARG_STRING
, point_list
);
1402 update_multiple_arg((void *)&(args_info
->omegafile_arg
),
1403 &(args_info
->omegafile_orig
), args_info
->omegafile_given
,
1404 local_args_info
.omegafile_given
, 0,
1405 ARG_STRING
, omegafile_list
);
1406 update_multiple_arg((void *)&(args_info
->omega_arg
),
1407 &(args_info
->omega_orig
), args_info
->omega_given
,
1408 local_args_info
.omega_given
, 0,
1409 ARG_STRING
, omega_list
);
1410 multiple_default_value
.default_string_arg
= "-";
1411 update_multiple_arg((void *)&(args_info
->kfile_arg
),
1412 &(args_info
->kfile_orig
), args_info
->kfile_given
,
1413 local_args_info
.kfile_given
, &multiple_default_value
,
1414 ARG_STRING
, kfile_list
);
1415 update_multiple_arg((void *)&(args_info
->k_arg
),
1416 &(args_info
->k_orig
), args_info
->k_given
,
1417 local_args_info
.k_given
, 0,
1418 ARG_STRING
, k_list
);
1420 args_info
->base_vector_given
+= local_args_info
.base_vector_given
;
1421 local_args_info
.base_vector_given
= 0;
1422 args_info
->particle_given
+= local_args_info
.particle_given
;
1423 local_args_info
.particle_given
= 0;
1424 args_info
->pointfile_given
+= local_args_info
.pointfile_given
;
1425 local_args_info
.pointfile_given
= 0;
1426 args_info
->point_given
+= local_args_info
.point_given
;
1427 local_args_info
.point_given
= 0;
1428 args_info
->omegafile_given
+= local_args_info
.omegafile_given
;
1429 local_args_info
.omegafile_given
= 0;
1430 args_info
->omega_given
+= local_args_info
.omega_given
;
1431 local_args_info
.omega_given
= 0;
1432 args_info
->kfile_given
+= local_args_info
.kfile_given
;
1433 local_args_info
.kfile_given
= 0;
1434 args_info
->k_given
+= local_args_info
.k_given
;
1435 local_args_info
.k_given
= 0;
1437 if (args_info
->k_omega_meshgrid_mode_counter
&& args_info
->k_omega_points_mode_counter
) {
1438 int k_omega_meshgrid_given
[] = {args_info
->omegafile_given
, args_info
->omega_given
, args_info
->kfile_given
, args_info
->k_given
, -1};
1439 const char *k_omega_meshgrid_desc
[] = {"--omegafile", "--omega", "--kfile", "--k", 0};
1440 int k_omega_points_given
[] = {args_info
->pointfile_given
, args_info
->point_given
, -1};
1441 const char *k_omega_points_desc
[] = {"--pointfile", "--point", 0};
1442 error_occurred
+= check_modes(k_omega_meshgrid_given
, k_omega_meshgrid_desc
, k_omega_points_given
, k_omega_points_desc
);
1447 error_occurred
+= cmdline_parser_required2 (args_info
, argv
[0], additional_error
);
1450 cmdline_parser_release (&local_args_info
);
1452 if ( error_occurred
)
1453 return (EXIT_FAILURE
);
1458 free_list (base_vector_list
, 1 );
1459 free_list (particle_list
, 1 );
1460 free_list (pointfile_list
, 1 );
1461 free_list (point_list
, 1 );
1462 free_list (omegafile_list
, 1 );
1463 free_list (omega_list
, 1 );
1464 free_list (kfile_list
, 1 );
1465 free_list (k_list
, 1 );
1467 cmdline_parser_release (&local_args_info
);
1468 return (EXIT_FAILURE
);