ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/hydrodynamics/HydroCmd.cpp
Revision: 1793
Committed: Fri Aug 31 21:16:10 2012 UTC (12 years, 8 months ago) by gezelter
File size: 18548 byte(s)
Log Message:
Cleaning up some warning messages on linux

File Contents

# Content
1 /*
2 File autogenerated by gengetopt version 2.22.4
3 generated with the following command:
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 #ifndef FIX_UNUSED
21 #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
22 #endif
23
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, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |\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",
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 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 args_info->inputs = 0;
143 args_info->inputs_num = 0;
144 }
145
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 = 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);
280 return result;
281 }
282
283 int
284 cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
285 {
286 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
287 }
288
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 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, &params, 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 const char *val = value;
403 int found;
404 char **string_field;
405 FIX_UNUSED (field);
406
407 found = 0;
408
409 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
410 {
411 if (short_opt != '-')
412 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
413 package_name, long_opt, short_opt,
414 (additional_error ? additional_error : ""));
415 else
416 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
417 package_name, long_opt,
418 (additional_error ? additional_error : ""));
419 return 1; /* failure */
420 }
421
422 FIX_UNUSED (default_value);
423
424 if (field_given && *field_given && ! override)
425 return 0;
426 if (prev_given)
427 (*prev_given)++;
428 if (field_given)
429 (*field_given)++;
430 if (possible_values)
431 val = possible_values[found];
432
433 switch(arg_type) {
434 case ARG_FLAG:
435 *((int *)field) = !*((int *)field);
436 break;
437 case ARG_STRING:
438 if (val) {
439 string_field = (char **)field;
440 if (!no_free && *string_field)
441 free (*string_field); /* free previous string */
442 *string_field = gengetopt_strdup (val);
443 }
444 break;
445 default:
446 break;
447 };
448
449
450 /* store the original value */
451 switch(arg_type) {
452 case ARG_NO:
453 case ARG_FLAG:
454 break;
455 default:
456 if (value && orig_field) {
457 if (no_free) {
458 *orig_field = value;
459 } else {
460 if (*orig_field)
461 free (*orig_field); /* free previous string */
462 *orig_field = gengetopt_strdup (value);
463 }
464 }
465 };
466
467 return 0; /* OK */
468 }
469
470
471 int
472 cmdline_parser_internal (
473 int argc, char **argv, struct gengetopt_args_info *args_info,
474 struct cmdline_parser_params *params, const char *additional_error)
475 {
476 int c; /* Character of the parsed option. */
477
478 int error = 0;
479 struct gengetopt_args_info local_args_info;
480
481 int override;
482 int initialize;
483 int check_required;
484 int check_ambiguity;
485
486 package_name = argv[0];
487
488 override = params->override;
489 initialize = params->initialize;
490 check_required = params->check_required;
491 check_ambiguity = params->check_ambiguity;
492
493 if (initialize)
494 cmdline_parser_init (args_info);
495
496 cmdline_parser_init (&local_args_info);
497
498 optarg = 0;
499 optind = 0;
500 opterr = params->print_errors;
501 optopt = '?';
502
503 while (1)
504 {
505 int option_index = 0;
506
507 static struct option long_options[] = {
508 { "help", 0, NULL, 'h' },
509 { "version", 0, NULL, 'V' },
510 { "input", 1, NULL, 'i' },
511 { "output", 1, NULL, 'o' },
512 { "model", 1, NULL, 0 },
513 { "beads", 0, NULL, 'b' },
514 { 0, 0, 0, 0 }
515 };
516
517 c = getopt_long (argc, argv, "hVi:o:b", long_options, &option_index);
518
519 if (c == -1) break; /* Exit from `while (1)' loop. */
520
521 switch (c)
522 {
523 case 'h': /* Print help and exit. */
524 cmdline_parser_print_help ();
525 cmdline_parser_free (&local_args_info);
526 exit (EXIT_SUCCESS);
527
528 case 'V': /* Print version and exit. */
529 cmdline_parser_print_version ();
530 cmdline_parser_free (&local_args_info);
531 exit (EXIT_SUCCESS);
532
533 case 'i': /* input MetaData (md) file. */
534
535
536 if (update_arg( (void *)&(args_info->input_arg),
537 &(args_info->input_orig), &(args_info->input_given),
538 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
539 check_ambiguity, override, 0, 0,
540 "input", 'i',
541 additional_error))
542 goto failure;
543
544 break;
545 case 'o': /* output file prefix. */
546
547
548 if (update_arg( (void *)&(args_info->output_arg),
549 &(args_info->output_orig), &(args_info->output_given),
550 &(local_args_info.output_given), optarg, 0, "hydro", ARG_STRING,
551 check_ambiguity, override, 0, 0,
552 "output", 'o',
553 additional_error))
554 goto failure;
555
556 break;
557 case 'b': /* generate the beads only, hydrodynamics will be performed. */
558
559
560 if (update_arg((void *)&(args_info->beads_flag), 0, &(args_info->beads_given),
561 &(local_args_info.beads_given), optarg, 0, 0, ARG_FLAG,
562 check_ambiguity, override, 1, 0, "beads", 'b',
563 additional_error))
564 goto failure;
565
566 break;
567
568 case 0: /* Long option with no short option */
569 /* hydrodynamics model (supports RoughShell and BeadModel). */
570 if (strcmp (long_options[option_index].name, "model") == 0)
571 {
572
573
574 if (update_arg( (void *)&(args_info->model_arg),
575 &(args_info->model_orig), &(args_info->model_given),
576 &(local_args_info.model_given), optarg, 0, 0, ARG_STRING,
577 check_ambiguity, override, 0, 0,
578 "model", '-',
579 additional_error))
580 goto failure;
581
582 }
583
584 break;
585 case '?': /* Invalid option. */
586 /* `getopt_long' already printed an error message. */
587 goto failure;
588
589 default: /* bug: option not considered. */
590 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
591 abort ();
592 } /* switch */
593 } /* while */
594
595
596
597 if (check_required)
598 {
599 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
600 }
601
602 cmdline_parser_release (&local_args_info);
603
604 if ( error )
605 return (EXIT_FAILURE);
606
607 if (optind < argc)
608 {
609 int i = 0 ;
610 int found_prog_name = 0;
611 /* whether program name, i.e., argv[0], is in the remaining args
612 (this may happen with some implementations of getopt,
613 but surely not with the one included by gengetopt) */
614
615 i = optind;
616 while (i < argc)
617 if (argv[i++] == argv[0]) {
618 found_prog_name = 1;
619 break;
620 }
621 i = 0;
622
623 args_info->inputs_num = argc - optind - found_prog_name;
624 args_info->inputs =
625 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
626 while (optind < argc)
627 if (argv[optind++] != argv[0])
628 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
629 }
630
631 return 0;
632
633 failure:
634
635 cmdline_parser_release (&local_args_info);
636 return (EXIT_FAILURE);
637 }

Properties

Name Value
svn:keywords Author Id Revision Date