1 |
/* |
2 |
File autogenerated by gengetopt version 2.13 |
3 |
generated with the following command: |
4 |
gengetopt -u --file-name=nanorodBuilderCmd |
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 |
/* If we use autoconf. */ |
12 |
#ifdef HAVE_CONFIG_H |
13 |
#include "config.h" |
14 |
#endif |
15 |
|
16 |
#include <stdio.h> |
17 |
#include <stdlib.h> |
18 |
#include <string.h> |
19 |
|
20 |
#include "getopt.h" |
21 |
|
22 |
#include "nanorodBuilderCmd.h" |
23 |
|
24 |
static |
25 |
void clear_given (struct gengetopt_args_info *args_info); |
26 |
static |
27 |
void clear_args (struct gengetopt_args_info *args_info); |
28 |
|
29 |
static int |
30 |
cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error); |
31 |
|
32 |
static int |
33 |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); |
34 |
|
35 |
static char * |
36 |
gengetopt_strdup (const char *s); |
37 |
|
38 |
static |
39 |
void clear_given (struct gengetopt_args_info *args_info) |
40 |
{ |
41 |
args_info->help_given = 0 ; |
42 |
args_info->version_given = 0 ; |
43 |
args_info->output_given = 0 ; |
44 |
args_info->latticetype_given = 0 ; |
45 |
args_info->length_given = 0 ; |
46 |
args_info->width_given = 0 ; |
47 |
args_info->latticeCnst_given = 0 ; |
48 |
args_info->genGeomview_given = 0 ; |
49 |
} |
50 |
|
51 |
static |
52 |
void clear_args (struct gengetopt_args_info *args_info) |
53 |
{ |
54 |
args_info->output_arg = NULL; |
55 |
args_info->latticetype_arg = gengetopt_strdup ("fcc"); |
56 |
args_info->genGeomview_flag = 0; |
57 |
} |
58 |
|
59 |
void |
60 |
cmdline_parser_print_version (void) |
61 |
{ |
62 |
printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); |
63 |
} |
64 |
|
65 |
void |
66 |
cmdline_parser_print_help (void) |
67 |
{ |
68 |
cmdline_parser_print_version (); |
69 |
printf("\n%s\n", "Builds penta-hexagonal nanorods and outputs a xyz input file"); |
70 |
printf("\nUsage: nanorodBuilder [OPTIONS]... [FILES]...\n\n"); |
71 |
printf("%s\n"," -h, --help Print help and exit"); |
72 |
printf("%s\n"," -V, --version Print version and exit"); |
73 |
printf("%s\n"," -o, --output=STRING Output file name"); |
74 |
printf("%s\n"," --latticetype=STRING Lattice type string. Valid types are fcc,hcp,bcc. \n (default=`fcc')"); |
75 |
printf("%s\n"," --length=DOUBLE length of nanorod in Angstroms"); |
76 |
printf("%s\n"," --width=DOUBLE diameter of nanorod in Angstroms"); |
77 |
printf("%s\n"," --latticeCnst=DOUBLE lattice spacing in Angstrons for cubic lattice"); |
78 |
printf("%s\n"," --genGeomview generate a geomview file with the object geometry \n (default=off)"); |
79 |
|
80 |
} |
81 |
|
82 |
void |
83 |
cmdline_parser_init (struct gengetopt_args_info *args_info) |
84 |
{ |
85 |
clear_given (args_info); |
86 |
clear_args (args_info); |
87 |
|
88 |
args_info->inputs = NULL; |
89 |
args_info->inputs_num = 0; |
90 |
} |
91 |
|
92 |
void |
93 |
cmdline_parser_free (struct gengetopt_args_info *args_info) |
94 |
{ |
95 |
|
96 |
unsigned int i; |
97 |
if (args_info->output_arg) |
98 |
{ |
99 |
free (args_info->output_arg); /* free previous argument */ |
100 |
args_info->output_arg = 0; |
101 |
} |
102 |
if (args_info->latticetype_arg) |
103 |
{ |
104 |
free (args_info->latticetype_arg); /* free previous argument */ |
105 |
args_info->latticetype_arg = 0; |
106 |
} |
107 |
|
108 |
for (i = 0; i < args_info->inputs_num; ++i) |
109 |
free (args_info->inputs [i]); |
110 |
|
111 |
if (args_info->inputs_num) |
112 |
free (args_info->inputs); |
113 |
|
114 |
clear_given (args_info); |
115 |
} |
116 |
|
117 |
/* gengetopt_strdup() */ |
118 |
/* strdup.c replacement of strdup, which is not standard */ |
119 |
char * |
120 |
gengetopt_strdup (const char *s) |
121 |
{ |
122 |
char *result = NULL; |
123 |
if (!s) |
124 |
return result; |
125 |
|
126 |
result = (char*)malloc(strlen(s) + 1); |
127 |
if (result == (char*)0) |
128 |
return (char*)0; |
129 |
strcpy(result, s); |
130 |
return result; |
131 |
} |
132 |
|
133 |
int |
134 |
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
135 |
{ |
136 |
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
137 |
} |
138 |
|
139 |
int |
140 |
cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
141 |
{ |
142 |
int result; |
143 |
|
144 |
result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); |
145 |
|
146 |
if (result == EXIT_FAILURE) |
147 |
{ |
148 |
cmdline_parser_free (args_info); |
149 |
exit (EXIT_FAILURE); |
150 |
} |
151 |
|
152 |
return result; |
153 |
} |
154 |
|
155 |
int |
156 |
cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) |
157 |
{ |
158 |
int result = EXIT_SUCCESS; |
159 |
|
160 |
if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) |
161 |
result = EXIT_FAILURE; |
162 |
|
163 |
if (result == EXIT_FAILURE) |
164 |
{ |
165 |
cmdline_parser_free (args_info); |
166 |
exit (EXIT_FAILURE); |
167 |
} |
168 |
|
169 |
return result; |
170 |
} |
171 |
|
172 |
int |
173 |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) |
174 |
{ |
175 |
int error = 0; |
176 |
|
177 |
if (! args_info->length_given) |
178 |
{ |
179 |
fprintf (stderr, "%s: '--length' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
180 |
error = 1; |
181 |
} |
182 |
if (! args_info->width_given) |
183 |
{ |
184 |
fprintf (stderr, "%s: '--width' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
185 |
error = 1; |
186 |
} |
187 |
if (! args_info->latticeCnst_given) |
188 |
{ |
189 |
fprintf (stderr, "%s: '--latticeCnst' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
190 |
error = 1; |
191 |
} |
192 |
|
193 |
return error; |
194 |
} |
195 |
|
196 |
int |
197 |
cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error) |
198 |
{ |
199 |
int c; /* Character of the parsed option. */ |
200 |
|
201 |
int error = 0; |
202 |
struct gengetopt_args_info local_args_info; |
203 |
|
204 |
if (initialize) |
205 |
cmdline_parser_init (args_info); |
206 |
|
207 |
cmdline_parser_init (&local_args_info); |
208 |
|
209 |
optarg = 0; |
210 |
optind = 1; |
211 |
opterr = 1; |
212 |
optopt = '?'; |
213 |
|
214 |
while (1) |
215 |
{ |
216 |
int option_index = 0; |
217 |
char *stop_char; |
218 |
|
219 |
static struct option long_options[] = { |
220 |
{ "help", 0, NULL, 'h' }, |
221 |
{ "version", 0, NULL, 'V' }, |
222 |
{ "output", 1, NULL, 'o' }, |
223 |
{ "latticetype", 1, NULL, 0 }, |
224 |
{ "length", 1, NULL, 0 }, |
225 |
{ "width", 1, NULL, 0 }, |
226 |
{ "latticeCnst", 1, NULL, 0 }, |
227 |
{ "genGeomview", 0, NULL, 0 }, |
228 |
{ NULL, 0, NULL, 0 } |
229 |
}; |
230 |
|
231 |
stop_char = 0; |
232 |
c = getopt_long (argc, argv, "hVo:", long_options, &option_index); |
233 |
|
234 |
if (c == -1) break; /* Exit from `while (1)' loop. */ |
235 |
|
236 |
switch (c) |
237 |
{ |
238 |
case 'h': /* Print help and exit. */ |
239 |
cmdline_parser_print_help (); |
240 |
exit (EXIT_SUCCESS); |
241 |
|
242 |
case 'V': /* Print version and exit. */ |
243 |
cmdline_parser_print_version (); |
244 |
exit (EXIT_SUCCESS); |
245 |
|
246 |
case 'o': /* Output file name. */ |
247 |
if (local_args_info.output_given) |
248 |
{ |
249 |
fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
250 |
goto failure; |
251 |
} |
252 |
if (args_info->output_given && ! override) |
253 |
continue; |
254 |
local_args_info.output_given = 1; |
255 |
args_info->output_given = 1; |
256 |
if (args_info->output_arg) |
257 |
free (args_info->output_arg); /* free previous string */ |
258 |
args_info->output_arg = gengetopt_strdup (optarg); |
259 |
break; |
260 |
|
261 |
|
262 |
case 0: /* Long option with no short option */ |
263 |
/* Lattice type string. Valid types are fcc,hcp,bcc.. */ |
264 |
if (strcmp (long_options[option_index].name, "latticetype") == 0) |
265 |
{ |
266 |
if (local_args_info.latticetype_given) |
267 |
{ |
268 |
fprintf (stderr, "%s: `--latticetype' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
269 |
goto failure; |
270 |
} |
271 |
if (args_info->latticetype_given && ! override) |
272 |
continue; |
273 |
local_args_info.latticetype_given = 1; |
274 |
args_info->latticetype_given = 1; |
275 |
if (args_info->latticetype_arg) |
276 |
free (args_info->latticetype_arg); /* free previous string */ |
277 |
args_info->latticetype_arg = gengetopt_strdup (optarg); |
278 |
} |
279 |
/* length of nanorod in Angstroms. */ |
280 |
else if (strcmp (long_options[option_index].name, "length") == 0) |
281 |
{ |
282 |
if (local_args_info.length_given) |
283 |
{ |
284 |
fprintf (stderr, "%s: `--length' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
285 |
goto failure; |
286 |
} |
287 |
if (args_info->length_given && ! override) |
288 |
continue; |
289 |
local_args_info.length_given = 1; |
290 |
args_info->length_given = 1; |
291 |
args_info->length_arg = strtod (optarg, NULL); |
292 |
} |
293 |
/* diameter of nanorod in Angstroms. */ |
294 |
else if (strcmp (long_options[option_index].name, "width") == 0) |
295 |
{ |
296 |
if (local_args_info.width_given) |
297 |
{ |
298 |
fprintf (stderr, "%s: `--width' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
299 |
goto failure; |
300 |
} |
301 |
if (args_info->width_given && ! override) |
302 |
continue; |
303 |
local_args_info.width_given = 1; |
304 |
args_info->width_given = 1; |
305 |
args_info->width_arg = strtod (optarg, NULL); |
306 |
} |
307 |
/* lattice spacing in Angstrons for cubic lattice. */ |
308 |
else if (strcmp (long_options[option_index].name, "latticeCnst") == 0) |
309 |
{ |
310 |
if (local_args_info.latticeCnst_given) |
311 |
{ |
312 |
fprintf (stderr, "%s: `--latticeCnst' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
313 |
goto failure; |
314 |
} |
315 |
if (args_info->latticeCnst_given && ! override) |
316 |
continue; |
317 |
local_args_info.latticeCnst_given = 1; |
318 |
args_info->latticeCnst_given = 1; |
319 |
args_info->latticeCnst_arg = strtod (optarg, NULL); |
320 |
} |
321 |
/* generate a geomview file with the object geometry. */ |
322 |
else if (strcmp (long_options[option_index].name, "genGeomview") == 0) |
323 |
{ |
324 |
if (local_args_info.genGeomview_given) |
325 |
{ |
326 |
fprintf (stderr, "%s: `--genGeomview' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
327 |
goto failure; |
328 |
} |
329 |
if (args_info->genGeomview_given && ! override) |
330 |
continue; |
331 |
local_args_info.genGeomview_given = 1; |
332 |
args_info->genGeomview_given = 1; |
333 |
args_info->genGeomview_flag = !(args_info->genGeomview_flag); |
334 |
} |
335 |
|
336 |
break; |
337 |
case '?': /* Invalid option. */ |
338 |
/* `getopt_long' already printed an error message. */ |
339 |
goto failure; |
340 |
|
341 |
default: /* bug: option not considered. */ |
342 |
fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); |
343 |
abort (); |
344 |
} /* switch */ |
345 |
} /* while */ |
346 |
|
347 |
|
348 |
|
349 |
if (check_required) |
350 |
{ |
351 |
error += cmdline_parser_required2 (args_info, argv[0], additional_error); |
352 |
} |
353 |
|
354 |
cmdline_parser_free (&local_args_info); |
355 |
|
356 |
if ( error ) |
357 |
return (EXIT_FAILURE); |
358 |
|
359 |
if (optind < argc) |
360 |
{ |
361 |
int i = 0 ; |
362 |
|
363 |
args_info->inputs_num = argc - optind ; |
364 |
args_info->inputs = |
365 |
(char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; |
366 |
while (optind < argc) |
367 |
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; |
368 |
} |
369 |
|
370 |
return 0; |
371 |
|
372 |
failure: |
373 |
|
374 |
cmdline_parser_free (&local_args_info); |
375 |
return (EXIT_FAILURE); |
376 |
} |