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