1 |
tim |
1424 |
/* |
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 simpleBuilderCmd -u |
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 "simpleBuilderCmd.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]... [FILES]...\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, --include=STRING File name that should be included at the top of \n the output bass file.\n"); |
41 |
|
|
printf(" -o, --output=STRING Output file name\n"); |
42 |
|
|
printf(" --latticetype=STRING Lattice type string. Valid types are fcc,hcp,bcc \n and hcp-water.\n"); |
43 |
|
|
printf(" --density=DOUBLE density g/cm^3\n"); |
44 |
|
|
printf(" --ndensity=DOUBLE number density\n"); |
45 |
|
|
printf(" --nx=INT number of unit cells in x\n"); |
46 |
|
|
printf(" --ny=INT number of unit cells in y\n"); |
47 |
|
|
printf(" --nz=INT number of unit cells in z\n"); |
48 |
|
|
printf(" --a1=DOUBLE lattice spacing in Angstroms h - for cubic \n lattice, specify this parameter\n"); |
49 |
|
|
printf(" --a2=DOUBLE lattice spacing in Angstroms k\n"); |
50 |
|
|
printf(" --a3=DOUBLE lattice spacing in Angstroms l\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 include_list |
74 |
|
|
{ |
75 |
|
|
char * include_arg; |
76 |
|
|
struct include_list * next; |
77 |
|
|
}; |
78 |
|
|
struct include_list * include_list = NULL,* include_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->include_given = 0 ; |
85 |
|
|
args_info->output_given = 0 ; |
86 |
|
|
args_info->latticetype_given = 0 ; |
87 |
|
|
args_info->density_given = 0 ; |
88 |
|
|
args_info->ndensity_given = 0 ; |
89 |
|
|
args_info->nx_given = 0 ; |
90 |
|
|
args_info->ny_given = 0 ; |
91 |
|
|
args_info->nz_given = 0 ; |
92 |
|
|
args_info->a1_given = 0 ; |
93 |
|
|
args_info->a2_given = 0 ; |
94 |
|
|
args_info->a3_given = 0 ; |
95 |
|
|
#define clear_args() { \ |
96 |
|
|
args_info->include_arg = NULL; \ |
97 |
|
|
args_info->output_arg = NULL; \ |
98 |
|
|
args_info->latticetype_arg = NULL; \ |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
clear_args(); |
102 |
|
|
|
103 |
|
|
args_info->inputs = NULL; |
104 |
|
|
args_info->inputs_num = 0; |
105 |
|
|
|
106 |
|
|
optarg = 0; |
107 |
|
|
optind = 1; |
108 |
|
|
opterr = 1; |
109 |
|
|
optopt = '?'; |
110 |
|
|
|
111 |
|
|
while (1) |
112 |
|
|
{ |
113 |
|
|
int option_index = 0; |
114 |
|
|
char *stop_char; |
115 |
|
|
|
116 |
|
|
static struct option long_options[] = { |
117 |
|
|
{ "help", 0, NULL, 'h' }, |
118 |
|
|
{ "version", 0, NULL, 'V' }, |
119 |
|
|
{ "include", 1, NULL, 'I' }, |
120 |
|
|
{ "output", 1, NULL, 'o' }, |
121 |
|
|
{ "latticetype", 1, NULL, 0 }, |
122 |
|
|
{ "density", 1, NULL, 0 }, |
123 |
|
|
{ "ndensity", 1, NULL, 0 }, |
124 |
|
|
{ "nx", 1, NULL, 0 }, |
125 |
|
|
{ "ny", 1, NULL, 0 }, |
126 |
|
|
{ "nz", 1, NULL, 0 }, |
127 |
|
|
{ "a1", 1, NULL, 0 }, |
128 |
|
|
{ "a2", 1, NULL, 0 }, |
129 |
|
|
{ "a3", 1, NULL, 0 }, |
130 |
|
|
{ NULL, 0, NULL, 0 } |
131 |
|
|
}; |
132 |
|
|
|
133 |
|
|
stop_char = 0; |
134 |
|
|
c = getopt_long (argc, argv, "hVI:o:", long_options, &option_index); |
135 |
|
|
|
136 |
|
|
if (c == -1) break; /* Exit from `while (1)' loop. */ |
137 |
|
|
|
138 |
|
|
switch (c) |
139 |
|
|
{ |
140 |
|
|
case 'h': /* Print help and exit. */ |
141 |
|
|
clear_args (); |
142 |
|
|
cmdline_parser_print_help (); |
143 |
|
|
exit (EXIT_SUCCESS); |
144 |
|
|
|
145 |
|
|
case 'V': /* Print version and exit. */ |
146 |
|
|
clear_args (); |
147 |
|
|
cmdline_parser_print_version (); |
148 |
|
|
exit (EXIT_SUCCESS); |
149 |
|
|
|
150 |
|
|
case 'I': /* File name that should be included at the top of the output bass file.. */ |
151 |
|
|
args_info->include_given++; |
152 |
|
|
include_new = (struct include_list *) malloc (sizeof (struct include_list)); |
153 |
|
|
include_new->next = include_list; |
154 |
|
|
include_list = include_new; |
155 |
|
|
include_new->include_arg = gengetopt_strdup (optarg); |
156 |
|
|
break; |
157 |
|
|
|
158 |
|
|
case 'o': /* Output file name. */ |
159 |
|
|
if (args_info->output_given) |
160 |
|
|
{ |
161 |
|
|
fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
162 |
|
|
clear_args (); |
163 |
|
|
exit (EXIT_FAILURE); |
164 |
|
|
} |
165 |
|
|
args_info->output_given = 1; |
166 |
|
|
args_info->output_arg = gengetopt_strdup (optarg); |
167 |
|
|
break; |
168 |
|
|
|
169 |
|
|
|
170 |
|
|
case 0: /* Long option with no short option */ |
171 |
|
|
/* Lattice type string. Valid types are fcc,hcp,bcc and hcp-water.. */ |
172 |
|
|
if (strcmp (long_options[option_index].name, "latticetype") == 0) |
173 |
|
|
{ |
174 |
|
|
if (args_info->latticetype_given) |
175 |
|
|
{ |
176 |
|
|
fprintf (stderr, "%s: `--latticetype' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
177 |
|
|
clear_args (); |
178 |
|
|
exit (EXIT_FAILURE); |
179 |
|
|
} |
180 |
|
|
args_info->latticetype_given = 1; |
181 |
|
|
args_info->latticetype_arg = gengetopt_strdup (optarg); |
182 |
|
|
break; |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
/* density g/cm^3. */ |
186 |
|
|
else if (strcmp (long_options[option_index].name, "density") == 0) |
187 |
|
|
{ |
188 |
|
|
if (args_info->density_given) |
189 |
|
|
{ |
190 |
|
|
fprintf (stderr, "%s: `--density' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
191 |
|
|
clear_args (); |
192 |
|
|
exit (EXIT_FAILURE); |
193 |
|
|
} |
194 |
|
|
args_info->density_given = 1; |
195 |
|
|
args_info->density_arg = strtod (optarg, NULL); |
196 |
|
|
break; |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
/* number density. */ |
200 |
|
|
else if (strcmp (long_options[option_index].name, "ndensity") == 0) |
201 |
|
|
{ |
202 |
|
|
if (args_info->ndensity_given) |
203 |
|
|
{ |
204 |
|
|
fprintf (stderr, "%s: `--ndensity' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
205 |
|
|
clear_args (); |
206 |
|
|
exit (EXIT_FAILURE); |
207 |
|
|
} |
208 |
|
|
args_info->ndensity_given = 1; |
209 |
|
|
args_info->ndensity_arg = strtod (optarg, NULL); |
210 |
|
|
break; |
211 |
|
|
} |
212 |
|
|
|
213 |
|
|
/* number of unit cells in x. */ |
214 |
|
|
else if (strcmp (long_options[option_index].name, "nx") == 0) |
215 |
|
|
{ |
216 |
|
|
if (args_info->nx_given) |
217 |
|
|
{ |
218 |
|
|
fprintf (stderr, "%s: `--nx' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
219 |
|
|
clear_args (); |
220 |
|
|
exit (EXIT_FAILURE); |
221 |
|
|
} |
222 |
|
|
args_info->nx_given = 1; |
223 |
|
|
args_info->nx_arg = strtol (optarg,&stop_char,0); |
224 |
|
|
break; |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
/* number of unit cells in y. */ |
228 |
|
|
else if (strcmp (long_options[option_index].name, "ny") == 0) |
229 |
|
|
{ |
230 |
|
|
if (args_info->ny_given) |
231 |
|
|
{ |
232 |
|
|
fprintf (stderr, "%s: `--ny' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
233 |
|
|
clear_args (); |
234 |
|
|
exit (EXIT_FAILURE); |
235 |
|
|
} |
236 |
|
|
args_info->ny_given = 1; |
237 |
|
|
args_info->ny_arg = strtol (optarg,&stop_char,0); |
238 |
|
|
break; |
239 |
|
|
} |
240 |
|
|
|
241 |
|
|
/* number of unit cells in z. */ |
242 |
|
|
else if (strcmp (long_options[option_index].name, "nz") == 0) |
243 |
|
|
{ |
244 |
|
|
if (args_info->nz_given) |
245 |
|
|
{ |
246 |
|
|
fprintf (stderr, "%s: `--nz' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
247 |
|
|
clear_args (); |
248 |
|
|
exit (EXIT_FAILURE); |
249 |
|
|
} |
250 |
|
|
args_info->nz_given = 1; |
251 |
|
|
args_info->nz_arg = strtol (optarg,&stop_char,0); |
252 |
|
|
break; |
253 |
|
|
} |
254 |
|
|
|
255 |
|
|
/* lattice spacing in Angstroms h - for cubic lattice, specify this parameter. */ |
256 |
|
|
else if (strcmp (long_options[option_index].name, "a1") == 0) |
257 |
|
|
{ |
258 |
|
|
if (args_info->a1_given) |
259 |
|
|
{ |
260 |
|
|
fprintf (stderr, "%s: `--a1' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
261 |
|
|
clear_args (); |
262 |
|
|
exit (EXIT_FAILURE); |
263 |
|
|
} |
264 |
|
|
args_info->a1_given = 1; |
265 |
|
|
args_info->a1_arg = strtod (optarg, NULL); |
266 |
|
|
break; |
267 |
|
|
} |
268 |
|
|
|
269 |
|
|
/* lattice spacing in Angstroms k. */ |
270 |
|
|
else if (strcmp (long_options[option_index].name, "a2") == 0) |
271 |
|
|
{ |
272 |
|
|
if (args_info->a2_given) |
273 |
|
|
{ |
274 |
|
|
fprintf (stderr, "%s: `--a2' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
275 |
|
|
clear_args (); |
276 |
|
|
exit (EXIT_FAILURE); |
277 |
|
|
} |
278 |
|
|
args_info->a2_given = 1; |
279 |
|
|
args_info->a2_arg = strtod (optarg, NULL); |
280 |
|
|
break; |
281 |
|
|
} |
282 |
|
|
|
283 |
|
|
/* lattice spacing in Angstroms l. */ |
284 |
|
|
else if (strcmp (long_options[option_index].name, "a3") == 0) |
285 |
|
|
{ |
286 |
|
|
if (args_info->a3_given) |
287 |
|
|
{ |
288 |
|
|
fprintf (stderr, "%s: `--a3' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
289 |
|
|
clear_args (); |
290 |
|
|
exit (EXIT_FAILURE); |
291 |
|
|
} |
292 |
|
|
args_info->a3_given = 1; |
293 |
|
|
args_info->a3_arg = strtod (optarg, NULL); |
294 |
|
|
break; |
295 |
|
|
} |
296 |
|
|
|
297 |
|
|
|
298 |
|
|
case '?': /* Invalid option. */ |
299 |
|
|
/* `getopt_long' already printed an error message. */ |
300 |
|
|
exit (EXIT_FAILURE); |
301 |
|
|
|
302 |
|
|
default: /* bug: option not considered. */ |
303 |
|
|
fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); |
304 |
|
|
abort (); |
305 |
|
|
} /* switch */ |
306 |
|
|
} /* while */ |
307 |
|
|
|
308 |
|
|
|
309 |
|
|
if (! args_info->nx_given) |
310 |
|
|
{ |
311 |
|
|
fprintf (stderr, "%s: '--nx' option required\n", CMDLINE_PARSER_PACKAGE); |
312 |
|
|
missing_required_options = 1; |
313 |
|
|
} |
314 |
|
|
if (! args_info->ny_given) |
315 |
|
|
{ |
316 |
|
|
fprintf (stderr, "%s: '--ny' option required\n", CMDLINE_PARSER_PACKAGE); |
317 |
|
|
missing_required_options = 1; |
318 |
|
|
} |
319 |
|
|
if (! args_info->nz_given) |
320 |
|
|
{ |
321 |
|
|
fprintf (stderr, "%s: '--nz' option required\n", CMDLINE_PARSER_PACKAGE); |
322 |
|
|
missing_required_options = 1; |
323 |
|
|
} |
324 |
|
|
if (! args_info->a1_given) |
325 |
|
|
{ |
326 |
|
|
fprintf (stderr, "%s: '--a1' option required\n", CMDLINE_PARSER_PACKAGE); |
327 |
|
|
missing_required_options = 1; |
328 |
|
|
} |
329 |
|
|
if ( missing_required_options ) |
330 |
|
|
exit (EXIT_FAILURE); |
331 |
|
|
|
332 |
|
|
if (args_info->include_given) |
333 |
|
|
{ |
334 |
|
|
args_info->include_arg = (char * *) malloc (args_info->include_given * sizeof (char *)); |
335 |
|
|
for (i = 0; i < args_info->include_given; i++) |
336 |
|
|
{ |
337 |
|
|
args_info->include_arg [i] = include_list->include_arg; |
338 |
|
|
include_list = include_list->next; |
339 |
|
|
} |
340 |
|
|
} |
341 |
|
|
|
342 |
|
|
if (optind < argc) |
343 |
|
|
{ |
344 |
|
|
int i = 0 ; |
345 |
|
|
|
346 |
|
|
args_info->inputs_num = argc - optind ; |
347 |
|
|
args_info->inputs = |
348 |
|
|
(char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; |
349 |
|
|
while (optind < argc) |
350 |
|
|
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; |
351 |
|
|
} |
352 |
|
|
|
353 |
|
|
return 0; |
354 |
|
|
} |