ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/hydrodynamics/HydroCmd.cpp
Revision: 1630
Committed: Wed Sep 14 21:40:12 2011 UTC (13 years, 7 months ago) by gezelter
Content type: text/plain
Original Path: branches/development/src/applications/hydrodynamics/HydroCmd.c
File size: 18560 byte(s)
Log Message:
updating gengetopt runs

File Contents

# User Rev Content
1 tim 891 /*
2 gezelter 1630 File autogenerated by gengetopt version 2.22.4
3 tim 891 generated with the following command:
4 gezelter 1630 gengetopt -F HydroCmd -u
5 tim 891
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 gezelter 938 /* If we use autoconf. */
12     #ifdef HAVE_CONFIG_H
13     #include "config.h"
14     #endif
15 tim 891
16     #include <stdio.h>
17     #include <stdlib.h>
18     #include <string.h>
19    
20 gezelter 1630 #ifndef FIX_UNUSED
21     #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
22     #endif
23 tim 891
24 gezelter 1630 #include <getopt.h>
25    
26 tim 891 #include "HydroCmd.h"
27    
28 gezelter 1390 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 gezelter 1630 const char *gengetopt_args_info_usage = "Usage: Hydro [OPTIONS]... [FILES]...";
31 gezelter 1390
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 gezelter 938 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 gezelter 1630 cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
56 gezelter 1390 struct cmdline_parser_params *params, const char *additional_error);
57 gezelter 938
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 gezelter 1630 FIX_UNUSED (args_info);
79 gezelter 938 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 gezelter 1390 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 tim 891 void
104     cmdline_parser_print_version (void)
105     {
106 gezelter 1630 printf ("%s %s\n",
107     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
108     CMDLINE_PARSER_VERSION);
109 tim 891 }
110    
111 gezelter 1390 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 gezelter 1630 printf("%s\n\n", gengetopt_args_info_description);
124 gezelter 1390 }
125    
126 tim 891 void
127     cmdline_parser_print_help (void)
128     {
129 gezelter 1390 int i = 0;
130     print_help_common();
131     while (gengetopt_args_info_help[i])
132     printf("%s\n", gengetopt_args_info_help[i++]);
133 tim 891 }
134    
135 gezelter 938 void
136     cmdline_parser_init (struct gengetopt_args_info *args_info)
137     {
138     clear_given (args_info);
139     clear_args (args_info);
140 gezelter 1390 init_args_info (args_info);
141 gezelter 1630
142     args_info->inputs = 0;
143     args_info->inputs_num = 0;
144 gezelter 938 }
145 tim 891
146 gezelter 1390 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 gezelter 938 static void
169 gezelter 1390 free_string_field (char **s)
170     {
171     if (*s)
172     {
173     free (*s);
174     *s = 0;
175     }
176     }
177    
178    
179     static void
180 gezelter 938 cmdline_parser_release (struct gengetopt_args_info *args_info)
181     {
182 gezelter 1630 unsigned int i;
183 gezelter 1390 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 gezelter 938
190 gezelter 1390
191 gezelter 1630 for (i = 0; i < args_info->inputs_num; ++i)
192     free (args_info->inputs [i]);
193 gezelter 1390
194 gezelter 1630 if (args_info->inputs_num)
195     free (args_info->inputs);
196    
197 gezelter 1390 clear_given (args_info);
198     }
199    
200    
201     static void
202 gezelter 1630 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
203 gezelter 1390 {
204 gezelter 1630 FIX_UNUSED (values);
205 gezelter 1390 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 gezelter 938 {
220 gezelter 1390 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
221     return EXIT_FAILURE;
222 gezelter 938 }
223 gezelter 1390
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 gezelter 938
237 gezelter 1390
238     i = EXIT_SUCCESS;
239     return i;
240 gezelter 938 }
241 tim 891
242 gezelter 938 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 gezelter 1390 i = cmdline_parser_dump(outfile, args_info);
257 gezelter 938 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 gezelter 1390 /** @brief replacement of strdup, which is not standard */
269 tim 891 char *
270     gengetopt_strdup (const char *s)
271     {
272 gezelter 1630 char *result = 0;
273 gezelter 938 if (!s)
274     return result;
275    
276     result = (char*)malloc(strlen(s) + 1);
277 tim 891 if (result == (char*)0)
278     return (char*)0;
279     strcpy(result, s);
280     return result;
281     }
282    
283     int
284 gezelter 1630 cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
285 tim 891 {
286 gezelter 938 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
287     }
288 tim 891
289 gezelter 938 int
290 gezelter 1630 cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
291 gezelter 1390 struct cmdline_parser_params *params)
292     {
293     int result;
294 gezelter 1630 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
295 gezelter 1390
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 gezelter 1630 cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
307 gezelter 938 {
308     int result;
309 gezelter 1390 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 gezelter 938
317 gezelter 1630 result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
318 gezelter 938
319     if (result == EXIT_FAILURE)
320     {
321     cmdline_parser_free (args_info);
322     exit (EXIT_FAILURE);
323     }
324    
325     return result;
326 tim 891 }
327    
328 gezelter 938 int
329     cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
330     {
331     int result = EXIT_SUCCESS;
332 tim 891
333 gezelter 1630 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
334 gezelter 938 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 gezelter 1630 FIX_UNUSED (additional_error);
350 gezelter 938
351 gezelter 1390 /* checks for required options */
352 gezelter 938 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 gezelter 1390
358 gezelter 938 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 gezelter 1390
364    
365     /* checks for dependences among options */
366 gezelter 938
367     return error;
368     }
369    
370 gezelter 1390
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 gezelter 1630 char *value, const char *possible_values[],
395     const char *default_value,
396 gezelter 1390 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 gezelter 1630 FIX_UNUSED (field);
407 gezelter 1390
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 gezelter 1630 FIX_UNUSED (default_value);
425 gezelter 1390
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 gezelter 938 int
474 gezelter 1630 cmdline_parser_internal (
475     int argc, char **argv, struct gengetopt_args_info *args_info,
476 gezelter 1390 struct cmdline_parser_params *params, const char *additional_error)
477 gezelter 938 {
478     int c; /* Character of the parsed option. */
479    
480     int error = 0;
481     struct gengetopt_args_info local_args_info;
482 gezelter 1390
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 gezelter 938
495     if (initialize)
496     cmdline_parser_init (args_info);
497    
498     cmdline_parser_init (&local_args_info);
499    
500 tim 891 optarg = 0;
501 gezelter 938 optind = 0;
502 gezelter 1390 opterr = params->print_errors;
503 tim 891 optopt = '?';
504    
505     while (1)
506     {
507     int option_index = 0;
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' },
514     { "model", 1, NULL, 0 },
515 tim 921 { "beads", 0, NULL, 'b' },
516 gezelter 1630 { 0, 0, 0, 0 }
517 tim 891 };
518    
519 tim 921 c = getopt_long (argc, argv, "hVi:o:b", long_options, &option_index);
520 tim 891
521     if (c == -1) break; /* Exit from `while (1)' loop. */
522    
523     switch (c)
524     {
525     case 'h': /* Print help and exit. */
526     cmdline_parser_print_help ();
527 gezelter 938 cmdline_parser_free (&local_args_info);
528 tim 891 exit (EXIT_SUCCESS);
529    
530     case 'V': /* Print version and exit. */
531     cmdline_parser_print_version ();
532 gezelter 938 cmdline_parser_free (&local_args_info);
533 tim 891 exit (EXIT_SUCCESS);
534    
535 xsun 1177 case 'i': /* input MetaData (md) file. */
536 gezelter 1390
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 tim 891 break;
547     case 'o': /* output file prefix. */
548 gezelter 1390
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 tim 891 break;
559 tim 921 case 'b': /* generate the beads only, hydrodynamics will be performed. */
560 gezelter 1390
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 tim 921 break;
569 tim 891
570     case 0: /* Long option with no short option */
571 xsun 1177 /* hydrodynamics model (supports RoughShell and BeadModel). */
572 tim 906 if (strcmp (long_options[option_index].name, "model") == 0)
573 tim 891 {
574 gezelter 1390
575    
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    
584 tim 891 }
585    
586 gezelter 938 break;
587 tim 891 case '?': /* Invalid option. */
588     /* `getopt_long' already printed an error message. */
589 gezelter 938 goto failure;
590 tim 891
591     default: /* bug: option not considered. */
592 gezelter 938 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
593 tim 891 abort ();
594     } /* switch */
595     } /* while */
596    
597    
598 gezelter 938
599     if (check_required)
600 tim 891 {
601 gezelter 938 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
602 tim 891 }
603    
604 gezelter 938 cmdline_parser_release (&local_args_info);
605    
606     if ( error )
607 xsun 1177 return (EXIT_FAILURE);
608 gezelter 938
609 gezelter 1630 if (optind < argc)
610     {
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     }
632    
633 tim 891 return 0;
634 gezelter 938
635     failure:
636    
637     cmdline_parser_release (&local_args_info);
638     return (EXIT_FAILURE);
639 tim 891 }

Properties

Name Value
svn:keywords Author Id Revision Date