1 |
gezelter |
2024 |
/* |
2 |
|
|
File autogenerated by gengetopt version 2.22.4 |
3 |
|
|
generated with the following command: |
4 |
|
|
gengetopt --file-name=SequentialPropsCmd --unamed-opts |
5 |
|
|
|
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. |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
/* If we use autoconf. */ |
12 |
|
|
#ifdef HAVE_CONFIG_H |
13 |
|
|
#include "config.h" |
14 |
|
|
#endif |
15 |
|
|
|
16 |
|
|
#include <stdio.h> |
17 |
|
|
#include <stdlib.h> |
18 |
|
|
#include <string.h> |
19 |
|
|
|
20 |
|
|
#ifndef FIX_UNUSED |
21 |
|
|
#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ |
22 |
|
|
#endif |
23 |
|
|
|
24 |
|
|
#ifdef WIN32 |
25 |
|
|
#include "utils/wingetopt.h" |
26 |
|
|
#else |
27 |
|
|
#include <getopt.h> |
28 |
|
|
#endif |
29 |
|
|
|
30 |
|
|
#include "SequentialPropsCmd.h" |
31 |
|
|
|
32 |
|
|
const char *gengetopt_args_info_purpose = ""; |
33 |
|
|
|
34 |
|
|
const char *gengetopt_args_info_usage = "Usage: SequentialProps [OPTIONS]... [FILES]..."; |
35 |
|
|
|
36 |
|
|
const char *gengetopt_args_info_description = ""; |
37 |
|
|
|
38 |
|
|
const char *gengetopt_args_info_help[] = { |
39 |
|
|
" -h, --help Print help and exit", |
40 |
|
|
" -V, --version Print version and exit", |
41 |
|
|
" -i, --input=filename input dump file", |
42 |
|
|
" -o, --output=filename output file name", |
43 |
|
|
" --sele1=selection script select first stuntdouble set", |
44 |
|
|
" --sele2=selection script select second stuntdouble set (if sele2 is not \n set, use script from sele1)", |
45 |
gezelter |
2035 |
" -b, --nbins=INT number of bins (general purpose) \n (default=`100')", |
46 |
|
|
" --nbins_z=INT number of bins in z axis (default=`100')", |
47 |
gezelter |
2029 |
" -z, --referenceZ=DOUBLE Reference z-height of solid surface", |
48 |
|
|
" -r, --dropletR=DOUBLE Droplet radius in angstroms", |
49 |
gezelter |
2035 |
" --threshDens=DOUBLE Threshold Density in g/cm^3", |
50 |
gezelter |
2024 |
"\n Group: sequentialProps\n an option of this group is required", |
51 |
gezelter |
2029 |
" -c, --com selection center of mass", |
52 |
|
|
" --ca1 contact angle of selection (using center of \n mass)", |
53 |
|
|
" --ca2 contact angle of selection (using density \n profile)", |
54 |
gezelter |
2024 |
0 |
55 |
|
|
}; |
56 |
|
|
|
57 |
|
|
typedef enum {ARG_NO |
58 |
|
|
, ARG_STRING |
59 |
|
|
, ARG_INT |
60 |
gezelter |
2029 |
, ARG_DOUBLE |
61 |
gezelter |
2024 |
} cmdline_parser_arg_type; |
62 |
|
|
|
63 |
|
|
static |
64 |
|
|
void clear_given (struct gengetopt_args_info *args_info); |
65 |
|
|
static |
66 |
|
|
void clear_args (struct gengetopt_args_info *args_info); |
67 |
|
|
|
68 |
|
|
static int |
69 |
|
|
cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, |
70 |
|
|
struct cmdline_parser_params *params, const char *additional_error); |
71 |
|
|
|
72 |
|
|
static int |
73 |
|
|
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); |
74 |
|
|
|
75 |
|
|
static char * |
76 |
|
|
gengetopt_strdup (const char *s); |
77 |
|
|
|
78 |
|
|
static |
79 |
|
|
void clear_given (struct gengetopt_args_info *args_info) |
80 |
|
|
{ |
81 |
|
|
args_info->help_given = 0 ; |
82 |
|
|
args_info->version_given = 0 ; |
83 |
|
|
args_info->input_given = 0 ; |
84 |
|
|
args_info->output_given = 0 ; |
85 |
|
|
args_info->sele1_given = 0 ; |
86 |
|
|
args_info->sele2_given = 0 ; |
87 |
|
|
args_info->nbins_given = 0 ; |
88 |
gezelter |
2035 |
args_info->nbins_z_given = 0 ; |
89 |
gezelter |
2029 |
args_info->referenceZ_given = 0 ; |
90 |
|
|
args_info->dropletR_given = 0 ; |
91 |
gezelter |
2035 |
args_info->threshDens_given = 0 ; |
92 |
gezelter |
2029 |
args_info->com_given = 0 ; |
93 |
|
|
args_info->ca1_given = 0 ; |
94 |
|
|
args_info->ca2_given = 0 ; |
95 |
gezelter |
2024 |
args_info->sequentialProps_group_counter = 0 ; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
static |
99 |
|
|
void clear_args (struct gengetopt_args_info *args_info) |
100 |
|
|
{ |
101 |
|
|
FIX_UNUSED (args_info); |
102 |
|
|
args_info->input_arg = NULL; |
103 |
|
|
args_info->input_orig = NULL; |
104 |
|
|
args_info->output_arg = NULL; |
105 |
|
|
args_info->output_orig = NULL; |
106 |
|
|
args_info->sele1_arg = NULL; |
107 |
|
|
args_info->sele1_orig = NULL; |
108 |
|
|
args_info->sele2_arg = NULL; |
109 |
|
|
args_info->sele2_orig = NULL; |
110 |
|
|
args_info->nbins_arg = 100; |
111 |
|
|
args_info->nbins_orig = NULL; |
112 |
gezelter |
2035 |
args_info->nbins_z_arg = 100; |
113 |
|
|
args_info->nbins_z_orig = NULL; |
114 |
gezelter |
2029 |
args_info->referenceZ_orig = NULL; |
115 |
|
|
args_info->dropletR_orig = NULL; |
116 |
gezelter |
2035 |
args_info->threshDens_orig = NULL; |
117 |
gezelter |
2024 |
|
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
static |
121 |
|
|
void init_args_info(struct gengetopt_args_info *args_info) |
122 |
|
|
{ |
123 |
|
|
|
124 |
|
|
|
125 |
|
|
args_info->help_help = gengetopt_args_info_help[0] ; |
126 |
|
|
args_info->version_help = gengetopt_args_info_help[1] ; |
127 |
|
|
args_info->input_help = gengetopt_args_info_help[2] ; |
128 |
|
|
args_info->output_help = gengetopt_args_info_help[3] ; |
129 |
|
|
args_info->sele1_help = gengetopt_args_info_help[4] ; |
130 |
|
|
args_info->sele2_help = gengetopt_args_info_help[5] ; |
131 |
|
|
args_info->nbins_help = gengetopt_args_info_help[6] ; |
132 |
gezelter |
2035 |
args_info->nbins_z_help = gengetopt_args_info_help[7] ; |
133 |
|
|
args_info->referenceZ_help = gengetopt_args_info_help[8] ; |
134 |
|
|
args_info->dropletR_help = gengetopt_args_info_help[9] ; |
135 |
|
|
args_info->threshDens_help = gengetopt_args_info_help[10] ; |
136 |
|
|
args_info->com_help = gengetopt_args_info_help[12] ; |
137 |
|
|
args_info->ca1_help = gengetopt_args_info_help[13] ; |
138 |
|
|
args_info->ca2_help = gengetopt_args_info_help[14] ; |
139 |
gezelter |
2024 |
|
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
void |
143 |
|
|
cmdline_parser_print_version (void) |
144 |
|
|
{ |
145 |
|
|
printf ("%s %s\n", |
146 |
|
|
(strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), |
147 |
|
|
CMDLINE_PARSER_VERSION); |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
static void print_help_common(void) { |
151 |
|
|
cmdline_parser_print_version (); |
152 |
|
|
|
153 |
|
|
if (strlen(gengetopt_args_info_purpose) > 0) |
154 |
|
|
printf("\n%s\n", gengetopt_args_info_purpose); |
155 |
|
|
|
156 |
|
|
if (strlen(gengetopt_args_info_usage) > 0) |
157 |
|
|
printf("\n%s\n", gengetopt_args_info_usage); |
158 |
|
|
|
159 |
|
|
printf("\n"); |
160 |
|
|
|
161 |
|
|
if (strlen(gengetopt_args_info_description) > 0) |
162 |
|
|
printf("%s\n\n", gengetopt_args_info_description); |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
void |
166 |
|
|
cmdline_parser_print_help (void) |
167 |
|
|
{ |
168 |
|
|
int i = 0; |
169 |
|
|
print_help_common(); |
170 |
|
|
while (gengetopt_args_info_help[i]) |
171 |
|
|
printf("%s\n", gengetopt_args_info_help[i++]); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
void |
175 |
|
|
cmdline_parser_init (struct gengetopt_args_info *args_info) |
176 |
|
|
{ |
177 |
|
|
clear_given (args_info); |
178 |
|
|
clear_args (args_info); |
179 |
|
|
init_args_info (args_info); |
180 |
|
|
|
181 |
|
|
args_info->inputs = 0; |
182 |
|
|
args_info->inputs_num = 0; |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
void |
186 |
|
|
cmdline_parser_params_init(struct cmdline_parser_params *params) |
187 |
|
|
{ |
188 |
|
|
if (params) |
189 |
|
|
{ |
190 |
|
|
params->override = 0; |
191 |
|
|
params->initialize = 1; |
192 |
|
|
params->check_required = 1; |
193 |
|
|
params->check_ambiguity = 0; |
194 |
|
|
params->print_errors = 1; |
195 |
|
|
} |
196 |
|
|
} |
197 |
|
|
|
198 |
|
|
struct cmdline_parser_params * |
199 |
|
|
cmdline_parser_params_create(void) |
200 |
|
|
{ |
201 |
|
|
struct cmdline_parser_params *params = |
202 |
|
|
(struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); |
203 |
|
|
cmdline_parser_params_init(params); |
204 |
|
|
return params; |
205 |
|
|
} |
206 |
|
|
|
207 |
|
|
static void |
208 |
|
|
free_string_field (char **s) |
209 |
|
|
{ |
210 |
|
|
if (*s) |
211 |
|
|
{ |
212 |
|
|
free (*s); |
213 |
|
|
*s = 0; |
214 |
|
|
} |
215 |
|
|
} |
216 |
|
|
|
217 |
|
|
|
218 |
|
|
static void |
219 |
|
|
cmdline_parser_release (struct gengetopt_args_info *args_info) |
220 |
|
|
{ |
221 |
|
|
unsigned int i; |
222 |
|
|
free_string_field (&(args_info->input_arg)); |
223 |
|
|
free_string_field (&(args_info->input_orig)); |
224 |
|
|
free_string_field (&(args_info->output_arg)); |
225 |
|
|
free_string_field (&(args_info->output_orig)); |
226 |
|
|
free_string_field (&(args_info->sele1_arg)); |
227 |
|
|
free_string_field (&(args_info->sele1_orig)); |
228 |
|
|
free_string_field (&(args_info->sele2_arg)); |
229 |
|
|
free_string_field (&(args_info->sele2_orig)); |
230 |
|
|
free_string_field (&(args_info->nbins_orig)); |
231 |
gezelter |
2035 |
free_string_field (&(args_info->nbins_z_orig)); |
232 |
gezelter |
2029 |
free_string_field (&(args_info->referenceZ_orig)); |
233 |
|
|
free_string_field (&(args_info->dropletR_orig)); |
234 |
gezelter |
2035 |
free_string_field (&(args_info->threshDens_orig)); |
235 |
gezelter |
2024 |
|
236 |
|
|
|
237 |
|
|
for (i = 0; i < args_info->inputs_num; ++i) |
238 |
|
|
free (args_info->inputs [i]); |
239 |
|
|
|
240 |
|
|
if (args_info->inputs_num) |
241 |
|
|
free (args_info->inputs); |
242 |
|
|
|
243 |
|
|
clear_given (args_info); |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
|
247 |
|
|
static void |
248 |
|
|
write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) |
249 |
|
|
{ |
250 |
|
|
FIX_UNUSED (values); |
251 |
|
|
if (arg) { |
252 |
|
|
fprintf(outfile, "%s=\"%s\"\n", opt, arg); |
253 |
|
|
} else { |
254 |
|
|
fprintf(outfile, "%s\n", opt); |
255 |
|
|
} |
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
|
259 |
|
|
int |
260 |
|
|
cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) |
261 |
|
|
{ |
262 |
|
|
int i = 0; |
263 |
|
|
|
264 |
|
|
if (!outfile) |
265 |
|
|
{ |
266 |
|
|
fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); |
267 |
|
|
return EXIT_FAILURE; |
268 |
|
|
} |
269 |
|
|
|
270 |
|
|
if (args_info->help_given) |
271 |
|
|
write_into_file(outfile, "help", 0, 0 ); |
272 |
|
|
if (args_info->version_given) |
273 |
|
|
write_into_file(outfile, "version", 0, 0 ); |
274 |
|
|
if (args_info->input_given) |
275 |
|
|
write_into_file(outfile, "input", args_info->input_orig, 0); |
276 |
|
|
if (args_info->output_given) |
277 |
|
|
write_into_file(outfile, "output", args_info->output_orig, 0); |
278 |
|
|
if (args_info->sele1_given) |
279 |
|
|
write_into_file(outfile, "sele1", args_info->sele1_orig, 0); |
280 |
|
|
if (args_info->sele2_given) |
281 |
|
|
write_into_file(outfile, "sele2", args_info->sele2_orig, 0); |
282 |
|
|
if (args_info->nbins_given) |
283 |
|
|
write_into_file(outfile, "nbins", args_info->nbins_orig, 0); |
284 |
gezelter |
2035 |
if (args_info->nbins_z_given) |
285 |
|
|
write_into_file(outfile, "nbins_z", args_info->nbins_z_orig, 0); |
286 |
gezelter |
2029 |
if (args_info->referenceZ_given) |
287 |
|
|
write_into_file(outfile, "referenceZ", args_info->referenceZ_orig, 0); |
288 |
|
|
if (args_info->dropletR_given) |
289 |
|
|
write_into_file(outfile, "dropletR", args_info->dropletR_orig, 0); |
290 |
gezelter |
2035 |
if (args_info->threshDens_given) |
291 |
|
|
write_into_file(outfile, "threshDens", args_info->threshDens_orig, 0); |
292 |
gezelter |
2029 |
if (args_info->com_given) |
293 |
|
|
write_into_file(outfile, "com", 0, 0 ); |
294 |
|
|
if (args_info->ca1_given) |
295 |
|
|
write_into_file(outfile, "ca1", 0, 0 ); |
296 |
|
|
if (args_info->ca2_given) |
297 |
|
|
write_into_file(outfile, "ca2", 0, 0 ); |
298 |
gezelter |
2024 |
|
299 |
|
|
|
300 |
|
|
i = EXIT_SUCCESS; |
301 |
|
|
return i; |
302 |
|
|
} |
303 |
|
|
|
304 |
|
|
int |
305 |
|
|
cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) |
306 |
|
|
{ |
307 |
|
|
FILE *outfile; |
308 |
|
|
int i = 0; |
309 |
|
|
|
310 |
|
|
outfile = fopen(filename, "w"); |
311 |
|
|
|
312 |
|
|
if (!outfile) |
313 |
|
|
{ |
314 |
|
|
fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); |
315 |
|
|
return EXIT_FAILURE; |
316 |
|
|
} |
317 |
|
|
|
318 |
|
|
i = cmdline_parser_dump(outfile, args_info); |
319 |
|
|
fclose (outfile); |
320 |
|
|
|
321 |
|
|
return i; |
322 |
|
|
} |
323 |
|
|
|
324 |
|
|
void |
325 |
|
|
cmdline_parser_free (struct gengetopt_args_info *args_info) |
326 |
|
|
{ |
327 |
|
|
cmdline_parser_release (args_info); |
328 |
|
|
} |
329 |
|
|
|
330 |
|
|
/** @brief replacement of strdup, which is not standard */ |
331 |
|
|
char * |
332 |
|
|
gengetopt_strdup (const char *s) |
333 |
|
|
{ |
334 |
|
|
char *result = 0; |
335 |
|
|
if (!s) |
336 |
|
|
return result; |
337 |
|
|
|
338 |
|
|
result = (char*)malloc(strlen(s) + 1); |
339 |
|
|
if (result == (char*)0) |
340 |
|
|
return (char*)0; |
341 |
|
|
strcpy(result, s); |
342 |
|
|
return result; |
343 |
|
|
} |
344 |
|
|
|
345 |
|
|
static void |
346 |
|
|
reset_group_sequentialProps(struct gengetopt_args_info *args_info) |
347 |
|
|
{ |
348 |
|
|
if (! args_info->sequentialProps_group_counter) |
349 |
|
|
return; |
350 |
|
|
|
351 |
gezelter |
2029 |
args_info->com_given = 0 ; |
352 |
|
|
args_info->ca1_given = 0 ; |
353 |
|
|
args_info->ca2_given = 0 ; |
354 |
gezelter |
2024 |
|
355 |
|
|
args_info->sequentialProps_group_counter = 0; |
356 |
|
|
} |
357 |
|
|
|
358 |
|
|
int |
359 |
|
|
cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) |
360 |
|
|
{ |
361 |
|
|
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
362 |
|
|
} |
363 |
|
|
|
364 |
|
|
int |
365 |
|
|
cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, |
366 |
|
|
struct cmdline_parser_params *params) |
367 |
|
|
{ |
368 |
|
|
int result; |
369 |
|
|
result = cmdline_parser_internal (argc, argv, args_info, params, 0); |
370 |
|
|
|
371 |
|
|
if (result == EXIT_FAILURE) |
372 |
|
|
{ |
373 |
|
|
cmdline_parser_free (args_info); |
374 |
|
|
exit (EXIT_FAILURE); |
375 |
|
|
} |
376 |
|
|
|
377 |
|
|
return result; |
378 |
|
|
} |
379 |
|
|
|
380 |
|
|
int |
381 |
|
|
cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
382 |
|
|
{ |
383 |
|
|
int result; |
384 |
|
|
struct cmdline_parser_params params; |
385 |
|
|
|
386 |
|
|
params.override = override; |
387 |
|
|
params.initialize = initialize; |
388 |
|
|
params.check_required = check_required; |
389 |
|
|
params.check_ambiguity = 0; |
390 |
|
|
params.print_errors = 1; |
391 |
|
|
|
392 |
|
|
result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); |
393 |
|
|
|
394 |
|
|
if (result == EXIT_FAILURE) |
395 |
|
|
{ |
396 |
|
|
cmdline_parser_free (args_info); |
397 |
|
|
exit (EXIT_FAILURE); |
398 |
|
|
} |
399 |
|
|
|
400 |
|
|
return result; |
401 |
|
|
} |
402 |
|
|
|
403 |
|
|
int |
404 |
|
|
cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) |
405 |
|
|
{ |
406 |
|
|
int result = EXIT_SUCCESS; |
407 |
|
|
|
408 |
|
|
if (cmdline_parser_required2(args_info, prog_name, 0) > 0) |
409 |
|
|
result = EXIT_FAILURE; |
410 |
|
|
|
411 |
|
|
if (result == EXIT_FAILURE) |
412 |
|
|
{ |
413 |
|
|
cmdline_parser_free (args_info); |
414 |
|
|
exit (EXIT_FAILURE); |
415 |
|
|
} |
416 |
|
|
|
417 |
|
|
return result; |
418 |
|
|
} |
419 |
|
|
|
420 |
|
|
int |
421 |
|
|
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) |
422 |
|
|
{ |
423 |
|
|
int error = 0; |
424 |
|
|
FIX_UNUSED (additional_error); |
425 |
|
|
|
426 |
|
|
/* checks for required options */ |
427 |
|
|
if (! args_info->input_given) |
428 |
|
|
{ |
429 |
|
|
fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); |
430 |
|
|
error = 1; |
431 |
|
|
} |
432 |
|
|
|
433 |
|
|
if (args_info->sequentialProps_group_counter == 0) |
434 |
|
|
{ |
435 |
|
|
fprintf (stderr, "%s: %d options of group sequentialProps were given. One is required%s.\n", prog_name, args_info->sequentialProps_group_counter, (additional_error ? additional_error : "")); |
436 |
|
|
error = 1; |
437 |
|
|
} |
438 |
|
|
|
439 |
|
|
|
440 |
|
|
/* checks for dependences among options */ |
441 |
|
|
|
442 |
|
|
return error; |
443 |
|
|
} |
444 |
|
|
|
445 |
|
|
|
446 |
|
|
static char *package_name = 0; |
447 |
|
|
|
448 |
|
|
/** |
449 |
|
|
* @brief updates an option |
450 |
|
|
* @param field the generic pointer to the field to update |
451 |
|
|
* @param orig_field the pointer to the orig field |
452 |
|
|
* @param field_given the pointer to the number of occurrence of this option |
453 |
|
|
* @param prev_given the pointer to the number of occurrence already seen |
454 |
|
|
* @param value the argument for this option (if null no arg was specified) |
455 |
|
|
* @param possible_values the possible values for this option (if specified) |
456 |
|
|
* @param default_value the default value (in case the option only accepts fixed values) |
457 |
|
|
* @param arg_type the type of this option |
458 |
|
|
* @param check_ambiguity @see cmdline_parser_params.check_ambiguity |
459 |
|
|
* @param override @see cmdline_parser_params.override |
460 |
|
|
* @param no_free whether to free a possible previous value |
461 |
|
|
* @param multiple_option whether this is a multiple option |
462 |
|
|
* @param long_opt the corresponding long option |
463 |
|
|
* @param short_opt the corresponding short option (or '-' if none) |
464 |
|
|
* @param additional_error possible further error specification |
465 |
|
|
*/ |
466 |
|
|
static |
467 |
|
|
int update_arg(void *field, char **orig_field, |
468 |
|
|
unsigned int *field_given, unsigned int *prev_given, |
469 |
|
|
char *value, const char *possible_values[], |
470 |
|
|
const char *default_value, |
471 |
|
|
cmdline_parser_arg_type arg_type, |
472 |
|
|
int check_ambiguity, int override, |
473 |
|
|
int no_free, int multiple_option, |
474 |
|
|
const char *long_opt, char short_opt, |
475 |
|
|
const char *additional_error) |
476 |
|
|
{ |
477 |
|
|
char *stop_char = 0; |
478 |
|
|
const char *val = value; |
479 |
|
|
int found; |
480 |
|
|
char **string_field; |
481 |
|
|
FIX_UNUSED (field); |
482 |
|
|
|
483 |
|
|
stop_char = 0; |
484 |
|
|
found = 0; |
485 |
|
|
|
486 |
|
|
if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) |
487 |
|
|
{ |
488 |
|
|
if (short_opt != '-') |
489 |
|
|
fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", |
490 |
|
|
package_name, long_opt, short_opt, |
491 |
|
|
(additional_error ? additional_error : "")); |
492 |
|
|
else |
493 |
|
|
fprintf (stderr, "%s: `--%s' option given more than once%s\n", |
494 |
|
|
package_name, long_opt, |
495 |
|
|
(additional_error ? additional_error : "")); |
496 |
|
|
return 1; /* failure */ |
497 |
|
|
} |
498 |
|
|
|
499 |
|
|
FIX_UNUSED (default_value); |
500 |
|
|
|
501 |
|
|
if (field_given && *field_given && ! override) |
502 |
|
|
return 0; |
503 |
|
|
if (prev_given) |
504 |
|
|
(*prev_given)++; |
505 |
|
|
if (field_given) |
506 |
|
|
(*field_given)++; |
507 |
|
|
if (possible_values) |
508 |
|
|
val = possible_values[found]; |
509 |
|
|
|
510 |
|
|
switch(arg_type) { |
511 |
|
|
case ARG_INT: |
512 |
|
|
if (val) *((int *)field) = strtol (val, &stop_char, 0); |
513 |
|
|
break; |
514 |
gezelter |
2029 |
case ARG_DOUBLE: |
515 |
|
|
if (val) *((double *)field) = strtod (val, &stop_char); |
516 |
|
|
break; |
517 |
gezelter |
2024 |
case ARG_STRING: |
518 |
|
|
if (val) { |
519 |
|
|
string_field = (char **)field; |
520 |
|
|
if (!no_free && *string_field) |
521 |
|
|
free (*string_field); /* free previous string */ |
522 |
|
|
*string_field = gengetopt_strdup (val); |
523 |
|
|
} |
524 |
|
|
break; |
525 |
|
|
default: |
526 |
|
|
break; |
527 |
|
|
}; |
528 |
|
|
|
529 |
|
|
/* check numeric conversion */ |
530 |
|
|
switch(arg_type) { |
531 |
|
|
case ARG_INT: |
532 |
gezelter |
2029 |
case ARG_DOUBLE: |
533 |
gezelter |
2024 |
if (val && !(stop_char && *stop_char == '\0')) { |
534 |
|
|
fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); |
535 |
|
|
return 1; /* failure */ |
536 |
|
|
} |
537 |
|
|
break; |
538 |
|
|
default: |
539 |
|
|
; |
540 |
|
|
}; |
541 |
|
|
|
542 |
|
|
/* store the original value */ |
543 |
|
|
switch(arg_type) { |
544 |
|
|
case ARG_NO: |
545 |
|
|
break; |
546 |
|
|
default: |
547 |
|
|
if (value && orig_field) { |
548 |
|
|
if (no_free) { |
549 |
|
|
*orig_field = value; |
550 |
|
|
} else { |
551 |
|
|
if (*orig_field) |
552 |
|
|
free (*orig_field); /* free previous string */ |
553 |
|
|
*orig_field = gengetopt_strdup (value); |
554 |
|
|
} |
555 |
|
|
} |
556 |
|
|
}; |
557 |
|
|
|
558 |
|
|
return 0; /* OK */ |
559 |
|
|
} |
560 |
|
|
|
561 |
|
|
|
562 |
|
|
int |
563 |
|
|
cmdline_parser_internal ( |
564 |
|
|
int argc, char **argv, struct gengetopt_args_info *args_info, |
565 |
|
|
struct cmdline_parser_params *params, const char *additional_error) |
566 |
|
|
{ |
567 |
|
|
int c; /* Character of the parsed option. */ |
568 |
|
|
|
569 |
|
|
int error = 0; |
570 |
|
|
struct gengetopt_args_info local_args_info; |
571 |
|
|
|
572 |
|
|
int override; |
573 |
|
|
int initialize; |
574 |
|
|
int check_required; |
575 |
|
|
int check_ambiguity; |
576 |
|
|
|
577 |
|
|
package_name = argv[0]; |
578 |
|
|
|
579 |
|
|
override = params->override; |
580 |
|
|
initialize = params->initialize; |
581 |
|
|
check_required = params->check_required; |
582 |
|
|
check_ambiguity = params->check_ambiguity; |
583 |
|
|
|
584 |
|
|
if (initialize) |
585 |
|
|
cmdline_parser_init (args_info); |
586 |
|
|
|
587 |
|
|
cmdline_parser_init (&local_args_info); |
588 |
|
|
|
589 |
|
|
optarg = 0; |
590 |
|
|
optind = 0; |
591 |
|
|
opterr = params->print_errors; |
592 |
|
|
optopt = '?'; |
593 |
|
|
|
594 |
|
|
while (1) |
595 |
|
|
{ |
596 |
|
|
int option_index = 0; |
597 |
|
|
|
598 |
|
|
static struct option long_options[] = { |
599 |
|
|
{ "help", 0, NULL, 'h' }, |
600 |
|
|
{ "version", 0, NULL, 'V' }, |
601 |
|
|
{ "input", 1, NULL, 'i' }, |
602 |
|
|
{ "output", 1, NULL, 'o' }, |
603 |
|
|
{ "sele1", 1, NULL, 0 }, |
604 |
|
|
{ "sele2", 1, NULL, 0 }, |
605 |
gezelter |
2035 |
{ "nbins", 1, NULL, 'b' }, |
606 |
|
|
{ "nbins_z", 1, NULL, 0 }, |
607 |
gezelter |
2029 |
{ "referenceZ", 1, NULL, 'z' }, |
608 |
|
|
{ "dropletR", 1, NULL, 'r' }, |
609 |
gezelter |
2035 |
{ "threshDens", 1, NULL, 0 }, |
610 |
gezelter |
2029 |
{ "com", 0, NULL, 'c' }, |
611 |
|
|
{ "ca1", 0, NULL, 0 }, |
612 |
|
|
{ "ca2", 0, NULL, 0 }, |
613 |
gezelter |
2024 |
{ 0, 0, 0, 0 } |
614 |
|
|
}; |
615 |
|
|
|
616 |
gezelter |
2035 |
c = getopt_long (argc, argv, "hVi:o:b:z:r:c", long_options, &option_index); |
617 |
gezelter |
2024 |
|
618 |
|
|
if (c == -1) break; /* Exit from `while (1)' loop. */ |
619 |
|
|
|
620 |
|
|
switch (c) |
621 |
|
|
{ |
622 |
|
|
case 'h': /* Print help and exit. */ |
623 |
|
|
cmdline_parser_print_help (); |
624 |
|
|
cmdline_parser_free (&local_args_info); |
625 |
|
|
exit (EXIT_SUCCESS); |
626 |
|
|
|
627 |
|
|
case 'V': /* Print version and exit. */ |
628 |
|
|
cmdline_parser_print_version (); |
629 |
|
|
cmdline_parser_free (&local_args_info); |
630 |
|
|
exit (EXIT_SUCCESS); |
631 |
|
|
|
632 |
|
|
case 'i': /* input dump file. */ |
633 |
|
|
|
634 |
|
|
|
635 |
|
|
if (update_arg( (void *)&(args_info->input_arg), |
636 |
|
|
&(args_info->input_orig), &(args_info->input_given), |
637 |
|
|
&(local_args_info.input_given), optarg, 0, 0, ARG_STRING, |
638 |
|
|
check_ambiguity, override, 0, 0, |
639 |
|
|
"input", 'i', |
640 |
|
|
additional_error)) |
641 |
|
|
goto failure; |
642 |
|
|
|
643 |
|
|
break; |
644 |
|
|
case 'o': /* output file name. */ |
645 |
|
|
|
646 |
|
|
|
647 |
|
|
if (update_arg( (void *)&(args_info->output_arg), |
648 |
|
|
&(args_info->output_orig), &(args_info->output_given), |
649 |
|
|
&(local_args_info.output_given), optarg, 0, 0, ARG_STRING, |
650 |
|
|
check_ambiguity, override, 0, 0, |
651 |
|
|
"output", 'o', |
652 |
|
|
additional_error)) |
653 |
|
|
goto failure; |
654 |
|
|
|
655 |
|
|
break; |
656 |
gezelter |
2035 |
case 'b': /* number of bins (general purpose). */ |
657 |
gezelter |
2024 |
|
658 |
|
|
|
659 |
|
|
if (update_arg( (void *)&(args_info->nbins_arg), |
660 |
|
|
&(args_info->nbins_orig), &(args_info->nbins_given), |
661 |
|
|
&(local_args_info.nbins_given), optarg, 0, "100", ARG_INT, |
662 |
|
|
check_ambiguity, override, 0, 0, |
663 |
gezelter |
2035 |
"nbins", 'b', |
664 |
gezelter |
2024 |
additional_error)) |
665 |
|
|
goto failure; |
666 |
|
|
|
667 |
|
|
break; |
668 |
gezelter |
2029 |
case 'z': /* Reference z-height of solid surface. */ |
669 |
gezelter |
2024 |
|
670 |
gezelter |
2029 |
|
671 |
|
|
if (update_arg( (void *)&(args_info->referenceZ_arg), |
672 |
|
|
&(args_info->referenceZ_orig), &(args_info->referenceZ_given), |
673 |
|
|
&(local_args_info.referenceZ_given), optarg, 0, 0, ARG_DOUBLE, |
674 |
|
|
check_ambiguity, override, 0, 0, |
675 |
|
|
"referenceZ", 'z', |
676 |
|
|
additional_error)) |
677 |
|
|
goto failure; |
678 |
|
|
|
679 |
|
|
break; |
680 |
|
|
case 'r': /* Droplet radius in angstroms. */ |
681 |
|
|
|
682 |
|
|
|
683 |
|
|
if (update_arg( (void *)&(args_info->dropletR_arg), |
684 |
|
|
&(args_info->dropletR_orig), &(args_info->dropletR_given), |
685 |
|
|
&(local_args_info.dropletR_given), optarg, 0, 0, ARG_DOUBLE, |
686 |
|
|
check_ambiguity, override, 0, 0, |
687 |
|
|
"dropletR", 'r', |
688 |
|
|
additional_error)) |
689 |
|
|
goto failure; |
690 |
|
|
|
691 |
|
|
break; |
692 |
|
|
case 'c': /* selection center of mass. */ |
693 |
|
|
|
694 |
gezelter |
2024 |
if (args_info->sequentialProps_group_counter && override) |
695 |
|
|
reset_group_sequentialProps (args_info); |
696 |
|
|
args_info->sequentialProps_group_counter += 1; |
697 |
|
|
|
698 |
|
|
if (update_arg( 0 , |
699 |
gezelter |
2029 |
0 , &(args_info->com_given), |
700 |
|
|
&(local_args_info.com_given), optarg, 0, 0, ARG_NO, |
701 |
gezelter |
2024 |
check_ambiguity, override, 0, 0, |
702 |
gezelter |
2029 |
"com", 'c', |
703 |
gezelter |
2024 |
additional_error)) |
704 |
|
|
goto failure; |
705 |
|
|
|
706 |
|
|
break; |
707 |
|
|
|
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 |
|
|
|
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 |
|
|
|
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 |
gezelter |
2035 |
/* number of bins in z axis. */ |
738 |
|
|
else if (strcmp (long_options[option_index].name, "nbins_z") == 0) |
739 |
|
|
{ |
740 |
|
|
|
741 |
|
|
|
742 |
|
|
if (update_arg( (void *)&(args_info->nbins_z_arg), |
743 |
|
|
&(args_info->nbins_z_orig), &(args_info->nbins_z_given), |
744 |
|
|
&(local_args_info.nbins_z_given), optarg, 0, "100", ARG_INT, |
745 |
|
|
check_ambiguity, override, 0, 0, |
746 |
|
|
"nbins_z", '-', |
747 |
|
|
additional_error)) |
748 |
|
|
goto failure; |
749 |
|
|
|
750 |
|
|
} |
751 |
|
|
/* Threshold Density in g/cm^3. */ |
752 |
|
|
else if (strcmp (long_options[option_index].name, "threshDens") == 0) |
753 |
|
|
{ |
754 |
|
|
|
755 |
|
|
|
756 |
|
|
if (update_arg( (void *)&(args_info->threshDens_arg), |
757 |
|
|
&(args_info->threshDens_orig), &(args_info->threshDens_given), |
758 |
|
|
&(local_args_info.threshDens_given), optarg, 0, 0, ARG_DOUBLE, |
759 |
|
|
check_ambiguity, override, 0, 0, |
760 |
|
|
"threshDens", '-', |
761 |
|
|
additional_error)) |
762 |
|
|
goto failure; |
763 |
|
|
|
764 |
|
|
} |
765 |
gezelter |
2029 |
/* contact angle of selection (using center of mass). */ |
766 |
|
|
else if (strcmp (long_options[option_index].name, "ca1") == 0) |
767 |
|
|
{ |
768 |
gezelter |
2024 |
|
769 |
gezelter |
2029 |
if (args_info->sequentialProps_group_counter && override) |
770 |
|
|
reset_group_sequentialProps (args_info); |
771 |
|
|
args_info->sequentialProps_group_counter += 1; |
772 |
|
|
|
773 |
|
|
if (update_arg( 0 , |
774 |
|
|
0 , &(args_info->ca1_given), |
775 |
|
|
&(local_args_info.ca1_given), optarg, 0, 0, ARG_NO, |
776 |
|
|
check_ambiguity, override, 0, 0, |
777 |
|
|
"ca1", '-', |
778 |
|
|
additional_error)) |
779 |
|
|
goto failure; |
780 |
|
|
|
781 |
|
|
} |
782 |
|
|
/* contact angle of selection (using density profile). */ |
783 |
|
|
else if (strcmp (long_options[option_index].name, "ca2") == 0) |
784 |
|
|
{ |
785 |
|
|
|
786 |
|
|
if (args_info->sequentialProps_group_counter && override) |
787 |
|
|
reset_group_sequentialProps (args_info); |
788 |
|
|
args_info->sequentialProps_group_counter += 1; |
789 |
|
|
|
790 |
|
|
if (update_arg( 0 , |
791 |
|
|
0 , &(args_info->ca2_given), |
792 |
|
|
&(local_args_info.ca2_given), optarg, 0, 0, ARG_NO, |
793 |
|
|
check_ambiguity, override, 0, 0, |
794 |
|
|
"ca2", '-', |
795 |
|
|
additional_error)) |
796 |
|
|
goto failure; |
797 |
|
|
|
798 |
|
|
} |
799 |
|
|
|
800 |
gezelter |
2024 |
break; |
801 |
|
|
case '?': /* Invalid option. */ |
802 |
|
|
/* `getopt_long' already printed an error message. */ |
803 |
|
|
goto failure; |
804 |
|
|
|
805 |
|
|
default: /* bug: option not considered. */ |
806 |
|
|
fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
807 |
|
|
abort (); |
808 |
|
|
} /* switch */ |
809 |
|
|
} /* while */ |
810 |
|
|
|
811 |
|
|
if (args_info->sequentialProps_group_counter > 1) |
812 |
|
|
{ |
813 |
|
|
fprintf (stderr, "%s: %d options of group sequentialProps were given. One is required%s.\n", argv[0], args_info->sequentialProps_group_counter, (additional_error ? additional_error : "")); |
814 |
|
|
error = 1; |
815 |
|
|
} |
816 |
|
|
|
817 |
|
|
|
818 |
|
|
|
819 |
|
|
if (check_required) |
820 |
|
|
{ |
821 |
|
|
error += cmdline_parser_required2 (args_info, argv[0], additional_error); |
822 |
|
|
} |
823 |
|
|
|
824 |
|
|
cmdline_parser_release (&local_args_info); |
825 |
|
|
|
826 |
|
|
if ( error ) |
827 |
|
|
return (EXIT_FAILURE); |
828 |
|
|
|
829 |
|
|
if (optind < argc) |
830 |
|
|
{ |
831 |
|
|
int i = 0 ; |
832 |
|
|
int found_prog_name = 0; |
833 |
|
|
/* whether program name, i.e., argv[0], is in the remaining args |
834 |
|
|
(this may happen with some implementations of getopt, |
835 |
|
|
but surely not with the one included by gengetopt) */ |
836 |
|
|
|
837 |
|
|
i = optind; |
838 |
|
|
while (i < argc) |
839 |
|
|
if (argv[i++] == argv[0]) { |
840 |
|
|
found_prog_name = 1; |
841 |
|
|
break; |
842 |
|
|
} |
843 |
|
|
i = 0; |
844 |
|
|
|
845 |
|
|
args_info->inputs_num = argc - optind - found_prog_name; |
846 |
|
|
args_info->inputs = |
847 |
|
|
(char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; |
848 |
|
|
while (optind < argc) |
849 |
|
|
if (argv[optind++] != argv[0]) |
850 |
|
|
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ; |
851 |
|
|
} |
852 |
|
|
|
853 |
|
|
return 0; |
854 |
|
|
|
855 |
|
|
failure: |
856 |
|
|
|
857 |
|
|
cmdline_parser_release (&local_args_info); |
858 |
|
|
return (EXIT_FAILURE); |
859 |
|
|
} |