# | Line 1 | Line 1 | |
---|---|---|
1 | /* | |
2 | < | File autogenerated by gengetopt version 2.14 |
2 | > | File autogenerated by gengetopt version 2.22.4 |
3 | generated with the following command: | |
4 | < | gengetopt -i DynamicProps.ggo -F DynamicPropsCmd |
4 | > | gengetopt |
5 | ||
6 | The developers of gengetopt consider the fixed text that goes in all | |
7 | gengetopt output files to be in the public domain: | |
# | Line 17 | Line 17 | |
17 | #include <stdlib.h> | |
18 | #include <string.h> | |
19 | ||
20 | < | #include "getopt.h" |
20 | > | #ifndef FIX_UNUSED |
21 | > | #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ |
22 | > | #endif |
23 | ||
24 | + | #include <getopt.h> |
25 | + | |
26 | #include "DynamicPropsCmd.h" | |
27 | ||
28 | + | const char *gengetopt_args_info_purpose = ""; |
29 | + | |
30 | + | const char *gengetopt_args_info_usage = "Usage: DynamicProps [OPTIONS]..."; |
31 | + | |
32 | + | const char *gengetopt_args_info_description = ""; |
33 | + | |
34 | + | const char *gengetopt_args_info_help[] = { |
35 | + | " -h, --help Print help and exit", |
36 | + | " -V, --version Print version and exit", |
37 | + | " -i, --input=filename input dump file", |
38 | + | " -o, --output=filename output file name", |
39 | + | " --sele1=selection script select first stuntdouble set", |
40 | + | " --sele2=selection script select second stuntdouble set (if sele2 is not \n set, use script from sele1)", |
41 | + | " --order=INT Lengendre Polynomial Order", |
42 | + | "\n Group: dynamicProps\n an option of this group is required", |
43 | + | " -r, --rcorr rmsd", |
44 | + | " -v, --vcorr velocity correlation function", |
45 | + | " -d, --dcorr dipole correlation function", |
46 | + | " -l, --lcorr Lengendre correlation function", |
47 | + | " --r_rcorr Radial rmsd", |
48 | + | " --thetacorr Angular rmsd", |
49 | + | " --drcorr Directional rmsd for particles with unit \n vectors", |
50 | + | " --helfandEcorr Helfand moment for thermal conductvity", |
51 | + | " --stresscorr Stress tensor correlation function", |
52 | + | 0 |
53 | + | }; |
54 | + | |
55 | + | typedef enum {ARG_NO |
56 | + | , ARG_STRING |
57 | + | , ARG_INT |
58 | + | } cmdline_parser_arg_type; |
59 | + | |
60 | static | |
61 | void clear_given (struct gengetopt_args_info *args_info); | |
62 | static | |
63 | void clear_args (struct gengetopt_args_info *args_info); | |
64 | ||
65 | static int | |
66 | < | cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error); |
66 | > | cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, |
67 | > | struct cmdline_parser_params *params, const char *additional_error); |
68 | ||
69 | static int | |
70 | cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); | |
# | Line 53 | Line 90 | void clear_given (struct gengetopt_args_info *args_inf | |
90 | args_info->thetacorr_given = 0 ; | |
91 | args_info->drcorr_given = 0 ; | |
92 | args_info->helfandEcorr_given = 0 ; | |
93 | + | args_info->stresscorr_given = 0 ; |
94 | args_info->dynamicProps_group_counter = 0 ; | |
95 | } | |
96 | ||
97 | static | |
98 | void clear_args (struct gengetopt_args_info *args_info) | |
99 | { | |
100 | + | FIX_UNUSED (args_info); |
101 | args_info->input_arg = NULL; | |
102 | args_info->input_orig = NULL; | |
103 | args_info->output_arg = NULL; | |
# | Line 71 | Line 110 | void clear_args (struct gengetopt_args_info *args_info | |
110 | ||
111 | } | |
112 | ||
113 | + | static |
114 | + | void init_args_info(struct gengetopt_args_info *args_info) |
115 | + | { |
116 | + | |
117 | + | |
118 | + | args_info->help_help = gengetopt_args_info_help[0] ; |
119 | + | args_info->version_help = gengetopt_args_info_help[1] ; |
120 | + | args_info->input_help = gengetopt_args_info_help[2] ; |
121 | + | args_info->output_help = gengetopt_args_info_help[3] ; |
122 | + | args_info->sele1_help = gengetopt_args_info_help[4] ; |
123 | + | args_info->sele2_help = gengetopt_args_info_help[5] ; |
124 | + | args_info->order_help = gengetopt_args_info_help[6] ; |
125 | + | args_info->rcorr_help = gengetopt_args_info_help[8] ; |
126 | + | args_info->vcorr_help = gengetopt_args_info_help[9] ; |
127 | + | args_info->dcorr_help = gengetopt_args_info_help[10] ; |
128 | + | args_info->lcorr_help = gengetopt_args_info_help[11] ; |
129 | + | args_info->r_rcorr_help = gengetopt_args_info_help[12] ; |
130 | + | args_info->thetacorr_help = gengetopt_args_info_help[13] ; |
131 | + | args_info->drcorr_help = gengetopt_args_info_help[14] ; |
132 | + | args_info->helfandEcorr_help = gengetopt_args_info_help[15] ; |
133 | + | args_info->stresscorr_help = gengetopt_args_info_help[16] ; |
134 | + | |
135 | + | } |
136 | + | |
137 | void | |
138 | cmdline_parser_print_version (void) | |
139 | { | |
140 | < | printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); |
140 | > | printf ("%s %s\n", |
141 | > | (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), |
142 | > | CMDLINE_PARSER_VERSION); |
143 | } | |
144 | ||
145 | + | static void print_help_common(void) { |
146 | + | cmdline_parser_print_version (); |
147 | + | |
148 | + | if (strlen(gengetopt_args_info_purpose) > 0) |
149 | + | printf("\n%s\n", gengetopt_args_info_purpose); |
150 | + | |
151 | + | if (strlen(gengetopt_args_info_usage) > 0) |
152 | + | printf("\n%s\n", gengetopt_args_info_usage); |
153 | + | |
154 | + | printf("\n"); |
155 | + | |
156 | + | if (strlen(gengetopt_args_info_description) > 0) |
157 | + | printf("%s\n\n", gengetopt_args_info_description); |
158 | + | } |
159 | + | |
160 | void | |
161 | cmdline_parser_print_help (void) | |
162 | { | |
163 | < | cmdline_parser_print_version (); |
164 | < | printf("\nUsage: DynamicProps [OPTIONS]...\n\n"); |
165 | < | printf("%s\n"," -h, --help Print help and exit"); |
166 | < | printf("%s\n"," -V, --version Print version and exit"); |
87 | < | printf("%s\n"," -i, --input=filename input dump file"); |
88 | < | printf("%s\n"," -o, --output=filename output file name"); |
89 | < | printf("%s\n"," --sele1=selection script select first stuntdouble set"); |
90 | < | printf("%s\n"," --sele2=selection script select second stuntdouble set (if sele2 is not \n set, use script from sele1)"); |
91 | < | printf("%s\n"," --order=INT Lengendre Polynomial Order"); |
92 | < | printf("%s\n","\n Group: dynamicProps\n an option of this group is required"); |
93 | < | printf("%s\n"," -r, --rcorr rmsd"); |
94 | < | printf("%s\n"," -v, --vcorr velocity correlation function"); |
95 | < | printf("%s\n"," -d, --dcorr dipole correlation function"); |
96 | < | printf("%s\n"," -l, --lcorr Lengendre correlation function"); |
97 | < | printf("%s\n"," --r_rcorr Radial rmsd"); |
98 | < | printf("%s\n"," --thetacorr Angular rmsd"); |
99 | < | printf("%s\n"," --drcorr Directional rmsd for particles with unit \n vectors"); |
100 | < | printf("%s\n"," --helfandEcorr Helfand moment for thermal conductvity"); |
101 | < | |
163 | > | int i = 0; |
164 | > | print_help_common(); |
165 | > | while (gengetopt_args_info_help[i]) |
166 | > | printf("%s\n", gengetopt_args_info_help[i++]); |
167 | } | |
168 | ||
169 | void | |
# | Line 106 | Line 171 | cmdline_parser_init (struct gengetopt_args_info *args_ | |
171 | { | |
172 | clear_given (args_info); | |
173 | clear_args (args_info); | |
174 | + | init_args_info (args_info); |
175 | } | |
176 | ||
177 | + | void |
178 | + | cmdline_parser_params_init(struct cmdline_parser_params *params) |
179 | + | { |
180 | + | if (params) |
181 | + | { |
182 | + | params->override = 0; |
183 | + | params->initialize = 1; |
184 | + | params->check_required = 1; |
185 | + | params->check_ambiguity = 0; |
186 | + | params->print_errors = 1; |
187 | + | } |
188 | + | } |
189 | + | |
190 | + | struct cmdline_parser_params * |
191 | + | cmdline_parser_params_create(void) |
192 | + | { |
193 | + | struct cmdline_parser_params *params = |
194 | + | (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); |
195 | + | cmdline_parser_params_init(params); |
196 | + | return params; |
197 | + | } |
198 | + | |
199 | static void | |
200 | < | cmdline_parser_release (struct gengetopt_args_info *args_info) |
200 | > | free_string_field (char **s) |
201 | { | |
202 | < | |
115 | < | if (args_info->input_arg) |
202 | > | if (*s) |
203 | { | |
204 | < | free (args_info->input_arg); /* free previous argument */ |
205 | < | args_info->input_arg = 0; |
204 | > | free (*s); |
205 | > | *s = 0; |
206 | } | |
207 | < | if (args_info->input_orig) |
208 | < | { |
209 | < | free (args_info->input_orig); /* free previous argument */ |
210 | < | args_info->input_orig = 0; |
211 | < | } |
212 | < | if (args_info->output_arg) |
213 | < | { |
214 | < | free (args_info->output_arg); /* free previous argument */ |
215 | < | args_info->output_arg = 0; |
216 | < | } |
217 | < | if (args_info->output_orig) |
218 | < | { |
219 | < | free (args_info->output_orig); /* free previous argument */ |
220 | < | args_info->output_orig = 0; |
221 | < | } |
222 | < | if (args_info->sele1_arg) |
223 | < | { |
224 | < | free (args_info->sele1_arg); /* free previous argument */ |
225 | < | args_info->sele1_arg = 0; |
226 | < | } |
227 | < | if (args_info->sele1_orig) |
228 | < | { |
229 | < | free (args_info->sele1_orig); /* free previous argument */ |
230 | < | args_info->sele1_orig = 0; |
231 | < | } |
232 | < | if (args_info->sele2_arg) |
233 | < | { |
234 | < | free (args_info->sele2_arg); /* free previous argument */ |
235 | < | args_info->sele2_arg = 0; |
236 | < | } |
237 | < | if (args_info->sele2_orig) |
238 | < | { |
239 | < | free (args_info->sele2_orig); /* free previous argument */ |
240 | < | args_info->sele2_orig = 0; |
241 | < | } |
242 | < | if (args_info->order_orig) |
207 | > | } |
208 | > | |
209 | > | |
210 | > | static void |
211 | > | cmdline_parser_release (struct gengetopt_args_info *args_info) |
212 | > | { |
213 | > | |
214 | > | free_string_field (&(args_info->input_arg)); |
215 | > | free_string_field (&(args_info->input_orig)); |
216 | > | free_string_field (&(args_info->output_arg)); |
217 | > | free_string_field (&(args_info->output_orig)); |
218 | > | free_string_field (&(args_info->sele1_arg)); |
219 | > | free_string_field (&(args_info->sele1_orig)); |
220 | > | free_string_field (&(args_info->sele2_arg)); |
221 | > | free_string_field (&(args_info->sele2_orig)); |
222 | > | free_string_field (&(args_info->order_orig)); |
223 | > | |
224 | > | |
225 | > | |
226 | > | clear_given (args_info); |
227 | > | } |
228 | > | |
229 | > | |
230 | > | static void |
231 | > | write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) |
232 | > | { |
233 | > | FIX_UNUSED (values); |
234 | > | if (arg) { |
235 | > | fprintf(outfile, "%s=\"%s\"\n", opt, arg); |
236 | > | } else { |
237 | > | fprintf(outfile, "%s\n", opt); |
238 | > | } |
239 | > | } |
240 | > | |
241 | > | |
242 | > | int |
243 | > | cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) |
244 | > | { |
245 | > | int i = 0; |
246 | > | |
247 | > | if (!outfile) |
248 | { | |
249 | < | free (args_info->order_orig); /* free previous argument */ |
250 | < | args_info->order_orig = 0; |
249 | > | fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); |
250 | > | return EXIT_FAILURE; |
251 | } | |
252 | + | |
253 | + | if (args_info->help_given) |
254 | + | write_into_file(outfile, "help", 0, 0 ); |
255 | + | if (args_info->version_given) |
256 | + | write_into_file(outfile, "version", 0, 0 ); |
257 | + | if (args_info->input_given) |
258 | + | write_into_file(outfile, "input", args_info->input_orig, 0); |
259 | + | if (args_info->output_given) |
260 | + | write_into_file(outfile, "output", args_info->output_orig, 0); |
261 | + | if (args_info->sele1_given) |
262 | + | write_into_file(outfile, "sele1", args_info->sele1_orig, 0); |
263 | + | if (args_info->sele2_given) |
264 | + | write_into_file(outfile, "sele2", args_info->sele2_orig, 0); |
265 | + | if (args_info->order_given) |
266 | + | write_into_file(outfile, "order", args_info->order_orig, 0); |
267 | + | if (args_info->rcorr_given) |
268 | + | write_into_file(outfile, "rcorr", 0, 0 ); |
269 | + | if (args_info->vcorr_given) |
270 | + | write_into_file(outfile, "vcorr", 0, 0 ); |
271 | + | if (args_info->dcorr_given) |
272 | + | write_into_file(outfile, "dcorr", 0, 0 ); |
273 | + | if (args_info->lcorr_given) |
274 | + | write_into_file(outfile, "lcorr", 0, 0 ); |
275 | + | if (args_info->r_rcorr_given) |
276 | + | write_into_file(outfile, "r_rcorr", 0, 0 ); |
277 | + | if (args_info->thetacorr_given) |
278 | + | write_into_file(outfile, "thetacorr", 0, 0 ); |
279 | + | if (args_info->drcorr_given) |
280 | + | write_into_file(outfile, "drcorr", 0, 0 ); |
281 | + | if (args_info->helfandEcorr_given) |
282 | + | write_into_file(outfile, "helfandEcorr", 0, 0 ); |
283 | + | if (args_info->stresscorr_given) |
284 | + | write_into_file(outfile, "stresscorr", 0, 0 ); |
285 | ||
286 | < | clear_given (args_info); |
286 | > | |
287 | > | i = EXIT_SUCCESS; |
288 | > | return i; |
289 | } | |
290 | ||
291 | int | |
# | Line 175 | Line 302 | cmdline_parser_file_save(const char *filename, struct | |
302 | return EXIT_FAILURE; | |
303 | } | |
304 | ||
305 | < | if (args_info->help_given) { |
179 | < | fprintf(outfile, "%s\n", "help"); |
180 | < | } |
181 | < | if (args_info->version_given) { |
182 | < | fprintf(outfile, "%s\n", "version"); |
183 | < | } |
184 | < | if (args_info->input_given) { |
185 | < | if (args_info->input_orig) { |
186 | < | fprintf(outfile, "%s=\"%s\"\n", "input", args_info->input_orig); |
187 | < | } else { |
188 | < | fprintf(outfile, "%s\n", "input"); |
189 | < | } |
190 | < | } |
191 | < | if (args_info->output_given) { |
192 | < | if (args_info->output_orig) { |
193 | < | fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig); |
194 | < | } else { |
195 | < | fprintf(outfile, "%s\n", "output"); |
196 | < | } |
197 | < | } |
198 | < | if (args_info->sele1_given) { |
199 | < | if (args_info->sele1_orig) { |
200 | < | fprintf(outfile, "%s=\"%s\"\n", "sele1", args_info->sele1_orig); |
201 | < | } else { |
202 | < | fprintf(outfile, "%s\n", "sele1"); |
203 | < | } |
204 | < | } |
205 | < | if (args_info->sele2_given) { |
206 | < | if (args_info->sele2_orig) { |
207 | < | fprintf(outfile, "%s=\"%s\"\n", "sele2", args_info->sele2_orig); |
208 | < | } else { |
209 | < | fprintf(outfile, "%s\n", "sele2"); |
210 | < | } |
211 | < | } |
212 | < | if (args_info->order_given) { |
213 | < | if (args_info->order_orig) { |
214 | < | fprintf(outfile, "%s=\"%s\"\n", "order", args_info->order_orig); |
215 | < | } else { |
216 | < | fprintf(outfile, "%s\n", "order"); |
217 | < | } |
218 | < | } |
219 | < | if (args_info->rcorr_given) { |
220 | < | fprintf(outfile, "%s\n", "rcorr"); |
221 | < | } |
222 | < | if (args_info->vcorr_given) { |
223 | < | fprintf(outfile, "%s\n", "vcorr"); |
224 | < | } |
225 | < | if (args_info->dcorr_given) { |
226 | < | fprintf(outfile, "%s\n", "dcorr"); |
227 | < | } |
228 | < | if (args_info->lcorr_given) { |
229 | < | fprintf(outfile, "%s\n", "lcorr"); |
230 | < | } |
231 | < | if (args_info->r_rcorr_given) { |
232 | < | fprintf(outfile, "%s\n", "r_rcorr"); |
233 | < | } |
234 | < | if (args_info->thetacorr_given) { |
235 | < | fprintf(outfile, "%s\n", "thetacorr"); |
236 | < | } |
237 | < | if (args_info->drcorr_given) { |
238 | < | fprintf(outfile, "%s\n", "drcorr"); |
239 | < | } |
240 | < | if (args_info->helfandEcorr_given) { |
241 | < | fprintf(outfile, "%s\n", "helfandEcorr"); |
242 | < | } |
243 | < | |
305 | > | i = cmdline_parser_dump(outfile, args_info); |
306 | fclose (outfile); | |
307 | ||
246 | – | i = EXIT_SUCCESS; |
308 | return i; | |
309 | } | |
310 | ||
# | Line 253 | Line 314 | cmdline_parser_free (struct gengetopt_args_info *args_ | |
314 | cmdline_parser_release (args_info); | |
315 | } | |
316 | ||
317 | < | |
257 | < | /* gengetopt_strdup() */ |
258 | < | /* strdup.c replacement of strdup, which is not standard */ |
317 | > | /** @brief replacement of strdup, which is not standard */ |
318 | char * | |
319 | gengetopt_strdup (const char *s) | |
320 | { | |
321 | < | char *result = NULL; |
321 | > | char *result = 0; |
322 | if (!s) | |
323 | return result; | |
324 | ||
# | Line 271 | Line 330 | static void | |
330 | } | |
331 | ||
332 | static void | |
274 | – | reset_group_dynamicProps(struct gengetopt_args_info *args_info); |
275 | – | |
276 | – | static void |
333 | reset_group_dynamicProps(struct gengetopt_args_info *args_info) | |
334 | { | |
335 | if (! args_info->dynamicProps_group_counter) | |
# | Line 287 | Line 343 | reset_group_dynamicProps(struct gengetopt_args_info *a | |
343 | args_info->thetacorr_given = 0 ; | |
344 | args_info->drcorr_given = 0 ; | |
345 | args_info->helfandEcorr_given = 0 ; | |
346 | + | args_info->stresscorr_given = 0 ; |
347 | ||
348 | args_info->dynamicProps_group_counter = 0; | |
349 | } | |
350 | ||
351 | int | |
352 | < | cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
352 | > | cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) |
353 | { | |
354 | return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); | |
355 | } | |
356 | ||
357 | int | |
358 | < | cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
358 | > | cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, |
359 | > | struct cmdline_parser_params *params) |
360 | { | |
361 | int result; | |
362 | + | result = cmdline_parser_internal (argc, argv, args_info, params, 0); |
363 | ||
364 | < | result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); |
364 | > | if (result == EXIT_FAILURE) |
365 | > | { |
366 | > | cmdline_parser_free (args_info); |
367 | > | exit (EXIT_FAILURE); |
368 | > | } |
369 | > | |
370 | > | return result; |
371 | > | } |
372 | ||
373 | + | int |
374 | + | cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
375 | + | { |
376 | + | int result; |
377 | + | struct cmdline_parser_params params; |
378 | + | |
379 | + | params.override = override; |
380 | + | params.initialize = initialize; |
381 | + | params.check_required = check_required; |
382 | + | params.check_ambiguity = 0; |
383 | + | params.print_errors = 1; |
384 | + | |
385 | + | result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); |
386 | + | |
387 | if (result == EXIT_FAILURE) | |
388 | { | |
389 | cmdline_parser_free (args_info); | |
# | Line 318 | Line 398 | cmdline_parser_required (struct gengetopt_args_info *a | |
398 | { | |
399 | int result = EXIT_SUCCESS; | |
400 | ||
401 | < | if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) |
401 | > | if (cmdline_parser_required2(args_info, prog_name, 0) > 0) |
402 | result = EXIT_FAILURE; | |
403 | ||
404 | if (result == EXIT_FAILURE) | |
# | Line 334 | Line 414 | cmdline_parser_required2 (struct gengetopt_args_info * | |
414 | cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) | |
415 | { | |
416 | int error = 0; | |
417 | + | FIX_UNUSED (additional_error); |
418 | ||
419 | + | /* checks for required options */ |
420 | if (! args_info->input_given) | |
421 | { | |
422 | fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); | |
423 | error = 1; | |
424 | } | |
425 | + | |
426 | if (args_info->dynamicProps_group_counter == 0) | |
427 | { | |
428 | < | fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required.%s\n", prog_name, args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); |
428 | > | fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required%s.\n", prog_name, args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); |
429 | error = 1; | |
430 | } | |
431 | ||
432 | ||
433 | + | /* checks for dependences among options */ |
434 | + | |
435 | return error; | |
436 | } | |
437 | ||
438 | + | |
439 | + | static char *package_name = 0; |
440 | + | |
441 | + | /** |
442 | + | * @brief updates an option |
443 | + | * @param field the generic pointer to the field to update |
444 | + | * @param orig_field the pointer to the orig field |
445 | + | * @param field_given the pointer to the number of occurrence of this option |
446 | + | * @param prev_given the pointer to the number of occurrence already seen |
447 | + | * @param value the argument for this option (if null no arg was specified) |
448 | + | * @param possible_values the possible values for this option (if specified) |
449 | + | * @param default_value the default value (in case the option only accepts fixed values) |
450 | + | * @param arg_type the type of this option |
451 | + | * @param check_ambiguity @see cmdline_parser_params.check_ambiguity |
452 | + | * @param override @see cmdline_parser_params.override |
453 | + | * @param no_free whether to free a possible previous value |
454 | + | * @param multiple_option whether this is a multiple option |
455 | + | * @param long_opt the corresponding long option |
456 | + | * @param short_opt the corresponding short option (or '-' if none) |
457 | + | * @param additional_error possible further error specification |
458 | + | */ |
459 | + | static |
460 | + | int update_arg(void *field, char **orig_field, |
461 | + | unsigned int *field_given, unsigned int *prev_given, |
462 | + | char *value, const char *possible_values[], |
463 | + | const char *default_value, |
464 | + | cmdline_parser_arg_type arg_type, |
465 | + | int check_ambiguity, int override, |
466 | + | int no_free, int multiple_option, |
467 | + | const char *long_opt, char short_opt, |
468 | + | const char *additional_error) |
469 | + | { |
470 | + | char *stop_char = 0; |
471 | + | const char *val = value; |
472 | + | int found; |
473 | + | char **string_field; |
474 | + | FIX_UNUSED (field); |
475 | + | |
476 | + | stop_char = 0; |
477 | + | found = 0; |
478 | + | |
479 | + | if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) |
480 | + | { |
481 | + | if (short_opt != '-') |
482 | + | fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", |
483 | + | package_name, long_opt, short_opt, |
484 | + | (additional_error ? additional_error : "")); |
485 | + | else |
486 | + | fprintf (stderr, "%s: `--%s' option given more than once%s\n", |
487 | + | package_name, long_opt, |
488 | + | (additional_error ? additional_error : "")); |
489 | + | return 1; /* failure */ |
490 | + | } |
491 | + | |
492 | + | FIX_UNUSED (default_value); |
493 | + | |
494 | + | if (field_given && *field_given && ! override) |
495 | + | return 0; |
496 | + | if (prev_given) |
497 | + | (*prev_given)++; |
498 | + | if (field_given) |
499 | + | (*field_given)++; |
500 | + | if (possible_values) |
501 | + | val = possible_values[found]; |
502 | + | |
503 | + | switch(arg_type) { |
504 | + | case ARG_INT: |
505 | + | if (val) *((int *)field) = strtol (val, &stop_char, 0); |
506 | + | break; |
507 | + | case ARG_STRING: |
508 | + | if (val) { |
509 | + | string_field = (char **)field; |
510 | + | if (!no_free && *string_field) |
511 | + | free (*string_field); /* free previous string */ |
512 | + | *string_field = gengetopt_strdup (val); |
513 | + | } |
514 | + | break; |
515 | + | default: |
516 | + | break; |
517 | + | }; |
518 | + | |
519 | + | /* check numeric conversion */ |
520 | + | switch(arg_type) { |
521 | + | case ARG_INT: |
522 | + | if (val && !(stop_char && *stop_char == '\0')) { |
523 | + | fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); |
524 | + | return 1; /* failure */ |
525 | + | } |
526 | + | break; |
527 | + | default: |
528 | + | ; |
529 | + | }; |
530 | + | |
531 | + | /* store the original value */ |
532 | + | switch(arg_type) { |
533 | + | case ARG_NO: |
534 | + | break; |
535 | + | default: |
536 | + | if (value && orig_field) { |
537 | + | if (no_free) { |
538 | + | *orig_field = value; |
539 | + | } else { |
540 | + | if (*orig_field) |
541 | + | free (*orig_field); /* free previous string */ |
542 | + | *orig_field = gengetopt_strdup (value); |
543 | + | } |
544 | + | } |
545 | + | }; |
546 | + | |
547 | + | return 0; /* OK */ |
548 | + | } |
549 | + | |
550 | + | |
551 | int | |
552 | < | cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error) |
552 | > | cmdline_parser_internal ( |
553 | > | int argc, char **argv, struct gengetopt_args_info *args_info, |
554 | > | struct cmdline_parser_params *params, const char *additional_error) |
555 | { | |
556 | int c; /* Character of the parsed option. */ | |
557 | ||
558 | int error = 0; | |
559 | struct gengetopt_args_info local_args_info; | |
560 | + | |
561 | + | int override; |
562 | + | int initialize; |
563 | + | int check_required; |
564 | + | int check_ambiguity; |
565 | + | |
566 | + | package_name = argv[0]; |
567 | + | |
568 | + | override = params->override; |
569 | + | initialize = params->initialize; |
570 | + | check_required = params->check_required; |
571 | + | check_ambiguity = params->check_ambiguity; |
572 | ||
573 | if (initialize) | |
574 | cmdline_parser_init (args_info); | |
# | Line 364 | Line 576 | cmdline_parser_internal (int argc, char * const *argv, | |
576 | cmdline_parser_init (&local_args_info); | |
577 | ||
578 | optarg = 0; | |
579 | < | optind = 1; |
580 | < | opterr = 1; |
579 | > | optind = 0; |
580 | > | opterr = params->print_errors; |
581 | optopt = '?'; | |
582 | ||
583 | while (1) | |
584 | { | |
585 | int option_index = 0; | |
374 | – | char *stop_char; |
586 | ||
587 | static struct option long_options[] = { | |
588 | { "help", 0, NULL, 'h' }, | |
# | Line 389 | Line 600 | cmdline_parser_internal (int argc, char * const *argv, | |
600 | { "thetacorr", 0, NULL, 0 }, | |
601 | { "drcorr", 0, NULL, 0 }, | |
602 | { "helfandEcorr", 0, NULL, 0 }, | |
603 | < | { NULL, 0, NULL, 0 } |
603 | > | { "stresscorr", 0, NULL, 0 }, |
604 | > | { 0, 0, 0, 0 } |
605 | }; | |
606 | ||
395 | – | stop_char = 0; |
607 | c = getopt_long (argc, argv, "hVi:o:rvdl", long_options, &option_index); | |
608 | ||
609 | if (c == -1) break; /* Exit from `while (1)' loop. */ | |
# | Line 410 | Line 621 | cmdline_parser_internal (int argc, char * const *argv, | |
621 | exit (EXIT_SUCCESS); | |
622 | ||
623 | case 'i': /* input dump file. */ | |
624 | < | if (local_args_info.input_given) |
625 | < | { |
626 | < | fprintf (stderr, "%s: `--input' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
627 | < | goto failure; |
628 | < | } |
629 | < | if (args_info->input_given && ! override) |
630 | < | continue; |
631 | < | local_args_info.input_given = 1; |
632 | < | args_info->input_given = 1; |
633 | < | if (args_info->input_arg) |
423 | < | free (args_info->input_arg); /* free previous string */ |
424 | < | args_info->input_arg = gengetopt_strdup (optarg); |
425 | < | if (args_info->input_orig) |
426 | < | free (args_info->input_orig); /* free previous string */ |
427 | < | args_info->input_orig = gengetopt_strdup (optarg); |
624 | > | |
625 | > | |
626 | > | if (update_arg( (void *)&(args_info->input_arg), |
627 | > | &(args_info->input_orig), &(args_info->input_given), |
628 | > | &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, |
629 | > | check_ambiguity, override, 0, 0, |
630 | > | "input", 'i', |
631 | > | additional_error)) |
632 | > | goto failure; |
633 | > | |
634 | break; | |
429 | – | |
635 | case 'o': /* output file name. */ | |
636 | < | if (local_args_info.output_given) |
637 | < | { |
638 | < | fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
639 | < | goto failure; |
640 | < | } |
641 | < | if (args_info->output_given && ! override) |
642 | < | continue; |
643 | < | local_args_info.output_given = 1; |
644 | < | args_info->output_given = 1; |
645 | < | if (args_info->output_arg) |
441 | < | free (args_info->output_arg); /* free previous string */ |
442 | < | args_info->output_arg = gengetopt_strdup (optarg); |
443 | < | if (args_info->output_orig) |
444 | < | free (args_info->output_orig); /* free previous string */ |
445 | < | args_info->output_orig = gengetopt_strdup (optarg); |
636 | > | |
637 | > | |
638 | > | if (update_arg( (void *)&(args_info->output_arg), |
639 | > | &(args_info->output_orig), &(args_info->output_given), |
640 | > | &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, |
641 | > | check_ambiguity, override, 0, 0, |
642 | > | "output", 'o', |
643 | > | additional_error)) |
644 | > | goto failure; |
645 | > | |
646 | break; | |
447 | – | |
647 | case 'r': /* rmsd. */ | |
648 | < | if (local_args_info.rcorr_given) |
450 | < | { |
451 | < | fprintf (stderr, "%s: `--rcorr' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
452 | < | goto failure; |
453 | < | } |
454 | < | if (args_info->rcorr_given && ! override) |
455 | < | continue; |
456 | < | local_args_info.rcorr_given = 1; |
457 | < | args_info->rcorr_given = 1; |
648 | > | |
649 | if (args_info->dynamicProps_group_counter && override) | |
650 | reset_group_dynamicProps (args_info); | |
651 | args_info->dynamicProps_group_counter += 1; | |
652 | + | |
653 | + | if (update_arg( 0 , |
654 | + | 0 , &(args_info->rcorr_given), |
655 | + | &(local_args_info.rcorr_given), optarg, 0, 0, ARG_NO, |
656 | + | check_ambiguity, override, 0, 0, |
657 | + | "rcorr", 'r', |
658 | + | additional_error)) |
659 | + | goto failure; |
660 | + | |
661 | break; | |
462 | – | |
662 | case 'v': /* velocity correlation function. */ | |
663 | < | if (local_args_info.vcorr_given) |
465 | < | { |
466 | < | fprintf (stderr, "%s: `--vcorr' (`-v') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
467 | < | goto failure; |
468 | < | } |
469 | < | if (args_info->vcorr_given && ! override) |
470 | < | continue; |
471 | < | local_args_info.vcorr_given = 1; |
472 | < | args_info->vcorr_given = 1; |
663 | > | |
664 | if (args_info->dynamicProps_group_counter && override) | |
665 | reset_group_dynamicProps (args_info); | |
666 | args_info->dynamicProps_group_counter += 1; | |
667 | + | |
668 | + | if (update_arg( 0 , |
669 | + | 0 , &(args_info->vcorr_given), |
670 | + | &(local_args_info.vcorr_given), optarg, 0, 0, ARG_NO, |
671 | + | check_ambiguity, override, 0, 0, |
672 | + | "vcorr", 'v', |
673 | + | additional_error)) |
674 | + | goto failure; |
675 | + | |
676 | break; | |
477 | – | |
677 | case 'd': /* dipole correlation function. */ | |
678 | < | if (local_args_info.dcorr_given) |
480 | < | { |
481 | < | fprintf (stderr, "%s: `--dcorr' (`-d') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
482 | < | goto failure; |
483 | < | } |
484 | < | if (args_info->dcorr_given && ! override) |
485 | < | continue; |
486 | < | local_args_info.dcorr_given = 1; |
487 | < | args_info->dcorr_given = 1; |
678 | > | |
679 | if (args_info->dynamicProps_group_counter && override) | |
680 | reset_group_dynamicProps (args_info); | |
681 | args_info->dynamicProps_group_counter += 1; | |
682 | < | break; |
683 | < | |
682 | > | |
683 | > | if (update_arg( 0 , |
684 | > | 0 , &(args_info->dcorr_given), |
685 | > | &(local_args_info.dcorr_given), optarg, 0, 0, ARG_NO, |
686 | > | check_ambiguity, override, 0, 0, |
687 | > | "dcorr", 'd', |
688 | > | additional_error)) |
689 | > | goto failure; |
690 | > | |
691 | > | break; |
692 | case 'l': /* Lengendre correlation function. */ | |
693 | < | if (local_args_info.lcorr_given) |
495 | < | { |
496 | < | fprintf (stderr, "%s: `--lcorr' (`-l') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
497 | < | goto failure; |
498 | < | } |
499 | < | if (args_info->lcorr_given && ! override) |
500 | < | continue; |
501 | < | local_args_info.lcorr_given = 1; |
502 | < | args_info->lcorr_given = 1; |
693 | > | |
694 | if (args_info->dynamicProps_group_counter && override) | |
695 | reset_group_dynamicProps (args_info); | |
696 | args_info->dynamicProps_group_counter += 1; | |
697 | + | |
698 | + | if (update_arg( 0 , |
699 | + | 0 , &(args_info->lcorr_given), |
700 | + | &(local_args_info.lcorr_given), optarg, 0, 0, ARG_NO, |
701 | + | check_ambiguity, override, 0, 0, |
702 | + | "lcorr", 'l', |
703 | + | additional_error)) |
704 | + | goto failure; |
705 | + | |
706 | break; | |
707 | ||
508 | – | |
708 | case 0: /* Long option with no short option */ | |
709 | /* select first stuntdouble set. */ | |
710 | if (strcmp (long_options[option_index].name, "sele1") == 0) | |
711 | { | |
712 | < | if (local_args_info.sele1_given) |
713 | < | { |
714 | < | fprintf (stderr, "%s: `--sele1' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
715 | < | goto failure; |
716 | < | } |
717 | < | if (args_info->sele1_given && ! override) |
718 | < | continue; |
719 | < | local_args_info.sele1_given = 1; |
720 | < | args_info->sele1_given = 1; |
721 | < | if (args_info->sele1_arg) |
523 | < | free (args_info->sele1_arg); /* free previous string */ |
524 | < | args_info->sele1_arg = gengetopt_strdup (optarg); |
525 | < | if (args_info->sele1_orig) |
526 | < | free (args_info->sele1_orig); /* free previous string */ |
527 | < | args_info->sele1_orig = gengetopt_strdup (optarg); |
712 | > | |
713 | > | |
714 | > | if (update_arg( (void *)&(args_info->sele1_arg), |
715 | > | &(args_info->sele1_orig), &(args_info->sele1_given), |
716 | > | &(local_args_info.sele1_given), optarg, 0, 0, ARG_STRING, |
717 | > | check_ambiguity, override, 0, 0, |
718 | > | "sele1", '-', |
719 | > | additional_error)) |
720 | > | goto failure; |
721 | > | |
722 | } | |
723 | /* select second stuntdouble set (if sele2 is not set, use script from sele1). */ | |
724 | else if (strcmp (long_options[option_index].name, "sele2") == 0) | |
725 | { | |
726 | < | if (local_args_info.sele2_given) |
727 | < | { |
728 | < | fprintf (stderr, "%s: `--sele2' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
729 | < | goto failure; |
730 | < | } |
731 | < | if (args_info->sele2_given && ! override) |
732 | < | continue; |
733 | < | local_args_info.sele2_given = 1; |
734 | < | args_info->sele2_given = 1; |
735 | < | if (args_info->sele2_arg) |
542 | < | free (args_info->sele2_arg); /* free previous string */ |
543 | < | args_info->sele2_arg = gengetopt_strdup (optarg); |
544 | < | if (args_info->sele2_orig) |
545 | < | free (args_info->sele2_orig); /* free previous string */ |
546 | < | args_info->sele2_orig = gengetopt_strdup (optarg); |
726 | > | |
727 | > | |
728 | > | if (update_arg( (void *)&(args_info->sele2_arg), |
729 | > | &(args_info->sele2_orig), &(args_info->sele2_given), |
730 | > | &(local_args_info.sele2_given), optarg, 0, 0, ARG_STRING, |
731 | > | check_ambiguity, override, 0, 0, |
732 | > | "sele2", '-', |
733 | > | additional_error)) |
734 | > | goto failure; |
735 | > | |
736 | } | |
737 | /* Lengendre Polynomial Order. */ | |
738 | else if (strcmp (long_options[option_index].name, "order") == 0) | |
739 | { | |
740 | < | if (local_args_info.order_given) |
741 | < | { |
742 | < | fprintf (stderr, "%s: `--order' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
743 | < | goto failure; |
744 | < | } |
745 | < | if (args_info->order_given && ! override) |
746 | < | continue; |
747 | < | local_args_info.order_given = 1; |
748 | < | args_info->order_given = 1; |
749 | < | args_info->order_arg = strtol (optarg,&stop_char,0); |
561 | < | if (args_info->order_orig) |
562 | < | free (args_info->order_orig); /* free previous string */ |
563 | < | args_info->order_orig = gengetopt_strdup (optarg); |
740 | > | |
741 | > | |
742 | > | if (update_arg( (void *)&(args_info->order_arg), |
743 | > | &(args_info->order_orig), &(args_info->order_given), |
744 | > | &(local_args_info.order_given), optarg, 0, 0, ARG_INT, |
745 | > | check_ambiguity, override, 0, 0, |
746 | > | "order", '-', |
747 | > | additional_error)) |
748 | > | goto failure; |
749 | > | |
750 | } | |
751 | /* Radial rmsd. */ | |
752 | else if (strcmp (long_options[option_index].name, "r_rcorr") == 0) | |
753 | { | |
754 | < | if (local_args_info.r_rcorr_given) |
569 | < | { |
570 | < | fprintf (stderr, "%s: `--r_rcorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
571 | < | goto failure; |
572 | < | } |
573 | < | if (args_info->r_rcorr_given && ! override) |
574 | < | continue; |
575 | < | local_args_info.r_rcorr_given = 1; |
576 | < | args_info->r_rcorr_given = 1; |
754 | > | |
755 | if (args_info->dynamicProps_group_counter && override) | |
756 | reset_group_dynamicProps (args_info); | |
757 | args_info->dynamicProps_group_counter += 1; | |
758 | < | break; |
758 | > | |
759 | > | if (update_arg( 0 , |
760 | > | 0 , &(args_info->r_rcorr_given), |
761 | > | &(local_args_info.r_rcorr_given), optarg, 0, 0, ARG_NO, |
762 | > | check_ambiguity, override, 0, 0, |
763 | > | "r_rcorr", '-', |
764 | > | additional_error)) |
765 | > | goto failure; |
766 | > | |
767 | } | |
768 | /* Angular rmsd. */ | |
769 | else if (strcmp (long_options[option_index].name, "thetacorr") == 0) | |
770 | { | |
771 | < | if (local_args_info.thetacorr_given) |
586 | < | { |
587 | < | fprintf (stderr, "%s: `--thetacorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
588 | < | goto failure; |
589 | < | } |
590 | < | if (args_info->thetacorr_given && ! override) |
591 | < | continue; |
592 | < | local_args_info.thetacorr_given = 1; |
593 | < | args_info->thetacorr_given = 1; |
771 | > | |
772 | if (args_info->dynamicProps_group_counter && override) | |
773 | reset_group_dynamicProps (args_info); | |
774 | args_info->dynamicProps_group_counter += 1; | |
775 | < | break; |
775 | > | |
776 | > | if (update_arg( 0 , |
777 | > | 0 , &(args_info->thetacorr_given), |
778 | > | &(local_args_info.thetacorr_given), optarg, 0, 0, ARG_NO, |
779 | > | check_ambiguity, override, 0, 0, |
780 | > | "thetacorr", '-', |
781 | > | additional_error)) |
782 | > | goto failure; |
783 | > | |
784 | } | |
785 | /* Directional rmsd for particles with unit vectors. */ | |
786 | else if (strcmp (long_options[option_index].name, "drcorr") == 0) | |
787 | { | |
788 | < | if (local_args_info.drcorr_given) |
603 | < | { |
604 | < | fprintf (stderr, "%s: `--drcorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
605 | < | goto failure; |
606 | < | } |
607 | < | if (args_info->drcorr_given && ! override) |
608 | < | continue; |
609 | < | local_args_info.drcorr_given = 1; |
610 | < | args_info->drcorr_given = 1; |
788 | > | |
789 | if (args_info->dynamicProps_group_counter && override) | |
790 | reset_group_dynamicProps (args_info); | |
791 | args_info->dynamicProps_group_counter += 1; | |
792 | < | break; |
792 | > | |
793 | > | if (update_arg( 0 , |
794 | > | 0 , &(args_info->drcorr_given), |
795 | > | &(local_args_info.drcorr_given), optarg, 0, 0, ARG_NO, |
796 | > | check_ambiguity, override, 0, 0, |
797 | > | "drcorr", '-', |
798 | > | additional_error)) |
799 | > | goto failure; |
800 | > | |
801 | } | |
802 | /* Helfand moment for thermal conductvity. */ | |
803 | else if (strcmp (long_options[option_index].name, "helfandEcorr") == 0) | |
804 | { | |
805 | < | if (local_args_info.helfandEcorr_given) |
620 | < | { |
621 | < | fprintf (stderr, "%s: `--helfandEcorr' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
622 | < | goto failure; |
623 | < | } |
624 | < | if (args_info->helfandEcorr_given && ! override) |
625 | < | continue; |
626 | < | local_args_info.helfandEcorr_given = 1; |
627 | < | args_info->helfandEcorr_given = 1; |
805 | > | |
806 | if (args_info->dynamicProps_group_counter && override) | |
807 | reset_group_dynamicProps (args_info); | |
808 | args_info->dynamicProps_group_counter += 1; | |
809 | < | break; |
809 | > | |
810 | > | if (update_arg( 0 , |
811 | > | 0 , &(args_info->helfandEcorr_given), |
812 | > | &(local_args_info.helfandEcorr_given), optarg, 0, 0, ARG_NO, |
813 | > | check_ambiguity, override, 0, 0, |
814 | > | "helfandEcorr", '-', |
815 | > | additional_error)) |
816 | > | goto failure; |
817 | > | |
818 | } | |
819 | + | /* Stress tensor correlation function. */ |
820 | + | else if (strcmp (long_options[option_index].name, "stresscorr") == 0) |
821 | + | { |
822 | ||
823 | + | if (args_info->dynamicProps_group_counter && override) |
824 | + | reset_group_dynamicProps (args_info); |
825 | + | args_info->dynamicProps_group_counter += 1; |
826 | + | |
827 | + | if (update_arg( 0 , |
828 | + | 0 , &(args_info->stresscorr_given), |
829 | + | &(local_args_info.stresscorr_given), optarg, 0, 0, ARG_NO, |
830 | + | check_ambiguity, override, 0, 0, |
831 | + | "stresscorr", '-', |
832 | + | additional_error)) |
833 | + | goto failure; |
834 | + | |
835 | + | } |
836 | + | |
837 | break; | |
838 | case '?': /* Invalid option. */ | |
839 | /* `getopt_long' already printed an error message. */ | |
# | Line 644 | Line 847 | cmdline_parser_internal (int argc, char * const *argv, | |
847 | ||
848 | if (args_info->dynamicProps_group_counter > 1) | |
849 | { | |
850 | < | fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required.%s\n", argv[0], args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); |
850 | > | fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required%s.\n", argv[0], args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); |
851 | error = 1; | |
852 | } | |
853 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |