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 |
|
|
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 |
66 |
|
cmdline_parser_print_help (void) |
67 |
|
{ |
68 |
|
cmdline_parser_print_version (); |
69 |
< |
printf("\n" |
70 |
< |
"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"); |
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"); |
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=LONG generate a geomview file with the object geometry"); |
78 |
> |
printf("%s\n"," --genGeomview generate a geomview file with the object geometry \n (default=off)"); |
79 |
> |
|
80 |
|
} |
81 |
|
|
82 |
|
void |
93 |
|
cmdline_parser_free (struct gengetopt_args_info *args_info) |
94 |
|
{ |
95 |
|
|
96 |
< |
int i; |
96 |
> |
unsigned int i; |
97 |
|
if (args_info->output_arg) |
98 |
|
{ |
99 |
|
free (args_info->output_arg); /* free previous argument */ |
114 |
|
clear_given (args_info); |
115 |
|
} |
116 |
|
|
116 |
– |
|
117 |
|
/* gengetopt_strdup() */ |
118 |
|
/* strdup.c replacement of strdup, which is not standard */ |
119 |
|
char * |
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); |
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) |
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 |
< |
result = cmdline_parser_internal (argc, argv, args_info, override, initialize, 1, NULL); |
153 |
< |
|
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); |
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 |
|
|
224 |
|
{ "length", 1, NULL, 0 }, |
225 |
|
{ "width", 1, NULL, 0 }, |
226 |
|
{ "latticeCnst", 1, NULL, 0 }, |
227 |
< |
{ "genGeomview", 1, NULL, 0 }, |
227 |
> |
{ "genGeomview", 0, NULL, 0 }, |
228 |
|
{ NULL, 0, NULL, 0 } |
229 |
|
}; |
230 |
|
|
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", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : "")); |
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) |
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", CMDLINE_PARSER_PACKAGE, (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 |
< |
} |
237 |
< |
|
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", CMDLINE_PARSER_PACKAGE, (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 |
< |
} |
252 |
< |
|
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", CMDLINE_PARSER_PACKAGE, (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 |
< |
} |
267 |
< |
|
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", CMDLINE_PARSER_PACKAGE, (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 |
< |
} |
282 |
< |
|
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", CMDLINE_PARSER_PACKAGE, (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_arg = strtol (optarg,&stop_char,0); |
334 |
< |
} |
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 |
|
|
298 |
– |
|
336 |
|
break; |
337 |
|
case '?': /* Invalid option. */ |
338 |
|
/* `getopt_long' already printed an error message. */ |
345 |
|
} /* while */ |
346 |
|
|
347 |
|
|
311 |
– |
cmdline_parser_free (&local_args_info); |
348 |
|
|
349 |
|
if (check_required) |
350 |
|
{ |
351 |
< |
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 |
< |
} |
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); |
359 |
|
if (optind < argc) |
360 |
|
{ |
361 |
|
int i = 0 ; |
362 |
< |
|
362 |
> |
|
363 |
|
args_info->inputs_num = argc - optind ; |
364 |
< |
args_info->inputs = |
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++]) ; |
367 |
> |
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; |
368 |
|
} |
369 |
< |
|
369 |
> |
|
370 |
|
return 0; |
371 |
|
|
372 |
< |
failure: |
372 |
> |
failure: |
373 |
> |
|
374 |
|
cmdline_parser_free (&local_args_info); |
375 |
|
return (EXIT_FAILURE); |
376 |
|
} |