ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/hydrodynamics/HydroCmd.c
Revision: 3206
Committed: Tue Aug 14 17:40:33 2007 UTC (17 years, 8 months ago) by xsun
Content type: text/plain
File size: 12877 byte(s)
Log Message:
Bug fixes for non-declared objects

File Contents

# Content
1 /*
2 File autogenerated by gengetopt version 2.16
3 generated with the following command:
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 /* 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 {
65 printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
66 }
67
68 void
69 cmdline_parser_print_help (void)
70 {
71 cmdline_parser_print_version ();
72 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+----------------------------------------------------------------------+");
73 printf("\nUsage: Hydro [OPTIONS]...\n\n");
74 printf("%s\n"," -h, --help Print help and exit");
75 printf("%s\n"," -V, --version Print version and exit");
76 printf("%s\n"," -i, --input=filename input MetaData (md) file");
77 printf("%s\n"," -o, --output=STRING output file prefix (default=`hydro')");
78 printf("%s\n"," --model=STRING hydrodynamics model (supports RoughShell and BeadModel)");
79 printf("%s\n"," -b, --beads generate the beads only, hydrodynamics will be \n performed (default=off)");
80
81 }
82
83 void
84 cmdline_parser_init (struct gengetopt_args_info *args_info)
85 {
86 clear_given (args_info);
87 clear_args (args_info);
88 }
89
90 static void
91 cmdline_parser_release (struct gengetopt_args_info *args_info)
92 {
93
94 if (args_info->input_arg)
95 {
96 free (args_info->input_arg); /* free previous argument */
97 args_info->input_arg = 0;
98 }
99 if (args_info->input_orig)
100 {
101 free (args_info->input_orig); /* free previous argument */
102 args_info->input_orig = 0;
103 }
104 if (args_info->output_arg)
105 {
106 free (args_info->output_arg); /* free previous argument */
107 args_info->output_arg = 0;
108 }
109 if (args_info->output_orig)
110 {
111 free (args_info->output_orig); /* free previous argument */
112 args_info->output_orig = 0;
113 }
114 if (args_info->model_arg)
115 {
116 free (args_info->model_arg); /* free previous argument */
117 args_info->model_arg = 0;
118 }
119 if (args_info->model_orig)
120 {
121 free (args_info->model_orig); /* free previous argument */
122 args_info->model_orig = 0;
123 }
124
125 clear_given (args_info);
126 }
127
128 int
129 cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
130 {
131 FILE *outfile;
132 int i = 0;
133
134 outfile = fopen(filename, "w");
135
136 if (!outfile)
137 {
138 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
139 return EXIT_FAILURE;
140 }
141
142 if (args_info->help_given) {
143 fprintf(outfile, "%s\n", "help");
144 }
145 if (args_info->version_given) {
146 fprintf(outfile, "%s\n", "version");
147 }
148 if (args_info->input_given) {
149 if (args_info->input_orig) {
150 fprintf(outfile, "%s=\"%s\"\n", "input", args_info->input_orig);
151 } else {
152 fprintf(outfile, "%s\n", "input");
153 }
154 }
155 if (args_info->output_given) {
156 if (args_info->output_orig) {
157 fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig);
158 } else {
159 fprintf(outfile, "%s\n", "output");
160 }
161 }
162 if (args_info->model_given) {
163 if (args_info->model_orig) {
164 fprintf(outfile, "%s=\"%s\"\n", "model", args_info->model_orig);
165 } else {
166 fprintf(outfile, "%s\n", "model");
167 }
168 }
169 if (args_info->beads_given) {
170 fprintf(outfile, "%s\n", "beads");
171 }
172
173 fclose (outfile);
174
175 i = EXIT_SUCCESS;
176 return i;
177 }
178
179 void
180 cmdline_parser_free (struct gengetopt_args_info *args_info)
181 {
182 cmdline_parser_release (args_info);
183 }
184
185
186 /* gengetopt_strdup() */
187 /* strdup.c replacement of strdup, which is not standard */
188 char *
189 gengetopt_strdup (const char *s)
190 {
191 char *result = NULL;
192 if (!s)
193 return result;
194
195 result = (char*)malloc(strlen(s) + 1);
196 if (result == (char*)0)
197 return (char*)0;
198 strcpy(result, s);
199 return result;
200 }
201
202 int
203 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
204 {
205 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
206 }
207
208 int
209 cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
210 {
211 int result;
212
213 result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
214
215 if (result == EXIT_FAILURE)
216 {
217 cmdline_parser_free (args_info);
218 exit (EXIT_FAILURE);
219 }
220
221 return result;
222 }
223
224 int
225 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
226 {
227 int result = EXIT_SUCCESS;
228
229 if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
230 result = EXIT_FAILURE;
231
232 if (result == EXIT_FAILURE)
233 {
234 cmdline_parser_free (args_info);
235 exit (EXIT_FAILURE);
236 }
237
238 return result;
239 }
240
241 int
242 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
243 {
244 int error = 0;
245
246 if (! args_info->input_given)
247 {
248 fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
249 error = 1;
250 }
251 if (! args_info->model_given)
252 {
253 fprintf (stderr, "%s: '--model' option required%s\n", prog_name, (additional_error ? additional_error : ""));
254 error = 1;
255 }
256
257 return error;
258 }
259
260 int
261 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)
262 {
263 int c; /* Character of the parsed option. */
264
265 int error = 0;
266 struct gengetopt_args_info local_args_info;
267
268 if (initialize)
269 cmdline_parser_init (args_info);
270
271 cmdline_parser_init (&local_args_info);
272
273 optarg = 0;
274 optind = 0;
275 opterr = 1;
276 optopt = '?';
277
278 while (1)
279 {
280 int option_index = 0;
281 char *stop_char;
282
283 static struct option long_options[] = {
284 { "help", 0, NULL, 'h' },
285 { "version", 0, NULL, 'V' },
286 { "input", 1, NULL, 'i' },
287 { "output", 1, NULL, 'o' },
288 { "model", 1, NULL, 0 },
289 { "beads", 0, NULL, 'b' },
290 { NULL, 0, NULL, 0 }
291 };
292
293 stop_char = 0;
294 c = getopt_long (argc, argv, "hVi:o:b", long_options, &option_index);
295
296 if (c == -1) break; /* Exit from `while (1)' loop. */
297
298 switch (c)
299 {
300 case 'h': /* Print help and exit. */
301 cmdline_parser_print_help ();
302 cmdline_parser_free (&local_args_info);
303 exit (EXIT_SUCCESS);
304
305 case 'V': /* Print version and exit. */
306 cmdline_parser_print_version ();
307 cmdline_parser_free (&local_args_info);
308 exit (EXIT_SUCCESS);
309
310 case 'i': /* input MetaData (md) file. */
311 if (local_args_info.input_given)
312 {
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 (local_args_info.output_given)
330 {
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 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 (local_args_info.beads_given)
348 {
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;
358
359
360 case 0: /* Long option with no short option */
361 /* hydrodynamics model (supports RoughShell and BeadModel). */
362 if (strcmp (long_options[option_index].name, "model") == 0)
363 {
364 if (local_args_info.model_given)
365 {
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 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 break;
382 case '?': /* Invalid option. */
383 /* `getopt_long' already printed an error message. */
384 goto failure;
385
386 default: /* bug: option not considered. */
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
394 if (check_required)
395 {
396 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
397 }
398
399 cmdline_parser_release (&local_args_info);
400
401 if ( error )
402 return (EXIT_FAILURE);
403
404 return 0;
405
406 failure:
407
408 cmdline_parser_release (&local_args_info);
409 return (EXIT_FAILURE);
410 }