1 |
|
/* |
2 |
< |
File autogenerated by gengetopt version 2.11 |
2 |
> |
File autogenerated by gengetopt version 2.16 |
3 |
|
generated with the following command: |
4 |
< |
/home/maul/gezelter/tim/program/gengetopt-2.11/src/gengetopt -F HydroCmd |
4 |
> |
gengetopt -F HydroCmd |
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 |
– |
|
12 |
– |
#include <stdio.h> |
13 |
– |
#include <stdlib.h> |
14 |
– |
#include <string.h> |
15 |
– |
|
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 |
|
#include "getopt.h" |
21 |
|
|
22 |
|
#include "HydroCmd.h" |
23 |
|
|
24 |
+ |
static |
25 |
+ |
void clear_given (struct gengetopt_args_info *args_info); |
26 |
+ |
static |
27 |
+ |
void clear_args (struct gengetopt_args_info *args_info); |
28 |
+ |
|
29 |
+ |
static int |
30 |
+ |
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); |
31 |
+ |
|
32 |
+ |
static int |
33 |
+ |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); |
34 |
+ |
|
35 |
+ |
static char * |
36 |
+ |
gengetopt_strdup (const char *s); |
37 |
+ |
|
38 |
+ |
static |
39 |
+ |
void clear_given (struct gengetopt_args_info *args_info) |
40 |
+ |
{ |
41 |
+ |
args_info->help_given = 0 ; |
42 |
+ |
args_info->version_given = 0 ; |
43 |
+ |
args_info->input_given = 0 ; |
44 |
+ |
args_info->output_given = 0 ; |
45 |
+ |
args_info->model_given = 0 ; |
46 |
+ |
args_info->beads_given = 0 ; |
47 |
+ |
} |
48 |
+ |
|
49 |
+ |
static |
50 |
+ |
void clear_args (struct gengetopt_args_info *args_info) |
51 |
+ |
{ |
52 |
+ |
args_info->input_arg = NULL; |
53 |
+ |
args_info->input_orig = NULL; |
54 |
+ |
args_info->output_arg = gengetopt_strdup ("hydro"); |
55 |
+ |
args_info->output_orig = NULL; |
56 |
+ |
args_info->model_arg = NULL; |
57 |
+ |
args_info->model_orig = NULL; |
58 |
+ |
args_info->beads_flag = 0; |
59 |
+ |
|
60 |
+ |
} |
61 |
+ |
|
62 |
|
void |
63 |
|
cmdline_parser_print_version (void) |
64 |
|
{ |
69 |
|
cmdline_parser_print_help (void) |
70 |
|
{ |
71 |
|
cmdline_parser_print_version (); |
72 |
< |
printf("\n" |
73 |
< |
"Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE); |
74 |
< |
printf("\n"); |
75 |
< |
printf(" -h, --help Print help and exit\n"); |
76 |
< |
printf(" -V, --version Print version and exit\n"); |
77 |
< |
printf(" -i, --input=filename input dump file\n"); |
78 |
< |
printf(" -o, --output=STRING output file prefix (default=`hydro')\n"); |
79 |
< |
printf(" --model=STRING hydrodynamics model (support RoughShell and BeadModel)\n"); |
43 |
< |
printf(" -b, --beads generate the beads only, hydrodynamics will be \n performed (default=off)\n"); |
72 |
> |
printf("\nUsage: Hydro [OPTIONS]...\n\n"); |
73 |
> |
printf("%s\n"," -h, --help Print help and exit"); |
74 |
> |
printf("%s\n"," -V, --version Print version and exit"); |
75 |
> |
printf("%s\n"," -i, --input=filename input dump file"); |
76 |
> |
printf("%s\n"," -o, --output=STRING output file prefix (default=`hydro')"); |
77 |
> |
printf("%s\n"," --model=STRING hydrodynamics model (support RoughShell and BeadModel)"); |
78 |
> |
printf("%s\n"," -b, --beads generate the beads only, hydrodynamics will be \n performed (default=off)"); |
79 |
> |
|
80 |
|
} |
81 |
|
|
82 |
+ |
void |
83 |
+ |
cmdline_parser_init (struct gengetopt_args_info *args_info) |
84 |
+ |
{ |
85 |
+ |
clear_given (args_info); |
86 |
+ |
clear_args (args_info); |
87 |
+ |
} |
88 |
|
|
89 |
< |
static char *gengetopt_strdup (const char *s); |
89 |
> |
static void |
90 |
> |
cmdline_parser_release (struct gengetopt_args_info *args_info) |
91 |
> |
{ |
92 |
> |
|
93 |
> |
if (args_info->input_arg) |
94 |
> |
{ |
95 |
> |
free (args_info->input_arg); /* free previous argument */ |
96 |
> |
args_info->input_arg = 0; |
97 |
> |
} |
98 |
> |
if (args_info->input_orig) |
99 |
> |
{ |
100 |
> |
free (args_info->input_orig); /* free previous argument */ |
101 |
> |
args_info->input_orig = 0; |
102 |
> |
} |
103 |
> |
if (args_info->output_arg) |
104 |
> |
{ |
105 |
> |
free (args_info->output_arg); /* free previous argument */ |
106 |
> |
args_info->output_arg = 0; |
107 |
> |
} |
108 |
> |
if (args_info->output_orig) |
109 |
> |
{ |
110 |
> |
free (args_info->output_orig); /* free previous argument */ |
111 |
> |
args_info->output_orig = 0; |
112 |
> |
} |
113 |
> |
if (args_info->model_arg) |
114 |
> |
{ |
115 |
> |
free (args_info->model_arg); /* free previous argument */ |
116 |
> |
args_info->model_arg = 0; |
117 |
> |
} |
118 |
> |
if (args_info->model_orig) |
119 |
> |
{ |
120 |
> |
free (args_info->model_orig); /* free previous argument */ |
121 |
> |
args_info->model_orig = 0; |
122 |
> |
} |
123 |
> |
|
124 |
> |
clear_given (args_info); |
125 |
> |
} |
126 |
|
|
127 |
+ |
int |
128 |
+ |
cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) |
129 |
+ |
{ |
130 |
+ |
FILE *outfile; |
131 |
+ |
int i = 0; |
132 |
+ |
|
133 |
+ |
outfile = fopen(filename, "w"); |
134 |
+ |
|
135 |
+ |
if (!outfile) |
136 |
+ |
{ |
137 |
+ |
fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); |
138 |
+ |
return EXIT_FAILURE; |
139 |
+ |
} |
140 |
+ |
|
141 |
+ |
if (args_info->help_given) { |
142 |
+ |
fprintf(outfile, "%s\n", "help"); |
143 |
+ |
} |
144 |
+ |
if (args_info->version_given) { |
145 |
+ |
fprintf(outfile, "%s\n", "version"); |
146 |
+ |
} |
147 |
+ |
if (args_info->input_given) { |
148 |
+ |
if (args_info->input_orig) { |
149 |
+ |
fprintf(outfile, "%s=\"%s\"\n", "input", args_info->input_orig); |
150 |
+ |
} else { |
151 |
+ |
fprintf(outfile, "%s\n", "input"); |
152 |
+ |
} |
153 |
+ |
} |
154 |
+ |
if (args_info->output_given) { |
155 |
+ |
if (args_info->output_orig) { |
156 |
+ |
fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig); |
157 |
+ |
} else { |
158 |
+ |
fprintf(outfile, "%s\n", "output"); |
159 |
+ |
} |
160 |
+ |
} |
161 |
+ |
if (args_info->model_given) { |
162 |
+ |
if (args_info->model_orig) { |
163 |
+ |
fprintf(outfile, "%s=\"%s\"\n", "model", args_info->model_orig); |
164 |
+ |
} else { |
165 |
+ |
fprintf(outfile, "%s\n", "model"); |
166 |
+ |
} |
167 |
+ |
} |
168 |
+ |
if (args_info->beads_given) { |
169 |
+ |
fprintf(outfile, "%s\n", "beads"); |
170 |
+ |
} |
171 |
+ |
|
172 |
+ |
fclose (outfile); |
173 |
+ |
|
174 |
+ |
i = EXIT_SUCCESS; |
175 |
+ |
return i; |
176 |
+ |
} |
177 |
+ |
|
178 |
+ |
void |
179 |
+ |
cmdline_parser_free (struct gengetopt_args_info *args_info) |
180 |
+ |
{ |
181 |
+ |
cmdline_parser_release (args_info); |
182 |
+ |
} |
183 |
+ |
|
184 |
+ |
|
185 |
|
/* gengetopt_strdup() */ |
186 |
|
/* strdup.c replacement of strdup, which is not standard */ |
187 |
|
char * |
188 |
|
gengetopt_strdup (const char *s) |
189 |
|
{ |
190 |
< |
char *result = (char*)malloc(strlen(s) + 1); |
190 |
> |
char *result = NULL; |
191 |
> |
if (!s) |
192 |
> |
return result; |
193 |
> |
|
194 |
> |
result = (char*)malloc(strlen(s) + 1); |
195 |
|
if (result == (char*)0) |
196 |
|
return (char*)0; |
197 |
|
strcpy(result, s); |
201 |
|
int |
202 |
|
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
203 |
|
{ |
204 |
< |
int c; /* Character of the parsed option. */ |
205 |
< |
int missing_required_options = 0; |
204 |
> |
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
205 |
> |
} |
206 |
|
|
207 |
< |
args_info->help_given = 0 ; |
208 |
< |
args_info->version_given = 0 ; |
209 |
< |
args_info->input_given = 0 ; |
210 |
< |
args_info->output_given = 0 ; |
211 |
< |
args_info->model_given = 0 ; |
212 |
< |
args_info->beads_given = 0 ; |
213 |
< |
#define clear_args() { \ |
214 |
< |
args_info->input_arg = NULL; \ |
215 |
< |
args_info->output_arg = gengetopt_strdup("hydro") ;\ |
216 |
< |
args_info->model_arg = NULL; \ |
217 |
< |
args_info->beads_flag = 0;\ |
207 |
> |
int |
208 |
> |
cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
209 |
> |
{ |
210 |
> |
int result; |
211 |
> |
|
212 |
> |
result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); |
213 |
> |
|
214 |
> |
if (result == EXIT_FAILURE) |
215 |
> |
{ |
216 |
> |
cmdline_parser_free (args_info); |
217 |
> |
exit (EXIT_FAILURE); |
218 |
> |
} |
219 |
> |
|
220 |
> |
return result; |
221 |
|
} |
222 |
|
|
223 |
< |
clear_args(); |
223 |
> |
int |
224 |
> |
cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) |
225 |
> |
{ |
226 |
> |
int result = EXIT_SUCCESS; |
227 |
|
|
228 |
+ |
if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) |
229 |
+ |
result = EXIT_FAILURE; |
230 |
+ |
|
231 |
+ |
if (result == EXIT_FAILURE) |
232 |
+ |
{ |
233 |
+ |
cmdline_parser_free (args_info); |
234 |
+ |
exit (EXIT_FAILURE); |
235 |
+ |
} |
236 |
+ |
|
237 |
+ |
return result; |
238 |
+ |
} |
239 |
+ |
|
240 |
+ |
int |
241 |
+ |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) |
242 |
+ |
{ |
243 |
+ |
int error = 0; |
244 |
+ |
|
245 |
+ |
if (! args_info->input_given) |
246 |
+ |
{ |
247 |
+ |
fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); |
248 |
+ |
error = 1; |
249 |
+ |
} |
250 |
+ |
if (! args_info->model_given) |
251 |
+ |
{ |
252 |
+ |
fprintf (stderr, "%s: '--model' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
253 |
+ |
error = 1; |
254 |
+ |
} |
255 |
+ |
|
256 |
+ |
return error; |
257 |
+ |
} |
258 |
+ |
|
259 |
+ |
int |
260 |
+ |
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) |
261 |
+ |
{ |
262 |
+ |
int c; /* Character of the parsed option. */ |
263 |
+ |
|
264 |
+ |
int error = 0; |
265 |
+ |
struct gengetopt_args_info local_args_info; |
266 |
+ |
|
267 |
+ |
if (initialize) |
268 |
+ |
cmdline_parser_init (args_info); |
269 |
+ |
|
270 |
+ |
cmdline_parser_init (&local_args_info); |
271 |
+ |
printf("\n%s\n", "\n+----------------------------------------------------------------------+ \n| ____ ____ ____ _____ ______ The OpenSource, Object-oriented | \n| / __ \\/ __ \\/ __ \\/ ___// ____/ Parallel Simulation Engine. | \n| / / / / / / / /_/ /\\__ \\/ __/ | \n| / /_/ / /_/ / ____/___/ / /___ Copyright 2004-2006 by the | \n| \\____/\\____/_/ /____/_____/ University of Notre Dame. | \n| | \n| http://www.oopse.org |\n| | \n| OOPSE is an OpenScience project. All source code is available for |\n| any use subject to only one condition: | \n| |\n| Any published work resulting from the use of this code must cite the | \n| following paper: M. A. Meineke, C. F. Vardeman II, T. Lin, | \n| C. J. Fennell, and J. D. Gezelter, | \n| J. Comput. Chem. 26, pp. 252-271 (2005). | \n+----------------------------------------------------------------------+"); |
272 |
+ |
|
273 |
|
optarg = 0; |
274 |
< |
optind = 1; |
274 |
> |
optind = 0; |
275 |
|
opterr = 1; |
276 |
|
optopt = '?'; |
277 |
|
|
298 |
|
switch (c) |
299 |
|
{ |
300 |
|
case 'h': /* Print help and exit. */ |
110 |
– |
clear_args (); |
301 |
|
cmdline_parser_print_help (); |
302 |
+ |
cmdline_parser_free (&local_args_info); |
303 |
|
exit (EXIT_SUCCESS); |
304 |
|
|
305 |
|
case 'V': /* Print version and exit. */ |
115 |
– |
clear_args (); |
306 |
|
cmdline_parser_print_version (); |
307 |
+ |
cmdline_parser_free (&local_args_info); |
308 |
|
exit (EXIT_SUCCESS); |
309 |
|
|
310 |
|
case 'i': /* input dump file. */ |
311 |
< |
if (args_info->input_given) |
311 |
> |
if (local_args_info.input_given) |
312 |
|
{ |
313 |
< |
fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
314 |
< |
clear_args (); |
124 |
< |
exit (EXIT_FAILURE); |
313 |
> |
fprintf (stderr, "%s: `--input' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
314 |
> |
goto failure; |
315 |
|
} |
316 |
+ |
if (args_info->input_given && ! override) |
317 |
+ |
continue; |
318 |
+ |
local_args_info.input_given = 1; |
319 |
|
args_info->input_given = 1; |
320 |
+ |
if (args_info->input_arg) |
321 |
+ |
free (args_info->input_arg); /* free previous string */ |
322 |
|
args_info->input_arg = gengetopt_strdup (optarg); |
323 |
+ |
if (args_info->input_orig) |
324 |
+ |
free (args_info->input_orig); /* free previous string */ |
325 |
+ |
args_info->input_orig = gengetopt_strdup (optarg); |
326 |
|
break; |
327 |
|
|
328 |
|
case 'o': /* output file prefix. */ |
329 |
< |
if (args_info->output_given) |
329 |
> |
if (local_args_info.output_given) |
330 |
|
{ |
331 |
< |
fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
332 |
< |
clear_args (); |
135 |
< |
exit (EXIT_FAILURE); |
331 |
> |
fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
332 |
> |
goto failure; |
333 |
|
} |
334 |
+ |
if (args_info->output_given && ! override) |
335 |
+ |
continue; |
336 |
+ |
local_args_info.output_given = 1; |
337 |
|
args_info->output_given = 1; |
338 |
|
if (args_info->output_arg) |
339 |
< |
free (args_info->output_arg); /* free default string */ |
339 |
> |
free (args_info->output_arg); /* free previous string */ |
340 |
|
args_info->output_arg = gengetopt_strdup (optarg); |
341 |
+ |
if (args_info->output_orig) |
342 |
+ |
free (args_info->output_orig); /* free previous string */ |
343 |
+ |
args_info->output_orig = gengetopt_strdup (optarg); |
344 |
|
break; |
345 |
|
|
346 |
|
case 'b': /* generate the beads only, hydrodynamics will be performed. */ |
347 |
< |
if (args_info->beads_given) |
347 |
> |
if (local_args_info.beads_given) |
348 |
|
{ |
349 |
< |
fprintf (stderr, "%s: `--beads' (`-b') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
350 |
< |
clear_args (); |
148 |
< |
exit (EXIT_FAILURE); |
349 |
> |
fprintf (stderr, "%s: `--beads' (`-b') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
350 |
> |
goto failure; |
351 |
|
} |
352 |
+ |
if (args_info->beads_given && ! override) |
353 |
+ |
continue; |
354 |
+ |
local_args_info.beads_given = 1; |
355 |
|
args_info->beads_given = 1; |
356 |
|
args_info->beads_flag = !(args_info->beads_flag); |
357 |
|
break; |
361 |
|
/* hydrodynamics model (support RoughShell and BeadModel). */ |
362 |
|
if (strcmp (long_options[option_index].name, "model") == 0) |
363 |
|
{ |
364 |
< |
if (args_info->model_given) |
364 |
> |
if (local_args_info.model_given) |
365 |
|
{ |
366 |
< |
fprintf (stderr, "%s: `--model' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
367 |
< |
clear_args (); |
163 |
< |
exit (EXIT_FAILURE); |
366 |
> |
fprintf (stderr, "%s: `--model' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
367 |
> |
goto failure; |
368 |
|
} |
369 |
+ |
if (args_info->model_given && ! override) |
370 |
+ |
continue; |
371 |
+ |
local_args_info.model_given = 1; |
372 |
|
args_info->model_given = 1; |
373 |
+ |
if (args_info->model_arg) |
374 |
+ |
free (args_info->model_arg); /* free previous string */ |
375 |
|
args_info->model_arg = gengetopt_strdup (optarg); |
376 |
< |
break; |
376 |
> |
if (args_info->model_orig) |
377 |
> |
free (args_info->model_orig); /* free previous string */ |
378 |
> |
args_info->model_orig = gengetopt_strdup (optarg); |
379 |
|
} |
380 |
|
|
381 |
< |
|
381 |
> |
break; |
382 |
|
case '?': /* Invalid option. */ |
383 |
|
/* `getopt_long' already printed an error message. */ |
384 |
< |
exit (EXIT_FAILURE); |
384 |
> |
goto failure; |
385 |
|
|
386 |
|
default: /* bug: option not considered. */ |
387 |
< |
fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); |
387 |
> |
fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
388 |
|
abort (); |
389 |
|
} /* switch */ |
390 |
|
} /* while */ |
391 |
|
|
392 |
|
|
393 |
< |
if (! args_info->input_given) |
393 |
> |
|
394 |
> |
if (check_required) |
395 |
|
{ |
396 |
< |
fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE); |
185 |
< |
missing_required_options = 1; |
396 |
> |
error += cmdline_parser_required2 (args_info, argv[0], additional_error); |
397 |
|
} |
187 |
– |
if (! args_info->model_given) |
188 |
– |
{ |
189 |
– |
fprintf (stderr, "%s: '--model' option required\n", CMDLINE_PARSER_PACKAGE); |
190 |
– |
missing_required_options = 1; |
191 |
– |
} |
192 |
– |
if ( missing_required_options ) |
193 |
– |
exit (EXIT_FAILURE); |
398 |
|
|
399 |
+ |
cmdline_parser_release (&local_args_info); |
400 |
+ |
|
401 |
+ |
if ( error ) |
402 |
+ |
goto failure; |
403 |
+ |
|
404 |
|
return 0; |
405 |
+ |
|
406 |
+ |
failure: |
407 |
+ |
|
408 |
+ |
cmdline_parser_print_help (); |
409 |
+ |
cmdline_parser_release (&local_args_info); |
410 |
+ |
return (EXIT_FAILURE); |
411 |
|
} |