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