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