1 |
/* |
2 |
File autogenerated by gengetopt version 2.11 |
3 |
generated with the following command: |
4 |
/home/maul/gezelter/tim/tmp/gengetopt-2.11/src/gengetopt -F CmdlineZsub |
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 "CmdlineZsub.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 name\n"); |
42 |
printf(" -n, --frame=INT print every n frame (default=`1')\n"); |
43 |
printf(" -d, --dipole print the dipole moments (default=off)\n"); |
44 |
printf(" -w, --water print the the waters (default=off)\n"); |
45 |
printf(" -m, --periodicBox map to the periodic box (default=off)\n"); |
46 |
printf(" -r, --replace replace the atom types of zconstraint molecules \n (default=off)\n"); |
47 |
printf(" --repeatX=INT The number of images to repeat in the x direction \n (default=`0')\n"); |
48 |
printf(" --repeatY=INT The number of images to repeat in the y direction \n (default=`0')\n"); |
49 |
printf(" --repeatZ=INT The number of images to repeat in the z direction \n (default=`0')\n"); |
50 |
} |
51 |
|
52 |
|
53 |
static char *gengetopt_strdup (const char *s); |
54 |
|
55 |
/* gengetopt_strdup() */ |
56 |
/* strdup.c replacement of strdup, which is not standard */ |
57 |
char * |
58 |
gengetopt_strdup (const char *s) |
59 |
{ |
60 |
char *result = (char*)malloc(strlen(s) + 1); |
61 |
if (result == (char*)0) |
62 |
return (char*)0; |
63 |
strcpy(result, s); |
64 |
return result; |
65 |
} |
66 |
|
67 |
int |
68 |
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
69 |
{ |
70 |
int c; /* Character of the parsed option. */ |
71 |
int missing_required_options = 0; |
72 |
|
73 |
args_info->help_given = 0 ; |
74 |
args_info->version_given = 0 ; |
75 |
args_info->input_given = 0 ; |
76 |
args_info->output_given = 0 ; |
77 |
args_info->frame_given = 0 ; |
78 |
args_info->dipole_given = 0 ; |
79 |
args_info->water_given = 0 ; |
80 |
args_info->periodicBox_given = 0 ; |
81 |
args_info->replace_given = 0 ; |
82 |
args_info->repeatX_given = 0 ; |
83 |
args_info->repeatY_given = 0 ; |
84 |
args_info->repeatZ_given = 0 ; |
85 |
#define clear_args() { \ |
86 |
args_info->input_arg = NULL; \ |
87 |
args_info->output_arg = NULL; \ |
88 |
args_info->frame_arg = 1 ;\ |
89 |
args_info->dipole_flag = 0;\ |
90 |
args_info->water_flag = 0;\ |
91 |
args_info->periodicBox_flag = 0;\ |
92 |
args_info->replace_flag = 0;\ |
93 |
args_info->repeatX_arg = 0 ;\ |
94 |
args_info->repeatY_arg = 0 ;\ |
95 |
args_info->repeatZ_arg = 0 ;\ |
96 |
} |
97 |
|
98 |
clear_args(); |
99 |
|
100 |
optarg = 0; |
101 |
optind = 1; |
102 |
opterr = 1; |
103 |
optopt = '?'; |
104 |
|
105 |
while (1) |
106 |
{ |
107 |
int option_index = 0; |
108 |
char *stop_char; |
109 |
|
110 |
static struct option long_options[] = { |
111 |
{ "help", 0, NULL, 'h' }, |
112 |
{ "version", 0, NULL, 'V' }, |
113 |
{ "input", 1, NULL, 'i' }, |
114 |
{ "output", 1, NULL, 'o' }, |
115 |
{ "frame", 1, NULL, 'n' }, |
116 |
{ "dipole", 0, NULL, 'd' }, |
117 |
{ "water", 0, NULL, 'w' }, |
118 |
{ "periodicBox", 0, NULL, 'm' }, |
119 |
{ "replace", 0, NULL, 'r' }, |
120 |
{ "repeatX", 1, NULL, 0 }, |
121 |
{ "repeatY", 1, NULL, 0 }, |
122 |
{ "repeatZ", 1, NULL, 0 }, |
123 |
{ NULL, 0, NULL, 0 } |
124 |
}; |
125 |
|
126 |
stop_char = 0; |
127 |
c = getopt_long (argc, argv, "hVi:o:n:dwmr", long_options, &option_index); |
128 |
|
129 |
if (c == -1) break; /* Exit from `while (1)' loop. */ |
130 |
|
131 |
switch (c) |
132 |
{ |
133 |
case 'h': /* Print help and exit. */ |
134 |
clear_args (); |
135 |
cmdline_parser_print_help (); |
136 |
exit (EXIT_SUCCESS); |
137 |
|
138 |
case 'V': /* Print version and exit. */ |
139 |
clear_args (); |
140 |
cmdline_parser_print_version (); |
141 |
exit (EXIT_SUCCESS); |
142 |
|
143 |
case 'i': /* input dump file. */ |
144 |
if (args_info->input_given) |
145 |
{ |
146 |
fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
147 |
clear_args (); |
148 |
exit (EXIT_FAILURE); |
149 |
} |
150 |
args_info->input_given = 1; |
151 |
args_info->input_arg = gengetopt_strdup (optarg); |
152 |
break; |
153 |
|
154 |
case 'o': /* output file name. */ |
155 |
if (args_info->output_given) |
156 |
{ |
157 |
fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
158 |
clear_args (); |
159 |
exit (EXIT_FAILURE); |
160 |
} |
161 |
args_info->output_given = 1; |
162 |
args_info->output_arg = gengetopt_strdup (optarg); |
163 |
break; |
164 |
|
165 |
case 'n': /* print every n frame. */ |
166 |
if (args_info->frame_given) |
167 |
{ |
168 |
fprintf (stderr, "%s: `--frame' (`-n') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
169 |
clear_args (); |
170 |
exit (EXIT_FAILURE); |
171 |
} |
172 |
args_info->frame_given = 1; |
173 |
args_info->frame_arg = strtol (optarg,&stop_char,0); |
174 |
break; |
175 |
|
176 |
case 'd': /* print the dipole moments. */ |
177 |
if (args_info->dipole_given) |
178 |
{ |
179 |
fprintf (stderr, "%s: `--dipole' (`-d') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
180 |
clear_args (); |
181 |
exit (EXIT_FAILURE); |
182 |
} |
183 |
args_info->dipole_given = 1; |
184 |
args_info->dipole_flag = !(args_info->dipole_flag); |
185 |
break; |
186 |
|
187 |
case 'w': /* print the the waters. */ |
188 |
if (args_info->water_given) |
189 |
{ |
190 |
fprintf (stderr, "%s: `--water' (`-w') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
191 |
clear_args (); |
192 |
exit (EXIT_FAILURE); |
193 |
} |
194 |
args_info->water_given = 1; |
195 |
args_info->water_flag = !(args_info->water_flag); |
196 |
break; |
197 |
|
198 |
case 'm': /* map to the periodic box. */ |
199 |
if (args_info->periodicBox_given) |
200 |
{ |
201 |
fprintf (stderr, "%s: `--periodicBox' (`-m') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
202 |
clear_args (); |
203 |
exit (EXIT_FAILURE); |
204 |
} |
205 |
args_info->periodicBox_given = 1; |
206 |
args_info->periodicBox_flag = !(args_info->periodicBox_flag); |
207 |
break; |
208 |
|
209 |
case 'r': /* replace the atom types of zconstraint molecules. */ |
210 |
if (args_info->replace_given) |
211 |
{ |
212 |
fprintf (stderr, "%s: `--replace' (`-r') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
213 |
clear_args (); |
214 |
exit (EXIT_FAILURE); |
215 |
} |
216 |
args_info->replace_given = 1; |
217 |
args_info->replace_flag = !(args_info->replace_flag); |
218 |
break; |
219 |
|
220 |
|
221 |
case 0: /* Long option with no short option */ |
222 |
/* The number of images to repeat in the x direction. */ |
223 |
if (strcmp (long_options[option_index].name, "repeatX") == 0) |
224 |
{ |
225 |
if (args_info->repeatX_given) |
226 |
{ |
227 |
fprintf (stderr, "%s: `--repeatX' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
228 |
clear_args (); |
229 |
exit (EXIT_FAILURE); |
230 |
} |
231 |
args_info->repeatX_given = 1; |
232 |
args_info->repeatX_arg = strtol (optarg,&stop_char,0); |
233 |
break; |
234 |
} |
235 |
|
236 |
/* The number of images to repeat in the y direction. */ |
237 |
else if (strcmp (long_options[option_index].name, "repeatY") == 0) |
238 |
{ |
239 |
if (args_info->repeatY_given) |
240 |
{ |
241 |
fprintf (stderr, "%s: `--repeatY' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
242 |
clear_args (); |
243 |
exit (EXIT_FAILURE); |
244 |
} |
245 |
args_info->repeatY_given = 1; |
246 |
args_info->repeatY_arg = strtol (optarg,&stop_char,0); |
247 |
break; |
248 |
} |
249 |
|
250 |
/* The number of images to repeat in the z direction. */ |
251 |
else if (strcmp (long_options[option_index].name, "repeatZ") == 0) |
252 |
{ |
253 |
if (args_info->repeatZ_given) |
254 |
{ |
255 |
fprintf (stderr, "%s: `--repeatZ' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
256 |
clear_args (); |
257 |
exit (EXIT_FAILURE); |
258 |
} |
259 |
args_info->repeatZ_given = 1; |
260 |
args_info->repeatZ_arg = strtol (optarg,&stop_char,0); |
261 |
break; |
262 |
} |
263 |
|
264 |
|
265 |
case '?': /* Invalid option. */ |
266 |
/* `getopt_long' already printed an error message. */ |
267 |
exit (EXIT_FAILURE); |
268 |
|
269 |
default: /* bug: option not considered. */ |
270 |
fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); |
271 |
abort (); |
272 |
} /* switch */ |
273 |
} /* while */ |
274 |
|
275 |
|
276 |
if (! args_info->input_given) |
277 |
{ |
278 |
fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE); |
279 |
missing_required_options = 1; |
280 |
} |
281 |
if ( missing_required_options ) |
282 |
exit (EXIT_FAILURE); |
283 |
|
284 |
return 0; |
285 |
} |