2 File autogenerated by gengetopt version 2.22.5
3 generated with the following command:
4 gengetopt -i RNAeval.ggo --file-name=RNAeval_cmdl --include-getopt --default-optional --func-name=RNAeval_cmdline_parser --arg-struct-name=RNAeval_args_info
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.
11 /* If we use autoconf. */
21 #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
25 #include "RNAeval_cmdl.h"
27 const char *RNAeval_args_info_purpose = "calculate energy of RNA sequences with given secondary structure";
29 const char *RNAeval_args_info_usage = "Usage: RNAeval [OPTIONS]...";
31 const char *RNAeval_args_info_description = "Evaluates the free energy of an RNA molecule in fixed secondary structure. \nSequences and structures are read alternately from stdin. The energy in \nKcal/Mol is written to stdout.\nThe program will continue to read new sequences and structures until a line \nconsisting of the single character \"@\" or an end of file condition is \nencountered.\nIf the input sequence or structure contains the separator character \"&\" the \nprogram calculates the energy of the co-folding of two RNA strands, where the \n\"&\" marks the boundary between the two strands.\n";
33 const char *RNAeval_args_info_detailed_help[] = {
34 " -h, --help Print help and exit",
35 " --detailed-help Print help, including all details and hidden \n options, and exit",
36 " -V, --version Print version and exit",
38 " Below are command line options which alter the general behavior of this \n program\n",
39 " --noconv Do not automatically substitude nucleotide \"T\" \n with \"U\"\n\n (default=off)",
40 " -v, --verbose Print out energy contribution of each loop in the \n structure.\n\n (default=off)",
42 " -T, --temp=DOUBLE Rescale energy parameters to a temperature of temp \n C. Default is 37C.\n\n",
43 " -4, --noTetra Do not include special tabulated stabilizing \n energies for tri-, tetra- and hexaloop hairpins. \n Mostly for testing.\n\n (default=off)",
44 " -d, --dangles=INT How to treat \"dangling end\" energies for bases \n adjacent to helices in free ends and multi-loops\n (default=`2')",
45 " \n With -d1 only unpaired bases can participate in at most one dangling end, \n this unsupported for the partition function folding.\n\n With -d2 this check is ignored, dangling energies will be added for the bases \n adjacent to a helix on both sides in any case; this is the default for \n partition function folding (-p).\n The option -d0 ignores dangling ends altogether (mostly for debugging).\n With -d3 mfe folding will allow coaxial stacking of adjacent helices in \n multi-loops. At the moment the implementation will not allow coaxial stacking \n of the two interior pairs in a loop of degree 3.\n",
46 " -e, --energyModel=INT Rarely used option to fold sequences from the \n artificial ABCD... alphabet, where A pairs B, \n C-D etc. Use the energy parameters for GC (-e \n 1) or AU (-e 2) pairs.\n\n",
47 " -P, --paramFile=paramfile Read energy parameters from paramfile, instead of \n using the default parameter set.\n",
48 " A sample parameter file should accompany your distribution.\n See the RNAlib documentation for details on the file format.\n\n",
49 " -c, --circ Assume a circular (instead of linear) RNA \n molecule.\n\n (default=off)",
50 " -g, --gquad Incoorporate G-Quadruplex formation into the \n structure prediction algorithm\n (default=off)",
51 " --logML Recalculate energies of structures using a \n logarithmic energy function for multi-loops \n before output.\n (default=off)",
52 " This option does not effect structure generation, only the energies that are \n printed out. Since logML lowers energies somewhat, some structures may be \n missing.\n\n",
53 "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
60 RNAeval_args_info_help[0] = RNAeval_args_info_detailed_help[0];
61 RNAeval_args_info_help[1] = RNAeval_args_info_detailed_help[1];
62 RNAeval_args_info_help[2] = RNAeval_args_info_detailed_help[2];
63 RNAeval_args_info_help[3] = RNAeval_args_info_detailed_help[3];
64 RNAeval_args_info_help[4] = RNAeval_args_info_detailed_help[4];
65 RNAeval_args_info_help[5] = RNAeval_args_info_detailed_help[5];
66 RNAeval_args_info_help[6] = RNAeval_args_info_detailed_help[6];
67 RNAeval_args_info_help[7] = RNAeval_args_info_detailed_help[7];
68 RNAeval_args_info_help[8] = RNAeval_args_info_detailed_help[8];
69 RNAeval_args_info_help[9] = RNAeval_args_info_detailed_help[9];
70 RNAeval_args_info_help[10] = RNAeval_args_info_detailed_help[10];
71 RNAeval_args_info_help[11] = RNAeval_args_info_detailed_help[12];
72 RNAeval_args_info_help[12] = RNAeval_args_info_detailed_help[13];
73 RNAeval_args_info_help[13] = RNAeval_args_info_detailed_help[15];
74 RNAeval_args_info_help[14] = RNAeval_args_info_detailed_help[16];
75 RNAeval_args_info_help[15] = RNAeval_args_info_detailed_help[17];
76 RNAeval_args_info_help[16] = RNAeval_args_info_detailed_help[19];
77 RNAeval_args_info_help[17] = 0;
81 const char *RNAeval_args_info_help[18];
88 } RNAeval_cmdline_parser_arg_type;
91 void clear_given (struct RNAeval_args_info *args_info);
93 void clear_args (struct RNAeval_args_info *args_info);
96 RNAeval_cmdline_parser_internal (int argc, char **argv, struct RNAeval_args_info *args_info,
97 struct RNAeval_cmdline_parser_params *params, const char *additional_error);
101 gengetopt_strdup (const char *s);
104 void clear_given (struct RNAeval_args_info *args_info)
106 args_info->help_given = 0 ;
107 args_info->detailed_help_given = 0 ;
108 args_info->version_given = 0 ;
109 args_info->noconv_given = 0 ;
110 args_info->verbose_given = 0 ;
111 args_info->temp_given = 0 ;
112 args_info->noTetra_given = 0 ;
113 args_info->dangles_given = 0 ;
114 args_info->energyModel_given = 0 ;
115 args_info->paramFile_given = 0 ;
116 args_info->circ_given = 0 ;
117 args_info->gquad_given = 0 ;
118 args_info->logML_given = 0 ;
122 void clear_args (struct RNAeval_args_info *args_info)
124 FIX_UNUSED (args_info);
125 args_info->noconv_flag = 0;
126 args_info->verbose_flag = 0;
127 args_info->temp_orig = NULL;
128 args_info->noTetra_flag = 0;
129 args_info->dangles_arg = 2;
130 args_info->dangles_orig = NULL;
131 args_info->energyModel_orig = NULL;
132 args_info->paramFile_arg = NULL;
133 args_info->paramFile_orig = NULL;
134 args_info->circ_flag = 0;
135 args_info->gquad_flag = 0;
136 args_info->logML_flag = 0;
141 void init_args_info(struct RNAeval_args_info *args_info)
145 args_info->help_help = RNAeval_args_info_detailed_help[0] ;
146 args_info->detailed_help_help = RNAeval_args_info_detailed_help[1] ;
147 args_info->version_help = RNAeval_args_info_detailed_help[2] ;
148 args_info->noconv_help = RNAeval_args_info_detailed_help[5] ;
149 args_info->verbose_help = RNAeval_args_info_detailed_help[6] ;
150 args_info->temp_help = RNAeval_args_info_detailed_help[8] ;
151 args_info->noTetra_help = RNAeval_args_info_detailed_help[9] ;
152 args_info->dangles_help = RNAeval_args_info_detailed_help[10] ;
153 args_info->energyModel_help = RNAeval_args_info_detailed_help[12] ;
154 args_info->paramFile_help = RNAeval_args_info_detailed_help[13] ;
155 args_info->circ_help = RNAeval_args_info_detailed_help[15] ;
156 args_info->gquad_help = RNAeval_args_info_detailed_help[16] ;
157 args_info->logML_help = RNAeval_args_info_detailed_help[17] ;
162 RNAeval_cmdline_parser_print_version (void)
165 (strlen(RNAEVAL_CMDLINE_PARSER_PACKAGE_NAME) ? RNAEVAL_CMDLINE_PARSER_PACKAGE_NAME : RNAEVAL_CMDLINE_PARSER_PACKAGE),
166 RNAEVAL_CMDLINE_PARSER_VERSION);
169 static void print_help_common(void) {
170 RNAeval_cmdline_parser_print_version ();
172 if (strlen(RNAeval_args_info_purpose) > 0)
173 printf("\n%s\n", RNAeval_args_info_purpose);
175 if (strlen(RNAeval_args_info_usage) > 0)
176 printf("\n%s\n", RNAeval_args_info_usage);
180 if (strlen(RNAeval_args_info_description) > 0)
181 printf("%s\n\n", RNAeval_args_info_description);
185 RNAeval_cmdline_parser_print_help (void)
189 while (RNAeval_args_info_help[i])
190 printf("%s\n", RNAeval_args_info_help[i++]);
194 RNAeval_cmdline_parser_print_detailed_help (void)
198 while (RNAeval_args_info_detailed_help[i])
199 printf("%s\n", RNAeval_args_info_detailed_help[i++]);
203 RNAeval_cmdline_parser_init (struct RNAeval_args_info *args_info)
205 clear_given (args_info);
206 clear_args (args_info);
207 init_args_info (args_info);
211 RNAeval_cmdline_parser_params_init(struct RNAeval_cmdline_parser_params *params)
215 params->override = 0;
216 params->initialize = 1;
217 params->check_required = 1;
218 params->check_ambiguity = 0;
219 params->print_errors = 1;
223 struct RNAeval_cmdline_parser_params *
224 RNAeval_cmdline_parser_params_create(void)
226 struct RNAeval_cmdline_parser_params *params =
227 (struct RNAeval_cmdline_parser_params *)malloc(sizeof(struct RNAeval_cmdline_parser_params));
228 RNAeval_cmdline_parser_params_init(params);
233 free_string_field (char **s)
244 RNAeval_cmdline_parser_release (struct RNAeval_args_info *args_info)
247 free_string_field (&(args_info->temp_orig));
248 free_string_field (&(args_info->dangles_orig));
249 free_string_field (&(args_info->energyModel_orig));
250 free_string_field (&(args_info->paramFile_arg));
251 free_string_field (&(args_info->paramFile_orig));
255 clear_given (args_info);
260 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
264 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
266 fprintf(outfile, "%s\n", opt);
272 RNAeval_cmdline_parser_dump(FILE *outfile, struct RNAeval_args_info *args_info)
278 fprintf (stderr, "%s: cannot dump options to stream\n", RNAEVAL_CMDLINE_PARSER_PACKAGE);
282 if (args_info->help_given)
283 write_into_file(outfile, "help", 0, 0 );
284 if (args_info->detailed_help_given)
285 write_into_file(outfile, "detailed-help", 0, 0 );
286 if (args_info->version_given)
287 write_into_file(outfile, "version", 0, 0 );
288 if (args_info->noconv_given)
289 write_into_file(outfile, "noconv", 0, 0 );
290 if (args_info->verbose_given)
291 write_into_file(outfile, "verbose", 0, 0 );
292 if (args_info->temp_given)
293 write_into_file(outfile, "temp", args_info->temp_orig, 0);
294 if (args_info->noTetra_given)
295 write_into_file(outfile, "noTetra", 0, 0 );
296 if (args_info->dangles_given)
297 write_into_file(outfile, "dangles", args_info->dangles_orig, 0);
298 if (args_info->energyModel_given)
299 write_into_file(outfile, "energyModel", args_info->energyModel_orig, 0);
300 if (args_info->paramFile_given)
301 write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
302 if (args_info->circ_given)
303 write_into_file(outfile, "circ", 0, 0 );
304 if (args_info->gquad_given)
305 write_into_file(outfile, "gquad", 0, 0 );
306 if (args_info->logML_given)
307 write_into_file(outfile, "logML", 0, 0 );
315 RNAeval_cmdline_parser_file_save(const char *filename, struct RNAeval_args_info *args_info)
320 outfile = fopen(filename, "w");
324 fprintf (stderr, "%s: cannot open file for writing: %s\n", RNAEVAL_CMDLINE_PARSER_PACKAGE, filename);
328 i = RNAeval_cmdline_parser_dump(outfile, args_info);
335 RNAeval_cmdline_parser_free (struct RNAeval_args_info *args_info)
337 RNAeval_cmdline_parser_release (args_info);
340 /** @brief replacement of strdup, which is not standard */
342 gengetopt_strdup (const char *s)
348 result = (char*)malloc(strlen(s) + 1);
349 if (result == (char*)0)
356 RNAeval_cmdline_parser (int argc, char **argv, struct RNAeval_args_info *args_info)
358 return RNAeval_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
362 RNAeval_cmdline_parser_ext (int argc, char **argv, struct RNAeval_args_info *args_info,
363 struct RNAeval_cmdline_parser_params *params)
366 result = RNAeval_cmdline_parser_internal (argc, argv, args_info, params, 0);
368 if (result == EXIT_FAILURE)
370 RNAeval_cmdline_parser_free (args_info);
378 RNAeval_cmdline_parser2 (int argc, char **argv, struct RNAeval_args_info *args_info, int override, int initialize, int check_required)
381 struct RNAeval_cmdline_parser_params params;
383 params.override = override;
384 params.initialize = initialize;
385 params.check_required = check_required;
386 params.check_ambiguity = 0;
387 params.print_errors = 1;
389 result = RNAeval_cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
391 if (result == EXIT_FAILURE)
393 RNAeval_cmdline_parser_free (args_info);
401 RNAeval_cmdline_parser_required (struct RNAeval_args_info *args_info, const char *prog_name)
403 FIX_UNUSED (args_info);
404 FIX_UNUSED (prog_name);
409 * Extracted from the glibc source tree, version 2.3.6
411 * Licensed under the GPL as per the whole glibc source tree.
413 * This file was modified so that getopt_long can be called
414 * many times without risking previous memory to be spoiled.
416 * Modified by Andre Noll and Lorenzo Bettini for use in
417 * GNU gengetopt generated files.
422 * we must include anything we need since this file is not thought to be
423 * inserted in a file already using getopt.h
431 /* has_arg can't be an enum because some compilers complain about
432 type mismatches in all the code that assumes it is an int. */
438 /* This version of `getopt' appears to the caller like standard Unix `getopt'
439 but it behaves differently for the user, since it allows the user
440 to intersperse the options with the other arguments.
442 As `getopt' works, it permutes the elements of ARGV so that,
443 when it is done, all the options precede everything else. Thus
444 all application programs are extended to handle flexible argument order.
447 If the field `flag' is not NULL, it points to a variable that is set
448 to the value given in the field `val' when the option is found, but
449 left unchanged if the option is not found.
451 To have a long-named option do something other than set an `int' to
452 a compiled-in constant, such as set a value from `custom_optarg', set the
453 option's `flag' field to zero and its `val' field to a nonzero
454 value (the equivalent single-letter option character, if there is
455 one). For long options that have a zero `flag' field, `getopt'
456 returns the contents of the `val' field. */
458 /* Names for the values of the `has_arg' field of `struct option'. */
460 #define no_argument 0
463 #ifndef required_argument
464 #define required_argument 1
467 #ifndef optional_argument
468 #define optional_argument 2
471 struct custom_getopt_data {
473 * These have exactly the same meaning as the corresponding global variables,
474 * except that they are used for the reentrant versions of getopt.
481 /* True if the internal members have been initialized. */
485 * The next char to be scanned in the option-element in which the last option
486 * character we returned was found. This allows us to pick up the scan where
487 * we left off. If this is zero, or a null string, it means resume the scan by
488 * advancing to the next ARGV-element.
493 * Describe the part of ARGV that contains non-options that have been skipped.
494 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
495 * the index after the last of them.
502 * the variables optarg, optind, opterr and optopt are renamed with
503 * the custom_ prefix so that they don't interfere with getopt ones.
505 * Moreover they're static so they are visible only from within the
506 * file where this very file will be included.
510 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
511 * option that takes an argument, the argument value is returned here.
513 static char *custom_optarg;
516 * Index in ARGV of the next element to be scanned. This is used for
517 * communication to and from the caller and for communication between
518 * successive calls to `custom_getopt'.
520 * On entry to `custom_getopt', 1 means this is the first call; initialize.
522 * When `custom_getopt' returns -1, this is the index of the first of the non-option
523 * elements that the caller should itself scan.
525 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
526 * has been scanned so far.
528 * 1003.2 says this must be 1 before any call.
530 static int custom_optind = 1;
533 * Callers store zero here to inhibit the error message for unrecognized
536 static int custom_opterr = 1;
539 * Set to an option character which was unrecognized. This must be initialized
540 * on some systems to avoid linking in the system's own getopt implementation.
542 static int custom_optopt = '?';
545 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
546 * [first_nonopt,last_nonopt) which contains all the non-options that have been
547 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
548 * all the options processed since those non-options were skipped.
549 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
550 * indices of the non-options in ARGV after they are moved.
552 static void exchange(char **argv, struct custom_getopt_data *d)
554 int bottom = d->first_nonopt;
555 int middle = d->last_nonopt;
556 int top = d->custom_optind;
560 * Exchange the shorter segment with the far end of the longer segment.
561 * That puts the shorter segment into the right place. It leaves the
562 * longer segment in the right place overall, but it consists of two
563 * parts that need to be swapped next.
565 while (top > middle && middle > bottom) {
566 if (top - middle > middle - bottom) {
567 /* Bottom segment is the short one. */
568 int len = middle - bottom;
571 /* Swap it with the top part of the top segment. */
572 for (i = 0; i < len; i++) {
573 tem = argv[bottom + i];
575 argv[top - (middle - bottom) + i];
576 argv[top - (middle - bottom) + i] = tem;
578 /* Exclude the moved bottom segment from further swapping. */
581 /* Top segment is the short one. */
582 int len = top - middle;
585 /* Swap it with the bottom part of the bottom segment. */
586 for (i = 0; i < len; i++) {
587 tem = argv[bottom + i];
588 argv[bottom + i] = argv[middle + i];
589 argv[middle + i] = tem;
591 /* Exclude the moved top segment from further swapping. */
595 /* Update records for the slots the non-options now occupy. */
596 d->first_nonopt += (d->custom_optind - d->last_nonopt);
597 d->last_nonopt = d->custom_optind;
600 /* Initialize the internal data when the first call is made. */
601 static void custom_getopt_initialize(struct custom_getopt_data *d)
604 * Start processing options with ARGV-element 1 (since ARGV-element 0
605 * is the program name); the sequence of previously skipped non-option
606 * ARGV-elements is empty.
608 d->first_nonopt = d->last_nonopt = d->custom_optind;
613 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
615 /* return: zero: continue, nonzero: return given value to user */
616 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
617 struct custom_getopt_data *d)
620 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
621 * moved back by the user (who may also have changed the arguments).
623 if (d->last_nonopt > d->custom_optind)
624 d->last_nonopt = d->custom_optind;
625 if (d->first_nonopt > d->custom_optind)
626 d->first_nonopt = d->custom_optind;
628 * If we have just processed some options following some
629 * non-options, exchange them so that the options come first.
631 if (d->first_nonopt != d->last_nonopt &&
632 d->last_nonopt != d->custom_optind)
633 exchange((char **) argv, d);
634 else if (d->last_nonopt != d->custom_optind)
635 d->first_nonopt = d->custom_optind;
637 * Skip any additional non-options and extend the range of
638 * non-options previously skipped.
640 while (d->custom_optind < argc && NONOPTION_P)
642 d->last_nonopt = d->custom_optind;
644 * The special ARGV-element `--' means premature end of options. Skip
645 * it like a null option, then exchange with previous non-options as if
646 * it were an option, then skip everything else like a non-option.
648 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
650 if (d->first_nonopt != d->last_nonopt
651 && d->last_nonopt != d->custom_optind)
652 exchange((char **) argv, d);
653 else if (d->first_nonopt == d->last_nonopt)
654 d->first_nonopt = d->custom_optind;
655 d->last_nonopt = argc;
656 d->custom_optind = argc;
659 * If we have done all the ARGV-elements, stop the scan and back over
660 * any non-options that we skipped and permuted.
662 if (d->custom_optind == argc) {
664 * Set the next-arg-index to point at the non-options that we
665 * previously skipped, so the caller will digest them.
667 if (d->first_nonopt != d->last_nonopt)
668 d->custom_optind = d->first_nonopt;
672 * If we have come to a non-option and did not permute it, either stop
673 * the scan or describe it to the caller and pass it by.
676 d->custom_optarg = argv[d->custom_optind++];
680 * We have found another option-ARGV-element. Skip the initial
683 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
688 * Check whether the ARGV-element is a long option.
690 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
691 * that an abbreviation of the long option, just like "--fu", and not "-f" with
694 * This distinction seems to be the most useful approach.
697 static int check_long_opt(int argc, char *const *argv, const char *optstring,
698 const struct option *longopts, int *longind,
699 int print_errors, struct custom_getopt_data *d)
702 const struct option *p;
703 const struct option *pfound = NULL;
709 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
712 /* Test all long options for either exact match or abbreviated matches */
713 for (p = longopts, option_index = 0; p->name; p++, option_index++)
714 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
715 if ((unsigned int) (nameend - d->nextchar)
716 == (unsigned int) strlen(p->name)) {
717 /* Exact match found. */
719 indfound = option_index;
722 } else if (pfound == NULL) {
723 /* First nonexact match found. */
725 indfound = option_index;
726 } else if (pfound->has_arg != p->has_arg
727 || pfound->flag != p->flag
728 || pfound->val != p->val)
729 /* Second or later nonexact match found. */
732 if (ambig && !exact) {
735 "%s: option `%s' is ambiguous\n",
736 argv[0], argv[d->custom_optind]);
738 d->nextchar += strlen(d->nextchar);
740 d->custom_optopt = 0;
744 option_index = indfound;
747 if (pfound->has_arg != no_argument)
748 d->custom_optarg = nameend + 1;
751 if (argv[d->custom_optind - 1][1] == '-') {
753 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
754 argv[0], pfound->name);
756 /* +option or -option */
757 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
758 argv[0], argv[d->custom_optind - 1][0], pfound->name);
762 d->nextchar += strlen(d->nextchar);
763 d->custom_optopt = pfound->val;
766 } else if (pfound->has_arg == required_argument) {
767 if (d->custom_optind < argc)
768 d->custom_optarg = argv[d->custom_optind++];
772 "%s: option `%s' requires an argument\n",
774 argv[d->custom_optind - 1]);
776 d->nextchar += strlen(d->nextchar);
777 d->custom_optopt = pfound->val;
778 return optstring[0] == ':' ? ':' : '?';
781 d->nextchar += strlen(d->nextchar);
783 *longind = option_index;
785 *(pfound->flag) = pfound->val;
791 * Can't find it as a long option. If this is not getopt_long_only, or
792 * the option starts with '--' or is not a valid short option, then
793 * it's an error. Otherwise interpret it as a short option.
796 if (argv[d->custom_optind][1] == '-') {
799 "%s: unrecognized option `--%s'\n",
800 argv[0], d->nextchar);
802 /* +option or -option */
804 "%s: unrecognized option `%c%s'\n",
805 argv[0], argv[d->custom_optind][0],
809 d->nextchar = (char *) "";
811 d->custom_optopt = 0;
815 static int check_short_opt(int argc, char *const *argv, const char *optstring,
816 int print_errors, struct custom_getopt_data *d)
818 char c = *d->nextchar++;
819 const char *temp = strchr(optstring, c);
821 /* Increment `custom_optind' when we start to process its last character. */
822 if (*d->nextchar == '\0')
824 if (!temp || c == ':') {
826 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
828 d->custom_optopt = c;
831 if (temp[1] == ':') {
832 if (temp[2] == ':') {
833 /* This is an option that accepts an argument optionally. */
834 if (*d->nextchar != '\0') {
835 d->custom_optarg = d->nextchar;
838 d->custom_optarg = NULL;
841 /* This is an option that requires an argument. */
842 if (*d->nextchar != '\0') {
843 d->custom_optarg = d->nextchar;
845 * If we end this ARGV-element by taking the
846 * rest as an arg, we must advance to the next
850 } else if (d->custom_optind == argc) {
853 "%s: option requires an argument -- %c\n",
856 d->custom_optopt = c;
857 if (optstring[0] == ':')
863 * We already incremented `custom_optind' once;
864 * increment it again when taking next ARGV-elt
867 d->custom_optarg = argv[d->custom_optind++];
875 * Scan elements of ARGV for option characters given in OPTSTRING.
877 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
878 * then it is an option element. The characters of this element
879 * (aside from the initial '-') are option characters. If `getopt'
880 * is called repeatedly, it returns successively each of the option characters
881 * from each of the option elements.
883 * If `getopt' finds another option character, it returns that character,
884 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
885 * resume the scan with the following option character or ARGV-element.
887 * If there are no more option characters, `getopt' returns -1.
888 * Then `custom_optind' is the index in ARGV of the first ARGV-element
889 * that is not an option. (The ARGV-elements have been permuted
890 * so that those that are not options now come last.)
892 * OPTSTRING is a string containing the legitimate option characters.
893 * If an option character is seen that is not listed in OPTSTRING,
894 * return '?' after printing an error message. If you set `custom_opterr' to
895 * zero, the error message is suppressed but we still return '?'.
897 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
898 * so the following text in the same ARGV-element, or the text of the following
899 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
900 * wants an optional arg; if there is text in the current ARGV-element,
901 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
903 * If OPTSTRING starts with `-' or `+', it requests different methods of
904 * handling the non-option ARGV-elements.
905 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
907 * Long-named options begin with `--' instead of `-'.
908 * Their names may be abbreviated as long as the abbreviation is unique
909 * or is an exact match for some defined option. If they have an
910 * argument, it follows the option name in the same ARGV-element, separated
911 * from the option name by a `=', or else the in next ARGV-element.
912 * When `getopt' finds a long-named option, it returns 0 if that option's
913 * `flag' field is nonzero, the value of the option's `val' field
914 * if the `flag' field is zero.
916 * The elements of ARGV aren't really const, because we permute them.
917 * But we pretend they're const in the prototype to be compatible
918 * with other systems.
920 * LONGOPTS is a vector of `struct option' terminated by an
921 * element containing a name which is zero.
923 * LONGIND returns the index in LONGOPT of the long-named option found.
924 * It is only valid when a long-named option has been found by the most
927 * Return the option character from OPTS just read. Return -1 when there are
928 * no more options. For unrecognized options, or options missing arguments,
929 * `custom_optopt' is set to the option letter, and '?' is returned.
931 * The OPTS string is a list of characters which are recognized option letters,
932 * optionally followed by colons, specifying that that letter takes an
933 * argument, to be placed in `custom_optarg'.
935 * If a letter in OPTS is followed by two colons, its argument is optional.
936 * This behavior is specific to the GNU `getopt'.
938 * The argument `--' causes premature termination of argument scanning,
939 * explicitly telling `getopt' that there are no more options. If OPTS begins
940 * with `--', then non-option arguments are treated as arguments to the option
941 * '\0'. This behavior is specific to the GNU `getopt'.
944 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
945 const struct option *longopts, int *longind,
946 struct custom_getopt_data *d)
948 int ret, print_errors = d->custom_opterr;
950 if (optstring[0] == ':')
954 d->custom_optarg = NULL;
957 * This is a big difference with GNU getopt, since optind == 0
958 * means initialization while here 1 means first call.
960 if (d->custom_optind == 0 || !d->initialized) {
961 if (d->custom_optind == 0)
962 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
963 custom_getopt_initialize(d);
965 if (d->nextchar == NULL || *d->nextchar == '\0') {
966 ret = shuffle_argv(argc, argv, longopts, d);
970 if (longopts && (argv[d->custom_optind][1] == '-' ))
971 return check_long_opt(argc, argv, optstring, longopts,
972 longind, print_errors, d);
973 return check_short_opt(argc, argv, optstring, print_errors, d);
976 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
977 const struct option *longopts, int *longind)
980 /* Keep a global copy of all internal members of d */
981 static struct custom_getopt_data d;
983 d.custom_optind = custom_optind;
984 d.custom_opterr = custom_opterr;
985 result = getopt_internal_r(argc, argv, optstring, longopts,
987 custom_optind = d.custom_optind;
988 custom_optarg = d.custom_optarg;
989 custom_optopt = d.custom_optopt;
993 static int custom_getopt_long (int argc, char *const *argv, const char *options,
994 const struct option *long_options, int *opt_index)
996 return custom_getopt_internal(argc, argv, options, long_options,
1001 static char *package_name = 0;
1004 * @brief updates an option
1005 * @param field the generic pointer to the field to update
1006 * @param orig_field the pointer to the orig field
1007 * @param field_given the pointer to the number of occurrence of this option
1008 * @param prev_given the pointer to the number of occurrence already seen
1009 * @param value the argument for this option (if null no arg was specified)
1010 * @param possible_values the possible values for this option (if specified)
1011 * @param default_value the default value (in case the option only accepts fixed values)
1012 * @param arg_type the type of this option
1013 * @param check_ambiguity @see RNAeval_cmdline_parser_params.check_ambiguity
1014 * @param override @see RNAeval_cmdline_parser_params.override
1015 * @param no_free whether to free a possible previous value
1016 * @param multiple_option whether this is a multiple option
1017 * @param long_opt the corresponding long option
1018 * @param short_opt the corresponding short option (or '-' if none)
1019 * @param additional_error possible further error specification
1022 int update_arg(void *field, char **orig_field,
1023 unsigned int *field_given, unsigned int *prev_given,
1024 char *value, const char *possible_values[],
1025 const char *default_value,
1026 RNAeval_cmdline_parser_arg_type arg_type,
1027 int check_ambiguity, int override,
1028 int no_free, int multiple_option,
1029 const char *long_opt, char short_opt,
1030 const char *additional_error)
1032 char *stop_char = 0;
1033 const char *val = value;
1035 char **string_field;
1041 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1043 if (short_opt != '-')
1044 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1045 package_name, long_opt, short_opt,
1046 (additional_error ? additional_error : ""));
1048 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1049 package_name, long_opt,
1050 (additional_error ? additional_error : ""));
1051 return 1; /* failure */
1054 FIX_UNUSED (default_value);
1056 if (field_given && *field_given && ! override)
1062 if (possible_values)
1063 val = possible_values[found];
1067 *((int *)field) = !*((int *)field);
1070 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1073 if (val) *((double *)field) = strtod (val, &stop_char);
1077 string_field = (char **)field;
1078 if (!no_free && *string_field)
1079 free (*string_field); /* free previous string */
1080 *string_field = gengetopt_strdup (val);
1087 /* check numeric conversion */
1091 if (val && !(stop_char && *stop_char == '\0')) {
1092 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1093 return 1; /* failure */
1100 /* store the original value */
1106 if (value && orig_field) {
1108 *orig_field = value;
1111 free (*orig_field); /* free previous string */
1112 *orig_field = gengetopt_strdup (value);
1122 RNAeval_cmdline_parser_internal (
1123 int argc, char **argv, struct RNAeval_args_info *args_info,
1124 struct RNAeval_cmdline_parser_params *params, const char *additional_error)
1126 int c; /* Character of the parsed option. */
1129 struct RNAeval_args_info local_args_info;
1134 int check_ambiguity;
1141 package_name = argv[0];
1143 override = params->override;
1144 initialize = params->initialize;
1145 check_required = params->check_required;
1146 check_ambiguity = params->check_ambiguity;
1149 RNAeval_cmdline_parser_init (args_info);
1151 RNAeval_cmdline_parser_init (&local_args_info);
1155 opterr = params->print_errors;
1160 int option_index = 0;
1162 static struct option long_options[] = {
1163 { "help", 0, NULL, 'h' },
1164 { "detailed-help", 0, NULL, 0 },
1165 { "version", 0, NULL, 'V' },
1166 { "noconv", 0, NULL, 0 },
1167 { "verbose", 0, NULL, 'v' },
1168 { "temp", 1, NULL, 'T' },
1169 { "noTetra", 0, NULL, '4' },
1170 { "dangles", 1, NULL, 'd' },
1171 { "energyModel", 1, NULL, 'e' },
1172 { "paramFile", 1, NULL, 'P' },
1173 { "circ", 0, NULL, 'c' },
1174 { "gquad", 0, NULL, 'g' },
1175 { "logML", 0, NULL, 0 },
1179 custom_optarg = optarg;
1180 custom_optind = optind;
1181 custom_opterr = opterr;
1182 custom_optopt = optopt;
1184 c = custom_getopt_long (argc, argv, "hVvT:4d:e:P:cg", long_options, &option_index);
1186 optarg = custom_optarg;
1187 optind = custom_optind;
1188 opterr = custom_opterr;
1189 optopt = custom_optopt;
1191 if (c == -1) break; /* Exit from `while (1)' loop. */
1195 case 'h': /* Print help and exit. */
1196 RNAeval_cmdline_parser_print_help ();
1197 RNAeval_cmdline_parser_free (&local_args_info);
1198 exit (EXIT_SUCCESS);
1200 case 'V': /* Print version and exit. */
1201 RNAeval_cmdline_parser_print_version ();
1202 RNAeval_cmdline_parser_free (&local_args_info);
1203 exit (EXIT_SUCCESS);
1205 case 'v': /* Print out energy contribution of each loop in the structure.
1210 if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
1211 &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
1212 check_ambiguity, override, 1, 0, "verbose", 'v',
1217 case 'T': /* Rescale energy parameters to a temperature of temp C. Default is 37C.
1222 if (update_arg( (void *)&(args_info->temp_arg),
1223 &(args_info->temp_orig), &(args_info->temp_given),
1224 &(local_args_info.temp_given), optarg, 0, 0, ARG_DOUBLE,
1225 check_ambiguity, override, 0, 0,
1231 case '4': /* Do not include special tabulated stabilizing energies for tri-, tetra- and hexaloop hairpins. Mostly for testing.
1236 if (update_arg((void *)&(args_info->noTetra_flag), 0, &(args_info->noTetra_given),
1237 &(local_args_info.noTetra_given), optarg, 0, 0, ARG_FLAG,
1238 check_ambiguity, override, 1, 0, "noTetra", '4',
1243 case 'd': /* How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops
1247 if (update_arg( (void *)&(args_info->dangles_arg),
1248 &(args_info->dangles_orig), &(args_info->dangles_given),
1249 &(local_args_info.dangles_given), optarg, 0, "2", ARG_INT,
1250 check_ambiguity, override, 0, 0,
1256 case 'e': /* Rarely used option to fold sequences from the artificial ABCD... alphabet, where A pairs B, C-D etc. Use the energy parameters for GC (-e 1) or AU (-e 2) pairs.
1261 if (update_arg( (void *)&(args_info->energyModel_arg),
1262 &(args_info->energyModel_orig), &(args_info->energyModel_given),
1263 &(local_args_info.energyModel_given), optarg, 0, 0, ARG_INT,
1264 check_ambiguity, override, 0, 0,
1270 case 'P': /* Read energy parameters from paramfile, instead of using the default parameter set.
1274 if (update_arg( (void *)&(args_info->paramFile_arg),
1275 &(args_info->paramFile_orig), &(args_info->paramFile_given),
1276 &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1277 check_ambiguity, override, 0, 0,
1283 case 'c': /* Assume a circular (instead of linear) RNA molecule.
1288 if (update_arg((void *)&(args_info->circ_flag), 0, &(args_info->circ_given),
1289 &(local_args_info.circ_given), optarg, 0, 0, ARG_FLAG,
1290 check_ambiguity, override, 1, 0, "circ", 'c',
1295 case 'g': /* Incoorporate G-Quadruplex formation into the structure prediction algorithm
1299 if (update_arg((void *)&(args_info->gquad_flag), 0, &(args_info->gquad_given),
1300 &(local_args_info.gquad_given), optarg, 0, 0, ARG_FLAG,
1301 check_ambiguity, override, 1, 0, "gquad", 'g',
1307 case 0: /* Long option with no short option */
1308 if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1309 RNAeval_cmdline_parser_print_detailed_help ();
1310 RNAeval_cmdline_parser_free (&local_args_info);
1311 exit (EXIT_SUCCESS);
1314 /* Do not automatically substitude nucleotide \"T\" with \"U\"
1317 if (strcmp (long_options[option_index].name, "noconv") == 0)
1321 if (update_arg((void *)&(args_info->noconv_flag), 0, &(args_info->noconv_given),
1322 &(local_args_info.noconv_given), optarg, 0, 0, ARG_FLAG,
1323 check_ambiguity, override, 1, 0, "noconv", '-',
1328 /* Recalculate energies of structures using a logarithmic energy function for multi-loops before output.
1330 else if (strcmp (long_options[option_index].name, "logML") == 0)
1334 if (update_arg((void *)&(args_info->logML_flag), 0, &(args_info->logML_given),
1335 &(local_args_info.logML_given), optarg, 0, 0, ARG_FLAG,
1336 check_ambiguity, override, 1, 0, "logML", '-',
1343 case '?': /* Invalid option. */
1344 /* `getopt_long' already printed an error message. */
1347 default: /* bug: option not considered. */
1348 fprintf (stderr, "%s: option unknown: %c%s\n", RNAEVAL_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1356 RNAeval_cmdline_parser_release (&local_args_info);
1359 return (EXIT_FAILURE);
1365 RNAeval_cmdline_parser_release (&local_args_info);
1366 return (EXIT_FAILURE);