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

# 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 1665 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 gezelter 1390
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     const char *val = value;
403     int found;
404     char **string_field;
405 gezelter 1630 FIX_UNUSED (field);
406 gezelter 1390
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 gezelter 1630 FIX_UNUSED (default_value);
423 gezelter 1390
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 gezelter 938 int
472 gezelter 1630 cmdline_parser_internal (
473     int argc, char **argv, struct gengetopt_args_info *args_info,
474 gezelter 1390 struct cmdline_parser_params *params, const char *additional_error)
475 gezelter 938 {
476     int c; /* Character of the parsed option. */
477    
478     int error = 0;
479     struct gengetopt_args_info local_args_info;
480 gezelter 1390
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 gezelter 938
493     if (initialize)
494     cmdline_parser_init (args_info);
495    
496     cmdline_parser_init (&local_args_info);
497    
498 tim 891 optarg = 0;
499 gezelter 938 optind = 0;
500 gezelter 1390 opterr = params->print_errors;
501 tim 891 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 tim 921 { "beads", 0, NULL, 'b' },
514 gezelter 1630 { 0, 0, 0, 0 }
515 tim 891 };
516    
517 tim 921 c = getopt_long (argc, argv, "hVi:o:b", long_options, &option_index);
518 tim 891
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 gezelter 938 cmdline_parser_free (&local_args_info);
526 tim 891 exit (EXIT_SUCCESS);
527    
528     case 'V': /* Print version and exit. */
529     cmdline_parser_print_version ();
530 gezelter 938 cmdline_parser_free (&local_args_info);
531 tim 891 exit (EXIT_SUCCESS);
532    
533 xsun 1177 case 'i': /* input MetaData (md) file. */
534 gezelter 1390
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 tim 891 break;
545     case 'o': /* output file prefix. */
546 gezelter 1390
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 tim 891 break;
557 tim 921 case 'b': /* generate the beads only, hydrodynamics will be performed. */
558 gezelter 1390
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 tim 921 break;
567 tim 891
568     case 0: /* Long option with no short option */
569 xsun 1177 /* hydrodynamics model (supports RoughShell and BeadModel). */
570 tim 906 if (strcmp (long_options[option_index].name, "model") == 0)
571 tim 891 {
572 gezelter 1390
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 tim 891 }
583    
584 gezelter 938 break;
585 tim 891 case '?': /* Invalid option. */
586     /* `getopt_long' already printed an error message. */
587 gezelter 938 goto failure;
588 tim 891
589     default: /* bug: option not considered. */
590 gezelter 938 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
591 tim 891 abort ();
592     } /* switch */
593     } /* while */
594    
595    
596 gezelter 938
597     if (check_required)
598 tim 891 {
599 gezelter 938 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
600 tim 891 }
601    
602 gezelter 938 cmdline_parser_release (&local_args_info);
603    
604     if ( error )
605 xsun 1177 return (EXIT_FAILURE);
606 gezelter 938
607 gezelter 1630 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 tim 891 return 0;
632 gezelter 938
633     failure:
634    
635     cmdline_parser_release (&local_args_info);
636     return (EXIT_FAILURE);
637 tim 891 }

Properties

Name Value
svn:keywords Author Id Revision Date