2 File autogenerated by gengetopt version 2.22.5
3 generated with the following command:
4 gengetopt -i RNAinverse.ggo --file-name=RNAinverse_cmdl --include-getopt --default-optional --func-name=RNAinverse_cmdline_parser --arg-struct-name=RNAinverse_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 "RNAinverse_cmdl.h"
27 const char *RNAinverse_args_info_purpose = "Find RNA sequences with given secondary structure";
29 const char *RNAinverse_args_info_usage = "Usage: RNAinverse [OPTIONS]...";
31 const char *RNAinverse_args_info_description = "The program searches for sequences folding into a predefined structure, thereby \ninverting the folding algorithm. Target structures (in bracket notation) and \nstarting sequences for the search are read alternately from stdin.\nCharacters in the start sequence other than \"AUGC\" (or the alphabet specified \nwith -a) will be treated as wild cards and replaced by a random character. Any \nlower case characters in the start sequence will be kept fixed during the \nsearch. If necessary, the sequence will be elongated to the length of the \nstructure. Thus a string of \"N\"s as well as a blank line specify a random \nstart sequence.\nFor each search the best sequence found and its Hamming distance to the start \nsequence are printed to stdout. If the the search was unsuccessful, a structure \ndistance to the target is appended.\nThe -Fp and -R options can modify the output format, see commandline options \nbelow.\nThe program will continue to read new structures and sequences until a line \nconsisting of the single character \"@\" or an end of file condition is \nencountered.\n";
33 const char *RNAinverse_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 " -R, --repeat[=INT] Search repeatedly for the same structure.\n If an argument is supplied to this option it \n must follow the option flag immediately. E.g.: \n -R5\n (default=`100')",
41 " If repeats is negative search until --repeats exact solutions are found, no \n output is done for unsuccessful searches. Be aware, that the program will not \n terminate if the target structure can not be found.\n If no value is supplied with this option, the default value is used.\n\n",
42 " -a, --alphabet=ALPHABET Find sequences using only nucleotides from a given \n alphabet.\n\n",
43 " -v, --verbose In conjunction with a negative value supplied to \n -R, print the last subsequence and substructure \n for each unsuccessful search.\n\n (default=off)",
45 " Select additional algorithms which should be included in the calculations.\n\n",
46 " -F, --function=mp Use minimum energy (-Fm), partition function \n folding (-Fp) or both (-Fmp).\n (default=`m')",
47 " In partition function mode, the probability of the target structure \n exp(-E(S)/kT)/Q is maximized. This probability is written in brackets after \n the found sequence and Hamming distance. In most cases you'll want to use the \n -f option in conjunction with -Fp, see below.\n\n",
48 " -f, --final=FLOAT In combination with -Fp stop search when sequence \n is found with E(s)-F is smaller than final, \n where F=-kT*ln(Q).\n\n",
50 " -T, --temp=DOUBLE Rescale energy parameters to a temperature of temp \n C. Default is 37C.\n\n",
51 " -4, --noTetra Do not include special tabulated stabilizing \n energies for tri-, tetra- and hexaloop hairpins. \n Mostly for testing.\n\n (default=off)",
52 " -d, --dangles=INT How to treat \"dangling end\" energies for bases \n adjacent to helices in free ends and multi-loops\n (default=`2')",
53 " \n With -d1 only unpaired bases can participate in at most one dangling end, \n this is 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 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 -Fp to ensure that both \n algorithms use the same energy model.\n\n",
54 " --noGU Do not allow GU pairs\n\n (default=off)",
55 " --noClosingGU Do not allow GU pairs at the end of helices\n\n (default=off)",
56 " -P, --paramFile=paramfile Read energy parameters from paramfile, instead of \n using the default parameter set.\n",
57 " A sample parameter file should accompany your distribution.\n See the RNAlib documentation for details on the file format.\n\n",
58 " --nsp=STRING Allow other pairs in addition to the usual \n AU,GC,and GU pairs.\n",
59 " 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",
60 " -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",
61 "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
65 init_full_help_array(void)
67 RNAinverse_args_info_full_help[0] = RNAinverse_args_info_detailed_help[0];
68 RNAinverse_args_info_full_help[1] = RNAinverse_args_info_detailed_help[1];
69 RNAinverse_args_info_full_help[2] = RNAinverse_args_info_detailed_help[2];
70 RNAinverse_args_info_full_help[3] = RNAinverse_args_info_detailed_help[3];
71 RNAinverse_args_info_full_help[4] = RNAinverse_args_info_detailed_help[4];
72 RNAinverse_args_info_full_help[5] = RNAinverse_args_info_detailed_help[5];
73 RNAinverse_args_info_full_help[6] = RNAinverse_args_info_detailed_help[6];
74 RNAinverse_args_info_full_help[7] = RNAinverse_args_info_detailed_help[8];
75 RNAinverse_args_info_full_help[8] = RNAinverse_args_info_detailed_help[9];
76 RNAinverse_args_info_full_help[9] = RNAinverse_args_info_detailed_help[10];
77 RNAinverse_args_info_full_help[10] = RNAinverse_args_info_detailed_help[11];
78 RNAinverse_args_info_full_help[11] = RNAinverse_args_info_detailed_help[12];
79 RNAinverse_args_info_full_help[12] = RNAinverse_args_info_detailed_help[14];
80 RNAinverse_args_info_full_help[13] = RNAinverse_args_info_detailed_help[15];
81 RNAinverse_args_info_full_help[14] = RNAinverse_args_info_detailed_help[16];
82 RNAinverse_args_info_full_help[15] = RNAinverse_args_info_detailed_help[17];
83 RNAinverse_args_info_full_help[16] = RNAinverse_args_info_detailed_help[18];
84 RNAinverse_args_info_full_help[17] = RNAinverse_args_info_detailed_help[20];
85 RNAinverse_args_info_full_help[18] = RNAinverse_args_info_detailed_help[21];
86 RNAinverse_args_info_full_help[19] = RNAinverse_args_info_detailed_help[22];
87 RNAinverse_args_info_full_help[20] = RNAinverse_args_info_detailed_help[24];
88 RNAinverse_args_info_full_help[21] = RNAinverse_args_info_detailed_help[26];
89 RNAinverse_args_info_full_help[22] = RNAinverse_args_info_detailed_help[27];
90 RNAinverse_args_info_full_help[23] = 0;
94 const char *RNAinverse_args_info_full_help[24];
99 RNAinverse_args_info_help[0] = RNAinverse_args_info_detailed_help[0];
100 RNAinverse_args_info_help[1] = RNAinverse_args_info_detailed_help[1];
101 RNAinverse_args_info_help[2] = RNAinverse_args_info_detailed_help[2];
102 RNAinverse_args_info_help[3] = RNAinverse_args_info_detailed_help[3];
103 RNAinverse_args_info_help[4] = RNAinverse_args_info_detailed_help[4];
104 RNAinverse_args_info_help[5] = RNAinverse_args_info_detailed_help[5];
105 RNAinverse_args_info_help[6] = RNAinverse_args_info_detailed_help[6];
106 RNAinverse_args_info_help[7] = RNAinverse_args_info_detailed_help[8];
107 RNAinverse_args_info_help[8] = RNAinverse_args_info_detailed_help[9];
108 RNAinverse_args_info_help[9] = RNAinverse_args_info_detailed_help[10];
109 RNAinverse_args_info_help[10] = RNAinverse_args_info_detailed_help[11];
110 RNAinverse_args_info_help[11] = RNAinverse_args_info_detailed_help[12];
111 RNAinverse_args_info_help[12] = RNAinverse_args_info_detailed_help[14];
112 RNAinverse_args_info_help[13] = RNAinverse_args_info_detailed_help[15];
113 RNAinverse_args_info_help[14] = RNAinverse_args_info_detailed_help[16];
114 RNAinverse_args_info_help[15] = RNAinverse_args_info_detailed_help[17];
115 RNAinverse_args_info_help[16] = RNAinverse_args_info_detailed_help[18];
116 RNAinverse_args_info_help[17] = RNAinverse_args_info_detailed_help[20];
117 RNAinverse_args_info_help[18] = RNAinverse_args_info_detailed_help[21];
118 RNAinverse_args_info_help[19] = RNAinverse_args_info_detailed_help[22];
119 RNAinverse_args_info_help[20] = RNAinverse_args_info_detailed_help[27];
120 RNAinverse_args_info_help[21] = 0;
124 const char *RNAinverse_args_info_help[22];
132 } RNAinverse_cmdline_parser_arg_type;
135 void clear_given (struct RNAinverse_args_info *args_info);
137 void clear_args (struct RNAinverse_args_info *args_info);
140 RNAinverse_cmdline_parser_internal (int argc, char **argv, struct RNAinverse_args_info *args_info,
141 struct RNAinverse_cmdline_parser_params *params, const char *additional_error);
145 gengetopt_strdup (const char *s);
148 void clear_given (struct RNAinverse_args_info *args_info)
150 args_info->help_given = 0 ;
151 args_info->detailed_help_given = 0 ;
152 args_info->full_help_given = 0 ;
153 args_info->version_given = 0 ;
154 args_info->repeat_given = 0 ;
155 args_info->alphabet_given = 0 ;
156 args_info->verbose_given = 0 ;
157 args_info->function_given = 0 ;
158 args_info->final_given = 0 ;
159 args_info->temp_given = 0 ;
160 args_info->noTetra_given = 0 ;
161 args_info->dangles_given = 0 ;
162 args_info->noGU_given = 0 ;
163 args_info->noClosingGU_given = 0 ;
164 args_info->paramFile_given = 0 ;
165 args_info->nsp_given = 0 ;
166 args_info->energyModel_given = 0 ;
170 void clear_args (struct RNAinverse_args_info *args_info)
172 FIX_UNUSED (args_info);
173 args_info->repeat_arg = 100;
174 args_info->repeat_orig = NULL;
175 args_info->alphabet_arg = NULL;
176 args_info->alphabet_orig = NULL;
177 args_info->verbose_flag = 0;
178 args_info->function_arg = gengetopt_strdup ("m");
179 args_info->function_orig = NULL;
180 args_info->final_orig = NULL;
181 args_info->temp_orig = NULL;
182 args_info->noTetra_flag = 0;
183 args_info->dangles_arg = 2;
184 args_info->dangles_orig = NULL;
185 args_info->noGU_flag = 0;
186 args_info->noClosingGU_flag = 0;
187 args_info->paramFile_arg = NULL;
188 args_info->paramFile_orig = NULL;
189 args_info->nsp_arg = NULL;
190 args_info->nsp_orig = NULL;
191 args_info->energyModel_orig = NULL;
196 void init_args_info(struct RNAinverse_args_info *args_info)
198 init_full_help_array();
200 args_info->help_help = RNAinverse_args_info_detailed_help[0] ;
201 args_info->detailed_help_help = RNAinverse_args_info_detailed_help[1] ;
202 args_info->full_help_help = RNAinverse_args_info_detailed_help[2] ;
203 args_info->version_help = RNAinverse_args_info_detailed_help[3] ;
204 args_info->repeat_help = RNAinverse_args_info_detailed_help[6] ;
205 args_info->alphabet_help = RNAinverse_args_info_detailed_help[8] ;
206 args_info->verbose_help = RNAinverse_args_info_detailed_help[9] ;
207 args_info->function_help = RNAinverse_args_info_detailed_help[12] ;
208 args_info->final_help = RNAinverse_args_info_detailed_help[14] ;
209 args_info->temp_help = RNAinverse_args_info_detailed_help[16] ;
210 args_info->noTetra_help = RNAinverse_args_info_detailed_help[17] ;
211 args_info->dangles_help = RNAinverse_args_info_detailed_help[18] ;
212 args_info->noGU_help = RNAinverse_args_info_detailed_help[20] ;
213 args_info->noClosingGU_help = RNAinverse_args_info_detailed_help[21] ;
214 args_info->paramFile_help = RNAinverse_args_info_detailed_help[22] ;
215 args_info->nsp_help = RNAinverse_args_info_detailed_help[24] ;
216 args_info->energyModel_help = RNAinverse_args_info_detailed_help[26] ;
221 RNAinverse_cmdline_parser_print_version (void)
224 (strlen(RNAINVERSE_CMDLINE_PARSER_PACKAGE_NAME) ? RNAINVERSE_CMDLINE_PARSER_PACKAGE_NAME : RNAINVERSE_CMDLINE_PARSER_PACKAGE),
225 RNAINVERSE_CMDLINE_PARSER_VERSION);
228 static void print_help_common(void) {
229 RNAinverse_cmdline_parser_print_version ();
231 if (strlen(RNAinverse_args_info_purpose) > 0)
232 printf("\n%s\n", RNAinverse_args_info_purpose);
234 if (strlen(RNAinverse_args_info_usage) > 0)
235 printf("\n%s\n", RNAinverse_args_info_usage);
239 if (strlen(RNAinverse_args_info_description) > 0)
240 printf("%s\n\n", RNAinverse_args_info_description);
244 RNAinverse_cmdline_parser_print_help (void)
248 while (RNAinverse_args_info_help[i])
249 printf("%s\n", RNAinverse_args_info_help[i++]);
253 RNAinverse_cmdline_parser_print_full_help (void)
257 while (RNAinverse_args_info_full_help[i])
258 printf("%s\n", RNAinverse_args_info_full_help[i++]);
262 RNAinverse_cmdline_parser_print_detailed_help (void)
266 while (RNAinverse_args_info_detailed_help[i])
267 printf("%s\n", RNAinverse_args_info_detailed_help[i++]);
271 RNAinverse_cmdline_parser_init (struct RNAinverse_args_info *args_info)
273 clear_given (args_info);
274 clear_args (args_info);
275 init_args_info (args_info);
279 RNAinverse_cmdline_parser_params_init(struct RNAinverse_cmdline_parser_params *params)
283 params->override = 0;
284 params->initialize = 1;
285 params->check_required = 1;
286 params->check_ambiguity = 0;
287 params->print_errors = 1;
291 struct RNAinverse_cmdline_parser_params *
292 RNAinverse_cmdline_parser_params_create(void)
294 struct RNAinverse_cmdline_parser_params *params =
295 (struct RNAinverse_cmdline_parser_params *)malloc(sizeof(struct RNAinverse_cmdline_parser_params));
296 RNAinverse_cmdline_parser_params_init(params);
301 free_string_field (char **s)
312 RNAinverse_cmdline_parser_release (struct RNAinverse_args_info *args_info)
315 free_string_field (&(args_info->repeat_orig));
316 free_string_field (&(args_info->alphabet_arg));
317 free_string_field (&(args_info->alphabet_orig));
318 free_string_field (&(args_info->function_arg));
319 free_string_field (&(args_info->function_orig));
320 free_string_field (&(args_info->final_orig));
321 free_string_field (&(args_info->temp_orig));
322 free_string_field (&(args_info->dangles_orig));
323 free_string_field (&(args_info->paramFile_arg));
324 free_string_field (&(args_info->paramFile_orig));
325 free_string_field (&(args_info->nsp_arg));
326 free_string_field (&(args_info->nsp_orig));
327 free_string_field (&(args_info->energyModel_orig));
331 clear_given (args_info);
336 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
340 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
342 fprintf(outfile, "%s\n", opt);
348 RNAinverse_cmdline_parser_dump(FILE *outfile, struct RNAinverse_args_info *args_info)
354 fprintf (stderr, "%s: cannot dump options to stream\n", RNAINVERSE_CMDLINE_PARSER_PACKAGE);
358 if (args_info->help_given)
359 write_into_file(outfile, "help", 0, 0 );
360 if (args_info->detailed_help_given)
361 write_into_file(outfile, "detailed-help", 0, 0 );
362 if (args_info->full_help_given)
363 write_into_file(outfile, "full-help", 0, 0 );
364 if (args_info->version_given)
365 write_into_file(outfile, "version", 0, 0 );
366 if (args_info->repeat_given)
367 write_into_file(outfile, "repeat", args_info->repeat_orig, 0);
368 if (args_info->alphabet_given)
369 write_into_file(outfile, "alphabet", args_info->alphabet_orig, 0);
370 if (args_info->verbose_given)
371 write_into_file(outfile, "verbose", 0, 0 );
372 if (args_info->function_given)
373 write_into_file(outfile, "function", args_info->function_orig, 0);
374 if (args_info->final_given)
375 write_into_file(outfile, "final", args_info->final_orig, 0);
376 if (args_info->temp_given)
377 write_into_file(outfile, "temp", args_info->temp_orig, 0);
378 if (args_info->noTetra_given)
379 write_into_file(outfile, "noTetra", 0, 0 );
380 if (args_info->dangles_given)
381 write_into_file(outfile, "dangles", args_info->dangles_orig, 0);
382 if (args_info->noGU_given)
383 write_into_file(outfile, "noGU", 0, 0 );
384 if (args_info->noClosingGU_given)
385 write_into_file(outfile, "noClosingGU", 0, 0 );
386 if (args_info->paramFile_given)
387 write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
388 if (args_info->nsp_given)
389 write_into_file(outfile, "nsp", args_info->nsp_orig, 0);
390 if (args_info->energyModel_given)
391 write_into_file(outfile, "energyModel", args_info->energyModel_orig, 0);
399 RNAinverse_cmdline_parser_file_save(const char *filename, struct RNAinverse_args_info *args_info)
404 outfile = fopen(filename, "w");
408 fprintf (stderr, "%s: cannot open file for writing: %s\n", RNAINVERSE_CMDLINE_PARSER_PACKAGE, filename);
412 i = RNAinverse_cmdline_parser_dump(outfile, args_info);
419 RNAinverse_cmdline_parser_free (struct RNAinverse_args_info *args_info)
421 RNAinverse_cmdline_parser_release (args_info);
424 /** @brief replacement of strdup, which is not standard */
426 gengetopt_strdup (const char *s)
432 result = (char*)malloc(strlen(s) + 1);
433 if (result == (char*)0)
440 RNAinverse_cmdline_parser (int argc, char **argv, struct RNAinverse_args_info *args_info)
442 return RNAinverse_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
446 RNAinverse_cmdline_parser_ext (int argc, char **argv, struct RNAinverse_args_info *args_info,
447 struct RNAinverse_cmdline_parser_params *params)
450 result = RNAinverse_cmdline_parser_internal (argc, argv, args_info, params, 0);
452 if (result == EXIT_FAILURE)
454 RNAinverse_cmdline_parser_free (args_info);
462 RNAinverse_cmdline_parser2 (int argc, char **argv, struct RNAinverse_args_info *args_info, int override, int initialize, int check_required)
465 struct RNAinverse_cmdline_parser_params params;
467 params.override = override;
468 params.initialize = initialize;
469 params.check_required = check_required;
470 params.check_ambiguity = 0;
471 params.print_errors = 1;
473 result = RNAinverse_cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
475 if (result == EXIT_FAILURE)
477 RNAinverse_cmdline_parser_free (args_info);
485 RNAinverse_cmdline_parser_required (struct RNAinverse_args_info *args_info, const char *prog_name)
487 FIX_UNUSED (args_info);
488 FIX_UNUSED (prog_name);
493 * Extracted from the glibc source tree, version 2.3.6
495 * Licensed under the GPL as per the whole glibc source tree.
497 * This file was modified so that getopt_long can be called
498 * many times without risking previous memory to be spoiled.
500 * Modified by Andre Noll and Lorenzo Bettini for use in
501 * GNU gengetopt generated files.
506 * we must include anything we need since this file is not thought to be
507 * inserted in a file already using getopt.h
515 /* has_arg can't be an enum because some compilers complain about
516 type mismatches in all the code that assumes it is an int. */
522 /* This version of `getopt' appears to the caller like standard Unix `getopt'
523 but it behaves differently for the user, since it allows the user
524 to intersperse the options with the other arguments.
526 As `getopt' works, it permutes the elements of ARGV so that,
527 when it is done, all the options precede everything else. Thus
528 all application programs are extended to handle flexible argument order.
531 If the field `flag' is not NULL, it points to a variable that is set
532 to the value given in the field `val' when the option is found, but
533 left unchanged if the option is not found.
535 To have a long-named option do something other than set an `int' to
536 a compiled-in constant, such as set a value from `custom_optarg', set the
537 option's `flag' field to zero and its `val' field to a nonzero
538 value (the equivalent single-letter option character, if there is
539 one). For long options that have a zero `flag' field, `getopt'
540 returns the contents of the `val' field. */
542 /* Names for the values of the `has_arg' field of `struct option'. */
544 #define no_argument 0
547 #ifndef required_argument
548 #define required_argument 1
551 #ifndef optional_argument
552 #define optional_argument 2
555 struct custom_getopt_data {
557 * These have exactly the same meaning as the corresponding global variables,
558 * except that they are used for the reentrant versions of getopt.
565 /* True if the internal members have been initialized. */
569 * The next char to be scanned in the option-element in which the last option
570 * character we returned was found. This allows us to pick up the scan where
571 * we left off. If this is zero, or a null string, it means resume the scan by
572 * advancing to the next ARGV-element.
577 * Describe the part of ARGV that contains non-options that have been skipped.
578 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
579 * the index after the last of them.
586 * the variables optarg, optind, opterr and optopt are renamed with
587 * the custom_ prefix so that they don't interfere with getopt ones.
589 * Moreover they're static so they are visible only from within the
590 * file where this very file will be included.
594 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
595 * option that takes an argument, the argument value is returned here.
597 static char *custom_optarg;
600 * Index in ARGV of the next element to be scanned. This is used for
601 * communication to and from the caller and for communication between
602 * successive calls to `custom_getopt'.
604 * On entry to `custom_getopt', 1 means this is the first call; initialize.
606 * When `custom_getopt' returns -1, this is the index of the first of the non-option
607 * elements that the caller should itself scan.
609 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
610 * has been scanned so far.
612 * 1003.2 says this must be 1 before any call.
614 static int custom_optind = 1;
617 * Callers store zero here to inhibit the error message for unrecognized
620 static int custom_opterr = 1;
623 * Set to an option character which was unrecognized. This must be initialized
624 * on some systems to avoid linking in the system's own getopt implementation.
626 static int custom_optopt = '?';
629 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
630 * [first_nonopt,last_nonopt) which contains all the non-options that have been
631 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
632 * all the options processed since those non-options were skipped.
633 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
634 * indices of the non-options in ARGV after they are moved.
636 static void exchange(char **argv, struct custom_getopt_data *d)
638 int bottom = d->first_nonopt;
639 int middle = d->last_nonopt;
640 int top = d->custom_optind;
644 * Exchange the shorter segment with the far end of the longer segment.
645 * That puts the shorter segment into the right place. It leaves the
646 * longer segment in the right place overall, but it consists of two
647 * parts that need to be swapped next.
649 while (top > middle && middle > bottom) {
650 if (top - middle > middle - bottom) {
651 /* Bottom segment is the short one. */
652 int len = middle - bottom;
655 /* Swap it with the top part of the top segment. */
656 for (i = 0; i < len; i++) {
657 tem = argv[bottom + i];
659 argv[top - (middle - bottom) + i];
660 argv[top - (middle - bottom) + i] = tem;
662 /* Exclude the moved bottom segment from further swapping. */
665 /* Top segment is the short one. */
666 int len = top - middle;
669 /* Swap it with the bottom part of the bottom segment. */
670 for (i = 0; i < len; i++) {
671 tem = argv[bottom + i];
672 argv[bottom + i] = argv[middle + i];
673 argv[middle + i] = tem;
675 /* Exclude the moved top segment from further swapping. */
679 /* Update records for the slots the non-options now occupy. */
680 d->first_nonopt += (d->custom_optind - d->last_nonopt);
681 d->last_nonopt = d->custom_optind;
684 /* Initialize the internal data when the first call is made. */
685 static void custom_getopt_initialize(struct custom_getopt_data *d)
688 * Start processing options with ARGV-element 1 (since ARGV-element 0
689 * is the program name); the sequence of previously skipped non-option
690 * ARGV-elements is empty.
692 d->first_nonopt = d->last_nonopt = d->custom_optind;
697 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
699 /* return: zero: continue, nonzero: return given value to user */
700 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
701 struct custom_getopt_data *d)
704 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
705 * moved back by the user (who may also have changed the arguments).
707 if (d->last_nonopt > d->custom_optind)
708 d->last_nonopt = d->custom_optind;
709 if (d->first_nonopt > d->custom_optind)
710 d->first_nonopt = d->custom_optind;
712 * If we have just processed some options following some
713 * non-options, exchange them so that the options come first.
715 if (d->first_nonopt != d->last_nonopt &&
716 d->last_nonopt != d->custom_optind)
717 exchange((char **) argv, d);
718 else if (d->last_nonopt != d->custom_optind)
719 d->first_nonopt = d->custom_optind;
721 * Skip any additional non-options and extend the range of
722 * non-options previously skipped.
724 while (d->custom_optind < argc && NONOPTION_P)
726 d->last_nonopt = d->custom_optind;
728 * The special ARGV-element `--' means premature end of options. Skip
729 * it like a null option, then exchange with previous non-options as if
730 * it were an option, then skip everything else like a non-option.
732 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
734 if (d->first_nonopt != d->last_nonopt
735 && d->last_nonopt != d->custom_optind)
736 exchange((char **) argv, d);
737 else if (d->first_nonopt == d->last_nonopt)
738 d->first_nonopt = d->custom_optind;
739 d->last_nonopt = argc;
740 d->custom_optind = argc;
743 * If we have done all the ARGV-elements, stop the scan and back over
744 * any non-options that we skipped and permuted.
746 if (d->custom_optind == argc) {
748 * Set the next-arg-index to point at the non-options that we
749 * previously skipped, so the caller will digest them.
751 if (d->first_nonopt != d->last_nonopt)
752 d->custom_optind = d->first_nonopt;
756 * If we have come to a non-option and did not permute it, either stop
757 * the scan or describe it to the caller and pass it by.
760 d->custom_optarg = argv[d->custom_optind++];
764 * We have found another option-ARGV-element. Skip the initial
767 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
772 * Check whether the ARGV-element is a long option.
774 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
775 * that an abbreviation of the long option, just like "--fu", and not "-f" with
778 * This distinction seems to be the most useful approach.
781 static int check_long_opt(int argc, char *const *argv, const char *optstring,
782 const struct option *longopts, int *longind,
783 int print_errors, struct custom_getopt_data *d)
786 const struct option *p;
787 const struct option *pfound = NULL;
793 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
796 /* Test all long options for either exact match or abbreviated matches */
797 for (p = longopts, option_index = 0; p->name; p++, option_index++)
798 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
799 if ((unsigned int) (nameend - d->nextchar)
800 == (unsigned int) strlen(p->name)) {
801 /* Exact match found. */
803 indfound = option_index;
806 } else if (pfound == NULL) {
807 /* First nonexact match found. */
809 indfound = option_index;
810 } else if (pfound->has_arg != p->has_arg
811 || pfound->flag != p->flag
812 || pfound->val != p->val)
813 /* Second or later nonexact match found. */
816 if (ambig && !exact) {
819 "%s: option `%s' is ambiguous\n",
820 argv[0], argv[d->custom_optind]);
822 d->nextchar += strlen(d->nextchar);
824 d->custom_optopt = 0;
828 option_index = indfound;
831 if (pfound->has_arg != no_argument)
832 d->custom_optarg = nameend + 1;
835 if (argv[d->custom_optind - 1][1] == '-') {
837 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
838 argv[0], pfound->name);
840 /* +option or -option */
841 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
842 argv[0], argv[d->custom_optind - 1][0], pfound->name);
846 d->nextchar += strlen(d->nextchar);
847 d->custom_optopt = pfound->val;
850 } else if (pfound->has_arg == required_argument) {
851 if (d->custom_optind < argc)
852 d->custom_optarg = argv[d->custom_optind++];
856 "%s: option `%s' requires an argument\n",
858 argv[d->custom_optind - 1]);
860 d->nextchar += strlen(d->nextchar);
861 d->custom_optopt = pfound->val;
862 return optstring[0] == ':' ? ':' : '?';
865 d->nextchar += strlen(d->nextchar);
867 *longind = option_index;
869 *(pfound->flag) = pfound->val;
875 * Can't find it as a long option. If this is not getopt_long_only, or
876 * the option starts with '--' or is not a valid short option, then
877 * it's an error. Otherwise interpret it as a short option.
880 if (argv[d->custom_optind][1] == '-') {
883 "%s: unrecognized option `--%s'\n",
884 argv[0], d->nextchar);
886 /* +option or -option */
888 "%s: unrecognized option `%c%s'\n",
889 argv[0], argv[d->custom_optind][0],
893 d->nextchar = (char *) "";
895 d->custom_optopt = 0;
899 static int check_short_opt(int argc, char *const *argv, const char *optstring,
900 int print_errors, struct custom_getopt_data *d)
902 char c = *d->nextchar++;
903 const char *temp = strchr(optstring, c);
905 /* Increment `custom_optind' when we start to process its last character. */
906 if (*d->nextchar == '\0')
908 if (!temp || c == ':') {
910 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
912 d->custom_optopt = c;
915 if (temp[1] == ':') {
916 if (temp[2] == ':') {
917 /* This is an option that accepts an argument optionally. */
918 if (*d->nextchar != '\0') {
919 d->custom_optarg = d->nextchar;
922 d->custom_optarg = NULL;
925 /* This is an option that requires an argument. */
926 if (*d->nextchar != '\0') {
927 d->custom_optarg = d->nextchar;
929 * If we end this ARGV-element by taking the
930 * rest as an arg, we must advance to the next
934 } else if (d->custom_optind == argc) {
937 "%s: option requires an argument -- %c\n",
940 d->custom_optopt = c;
941 if (optstring[0] == ':')
947 * We already incremented `custom_optind' once;
948 * increment it again when taking next ARGV-elt
951 d->custom_optarg = argv[d->custom_optind++];
959 * Scan elements of ARGV for option characters given in OPTSTRING.
961 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
962 * then it is an option element. The characters of this element
963 * (aside from the initial '-') are option characters. If `getopt'
964 * is called repeatedly, it returns successively each of the option characters
965 * from each of the option elements.
967 * If `getopt' finds another option character, it returns that character,
968 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
969 * resume the scan with the following option character or ARGV-element.
971 * If there are no more option characters, `getopt' returns -1.
972 * Then `custom_optind' is the index in ARGV of the first ARGV-element
973 * that is not an option. (The ARGV-elements have been permuted
974 * so that those that are not options now come last.)
976 * OPTSTRING is a string containing the legitimate option characters.
977 * If an option character is seen that is not listed in OPTSTRING,
978 * return '?' after printing an error message. If you set `custom_opterr' to
979 * zero, the error message is suppressed but we still return '?'.
981 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
982 * so the following text in the same ARGV-element, or the text of the following
983 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
984 * wants an optional arg; if there is text in the current ARGV-element,
985 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
987 * If OPTSTRING starts with `-' or `+', it requests different methods of
988 * handling the non-option ARGV-elements.
989 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
991 * Long-named options begin with `--' instead of `-'.
992 * Their names may be abbreviated as long as the abbreviation is unique
993 * or is an exact match for some defined option. If they have an
994 * argument, it follows the option name in the same ARGV-element, separated
995 * from the option name by a `=', or else the in next ARGV-element.
996 * When `getopt' finds a long-named option, it returns 0 if that option's
997 * `flag' field is nonzero, the value of the option's `val' field
998 * if the `flag' field is zero.
1000 * The elements of ARGV aren't really const, because we permute them.
1001 * But we pretend they're const in the prototype to be compatible
1002 * with other systems.
1004 * LONGOPTS is a vector of `struct option' terminated by an
1005 * element containing a name which is zero.
1007 * LONGIND returns the index in LONGOPT of the long-named option found.
1008 * It is only valid when a long-named option has been found by the most
1011 * Return the option character from OPTS just read. Return -1 when there are
1012 * no more options. For unrecognized options, or options missing arguments,
1013 * `custom_optopt' is set to the option letter, and '?' is returned.
1015 * The OPTS string is a list of characters which are recognized option letters,
1016 * optionally followed by colons, specifying that that letter takes an
1017 * argument, to be placed in `custom_optarg'.
1019 * If a letter in OPTS is followed by two colons, its argument is optional.
1020 * This behavior is specific to the GNU `getopt'.
1022 * The argument `--' causes premature termination of argument scanning,
1023 * explicitly telling `getopt' that there are no more options. If OPTS begins
1024 * with `--', then non-option arguments are treated as arguments to the option
1025 * '\0'. This behavior is specific to the GNU `getopt'.
1028 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1029 const struct option *longopts, int *longind,
1030 struct custom_getopt_data *d)
1032 int ret, print_errors = d->custom_opterr;
1034 if (optstring[0] == ':')
1038 d->custom_optarg = NULL;
1041 * This is a big difference with GNU getopt, since optind == 0
1042 * means initialization while here 1 means first call.
1044 if (d->custom_optind == 0 || !d->initialized) {
1045 if (d->custom_optind == 0)
1046 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
1047 custom_getopt_initialize(d);
1049 if (d->nextchar == NULL || *d->nextchar == '\0') {
1050 ret = shuffle_argv(argc, argv, longopts, d);
1054 if (longopts && (argv[d->custom_optind][1] == '-' ))
1055 return check_long_opt(argc, argv, optstring, longopts,
1056 longind, print_errors, d);
1057 return check_short_opt(argc, argv, optstring, print_errors, d);
1060 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1061 const struct option *longopts, int *longind)
1064 /* Keep a global copy of all internal members of d */
1065 static struct custom_getopt_data d;
1067 d.custom_optind = custom_optind;
1068 d.custom_opterr = custom_opterr;
1069 result = getopt_internal_r(argc, argv, optstring, longopts,
1071 custom_optind = d.custom_optind;
1072 custom_optarg = d.custom_optarg;
1073 custom_optopt = d.custom_optopt;
1077 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1078 const struct option *long_options, int *opt_index)
1080 return custom_getopt_internal(argc, argv, options, long_options,
1085 static char *package_name = 0;
1088 * @brief updates an option
1089 * @param field the generic pointer to the field to update
1090 * @param orig_field the pointer to the orig field
1091 * @param field_given the pointer to the number of occurrence of this option
1092 * @param prev_given the pointer to the number of occurrence already seen
1093 * @param value the argument for this option (if null no arg was specified)
1094 * @param possible_values the possible values for this option (if specified)
1095 * @param default_value the default value (in case the option only accepts fixed values)
1096 * @param arg_type the type of this option
1097 * @param check_ambiguity @see RNAinverse_cmdline_parser_params.check_ambiguity
1098 * @param override @see RNAinverse_cmdline_parser_params.override
1099 * @param no_free whether to free a possible previous value
1100 * @param multiple_option whether this is a multiple option
1101 * @param long_opt the corresponding long option
1102 * @param short_opt the corresponding short option (or '-' if none)
1103 * @param additional_error possible further error specification
1106 int update_arg(void *field, char **orig_field,
1107 unsigned int *field_given, unsigned int *prev_given,
1108 char *value, const char *possible_values[],
1109 const char *default_value,
1110 RNAinverse_cmdline_parser_arg_type arg_type,
1111 int check_ambiguity, int override,
1112 int no_free, int multiple_option,
1113 const char *long_opt, char short_opt,
1114 const char *additional_error)
1116 char *stop_char = 0;
1117 const char *val = value;
1119 char **string_field;
1125 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1127 if (short_opt != '-')
1128 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1129 package_name, long_opt, short_opt,
1130 (additional_error ? additional_error : ""));
1132 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1133 package_name, long_opt,
1134 (additional_error ? additional_error : ""));
1135 return 1; /* failure */
1138 FIX_UNUSED (default_value);
1140 if (field_given && *field_given && ! override)
1146 if (possible_values)
1147 val = possible_values[found];
1151 *((int *)field) = !*((int *)field);
1154 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1157 if (val) *((float *)field) = (float)strtod (val, &stop_char);
1160 if (val) *((double *)field) = strtod (val, &stop_char);
1164 string_field = (char **)field;
1165 if (!no_free && *string_field)
1166 free (*string_field); /* free previous string */
1167 *string_field = gengetopt_strdup (val);
1174 /* check numeric conversion */
1179 if (val && !(stop_char && *stop_char == '\0')) {
1180 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1181 return 1; /* failure */
1188 /* store the original value */
1194 if (value && orig_field) {
1196 *orig_field = value;
1199 free (*orig_field); /* free previous string */
1200 *orig_field = gengetopt_strdup (value);
1210 RNAinverse_cmdline_parser_internal (
1211 int argc, char **argv, struct RNAinverse_args_info *args_info,
1212 struct RNAinverse_cmdline_parser_params *params, const char *additional_error)
1214 int c; /* Character of the parsed option. */
1217 struct RNAinverse_args_info local_args_info;
1222 int check_ambiguity;
1229 package_name = argv[0];
1231 override = params->override;
1232 initialize = params->initialize;
1233 check_required = params->check_required;
1234 check_ambiguity = params->check_ambiguity;
1237 RNAinverse_cmdline_parser_init (args_info);
1239 RNAinverse_cmdline_parser_init (&local_args_info);
1243 opterr = params->print_errors;
1248 int option_index = 0;
1250 static struct option long_options[] = {
1251 { "help", 0, NULL, 'h' },
1252 { "detailed-help", 0, NULL, 0 },
1253 { "full-help", 0, NULL, 0 },
1254 { "version", 0, NULL, 'V' },
1255 { "repeat", 2, NULL, 'R' },
1256 { "alphabet", 1, NULL, 'a' },
1257 { "verbose", 0, NULL, 'v' },
1258 { "function", 1, NULL, 'F' },
1259 { "final", 1, NULL, 'f' },
1260 { "temp", 1, NULL, 'T' },
1261 { "noTetra", 0, NULL, '4' },
1262 { "dangles", 1, NULL, 'd' },
1263 { "noGU", 0, NULL, 0 },
1264 { "noClosingGU", 0, NULL, 0 },
1265 { "paramFile", 1, NULL, 'P' },
1266 { "nsp", 1, NULL, 0 },
1267 { "energyModel", 1, NULL, 'e' },
1271 custom_optarg = optarg;
1272 custom_optind = optind;
1273 custom_opterr = opterr;
1274 custom_optopt = optopt;
1276 c = custom_getopt_long (argc, argv, "hVR::a:vF:f:T:4d:P:e:", long_options, &option_index);
1278 optarg = custom_optarg;
1279 optind = custom_optind;
1280 opterr = custom_opterr;
1281 optopt = custom_optopt;
1283 if (c == -1) break; /* Exit from `while (1)' loop. */
1287 case 'h': /* Print help and exit. */
1288 RNAinverse_cmdline_parser_print_help ();
1289 RNAinverse_cmdline_parser_free (&local_args_info);
1290 exit (EXIT_SUCCESS);
1292 case 'V': /* Print version and exit. */
1293 RNAinverse_cmdline_parser_print_version ();
1294 RNAinverse_cmdline_parser_free (&local_args_info);
1295 exit (EXIT_SUCCESS);
1297 case 'R': /* Search repeatedly for the same structure.
1298 If an argument is supplied to this option it must follow the option flag immediately. E.g.: -R5
1302 if (update_arg( (void *)&(args_info->repeat_arg),
1303 &(args_info->repeat_orig), &(args_info->repeat_given),
1304 &(local_args_info.repeat_given), optarg, 0, "100", ARG_INT,
1305 check_ambiguity, override, 0, 0,
1311 case 'a': /* Find sequences using only nucleotides from a given alphabet.
1316 if (update_arg( (void *)&(args_info->alphabet_arg),
1317 &(args_info->alphabet_orig), &(args_info->alphabet_given),
1318 &(local_args_info.alphabet_given), optarg, 0, 0, ARG_STRING,
1319 check_ambiguity, override, 0, 0,
1325 case 'v': /* In conjunction with a negative value supplied to -R, print the last subsequence and substructure for each unsuccessful search.
1330 if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
1331 &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
1332 check_ambiguity, override, 1, 0, "verbose", 'v',
1337 case 'F': /* Use minimum energy (-Fm), partition function folding (-Fp) or both (-Fmp).
1341 if (update_arg( (void *)&(args_info->function_arg),
1342 &(args_info->function_orig), &(args_info->function_given),
1343 &(local_args_info.function_given), optarg, 0, "m", ARG_STRING,
1344 check_ambiguity, override, 0, 0,
1350 case 'f': /* In combination with -Fp stop search when sequence is found with E(s)-F is smaller than final, where F=-kT*ln(Q).
1355 if (update_arg( (void *)&(args_info->final_arg),
1356 &(args_info->final_orig), &(args_info->final_given),
1357 &(local_args_info.final_given), optarg, 0, 0, ARG_FLOAT,
1358 check_ambiguity, override, 0, 0,
1364 case 'T': /* Rescale energy parameters to a temperature of temp C. Default is 37C.
1369 if (update_arg( (void *)&(args_info->temp_arg),
1370 &(args_info->temp_orig), &(args_info->temp_given),
1371 &(local_args_info.temp_given), optarg, 0, 0, ARG_DOUBLE,
1372 check_ambiguity, override, 0, 0,
1378 case '4': /* Do not include special tabulated stabilizing energies for tri-, tetra- and hexaloop hairpins. Mostly for testing.
1383 if (update_arg((void *)&(args_info->noTetra_flag), 0, &(args_info->noTetra_given),
1384 &(local_args_info.noTetra_given), optarg, 0, 0, ARG_FLAG,
1385 check_ambiguity, override, 1, 0, "noTetra", '4',
1390 case 'd': /* How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops
1394 if (update_arg( (void *)&(args_info->dangles_arg),
1395 &(args_info->dangles_orig), &(args_info->dangles_given),
1396 &(local_args_info.dangles_given), optarg, 0, "2", ARG_INT,
1397 check_ambiguity, override, 0, 0,
1403 case 'P': /* Read energy parameters from paramfile, instead of using the default parameter set.
1407 if (update_arg( (void *)&(args_info->paramFile_arg),
1408 &(args_info->paramFile_orig), &(args_info->paramFile_given),
1409 &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1410 check_ambiguity, override, 0, 0,
1416 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.
1421 if (update_arg( (void *)&(args_info->energyModel_arg),
1422 &(args_info->energyModel_orig), &(args_info->energyModel_given),
1423 &(local_args_info.energyModel_given), optarg, 0, 0, ARG_INT,
1424 check_ambiguity, override, 0, 0,
1431 case 0: /* Long option with no short option */
1432 if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1433 RNAinverse_cmdline_parser_print_detailed_help ();
1434 RNAinverse_cmdline_parser_free (&local_args_info);
1435 exit (EXIT_SUCCESS);
1438 if (strcmp (long_options[option_index].name, "full-help") == 0) {
1439 RNAinverse_cmdline_parser_print_full_help ();
1440 RNAinverse_cmdline_parser_free (&local_args_info);
1441 exit (EXIT_SUCCESS);
1444 /* Do not allow GU pairs
1447 if (strcmp (long_options[option_index].name, "noGU") == 0)
1451 if (update_arg((void *)&(args_info->noGU_flag), 0, &(args_info->noGU_given),
1452 &(local_args_info.noGU_given), optarg, 0, 0, ARG_FLAG,
1453 check_ambiguity, override, 1, 0, "noGU", '-',
1458 /* Do not allow GU pairs at the end of helices
1461 else if (strcmp (long_options[option_index].name, "noClosingGU") == 0)
1465 if (update_arg((void *)&(args_info->noClosingGU_flag), 0, &(args_info->noClosingGU_given),
1466 &(local_args_info.noClosingGU_given), optarg, 0, 0, ARG_FLAG,
1467 check_ambiguity, override, 1, 0, "noClosingGU", '-',
1472 /* Allow other pairs in addition to the usual AU,GC,and GU pairs.
1474 else if (strcmp (long_options[option_index].name, "nsp") == 0)
1478 if (update_arg( (void *)&(args_info->nsp_arg),
1479 &(args_info->nsp_orig), &(args_info->nsp_given),
1480 &(local_args_info.nsp_given), optarg, 0, 0, ARG_STRING,
1481 check_ambiguity, override, 0, 0,
1489 case '?': /* Invalid option. */
1490 /* `getopt_long' already printed an error message. */
1493 default: /* bug: option not considered. */
1494 fprintf (stderr, "%s: option unknown: %c%s\n", RNAINVERSE_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1502 RNAinverse_cmdline_parser_release (&local_args_info);
1505 return (EXIT_FAILURE);
1511 RNAinverse_cmdline_parser_release (&local_args_info);
1512 return (EXIT_FAILURE);