OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
icosahedralBuilderCmd.cpp
1/*
2 File autogenerated by gengetopt version 2.22.6
3 generated with the following command:
4 gengetopt --no-handle-error --include-getopt --show-required --unamed-opts --file-name=icosahedralBuilderCmd --c-extension=cpp --header-extension=hpp
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#ifndef FIX_UNUSED
21#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
22#endif
23
24
26
27const char *gengetopt_args_info_purpose = "Creates single-component geometric solids that can be useful in\nsimulating nanostructures. Like the other builders, it requires an\ninitial, but skeletal OpenMD file to specify the component that is to\nbe placed on the lattice. The total number of placed molecules will be\nshown at the top of the configuration file that is generated, and that\nnumber may not match the original meta-data file, so a new meta-data\nfile is also generated which matches the lattice structure.";
28
29const char *gengetopt_args_info_usage = "Usage: icosahedralBuilder [OPTIONS]... [FILES]...";
30
31const char *gengetopt_args_info_versiontext = "";
32
33const char *gengetopt_args_info_description = "";
34
35const char *gengetopt_args_info_help[] = {
36 " -h, --help Print help and exit",
37 " -V, --version Print version and exit",
38 " -o, --output=STRING Output file name (mandatory)",
39 " -n, --shells=INT Nanoparticle shells",
40 " -d, --latticeConstant=DOUBLE Lattice spacing in Angstroms for cubic lattice.",
41 " -l, --lattice=STRING Lattice Type (possible values=\"FCC\",\n \"BCC\", \"SC\")",
42 " -c, --columnAtoms=INT Number of atoms along central column\n (Decahedron only)",
43 " -t, --twinAtoms=INT Number of atoms along twin boundary (Decahedron\n only)",
44 " -p, --truncatedPlanes=INT Number of truncated planes (Curling-stone\n Decahedra and Truncated Cubes only)",
45 " -u, --unitCells=INT Number of unit cell (Cuboctahedron and\n Truncated Cube only)",
46 "\n Group: clusterShape\n a cluster shape is required",
47 " --ico Create an Icosahedral cluster",
48 " --deca Create a regualar Decahedral cluster",
49 " --ino Create an Ino Decahedral cluster",
50 " --marks Create a Marks Decahedral cluster",
51 " --stone Create a Curling-stone Decahedral cluster",
52 " --cuboctahedron Create a regular Cuboctahedron (requires\n lattice)",
53 " --truncatedCube Create a Truncated Cube (requires lattice)",
54 0
55};
56
57typedef enum {ARG_NO
58 , ARG_STRING
59 , ARG_INT
60 , ARG_DOUBLE
61} cmdline_parser_arg_type;
62
63static
64void clear_given (struct gengetopt_args_info *args_info);
65static
66void clear_args (struct gengetopt_args_info *args_info);
67
68static int
69cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
70 struct cmdline_parser_params *params, const char *additional_error);
71
72static int
73cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
74
75const char *cmdline_parser_lattice_values[] = {"FCC", "BCC", "SC", 0}; /*< Possible values for lattice. */
76
77static char *
78gengetopt_strdup (const char *s);
79
80static
81void clear_given (struct gengetopt_args_info *args_info)
82{
83 args_info->help_given = 0 ;
84 args_info->version_given = 0 ;
85 args_info->output_given = 0 ;
86 args_info->shells_given = 0 ;
87 args_info->latticeConstant_given = 0 ;
88 args_info->lattice_given = 0 ;
89 args_info->columnAtoms_given = 0 ;
90 args_info->twinAtoms_given = 0 ;
91 args_info->truncatedPlanes_given = 0 ;
92 args_info->unitCells_given = 0 ;
93 args_info->ico_given = 0 ;
94 args_info->deca_given = 0 ;
95 args_info->ino_given = 0 ;
96 args_info->marks_given = 0 ;
97 args_info->stone_given = 0 ;
98 args_info->cuboctahedron_given = 0 ;
99 args_info->truncatedCube_given = 0 ;
100 args_info->clusterShape_group_counter = 0 ;
101}
102
103static
104void clear_args (struct gengetopt_args_info *args_info)
105{
106 FIX_UNUSED (args_info);
107 args_info->output_arg = NULL;
108 args_info->output_orig = NULL;
109 args_info->shells_orig = NULL;
110 args_info->latticeConstant_orig = NULL;
111 args_info->lattice_arg = NULL;
112 args_info->lattice_orig = NULL;
113 args_info->columnAtoms_orig = NULL;
114 args_info->twinAtoms_orig = NULL;
115 args_info->truncatedPlanes_orig = NULL;
116 args_info->unitCells_orig = NULL;
117
118}
119
120static
121void init_args_info(struct gengetopt_args_info *args_info)
122{
123
124
125 args_info->help_help = gengetopt_args_info_help[0] ;
126 args_info->version_help = gengetopt_args_info_help[1] ;
127 args_info->output_help = gengetopt_args_info_help[2] ;
128 args_info->shells_help = gengetopt_args_info_help[3] ;
129 args_info->latticeConstant_help = gengetopt_args_info_help[4] ;
130 args_info->lattice_help = gengetopt_args_info_help[5] ;
131 args_info->columnAtoms_help = gengetopt_args_info_help[6] ;
132 args_info->twinAtoms_help = gengetopt_args_info_help[7] ;
133 args_info->truncatedPlanes_help = gengetopt_args_info_help[8] ;
134 args_info->unitCells_help = gengetopt_args_info_help[9] ;
135 args_info->ico_help = gengetopt_args_info_help[11] ;
136 args_info->deca_help = gengetopt_args_info_help[12] ;
137 args_info->ino_help = gengetopt_args_info_help[13] ;
138 args_info->marks_help = gengetopt_args_info_help[14] ;
139 args_info->stone_help = gengetopt_args_info_help[15] ;
140 args_info->cuboctahedron_help = gengetopt_args_info_help[16] ;
141 args_info->truncatedCube_help = gengetopt_args_info_help[17] ;
142
143}
144
145void
146cmdline_parser_print_version (void)
147{
148 printf ("%s %s\n",
151
152 if (strlen(gengetopt_args_info_versiontext) > 0)
153 printf("\n%s\n", gengetopt_args_info_versiontext);
154}
155
156static void print_help_common(void) {
157 cmdline_parser_print_version ();
158
159 if (strlen(gengetopt_args_info_purpose) > 0)
160 printf("\n%s\n", gengetopt_args_info_purpose);
161
162 if (strlen(gengetopt_args_info_usage) > 0)
163 printf("\n%s\n", gengetopt_args_info_usage);
164
165 printf("\n");
166
167 if (strlen(gengetopt_args_info_description) > 0)
168 printf("%s\n\n", gengetopt_args_info_description);
169}
170
171void
172cmdline_parser_print_help (void)
173{
174 int i = 0;
175 print_help_common();
176 while (gengetopt_args_info_help[i])
177 printf("%s\n", gengetopt_args_info_help[i++]);
178}
179
180void
181cmdline_parser_init (struct gengetopt_args_info *args_info)
182{
183 clear_given (args_info);
184 clear_args (args_info);
185 init_args_info (args_info);
186
187 args_info->inputs = 0;
188 args_info->inputs_num = 0;
189}
190
191void
192cmdline_parser_params_init(struct cmdline_parser_params *params)
193{
194 if (params)
195 {
196 params->override = 0;
197 params->initialize = 1;
198 params->check_required = 1;
199 params->check_ambiguity = 0;
200 params->print_errors = 1;
201 }
202}
203
206{
207 struct cmdline_parser_params *params =
208 (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
210 return params;
211}
212
213static void
214free_string_field (char **s)
215{
216 if (*s)
217 {
218 free (*s);
219 *s = 0;
220 }
221}
222
223
224static void
225cmdline_parser_release (struct gengetopt_args_info *args_info)
226{
227 unsigned int i;
228 free_string_field (&(args_info->output_arg));
229 free_string_field (&(args_info->output_orig));
230 free_string_field (&(args_info->shells_orig));
231 free_string_field (&(args_info->latticeConstant_orig));
232 free_string_field (&(args_info->lattice_arg));
233 free_string_field (&(args_info->lattice_orig));
234 free_string_field (&(args_info->columnAtoms_orig));
235 free_string_field (&(args_info->twinAtoms_orig));
236 free_string_field (&(args_info->truncatedPlanes_orig));
237 free_string_field (&(args_info->unitCells_orig));
238
239
240 for (i = 0; i < args_info->inputs_num; ++i)
241 free (args_info->inputs [i]);
242
243 if (args_info->inputs_num)
244 free (args_info->inputs);
245
246 clear_given (args_info);
247}
248
249/**
250 * @param val the value to check
251 * @param values the possible values
252 * @return the index of the matched value:
253 * -1 if no value matched,
254 * -2 if more than one value has matched
255 */
256static int
257check_possible_values(const char *val, const char *values[])
258{
259 int i, found, last;
260 size_t len;
261
262 if (!val) /* otherwise strlen() crashes below */
263 return -1; /* -1 means no argument for the option */
264
265 found = last = 0;
266
267 for (i = 0, len = strlen(val); values[i]; ++i)
268 {
269 if (strncmp(val, values[i], len) == 0)
270 {
271 ++found;
272 last = i;
273 if (strlen(values[i]) == len)
274 return i; /* exact macth no need to check more */
275 }
276 }
277
278 if (found == 1) /* one match: OK */
279 return last;
280
281 return (found ? -2 : -1); /* return many values or none matched */
282}
283
284
285static void
286write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
287{
288 int found = -1;
289 if (arg) {
290 if (values) {
291 found = check_possible_values(arg, values);
292 }
293 if (found >= 0)
294 fprintf(outfile, "%s=\"%s\" # %s\n", opt, arg, values[found]);
295 else
296 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
297 } else {
298 fprintf(outfile, "%s\n", opt);
299 }
300}
301
302
303int
304cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
305{
306 int i = 0;
307
308 if (!outfile)
309 {
310 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
311 return EXIT_FAILURE;
312 }
313
314 if (args_info->help_given)
315 write_into_file(outfile, "help", 0, 0 );
316 if (args_info->version_given)
317 write_into_file(outfile, "version", 0, 0 );
318 if (args_info->output_given)
319 write_into_file(outfile, "output", args_info->output_orig, 0);
320 if (args_info->shells_given)
321 write_into_file(outfile, "shells", args_info->shells_orig, 0);
322 if (args_info->latticeConstant_given)
323 write_into_file(outfile, "latticeConstant", args_info->latticeConstant_orig, 0);
324 if (args_info->lattice_given)
325 write_into_file(outfile, "lattice", args_info->lattice_orig, cmdline_parser_lattice_values);
326 if (args_info->columnAtoms_given)
327 write_into_file(outfile, "columnAtoms", args_info->columnAtoms_orig, 0);
328 if (args_info->twinAtoms_given)
329 write_into_file(outfile, "twinAtoms", args_info->twinAtoms_orig, 0);
330 if (args_info->truncatedPlanes_given)
331 write_into_file(outfile, "truncatedPlanes", args_info->truncatedPlanes_orig, 0);
332 if (args_info->unitCells_given)
333 write_into_file(outfile, "unitCells", args_info->unitCells_orig, 0);
334 if (args_info->ico_given)
335 write_into_file(outfile, "ico", 0, 0 );
336 if (args_info->deca_given)
337 write_into_file(outfile, "deca", 0, 0 );
338 if (args_info->ino_given)
339 write_into_file(outfile, "ino", 0, 0 );
340 if (args_info->marks_given)
341 write_into_file(outfile, "marks", 0, 0 );
342 if (args_info->stone_given)
343 write_into_file(outfile, "stone", 0, 0 );
344 if (args_info->cuboctahedron_given)
345 write_into_file(outfile, "cuboctahedron", 0, 0 );
346 if (args_info->truncatedCube_given)
347 write_into_file(outfile, "truncatedCube", 0, 0 );
348
349
350 i = EXIT_SUCCESS;
351 return i;
352}
353
354int
355cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
356{
357 FILE *outfile;
358 int i = 0;
359
360 outfile = fopen(filename, "w");
361
362 if (!outfile)
363 {
364 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
365 return EXIT_FAILURE;
366 }
367
368 i = cmdline_parser_dump(outfile, args_info);
369 fclose (outfile);
370
371 return i;
372}
373
374void
376{
377 cmdline_parser_release (args_info);
378}
379
380/** @brief replacement of strdup, which is not standard */
381char *
382gengetopt_strdup (const char *s)
383{
384 char *result = 0;
385 if (!s)
386 return result;
387
388 result = (char*)malloc(strlen(s) + 1);
389 if (result == (char*)0)
390 return (char*)0;
391 strcpy(result, s);
392 return result;
393}
394
395static void
396reset_group_clusterShape(struct gengetopt_args_info *args_info)
397{
398 if (! args_info->clusterShape_group_counter)
399 return;
400
401 args_info->ico_given = 0 ;
402 args_info->deca_given = 0 ;
403 args_info->ino_given = 0 ;
404 args_info->marks_given = 0 ;
405 args_info->stone_given = 0 ;
406 args_info->cuboctahedron_given = 0 ;
407 args_info->truncatedCube_given = 0 ;
408
409 args_info->clusterShape_group_counter = 0;
410}
411
412int
413cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
414{
415 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
416}
417
418int
419cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
420 struct cmdline_parser_params *params)
421{
422 int result;
423 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
424
425 return result;
426}
427
428int
429cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
430{
431 int result;
432 struct cmdline_parser_params params;
433
434 params.override = override;
435 params.initialize = initialize;
437 params.check_ambiguity = 0;
438 params.print_errors = 1;
439
440 result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
441
442 return result;
443}
444
445int
446cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
447{
448 int result = EXIT_SUCCESS;
449
450 if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
451 result = EXIT_FAILURE;
452
453 return result;
454}
455
456int
457cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
458{
459 int error_occurred = 0;
460 FIX_UNUSED (additional_error);
461
462 /* checks for required options */
463 if (! args_info->output_given)
464 {
465 fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
466 error_occurred = 1;
467 }
468
469 if (args_info->clusterShape_group_counter == 0)
470 {
471 fprintf (stderr, "%s: %d options of group clusterShape were given. One is required%s.\n", prog_name, args_info->clusterShape_group_counter, (additional_error ? additional_error : ""));
472 error_occurred = 1;
473 }
474
475
476 /* checks for dependences among options */
477
478 return error_occurred;
479}
480
481/*
482 * Extracted from the glibc source tree, version 2.3.6
483 *
484 * Licensed under the GPL as per the whole glibc source tree.
485 *
486 * This file was modified so that getopt_long can be called
487 * many times without risking previous memory to be spoiled.
488 *
489 * Modified by Andre Noll and Lorenzo Bettini for use in
490 * GNU gengetopt generated files.
491 *
492 */
493
494/*
495 * we must include anything we need since this file is not thought to be
496 * inserted in a file already using getopt.h
497 *
498 * Lorenzo
499 */
500
501struct option
502{
503 const char *name;
504 /* has_arg can't be an enum because some compilers complain about
505 type mismatches in all the code that assumes it is an int. */
506 int has_arg;
507 int *flag;
508 int val;
509};
510
511/* This version of `getopt' appears to the caller like standard Unix `getopt'
512 but it behaves differently for the user, since it allows the user
513 to intersperse the options with the other arguments.
514
515 As `getopt' works, it permutes the elements of ARGV so that,
516 when it is done, all the options precede everything else. Thus
517 all application programs are extended to handle flexible argument order.
518*/
519/*
520 If the field `flag' is not NULL, it points to a variable that is set
521 to the value given in the field `val' when the option is found, but
522 left unchanged if the option is not found.
523
524 To have a long-named option do something other than set an `int' to
525 a compiled-in constant, such as set a value from `custom_optarg', set the
526 option's `flag' field to zero and its `val' field to a nonzero
527 value (the equivalent single-letter option character, if there is
528 one). For long options that have a zero `flag' field, `getopt'
529 returns the contents of the `val' field. */
530
531/* Names for the values of the `has_arg' field of `struct option'. */
532#ifndef no_argument
533#define no_argument 0
534#endif
535
536#ifndef required_argument
537#define required_argument 1
538#endif
539
540#ifndef optional_argument
541#define optional_argument 2
542#endif
543
544struct custom_getopt_data {
545 /*
546 * These have exactly the same meaning as the corresponding global variables,
547 * except that they are used for the reentrant versions of getopt.
548 */
549 int custom_optind;
550 int custom_opterr;
551 int custom_optopt;
552 char *custom_optarg;
553
554 /* True if the internal members have been initialized. */
555 int initialized;
556
557 /*
558 * The next char to be scanned in the option-element in which the last option
559 * character we returned was found. This allows us to pick up the scan where
560 * we left off. If this is zero, or a null string, it means resume the scan by
561 * advancing to the next ARGV-element.
562 */
563 char *nextchar;
564
565 /*
566 * Describe the part of ARGV that contains non-options that have been skipped.
567 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
568 * the index after the last of them.
569 */
570 int first_nonopt;
571 int last_nonopt;
572};
573
574/*
575 * the variables optarg, optind, opterr and optopt are renamed with
576 * the custom_ prefix so that they don't interfere with getopt ones.
577 *
578 * Moreover they're static so they are visible only from within the
579 * file where this very file will be included.
580 */
581
582/*
583 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
584 * option that takes an argument, the argument value is returned here.
585 */
586static char *custom_optarg;
587
588/*
589 * Index in ARGV of the next element to be scanned. This is used for
590 * communication to and from the caller and for communication between
591 * successive calls to `custom_getopt'.
592 *
593 * On entry to `custom_getopt', 1 means this is the first call; initialize.
594 *
595 * When `custom_getopt' returns -1, this is the index of the first of the non-option
596 * elements that the caller should itself scan.
597 *
598 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
599 * has been scanned so far.
600 *
601 * 1003.2 says this must be 1 before any call.
602 */
603static int custom_optind = 1;
604
605/*
606 * Callers store zero here to inhibit the error message for unrecognized
607 * options.
608 */
609static int custom_opterr = 1;
610
611/*
612 * Set to an option character which was unrecognized. This must be initialized
613 * on some systems to avoid linking in the system's own getopt implementation.
614 */
615static int custom_optopt = '?';
616
617/*
618 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
619 * [first_nonopt,last_nonopt) which contains all the non-options that have been
620 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
621 * all the options processed since those non-options were skipped.
622 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
623 * indices of the non-options in ARGV after they are moved.
624 */
625static void exchange(char **argv, struct custom_getopt_data *d)
626{
627 int bottom = d->first_nonopt;
628 int middle = d->last_nonopt;
629 int top = d->custom_optind;
630 char *tem;
631
632 /*
633 * Exchange the shorter segment with the far end of the longer segment.
634 * That puts the shorter segment into the right place. It leaves the
635 * longer segment in the right place overall, but it consists of two
636 * parts that need to be swapped next.
637 */
638 while (top > middle && middle > bottom) {
639 if (top - middle > middle - bottom) {
640 /* Bottom segment is the short one. */
641 int len = middle - bottom;
642 int i;
643
644 /* Swap it with the top part of the top segment. */
645 for (i = 0; i < len; i++) {
646 tem = argv[bottom + i];
647 argv[bottom + i] =
648 argv[top - (middle - bottom) + i];
649 argv[top - (middle - bottom) + i] = tem;
650 }
651 /* Exclude the moved bottom segment from further swapping. */
652 top -= len;
653 } else {
654 /* Top segment is the short one. */
655 int len = top - middle;
656 int i;
657
658 /* Swap it with the bottom part of the bottom segment. */
659 for (i = 0; i < len; i++) {
660 tem = argv[bottom + i];
661 argv[bottom + i] = argv[middle + i];
662 argv[middle + i] = tem;
663 }
664 /* Exclude the moved top segment from further swapping. */
665 bottom += len;
666 }
667 }
668 /* Update records for the slots the non-options now occupy. */
669 d->first_nonopt += (d->custom_optind - d->last_nonopt);
670 d->last_nonopt = d->custom_optind;
671}
672
673/* Initialize the internal data when the first call is made. */
674static void custom_getopt_initialize(struct custom_getopt_data *d)
675{
676 /*
677 * Start processing options with ARGV-element 1 (since ARGV-element 0
678 * is the program name); the sequence of previously skipped non-option
679 * ARGV-elements is empty.
680 */
681 d->first_nonopt = d->last_nonopt = d->custom_optind;
682 d->nextchar = NULL;
683 d->initialized = 1;
684}
685
686#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
687
688/* return: zero: continue, nonzero: return given value to user */
689static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
690 struct custom_getopt_data *d)
691{
692 /*
693 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
694 * moved back by the user (who may also have changed the arguments).
695 */
696 if (d->last_nonopt > d->custom_optind)
697 d->last_nonopt = d->custom_optind;
698 if (d->first_nonopt > d->custom_optind)
699 d->first_nonopt = d->custom_optind;
700 /*
701 * If we have just processed some options following some
702 * non-options, exchange them so that the options come first.
703 */
704 if (d->first_nonopt != d->last_nonopt &&
705 d->last_nonopt != d->custom_optind)
706 exchange((char **) argv, d);
707 else if (d->last_nonopt != d->custom_optind)
708 d->first_nonopt = d->custom_optind;
709 /*
710 * Skip any additional non-options and extend the range of
711 * non-options previously skipped.
712 */
713 while (d->custom_optind < argc && NONOPTION_P)
714 d->custom_optind++;
715 d->last_nonopt = d->custom_optind;
716 /*
717 * The special ARGV-element `--' means premature end of options. Skip
718 * it like a null option, then exchange with previous non-options as if
719 * it were an option, then skip everything else like a non-option.
720 */
721 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
722 d->custom_optind++;
723 if (d->first_nonopt != d->last_nonopt
724 && d->last_nonopt != d->custom_optind)
725 exchange((char **) argv, d);
726 else if (d->first_nonopt == d->last_nonopt)
727 d->first_nonopt = d->custom_optind;
728 d->last_nonopt = argc;
729 d->custom_optind = argc;
730 }
731 /*
732 * If we have done all the ARGV-elements, stop the scan and back over
733 * any non-options that we skipped and permuted.
734 */
735 if (d->custom_optind == argc) {
736 /*
737 * Set the next-arg-index to point at the non-options that we
738 * previously skipped, so the caller will digest them.
739 */
740 if (d->first_nonopt != d->last_nonopt)
741 d->custom_optind = d->first_nonopt;
742 return -1;
743 }
744 /*
745 * If we have come to a non-option and did not permute it, either stop
746 * the scan or describe it to the caller and pass it by.
747 */
748 if (NONOPTION_P) {
749 d->custom_optarg = argv[d->custom_optind++];
750 return 1;
751 }
752 /*
753 * We have found another option-ARGV-element. Skip the initial
754 * punctuation.
755 */
756 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
757 return 0;
758}
759
760/*
761 * Check whether the ARGV-element is a long option.
762 *
763 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
764 * that an abbreviation of the long option, just like "--fu", and not "-f" with
765 * arg "u".
766 *
767 * This distinction seems to be the most useful approach.
768 *
769 */
770static int check_long_opt(int argc, char *const *argv, const char *optstring,
771 const struct option *longopts, int *longind,
772 int print_errors, struct custom_getopt_data *d)
773{
774 char *nameend;
775 const struct option *p;
776 const struct option *pfound = NULL;
777 int exact = 0;
778 int ambig = 0;
779 int indfound = -1;
780 int option_index;
781
782 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
783 /* Do nothing. */ ;
784
785 /* Test all long options for either exact match or abbreviated matches */
786 for (p = longopts, option_index = 0; p->name; p++, option_index++)
787 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
788 if ((unsigned int) (nameend - d->nextchar)
789 == (unsigned int) strlen(p->name)) {
790 /* Exact match found. */
791 pfound = p;
792 indfound = option_index;
793 exact = 1;
794 break;
795 } else if (pfound == NULL) {
796 /* First nonexact match found. */
797 pfound = p;
798 indfound = option_index;
799 } else if (pfound->has_arg != p->has_arg
800 || pfound->flag != p->flag
801 || pfound->val != p->val)
802 /* Second or later nonexact match found. */
803 ambig = 1;
804 }
805 if (ambig && !exact) {
806 if (print_errors) {
807 fprintf(stderr,
808 "%s: option `%s' is ambiguous\n",
809 argv[0], argv[d->custom_optind]);
810 }
811 d->nextchar += strlen(d->nextchar);
812 d->custom_optind++;
813 d->custom_optopt = 0;
814 return '?';
815 }
816 if (pfound) {
817 option_index = indfound;
818 d->custom_optind++;
819 if (*nameend) {
820 if (pfound->has_arg != no_argument)
821 d->custom_optarg = nameend + 1;
822 else {
823 if (print_errors) {
824 if (argv[d->custom_optind - 1][1] == '-') {
825 /* --option */
826 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
827 argv[0], pfound->name);
828 } else {
829 /* +option or -option */
830 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
831 argv[0], argv[d->custom_optind - 1][0], pfound->name);
832 }
833
834 }
835 d->nextchar += strlen(d->nextchar);
836 d->custom_optopt = pfound->val;
837 return '?';
838 }
839 } else if (pfound->has_arg == required_argument) {
840 if (d->custom_optind < argc)
841 d->custom_optarg = argv[d->custom_optind++];
842 else {
843 if (print_errors) {
844 fprintf(stderr,
845 "%s: option `%s' requires an argument\n",
846 argv[0],
847 argv[d->custom_optind - 1]);
848 }
849 d->nextchar += strlen(d->nextchar);
850 d->custom_optopt = pfound->val;
851 return optstring[0] == ':' ? ':' : '?';
852 }
853 }
854 d->nextchar += strlen(d->nextchar);
855 if (longind != NULL)
856 *longind = option_index;
857 if (pfound->flag) {
858 *(pfound->flag) = pfound->val;
859 return 0;
860 }
861 return pfound->val;
862 }
863 /*
864 * Can't find it as a long option. If this is not getopt_long_only, or
865 * the option starts with '--' or is not a valid short option, then
866 * it's an error. Otherwise interpret it as a short option.
867 */
868 if (print_errors) {
869 if (argv[d->custom_optind][1] == '-') {
870 /* --option */
871 fprintf(stderr,
872 "%s: unrecognized option `--%s'\n",
873 argv[0], d->nextchar);
874 } else {
875 /* +option or -option */
876 fprintf(stderr,
877 "%s: unrecognized option `%c%s'\n",
878 argv[0], argv[d->custom_optind][0],
879 d->nextchar);
880 }
881 }
882 d->nextchar = (char *) "";
883 d->custom_optind++;
884 d->custom_optopt = 0;
885 return '?';
886}
887
888static int check_short_opt(int argc, char *const *argv, const char *optstring,
889 int print_errors, struct custom_getopt_data *d)
890{
891 char c = *d->nextchar++;
892 const char *temp = strchr(optstring, c);
893
894 /* Increment `custom_optind' when we start to process its last character. */
895 if (*d->nextchar == '\0')
896 ++d->custom_optind;
897 if (!temp || c == ':') {
898 if (print_errors)
899 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
900
901 d->custom_optopt = c;
902 return '?';
903 }
904 if (temp[1] == ':') {
905 if (temp[2] == ':') {
906 /* This is an option that accepts an argument optionally. */
907 if (*d->nextchar != '\0') {
908 d->custom_optarg = d->nextchar;
909 d->custom_optind++;
910 } else
911 d->custom_optarg = NULL;
912 d->nextchar = NULL;
913 } else {
914 /* This is an option that requires an argument. */
915 if (*d->nextchar != '\0') {
916 d->custom_optarg = d->nextchar;
917 /*
918 * If we end this ARGV-element by taking the
919 * rest as an arg, we must advance to the next
920 * element now.
921 */
922 d->custom_optind++;
923 } else if (d->custom_optind == argc) {
924 if (print_errors) {
925 fprintf(stderr,
926 "%s: option requires an argument -- %c\n",
927 argv[0], c);
928 }
929 d->custom_optopt = c;
930 if (optstring[0] == ':')
931 c = ':';
932 else
933 c = '?';
934 } else
935 /*
936 * We already incremented `custom_optind' once;
937 * increment it again when taking next ARGV-elt
938 * as argument.
939 */
940 d->custom_optarg = argv[d->custom_optind++];
941 d->nextchar = NULL;
942 }
943 }
944 return c;
945}
946
947/*
948 * Scan elements of ARGV for option characters given in OPTSTRING.
949 *
950 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
951 * then it is an option element. The characters of this element
952 * (aside from the initial '-') are option characters. If `getopt'
953 * is called repeatedly, it returns successively each of the option characters
954 * from each of the option elements.
955 *
956 * If `getopt' finds another option character, it returns that character,
957 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
958 * resume the scan with the following option character or ARGV-element.
959 *
960 * If there are no more option characters, `getopt' returns -1.
961 * Then `custom_optind' is the index in ARGV of the first ARGV-element
962 * that is not an option. (The ARGV-elements have been permuted
963 * so that those that are not options now come last.)
964 *
965 * OPTSTRING is a string containing the legitimate option characters.
966 * If an option character is seen that is not listed in OPTSTRING,
967 * return '?' after printing an error message. If you set `custom_opterr' to
968 * zero, the error message is suppressed but we still return '?'.
969 *
970 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
971 * so the following text in the same ARGV-element, or the text of the following
972 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
973 * wants an optional arg; if there is text in the current ARGV-element,
974 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
975 *
976 * If OPTSTRING starts with `-' or `+', it requests different methods of
977 * handling the non-option ARGV-elements.
978 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
979 *
980 * Long-named options begin with `--' instead of `-'.
981 * Their names may be abbreviated as long as the abbreviation is unique
982 * or is an exact match for some defined option. If they have an
983 * argument, it follows the option name in the same ARGV-element, separated
984 * from the option name by a `=', or else the in next ARGV-element.
985 * When `getopt' finds a long-named option, it returns 0 if that option's
986 * `flag' field is nonzero, the value of the option's `val' field
987 * if the `flag' field is zero.
988 *
989 * The elements of ARGV aren't really const, because we permute them.
990 * But we pretend they're const in the prototype to be compatible
991 * with other systems.
992 *
993 * LONGOPTS is a vector of `struct option' terminated by an
994 * element containing a name which is zero.
995 *
996 * LONGIND returns the index in LONGOPT of the long-named option found.
997 * It is only valid when a long-named option has been found by the most
998 * recent call.
999 *
1000 * Return the option character from OPTS just read. Return -1 when there are
1001 * no more options. For unrecognized options, or options missing arguments,
1002 * `custom_optopt' is set to the option letter, and '?' is returned.
1003 *
1004 * The OPTS string is a list of characters which are recognized option letters,
1005 * optionally followed by colons, specifying that that letter takes an
1006 * argument, to be placed in `custom_optarg'.
1007 *
1008 * If a letter in OPTS is followed by two colons, its argument is optional.
1009 * This behavior is specific to the GNU `getopt'.
1010 *
1011 * The argument `--' causes premature termination of argument scanning,
1012 * explicitly telling `getopt' that there are no more options. If OPTS begins
1013 * with `--', then non-option arguments are treated as arguments to the option
1014 * '\0'. This behavior is specific to the GNU `getopt'.
1015 */
1016
1017static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1018 const struct option *longopts, int *longind,
1019 struct custom_getopt_data *d)
1020{
1021 int ret, print_errors = d->custom_opterr;
1022
1023 if (optstring[0] == ':')
1024 print_errors = 0;
1025 if (argc < 1)
1026 return -1;
1027 d->custom_optarg = NULL;
1028
1029 /*
1030 * This is a big difference with GNU getopt, since optind == 0
1031 * means initialization while here 1 means first call.
1032 */
1033 if (d->custom_optind == 0 || !d->initialized) {
1034 if (d->custom_optind == 0)
1035 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
1036 custom_getopt_initialize(d);
1037 }
1038 if (d->nextchar == NULL || *d->nextchar == '\0') {
1039 ret = shuffle_argv(argc, argv, longopts, d);
1040 if (ret)
1041 return ret;
1042 }
1043 if (longopts && (argv[d->custom_optind][1] == '-' ))
1044 return check_long_opt(argc, argv, optstring, longopts,
1045 longind, print_errors, d);
1046 return check_short_opt(argc, argv, optstring, print_errors, d);
1047}
1048
1049static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1050 const struct option *longopts, int *longind)
1051{
1052 int result;
1053 /* Keep a global copy of all internal members of d */
1054 static struct custom_getopt_data d;
1055
1056 d.custom_optind = custom_optind;
1057 d.custom_opterr = custom_opterr;
1058 result = getopt_internal_r(argc, argv, optstring, longopts,
1059 longind, &d);
1060 custom_optind = d.custom_optind;
1061 custom_optarg = d.custom_optarg;
1062 custom_optopt = d.custom_optopt;
1063 return result;
1064}
1065
1066static int custom_getopt_long (int argc, char *const *argv, const char *options,
1067 const struct option *long_options, int *opt_index)
1068{
1069 return custom_getopt_internal(argc, argv, options, long_options,
1070 opt_index);
1071}
1072
1073
1074static char *package_name = 0;
1075
1076/**
1077 * @brief updates an option
1078 * @param field the generic pointer to the field to update
1079 * @param orig_field the pointer to the orig field
1080 * @param field_given the pointer to the number of occurrence of this option
1081 * @param prev_given the pointer to the number of occurrence already seen
1082 * @param value the argument for this option (if null no arg was specified)
1083 * @param possible_values the possible values for this option (if specified)
1084 * @param default_value the default value (in case the option only accepts fixed values)
1085 * @param arg_type the type of this option
1086 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
1087 * @param override @see cmdline_parser_params.override
1088 * @param no_free whether to free a possible previous value
1089 * @param multiple_option whether this is a multiple option
1090 * @param long_opt the corresponding long option
1091 * @param short_opt the corresponding short option (or '-' if none)
1092 * @param additional_error possible further error specification
1093 */
1094static
1095int update_arg(void *field, char **orig_field,
1096 unsigned int *field_given, unsigned int *prev_given,
1097 char *value, const char *possible_values[],
1098 const char *default_value,
1099 cmdline_parser_arg_type arg_type,
1100 int check_ambiguity, int override,
1101 int no_free, int multiple_option,
1102 const char *long_opt, char short_opt,
1103 const char *additional_error)
1104{
1105 char *stop_char = 0;
1106 const char *val = value;
1107 int found;
1108 char **string_field;
1109 FIX_UNUSED (field);
1110
1111 stop_char = 0;
1112 found = 0;
1113
1114 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1115 {
1116 if (short_opt != '-')
1117 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1118 package_name, long_opt, short_opt,
1119 (additional_error ? additional_error : ""));
1120 else
1121 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1122 package_name, long_opt,
1123 (additional_error ? additional_error : ""));
1124 return 1; /* failure */
1125 }
1126
1127 if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0)
1128 {
1129 if (short_opt != '-')
1130 fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n",
1131 package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, short_opt,
1132 (additional_error ? additional_error : ""));
1133 else
1134 fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n",
1135 package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt,
1136 (additional_error ? additional_error : ""));
1137 return 1; /* failure */
1138 }
1139
1140 if (field_given && *field_given && ! override)
1141 return 0;
1142 if (prev_given)
1143 (*prev_given)++;
1144 if (field_given)
1145 (*field_given)++;
1146 if (possible_values)
1147 val = possible_values[found];
1148
1149 switch(arg_type) {
1150 case ARG_INT:
1151 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1152 break;
1153 case ARG_DOUBLE:
1154 if (val) *((double *)field) = strtod (val, &stop_char);
1155 break;
1156 case ARG_STRING:
1157 if (val) {
1158 string_field = (char **)field;
1159 if (!no_free && *string_field)
1160 free (*string_field); /* free previous string */
1161 *string_field = gengetopt_strdup (val);
1162 }
1163 break;
1164 default:
1165 break;
1166 };
1167
1168 /* check numeric conversion */
1169 switch(arg_type) {
1170 case ARG_INT:
1171 case ARG_DOUBLE:
1172 if (val && !(stop_char && *stop_char == '\0')) {
1173 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1174 return 1; /* failure */
1175 }
1176 break;
1177 default:
1178 ;
1179 };
1180
1181 /* store the original value */
1182 switch(arg_type) {
1183 case ARG_NO:
1184 break;
1185 default:
1186 if (value && orig_field) {
1187 if (no_free) {
1188 *orig_field = value;
1189 } else {
1190 if (*orig_field)
1191 free (*orig_field); /* free previous string */
1192 *orig_field = gengetopt_strdup (value);
1193 }
1194 }
1195 };
1196
1197 return 0; /* OK */
1198}
1199
1200
1201int
1202cmdline_parser_internal (
1203 int argc, char **argv, struct gengetopt_args_info *args_info,
1204 struct cmdline_parser_params *params, const char *additional_error)
1205{
1206 int c; /* Character of the parsed option. */
1207
1208 int error_occurred = 0;
1209 struct gengetopt_args_info local_args_info;
1210
1211 int override;
1212 int initialize;
1213 int check_required;
1214 int check_ambiguity;
1215
1216 char *optarg;
1217 int optind;
1218 int opterr;
1219 int optopt;
1220
1221 package_name = argv[0];
1222
1223 override = params->override;
1224 initialize = params->initialize;
1225 check_required = params->check_required;
1226 check_ambiguity = params->check_ambiguity;
1227
1228 if (initialize)
1229 cmdline_parser_init (args_info);
1230
1231 cmdline_parser_init (&local_args_info);
1232
1233 optarg = 0;
1234 optind = 0;
1235 opterr = params->print_errors;
1236 optopt = '?';
1237
1238 while (1)
1239 {
1240 int option_index = 0;
1241
1242 static struct option long_options[] = {
1243 { "help", 0, NULL, 'h' },
1244 { "version", 0, NULL, 'V' },
1245 { "output", 1, NULL, 'o' },
1246 { "shells", 1, NULL, 'n' },
1247 { "latticeConstant", 1, NULL, 'd' },
1248 { "lattice", 1, NULL, 'l' },
1249 { "columnAtoms", 1, NULL, 'c' },
1250 { "twinAtoms", 1, NULL, 't' },
1251 { "truncatedPlanes", 1, NULL, 'p' },
1252 { "unitCells", 1, NULL, 'u' },
1253 { "ico", 0, NULL, 0 },
1254 { "deca", 0, NULL, 0 },
1255 { "ino", 0, NULL, 0 },
1256 { "marks", 0, NULL, 0 },
1257 { "stone", 0, NULL, 0 },
1258 { "cuboctahedron", 0, NULL, 0 },
1259 { "truncatedCube", 0, NULL, 0 },
1260 { 0, 0, 0, 0 }
1261 };
1262
1263 custom_optarg = optarg;
1264 custom_optind = optind;
1265 custom_opterr = opterr;
1266 custom_optopt = optopt;
1267
1268 c = custom_getopt_long (argc, argv, "hVo:n:d:l:c:t:p:u:", long_options, &option_index);
1269
1270 optarg = custom_optarg;
1271 optind = custom_optind;
1272 opterr = custom_opterr;
1273 optopt = custom_optopt;
1274
1275 if (c == -1) break; /* Exit from `while (1)' loop. */
1276
1277 switch (c)
1278 {
1279 case 'h': /* Print help and exit. */
1280 cmdline_parser_print_help ();
1281 cmdline_parser_free (&local_args_info);
1282 exit (EXIT_SUCCESS);
1283
1284 case 'V': /* Print version and exit. */
1285 cmdline_parser_print_version ();
1286 cmdline_parser_free (&local_args_info);
1287 exit (EXIT_SUCCESS);
1288
1289 case 'o': /* Output file name. */
1290
1291
1292 if (update_arg( (void *)&(args_info->output_arg),
1293 &(args_info->output_orig), &(args_info->output_given),
1294 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1295 check_ambiguity, override, 0, 0,
1296 "output", 'o',
1297 additional_error))
1298 goto failure;
1299
1300 break;
1301 case 'n': /* Nanoparticle shells. */
1302
1303
1304 if (update_arg( (void *)&(args_info->shells_arg),
1305 &(args_info->shells_orig), &(args_info->shells_given),
1306 &(local_args_info.shells_given), optarg, 0, 0, ARG_INT,
1307 check_ambiguity, override, 0, 0,
1308 "shells", 'n',
1309 additional_error))
1310 goto failure;
1311
1312 break;
1313 case 'd': /* Lattice spacing in Angstroms for cubic lattice.. */
1314
1315
1316 if (update_arg( (void *)&(args_info->latticeConstant_arg),
1317 &(args_info->latticeConstant_orig), &(args_info->latticeConstant_given),
1318 &(local_args_info.latticeConstant_given), optarg, 0, 0, ARG_DOUBLE,
1319 check_ambiguity, override, 0, 0,
1320 "latticeConstant", 'd',
1321 additional_error))
1322 goto failure;
1323
1324 break;
1325 case 'l': /* Lattice Type. */
1326
1327
1328 if (update_arg( (void *)&(args_info->lattice_arg),
1329 &(args_info->lattice_orig), &(args_info->lattice_given),
1330 &(local_args_info.lattice_given), optarg, cmdline_parser_lattice_values, 0, ARG_STRING,
1331 check_ambiguity, override, 0, 0,
1332 "lattice", 'l',
1333 additional_error))
1334 goto failure;
1335
1336 break;
1337 case 'c': /* Number of atoms along central column (Decahedron only). */
1338
1339
1340 if (update_arg( (void *)&(args_info->columnAtoms_arg),
1341 &(args_info->columnAtoms_orig), &(args_info->columnAtoms_given),
1342 &(local_args_info.columnAtoms_given), optarg, 0, 0, ARG_INT,
1343 check_ambiguity, override, 0, 0,
1344 "columnAtoms", 'c',
1345 additional_error))
1346 goto failure;
1347
1348 break;
1349 case 't': /* Number of atoms along twin boundary (Decahedron only). */
1350
1351
1352 if (update_arg( (void *)&(args_info->twinAtoms_arg),
1353 &(args_info->twinAtoms_orig), &(args_info->twinAtoms_given),
1354 &(local_args_info.twinAtoms_given), optarg, 0, 0, ARG_INT,
1355 check_ambiguity, override, 0, 0,
1356 "twinAtoms", 't',
1357 additional_error))
1358 goto failure;
1359
1360 break;
1361 case 'p': /* Number of truncated planes (Curling-stone Decahedra and Truncated Cubes only). */
1362
1363
1364 if (update_arg( (void *)&(args_info->truncatedPlanes_arg),
1365 &(args_info->truncatedPlanes_orig), &(args_info->truncatedPlanes_given),
1366 &(local_args_info.truncatedPlanes_given), optarg, 0, 0, ARG_INT,
1367 check_ambiguity, override, 0, 0,
1368 "truncatedPlanes", 'p',
1369 additional_error))
1370 goto failure;
1371
1372 break;
1373 case 'u': /* Number of unit cell (Cuboctahedron and Truncated Cube only). */
1374
1375
1376 if (update_arg( (void *)&(args_info->unitCells_arg),
1377 &(args_info->unitCells_orig), &(args_info->unitCells_given),
1378 &(local_args_info.unitCells_given), optarg, 0, 0, ARG_INT,
1379 check_ambiguity, override, 0, 0,
1380 "unitCells", 'u',
1381 additional_error))
1382 goto failure;
1383
1384 break;
1385
1386 case 0: /* Long option with no short option */
1387 /* Create an Icosahedral cluster. */
1388 if (strcmp (long_options[option_index].name, "ico") == 0)
1389 {
1390
1391 if (args_info->clusterShape_group_counter && override)
1392 reset_group_clusterShape (args_info);
1393 args_info->clusterShape_group_counter += 1;
1394
1395 if (update_arg( 0 ,
1396 0 , &(args_info->ico_given),
1397 &(local_args_info.ico_given), optarg, 0, 0, ARG_NO,
1398 check_ambiguity, override, 0, 0,
1399 "ico", '-',
1400 additional_error))
1401 goto failure;
1402
1403 }
1404 /* Create a regualar Decahedral cluster. */
1405 else if (strcmp (long_options[option_index].name, "deca") == 0)
1406 {
1407
1408 if (args_info->clusterShape_group_counter && override)
1409 reset_group_clusterShape (args_info);
1410 args_info->clusterShape_group_counter += 1;
1411
1412 if (update_arg( 0 ,
1413 0 , &(args_info->deca_given),
1414 &(local_args_info.deca_given), optarg, 0, 0, ARG_NO,
1415 check_ambiguity, override, 0, 0,
1416 "deca", '-',
1417 additional_error))
1418 goto failure;
1419
1420 }
1421 /* Create an Ino Decahedral cluster. */
1422 else if (strcmp (long_options[option_index].name, "ino") == 0)
1423 {
1424
1425 if (args_info->clusterShape_group_counter && override)
1426 reset_group_clusterShape (args_info);
1427 args_info->clusterShape_group_counter += 1;
1428
1429 if (update_arg( 0 ,
1430 0 , &(args_info->ino_given),
1431 &(local_args_info.ino_given), optarg, 0, 0, ARG_NO,
1432 check_ambiguity, override, 0, 0,
1433 "ino", '-',
1434 additional_error))
1435 goto failure;
1436
1437 }
1438 /* Create a Marks Decahedral cluster. */
1439 else if (strcmp (long_options[option_index].name, "marks") == 0)
1440 {
1441
1442 if (args_info->clusterShape_group_counter && override)
1443 reset_group_clusterShape (args_info);
1444 args_info->clusterShape_group_counter += 1;
1445
1446 if (update_arg( 0 ,
1447 0 , &(args_info->marks_given),
1448 &(local_args_info.marks_given), optarg, 0, 0, ARG_NO,
1449 check_ambiguity, override, 0, 0,
1450 "marks", '-',
1451 additional_error))
1452 goto failure;
1453
1454 }
1455 /* Create a Curling-stone Decahedral cluster. */
1456 else if (strcmp (long_options[option_index].name, "stone") == 0)
1457 {
1458
1459 if (args_info->clusterShape_group_counter && override)
1460 reset_group_clusterShape (args_info);
1461 args_info->clusterShape_group_counter += 1;
1462
1463 if (update_arg( 0 ,
1464 0 , &(args_info->stone_given),
1465 &(local_args_info.stone_given), optarg, 0, 0, ARG_NO,
1466 check_ambiguity, override, 0, 0,
1467 "stone", '-',
1468 additional_error))
1469 goto failure;
1470
1471 }
1472 /* Create a regular Cuboctahedron (requires lattice). */
1473 else if (strcmp (long_options[option_index].name, "cuboctahedron") == 0)
1474 {
1475
1476 if (args_info->clusterShape_group_counter && override)
1477 reset_group_clusterShape (args_info);
1478 args_info->clusterShape_group_counter += 1;
1479
1480 if (update_arg( 0 ,
1481 0 , &(args_info->cuboctahedron_given),
1482 &(local_args_info.cuboctahedron_given), optarg, 0, 0, ARG_NO,
1483 check_ambiguity, override, 0, 0,
1484 "cuboctahedron", '-',
1485 additional_error))
1486 goto failure;
1487
1488 }
1489 /* Create a Truncated Cube (requires lattice). */
1490 else if (strcmp (long_options[option_index].name, "truncatedCube") == 0)
1491 {
1492
1493 if (args_info->clusterShape_group_counter && override)
1494 reset_group_clusterShape (args_info);
1495 args_info->clusterShape_group_counter += 1;
1496
1497 if (update_arg( 0 ,
1498 0 , &(args_info->truncatedCube_given),
1499 &(local_args_info.truncatedCube_given), optarg, 0, 0, ARG_NO,
1500 check_ambiguity, override, 0, 0,
1501 "truncatedCube", '-',
1502 additional_error))
1503 goto failure;
1504
1505 }
1506
1507 break;
1508 case '?': /* Invalid option. */
1509 /* `getopt_long' already printed an error message. */
1510 goto failure;
1511
1512 default: /* bug: option not considered. */
1513 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1514 abort ();
1515 } /* switch */
1516 } /* while */
1517
1518 if (args_info->clusterShape_group_counter > 1)
1519 {
1520 fprintf (stderr, "%s: %d options of group clusterShape were given. One is required%s.\n", argv[0], args_info->clusterShape_group_counter, (additional_error ? additional_error : ""));
1521 error_occurred = 1;
1522 }
1523
1524
1525
1526 if (check_required)
1527 {
1528 error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error);
1529 }
1530
1531 cmdline_parser_release (&local_args_info);
1532
1533 if ( error_occurred )
1534 return (EXIT_FAILURE);
1535
1536 if (optind < argc)
1537 {
1538 int i = 0 ;
1539 int found_prog_name = 0;
1540 /* whether program name, i.e., argv[0], is in the remaining args
1541 (this may happen with some implementations of getopt,
1542 but surely not with the one included by gengetopt) */
1543
1544
1545 args_info->inputs_num = argc - optind - found_prog_name;
1546 args_info->inputs =
1547 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1548 while (optind < argc)
1549 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1550 }
1551
1552 return 0;
1553
1554failure:
1555
1556 cmdline_parser_release (&local_args_info);
1557 return (EXIT_FAILURE);
1558}
#define CMDLINE_PARSER_VERSION
the program version
#define CMDLINE_PARSER_PACKAGE_NAME
the complete program name (used for help and version)
#define CMDLINE_PARSER_PACKAGE
the program name (used for printing errors)
The header file for the command line option parser generated by GNU Gengetopt version 2....
The additional parameters to pass to parser functions.
int print_errors
whether getopt_long should print an error message for a bad option (default 1)
int check_required
whether to check that all required options were provided (default 1)
int check_ambiguity
whether to check for options already specified in the option structure gengetopt_args_info (default 0...
int initialize
whether to initialize the option structure gengetopt_args_info (default 1)
int override
whether to override possibly already present options (default 0)
Where the command line options are stored.
unsigned int ico_given
Whether ico was given.
const char * ino_help
Create an Ino Decahedral cluster help description.
const char * stone_help
Create a Curling-stone Decahedral cluster help description.
unsigned int output_given
Whether output was given.
int clusterShape_group_counter
Counter for group clusterShape.
unsigned int latticeConstant_given
Whether latticeConstant was given.
char * output_orig
output file name original value given at command line.
const char * output_help
output file name help description.
int unitCells_arg
Number of unit cell (Cuboctahedron and Truncated Cube only).
char * twinAtoms_orig
Number of atoms along twin boundary (Decahedron only) original value given at command line.
int shells_arg
Nanoparticle shells.
unsigned int truncatedPlanes_given
Whether truncatedPlanes was given.
unsigned inputs_num
unamed options number
unsigned int marks_given
Whether marks was given.
unsigned int ino_given
Whether ino was given.
const char * columnAtoms_help
Number of atoms along central column (Decahedron only) help description.
const char * shells_help
Nanoparticle shells help description.
unsigned int cuboctahedron_given
Whether cuboctahedron was given.
unsigned int stone_given
Whether stone was given.
const char * latticeConstant_help
Lattice spacing in Angstroms for cubic lattice.
char * truncatedPlanes_orig
Number of truncated planes (Curling-stone Decahedra and Truncated Cubes only) original value given at...
unsigned int lattice_given
Whether lattice was given.
const char * truncatedPlanes_help
Number of truncated planes (Curling-stone Decahedra and Truncated Cubes only) help description.
const char * lattice_help
Lattice Type help description.
unsigned int shells_given
Whether shells was given.
const char * help_help
Print help and exit help description.
int columnAtoms_arg
Number of atoms along central column (Decahedron only).
char * output_arg
output file name.
char ** inputs
unamed options (options without names)
unsigned int deca_given
Whether deca was given.
const char * unitCells_help
Number of unit cell (Cuboctahedron and Truncated Cube only) help description.
int truncatedPlanes_arg
Number of truncated planes (Curling-stone Decahedra and Truncated Cubes only).
char * latticeConstant_orig
Lattice spacing in Angstroms for cubic lattice.
const char * twinAtoms_help
Number of atoms along twin boundary (Decahedron only) help description.
unsigned int twinAtoms_given
Whether twinAtoms was given.
const char * deca_help
Create a regualar Decahedral cluster help description.
const char * ico_help
Create an Icosahedral cluster help description.
int twinAtoms_arg
Number of atoms along twin boundary (Decahedron only).
unsigned int help_given
Whether help was given.
const char * marks_help
Create a Marks Decahedral cluster help description.
char * shells_orig
Nanoparticle shells original value given at command line.
char * lattice_orig
Lattice Type original value given at command line.
unsigned int version_given
Whether version was given.
unsigned int truncatedCube_given
Whether truncatedCube was given.
const char * version_help
Print version and exit help description.
const char * truncatedCube_help
Create a Truncated Cube (requires lattice) help description.
unsigned int columnAtoms_given
Whether columnAtoms was given.
double latticeConstant_arg
Lattice spacing in Angstroms for cubic lattice.
unsigned int unitCells_given
Whether unitCells was given.
char * lattice_arg
Lattice Type.
char * columnAtoms_orig
Number of atoms along central column (Decahedron only) original value given at command line.
const char * cuboctahedron_help
Create a regular Cuboctahedron (requires lattice) help description.
char * unitCells_orig
Number of unit cell (Cuboctahedron and Truncated Cube only) original value given at command line.
int cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
Save the contents of the option struct into an already open FILE stream.
int cmdline_parser(int argc, char **argv, struct gengetopt_args_info *args_info)
The command line parser.
int cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
Save the contents of the option struct into a (text) file.
int cmdline_parser2(int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
The command line parser (version with additional parameters - deprecated)
int cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name)
Checks that all the required options were specified.
struct cmdline_parser_params * cmdline_parser_params_create(void)
Allocates dynamically a cmdline_parser_params structure and initializes all its fields to their defau...
int cmdline_parser_ext(int argc, char **argv, struct gengetopt_args_info *args_info, struct cmdline_parser_params *params)
The command line parser (version with additional parameters)
void cmdline_parser_init(struct gengetopt_args_info *args_info)
Initializes the passed gengetopt_args_info structure's fields (also set default values for options th...
void cmdline_parser_free(struct gengetopt_args_info *args_info)
Deallocates the string fields of the gengetopt_args_info structure (but does not deallocate the struc...
void cmdline_parser_params_init(struct cmdline_parser_params *params)
Initializes all the fields a cmdline_parser_params structure to their default values.