1 |
|
/* |
2 |
< |
File autogenerated by gengetopt version 2.12 |
2 |
> |
File autogenerated by gengetopt version 2.13 |
3 |
|
generated with the following command: |
4 |
|
gengetopt -u --file-name=nanorodBuilderCmd |
5 |
|
|
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 |
|
|
46 |
|
args_info->width_given = 0 ; |
47 |
|
args_info->latticeCnst_given = 0 ; |
48 |
|
args_info->genGeomview_given = 0 ; |
49 |
+ |
args_info->twinnedCrystal_given = 0 ; |
50 |
|
} |
51 |
|
|
52 |
|
static |
54 |
|
{ |
55 |
|
args_info->output_arg = NULL; |
56 |
|
args_info->latticetype_arg = gengetopt_strdup ("fcc"); |
57 |
+ |
args_info->genGeomview_flag = 0; |
58 |
+ |
args_info->twinnedCrystal_flag = 0; |
59 |
|
} |
60 |
|
|
61 |
|
void |
68 |
|
cmdline_parser_print_help (void) |
69 |
|
{ |
70 |
|
cmdline_parser_print_version (); |
71 |
< |
printf("\n" |
72 |
< |
"Purpose:\n" |
67 |
< |
" Builds penta-hexagonal nanorods and outputs a xyz input file\n" |
68 |
< |
"\n" |
69 |
< |
"Usage: %s [OPTIONS]... [FILES]...\n", CMDLINE_PARSER_PACKAGE); |
70 |
< |
printf("\n"); |
71 |
> |
printf("\n%s\n", "Builds penta-hexagonal nanorods and outputs a xyz input file"); |
72 |
> |
printf("\nUsage: nanorodBuilder [OPTIONS]... [FILES]...\n\n"); |
73 |
|
printf("%s\n"," -h, --help Print help and exit"); |
74 |
|
printf("%s\n"," -V, --version Print version and exit"); |
75 |
|
printf("%s\n"," -o, --output=STRING Output file name"); |
77 |
|
printf("%s\n"," --length=DOUBLE length of nanorod in Angstroms"); |
78 |
|
printf("%s\n"," --width=DOUBLE diameter of nanorod in Angstroms"); |
79 |
|
printf("%s\n"," --latticeCnst=DOUBLE lattice spacing in Angstrons for cubic lattice"); |
80 |
< |
printf("%s\n"," --genGeomview=LONG generate a geomview file with the object geometry"); |
80 |
> |
printf("%s\n"," --genGeomview generate a geomview file with the object geometry \n (default=off)"); |
81 |
> |
printf("%s\n"," --twinnedCrystal generate a twinned crystal nanorod (default=off)"); |
82 |
> |
|
83 |
|
} |
84 |
|
|
85 |
|
void |
96 |
|
cmdline_parser_free (struct gengetopt_args_info *args_info) |
97 |
|
{ |
98 |
|
|
99 |
< |
int i; |
99 |
> |
unsigned int i; |
100 |
|
if (args_info->output_arg) |
101 |
|
{ |
102 |
|
free (args_info->output_arg); /* free previous argument */ |
117 |
|
clear_given (args_info); |
118 |
|
} |
119 |
|
|
116 |
– |
|
120 |
|
/* gengetopt_strdup() */ |
121 |
|
/* strdup.c replacement of strdup, which is not standard */ |
122 |
|
char * |
136 |
|
int |
137 |
|
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
138 |
|
{ |
139 |
< |
return cmdline_parser2 (argc, argv, args_info, 0, 1); |
139 |
> |
return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); |
140 |
|
} |
141 |
|
|
142 |
|
int |
143 |
< |
cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize) |
143 |
> |
cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) |
144 |
|
{ |
145 |
|
int result; |
146 |
+ |
|
147 |
+ |
result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); |
148 |
+ |
|
149 |
+ |
if (result == EXIT_FAILURE) |
150 |
+ |
{ |
151 |
+ |
cmdline_parser_free (args_info); |
152 |
+ |
exit (EXIT_FAILURE); |
153 |
+ |
} |
154 |
|
|
155 |
< |
result = cmdline_parser_internal (argc, argv, args_info, override, initialize, 1, NULL); |
156 |
< |
|
155 |
> |
return result; |
156 |
> |
} |
157 |
> |
|
158 |
> |
int |
159 |
> |
cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) |
160 |
> |
{ |
161 |
> |
int result = EXIT_SUCCESS; |
162 |
> |
|
163 |
> |
if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) |
164 |
> |
result = EXIT_FAILURE; |
165 |
> |
|
166 |
|
if (result == EXIT_FAILURE) |
167 |
|
{ |
168 |
|
cmdline_parser_free (args_info); |
170 |
|
} |
171 |
|
|
172 |
|
return result; |
173 |
+ |
} |
174 |
+ |
|
175 |
+ |
int |
176 |
+ |
cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) |
177 |
+ |
{ |
178 |
+ |
int error = 0; |
179 |
+ |
|
180 |
+ |
if (! args_info->length_given) |
181 |
+ |
{ |
182 |
+ |
fprintf (stderr, "%s: '--length' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
183 |
+ |
error = 1; |
184 |
+ |
} |
185 |
+ |
if (! args_info->width_given) |
186 |
+ |
{ |
187 |
+ |
fprintf (stderr, "%s: '--width' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
188 |
+ |
error = 1; |
189 |
+ |
} |
190 |
+ |
if (! args_info->latticeCnst_given) |
191 |
+ |
{ |
192 |
+ |
fprintf (stderr, "%s: '--latticeCnst' option required%s\n", prog_name, (additional_error ? additional_error : "")); |
193 |
+ |
error = 1; |
194 |
+ |
} |
195 |
+ |
|
196 |
+ |
return error; |
197 |
|
} |
198 |
|
|
199 |
|
int |
200 |
|
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) |
201 |
|
{ |
202 |
|
int c; /* Character of the parsed option. */ |
203 |
+ |
|
204 |
|
int error = 0; |
205 |
|
struct gengetopt_args_info local_args_info; |
206 |
|
|
227 |
|
{ "length", 1, NULL, 0 }, |
228 |
|
{ "width", 1, NULL, 0 }, |
229 |
|
{ "latticeCnst", 1, NULL, 0 }, |
230 |
< |
{ "genGeomview", 1, NULL, 0 }, |
230 |
> |
{ "genGeomview", 0, NULL, 0 }, |
231 |
> |
{ "twinnedCrystal", 0, NULL, 0 }, |
232 |
|
{ NULL, 0, NULL, 0 } |
233 |
|
}; |
234 |
|
|
250 |
|
case 'o': /* Output file name. */ |
251 |
|
if (local_args_info.output_given) |
252 |
|
{ |
253 |
< |
fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
253 |
> |
fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
254 |
|
goto failure; |
255 |
|
} |
256 |
|
if (args_info->output_given && ! override) |
269 |
|
{ |
270 |
|
if (local_args_info.latticetype_given) |
271 |
|
{ |
272 |
< |
fprintf (stderr, "%s: `--latticetype' option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
272 |
> |
fprintf (stderr, "%s: `--latticetype' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
273 |
|
goto failure; |
274 |
|
} |
275 |
|
if (args_info->latticetype_given && ! override) |
280 |
|
free (args_info->latticetype_arg); /* free previous string */ |
281 |
|
args_info->latticetype_arg = gengetopt_strdup (optarg); |
282 |
|
} |
237 |
– |
|
283 |
|
/* length of nanorod in Angstroms. */ |
284 |
|
else if (strcmp (long_options[option_index].name, "length") == 0) |
285 |
|
{ |
286 |
|
if (local_args_info.length_given) |
287 |
|
{ |
288 |
< |
fprintf (stderr, "%s: `--length' option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
288 |
> |
fprintf (stderr, "%s: `--length' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
289 |
|
goto failure; |
290 |
|
} |
291 |
|
if (args_info->length_given && ! override) |
294 |
|
args_info->length_given = 1; |
295 |
|
args_info->length_arg = strtod (optarg, NULL); |
296 |
|
} |
252 |
– |
|
297 |
|
/* diameter of nanorod in Angstroms. */ |
298 |
|
else if (strcmp (long_options[option_index].name, "width") == 0) |
299 |
|
{ |
300 |
|
if (local_args_info.width_given) |
301 |
|
{ |
302 |
< |
fprintf (stderr, "%s: `--width' option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
302 |
> |
fprintf (stderr, "%s: `--width' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
303 |
|
goto failure; |
304 |
|
} |
305 |
|
if (args_info->width_given && ! override) |
308 |
|
args_info->width_given = 1; |
309 |
|
args_info->width_arg = strtod (optarg, NULL); |
310 |
|
} |
267 |
– |
|
311 |
|
/* lattice spacing in Angstrons for cubic lattice. */ |
312 |
|
else if (strcmp (long_options[option_index].name, "latticeCnst") == 0) |
313 |
|
{ |
314 |
|
if (local_args_info.latticeCnst_given) |
315 |
|
{ |
316 |
< |
fprintf (stderr, "%s: `--latticeCnst' option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
316 |
> |
fprintf (stderr, "%s: `--latticeCnst' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
317 |
|
goto failure; |
318 |
|
} |
319 |
|
if (args_info->latticeCnst_given && ! override) |
322 |
|
args_info->latticeCnst_given = 1; |
323 |
|
args_info->latticeCnst_arg = strtod (optarg, NULL); |
324 |
|
} |
282 |
– |
|
325 |
|
/* generate a geomview file with the object geometry. */ |
326 |
|
else if (strcmp (long_options[option_index].name, "genGeomview") == 0) |
327 |
|
{ |
328 |
|
if (local_args_info.genGeomview_given) |
329 |
|
{ |
330 |
< |
fprintf (stderr, "%s: `--genGeomview' option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
330 |
> |
fprintf (stderr, "%s: `--genGeomview' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
331 |
|
goto failure; |
332 |
|
} |
333 |
|
if (args_info->genGeomview_given && ! override) |
334 |
|
continue; |
335 |
|
local_args_info.genGeomview_given = 1; |
336 |
|
args_info->genGeomview_given = 1; |
337 |
< |
args_info->genGeomview_arg = strtol (optarg,&stop_char,0); |
337 |
> |
args_info->genGeomview_flag = !(args_info->genGeomview_flag); |
338 |
|
} |
339 |
+ |
/* generate a twinned crystal nanorod. */ |
340 |
+ |
else if (strcmp (long_options[option_index].name, "twinnedCrystal") == 0) |
341 |
+ |
{ |
342 |
+ |
if (local_args_info.twinnedCrystal_given) |
343 |
+ |
{ |
344 |
+ |
fprintf (stderr, "%s: `--twinnedCrystal' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); |
345 |
+ |
goto failure; |
346 |
+ |
} |
347 |
+ |
if (args_info->twinnedCrystal_given && ! override) |
348 |
+ |
continue; |
349 |
+ |
local_args_info.twinnedCrystal_given = 1; |
350 |
+ |
args_info->twinnedCrystal_given = 1; |
351 |
+ |
args_info->twinnedCrystal_flag = !(args_info->twinnedCrystal_flag); |
352 |
+ |
} |
353 |
|
|
298 |
– |
|
354 |
|
break; |
355 |
|
case '?': /* Invalid option. */ |
356 |
|
/* `getopt_long' already printed an error message. */ |
363 |
|
} /* while */ |
364 |
|
|
365 |
|
|
311 |
– |
cmdline_parser_free (&local_args_info); |
366 |
|
|
367 |
|
if (check_required) |
368 |
|
{ |
369 |
< |
if (! args_info->length_given) |
316 |
< |
{ |
317 |
< |
fprintf (stderr, "%s: '--length' option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
318 |
< |
error = 1; |
319 |
< |
} |
320 |
< |
if (! args_info->width_given) |
321 |
< |
{ |
322 |
< |
fprintf (stderr, "%s: '--width' option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
323 |
< |
error = 1; |
324 |
< |
} |
325 |
< |
if (! args_info->latticeCnst_given) |
326 |
< |
{ |
327 |
< |
fprintf (stderr, "%s: '--latticeCnst' option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
328 |
< |
error = 1; |
329 |
< |
} |
369 |
> |
error += cmdline_parser_required2 (args_info, argv[0], additional_error); |
370 |
|
} |
371 |
|
|
372 |
+ |
cmdline_parser_free (&local_args_info); |
373 |
|
|
374 |
|
if ( error ) |
375 |
|
return (EXIT_FAILURE); |
377 |
|
if (optind < argc) |
378 |
|
{ |
379 |
|
int i = 0 ; |
380 |
< |
|
380 |
> |
|
381 |
|
args_info->inputs_num = argc - optind ; |
382 |
< |
args_info->inputs = |
382 |
> |
args_info->inputs = |
383 |
|
(char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; |
384 |
|
while (optind < argc) |
385 |
< |
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; |
385 |
> |
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; |
386 |
|
} |
387 |
< |
|
387 |
> |
|
388 |
|
return 0; |
389 |
|
|
390 |
|
failure: |
391 |
+ |
|
392 |
|
cmdline_parser_free (&local_args_info); |
393 |
|
return (EXIT_FAILURE); |
394 |
|
} |