1 |
|
/* |
2 |
< |
File autogenerated by gengetopt version 2.11 |
2 |
> |
File autogenerated by gengetopt version 2.22.4 |
3 |
|
generated with the following command: |
4 |
< |
/home/maul/gezelter/tim/program/gengetopt-2.11/src/gengetopt -F HydroCmd |
4 |
> |
gengetopt --file-name=HydroCmd --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 |
< |
/* If we use autoconf. */ |
21 |
< |
#ifdef HAVE_CONFIG_H |
18 |
< |
#include "config.h" |
20 |
> |
#ifndef FIX_UNUSED |
21 |
> |
#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ |
22 |
|
#endif |
23 |
|
|
24 |
< |
#include "getopt.h" |
24 |
> |
#ifdef WIN32 |
25 |
> |
#include "utils/wingetopt.h" |
26 |
> |
#else |
27 |
> |
#include <getopt.h> |
28 |
> |
#endif |
29 |
|
|
30 |
|
#include "HydroCmd.h" |
31 |
|
|
32 |
+ |
const char *gengetopt_args_info_purpose = "\n+--------------------------------------------------------------------------+\n| ____ __ ___ ____ |\n| / __ \\____ ___ ____ / |/ // __ \\ The Open Molecular Dynamics |\n| / / / / __ \\/ _ \\/ __ \\ / /|_/ // / / / Engine (formerly OOPSE). |\n| / /_/ / /_/ / __/ / / // / / // /_/ / |\n| \\____/ .___/\\___/_/ /_//_/ /_//_____/ Copyright 2004-2014 by the |\n| /_/ University of Notre Dame. |\n| |\n| http://www.openmd.org |\n| |\n| OpenMD is an OpenScience project. All source code is available for |\n| any use whatsoever under a BSD-style license. |\n| |\n| Support OpenScience! If you use OpenMD or its source code in your |\n| research, please cite the appropriate papers when you publish your |\n| work. Good starting points are: |\n| |\n| [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |\n| [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |\n| [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |\n| [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |\n| [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |\n| [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012). |\n+--------------------------------------------------------------------------+"; |
33 |
+ |
|
34 |
+ |
const char *gengetopt_args_info_usage = "Usage: Hydro [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 MetaData (md) file", |
42 |
+ |
" -o, --output=STRING output file prefix (default=`hydro')", |
43 |
+ |
" --model=STRING hydrodynamics model (supports RoughShell and BeadModel)", |
44 |
+ |
" -b, --beads generate the beads only, hydrodynamics will be \n performed (default=off)", |
45 |
+ |
0 |
46 |
+ |
}; |
47 |
+ |
|
48 |
+ |
typedef enum {ARG_NO |
49 |
+ |
, ARG_FLAG |
50 |
+ |
, ARG_STRING |
51 |
+ |
} cmdline_parser_arg_type; |
52 |
+ |
|
53 |
+ |
static |
54 |
+ |
void clear_given (struct gengetopt_args_info *args_info); |
55 |
+ |
static |
56 |
+ |
void clear_args (struct gengetopt_args_info *args_info); |
57 |
+ |
|
58 |
+ |
static int |
59 |
+ |
cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, |
60 |
+ |
struct cmdline_parser_params *params, const char *additional_error); |
61 |
+ |
|
62 |
+ |
static int |
63 |
+ |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); |
64 |
+ |
|
65 |
+ |
static char * |
66 |
+ |
gengetopt_strdup (const char *s); |
67 |
+ |
|
68 |
+ |
static |
69 |
+ |
void clear_given (struct gengetopt_args_info *args_info) |
70 |
+ |
{ |
71 |
+ |
args_info->help_given = 0 ; |
72 |
+ |
args_info->version_given = 0 ; |
73 |
+ |
args_info->input_given = 0 ; |
74 |
+ |
args_info->output_given = 0 ; |
75 |
+ |
args_info->model_given = 0 ; |
76 |
+ |
args_info->beads_given = 0 ; |
77 |
+ |
} |
78 |
+ |
|
79 |
+ |
static |
80 |
+ |
void clear_args (struct gengetopt_args_info *args_info) |
81 |
+ |
{ |
82 |
+ |
FIX_UNUSED (args_info); |
83 |
+ |
args_info->input_arg = NULL; |
84 |
+ |
args_info->input_orig = NULL; |
85 |
+ |
args_info->output_arg = gengetopt_strdup ("hydro"); |
86 |
+ |
args_info->output_orig = NULL; |
87 |
+ |
args_info->model_arg = NULL; |
88 |
+ |
args_info->model_orig = NULL; |
89 |
+ |
args_info->beads_flag = 0; |
90 |
+ |
|
91 |
+ |
} |
92 |
+ |
|
93 |
+ |
static |
94 |
+ |
void init_args_info(struct gengetopt_args_info *args_info) |
95 |
+ |
{ |
96 |
+ |
|
97 |
+ |
|
98 |
+ |
args_info->help_help = gengetopt_args_info_help[0] ; |
99 |
+ |
args_info->version_help = gengetopt_args_info_help[1] ; |
100 |
+ |
args_info->input_help = gengetopt_args_info_help[2] ; |
101 |
+ |
args_info->output_help = gengetopt_args_info_help[3] ; |
102 |
+ |
args_info->model_help = gengetopt_args_info_help[4] ; |
103 |
+ |
args_info->beads_help = gengetopt_args_info_help[5] ; |
104 |
+ |
|
105 |
+ |
} |
106 |
+ |
|
107 |
|
void |
108 |
|
cmdline_parser_print_version (void) |
109 |
|
{ |
110 |
< |
printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); |
110 |
> |
printf ("%s %s\n", |
111 |
> |
(strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), |
112 |
> |
CMDLINE_PARSER_VERSION); |
113 |
|
} |
114 |
|
|
115 |
+ |
static void print_help_common(void) { |
116 |
+ |
cmdline_parser_print_version (); |
117 |
+ |
|
118 |
+ |
if (strlen(gengetopt_args_info_purpose) > 0) |
119 |
+ |
printf("\n%s\n", gengetopt_args_info_purpose); |
120 |
+ |
|
121 |
+ |
if (strlen(gengetopt_args_info_usage) > 0) |
122 |
+ |
printf("\n%s\n", gengetopt_args_info_usage); |
123 |
+ |
|
124 |
+ |
printf("\n"); |
125 |
+ |
|
126 |
+ |
if (strlen(gengetopt_args_info_description) > 0) |
127 |
+ |
printf("%s\n\n", gengetopt_args_info_description); |
128 |
+ |
} |
129 |
+ |
|
130 |
|
void |
131 |
|
cmdline_parser_print_help (void) |
132 |
|
{ |
133 |
< |
cmdline_parser_print_version (); |
134 |
< |
printf("\n" |
135 |
< |
"Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE); |
136 |
< |
printf("\n"); |
38 |
< |
printf(" -h, --help Print help and exit\n"); |
39 |
< |
printf(" -V, --version Print version and exit\n"); |
40 |
< |
printf(" -i, --input=filename input dump file\n"); |
41 |
< |
printf(" -o, --output=STRING output file prefix (default=`hydro')\n"); |
42 |
< |
printf(" --model=STRING hydrodynamics model (support RoughShell and BeadModel)\n"); |
133 |
> |
int i = 0; |
134 |
> |
print_help_common(); |
135 |
> |
while (gengetopt_args_info_help[i]) |
136 |
> |
printf("%s\n", gengetopt_args_info_help[i++]); |
137 |
|
} |
138 |
|
|
139 |
+ |
void |
140 |
+ |
cmdline_parser_init (struct gengetopt_args_info *args_info) |
141 |
+ |
{ |
142 |
+ |
clear_given (args_info); |
143 |
+ |
clear_args (args_info); |
144 |
+ |
init_args_info (args_info); |
145 |
|
|
146 |
< |
static char *gengetopt_strdup (const char *s); |
146 |
> |
args_info->inputs = 0; |
147 |
> |
args_info->inputs_num = 0; |
148 |
> |
} |
149 |
|
|
150 |
< |
/* gengetopt_strdup() */ |
151 |
< |
/* strdup.c replacement of strdup, which is not standard */ |
150 |
> |
void |
151 |
> |
cmdline_parser_params_init(struct cmdline_parser_params *params) |
152 |
> |
{ |
153 |
> |
if (params) |
154 |
> |
{ |
155 |
> |
params->override = 0; |
156 |
> |
params->initialize = 1; |
157 |
> |
params->check_required = 1; |
158 |
> |
params->check_ambiguity = 0; |
159 |
> |
params->print_errors = 1; |
160 |
> |
} |
161 |
> |
} |
162 |
> |
|
163 |
> |
struct cmdline_parser_params * |
164 |
> |
cmdline_parser_params_create(void) |
165 |
> |
{ |
166 |
> |
struct cmdline_parser_params *params = |
167 |
> |
(struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); |
168 |
> |
cmdline_parser_params_init(params); |
169 |
> |
return params; |
170 |
> |
} |
171 |
> |
|
172 |
> |
static void |
173 |
> |
free_string_field (char **s) |
174 |
> |
{ |
175 |
> |
if (*s) |
176 |
> |
{ |
177 |
> |
free (*s); |
178 |
> |
*s = 0; |
179 |
> |
} |
180 |
> |
} |
181 |
> |
|
182 |
> |
|
183 |
> |
static void |
184 |
> |
cmdline_parser_release (struct gengetopt_args_info *args_info) |
185 |
> |
{ |
186 |
> |
unsigned int i; |
187 |
> |
free_string_field (&(args_info->input_arg)); |
188 |
> |
free_string_field (&(args_info->input_orig)); |
189 |
> |
free_string_field (&(args_info->output_arg)); |
190 |
> |
free_string_field (&(args_info->output_orig)); |
191 |
> |
free_string_field (&(args_info->model_arg)); |
192 |
> |
free_string_field (&(args_info->model_orig)); |
193 |
> |
|
194 |
> |
|
195 |
> |
for (i = 0; i < args_info->inputs_num; ++i) |
196 |
> |
free (args_info->inputs [i]); |
197 |
> |
|
198 |
> |
if (args_info->inputs_num) |
199 |
> |
free (args_info->inputs); |
200 |
> |
|
201 |
> |
clear_given (args_info); |
202 |
> |
} |
203 |
> |
|
204 |
> |
|
205 |
> |
static void |
206 |
> |
write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) |
207 |
> |
{ |
208 |
> |
FIX_UNUSED (values); |
209 |
> |
if (arg) { |
210 |
> |
fprintf(outfile, "%s=\"%s\"\n", opt, arg); |
211 |
> |
} else { |
212 |
> |
fprintf(outfile, "%s\n", opt); |
213 |
> |
} |
214 |
> |
} |
215 |
> |
|
216 |
> |
|
217 |
> |
int |
218 |
> |
cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) |
219 |
> |
{ |
220 |
> |
int i = 0; |
221 |
> |
|
222 |
> |
if (!outfile) |
223 |
> |
{ |
224 |
> |
fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); |
225 |
> |
return EXIT_FAILURE; |
226 |
> |
} |
227 |
> |
|
228 |
> |
if (args_info->help_given) |
229 |
> |
write_into_file(outfile, "help", 0, 0 ); |
230 |
> |
if (args_info->version_given) |
231 |
> |
write_into_file(outfile, "version", 0, 0 ); |
232 |
> |
if (args_info->input_given) |
233 |
> |
write_into_file(outfile, "input", args_info->input_orig, 0); |
234 |
> |
if (args_info->output_given) |
235 |
> |
write_into_file(outfile, "output", args_info->output_orig, 0); |
236 |
> |
if (args_info->model_given) |
237 |
> |
write_into_file(outfile, "model", args_info->model_orig, 0); |
238 |
> |
if (args_info->beads_given) |
239 |
> |
write_into_file(outfile, "beads", 0, 0 ); |
240 |
> |
|
241 |
> |
|
242 |
> |
i = EXIT_SUCCESS; |
243 |
> |
return i; |
244 |
> |
} |
245 |
> |
|
246 |
> |
int |
247 |
> |
cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) |
248 |
> |
{ |
249 |
> |
FILE *outfile; |
250 |
> |
int i = 0; |
251 |
> |
|
252 |
> |
outfile = fopen(filename, "w"); |
253 |
> |
|
254 |
> |
if (!outfile) |
255 |
> |
{ |
256 |
> |
fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); |
257 |
> |
return EXIT_FAILURE; |
258 |
> |
} |
259 |
> |
|
260 |
> |
i = cmdline_parser_dump(outfile, args_info); |
261 |
> |
fclose (outfile); |
262 |
> |
|
263 |
> |
return i; |
264 |
> |
} |
265 |
> |
|
266 |
> |
void |
267 |
> |
cmdline_parser_free (struct gengetopt_args_info *args_info) |
268 |
> |
{ |
269 |
> |
cmdline_parser_release (args_info); |
270 |
> |
} |
271 |
> |
|
272 |
> |
/** @brief replacement of strdup, which is not standard */ |
273 |
|
char * |
274 |
|
gengetopt_strdup (const char *s) |
275 |
|
{ |
276 |
< |
char *result = (char*)malloc(strlen(s) + 1); |
276 |
> |
char *result = 0; |
277 |
> |
if (!s) |
278 |
> |
return result; |
279 |
> |
|
280 |
> |
result = (char*)malloc(strlen(s) + 1); |
281 |
|
if (result == (char*)0) |
282 |
|
return (char*)0; |
283 |
|
strcpy(result, s); |
285 |
|
} |
286 |
|
|
287 |
|
int |
288 |
< |
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
288 |
> |
cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) |
289 |
|
{ |
290 |
< |
int c; /* Character of the parsed option. */ |
291 |
< |
int missing_required_options = 0; |
290 |
> |
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
291 |
> |
} |
292 |
|
|
293 |
< |
args_info->help_given = 0 ; |
294 |
< |
args_info->version_given = 0 ; |
295 |
< |
args_info->input_given = 0 ; |
296 |
< |
args_info->output_given = 0 ; |
297 |
< |
args_info->model_given = 0 ; |
298 |
< |
#define clear_args() { \ |
299 |
< |
args_info->input_arg = NULL; \ |
300 |
< |
args_info->output_arg = gengetopt_strdup("hydro") ;\ |
301 |
< |
args_info->model_arg = NULL; \ |
293 |
> |
int |
294 |
> |
cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, |
295 |
> |
struct cmdline_parser_params *params) |
296 |
> |
{ |
297 |
> |
int result; |
298 |
> |
result = cmdline_parser_internal (argc, argv, args_info, params, 0); |
299 |
> |
|
300 |
> |
if (result == EXIT_FAILURE) |
301 |
> |
{ |
302 |
> |
cmdline_parser_free (args_info); |
303 |
> |
exit (EXIT_FAILURE); |
304 |
> |
} |
305 |
> |
|
306 |
> |
return result; |
307 |
|
} |
308 |
|
|
309 |
< |
clear_args(); |
309 |
> |
int |
310 |
> |
cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
311 |
> |
{ |
312 |
> |
int result; |
313 |
> |
struct cmdline_parser_params params; |
314 |
> |
|
315 |
> |
params.override = override; |
316 |
> |
params.initialize = initialize; |
317 |
> |
params.check_required = check_required; |
318 |
> |
params.check_ambiguity = 0; |
319 |
> |
params.print_errors = 1; |
320 |
> |
|
321 |
> |
result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); |
322 |
> |
|
323 |
> |
if (result == EXIT_FAILURE) |
324 |
> |
{ |
325 |
> |
cmdline_parser_free (args_info); |
326 |
> |
exit (EXIT_FAILURE); |
327 |
> |
} |
328 |
> |
|
329 |
> |
return result; |
330 |
> |
} |
331 |
> |
|
332 |
> |
int |
333 |
> |
cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) |
334 |
> |
{ |
335 |
> |
int result = EXIT_SUCCESS; |
336 |
|
|
337 |
+ |
if (cmdline_parser_required2(args_info, prog_name, 0) > 0) |
338 |
+ |
result = EXIT_FAILURE; |
339 |
+ |
|
340 |
+ |
if (result == EXIT_FAILURE) |
341 |
+ |
{ |
342 |
+ |
cmdline_parser_free (args_info); |
343 |
+ |
exit (EXIT_FAILURE); |
344 |
+ |
} |
345 |
+ |
|
346 |
+ |
return result; |
347 |
+ |
} |
348 |
+ |
|
349 |
+ |
int |
350 |
+ |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) |
351 |
+ |
{ |
352 |
+ |
int error = 0; |
353 |
+ |
FIX_UNUSED (additional_error); |
354 |
+ |
|
355 |
+ |
/* checks for required options */ |
356 |
+ |
if (! args_info->input_given) |
357 |
+ |
{ |
358 |
+ |
fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); |
359 |
+ |
error = 1; |
360 |
+ |
} |
361 |
+ |
|
362 |
+ |
if (! args_info->model_given) |
363 |
+ |
{ |
364 |
+ |
fprintf (stderr, "%s: '--model' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
365 |
+ |
error = 1; |
366 |
+ |
} |
367 |
+ |
|
368 |
+ |
|
369 |
+ |
/* checks for dependences among options */ |
370 |
+ |
|
371 |
+ |
return error; |
372 |
+ |
} |
373 |
+ |
|
374 |
+ |
|
375 |
+ |
static char *package_name = 0; |
376 |
+ |
|
377 |
+ |
/** |
378 |
+ |
* @brief updates an option |
379 |
+ |
* @param field the generic pointer to the field to update |
380 |
+ |
* @param orig_field the pointer to the orig field |
381 |
+ |
* @param field_given the pointer to the number of occurrence of this option |
382 |
+ |
* @param prev_given the pointer to the number of occurrence already seen |
383 |
+ |
* @param value the argument for this option (if null no arg was specified) |
384 |
+ |
* @param possible_values the possible values for this option (if specified) |
385 |
+ |
* @param default_value the default value (in case the option only accepts fixed values) |
386 |
+ |
* @param arg_type the type of this option |
387 |
+ |
* @param check_ambiguity @see cmdline_parser_params.check_ambiguity |
388 |
+ |
* @param override @see cmdline_parser_params.override |
389 |
+ |
* @param no_free whether to free a possible previous value |
390 |
+ |
* @param multiple_option whether this is a multiple option |
391 |
+ |
* @param long_opt the corresponding long option |
392 |
+ |
* @param short_opt the corresponding short option (or '-' if none) |
393 |
+ |
* @param additional_error possible further error specification |
394 |
+ |
*/ |
395 |
+ |
static |
396 |
+ |
int update_arg(void *field, char **orig_field, |
397 |
+ |
unsigned int *field_given, unsigned int *prev_given, |
398 |
+ |
char *value, const char *possible_values[], |
399 |
+ |
const char *default_value, |
400 |
+ |
cmdline_parser_arg_type arg_type, |
401 |
+ |
int check_ambiguity, int override, |
402 |
+ |
int no_free, int multiple_option, |
403 |
+ |
const char *long_opt, char short_opt, |
404 |
+ |
const char *additional_error) |
405 |
+ |
{ |
406 |
+ |
const char *val = value; |
407 |
+ |
int found; |
408 |
+ |
char **string_field; |
409 |
+ |
FIX_UNUSED (field); |
410 |
+ |
|
411 |
+ |
found = 0; |
412 |
+ |
|
413 |
+ |
if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) |
414 |
+ |
{ |
415 |
+ |
if (short_opt != '-') |
416 |
+ |
fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", |
417 |
+ |
package_name, long_opt, short_opt, |
418 |
+ |
(additional_error ? additional_error : "")); |
419 |
+ |
else |
420 |
+ |
fprintf (stderr, "%s: `--%s' option given more than once%s\n", |
421 |
+ |
package_name, long_opt, |
422 |
+ |
(additional_error ? additional_error : "")); |
423 |
+ |
return 1; /* failure */ |
424 |
+ |
} |
425 |
+ |
|
426 |
+ |
FIX_UNUSED (default_value); |
427 |
+ |
|
428 |
+ |
if (field_given && *field_given && ! override) |
429 |
+ |
return 0; |
430 |
+ |
if (prev_given) |
431 |
+ |
(*prev_given)++; |
432 |
+ |
if (field_given) |
433 |
+ |
(*field_given)++; |
434 |
+ |
if (possible_values) |
435 |
+ |
val = possible_values[found]; |
436 |
+ |
|
437 |
+ |
switch(arg_type) { |
438 |
+ |
case ARG_FLAG: |
439 |
+ |
*((int *)field) = !*((int *)field); |
440 |
+ |
break; |
441 |
+ |
case ARG_STRING: |
442 |
+ |
if (val) { |
443 |
+ |
string_field = (char **)field; |
444 |
+ |
if (!no_free && *string_field) |
445 |
+ |
free (*string_field); /* free previous string */ |
446 |
+ |
*string_field = gengetopt_strdup (val); |
447 |
+ |
} |
448 |
+ |
break; |
449 |
+ |
default: |
450 |
+ |
break; |
451 |
+ |
}; |
452 |
+ |
|
453 |
+ |
|
454 |
+ |
/* store the original value */ |
455 |
+ |
switch(arg_type) { |
456 |
+ |
case ARG_NO: |
457 |
+ |
case ARG_FLAG: |
458 |
+ |
break; |
459 |
+ |
default: |
460 |
+ |
if (value && orig_field) { |
461 |
+ |
if (no_free) { |
462 |
+ |
*orig_field = value; |
463 |
+ |
} else { |
464 |
+ |
if (*orig_field) |
465 |
+ |
free (*orig_field); /* free previous string */ |
466 |
+ |
*orig_field = gengetopt_strdup (value); |
467 |
+ |
} |
468 |
+ |
} |
469 |
+ |
}; |
470 |
+ |
|
471 |
+ |
return 0; /* OK */ |
472 |
+ |
} |
473 |
+ |
|
474 |
+ |
|
475 |
+ |
int |
476 |
+ |
cmdline_parser_internal ( |
477 |
+ |
int argc, char **argv, struct gengetopt_args_info *args_info, |
478 |
+ |
struct cmdline_parser_params *params, const char *additional_error) |
479 |
+ |
{ |
480 |
+ |
int c; /* Character of the parsed option. */ |
481 |
+ |
|
482 |
+ |
int error = 0; |
483 |
+ |
struct gengetopt_args_info local_args_info; |
484 |
+ |
|
485 |
+ |
int override; |
486 |
+ |
int initialize; |
487 |
+ |
int check_required; |
488 |
+ |
int check_ambiguity; |
489 |
+ |
|
490 |
+ |
package_name = argv[0]; |
491 |
+ |
|
492 |
+ |
override = params->override; |
493 |
+ |
initialize = params->initialize; |
494 |
+ |
check_required = params->check_required; |
495 |
+ |
check_ambiguity = params->check_ambiguity; |
496 |
+ |
|
497 |
+ |
if (initialize) |
498 |
+ |
cmdline_parser_init (args_info); |
499 |
+ |
|
500 |
+ |
cmdline_parser_init (&local_args_info); |
501 |
+ |
|
502 |
|
optarg = 0; |
503 |
< |
optind = 1; |
504 |
< |
opterr = 1; |
503 |
> |
optind = 0; |
504 |
> |
opterr = params->print_errors; |
505 |
|
optopt = '?'; |
506 |
|
|
507 |
|
while (1) |
508 |
|
{ |
509 |
|
int option_index = 0; |
87 |
– |
char *stop_char; |
510 |
|
|
511 |
|
static struct option long_options[] = { |
512 |
|
{ "help", 0, NULL, 'h' }, |
514 |
|
{ "input", 1, NULL, 'i' }, |
515 |
|
{ "output", 1, NULL, 'o' }, |
516 |
|
{ "model", 1, NULL, 0 }, |
517 |
< |
{ NULL, 0, NULL, 0 } |
517 |
> |
{ "beads", 0, NULL, 'b' }, |
518 |
> |
{ 0, 0, 0, 0 } |
519 |
|
}; |
520 |
|
|
521 |
< |
stop_char = 0; |
99 |
< |
c = getopt_long (argc, argv, "hVi:o:", long_options, &option_index); |
521 |
> |
c = getopt_long (argc, argv, "hVi:o:b", long_options, &option_index); |
522 |
|
|
523 |
|
if (c == -1) break; /* Exit from `while (1)' loop. */ |
524 |
|
|
525 |
|
switch (c) |
526 |
|
{ |
527 |
|
case 'h': /* Print help and exit. */ |
106 |
– |
clear_args (); |
528 |
|
cmdline_parser_print_help (); |
529 |
+ |
cmdline_parser_free (&local_args_info); |
530 |
|
exit (EXIT_SUCCESS); |
531 |
|
|
532 |
|
case 'V': /* Print version and exit. */ |
111 |
– |
clear_args (); |
533 |
|
cmdline_parser_print_version (); |
534 |
+ |
cmdline_parser_free (&local_args_info); |
535 |
|
exit (EXIT_SUCCESS); |
536 |
|
|
537 |
< |
case 'i': /* input dump file. */ |
538 |
< |
if (args_info->input_given) |
539 |
< |
{ |
540 |
< |
fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
541 |
< |
clear_args (); |
542 |
< |
exit (EXIT_FAILURE); |
543 |
< |
} |
544 |
< |
args_info->input_given = 1; |
545 |
< |
args_info->input_arg = gengetopt_strdup (optarg); |
537 |
> |
case 'i': /* input MetaData (md) file. */ |
538 |
> |
|
539 |
> |
|
540 |
> |
if (update_arg( (void *)&(args_info->input_arg), |
541 |
> |
&(args_info->input_orig), &(args_info->input_given), |
542 |
> |
&(local_args_info.input_given), optarg, 0, 0, ARG_STRING, |
543 |
> |
check_ambiguity, override, 0, 0, |
544 |
> |
"input", 'i', |
545 |
> |
additional_error)) |
546 |
> |
goto failure; |
547 |
> |
|
548 |
|
break; |
125 |
– |
|
549 |
|
case 'o': /* output file prefix. */ |
550 |
< |
if (args_info->output_given) |
551 |
< |
{ |
552 |
< |
fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
553 |
< |
clear_args (); |
554 |
< |
exit (EXIT_FAILURE); |
555 |
< |
} |
556 |
< |
args_info->output_given = 1; |
557 |
< |
if (args_info->output_arg) |
558 |
< |
free (args_info->output_arg); /* free default string */ |
559 |
< |
args_info->output_arg = gengetopt_strdup (optarg); |
550 |
> |
|
551 |
> |
|
552 |
> |
if (update_arg( (void *)&(args_info->output_arg), |
553 |
> |
&(args_info->output_orig), &(args_info->output_given), |
554 |
> |
&(local_args_info.output_given), optarg, 0, "hydro", ARG_STRING, |
555 |
> |
check_ambiguity, override, 0, 0, |
556 |
> |
"output", 'o', |
557 |
> |
additional_error)) |
558 |
> |
goto failure; |
559 |
> |
|
560 |
|
break; |
561 |
+ |
case 'b': /* generate the beads only, hydrodynamics will be performed. */ |
562 |
+ |
|
563 |
+ |
|
564 |
+ |
if (update_arg((void *)&(args_info->beads_flag), 0, &(args_info->beads_given), |
565 |
+ |
&(local_args_info.beads_given), optarg, 0, 0, ARG_FLAG, |
566 |
+ |
check_ambiguity, override, 1, 0, "beads", 'b', |
567 |
+ |
additional_error)) |
568 |
+ |
goto failure; |
569 |
+ |
|
570 |
+ |
break; |
571 |
|
|
139 |
– |
|
572 |
|
case 0: /* Long option with no short option */ |
573 |
< |
/* hydrodynamics model (support RoughShell and BeadModel). */ |
573 |
> |
/* hydrodynamics model (supports RoughShell and BeadModel). */ |
574 |
|
if (strcmp (long_options[option_index].name, "model") == 0) |
575 |
|
{ |
576 |
< |
if (args_info->model_given) |
577 |
< |
{ |
578 |
< |
fprintf (stderr, "%s: `--model' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
579 |
< |
clear_args (); |
580 |
< |
exit (EXIT_FAILURE); |
581 |
< |
} |
582 |
< |
args_info->model_given = 1; |
583 |
< |
args_info->model_arg = gengetopt_strdup (optarg); |
584 |
< |
break; |
576 |
> |
|
577 |
> |
|
578 |
> |
if (update_arg( (void *)&(args_info->model_arg), |
579 |
> |
&(args_info->model_orig), &(args_info->model_given), |
580 |
> |
&(local_args_info.model_given), optarg, 0, 0, ARG_STRING, |
581 |
> |
check_ambiguity, override, 0, 0, |
582 |
> |
"model", '-', |
583 |
> |
additional_error)) |
584 |
> |
goto failure; |
585 |
> |
|
586 |
|
} |
587 |
|
|
588 |
< |
|
588 |
> |
break; |
589 |
|
case '?': /* Invalid option. */ |
590 |
|
/* `getopt_long' already printed an error message. */ |
591 |
< |
exit (EXIT_FAILURE); |
591 |
> |
goto failure; |
592 |
|
|
593 |
|
default: /* bug: option not considered. */ |
594 |
< |
fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); |
594 |
> |
fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
595 |
|
abort (); |
596 |
|
} /* switch */ |
597 |
|
} /* while */ |
598 |
|
|
599 |
|
|
600 |
< |
if (! args_info->input_given) |
600 |
> |
|
601 |
> |
if (check_required) |
602 |
|
{ |
603 |
< |
fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE); |
170 |
< |
missing_required_options = 1; |
603 |
> |
error += cmdline_parser_required2 (args_info, argv[0], additional_error); |
604 |
|
} |
605 |
< |
if (! args_info->model_given) |
605 |
> |
|
606 |
> |
cmdline_parser_release (&local_args_info); |
607 |
> |
|
608 |
> |
if ( error ) |
609 |
> |
return (EXIT_FAILURE); |
610 |
> |
|
611 |
> |
if (optind < argc) |
612 |
|
{ |
613 |
< |
fprintf (stderr, "%s: '--model' option required\n", CMDLINE_PARSER_PACKAGE); |
614 |
< |
missing_required_options = 1; |
613 |
> |
int i = 0 ; |
614 |
> |
int found_prog_name = 0; |
615 |
> |
/* whether program name, i.e., argv[0], is in the remaining args |
616 |
> |
(this may happen with some implementations of getopt, |
617 |
> |
but surely not with the one included by gengetopt) */ |
618 |
> |
|
619 |
> |
i = optind; |
620 |
> |
while (i < argc) |
621 |
> |
if (argv[i++] == argv[0]) { |
622 |
> |
found_prog_name = 1; |
623 |
> |
break; |
624 |
> |
} |
625 |
> |
i = 0; |
626 |
> |
|
627 |
> |
args_info->inputs_num = argc - optind - found_prog_name; |
628 |
> |
args_info->inputs = |
629 |
> |
(char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; |
630 |
> |
while (optind < argc) |
631 |
> |
if (argv[optind++] != argv[0]) |
632 |
> |
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ; |
633 |
|
} |
177 |
– |
if ( missing_required_options ) |
178 |
– |
exit (EXIT_FAILURE); |
634 |
|
|
635 |
|
return 0; |
636 |
+ |
|
637 |
+ |
failure: |
638 |
+ |
|
639 |
+ |
cmdline_parser_release (&local_args_info); |
640 |
+ |
return (EXIT_FAILURE); |
641 |
|
} |