2 File autogenerated by gengetopt version 2.22.5
3 generated with the following command:
4 gengetopt -i RNAduplex.ggo --file-name=RNAduplex_cmdl --include-getopt --default-optional --func-name=RNAduplex_cmdline_parser --arg-struct-name=RNAduplex_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 "RNAduplex_cmdl.h"
27 const char *RNAduplex_args_info_purpose = "Compute the structure upon hybridization of two RNA strands";
29 const char *RNAduplex_args_info_usage = "Usage: RNAduplex [OPTIONS]...";
31 const char *RNAduplex_args_info_description = "reads two RNA sequences from stdin or <filename> and computes optimal and \nsuboptimal secondary structures for their hybridization. The calculation is \nsimplified by allowing only inter-molecular base pairs, for the general case \nuse RNAcofold.\nThe computed optimal and suboptimal structure are written to stdout, one \nstructure per line. Each line consist of: The structure in dot bracket format \nwith a \"&\" separating the two strands. The range of the structure in the two \nsequences in the format \"from,to : from,to\"; the energy of duplex structure \nin kcal/mol.\nThe format is especially useful for computing the hybrid structure between a \nsmall probe sequence and a long target sequence.\n";
33 const char *RNAduplex_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 " --full-help Print help, including hidden options, and exit",
37 " -V, --version Print version and exit",
39 " Below are command line options which alter the general behavior of this \n program\n",
40 " -s, --sorted sort the printed output by free energy\n\n (default=off)",
41 " --noconv Do not automatically substitude nucleotide \"T\" \n with \"U\"\n\n (default=off)",
43 " Select additional algorithms which should be included in the calculations.\n",
44 " -e, --deltaEnergy=range Compute suboptimal structures with energy in a \n certain range of the optimum (kcal/mol). Default \n is calculation of mfe structure only.\n\n",
46 " -T, --temp=DOUBLE Rescale energy parameters to a temperature of temp \n C. Default is 37C.\n\n",
47 " -4, --noTetra Do not include special tabulated stabilizing \n energies for tri-, tetra- and hexaloop hairpins. \n Mostly for testing.\n\n (default=off)",
48 " -d, --dangles=INT How to treat \"dangling end\" energies for bases \n adjacent to helices in free ends and multi-loops\n (default=`2')",
49 " \n With -d1 only unpaired bases can participate in at most one dangling end, \n this is the default for mfe folding but unsupported for the partition \n 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 and works only for mfe \n folding.\n\n Note that by default (as well as with -d1 and -d3) pf and mfe folding treat \n dangling ends differently. Use -d2 in addition to -p to ensure that both \n algorithms use the same energy model.\n\n",
50 " --noLP Produce structures without lonely pairs (helices \n of length 1).\n (default=off)",
51 " For partition function folding this only disallows pairs that can only occur \n isolated. Other pairs may still occasionally occur as helices of length 1.\n\n",
52 " --noGU Do not allow GU pairs\n\n (default=off)",
53 " --noClosingGU Do not allow GU pairs at the end of helices\n\n (default=off)",
54 " -P, --paramFile=paramfile Read energy parameters from paramfile, instead of \n using the default parameter set.\n",
55 " A sample parameter file should accompany your distribution.\n See the RNAlib documentation for details on the file format.\n\n",
56 " --nsp=STRING Allow other pairs in addition to the usual \n AU,GC,and GU pairs.\n",
57 " Its argument is a comma separated list of additionally allowed pairs. If the \n first character is a \"-\" then AB will imply that AB and BA are allowed \n pairs.\n e.g. RNAfold -nsp -GA will allow GA and AG pairs. Nonstandard pairs are \n given 0 stacking energy.\n\n",
58 "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
62 init_full_help_array(void)
64 RNAduplex_args_info_full_help[0] = RNAduplex_args_info_detailed_help[0];
65 RNAduplex_args_info_full_help[1] = RNAduplex_args_info_detailed_help[1];
66 RNAduplex_args_info_full_help[2] = RNAduplex_args_info_detailed_help[2];
67 RNAduplex_args_info_full_help[3] = RNAduplex_args_info_detailed_help[3];
68 RNAduplex_args_info_full_help[4] = RNAduplex_args_info_detailed_help[4];
69 RNAduplex_args_info_full_help[5] = RNAduplex_args_info_detailed_help[5];
70 RNAduplex_args_info_full_help[6] = RNAduplex_args_info_detailed_help[6];
71 RNAduplex_args_info_full_help[7] = RNAduplex_args_info_detailed_help[7];
72 RNAduplex_args_info_full_help[8] = RNAduplex_args_info_detailed_help[8];
73 RNAduplex_args_info_full_help[9] = RNAduplex_args_info_detailed_help[9];
74 RNAduplex_args_info_full_help[10] = RNAduplex_args_info_detailed_help[10];
75 RNAduplex_args_info_full_help[11] = RNAduplex_args_info_detailed_help[11];
76 RNAduplex_args_info_full_help[12] = RNAduplex_args_info_detailed_help[12];
77 RNAduplex_args_info_full_help[13] = RNAduplex_args_info_detailed_help[13];
78 RNAduplex_args_info_full_help[14] = RNAduplex_args_info_detailed_help[14];
79 RNAduplex_args_info_full_help[15] = RNAduplex_args_info_detailed_help[16];
80 RNAduplex_args_info_full_help[16] = RNAduplex_args_info_detailed_help[18];
81 RNAduplex_args_info_full_help[17] = RNAduplex_args_info_detailed_help[19];
82 RNAduplex_args_info_full_help[18] = RNAduplex_args_info_detailed_help[20];
83 RNAduplex_args_info_full_help[19] = RNAduplex_args_info_detailed_help[22];
84 RNAduplex_args_info_full_help[20] = RNAduplex_args_info_detailed_help[24];
85 RNAduplex_args_info_full_help[21] = 0;
89 const char *RNAduplex_args_info_full_help[22];
94 RNAduplex_args_info_help[0] = RNAduplex_args_info_detailed_help[0];
95 RNAduplex_args_info_help[1] = RNAduplex_args_info_detailed_help[1];
96 RNAduplex_args_info_help[2] = RNAduplex_args_info_detailed_help[2];
97 RNAduplex_args_info_help[3] = RNAduplex_args_info_detailed_help[3];
98 RNAduplex_args_info_help[4] = RNAduplex_args_info_detailed_help[4];
99 RNAduplex_args_info_help[5] = RNAduplex_args_info_detailed_help[5];
100 RNAduplex_args_info_help[6] = RNAduplex_args_info_detailed_help[6];
101 RNAduplex_args_info_help[7] = RNAduplex_args_info_detailed_help[7];
102 RNAduplex_args_info_help[8] = RNAduplex_args_info_detailed_help[8];
103 RNAduplex_args_info_help[9] = RNAduplex_args_info_detailed_help[9];
104 RNAduplex_args_info_help[10] = RNAduplex_args_info_detailed_help[10];
105 RNAduplex_args_info_help[11] = RNAduplex_args_info_detailed_help[11];
106 RNAduplex_args_info_help[12] = RNAduplex_args_info_detailed_help[12];
107 RNAduplex_args_info_help[13] = RNAduplex_args_info_detailed_help[13];
108 RNAduplex_args_info_help[14] = RNAduplex_args_info_detailed_help[14];
109 RNAduplex_args_info_help[15] = RNAduplex_args_info_detailed_help[16];
110 RNAduplex_args_info_help[16] = RNAduplex_args_info_detailed_help[18];
111 RNAduplex_args_info_help[17] = RNAduplex_args_info_detailed_help[19];
112 RNAduplex_args_info_help[18] = RNAduplex_args_info_detailed_help[20];
113 RNAduplex_args_info_help[19] = RNAduplex_args_info_detailed_help[24];
114 RNAduplex_args_info_help[20] = 0;
118 const char *RNAduplex_args_info_help[21];
126 } RNAduplex_cmdline_parser_arg_type;
129 void clear_given (struct RNAduplex_args_info *args_info);
131 void clear_args (struct RNAduplex_args_info *args_info);
134 RNAduplex_cmdline_parser_internal (int argc, char **argv, struct RNAduplex_args_info *args_info,
135 struct RNAduplex_cmdline_parser_params *params, const char *additional_error);
139 gengetopt_strdup (const char *s);
142 void clear_given (struct RNAduplex_args_info *args_info)
144 args_info->help_given = 0 ;
145 args_info->detailed_help_given = 0 ;
146 args_info->full_help_given = 0 ;
147 args_info->version_given = 0 ;
148 args_info->sorted_given = 0 ;
149 args_info->noconv_given = 0 ;
150 args_info->deltaEnergy_given = 0 ;
151 args_info->temp_given = 0 ;
152 args_info->noTetra_given = 0 ;
153 args_info->dangles_given = 0 ;
154 args_info->noLP_given = 0 ;
155 args_info->noGU_given = 0 ;
156 args_info->noClosingGU_given = 0 ;
157 args_info->paramFile_given = 0 ;
158 args_info->nsp_given = 0 ;
162 void clear_args (struct RNAduplex_args_info *args_info)
164 FIX_UNUSED (args_info);
165 args_info->sorted_flag = 0;
166 args_info->noconv_flag = 0;
167 args_info->deltaEnergy_orig = NULL;
168 args_info->temp_orig = NULL;
169 args_info->noTetra_flag = 0;
170 args_info->dangles_arg = 2;
171 args_info->dangles_orig = NULL;
172 args_info->noLP_flag = 0;
173 args_info->noGU_flag = 0;
174 args_info->noClosingGU_flag = 0;
175 args_info->paramFile_arg = NULL;
176 args_info->paramFile_orig = NULL;
177 args_info->nsp_arg = NULL;
178 args_info->nsp_orig = NULL;
183 void init_args_info(struct RNAduplex_args_info *args_info)
185 init_full_help_array();
187 args_info->help_help = RNAduplex_args_info_detailed_help[0] ;
188 args_info->detailed_help_help = RNAduplex_args_info_detailed_help[1] ;
189 args_info->full_help_help = RNAduplex_args_info_detailed_help[2] ;
190 args_info->version_help = RNAduplex_args_info_detailed_help[3] ;
191 args_info->sorted_help = RNAduplex_args_info_detailed_help[6] ;
192 args_info->noconv_help = RNAduplex_args_info_detailed_help[7] ;
193 args_info->deltaEnergy_help = RNAduplex_args_info_detailed_help[10] ;
194 args_info->temp_help = RNAduplex_args_info_detailed_help[12] ;
195 args_info->noTetra_help = RNAduplex_args_info_detailed_help[13] ;
196 args_info->dangles_help = RNAduplex_args_info_detailed_help[14] ;
197 args_info->noLP_help = RNAduplex_args_info_detailed_help[16] ;
198 args_info->noGU_help = RNAduplex_args_info_detailed_help[18] ;
199 args_info->noClosingGU_help = RNAduplex_args_info_detailed_help[19] ;
200 args_info->paramFile_help = RNAduplex_args_info_detailed_help[20] ;
201 args_info->nsp_help = RNAduplex_args_info_detailed_help[22] ;
206 RNAduplex_cmdline_parser_print_version (void)
209 (strlen(RNADUPLEX_CMDLINE_PARSER_PACKAGE_NAME) ? RNADUPLEX_CMDLINE_PARSER_PACKAGE_NAME : RNADUPLEX_CMDLINE_PARSER_PACKAGE),
210 RNADUPLEX_CMDLINE_PARSER_VERSION);
213 static void print_help_common(void) {
214 RNAduplex_cmdline_parser_print_version ();
216 if (strlen(RNAduplex_args_info_purpose) > 0)
217 printf("\n%s\n", RNAduplex_args_info_purpose);
219 if (strlen(RNAduplex_args_info_usage) > 0)
220 printf("\n%s\n", RNAduplex_args_info_usage);
224 if (strlen(RNAduplex_args_info_description) > 0)
225 printf("%s\n\n", RNAduplex_args_info_description);
229 RNAduplex_cmdline_parser_print_help (void)
233 while (RNAduplex_args_info_help[i])
234 printf("%s\n", RNAduplex_args_info_help[i++]);
238 RNAduplex_cmdline_parser_print_full_help (void)
242 while (RNAduplex_args_info_full_help[i])
243 printf("%s\n", RNAduplex_args_info_full_help[i++]);
247 RNAduplex_cmdline_parser_print_detailed_help (void)
251 while (RNAduplex_args_info_detailed_help[i])
252 printf("%s\n", RNAduplex_args_info_detailed_help[i++]);
256 RNAduplex_cmdline_parser_init (struct RNAduplex_args_info *args_info)
258 clear_given (args_info);
259 clear_args (args_info);
260 init_args_info (args_info);
264 RNAduplex_cmdline_parser_params_init(struct RNAduplex_cmdline_parser_params *params)
268 params->override = 0;
269 params->initialize = 1;
270 params->check_required = 1;
271 params->check_ambiguity = 0;
272 params->print_errors = 1;
276 struct RNAduplex_cmdline_parser_params *
277 RNAduplex_cmdline_parser_params_create(void)
279 struct RNAduplex_cmdline_parser_params *params =
280 (struct RNAduplex_cmdline_parser_params *)malloc(sizeof(struct RNAduplex_cmdline_parser_params));
281 RNAduplex_cmdline_parser_params_init(params);
286 free_string_field (char **s)
297 RNAduplex_cmdline_parser_release (struct RNAduplex_args_info *args_info)
300 free_string_field (&(args_info->deltaEnergy_orig));
301 free_string_field (&(args_info->temp_orig));
302 free_string_field (&(args_info->dangles_orig));
303 free_string_field (&(args_info->paramFile_arg));
304 free_string_field (&(args_info->paramFile_orig));
305 free_string_field (&(args_info->nsp_arg));
306 free_string_field (&(args_info->nsp_orig));
310 clear_given (args_info);
315 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
319 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
321 fprintf(outfile, "%s\n", opt);
327 RNAduplex_cmdline_parser_dump(FILE *outfile, struct RNAduplex_args_info *args_info)
333 fprintf (stderr, "%s: cannot dump options to stream\n", RNADUPLEX_CMDLINE_PARSER_PACKAGE);
337 if (args_info->help_given)
338 write_into_file(outfile, "help", 0, 0 );
339 if (args_info->detailed_help_given)
340 write_into_file(outfile, "detailed-help", 0, 0 );
341 if (args_info->full_help_given)
342 write_into_file(outfile, "full-help", 0, 0 );
343 if (args_info->version_given)
344 write_into_file(outfile, "version", 0, 0 );
345 if (args_info->sorted_given)
346 write_into_file(outfile, "sorted", 0, 0 );
347 if (args_info->noconv_given)
348 write_into_file(outfile, "noconv", 0, 0 );
349 if (args_info->deltaEnergy_given)
350 write_into_file(outfile, "deltaEnergy", args_info->deltaEnergy_orig, 0);
351 if (args_info->temp_given)
352 write_into_file(outfile, "temp", args_info->temp_orig, 0);
353 if (args_info->noTetra_given)
354 write_into_file(outfile, "noTetra", 0, 0 );
355 if (args_info->dangles_given)
356 write_into_file(outfile, "dangles", args_info->dangles_orig, 0);
357 if (args_info->noLP_given)
358 write_into_file(outfile, "noLP", 0, 0 );
359 if (args_info->noGU_given)
360 write_into_file(outfile, "noGU", 0, 0 );
361 if (args_info->noClosingGU_given)
362 write_into_file(outfile, "noClosingGU", 0, 0 );
363 if (args_info->paramFile_given)
364 write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
365 if (args_info->nsp_given)
366 write_into_file(outfile, "nsp", args_info->nsp_orig, 0);
374 RNAduplex_cmdline_parser_file_save(const char *filename, struct RNAduplex_args_info *args_info)
379 outfile = fopen(filename, "w");
383 fprintf (stderr, "%s: cannot open file for writing: %s\n", RNADUPLEX_CMDLINE_PARSER_PACKAGE, filename);
387 i = RNAduplex_cmdline_parser_dump(outfile, args_info);
394 RNAduplex_cmdline_parser_free (struct RNAduplex_args_info *args_info)
396 RNAduplex_cmdline_parser_release (args_info);
399 /** @brief replacement of strdup, which is not standard */
401 gengetopt_strdup (const char *s)
407 result = (char*)malloc(strlen(s) + 1);
408 if (result == (char*)0)
415 RNAduplex_cmdline_parser (int argc, char **argv, struct RNAduplex_args_info *args_info)
417 return RNAduplex_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
421 RNAduplex_cmdline_parser_ext (int argc, char **argv, struct RNAduplex_args_info *args_info,
422 struct RNAduplex_cmdline_parser_params *params)
425 result = RNAduplex_cmdline_parser_internal (argc, argv, args_info, params, 0);
427 if (result == EXIT_FAILURE)
429 RNAduplex_cmdline_parser_free (args_info);
437 RNAduplex_cmdline_parser2 (int argc, char **argv, struct RNAduplex_args_info *args_info, int override, int initialize, int check_required)
440 struct RNAduplex_cmdline_parser_params params;
442 params.override = override;
443 params.initialize = initialize;
444 params.check_required = check_required;
445 params.check_ambiguity = 0;
446 params.print_errors = 1;
448 result = RNAduplex_cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
450 if (result == EXIT_FAILURE)
452 RNAduplex_cmdline_parser_free (args_info);
460 RNAduplex_cmdline_parser_required (struct RNAduplex_args_info *args_info, const char *prog_name)
462 FIX_UNUSED (args_info);
463 FIX_UNUSED (prog_name);
468 * Extracted from the glibc source tree, version 2.3.6
470 * Licensed under the GPL as per the whole glibc source tree.
472 * This file was modified so that getopt_long can be called
473 * many times without risking previous memory to be spoiled.
475 * Modified by Andre Noll and Lorenzo Bettini for use in
476 * GNU gengetopt generated files.
481 * we must include anything we need since this file is not thought to be
482 * inserted in a file already using getopt.h
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. */
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.
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.
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.
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. */
517 /* Names for the values of the `has_arg' field of `struct option'. */
519 #define no_argument 0
522 #ifndef required_argument
523 #define required_argument 1
526 #ifndef optional_argument
527 #define optional_argument 2
530 struct custom_getopt_data {
532 * These have exactly the same meaning as the corresponding global variables,
533 * except that they are used for the reentrant versions of getopt.
540 /* True if the internal members have been initialized. */
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.
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.
561 * the variables optarg, optind, opterr and optopt are renamed with
562 * the custom_ prefix so that they don't interfere with getopt ones.
564 * Moreover they're static so they are visible only from within the
565 * file where this very file will be included.
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.
572 static char *custom_optarg;
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'.
579 * On entry to `custom_getopt', 1 means this is the first call; initialize.
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.
584 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
585 * has been scanned so far.
587 * 1003.2 says this must be 1 before any call.
589 static int custom_optind = 1;
592 * Callers store zero here to inhibit the error message for unrecognized
595 static int custom_opterr = 1;
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.
601 static int custom_optopt = '?';
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.
611 static void exchange(char **argv, struct custom_getopt_data *d)
613 int bottom = d->first_nonopt;
614 int middle = d->last_nonopt;
615 int top = d->custom_optind;
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.
624 while (top > middle && middle > bottom) {
625 if (top - middle > middle - bottom) {
626 /* Bottom segment is the short one. */
627 int len = middle - bottom;
630 /* Swap it with the top part of the top segment. */
631 for (i = 0; i < len; i++) {
632 tem = argv[bottom + i];
634 argv[top - (middle - bottom) + i];
635 argv[top - (middle - bottom) + i] = tem;
637 /* Exclude the moved bottom segment from further swapping. */
640 /* Top segment is the short one. */
641 int len = top - middle;
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;
650 /* Exclude the moved top segment from further swapping. */
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;
659 /* Initialize the internal data when the first call is made. */
660 static void custom_getopt_initialize(struct custom_getopt_data *d)
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.
667 d->first_nonopt = d->last_nonopt = d->custom_optind;
672 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
674 /* return: zero: continue, nonzero: return given value to user */
675 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
676 struct custom_getopt_data *d)
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).
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;
687 * If we have just processed some options following some
688 * non-options, exchange them so that the options come first.
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;
696 * Skip any additional non-options and extend the range of
697 * non-options previously skipped.
699 while (d->custom_optind < argc && NONOPTION_P)
701 d->last_nonopt = d->custom_optind;
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.
707 if (d->custom_optind != argc && !strcmp(argv[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;
718 * If we have done all the ARGV-elements, stop the scan and back over
719 * any non-options that we skipped and permuted.
721 if (d->custom_optind == argc) {
723 * Set the next-arg-index to point at the non-options that we
724 * previously skipped, so the caller will digest them.
726 if (d->first_nonopt != d->last_nonopt)
727 d->custom_optind = d->first_nonopt;
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.
735 d->custom_optarg = argv[d->custom_optind++];
739 * We have found another option-ARGV-element. Skip the initial
742 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
747 * Check whether the ARGV-element is a long option.
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
753 * This distinction seems to be the most useful approach.
756 static 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)
761 const struct option *p;
762 const struct option *pfound = NULL;
768 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
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. */
778 indfound = option_index;
781 } else if (pfound == NULL) {
782 /* First nonexact match found. */
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. */
791 if (ambig && !exact) {
794 "%s: option `%s' is ambiguous\n",
795 argv[0], argv[d->custom_optind]);
797 d->nextchar += strlen(d->nextchar);
799 d->custom_optopt = 0;
803 option_index = indfound;
806 if (pfound->has_arg != no_argument)
807 d->custom_optarg = nameend + 1;
810 if (argv[d->custom_optind - 1][1] == '-') {
812 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
813 argv[0], pfound->name);
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);
821 d->nextchar += strlen(d->nextchar);
822 d->custom_optopt = pfound->val;
825 } else if (pfound->has_arg == required_argument) {
826 if (d->custom_optind < argc)
827 d->custom_optarg = argv[d->custom_optind++];
831 "%s: option `%s' requires an argument\n",
833 argv[d->custom_optind - 1]);
835 d->nextchar += strlen(d->nextchar);
836 d->custom_optopt = pfound->val;
837 return optstring[0] == ':' ? ':' : '?';
840 d->nextchar += strlen(d->nextchar);
842 *longind = option_index;
844 *(pfound->flag) = pfound->val;
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.
855 if (argv[d->custom_optind][1] == '-') {
858 "%s: unrecognized option `--%s'\n",
859 argv[0], d->nextchar);
861 /* +option or -option */
863 "%s: unrecognized option `%c%s'\n",
864 argv[0], argv[d->custom_optind][0],
868 d->nextchar = (char *) "";
870 d->custom_optopt = 0;
874 static int check_short_opt(int argc, char *const *argv, const char *optstring,
875 int print_errors, struct custom_getopt_data *d)
877 char c = *d->nextchar++;
878 const char *temp = strchr(optstring, c);
880 /* Increment `custom_optind' when we start to process its last character. */
881 if (*d->nextchar == '\0')
883 if (!temp || c == ':') {
885 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
887 d->custom_optopt = c;
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;
897 d->custom_optarg = NULL;
900 /* This is an option that requires an argument. */
901 if (*d->nextchar != '\0') {
902 d->custom_optarg = d->nextchar;
904 * If we end this ARGV-element by taking the
905 * rest as an arg, we must advance to the next
909 } else if (d->custom_optind == argc) {
912 "%s: option requires an argument -- %c\n",
915 d->custom_optopt = c;
916 if (optstring[0] == ':')
922 * We already incremented `custom_optind' once;
923 * increment it again when taking next ARGV-elt
926 d->custom_optarg = argv[d->custom_optind++];
934 * Scan elements of ARGV for option characters given in OPTSTRING.
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.
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.
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.)
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 '?'.
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.
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.
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.
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.
979 * LONGOPTS is a vector of `struct option' terminated by an
980 * element containing a name which is zero.
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
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.
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'.
994 * If a letter in OPTS is followed by two colons, its argument is optional.
995 * This behavior is specific to the GNU `getopt'.
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'.
1003 static 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)
1007 int ret, print_errors = d->custom_opterr;
1009 if (optstring[0] == ':')
1013 d->custom_optarg = NULL;
1016 * This is a big difference with GNU getopt, since optind == 0
1017 * means initialization while here 1 means first call.
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);
1024 if (d->nextchar == NULL || *d->nextchar == '\0') {
1025 ret = shuffle_argv(argc, argv, longopts, d);
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);
1035 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1036 const struct option *longopts, int *longind)
1039 /* Keep a global copy of all internal members of d */
1040 static struct custom_getopt_data d;
1042 d.custom_optind = custom_optind;
1043 d.custom_opterr = custom_opterr;
1044 result = getopt_internal_r(argc, argv, optstring, longopts,
1046 custom_optind = d.custom_optind;
1047 custom_optarg = d.custom_optarg;
1048 custom_optopt = d.custom_optopt;
1052 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1053 const struct option *long_options, int *opt_index)
1055 return custom_getopt_internal(argc, argv, options, long_options,
1060 static char *package_name = 0;
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 RNAduplex_cmdline_parser_params.check_ambiguity
1073 * @param override @see RNAduplex_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
1081 int 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 RNAduplex_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)
1091 char *stop_char = 0;
1092 const char *val = value;
1094 char **string_field;
1100 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
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 : ""));
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 */
1113 FIX_UNUSED (default_value);
1115 if (field_given && *field_given && ! override)
1121 if (possible_values)
1122 val = possible_values[found];
1126 *((int *)field) = !*((int *)field);
1129 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1132 if (val) *((float *)field) = (float)strtod (val, &stop_char);
1135 if (val) *((double *)field) = strtod (val, &stop_char);
1139 string_field = (char **)field;
1140 if (!no_free && *string_field)
1141 free (*string_field); /* free previous string */
1142 *string_field = gengetopt_strdup (val);
1149 /* check numeric conversion */
1154 if (val && !(stop_char && *stop_char == '\0')) {
1155 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1156 return 1; /* failure */
1163 /* store the original value */
1169 if (value && orig_field) {
1171 *orig_field = value;
1174 free (*orig_field); /* free previous string */
1175 *orig_field = gengetopt_strdup (value);
1185 RNAduplex_cmdline_parser_internal (
1186 int argc, char **argv, struct RNAduplex_args_info *args_info,
1187 struct RNAduplex_cmdline_parser_params *params, const char *additional_error)
1189 int c; /* Character of the parsed option. */
1192 struct RNAduplex_args_info local_args_info;
1197 int check_ambiguity;
1204 package_name = argv[0];
1206 override = params->override;
1207 initialize = params->initialize;
1208 check_required = params->check_required;
1209 check_ambiguity = params->check_ambiguity;
1212 RNAduplex_cmdline_parser_init (args_info);
1214 RNAduplex_cmdline_parser_init (&local_args_info);
1218 opterr = params->print_errors;
1223 int option_index = 0;
1225 static struct option long_options[] = {
1226 { "help", 0, NULL, 'h' },
1227 { "detailed-help", 0, NULL, 0 },
1228 { "full-help", 0, NULL, 0 },
1229 { "version", 0, NULL, 'V' },
1230 { "sorted", 0, NULL, 's' },
1231 { "noconv", 0, NULL, 0 },
1232 { "deltaEnergy", 1, NULL, 'e' },
1233 { "temp", 1, NULL, 'T' },
1234 { "noTetra", 0, NULL, '4' },
1235 { "dangles", 1, NULL, 'd' },
1236 { "noLP", 0, NULL, 0 },
1237 { "noGU", 0, NULL, 0 },
1238 { "noClosingGU", 0, NULL, 0 },
1239 { "paramFile", 1, NULL, 'P' },
1240 { "nsp", 1, NULL, 0 },
1244 custom_optarg = optarg;
1245 custom_optind = optind;
1246 custom_opterr = opterr;
1247 custom_optopt = optopt;
1249 c = custom_getopt_long (argc, argv, "hVse:T:4d:P:", long_options, &option_index);
1251 optarg = custom_optarg;
1252 optind = custom_optind;
1253 opterr = custom_opterr;
1254 optopt = custom_optopt;
1256 if (c == -1) break; /* Exit from `while (1)' loop. */
1260 case 'h': /* Print help and exit. */
1261 RNAduplex_cmdline_parser_print_help ();
1262 RNAduplex_cmdline_parser_free (&local_args_info);
1263 exit (EXIT_SUCCESS);
1265 case 'V': /* Print version and exit. */
1266 RNAduplex_cmdline_parser_print_version ();
1267 RNAduplex_cmdline_parser_free (&local_args_info);
1268 exit (EXIT_SUCCESS);
1270 case 's': /* sort the printed output by free energy
1275 if (update_arg((void *)&(args_info->sorted_flag), 0, &(args_info->sorted_given),
1276 &(local_args_info.sorted_given), optarg, 0, 0, ARG_FLAG,
1277 check_ambiguity, override, 1, 0, "sorted", 's',
1282 case 'e': /* Compute suboptimal structures with energy in a certain range of the optimum (kcal/mol). Default is calculation of mfe structure only.
1287 if (update_arg( (void *)&(args_info->deltaEnergy_arg),
1288 &(args_info->deltaEnergy_orig), &(args_info->deltaEnergy_given),
1289 &(local_args_info.deltaEnergy_given), optarg, 0, 0, ARG_FLOAT,
1290 check_ambiguity, override, 0, 0,
1296 case 'T': /* Rescale energy parameters to a temperature of temp C. Default is 37C.
1301 if (update_arg( (void *)&(args_info->temp_arg),
1302 &(args_info->temp_orig), &(args_info->temp_given),
1303 &(local_args_info.temp_given), optarg, 0, 0, ARG_DOUBLE,
1304 check_ambiguity, override, 0, 0,
1310 case '4': /* Do not include special tabulated stabilizing energies for tri-, tetra- and hexaloop hairpins. Mostly for testing.
1315 if (update_arg((void *)&(args_info->noTetra_flag), 0, &(args_info->noTetra_given),
1316 &(local_args_info.noTetra_given), optarg, 0, 0, ARG_FLAG,
1317 check_ambiguity, override, 1, 0, "noTetra", '4',
1322 case 'd': /* How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops
1326 if (update_arg( (void *)&(args_info->dangles_arg),
1327 &(args_info->dangles_orig), &(args_info->dangles_given),
1328 &(local_args_info.dangles_given), optarg, 0, "2", ARG_INT,
1329 check_ambiguity, override, 0, 0,
1335 case 'P': /* Read energy parameters from paramfile, instead of using the default parameter set.
1339 if (update_arg( (void *)&(args_info->paramFile_arg),
1340 &(args_info->paramFile_orig), &(args_info->paramFile_given),
1341 &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1342 check_ambiguity, override, 0, 0,
1349 case 0: /* Long option with no short option */
1350 if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1351 RNAduplex_cmdline_parser_print_detailed_help ();
1352 RNAduplex_cmdline_parser_free (&local_args_info);
1353 exit (EXIT_SUCCESS);
1356 if (strcmp (long_options[option_index].name, "full-help") == 0) {
1357 RNAduplex_cmdline_parser_print_full_help ();
1358 RNAduplex_cmdline_parser_free (&local_args_info);
1359 exit (EXIT_SUCCESS);
1362 /* Do not automatically substitude nucleotide \"T\" with \"U\"
1365 if (strcmp (long_options[option_index].name, "noconv") == 0)
1369 if (update_arg((void *)&(args_info->noconv_flag), 0, &(args_info->noconv_given),
1370 &(local_args_info.noconv_given), optarg, 0, 0, ARG_FLAG,
1371 check_ambiguity, override, 1, 0, "noconv", '-',
1376 /* Produce structures without lonely pairs (helices of length 1).
1378 else if (strcmp (long_options[option_index].name, "noLP") == 0)
1382 if (update_arg((void *)&(args_info->noLP_flag), 0, &(args_info->noLP_given),
1383 &(local_args_info.noLP_given), optarg, 0, 0, ARG_FLAG,
1384 check_ambiguity, override, 1, 0, "noLP", '-',
1389 /* Do not allow GU pairs
1392 else if (strcmp (long_options[option_index].name, "noGU") == 0)
1396 if (update_arg((void *)&(args_info->noGU_flag), 0, &(args_info->noGU_given),
1397 &(local_args_info.noGU_given), optarg, 0, 0, ARG_FLAG,
1398 check_ambiguity, override, 1, 0, "noGU", '-',
1403 /* Do not allow GU pairs at the end of helices
1406 else if (strcmp (long_options[option_index].name, "noClosingGU") == 0)
1410 if (update_arg((void *)&(args_info->noClosingGU_flag), 0, &(args_info->noClosingGU_given),
1411 &(local_args_info.noClosingGU_given), optarg, 0, 0, ARG_FLAG,
1412 check_ambiguity, override, 1, 0, "noClosingGU", '-',
1417 /* Allow other pairs in addition to the usual AU,GC,and GU pairs.
1419 else if (strcmp (long_options[option_index].name, "nsp") == 0)
1423 if (update_arg( (void *)&(args_info->nsp_arg),
1424 &(args_info->nsp_orig), &(args_info->nsp_given),
1425 &(local_args_info.nsp_given), optarg, 0, 0, ARG_STRING,
1426 check_ambiguity, override, 0, 0,
1434 case '?': /* Invalid option. */
1435 /* `getopt_long' already printed an error message. */
1438 default: /* bug: option not considered. */
1439 fprintf (stderr, "%s: option unknown: %c%s\n", RNADUPLEX_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1447 RNAduplex_cmdline_parser_release (&local_args_info);
1450 return (EXIT_FAILURE);
1456 RNAduplex_cmdline_parser_release (&local_args_info);
1457 return (EXIT_FAILURE);