OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
HydroCmd.cpp
1/*
2 File autogenerated by gengetopt version 2.23
3 generated with the following command:
4 gengetopt --no-handle-error --include-getopt --show-required --unamed-opts --file-name=HydroCmd --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
25#include "HydroCmd.hpp"
26
27const char *gengetopt_args_info_purpose = "Generates resistance tensor (.hydro) files which are required when\nusing the Langevin integrator with complex rigid bodies. Hydro\nsupports three approximate models: AtomicBead, RoughShell, and\nBoundaryElement. Additionally, Hydro can generate resistance tensor\nfiles using analytic solutions for simple shapes. \n\nTo generate a .hydro file, one form of an input file must be\nspecified. This can either be a MetaData (omd) file, or xyz, stl, or\nMSMS output files. For stl and MSMS files which both describe triangulated\nsurfaces, the hydrodynamics model must be BoundaryElement. \n\nSince the resistance tensor depends on viscosity of the solvent, and\ndiffusion tensors depend on temperature, these must either be\nspecified as arguments or listed in the MetaData (omd) file with the\nkeywords viscosity and targetTemp. If the approximate model in use is\nthe RoughShell model the beadSize (the diameter of the small beads\nused to approximate the surface of the body) must also be specified.";
28
29const char *gengetopt_args_info_usage = "Usage: Hydro [OPTION]... [FILE]...";
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 "\n Group: input file\n an input file is required",
39 " -i, --input=filename input MetaData (omd) file",
40 " -x, --xyz=filename xyz file for AtomicBead model",
41 " --stl=filename stl file for BoundaryElement model",
42 " --msms=filename filename root for MSMS .vert and .face files",
43 " -o, --output=STRING output file prefix",
44 " --model=ENUM hydrodynamics model (possible\n values=\"AtomicBead\", \"RoughShell\",\n \"BoundaryElement\") (mandatory)",
45 " -s, --beadSize=DOUBLE bead size (diameter) for RoughShell model (in\n angstroms) (default=`0.2')",
46 " -e, --elements output the hydrodynamic elements (beads or\n triangles) only, hydrodynamics calculation will\n not be performed (default=off)",
47 " -v, --viscosity=DOUBLE viscosity (in poise) (default=`0.01')",
48 " -t, --temperature=DOUBLE temperature (in Kelvin (default=`300')",
49 0
50};
51
52typedef enum {ARG_NO
53 , ARG_FLAG
54 , ARG_STRING
55 , ARG_DOUBLE
56 , ARG_ENUM
57} cmdline_parser_arg_type;
58
59static
60void clear_given (struct gengetopt_args_info *args_info);
61static
62void clear_args (struct gengetopt_args_info *args_info);
63
64static int
65cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
66 struct cmdline_parser_params *params, const char *additional_error);
67
68static int
69cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
70
71const char *cmdline_parser_model_values[] = {"AtomicBead", "RoughShell", "BoundaryElement", 0}; /*< Possible values for model. */
72
73static char *
74gengetopt_strdup (const char *s);
75
76static
77void clear_given (struct gengetopt_args_info *args_info)
78{
79 args_info->help_given = 0 ;
80 args_info->version_given = 0 ;
81 args_info->input_given = 0 ;
82 args_info->xyz_given = 0 ;
83 args_info->stl_given = 0 ;
84 args_info->msms_given = 0 ;
85 args_info->output_given = 0 ;
86 args_info->model_given = 0 ;
87 args_info->beadSize_given = 0 ;
88 args_info->elements_given = 0 ;
89 args_info->viscosity_given = 0 ;
90 args_info->temperature_given = 0 ;
91 args_info->input_file_group_counter = 0 ;
92}
93
94static
95void clear_args (struct gengetopt_args_info *args_info)
96{
97 FIX_UNUSED (args_info);
98 args_info->input_arg = NULL;
99 args_info->input_orig = NULL;
100 args_info->xyz_arg = NULL;
101 args_info->xyz_orig = NULL;
102 args_info->stl_arg = NULL;
103 args_info->stl_orig = NULL;
104 args_info->msms_arg = NULL;
105 args_info->msms_orig = NULL;
106 args_info->output_arg = NULL;
107 args_info->output_orig = NULL;
108 args_info->model_arg = model__NULL;
109 args_info->model_orig = NULL;
110 args_info->beadSize_arg = 0.2;
111 args_info->beadSize_orig = NULL;
112 args_info->elements_flag = 0;
113 args_info->viscosity_arg = 0.01;
114 args_info->viscosity_orig = NULL;
115 args_info->temperature_arg = 300;
116 args_info->temperature_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->input_help = gengetopt_args_info_help[3] ;
128 args_info->xyz_help = gengetopt_args_info_help[4] ;
129 args_info->stl_help = gengetopt_args_info_help[5] ;
130 args_info->msms_help = gengetopt_args_info_help[6] ;
131 args_info->output_help = gengetopt_args_info_help[7] ;
132 args_info->model_help = gengetopt_args_info_help[8] ;
133 args_info->beadSize_help = gengetopt_args_info_help[9] ;
134 args_info->elements_help = gengetopt_args_info_help[10] ;
135 args_info->viscosity_help = gengetopt_args_info_help[11] ;
136 args_info->temperature_help = gengetopt_args_info_help[12] ;
137
138}
139
140void
141cmdline_parser_print_version (void)
142{
143 printf ("%s %s\n",
146
147 if (strlen(gengetopt_args_info_versiontext) > 0)
148 printf("\n%s\n", gengetopt_args_info_versiontext);
149}
150
151static void print_help_common(void)
152{
153 size_t len_purpose = strlen(gengetopt_args_info_purpose);
154 size_t len_usage = strlen(gengetopt_args_info_usage);
155
156 if (len_usage > 0) {
157 printf("%s\n", gengetopt_args_info_usage);
158 }
159 if (len_purpose > 0) {
160 printf("%s\n", gengetopt_args_info_purpose);
161 }
162
163 if (len_usage || len_purpose) {
164 printf("\n");
165 }
166
167 if (strlen(gengetopt_args_info_description) > 0) {
168 printf("%s\n\n", gengetopt_args_info_description);
169 }
170}
171
172void
173cmdline_parser_print_help (void)
174{
175 int i = 0;
176 print_help_common();
177 while (gengetopt_args_info_help[i])
178 printf("%s\n", gengetopt_args_info_help[i++]);
179}
180
181void
182cmdline_parser_init (struct gengetopt_args_info *args_info)
183{
184 clear_given (args_info);
185 clear_args (args_info);
186 init_args_info (args_info);
187
188 args_info->inputs = 0;
189 args_info->inputs_num = 0;
190}
191
192void
193cmdline_parser_params_init(struct cmdline_parser_params *params)
194{
195 if (params)
196 {
197 params->override = 0;
198 params->initialize = 1;
199 params->check_required = 1;
200 params->check_ambiguity = 0;
201 params->print_errors = 1;
202 }
203}
204
207{
208 struct cmdline_parser_params *params =
209 (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
211 return params;
212}
213
214static void
215free_string_field (char **s)
216{
217 if (*s)
218 {
219 free (*s);
220 *s = 0;
221 }
222}
223
224
225static void
226cmdline_parser_release (struct gengetopt_args_info *args_info)
227{
228 unsigned int i;
229 free_string_field (&(args_info->input_arg));
230 free_string_field (&(args_info->input_orig));
231 free_string_field (&(args_info->xyz_arg));
232 free_string_field (&(args_info->xyz_orig));
233 free_string_field (&(args_info->stl_arg));
234 free_string_field (&(args_info->stl_orig));
235 free_string_field (&(args_info->msms_arg));
236 free_string_field (&(args_info->msms_orig));
237 free_string_field (&(args_info->output_arg));
238 free_string_field (&(args_info->output_orig));
239 free_string_field (&(args_info->model_orig));
240 free_string_field (&(args_info->beadSize_orig));
241 free_string_field (&(args_info->viscosity_orig));
242 free_string_field (&(args_info->temperature_orig));
243
244
245 for (i = 0; i < args_info->inputs_num; ++i)
246 free (args_info->inputs [i]);
247
248 if (args_info->inputs_num)
249 free (args_info->inputs);
250
251 clear_given (args_info);
252}
253
254/**
255 * @param val the value to check
256 * @param values the possible values
257 * @return the index of the matched value:
258 * -1 if no value matched,
259 * -2 if more than one value has matched
260 */
261static int
262check_possible_values(const char *val, const char *values[])
263{
264 int i, found, last;
265 size_t len;
266
267 if (!val) /* otherwise strlen() crashes below */
268 return -1; /* -1 means no argument for the option */
269
270 found = last = 0;
271
272 for (i = 0, len = strlen(val); values[i]; ++i)
273 {
274 if (strncmp(val, values[i], len) == 0)
275 {
276 ++found;
277 last = i;
278 if (strlen(values[i]) == len)
279 return i; /* exact macth no need to check more */
280 }
281 }
282
283 if (found == 1) /* one match: OK */
284 return last;
285
286 return (found ? -2 : -1); /* return many values or none matched */
287}
288
289
290static void
291write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
292{
293 int found = -1;
294 if (arg) {
295 if (values) {
296 found = check_possible_values(arg, values);
297 }
298 if (found >= 0)
299 fprintf(outfile, "%s=\"%s\" # %s\n", opt, arg, values[found]);
300 else
301 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
302 } else {
303 fprintf(outfile, "%s\n", opt);
304 }
305}
306
307
308int
309cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
310{
311 int i = 0;
312
313 if (!outfile)
314 {
315 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
316 return EXIT_FAILURE;
317 }
318
319 if (args_info->help_given)
320 write_into_file(outfile, "help", 0, 0 );
321 if (args_info->version_given)
322 write_into_file(outfile, "version", 0, 0 );
323 if (args_info->input_given)
324 write_into_file(outfile, "input", args_info->input_orig, 0);
325 if (args_info->xyz_given)
326 write_into_file(outfile, "xyz", args_info->xyz_orig, 0);
327 if (args_info->stl_given)
328 write_into_file(outfile, "stl", args_info->stl_orig, 0);
329 if (args_info->msms_given)
330 write_into_file(outfile, "msms", args_info->msms_orig, 0);
331 if (args_info->output_given)
332 write_into_file(outfile, "output", args_info->output_orig, 0);
333 if (args_info->model_given)
334 write_into_file(outfile, "model", args_info->model_orig, cmdline_parser_model_values);
335 if (args_info->beadSize_given)
336 write_into_file(outfile, "beadSize", args_info->beadSize_orig, 0);
337 if (args_info->elements_given)
338 write_into_file(outfile, "elements", 0, 0 );
339 if (args_info->viscosity_given)
340 write_into_file(outfile, "viscosity", args_info->viscosity_orig, 0);
341 if (args_info->temperature_given)
342 write_into_file(outfile, "temperature", args_info->temperature_orig, 0);
343
344
345 i = EXIT_SUCCESS;
346 return i;
347}
348
349int
350cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
351{
352 FILE *outfile;
353 int i = 0;
354
355 outfile = fopen(filename, "w");
356
357 if (!outfile)
358 {
359 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
360 return EXIT_FAILURE;
361 }
362
363 i = cmdline_parser_dump(outfile, args_info);
364 fclose (outfile);
365
366 return i;
367}
368
369void
371{
372 cmdline_parser_release (args_info);
373}
374
375/** @brief replacement of strdup, which is not standard */
376char *
377gengetopt_strdup (const char *s)
378{
379 char *result = 0;
380 if (!s)
381 return result;
382
383 result = (char*)malloc(strlen(s) + 1);
384 if (result == (char*)0)
385 return (char*)0;
386 strcpy(result, s);
387 return result;
388}
389
390static void
391reset_group_input_file(struct gengetopt_args_info *args_info)
392{
393 if (! args_info->input_file_group_counter)
394 return;
395
396 args_info->input_given = 0 ;
397 free_string_field (&(args_info->input_arg));
398 free_string_field (&(args_info->input_orig));
399 args_info->xyz_given = 0 ;
400 free_string_field (&(args_info->xyz_arg));
401 free_string_field (&(args_info->xyz_orig));
402 args_info->stl_given = 0 ;
403 free_string_field (&(args_info->stl_arg));
404 free_string_field (&(args_info->stl_orig));
405 args_info->msms_given = 0 ;
406 free_string_field (&(args_info->msms_arg));
407 free_string_field (&(args_info->msms_orig));
408
409 args_info->input_file_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->model_given)
464 {
465 fprintf (stderr, "%s: '--model' option required%s\n", prog_name, (additional_error ? additional_error : ""));
466 error_occurred = 1;
467 }
468
469 if (args_info->input_file_group_counter == 0)
470 {
471 fprintf (stderr, "%s: %d options of group input file were given. One is required%s.\n", prog_name, args_info->input_file_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_FLAG:
1151 *((int *)field) = !*((int *)field);
1152 break;
1153 case ARG_DOUBLE:
1154 if (val) *((double *)field) = strtod (val, &stop_char);
1155 break;
1156 case ARG_ENUM:
1157 if (val) *((int *)field) = found;
1158 break;
1159 case ARG_STRING:
1160 if (val) {
1161 string_field = (char **)field;
1162 if (!no_free && *string_field)
1163 free (*string_field); /* free previous string */
1164 *string_field = gengetopt_strdup (val);
1165 }
1166 break;
1167 default:
1168 break;
1169 };
1170
1171 /* check numeric conversion */
1172 switch(arg_type) {
1173 case ARG_DOUBLE:
1174 if (val && !(stop_char && *stop_char == '\0')) {
1175 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1176 return 1; /* failure */
1177 }
1178 break;
1179 default:
1180 ;
1181 };
1182
1183 /* store the original value */
1184 switch(arg_type) {
1185 case ARG_NO:
1186 case ARG_FLAG:
1187 break;
1188 default:
1189 if (value && orig_field) {
1190 if (no_free) {
1191 *orig_field = value;
1192 } else {
1193 if (*orig_field)
1194 free (*orig_field); /* free previous string */
1195 *orig_field = gengetopt_strdup (value);
1196 }
1197 }
1198 };
1199
1200 return 0; /* OK */
1201}
1202
1203
1204int
1205cmdline_parser_internal (
1206 int argc, char **argv, struct gengetopt_args_info *args_info,
1207 struct cmdline_parser_params *params, const char *additional_error)
1208{
1209 int c; /* Character of the parsed option. */
1210
1211 int error_occurred = 0;
1212 struct gengetopt_args_info local_args_info;
1213
1214 int override;
1215 int initialize;
1216 int check_required;
1217 int check_ambiguity;
1218
1219 char *optarg;
1220 int optind;
1221 int opterr;
1222 int optopt;
1223
1224 package_name = argv[0];
1225
1226 /* TODO: Why is this here? It is not used anywhere. */
1227 override = params->override;
1228 FIX_UNUSED(override);
1229
1230 initialize = params->initialize;
1231 check_required = params->check_required;
1232
1233 /* TODO: Why is this here? It is not used anywhere. */
1234 check_ambiguity = params->check_ambiguity;
1235 FIX_UNUSED(check_ambiguity);
1236
1237 if (initialize)
1238 cmdline_parser_init (args_info);
1239
1240 cmdline_parser_init (&local_args_info);
1241
1242 optarg = 0;
1243 optind = 0;
1244 opterr = params->print_errors;
1245 optopt = '?';
1246
1247 while (1)
1248 {
1249 int option_index = 0;
1250
1251 static struct option long_options[] = {
1252 { "help", 0, NULL, 'h' },
1253 { "version", 0, NULL, 'V' },
1254 { "input", 1, NULL, 'i' },
1255 { "xyz", 1, NULL, 'x' },
1256 { "stl", 1, NULL, 0 },
1257 { "msms", 1, NULL, 0 },
1258 { "output", 1, NULL, 'o' },
1259 { "model", 1, NULL, 0 },
1260 { "beadSize", 1, NULL, 's' },
1261 { "elements", 0, NULL, 'e' },
1262 { "viscosity", 1, NULL, 'v' },
1263 { "temperature", 1, NULL, 't' },
1264 { 0, 0, 0, 0 }
1265 };
1266
1267 custom_optarg = optarg;
1268 custom_optind = optind;
1269 custom_opterr = opterr;
1270 custom_optopt = optopt;
1271
1272 c = custom_getopt_long (argc, argv, "hVi:x:o:s:ev:t:", long_options, &option_index);
1273
1274 optarg = custom_optarg;
1275 optind = custom_optind;
1276 opterr = custom_opterr;
1277 optopt = custom_optopt;
1278
1279 if (c == -1) break; /* Exit from `while (1)' loop. */
1280
1281 switch (c)
1282 {
1283 case 'h': /* Print help and exit. */
1284 cmdline_parser_print_help ();
1285 cmdline_parser_free (&local_args_info);
1286 exit (EXIT_SUCCESS);
1287
1288 case 'V': /* Print version and exit. */
1289 cmdline_parser_print_version ();
1290 cmdline_parser_free (&local_args_info);
1291 exit (EXIT_SUCCESS);
1292
1293 case 'i': /* input MetaData (omd) file. */
1294
1295 if (args_info->input_file_group_counter && override)
1296 reset_group_input_file (args_info);
1297 args_info->input_file_group_counter += 1;
1298
1299 if (update_arg( (void *)&(args_info->input_arg),
1300 &(args_info->input_orig), &(args_info->input_given),
1301 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1302 check_ambiguity, override, 0, 0,
1303 "input", 'i',
1304 additional_error))
1305 goto failure;
1306
1307 break;
1308 case 'x': /* xyz file for AtomicBead model. */
1309
1310 if (args_info->input_file_group_counter && override)
1311 reset_group_input_file (args_info);
1312 args_info->input_file_group_counter += 1;
1313
1314 if (update_arg( (void *)&(args_info->xyz_arg),
1315 &(args_info->xyz_orig), &(args_info->xyz_given),
1316 &(local_args_info.xyz_given), optarg, 0, 0, ARG_STRING,
1317 check_ambiguity, override, 0, 0,
1318 "xyz", 'x',
1319 additional_error))
1320 goto failure;
1321
1322 break;
1323 case 'o': /* output file prefix. */
1324
1325
1326 if (update_arg( (void *)&(args_info->output_arg),
1327 &(args_info->output_orig), &(args_info->output_given),
1328 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1329 check_ambiguity, override, 0, 0,
1330 "output", 'o',
1331 additional_error))
1332 goto failure;
1333
1334 break;
1335 case 's': /* bead size (diameter) for RoughShell model (in angstroms). */
1336
1337
1338 if (update_arg( (void *)&(args_info->beadSize_arg),
1339 &(args_info->beadSize_orig), &(args_info->beadSize_given),
1340 &(local_args_info.beadSize_given), optarg, 0, "0.2", ARG_DOUBLE,
1341 check_ambiguity, override, 0, 0,
1342 "beadSize", 's',
1343 additional_error))
1344 goto failure;
1345
1346 break;
1347 case 'e': /* output the hydrodynamic elements (beads or triangles) only, hydrodynamics calculation will not be performed. */
1348
1349
1350 if (update_arg((void *)&(args_info->elements_flag), 0, &(args_info->elements_given),
1351 &(local_args_info.elements_given), optarg, 0, 0, ARG_FLAG,
1352 check_ambiguity, override, 1, 0, "elements", 'e',
1353 additional_error))
1354 goto failure;
1355
1356 break;
1357 case 'v': /* viscosity (in poise). */
1358
1359
1360 if (update_arg( (void *)&(args_info->viscosity_arg),
1361 &(args_info->viscosity_orig), &(args_info->viscosity_given),
1362 &(local_args_info.viscosity_given), optarg, 0, "0.01", ARG_DOUBLE,
1363 check_ambiguity, override, 0, 0,
1364 "viscosity", 'v',
1365 additional_error))
1366 goto failure;
1367
1368 break;
1369 case 't': /* temperature (in Kelvin. */
1370
1371
1372 if (update_arg( (void *)&(args_info->temperature_arg),
1373 &(args_info->temperature_orig), &(args_info->temperature_given),
1374 &(local_args_info.temperature_given), optarg, 0, "300", ARG_DOUBLE,
1375 check_ambiguity, override, 0, 0,
1376 "temperature", 't',
1377 additional_error))
1378 goto failure;
1379
1380 break;
1381
1382 case 0: /* Long option with no short option */
1383 /* stl file for BoundaryElement model. */
1384 if (strcmp (long_options[option_index].name, "stl") == 0)
1385 {
1386
1387 if (args_info->input_file_group_counter && override)
1388 reset_group_input_file (args_info);
1389 args_info->input_file_group_counter += 1;
1390
1391 if (update_arg( (void *)&(args_info->stl_arg),
1392 &(args_info->stl_orig), &(args_info->stl_given),
1393 &(local_args_info.stl_given), optarg, 0, 0, ARG_STRING,
1394 check_ambiguity, override, 0, 0,
1395 "stl", '-',
1396 additional_error))
1397 goto failure;
1398
1399 }
1400 /* filename root for MSMS .vert and .face files. */
1401 else if (strcmp (long_options[option_index].name, "msms") == 0)
1402 {
1403
1404 if (args_info->input_file_group_counter && override)
1405 reset_group_input_file (args_info);
1406 args_info->input_file_group_counter += 1;
1407
1408 if (update_arg( (void *)&(args_info->msms_arg),
1409 &(args_info->msms_orig), &(args_info->msms_given),
1410 &(local_args_info.msms_given), optarg, 0, 0, ARG_STRING,
1411 check_ambiguity, override, 0, 0,
1412 "msms", '-',
1413 additional_error))
1414 goto failure;
1415
1416 }
1417 /* hydrodynamics model. */
1418 else if (strcmp (long_options[option_index].name, "model") == 0)
1419 {
1420
1421
1422 if (update_arg( (void *)&(args_info->model_arg),
1423 &(args_info->model_orig), &(args_info->model_given),
1424 &(local_args_info.model_given), optarg, cmdline_parser_model_values, 0, ARG_ENUM,
1425 check_ambiguity, override, 0, 0,
1426 "model", '-',
1427 additional_error))
1428 goto failure;
1429
1430 }
1431
1432 break;
1433 case '?': /* Invalid option. */
1434 /* `getopt_long' already printed an error message. */
1435 goto failure;
1436
1437 default: /* bug: option not considered. */
1438 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1439 abort ();
1440 } /* switch */
1441 } /* while */
1442
1443 if (args_info->input_file_group_counter > 1)
1444 {
1445 fprintf (stderr, "%s: %d options of group input file were given. One is required%s.\n", argv[0], args_info->input_file_group_counter, (additional_error ? additional_error : ""));
1446 error_occurred = 1;
1447 }
1448
1449
1450
1451 if (check_required)
1452 {
1453 error_occurred += cmdline_parser_required2 (args_info, argv[0], additional_error);
1454 }
1455
1456 cmdline_parser_release (&local_args_info);
1457
1458 if ( error_occurred )
1459 return (EXIT_FAILURE);
1460
1461 if (optind < argc)
1462 {
1463 int i = 0 ;
1464 int found_prog_name = 0;
1465 /* whether program name, i.e., argv[0], is in the remaining args
1466 (this may happen with some implementations of getopt,
1467 but surely not with the one included by gengetopt) */
1468
1469
1470 args_info->inputs_num = argc - optind - found_prog_name;
1471 args_info->inputs =
1472 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1473 while (optind < argc)
1474 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1475 }
1476
1477 return 0;
1478
1479failure:
1480
1481 cmdline_parser_release (&local_args_info);
1482 return (EXIT_FAILURE);
1483}
1484/* vim: set ft=c noet ts=8 sts=8 sw=8 tw=80 nojs spell : */
#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.
double viscosity_arg
viscosity (in poise) (default='0.01').
Definition HydroCmd.hpp:67
unsigned int output_given
Whether output was given.
char * beadSize_orig
bead size (diameter) for RoughShell model (in angstroms) original value given at command line.
Definition HydroCmd.hpp:63
char * output_orig
output file name original value given at command line.
const char * output_help
output file name help description.
char * temperature_orig
temperature (in Kelvin original value given at command line.
Definition HydroCmd.hpp:71
enum enum_model model_arg
hydrodynamics model.
Definition HydroCmd.hpp:59
unsigned int msms_given
Whether msms was given.
Definition HydroCmd.hpp:79
unsigned int xyz_given
Whether xyz was given.
Definition HydroCmd.hpp:77
unsigned inputs_num
unamed options number
double beadSize_arg
bead size (diameter) for RoughShell model (in angstroms) (default='0.2').
Definition HydroCmd.hpp:62
const char * xyz_help
xyz file for AtomicBead model help description.
Definition HydroCmd.hpp:49
const char * stl_help
stl file for BoundaryElement model help description.
Definition HydroCmd.hpp:52
const char * help_help
Print help and exit help description.
int input_file_group_counter
Counter for group input_file.
Definition HydroCmd.hpp:89
const char * model_help
hydrodynamics model help description.
Definition HydroCmd.hpp:61
char * output_arg
output file name.
char ** inputs
unamed options (options without names)
const char * temperature_help
temperature (in Kelvin help description.
Definition HydroCmd.hpp:72
char * input_arg
input dump file.
unsigned int beadSize_given
Whether beadSize was given.
Definition HydroCmd.hpp:82
char * msms_orig
filename root for MSMS .vert and .face files original value given at command line.
Definition HydroCmd.hpp:54
char * xyz_orig
xyz file for AtomicBead model original value given at command line.
Definition HydroCmd.hpp:48
const char * elements_help
output the hydrodynamic elements (beads or triangles) only, hydrodynamics calculation will not be per...
Definition HydroCmd.hpp:66
double temperature_arg
temperature (in Kelvin (default='300').
Definition HydroCmd.hpp:70
const char * beadSize_help
bead size (diameter) for RoughShell model (in angstroms) help description.
Definition HydroCmd.hpp:64
unsigned int elements_given
Whether elements was given.
Definition HydroCmd.hpp:83
const char * viscosity_help
viscosity (in poise) help description.
Definition HydroCmd.hpp:69
char * stl_orig
stl file for BoundaryElement model original value given at command line.
Definition HydroCmd.hpp:51
unsigned int temperature_given
Whether temperature was given.
Definition HydroCmd.hpp:85
unsigned int stl_given
Whether stl was given.
Definition HydroCmd.hpp:78
unsigned int help_given
Whether help was given.
char * xyz_arg
xyz file for AtomicBead model.
Definition HydroCmd.hpp:47
int elements_flag
output the hydrodynamic elements (beads or triangles) only, hydrodynamics calculation will not be per...
Definition HydroCmd.hpp:65
unsigned int input_given
Whether input was given.
char * model_orig
hydrodynamics model original value given at command line.
Definition HydroCmd.hpp:60
unsigned int version_given
Whether version was given.
char * viscosity_orig
viscosity (in poise) original value given at command line.
Definition HydroCmd.hpp:68
unsigned int viscosity_given
Whether viscosity was given.
Definition HydroCmd.hpp:84
const char * version_help
Print version and exit help description.
char * input_orig
input dump file original value given at command line.
char * stl_arg
stl file for BoundaryElement model.
Definition HydroCmd.hpp:50
const char * input_help
input dump file help description.
unsigned int model_given
Whether model was given.
Definition HydroCmd.hpp:81
char * msms_arg
filename root for MSMS .vert and .face files.
Definition HydroCmd.hpp:53
const char * msms_help
filename root for MSMS .vert and .face files help description.
Definition HydroCmd.hpp:55
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.