ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/hydrodynamics/HydroCmd.c
Revision: 2634
Committed: Fri Mar 17 23:20:35 2006 UTC (18 years, 4 months ago) by tim
Content type: text/plain
File size: 5068 byte(s)
Log Message:
refactor Hydrodynamics module.

File Contents

# User Rev Content
1 tim 2596 /*
2     File autogenerated by gengetopt version 2.11
3     generated with the following command:
4     /home/maul/gezelter/tim/program/gengetopt-2.11/src/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    
16     /* If we use autoconf. */
17     #ifdef HAVE_CONFIG_H
18     #include "config.h"
19     #endif
20    
21     #include "getopt.h"
22    
23     #include "HydroCmd.h"
24    
25     void
26     cmdline_parser_print_version (void)
27     {
28     printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
29     }
30    
31     void
32     cmdline_parser_print_help (void)
33     {
34     cmdline_parser_print_version ();
35     printf("\n"
36     "Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE);
37     printf("\n");
38 tim 2634 printf(" -h, --help Print help and exit\n");
39     printf(" -V, --version Print version and exit\n");
40     printf(" -i, --input=filename input dump file\n");
41     printf(" -o, --output=STRING output file prefix (default=`hydro')\n");
42     printf(" --model=STRING hydrodynamics model (support RoughShell and BeadModel)\n");
43 tim 2596 }
44    
45    
46     static char *gengetopt_strdup (const char *s);
47    
48     /* gengetopt_strdup() */
49     /* strdup.c replacement of strdup, which is not standard */
50     char *
51     gengetopt_strdup (const char *s)
52     {
53     char *result = (char*)malloc(strlen(s) + 1);
54     if (result == (char*)0)
55     return (char*)0;
56     strcpy(result, s);
57     return result;
58     }
59    
60     int
61     cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
62     {
63     int c; /* Character of the parsed option. */
64     int missing_required_options = 0;
65    
66     args_info->help_given = 0 ;
67     args_info->version_given = 0 ;
68     args_info->input_given = 0 ;
69     args_info->output_given = 0 ;
70     args_info->model_given = 0 ;
71     #define clear_args() { \
72     args_info->input_arg = NULL; \
73     args_info->output_arg = gengetopt_strdup("hydro") ;\
74     args_info->model_arg = NULL; \
75     }
76    
77     clear_args();
78    
79     optarg = 0;
80     optind = 1;
81     opterr = 1;
82     optopt = '?';
83    
84     while (1)
85     {
86     int option_index = 0;
87     char *stop_char;
88    
89     static struct option long_options[] = {
90     { "help", 0, NULL, 'h' },
91     { "version", 0, NULL, 'V' },
92     { "input", 1, NULL, 'i' },
93     { "output", 1, NULL, 'o' },
94     { "model", 1, NULL, 0 },
95     { NULL, 0, NULL, 0 }
96     };
97    
98     stop_char = 0;
99     c = getopt_long (argc, argv, "hVi:o:", long_options, &option_index);
100    
101     if (c == -1) break; /* Exit from `while (1)' loop. */
102    
103     switch (c)
104     {
105     case 'h': /* Print help and exit. */
106     clear_args ();
107     cmdline_parser_print_help ();
108     exit (EXIT_SUCCESS);
109    
110     case 'V': /* Print version and exit. */
111     clear_args ();
112     cmdline_parser_print_version ();
113     exit (EXIT_SUCCESS);
114    
115     case 'i': /* input dump file. */
116     if (args_info->input_given)
117     {
118     fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE);
119     clear_args ();
120     exit (EXIT_FAILURE);
121     }
122     args_info->input_given = 1;
123     args_info->input_arg = gengetopt_strdup (optarg);
124     break;
125    
126     case 'o': /* output file prefix. */
127     if (args_info->output_given)
128     {
129     fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
130     clear_args ();
131     exit (EXIT_FAILURE);
132     }
133     args_info->output_given = 1;
134     if (args_info->output_arg)
135     free (args_info->output_arg); /* free default string */
136     args_info->output_arg = gengetopt_strdup (optarg);
137     break;
138    
139    
140     case 0: /* Long option with no short option */
141     /* hydrodynamics model (support RoughShell and BeadModel). */
142 tim 2634 if (strcmp (long_options[option_index].name, "model") == 0)
143 tim 2596 {
144     if (args_info->model_given)
145     {
146     fprintf (stderr, "%s: `--model' option given more than once\n", CMDLINE_PARSER_PACKAGE);
147     clear_args ();
148     exit (EXIT_FAILURE);
149     }
150     args_info->model_given = 1;
151     args_info->model_arg = gengetopt_strdup (optarg);
152     break;
153     }
154    
155    
156     case '?': /* Invalid option. */
157     /* `getopt_long' already printed an error message. */
158     exit (EXIT_FAILURE);
159    
160     default: /* bug: option not considered. */
161     fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
162     abort ();
163     } /* switch */
164     } /* while */
165    
166    
167     if (! args_info->input_given)
168     {
169     fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE);
170     missing_required_options = 1;
171     }
172     if (! args_info->model_given)
173     {
174     fprintf (stderr, "%s: '--model' option required\n", CMDLINE_PARSER_PACKAGE);
175     missing_required_options = 1;
176     }
177     if ( missing_required_options )
178     exit (EXIT_FAILURE);
179    
180     return 0;
181     }