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