2 File autogenerated by gengetopt version 2.22.5
3 generated with the following command:
4 gengetopt -i RNAaliduplex.ggo --file-name=RNAaliduplex_cmdl --include-getopt --default-optional --unamed-opts --func-name=RNAaliduplex_cmdline_parser --arg-struct-name=RNAaliduplex_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 "RNAaliduplex_cmdl.h"
27 const char *RNAaliduplex_args_info_purpose = "Predict conserved RNA-RNA interactions between two alignments";
29 const char *RNAaliduplex_args_info_usage = "Usage: RNAaliduplex [options] <file1.aln> <file2.aln>";
31 const char *RNAaliduplex_args_info_description = "The program reads two alignments of RNA sequences in CLUSTAL format and \npredicts optimal and suboptimal binding sites, hybridization energies and the \ncorresponding structures. The calculation takes only inter-molecular base pairs \ninto account, for the general case use RNAcofold. The use of alignments allows \nto focus on binding sites that are evolutionary conserved. Note, that the two \ninput alignments need to have equal number of sequences and the same order, \ni.e. the 1st sequence in file1 will be hybridized to the 1st in file2 etc.\n\nThe computed binding sites, energies, and structures 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\n";
33 const char *RNAaliduplex_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 " -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",
40 " -s, --sorted print output sorted by free energy\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 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",
46 " --noLP Produce structures without lonely pairs (helices \n of length 1).\n (default=off)",
47 " 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",
48 " --noGU Do not allow GU pairs\n\n (default=off)",
49 " --noClosingGU Do not allow GU pairs at the end of helices\n\n (default=off)",
50 " --noconv Do not automatically substitude nucleotide \"T\" \n with \"U\"\n\n (default=off)",
51 " --nsp=STRING Allow other pairs in addition to the usual \n AU,GC,and GU pairs.\n",
52 " 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",
53 " -P, --paramFile=paramfile Read energy parameters from paramfile, instead of \n using the default parameter set.\n",
54 " A sample parameter file should accompany your distribution.\n See the RNAlib documentation for details on the file format.\n\n",
55 "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at\n",
62 RNAaliduplex_args_info_help[0] = RNAaliduplex_args_info_detailed_help[0];
63 RNAaliduplex_args_info_help[1] = RNAaliduplex_args_info_detailed_help[1];
64 RNAaliduplex_args_info_help[2] = RNAaliduplex_args_info_detailed_help[2];
65 RNAaliduplex_args_info_help[3] = RNAaliduplex_args_info_detailed_help[3];
66 RNAaliduplex_args_info_help[4] = RNAaliduplex_args_info_detailed_help[4];
67 RNAaliduplex_args_info_help[5] = RNAaliduplex_args_info_detailed_help[5];
68 RNAaliduplex_args_info_help[6] = RNAaliduplex_args_info_detailed_help[6];
69 RNAaliduplex_args_info_help[7] = RNAaliduplex_args_info_detailed_help[7];
70 RNAaliduplex_args_info_help[8] = RNAaliduplex_args_info_detailed_help[8];
71 RNAaliduplex_args_info_help[9] = RNAaliduplex_args_info_detailed_help[9];
72 RNAaliduplex_args_info_help[10] = RNAaliduplex_args_info_detailed_help[10];
73 RNAaliduplex_args_info_help[11] = RNAaliduplex_args_info_detailed_help[12];
74 RNAaliduplex_args_info_help[12] = RNAaliduplex_args_info_detailed_help[14];
75 RNAaliduplex_args_info_help[13] = RNAaliduplex_args_info_detailed_help[15];
76 RNAaliduplex_args_info_help[14] = RNAaliduplex_args_info_detailed_help[16];
77 RNAaliduplex_args_info_help[15] = RNAaliduplex_args_info_detailed_help[17];
78 RNAaliduplex_args_info_help[16] = RNAaliduplex_args_info_detailed_help[19];
79 RNAaliduplex_args_info_help[17] = RNAaliduplex_args_info_detailed_help[21];
80 RNAaliduplex_args_info_help[18] = 0;
84 const char *RNAaliduplex_args_info_help[19];
92 } RNAaliduplex_cmdline_parser_arg_type;
95 void clear_given (struct RNAaliduplex_args_info *args_info);
97 void clear_args (struct RNAaliduplex_args_info *args_info);
100 RNAaliduplex_cmdline_parser_internal (int argc, char **argv, struct RNAaliduplex_args_info *args_info,
101 struct RNAaliduplex_cmdline_parser_params *params, const char *additional_error);
105 gengetopt_strdup (const char *s);
108 void clear_given (struct RNAaliduplex_args_info *args_info)
110 args_info->help_given = 0 ;
111 args_info->detailed_help_given = 0 ;
112 args_info->version_given = 0 ;
113 args_info->deltaEnergy_given = 0 ;
114 args_info->sorted_given = 0 ;
115 args_info->temp_given = 0 ;
116 args_info->noTetra_given = 0 ;
117 args_info->dangles_given = 0 ;
118 args_info->noLP_given = 0 ;
119 args_info->noGU_given = 0 ;
120 args_info->noClosingGU_given = 0 ;
121 args_info->noconv_given = 0 ;
122 args_info->nsp_given = 0 ;
123 args_info->paramFile_given = 0 ;
127 void clear_args (struct RNAaliduplex_args_info *args_info)
129 FIX_UNUSED (args_info);
130 args_info->deltaEnergy_orig = NULL;
131 args_info->sorted_flag = 0;
132 args_info->temp_orig = NULL;
133 args_info->noTetra_flag = 0;
134 args_info->dangles_arg = 2;
135 args_info->dangles_orig = NULL;
136 args_info->noLP_flag = 0;
137 args_info->noGU_flag = 0;
138 args_info->noClosingGU_flag = 0;
139 args_info->noconv_flag = 0;
140 args_info->nsp_arg = NULL;
141 args_info->nsp_orig = NULL;
142 args_info->paramFile_arg = NULL;
143 args_info->paramFile_orig = NULL;
148 void init_args_info(struct RNAaliduplex_args_info *args_info)
152 args_info->help_help = RNAaliduplex_args_info_detailed_help[0] ;
153 args_info->detailed_help_help = RNAaliduplex_args_info_detailed_help[1] ;
154 args_info->version_help = RNAaliduplex_args_info_detailed_help[2] ;
155 args_info->deltaEnergy_help = RNAaliduplex_args_info_detailed_help[5] ;
156 args_info->sorted_help = RNAaliduplex_args_info_detailed_help[6] ;
157 args_info->temp_help = RNAaliduplex_args_info_detailed_help[8] ;
158 args_info->noTetra_help = RNAaliduplex_args_info_detailed_help[9] ;
159 args_info->dangles_help = RNAaliduplex_args_info_detailed_help[10] ;
160 args_info->noLP_help = RNAaliduplex_args_info_detailed_help[12] ;
161 args_info->noGU_help = RNAaliduplex_args_info_detailed_help[14] ;
162 args_info->noClosingGU_help = RNAaliduplex_args_info_detailed_help[15] ;
163 args_info->noconv_help = RNAaliduplex_args_info_detailed_help[16] ;
164 args_info->nsp_help = RNAaliduplex_args_info_detailed_help[17] ;
165 args_info->paramFile_help = RNAaliduplex_args_info_detailed_help[19] ;
170 RNAaliduplex_cmdline_parser_print_version (void)
173 (strlen(RNAALIDUPLEX_CMDLINE_PARSER_PACKAGE_NAME) ? RNAALIDUPLEX_CMDLINE_PARSER_PACKAGE_NAME : RNAALIDUPLEX_CMDLINE_PARSER_PACKAGE),
174 RNAALIDUPLEX_CMDLINE_PARSER_VERSION);
177 static void print_help_common(void) {
178 RNAaliduplex_cmdline_parser_print_version ();
180 if (strlen(RNAaliduplex_args_info_purpose) > 0)
181 printf("\n%s\n", RNAaliduplex_args_info_purpose);
183 if (strlen(RNAaliduplex_args_info_usage) > 0)
184 printf("\n%s\n", RNAaliduplex_args_info_usage);
188 if (strlen(RNAaliduplex_args_info_description) > 0)
189 printf("%s\n\n", RNAaliduplex_args_info_description);
193 RNAaliduplex_cmdline_parser_print_help (void)
197 while (RNAaliduplex_args_info_help[i])
198 printf("%s\n", RNAaliduplex_args_info_help[i++]);
202 RNAaliduplex_cmdline_parser_print_detailed_help (void)
206 while (RNAaliduplex_args_info_detailed_help[i])
207 printf("%s\n", RNAaliduplex_args_info_detailed_help[i++]);
211 RNAaliduplex_cmdline_parser_init (struct RNAaliduplex_args_info *args_info)
213 clear_given (args_info);
214 clear_args (args_info);
215 init_args_info (args_info);
217 args_info->inputs = 0;
218 args_info->inputs_num = 0;
222 RNAaliduplex_cmdline_parser_params_init(struct RNAaliduplex_cmdline_parser_params *params)
226 params->override = 0;
227 params->initialize = 1;
228 params->check_required = 1;
229 params->check_ambiguity = 0;
230 params->print_errors = 1;
234 struct RNAaliduplex_cmdline_parser_params *
235 RNAaliduplex_cmdline_parser_params_create(void)
237 struct RNAaliduplex_cmdline_parser_params *params =
238 (struct RNAaliduplex_cmdline_parser_params *)malloc(sizeof(struct RNAaliduplex_cmdline_parser_params));
239 RNAaliduplex_cmdline_parser_params_init(params);
244 free_string_field (char **s)
255 RNAaliduplex_cmdline_parser_release (struct RNAaliduplex_args_info *args_info)
258 free_string_field (&(args_info->deltaEnergy_orig));
259 free_string_field (&(args_info->temp_orig));
260 free_string_field (&(args_info->dangles_orig));
261 free_string_field (&(args_info->nsp_arg));
262 free_string_field (&(args_info->nsp_orig));
263 free_string_field (&(args_info->paramFile_arg));
264 free_string_field (&(args_info->paramFile_orig));
267 for (i = 0; i < args_info->inputs_num; ++i)
268 free (args_info->inputs [i]);
270 if (args_info->inputs_num)
271 free (args_info->inputs);
273 clear_given (args_info);
278 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
282 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
284 fprintf(outfile, "%s\n", opt);
290 RNAaliduplex_cmdline_parser_dump(FILE *outfile, struct RNAaliduplex_args_info *args_info)
296 fprintf (stderr, "%s: cannot dump options to stream\n", RNAALIDUPLEX_CMDLINE_PARSER_PACKAGE);
300 if (args_info->help_given)
301 write_into_file(outfile, "help", 0, 0 );
302 if (args_info->detailed_help_given)
303 write_into_file(outfile, "detailed-help", 0, 0 );
304 if (args_info->version_given)
305 write_into_file(outfile, "version", 0, 0 );
306 if (args_info->deltaEnergy_given)
307 write_into_file(outfile, "deltaEnergy", args_info->deltaEnergy_orig, 0);
308 if (args_info->sorted_given)
309 write_into_file(outfile, "sorted", 0, 0 );
310 if (args_info->temp_given)
311 write_into_file(outfile, "temp", args_info->temp_orig, 0);
312 if (args_info->noTetra_given)
313 write_into_file(outfile, "noTetra", 0, 0 );
314 if (args_info->dangles_given)
315 write_into_file(outfile, "dangles", args_info->dangles_orig, 0);
316 if (args_info->noLP_given)
317 write_into_file(outfile, "noLP", 0, 0 );
318 if (args_info->noGU_given)
319 write_into_file(outfile, "noGU", 0, 0 );
320 if (args_info->noClosingGU_given)
321 write_into_file(outfile, "noClosingGU", 0, 0 );
322 if (args_info->noconv_given)
323 write_into_file(outfile, "noconv", 0, 0 );
324 if (args_info->nsp_given)
325 write_into_file(outfile, "nsp", args_info->nsp_orig, 0);
326 if (args_info->paramFile_given)
327 write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
335 RNAaliduplex_cmdline_parser_file_save(const char *filename, struct RNAaliduplex_args_info *args_info)
340 outfile = fopen(filename, "w");
344 fprintf (stderr, "%s: cannot open file for writing: %s\n", RNAALIDUPLEX_CMDLINE_PARSER_PACKAGE, filename);
348 i = RNAaliduplex_cmdline_parser_dump(outfile, args_info);
355 RNAaliduplex_cmdline_parser_free (struct RNAaliduplex_args_info *args_info)
357 RNAaliduplex_cmdline_parser_release (args_info);
360 /** @brief replacement of strdup, which is not standard */
362 gengetopt_strdup (const char *s)
368 result = (char*)malloc(strlen(s) + 1);
369 if (result == (char*)0)
376 RNAaliduplex_cmdline_parser (int argc, char **argv, struct RNAaliduplex_args_info *args_info)
378 return RNAaliduplex_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
382 RNAaliduplex_cmdline_parser_ext (int argc, char **argv, struct RNAaliduplex_args_info *args_info,
383 struct RNAaliduplex_cmdline_parser_params *params)
386 result = RNAaliduplex_cmdline_parser_internal (argc, argv, args_info, params, 0);
388 if (result == EXIT_FAILURE)
390 RNAaliduplex_cmdline_parser_free (args_info);
398 RNAaliduplex_cmdline_parser2 (int argc, char **argv, struct RNAaliduplex_args_info *args_info, int override, int initialize, int check_required)
401 struct RNAaliduplex_cmdline_parser_params params;
403 params.override = override;
404 params.initialize = initialize;
405 params.check_required = check_required;
406 params.check_ambiguity = 0;
407 params.print_errors = 1;
409 result = RNAaliduplex_cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
411 if (result == EXIT_FAILURE)
413 RNAaliduplex_cmdline_parser_free (args_info);
421 RNAaliduplex_cmdline_parser_required (struct RNAaliduplex_args_info *args_info, const char *prog_name)
423 FIX_UNUSED (args_info);
424 FIX_UNUSED (prog_name);
429 * Extracted from the glibc source tree, version 2.3.6
431 * Licensed under the GPL as per the whole glibc source tree.
433 * This file was modified so that getopt_long can be called
434 * many times without risking previous memory to be spoiled.
436 * Modified by Andre Noll and Lorenzo Bettini for use in
437 * GNU gengetopt generated files.
442 * we must include anything we need since this file is not thought to be
443 * inserted in a file already using getopt.h
451 /* has_arg can't be an enum because some compilers complain about
452 type mismatches in all the code that assumes it is an int. */
458 /* This version of `getopt' appears to the caller like standard Unix `getopt'
459 but it behaves differently for the user, since it allows the user
460 to intersperse the options with the other arguments.
462 As `getopt' works, it permutes the elements of ARGV so that,
463 when it is done, all the options precede everything else. Thus
464 all application programs are extended to handle flexible argument order.
467 If the field `flag' is not NULL, it points to a variable that is set
468 to the value given in the field `val' when the option is found, but
469 left unchanged if the option is not found.
471 To have a long-named option do something other than set an `int' to
472 a compiled-in constant, such as set a value from `custom_optarg', set the
473 option's `flag' field to zero and its `val' field to a nonzero
474 value (the equivalent single-letter option character, if there is
475 one). For long options that have a zero `flag' field, `getopt'
476 returns the contents of the `val' field. */
478 /* Names for the values of the `has_arg' field of `struct option'. */
480 #define no_argument 0
483 #ifndef required_argument
484 #define required_argument 1
487 #ifndef optional_argument
488 #define optional_argument 2
491 struct custom_getopt_data {
493 * These have exactly the same meaning as the corresponding global variables,
494 * except that they are used for the reentrant versions of getopt.
501 /* True if the internal members have been initialized. */
505 * The next char to be scanned in the option-element in which the last option
506 * character we returned was found. This allows us to pick up the scan where
507 * we left off. If this is zero, or a null string, it means resume the scan by
508 * advancing to the next ARGV-element.
513 * Describe the part of ARGV that contains non-options that have been skipped.
514 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
515 * the index after the last of them.
522 * the variables optarg, optind, opterr and optopt are renamed with
523 * the custom_ prefix so that they don't interfere with getopt ones.
525 * Moreover they're static so they are visible only from within the
526 * file where this very file will be included.
530 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
531 * option that takes an argument, the argument value is returned here.
533 static char *custom_optarg;
536 * Index in ARGV of the next element to be scanned. This is used for
537 * communication to and from the caller and for communication between
538 * successive calls to `custom_getopt'.
540 * On entry to `custom_getopt', 1 means this is the first call; initialize.
542 * When `custom_getopt' returns -1, this is the index of the first of the non-option
543 * elements that the caller should itself scan.
545 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
546 * has been scanned so far.
548 * 1003.2 says this must be 1 before any call.
550 static int custom_optind = 1;
553 * Callers store zero here to inhibit the error message for unrecognized
556 static int custom_opterr = 1;
559 * Set to an option character which was unrecognized. This must be initialized
560 * on some systems to avoid linking in the system's own getopt implementation.
562 static int custom_optopt = '?';
565 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
566 * [first_nonopt,last_nonopt) which contains all the non-options that have been
567 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
568 * all the options processed since those non-options were skipped.
569 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
570 * indices of the non-options in ARGV after they are moved.
572 static void exchange(char **argv, struct custom_getopt_data *d)
574 int bottom = d->first_nonopt;
575 int middle = d->last_nonopt;
576 int top = d->custom_optind;
580 * Exchange the shorter segment with the far end of the longer segment.
581 * That puts the shorter segment into the right place. It leaves the
582 * longer segment in the right place overall, but it consists of two
583 * parts that need to be swapped next.
585 while (top > middle && middle > bottom) {
586 if (top - middle > middle - bottom) {
587 /* Bottom segment is the short one. */
588 int len = middle - bottom;
591 /* Swap it with the top part of the top segment. */
592 for (i = 0; i < len; i++) {
593 tem = argv[bottom + i];
595 argv[top - (middle - bottom) + i];
596 argv[top - (middle - bottom) + i] = tem;
598 /* Exclude the moved bottom segment from further swapping. */
601 /* Top segment is the short one. */
602 int len = top - middle;
605 /* Swap it with the bottom part of the bottom segment. */
606 for (i = 0; i < len; i++) {
607 tem = argv[bottom + i];
608 argv[bottom + i] = argv[middle + i];
609 argv[middle + i] = tem;
611 /* Exclude the moved top segment from further swapping. */
615 /* Update records for the slots the non-options now occupy. */
616 d->first_nonopt += (d->custom_optind - d->last_nonopt);
617 d->last_nonopt = d->custom_optind;
620 /* Initialize the internal data when the first call is made. */
621 static void custom_getopt_initialize(struct custom_getopt_data *d)
624 * Start processing options with ARGV-element 1 (since ARGV-element 0
625 * is the program name); the sequence of previously skipped non-option
626 * ARGV-elements is empty.
628 d->first_nonopt = d->last_nonopt = d->custom_optind;
633 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
635 /* return: zero: continue, nonzero: return given value to user */
636 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
637 struct custom_getopt_data *d)
640 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
641 * moved back by the user (who may also have changed the arguments).
643 if (d->last_nonopt > d->custom_optind)
644 d->last_nonopt = d->custom_optind;
645 if (d->first_nonopt > d->custom_optind)
646 d->first_nonopt = d->custom_optind;
648 * If we have just processed some options following some
649 * non-options, exchange them so that the options come first.
651 if (d->first_nonopt != d->last_nonopt &&
652 d->last_nonopt != d->custom_optind)
653 exchange((char **) argv, d);
654 else if (d->last_nonopt != d->custom_optind)
655 d->first_nonopt = d->custom_optind;
657 * Skip any additional non-options and extend the range of
658 * non-options previously skipped.
660 while (d->custom_optind < argc && NONOPTION_P)
662 d->last_nonopt = d->custom_optind;
664 * The special ARGV-element `--' means premature end of options. Skip
665 * it like a null option, then exchange with previous non-options as if
666 * it were an option, then skip everything else like a non-option.
668 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
670 if (d->first_nonopt != d->last_nonopt
671 && d->last_nonopt != d->custom_optind)
672 exchange((char **) argv, d);
673 else if (d->first_nonopt == d->last_nonopt)
674 d->first_nonopt = d->custom_optind;
675 d->last_nonopt = argc;
676 d->custom_optind = argc;
679 * If we have done all the ARGV-elements, stop the scan and back over
680 * any non-options that we skipped and permuted.
682 if (d->custom_optind == argc) {
684 * Set the next-arg-index to point at the non-options that we
685 * previously skipped, so the caller will digest them.
687 if (d->first_nonopt != d->last_nonopt)
688 d->custom_optind = d->first_nonopt;
692 * If we have come to a non-option and did not permute it, either stop
693 * the scan or describe it to the caller and pass it by.
696 d->custom_optarg = argv[d->custom_optind++];
700 * We have found another option-ARGV-element. Skip the initial
703 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
708 * Check whether the ARGV-element is a long option.
710 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
711 * that an abbreviation of the long option, just like "--fu", and not "-f" with
714 * This distinction seems to be the most useful approach.
717 static int check_long_opt(int argc, char *const *argv, const char *optstring,
718 const struct option *longopts, int *longind,
719 int print_errors, struct custom_getopt_data *d)
722 const struct option *p;
723 const struct option *pfound = NULL;
729 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
732 /* Test all long options for either exact match or abbreviated matches */
733 for (p = longopts, option_index = 0; p->name; p++, option_index++)
734 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
735 if ((unsigned int) (nameend - d->nextchar)
736 == (unsigned int) strlen(p->name)) {
737 /* Exact match found. */
739 indfound = option_index;
742 } else if (pfound == NULL) {
743 /* First nonexact match found. */
745 indfound = option_index;
746 } else if (pfound->has_arg != p->has_arg
747 || pfound->flag != p->flag
748 || pfound->val != p->val)
749 /* Second or later nonexact match found. */
752 if (ambig && !exact) {
755 "%s: option `%s' is ambiguous\n",
756 argv[0], argv[d->custom_optind]);
758 d->nextchar += strlen(d->nextchar);
760 d->custom_optopt = 0;
764 option_index = indfound;
767 if (pfound->has_arg != no_argument)
768 d->custom_optarg = nameend + 1;
771 if (argv[d->custom_optind - 1][1] == '-') {
773 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
774 argv[0], pfound->name);
776 /* +option or -option */
777 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
778 argv[0], argv[d->custom_optind - 1][0], pfound->name);
782 d->nextchar += strlen(d->nextchar);
783 d->custom_optopt = pfound->val;
786 } else if (pfound->has_arg == required_argument) {
787 if (d->custom_optind < argc)
788 d->custom_optarg = argv[d->custom_optind++];
792 "%s: option `%s' requires an argument\n",
794 argv[d->custom_optind - 1]);
796 d->nextchar += strlen(d->nextchar);
797 d->custom_optopt = pfound->val;
798 return optstring[0] == ':' ? ':' : '?';
801 d->nextchar += strlen(d->nextchar);
803 *longind = option_index;
805 *(pfound->flag) = pfound->val;
811 * Can't find it as a long option. If this is not getopt_long_only, or
812 * the option starts with '--' or is not a valid short option, then
813 * it's an error. Otherwise interpret it as a short option.
816 if (argv[d->custom_optind][1] == '-') {
819 "%s: unrecognized option `--%s'\n",
820 argv[0], d->nextchar);
822 /* +option or -option */
824 "%s: unrecognized option `%c%s'\n",
825 argv[0], argv[d->custom_optind][0],
829 d->nextchar = (char *) "";
831 d->custom_optopt = 0;
835 static int check_short_opt(int argc, char *const *argv, const char *optstring,
836 int print_errors, struct custom_getopt_data *d)
838 char c = *d->nextchar++;
839 const char *temp = strchr(optstring, c);
841 /* Increment `custom_optind' when we start to process its last character. */
842 if (*d->nextchar == '\0')
844 if (!temp || c == ':') {
846 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
848 d->custom_optopt = c;
851 if (temp[1] == ':') {
852 if (temp[2] == ':') {
853 /* This is an option that accepts an argument optionally. */
854 if (*d->nextchar != '\0') {
855 d->custom_optarg = d->nextchar;
858 d->custom_optarg = NULL;
861 /* This is an option that requires an argument. */
862 if (*d->nextchar != '\0') {
863 d->custom_optarg = d->nextchar;
865 * If we end this ARGV-element by taking the
866 * rest as an arg, we must advance to the next
870 } else if (d->custom_optind == argc) {
873 "%s: option requires an argument -- %c\n",
876 d->custom_optopt = c;
877 if (optstring[0] == ':')
883 * We already incremented `custom_optind' once;
884 * increment it again when taking next ARGV-elt
887 d->custom_optarg = argv[d->custom_optind++];
895 * Scan elements of ARGV for option characters given in OPTSTRING.
897 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
898 * then it is an option element. The characters of this element
899 * (aside from the initial '-') are option characters. If `getopt'
900 * is called repeatedly, it returns successively each of the option characters
901 * from each of the option elements.
903 * If `getopt' finds another option character, it returns that character,
904 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
905 * resume the scan with the following option character or ARGV-element.
907 * If there are no more option characters, `getopt' returns -1.
908 * Then `custom_optind' is the index in ARGV of the first ARGV-element
909 * that is not an option. (The ARGV-elements have been permuted
910 * so that those that are not options now come last.)
912 * OPTSTRING is a string containing the legitimate option characters.
913 * If an option character is seen that is not listed in OPTSTRING,
914 * return '?' after printing an error message. If you set `custom_opterr' to
915 * zero, the error message is suppressed but we still return '?'.
917 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
918 * so the following text in the same ARGV-element, or the text of the following
919 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
920 * wants an optional arg; if there is text in the current ARGV-element,
921 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
923 * If OPTSTRING starts with `-' or `+', it requests different methods of
924 * handling the non-option ARGV-elements.
925 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
927 * Long-named options begin with `--' instead of `-'.
928 * Their names may be abbreviated as long as the abbreviation is unique
929 * or is an exact match for some defined option. If they have an
930 * argument, it follows the option name in the same ARGV-element, separated
931 * from the option name by a `=', or else the in next ARGV-element.
932 * When `getopt' finds a long-named option, it returns 0 if that option's
933 * `flag' field is nonzero, the value of the option's `val' field
934 * if the `flag' field is zero.
936 * The elements of ARGV aren't really const, because we permute them.
937 * But we pretend they're const in the prototype to be compatible
938 * with other systems.
940 * LONGOPTS is a vector of `struct option' terminated by an
941 * element containing a name which is zero.
943 * LONGIND returns the index in LONGOPT of the long-named option found.
944 * It is only valid when a long-named option has been found by the most
947 * Return the option character from OPTS just read. Return -1 when there are
948 * no more options. For unrecognized options, or options missing arguments,
949 * `custom_optopt' is set to the option letter, and '?' is returned.
951 * The OPTS string is a list of characters which are recognized option letters,
952 * optionally followed by colons, specifying that that letter takes an
953 * argument, to be placed in `custom_optarg'.
955 * If a letter in OPTS is followed by two colons, its argument is optional.
956 * This behavior is specific to the GNU `getopt'.
958 * The argument `--' causes premature termination of argument scanning,
959 * explicitly telling `getopt' that there are no more options. If OPTS begins
960 * with `--', then non-option arguments are treated as arguments to the option
961 * '\0'. This behavior is specific to the GNU `getopt'.
964 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
965 const struct option *longopts, int *longind,
966 struct custom_getopt_data *d)
968 int ret, print_errors = d->custom_opterr;
970 if (optstring[0] == ':')
974 d->custom_optarg = NULL;
977 * This is a big difference with GNU getopt, since optind == 0
978 * means initialization while here 1 means first call.
980 if (d->custom_optind == 0 || !d->initialized) {
981 if (d->custom_optind == 0)
982 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
983 custom_getopt_initialize(d);
985 if (d->nextchar == NULL || *d->nextchar == '\0') {
986 ret = shuffle_argv(argc, argv, longopts, d);
990 if (longopts && (argv[d->custom_optind][1] == '-' ))
991 return check_long_opt(argc, argv, optstring, longopts,
992 longind, print_errors, d);
993 return check_short_opt(argc, argv, optstring, print_errors, d);
996 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
997 const struct option *longopts, int *longind)
1000 /* Keep a global copy of all internal members of d */
1001 static struct custom_getopt_data d;
1003 d.custom_optind = custom_optind;
1004 d.custom_opterr = custom_opterr;
1005 result = getopt_internal_r(argc, argv, optstring, longopts,
1007 custom_optind = d.custom_optind;
1008 custom_optarg = d.custom_optarg;
1009 custom_optopt = d.custom_optopt;
1013 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1014 const struct option *long_options, int *opt_index)
1016 return custom_getopt_internal(argc, argv, options, long_options,
1021 static char *package_name = 0;
1024 * @brief updates an option
1025 * @param field the generic pointer to the field to update
1026 * @param orig_field the pointer to the orig field
1027 * @param field_given the pointer to the number of occurrence of this option
1028 * @param prev_given the pointer to the number of occurrence already seen
1029 * @param value the argument for this option (if null no arg was specified)
1030 * @param possible_values the possible values for this option (if specified)
1031 * @param default_value the default value (in case the option only accepts fixed values)
1032 * @param arg_type the type of this option
1033 * @param check_ambiguity @see RNAaliduplex_cmdline_parser_params.check_ambiguity
1034 * @param override @see RNAaliduplex_cmdline_parser_params.override
1035 * @param no_free whether to free a possible previous value
1036 * @param multiple_option whether this is a multiple option
1037 * @param long_opt the corresponding long option
1038 * @param short_opt the corresponding short option (or '-' if none)
1039 * @param additional_error possible further error specification
1042 int update_arg(void *field, char **orig_field,
1043 unsigned int *field_given, unsigned int *prev_given,
1044 char *value, const char *possible_values[],
1045 const char *default_value,
1046 RNAaliduplex_cmdline_parser_arg_type arg_type,
1047 int check_ambiguity, int override,
1048 int no_free, int multiple_option,
1049 const char *long_opt, char short_opt,
1050 const char *additional_error)
1052 char *stop_char = 0;
1053 const char *val = value;
1055 char **string_field;
1061 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1063 if (short_opt != '-')
1064 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1065 package_name, long_opt, short_opt,
1066 (additional_error ? additional_error : ""));
1068 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1069 package_name, long_opt,
1070 (additional_error ? additional_error : ""));
1071 return 1; /* failure */
1074 FIX_UNUSED (default_value);
1076 if (field_given && *field_given && ! override)
1082 if (possible_values)
1083 val = possible_values[found];
1087 *((int *)field) = !*((int *)field);
1090 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1093 if (val) *((float *)field) = (float)strtod (val, &stop_char);
1096 if (val) *((double *)field) = strtod (val, &stop_char);
1100 string_field = (char **)field;
1101 if (!no_free && *string_field)
1102 free (*string_field); /* free previous string */
1103 *string_field = gengetopt_strdup (val);
1110 /* check numeric conversion */
1115 if (val && !(stop_char && *stop_char == '\0')) {
1116 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1117 return 1; /* failure */
1124 /* store the original value */
1130 if (value && orig_field) {
1132 *orig_field = value;
1135 free (*orig_field); /* free previous string */
1136 *orig_field = gengetopt_strdup (value);
1146 RNAaliduplex_cmdline_parser_internal (
1147 int argc, char **argv, struct RNAaliduplex_args_info *args_info,
1148 struct RNAaliduplex_cmdline_parser_params *params, const char *additional_error)
1150 int c; /* Character of the parsed option. */
1153 struct RNAaliduplex_args_info local_args_info;
1158 int check_ambiguity;
1165 package_name = argv[0];
1167 override = params->override;
1168 initialize = params->initialize;
1169 check_required = params->check_required;
1170 check_ambiguity = params->check_ambiguity;
1173 RNAaliduplex_cmdline_parser_init (args_info);
1175 RNAaliduplex_cmdline_parser_init (&local_args_info);
1179 opterr = params->print_errors;
1184 int option_index = 0;
1186 static struct option long_options[] = {
1187 { "help", 0, NULL, 'h' },
1188 { "detailed-help", 0, NULL, 0 },
1189 { "version", 0, NULL, 'V' },
1190 { "deltaEnergy", 1, NULL, 'e' },
1191 { "sorted", 0, NULL, 's' },
1192 { "temp", 1, NULL, 'T' },
1193 { "noTetra", 0, NULL, '4' },
1194 { "dangles", 1, NULL, 'd' },
1195 { "noLP", 0, NULL, 0 },
1196 { "noGU", 0, NULL, 0 },
1197 { "noClosingGU", 0, NULL, 0 },
1198 { "noconv", 0, NULL, 0 },
1199 { "nsp", 1, NULL, 0 },
1200 { "paramFile", 1, NULL, 'P' },
1204 custom_optarg = optarg;
1205 custom_optind = optind;
1206 custom_opterr = opterr;
1207 custom_optopt = optopt;
1209 c = custom_getopt_long (argc, argv, "hVe:sT:4d:P:", long_options, &option_index);
1211 optarg = custom_optarg;
1212 optind = custom_optind;
1213 opterr = custom_opterr;
1214 optopt = custom_optopt;
1216 if (c == -1) break; /* Exit from `while (1)' loop. */
1220 case 'h': /* Print help and exit. */
1221 RNAaliduplex_cmdline_parser_print_help ();
1222 RNAaliduplex_cmdline_parser_free (&local_args_info);
1223 exit (EXIT_SUCCESS);
1225 case 'V': /* Print version and exit. */
1226 RNAaliduplex_cmdline_parser_print_version ();
1227 RNAaliduplex_cmdline_parser_free (&local_args_info);
1228 exit (EXIT_SUCCESS);
1230 case 'e': /* Compute suboptimal structures with energy in a certain range of the optimum (kcal/mol). Default is calculation of mfe structure only.
1235 if (update_arg( (void *)&(args_info->deltaEnergy_arg),
1236 &(args_info->deltaEnergy_orig), &(args_info->deltaEnergy_given),
1237 &(local_args_info.deltaEnergy_given), optarg, 0, 0, ARG_FLOAT,
1238 check_ambiguity, override, 0, 0,
1244 case 's': /* print output sorted by free energy
1249 if (update_arg((void *)&(args_info->sorted_flag), 0, &(args_info->sorted_given),
1250 &(local_args_info.sorted_given), optarg, 0, 0, ARG_FLAG,
1251 check_ambiguity, override, 1, 0, "sorted", 's',
1256 case 'T': /* Rescale energy parameters to a temperature of temp C. Default is 37C.
1261 if (update_arg( (void *)&(args_info->temp_arg),
1262 &(args_info->temp_orig), &(args_info->temp_given),
1263 &(local_args_info.temp_given), optarg, 0, 0, ARG_DOUBLE,
1264 check_ambiguity, override, 0, 0,
1270 case '4': /* Do not include special tabulated stabilizing energies for tri-, tetra- and hexaloop hairpins. Mostly for testing.
1275 if (update_arg((void *)&(args_info->noTetra_flag), 0, &(args_info->noTetra_given),
1276 &(local_args_info.noTetra_given), optarg, 0, 0, ARG_FLAG,
1277 check_ambiguity, override, 1, 0, "noTetra", '4',
1282 case 'd': /* How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops
1286 if (update_arg( (void *)&(args_info->dangles_arg),
1287 &(args_info->dangles_orig), &(args_info->dangles_given),
1288 &(local_args_info.dangles_given), optarg, 0, "2", ARG_INT,
1289 check_ambiguity, override, 0, 0,
1295 case 'P': /* Read energy parameters from paramfile, instead of using the default parameter set.
1299 if (update_arg( (void *)&(args_info->paramFile_arg),
1300 &(args_info->paramFile_orig), &(args_info->paramFile_given),
1301 &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1302 check_ambiguity, override, 0, 0,
1309 case 0: /* Long option with no short option */
1310 if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1311 RNAaliduplex_cmdline_parser_print_detailed_help ();
1312 RNAaliduplex_cmdline_parser_free (&local_args_info);
1313 exit (EXIT_SUCCESS);
1316 /* Produce structures without lonely pairs (helices of length 1).
1318 if (strcmp (long_options[option_index].name, "noLP") == 0)
1322 if (update_arg((void *)&(args_info->noLP_flag), 0, &(args_info->noLP_given),
1323 &(local_args_info.noLP_given), optarg, 0, 0, ARG_FLAG,
1324 check_ambiguity, override, 1, 0, "noLP", '-',
1329 /* Do not allow GU pairs
1332 else if (strcmp (long_options[option_index].name, "noGU") == 0)
1336 if (update_arg((void *)&(args_info->noGU_flag), 0, &(args_info->noGU_given),
1337 &(local_args_info.noGU_given), optarg, 0, 0, ARG_FLAG,
1338 check_ambiguity, override, 1, 0, "noGU", '-',
1343 /* Do not allow GU pairs at the end of helices
1346 else if (strcmp (long_options[option_index].name, "noClosingGU") == 0)
1350 if (update_arg((void *)&(args_info->noClosingGU_flag), 0, &(args_info->noClosingGU_given),
1351 &(local_args_info.noClosingGU_given), optarg, 0, 0, ARG_FLAG,
1352 check_ambiguity, override, 1, 0, "noClosingGU", '-',
1357 /* Do not automatically substitude nucleotide \"T\" with \"U\"
1360 else if (strcmp (long_options[option_index].name, "noconv") == 0)
1364 if (update_arg((void *)&(args_info->noconv_flag), 0, &(args_info->noconv_given),
1365 &(local_args_info.noconv_given), optarg, 0, 0, ARG_FLAG,
1366 check_ambiguity, override, 1, 0, "noconv", '-',
1371 /* Allow other pairs in addition to the usual AU,GC,and GU pairs.
1373 else if (strcmp (long_options[option_index].name, "nsp") == 0)
1377 if (update_arg( (void *)&(args_info->nsp_arg),
1378 &(args_info->nsp_orig), &(args_info->nsp_given),
1379 &(local_args_info.nsp_given), optarg, 0, 0, ARG_STRING,
1380 check_ambiguity, override, 0, 0,
1388 case '?': /* Invalid option. */
1389 /* `getopt_long' already printed an error message. */
1392 default: /* bug: option not considered. */
1393 fprintf (stderr, "%s: option unknown: %c%s\n", RNAALIDUPLEX_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1401 RNAaliduplex_cmdline_parser_release (&local_args_info);
1404 return (EXIT_FAILURE);
1409 int found_prog_name = 0;
1410 /* whether program name, i.e., argv[0], is in the remaining args
1411 (this may happen with some implementations of getopt,
1412 but surely not with the one included by gengetopt) */
1415 args_info->inputs_num = argc - optind - found_prog_name;
1417 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1418 while (optind < argc)
1419 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1426 RNAaliduplex_cmdline_parser_release (&local_args_info);
1427 return (EXIT_FAILURE);