1 |
tim |
891 |
/* |
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 |
|
|
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(" --viscosity=DOUBLE viscosity of solvent\n"); |
43 |
|
|
printf(" --sigma=DOUBLE diameter of beads(use with rough shell model)\n"); |
44 |
|
|
printf(" --model=STRING hydrodynamics model (support RoughShell and \n BeadModel)\n"); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
static char *gengetopt_strdup (const char *s); |
49 |
|
|
|
50 |
|
|
/* gengetopt_strdup() */ |
51 |
|
|
/* strdup.c replacement of strdup, which is not standard */ |
52 |
|
|
char * |
53 |
|
|
gengetopt_strdup (const char *s) |
54 |
|
|
{ |
55 |
|
|
char *result = (char*)malloc(strlen(s) + 1); |
56 |
|
|
if (result == (char*)0) |
57 |
|
|
return (char*)0; |
58 |
|
|
strcpy(result, s); |
59 |
|
|
return result; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
int |
63 |
|
|
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
64 |
|
|
{ |
65 |
|
|
int c; /* Character of the parsed option. */ |
66 |
|
|
int missing_required_options = 0; |
67 |
|
|
|
68 |
|
|
args_info->help_given = 0 ; |
69 |
|
|
args_info->version_given = 0 ; |
70 |
|
|
args_info->input_given = 0 ; |
71 |
|
|
args_info->output_given = 0 ; |
72 |
|
|
args_info->viscosity_given = 0 ; |
73 |
|
|
args_info->sigma_given = 0 ; |
74 |
|
|
args_info->model_given = 0 ; |
75 |
|
|
#define clear_args() { \ |
76 |
|
|
args_info->input_arg = NULL; \ |
77 |
|
|
args_info->output_arg = gengetopt_strdup("hydro") ;\ |
78 |
|
|
args_info->model_arg = NULL; \ |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
clear_args(); |
82 |
|
|
|
83 |
|
|
optarg = 0; |
84 |
|
|
optind = 1; |
85 |
|
|
opterr = 1; |
86 |
|
|
optopt = '?'; |
87 |
|
|
|
88 |
|
|
while (1) |
89 |
|
|
{ |
90 |
|
|
int option_index = 0; |
91 |
|
|
char *stop_char; |
92 |
|
|
|
93 |
|
|
static struct option long_options[] = { |
94 |
|
|
{ "help", 0, NULL, 'h' }, |
95 |
|
|
{ "version", 0, NULL, 'V' }, |
96 |
|
|
{ "input", 1, NULL, 'i' }, |
97 |
|
|
{ "output", 1, NULL, 'o' }, |
98 |
|
|
{ "viscosity", 1, NULL, 0 }, |
99 |
|
|
{ "sigma", 1, NULL, 0 }, |
100 |
|
|
{ "model", 1, NULL, 0 }, |
101 |
|
|
{ NULL, 0, NULL, 0 } |
102 |
|
|
}; |
103 |
|
|
|
104 |
|
|
stop_char = 0; |
105 |
|
|
c = getopt_long (argc, argv, "hVi:o:", long_options, &option_index); |
106 |
|
|
|
107 |
|
|
if (c == -1) break; /* Exit from `while (1)' loop. */ |
108 |
|
|
|
109 |
|
|
switch (c) |
110 |
|
|
{ |
111 |
|
|
case 'h': /* Print help and exit. */ |
112 |
|
|
clear_args (); |
113 |
|
|
cmdline_parser_print_help (); |
114 |
|
|
exit (EXIT_SUCCESS); |
115 |
|
|
|
116 |
|
|
case 'V': /* Print version and exit. */ |
117 |
|
|
clear_args (); |
118 |
|
|
cmdline_parser_print_version (); |
119 |
|
|
exit (EXIT_SUCCESS); |
120 |
|
|
|
121 |
|
|
case 'i': /* input dump file. */ |
122 |
|
|
if (args_info->input_given) |
123 |
|
|
{ |
124 |
|
|
fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
125 |
|
|
clear_args (); |
126 |
|
|
exit (EXIT_FAILURE); |
127 |
|
|
} |
128 |
|
|
args_info->input_given = 1; |
129 |
|
|
args_info->input_arg = gengetopt_strdup (optarg); |
130 |
|
|
break; |
131 |
|
|
|
132 |
|
|
case 'o': /* output file prefix. */ |
133 |
|
|
if (args_info->output_given) |
134 |
|
|
{ |
135 |
|
|
fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
136 |
|
|
clear_args (); |
137 |
|
|
exit (EXIT_FAILURE); |
138 |
|
|
} |
139 |
|
|
args_info->output_given = 1; |
140 |
|
|
if (args_info->output_arg) |
141 |
|
|
free (args_info->output_arg); /* free default string */ |
142 |
|
|
args_info->output_arg = gengetopt_strdup (optarg); |
143 |
|
|
break; |
144 |
|
|
|
145 |
|
|
|
146 |
|
|
case 0: /* Long option with no short option */ |
147 |
|
|
/* viscosity of solvent. */ |
148 |
|
|
if (strcmp (long_options[option_index].name, "viscosity") == 0) |
149 |
|
|
{ |
150 |
|
|
if (args_info->viscosity_given) |
151 |
|
|
{ |
152 |
|
|
fprintf (stderr, "%s: `--viscosity' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
153 |
|
|
clear_args (); |
154 |
|
|
exit (EXIT_FAILURE); |
155 |
|
|
} |
156 |
|
|
args_info->viscosity_given = 1; |
157 |
|
|
args_info->viscosity_arg = strtod (optarg, NULL); |
158 |
|
|
break; |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
/* diameter of beads(use with rough shell model). */ |
162 |
|
|
else if (strcmp (long_options[option_index].name, "sigma") == 0) |
163 |
|
|
{ |
164 |
|
|
if (args_info->sigma_given) |
165 |
|
|
{ |
166 |
|
|
fprintf (stderr, "%s: `--sigma' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
167 |
|
|
clear_args (); |
168 |
|
|
exit (EXIT_FAILURE); |
169 |
|
|
} |
170 |
|
|
args_info->sigma_given = 1; |
171 |
|
|
args_info->sigma_arg = strtod (optarg, NULL); |
172 |
|
|
break; |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
/* hydrodynamics model (support RoughShell and BeadModel). */ |
176 |
|
|
else if (strcmp (long_options[option_index].name, "model") == 0) |
177 |
|
|
{ |
178 |
|
|
if (args_info->model_given) |
179 |
|
|
{ |
180 |
|
|
fprintf (stderr, "%s: `--model' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
181 |
|
|
clear_args (); |
182 |
|
|
exit (EXIT_FAILURE); |
183 |
|
|
} |
184 |
|
|
args_info->model_given = 1; |
185 |
|
|
args_info->model_arg = gengetopt_strdup (optarg); |
186 |
|
|
break; |
187 |
|
|
} |
188 |
|
|
|
189 |
|
|
|
190 |
|
|
case '?': /* Invalid option. */ |
191 |
|
|
/* `getopt_long' already printed an error message. */ |
192 |
|
|
exit (EXIT_FAILURE); |
193 |
|
|
|
194 |
|
|
default: /* bug: option not considered. */ |
195 |
|
|
fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); |
196 |
|
|
abort (); |
197 |
|
|
} /* switch */ |
198 |
|
|
} /* while */ |
199 |
|
|
|
200 |
|
|
|
201 |
|
|
if (! args_info->input_given) |
202 |
|
|
{ |
203 |
|
|
fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE); |
204 |
|
|
missing_required_options = 1; |
205 |
|
|
} |
206 |
|
|
if (! args_info->viscosity_given) |
207 |
|
|
{ |
208 |
|
|
fprintf (stderr, "%s: '--viscosity' option required\n", CMDLINE_PARSER_PACKAGE); |
209 |
|
|
missing_required_options = 1; |
210 |
|
|
} |
211 |
|
|
if (! args_info->model_given) |
212 |
|
|
{ |
213 |
|
|
fprintf (stderr, "%s: '--model' option required\n", CMDLINE_PARSER_PACKAGE); |
214 |
|
|
missing_required_options = 1; |
215 |
|
|
} |
216 |
|
|
if ( missing_required_options ) |
217 |
|
|
exit (EXIT_FAILURE); |
218 |
|
|
|
219 |
|
|
return 0; |
220 |
|
|
} |