2 File autogenerated by gengetopt version 2.22.5
3 generated with the following command:
4 gengetopt -i RNALfold.ggo --file-name=RNALfold_cmdl --include-getopt --default-optional --func-name=RNALfold_cmdline_parser --arg-struct-name=RNALfold_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 "RNALfold_cmdl.h"
27 const char *RNALfold_args_info_purpose = "calculate locally stable secondary structures of RNAs";
29 const char *RNALfold_args_info_usage = "Usage: RNALfold [OPTIONS]...";
31 const char *RNALfold_args_info_description = "Compute locally stable RNA secondary structure with a maximal base pair span. \nFor a sequence of length n and a base pair span of L the algorithm uses only \nO(n+L*L) memory and O(n*L*L) CPU time. Thus it is practical to \"scan\" very \nlarge genomes for short RNA structures.\nOutput consists of a list of secondary structure components of size <= L, one \nentry per line. Each output line contains the predicted local structure its \nenergy in kcal/mol and the starting position of the local structure.\n";
33 const char *RNALfold_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 " -L, --span=INT Set the maximum allowed separation of a base pair \n to span. I.e. no pairs (i,j) with j-i>span will \n be allowed.\n\n (default=`150')",
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 The Minimum free energy (MFE) and a structure representative are calculated \n in any case.\n\n",
44 " -z, --zscore[=DOUBLE] Activate z-score computation. An optional argument \n may be supplied to set the threshold\n Due to parsing the commandline parameters a \n negative value should be given immediately after \n \"z\" without spaces e.g. -z-4.9\n\n (default=`-2')",
45 " -g, --gquad Incoorporate G-Quadruplex formation into the \n structure prediction algorithm\n (default=off)",
47 " -T, --temp=DOUBLE Rescale energy parameters to a temperature of temp \n C. Default is 37C.\n\n",
48 " -4, --noTetra Do not include special tabulated stabilizing \n energies for tri-, tetra- and hexaloop hairpins. \n Mostly for testing.\n\n (default=off)",
49 " -d, --dangles=INT How to treat \"dangling end\" energies for bases \n adjacent to helices in free ends and multi-loops\n (default=`2')",
50 " \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",
51 " --noLP Produce structures without lonely pairs (helices \n of length 1).\n (default=off)",
52 " 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",
53 " --noGU Do not allow GU pairs\n\n (default=off)",
54 " --noClosingGU Do not allow GU pairs at the end of helices\n\n (default=off)",
55 " -P, --paramFile=paramfile Read energy parameters from paramfile, instead of \n using the default parameter set.\n",
56 " A sample parameter file should accompany your distribution.\n See the RNAlib documentation for details on the file format.\n\n",
57 " --nsp=STRING Allow other pairs in addition to the usual \n AU,GC,and GU pairs.\n",
58 " 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",
59 " -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",
60 "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
64 init_full_help_array(void)
66 RNALfold_args_info_full_help[0] = RNALfold_args_info_detailed_help[0];
67 RNALfold_args_info_full_help[1] = RNALfold_args_info_detailed_help[1];
68 RNALfold_args_info_full_help[2] = RNALfold_args_info_detailed_help[2];
69 RNALfold_args_info_full_help[3] = RNALfold_args_info_detailed_help[3];
70 RNALfold_args_info_full_help[4] = RNALfold_args_info_detailed_help[4];
71 RNALfold_args_info_full_help[5] = RNALfold_args_info_detailed_help[5];
72 RNALfold_args_info_full_help[6] = RNALfold_args_info_detailed_help[6];
73 RNALfold_args_info_full_help[7] = RNALfold_args_info_detailed_help[7];
74 RNALfold_args_info_full_help[8] = RNALfold_args_info_detailed_help[8];
75 RNALfold_args_info_full_help[9] = RNALfold_args_info_detailed_help[9];
76 RNALfold_args_info_full_help[10] = RNALfold_args_info_detailed_help[10];
77 RNALfold_args_info_full_help[11] = RNALfold_args_info_detailed_help[11];
78 RNALfold_args_info_full_help[12] = RNALfold_args_info_detailed_help[12];
79 RNALfold_args_info_full_help[13] = RNALfold_args_info_detailed_help[13];
80 RNALfold_args_info_full_help[14] = RNALfold_args_info_detailed_help[14];
81 RNALfold_args_info_full_help[15] = RNALfold_args_info_detailed_help[15];
82 RNALfold_args_info_full_help[16] = RNALfold_args_info_detailed_help[17];
83 RNALfold_args_info_full_help[17] = RNALfold_args_info_detailed_help[19];
84 RNALfold_args_info_full_help[18] = RNALfold_args_info_detailed_help[20];
85 RNALfold_args_info_full_help[19] = RNALfold_args_info_detailed_help[21];
86 RNALfold_args_info_full_help[20] = RNALfold_args_info_detailed_help[23];
87 RNALfold_args_info_full_help[21] = RNALfold_args_info_detailed_help[25];
88 RNALfold_args_info_full_help[22] = RNALfold_args_info_detailed_help[26];
89 RNALfold_args_info_full_help[23] = 0;
93 const char *RNALfold_args_info_full_help[24];
98 RNALfold_args_info_help[0] = RNALfold_args_info_detailed_help[0];
99 RNALfold_args_info_help[1] = RNALfold_args_info_detailed_help[1];
100 RNALfold_args_info_help[2] = RNALfold_args_info_detailed_help[2];
101 RNALfold_args_info_help[3] = RNALfold_args_info_detailed_help[3];
102 RNALfold_args_info_help[4] = RNALfold_args_info_detailed_help[4];
103 RNALfold_args_info_help[5] = RNALfold_args_info_detailed_help[5];
104 RNALfold_args_info_help[6] = RNALfold_args_info_detailed_help[6];
105 RNALfold_args_info_help[7] = RNALfold_args_info_detailed_help[7];
106 RNALfold_args_info_help[8] = RNALfold_args_info_detailed_help[8];
107 RNALfold_args_info_help[9] = RNALfold_args_info_detailed_help[9];
108 RNALfold_args_info_help[10] = RNALfold_args_info_detailed_help[10];
109 RNALfold_args_info_help[11] = RNALfold_args_info_detailed_help[11];
110 RNALfold_args_info_help[12] = RNALfold_args_info_detailed_help[12];
111 RNALfold_args_info_help[13] = RNALfold_args_info_detailed_help[13];
112 RNALfold_args_info_help[14] = RNALfold_args_info_detailed_help[14];
113 RNALfold_args_info_help[15] = RNALfold_args_info_detailed_help[15];
114 RNALfold_args_info_help[16] = RNALfold_args_info_detailed_help[17];
115 RNALfold_args_info_help[17] = RNALfold_args_info_detailed_help[19];
116 RNALfold_args_info_help[18] = RNALfold_args_info_detailed_help[20];
117 RNALfold_args_info_help[19] = RNALfold_args_info_detailed_help[21];
118 RNALfold_args_info_help[20] = RNALfold_args_info_detailed_help[26];
119 RNALfold_args_info_help[21] = 0;
123 const char *RNALfold_args_info_help[22];
130 } RNALfold_cmdline_parser_arg_type;
133 void clear_given (struct RNALfold_args_info *args_info);
135 void clear_args (struct RNALfold_args_info *args_info);
138 RNALfold_cmdline_parser_internal (int argc, char **argv, struct RNALfold_args_info *args_info,
139 struct RNALfold_cmdline_parser_params *params, const char *additional_error);
143 gengetopt_strdup (const char *s);
146 void clear_given (struct RNALfold_args_info *args_info)
148 args_info->help_given = 0 ;
149 args_info->detailed_help_given = 0 ;
150 args_info->full_help_given = 0 ;
151 args_info->version_given = 0 ;
152 args_info->span_given = 0 ;
153 args_info->noconv_given = 0 ;
154 args_info->zscore_given = 0 ;
155 args_info->gquad_given = 0 ;
156 args_info->temp_given = 0 ;
157 args_info->noTetra_given = 0 ;
158 args_info->dangles_given = 0 ;
159 args_info->noLP_given = 0 ;
160 args_info->noGU_given = 0 ;
161 args_info->noClosingGU_given = 0 ;
162 args_info->paramFile_given = 0 ;
163 args_info->nsp_given = 0 ;
164 args_info->energyModel_given = 0 ;
168 void clear_args (struct RNALfold_args_info *args_info)
170 FIX_UNUSED (args_info);
171 args_info->span_arg = 150;
172 args_info->span_orig = NULL;
173 args_info->noconv_flag = 0;
174 args_info->zscore_arg = -2;
175 args_info->zscore_orig = NULL;
176 args_info->gquad_flag = 0;
177 args_info->temp_orig = NULL;
178 args_info->noTetra_flag = 0;
179 args_info->dangles_arg = 2;
180 args_info->dangles_orig = NULL;
181 args_info->noLP_flag = 0;
182 args_info->noGU_flag = 0;
183 args_info->noClosingGU_flag = 0;
184 args_info->paramFile_arg = NULL;
185 args_info->paramFile_orig = NULL;
186 args_info->nsp_arg = NULL;
187 args_info->nsp_orig = NULL;
188 args_info->energyModel_orig = NULL;
193 void init_args_info(struct RNALfold_args_info *args_info)
195 init_full_help_array();
197 args_info->help_help = RNALfold_args_info_detailed_help[0] ;
198 args_info->detailed_help_help = RNALfold_args_info_detailed_help[1] ;
199 args_info->full_help_help = RNALfold_args_info_detailed_help[2] ;
200 args_info->version_help = RNALfold_args_info_detailed_help[3] ;
201 args_info->span_help = RNALfold_args_info_detailed_help[6] ;
202 args_info->noconv_help = RNALfold_args_info_detailed_help[7] ;
203 args_info->zscore_help = RNALfold_args_info_detailed_help[10] ;
204 args_info->gquad_help = RNALfold_args_info_detailed_help[11] ;
205 args_info->temp_help = RNALfold_args_info_detailed_help[13] ;
206 args_info->noTetra_help = RNALfold_args_info_detailed_help[14] ;
207 args_info->dangles_help = RNALfold_args_info_detailed_help[15] ;
208 args_info->noLP_help = RNALfold_args_info_detailed_help[17] ;
209 args_info->noGU_help = RNALfold_args_info_detailed_help[19] ;
210 args_info->noClosingGU_help = RNALfold_args_info_detailed_help[20] ;
211 args_info->paramFile_help = RNALfold_args_info_detailed_help[21] ;
212 args_info->nsp_help = RNALfold_args_info_detailed_help[23] ;
213 args_info->energyModel_help = RNALfold_args_info_detailed_help[25] ;
218 RNALfold_cmdline_parser_print_version (void)
221 (strlen(RNALFOLD_CMDLINE_PARSER_PACKAGE_NAME) ? RNALFOLD_CMDLINE_PARSER_PACKAGE_NAME : RNALFOLD_CMDLINE_PARSER_PACKAGE),
222 RNALFOLD_CMDLINE_PARSER_VERSION);
225 static void print_help_common(void) {
226 RNALfold_cmdline_parser_print_version ();
228 if (strlen(RNALfold_args_info_purpose) > 0)
229 printf("\n%s\n", RNALfold_args_info_purpose);
231 if (strlen(RNALfold_args_info_usage) > 0)
232 printf("\n%s\n", RNALfold_args_info_usage);
236 if (strlen(RNALfold_args_info_description) > 0)
237 printf("%s\n\n", RNALfold_args_info_description);
241 RNALfold_cmdline_parser_print_help (void)
245 while (RNALfold_args_info_help[i])
246 printf("%s\n", RNALfold_args_info_help[i++]);
250 RNALfold_cmdline_parser_print_full_help (void)
254 while (RNALfold_args_info_full_help[i])
255 printf("%s\n", RNALfold_args_info_full_help[i++]);
259 RNALfold_cmdline_parser_print_detailed_help (void)
263 while (RNALfold_args_info_detailed_help[i])
264 printf("%s\n", RNALfold_args_info_detailed_help[i++]);
268 RNALfold_cmdline_parser_init (struct RNALfold_args_info *args_info)
270 clear_given (args_info);
271 clear_args (args_info);
272 init_args_info (args_info);
276 RNALfold_cmdline_parser_params_init(struct RNALfold_cmdline_parser_params *params)
280 params->override = 0;
281 params->initialize = 1;
282 params->check_required = 1;
283 params->check_ambiguity = 0;
284 params->print_errors = 1;
288 struct RNALfold_cmdline_parser_params *
289 RNALfold_cmdline_parser_params_create(void)
291 struct RNALfold_cmdline_parser_params *params =
292 (struct RNALfold_cmdline_parser_params *)malloc(sizeof(struct RNALfold_cmdline_parser_params));
293 RNALfold_cmdline_parser_params_init(params);
298 free_string_field (char **s)
309 RNALfold_cmdline_parser_release (struct RNALfold_args_info *args_info)
312 free_string_field (&(args_info->span_orig));
313 free_string_field (&(args_info->zscore_orig));
314 free_string_field (&(args_info->temp_orig));
315 free_string_field (&(args_info->dangles_orig));
316 free_string_field (&(args_info->paramFile_arg));
317 free_string_field (&(args_info->paramFile_orig));
318 free_string_field (&(args_info->nsp_arg));
319 free_string_field (&(args_info->nsp_orig));
320 free_string_field (&(args_info->energyModel_orig));
324 clear_given (args_info);
329 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
333 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
335 fprintf(outfile, "%s\n", opt);
341 RNALfold_cmdline_parser_dump(FILE *outfile, struct RNALfold_args_info *args_info)
347 fprintf (stderr, "%s: cannot dump options to stream\n", RNALFOLD_CMDLINE_PARSER_PACKAGE);
351 if (args_info->help_given)
352 write_into_file(outfile, "help", 0, 0 );
353 if (args_info->detailed_help_given)
354 write_into_file(outfile, "detailed-help", 0, 0 );
355 if (args_info->full_help_given)
356 write_into_file(outfile, "full-help", 0, 0 );
357 if (args_info->version_given)
358 write_into_file(outfile, "version", 0, 0 );
359 if (args_info->span_given)
360 write_into_file(outfile, "span", args_info->span_orig, 0);
361 if (args_info->noconv_given)
362 write_into_file(outfile, "noconv", 0, 0 );
363 if (args_info->zscore_given)
364 write_into_file(outfile, "zscore", args_info->zscore_orig, 0);
365 if (args_info->gquad_given)
366 write_into_file(outfile, "gquad", 0, 0 );
367 if (args_info->temp_given)
368 write_into_file(outfile, "temp", args_info->temp_orig, 0);
369 if (args_info->noTetra_given)
370 write_into_file(outfile, "noTetra", 0, 0 );
371 if (args_info->dangles_given)
372 write_into_file(outfile, "dangles", args_info->dangles_orig, 0);
373 if (args_info->noLP_given)
374 write_into_file(outfile, "noLP", 0, 0 );
375 if (args_info->noGU_given)
376 write_into_file(outfile, "noGU", 0, 0 );
377 if (args_info->noClosingGU_given)
378 write_into_file(outfile, "noClosingGU", 0, 0 );
379 if (args_info->paramFile_given)
380 write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
381 if (args_info->nsp_given)
382 write_into_file(outfile, "nsp", args_info->nsp_orig, 0);
383 if (args_info->energyModel_given)
384 write_into_file(outfile, "energyModel", args_info->energyModel_orig, 0);
392 RNALfold_cmdline_parser_file_save(const char *filename, struct RNALfold_args_info *args_info)
397 outfile = fopen(filename, "w");
401 fprintf (stderr, "%s: cannot open file for writing: %s\n", RNALFOLD_CMDLINE_PARSER_PACKAGE, filename);
405 i = RNALfold_cmdline_parser_dump(outfile, args_info);
412 RNALfold_cmdline_parser_free (struct RNALfold_args_info *args_info)
414 RNALfold_cmdline_parser_release (args_info);
417 /** @brief replacement of strdup, which is not standard */
419 gengetopt_strdup (const char *s)
425 result = (char*)malloc(strlen(s) + 1);
426 if (result == (char*)0)
433 RNALfold_cmdline_parser (int argc, char **argv, struct RNALfold_args_info *args_info)
435 return RNALfold_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
439 RNALfold_cmdline_parser_ext (int argc, char **argv, struct RNALfold_args_info *args_info,
440 struct RNALfold_cmdline_parser_params *params)
443 result = RNALfold_cmdline_parser_internal (argc, argv, args_info, params, 0);
445 if (result == EXIT_FAILURE)
447 RNALfold_cmdline_parser_free (args_info);
455 RNALfold_cmdline_parser2 (int argc, char **argv, struct RNALfold_args_info *args_info, int override, int initialize, int check_required)
458 struct RNALfold_cmdline_parser_params params;
460 params.override = override;
461 params.initialize = initialize;
462 params.check_required = check_required;
463 params.check_ambiguity = 0;
464 params.print_errors = 1;
466 result = RNALfold_cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
468 if (result == EXIT_FAILURE)
470 RNALfold_cmdline_parser_free (args_info);
478 RNALfold_cmdline_parser_required (struct RNALfold_args_info *args_info, const char *prog_name)
480 FIX_UNUSED (args_info);
481 FIX_UNUSED (prog_name);
486 * Extracted from the glibc source tree, version 2.3.6
488 * Licensed under the GPL as per the whole glibc source tree.
490 * This file was modified so that getopt_long can be called
491 * many times without risking previous memory to be spoiled.
493 * Modified by Andre Noll and Lorenzo Bettini for use in
494 * GNU gengetopt generated files.
499 * we must include anything we need since this file is not thought to be
500 * inserted in a file already using getopt.h
508 /* has_arg can't be an enum because some compilers complain about
509 type mismatches in all the code that assumes it is an int. */
515 /* This version of `getopt' appears to the caller like standard Unix `getopt'
516 but it behaves differently for the user, since it allows the user
517 to intersperse the options with the other arguments.
519 As `getopt' works, it permutes the elements of ARGV so that,
520 when it is done, all the options precede everything else. Thus
521 all application programs are extended to handle flexible argument order.
524 If the field `flag' is not NULL, it points to a variable that is set
525 to the value given in the field `val' when the option is found, but
526 left unchanged if the option is not found.
528 To have a long-named option do something other than set an `int' to
529 a compiled-in constant, such as set a value from `custom_optarg', set the
530 option's `flag' field to zero and its `val' field to a nonzero
531 value (the equivalent single-letter option character, if there is
532 one). For long options that have a zero `flag' field, `getopt'
533 returns the contents of the `val' field. */
535 /* Names for the values of the `has_arg' field of `struct option'. */
537 #define no_argument 0
540 #ifndef required_argument
541 #define required_argument 1
544 #ifndef optional_argument
545 #define optional_argument 2
548 struct custom_getopt_data {
550 * These have exactly the same meaning as the corresponding global variables,
551 * except that they are used for the reentrant versions of getopt.
558 /* True if the internal members have been initialized. */
562 * The next char to be scanned in the option-element in which the last option
563 * character we returned was found. This allows us to pick up the scan where
564 * we left off. If this is zero, or a null string, it means resume the scan by
565 * advancing to the next ARGV-element.
570 * Describe the part of ARGV that contains non-options that have been skipped.
571 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
572 * the index after the last of them.
579 * the variables optarg, optind, opterr and optopt are renamed with
580 * the custom_ prefix so that they don't interfere with getopt ones.
582 * Moreover they're static so they are visible only from within the
583 * file where this very file will be included.
587 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
588 * option that takes an argument, the argument value is returned here.
590 static char *custom_optarg;
593 * Index in ARGV of the next element to be scanned. This is used for
594 * communication to and from the caller and for communication between
595 * successive calls to `custom_getopt'.
597 * On entry to `custom_getopt', 1 means this is the first call; initialize.
599 * When `custom_getopt' returns -1, this is the index of the first of the non-option
600 * elements that the caller should itself scan.
602 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
603 * has been scanned so far.
605 * 1003.2 says this must be 1 before any call.
607 static int custom_optind = 1;
610 * Callers store zero here to inhibit the error message for unrecognized
613 static int custom_opterr = 1;
616 * Set to an option character which was unrecognized. This must be initialized
617 * on some systems to avoid linking in the system's own getopt implementation.
619 static int custom_optopt = '?';
622 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
623 * [first_nonopt,last_nonopt) which contains all the non-options that have been
624 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
625 * all the options processed since those non-options were skipped.
626 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
627 * indices of the non-options in ARGV after they are moved.
629 static void exchange(char **argv, struct custom_getopt_data *d)
631 int bottom = d->first_nonopt;
632 int middle = d->last_nonopt;
633 int top = d->custom_optind;
637 * Exchange the shorter segment with the far end of the longer segment.
638 * That puts the shorter segment into the right place. It leaves the
639 * longer segment in the right place overall, but it consists of two
640 * parts that need to be swapped next.
642 while (top > middle && middle > bottom) {
643 if (top - middle > middle - bottom) {
644 /* Bottom segment is the short one. */
645 int len = middle - bottom;
648 /* Swap it with the top part of the top segment. */
649 for (i = 0; i < len; i++) {
650 tem = argv[bottom + i];
652 argv[top - (middle - bottom) + i];
653 argv[top - (middle - bottom) + i] = tem;
655 /* Exclude the moved bottom segment from further swapping. */
658 /* Top segment is the short one. */
659 int len = top - middle;
662 /* Swap it with the bottom part of the bottom segment. */
663 for (i = 0; i < len; i++) {
664 tem = argv[bottom + i];
665 argv[bottom + i] = argv[middle + i];
666 argv[middle + i] = tem;
668 /* Exclude the moved top segment from further swapping. */
672 /* Update records for the slots the non-options now occupy. */
673 d->first_nonopt += (d->custom_optind - d->last_nonopt);
674 d->last_nonopt = d->custom_optind;
677 /* Initialize the internal data when the first call is made. */
678 static void custom_getopt_initialize(struct custom_getopt_data *d)
681 * Start processing options with ARGV-element 1 (since ARGV-element 0
682 * is the program name); the sequence of previously skipped non-option
683 * ARGV-elements is empty.
685 d->first_nonopt = d->last_nonopt = d->custom_optind;
690 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
692 /* return: zero: continue, nonzero: return given value to user */
693 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
694 struct custom_getopt_data *d)
697 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
698 * moved back by the user (who may also have changed the arguments).
700 if (d->last_nonopt > d->custom_optind)
701 d->last_nonopt = d->custom_optind;
702 if (d->first_nonopt > d->custom_optind)
703 d->first_nonopt = d->custom_optind;
705 * If we have just processed some options following some
706 * non-options, exchange them so that the options come first.
708 if (d->first_nonopt != d->last_nonopt &&
709 d->last_nonopt != d->custom_optind)
710 exchange((char **) argv, d);
711 else if (d->last_nonopt != d->custom_optind)
712 d->first_nonopt = d->custom_optind;
714 * Skip any additional non-options and extend the range of
715 * non-options previously skipped.
717 while (d->custom_optind < argc && NONOPTION_P)
719 d->last_nonopt = d->custom_optind;
721 * The special ARGV-element `--' means premature end of options. Skip
722 * it like a null option, then exchange with previous non-options as if
723 * it were an option, then skip everything else like a non-option.
725 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
727 if (d->first_nonopt != d->last_nonopt
728 && d->last_nonopt != d->custom_optind)
729 exchange((char **) argv, d);
730 else if (d->first_nonopt == d->last_nonopt)
731 d->first_nonopt = d->custom_optind;
732 d->last_nonopt = argc;
733 d->custom_optind = argc;
736 * If we have done all the ARGV-elements, stop the scan and back over
737 * any non-options that we skipped and permuted.
739 if (d->custom_optind == argc) {
741 * Set the next-arg-index to point at the non-options that we
742 * previously skipped, so the caller will digest them.
744 if (d->first_nonopt != d->last_nonopt)
745 d->custom_optind = d->first_nonopt;
749 * If we have come to a non-option and did not permute it, either stop
750 * the scan or describe it to the caller and pass it by.
753 d->custom_optarg = argv[d->custom_optind++];
757 * We have found another option-ARGV-element. Skip the initial
760 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
765 * Check whether the ARGV-element is a long option.
767 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
768 * that an abbreviation of the long option, just like "--fu", and not "-f" with
771 * This distinction seems to be the most useful approach.
774 static int check_long_opt(int argc, char *const *argv, const char *optstring,
775 const struct option *longopts, int *longind,
776 int print_errors, struct custom_getopt_data *d)
779 const struct option *p;
780 const struct option *pfound = NULL;
786 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
789 /* Test all long options for either exact match or abbreviated matches */
790 for (p = longopts, option_index = 0; p->name; p++, option_index++)
791 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
792 if ((unsigned int) (nameend - d->nextchar)
793 == (unsigned int) strlen(p->name)) {
794 /* Exact match found. */
796 indfound = option_index;
799 } else if (pfound == NULL) {
800 /* First nonexact match found. */
802 indfound = option_index;
803 } else if (pfound->has_arg != p->has_arg
804 || pfound->flag != p->flag
805 || pfound->val != p->val)
806 /* Second or later nonexact match found. */
809 if (ambig && !exact) {
812 "%s: option `%s' is ambiguous\n",
813 argv[0], argv[d->custom_optind]);
815 d->nextchar += strlen(d->nextchar);
817 d->custom_optopt = 0;
821 option_index = indfound;
824 if (pfound->has_arg != no_argument)
825 d->custom_optarg = nameend + 1;
828 if (argv[d->custom_optind - 1][1] == '-') {
830 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
831 argv[0], pfound->name);
833 /* +option or -option */
834 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
835 argv[0], argv[d->custom_optind - 1][0], pfound->name);
839 d->nextchar += strlen(d->nextchar);
840 d->custom_optopt = pfound->val;
843 } else if (pfound->has_arg == required_argument) {
844 if (d->custom_optind < argc)
845 d->custom_optarg = argv[d->custom_optind++];
849 "%s: option `%s' requires an argument\n",
851 argv[d->custom_optind - 1]);
853 d->nextchar += strlen(d->nextchar);
854 d->custom_optopt = pfound->val;
855 return optstring[0] == ':' ? ':' : '?';
858 d->nextchar += strlen(d->nextchar);
860 *longind = option_index;
862 *(pfound->flag) = pfound->val;
868 * Can't find it as a long option. If this is not getopt_long_only, or
869 * the option starts with '--' or is not a valid short option, then
870 * it's an error. Otherwise interpret it as a short option.
873 if (argv[d->custom_optind][1] == '-') {
876 "%s: unrecognized option `--%s'\n",
877 argv[0], d->nextchar);
879 /* +option or -option */
881 "%s: unrecognized option `%c%s'\n",
882 argv[0], argv[d->custom_optind][0],
886 d->nextchar = (char *) "";
888 d->custom_optopt = 0;
892 static int check_short_opt(int argc, char *const *argv, const char *optstring,
893 int print_errors, struct custom_getopt_data *d)
895 char c = *d->nextchar++;
896 const char *temp = strchr(optstring, c);
898 /* Increment `custom_optind' when we start to process its last character. */
899 if (*d->nextchar == '\0')
901 if (!temp || c == ':') {
903 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
905 d->custom_optopt = c;
908 if (temp[1] == ':') {
909 if (temp[2] == ':') {
910 /* This is an option that accepts an argument optionally. */
911 if (*d->nextchar != '\0') {
912 d->custom_optarg = d->nextchar;
915 d->custom_optarg = NULL;
918 /* This is an option that requires an argument. */
919 if (*d->nextchar != '\0') {
920 d->custom_optarg = d->nextchar;
922 * If we end this ARGV-element by taking the
923 * rest as an arg, we must advance to the next
927 } else if (d->custom_optind == argc) {
930 "%s: option requires an argument -- %c\n",
933 d->custom_optopt = c;
934 if (optstring[0] == ':')
940 * We already incremented `custom_optind' once;
941 * increment it again when taking next ARGV-elt
944 d->custom_optarg = argv[d->custom_optind++];
952 * Scan elements of ARGV for option characters given in OPTSTRING.
954 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
955 * then it is an option element. The characters of this element
956 * (aside from the initial '-') are option characters. If `getopt'
957 * is called repeatedly, it returns successively each of the option characters
958 * from each of the option elements.
960 * If `getopt' finds another option character, it returns that character,
961 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
962 * resume the scan with the following option character or ARGV-element.
964 * If there are no more option characters, `getopt' returns -1.
965 * Then `custom_optind' is the index in ARGV of the first ARGV-element
966 * that is not an option. (The ARGV-elements have been permuted
967 * so that those that are not options now come last.)
969 * OPTSTRING is a string containing the legitimate option characters.
970 * If an option character is seen that is not listed in OPTSTRING,
971 * return '?' after printing an error message. If you set `custom_opterr' to
972 * zero, the error message is suppressed but we still return '?'.
974 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
975 * so the following text in the same ARGV-element, or the text of the following
976 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
977 * wants an optional arg; if there is text in the current ARGV-element,
978 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
980 * If OPTSTRING starts with `-' or `+', it requests different methods of
981 * handling the non-option ARGV-elements.
982 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
984 * Long-named options begin with `--' instead of `-'.
985 * Their names may be abbreviated as long as the abbreviation is unique
986 * or is an exact match for some defined option. If they have an
987 * argument, it follows the option name in the same ARGV-element, separated
988 * from the option name by a `=', or else the in next ARGV-element.
989 * When `getopt' finds a long-named option, it returns 0 if that option's
990 * `flag' field is nonzero, the value of the option's `val' field
991 * if the `flag' field is zero.
993 * The elements of ARGV aren't really const, because we permute them.
994 * But we pretend they're const in the prototype to be compatible
995 * with other systems.
997 * LONGOPTS is a vector of `struct option' terminated by an
998 * element containing a name which is zero.
1000 * LONGIND returns the index in LONGOPT of the long-named option found.
1001 * It is only valid when a long-named option has been found by the most
1004 * Return the option character from OPTS just read. Return -1 when there are
1005 * no more options. For unrecognized options, or options missing arguments,
1006 * `custom_optopt' is set to the option letter, and '?' is returned.
1008 * The OPTS string is a list of characters which are recognized option letters,
1009 * optionally followed by colons, specifying that that letter takes an
1010 * argument, to be placed in `custom_optarg'.
1012 * If a letter in OPTS is followed by two colons, its argument is optional.
1013 * This behavior is specific to the GNU `getopt'.
1015 * The argument `--' causes premature termination of argument scanning,
1016 * explicitly telling `getopt' that there are no more options. If OPTS begins
1017 * with `--', then non-option arguments are treated as arguments to the option
1018 * '\0'. This behavior is specific to the GNU `getopt'.
1021 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1022 const struct option *longopts, int *longind,
1023 struct custom_getopt_data *d)
1025 int ret, print_errors = d->custom_opterr;
1027 if (optstring[0] == ':')
1031 d->custom_optarg = NULL;
1034 * This is a big difference with GNU getopt, since optind == 0
1035 * means initialization while here 1 means first call.
1037 if (d->custom_optind == 0 || !d->initialized) {
1038 if (d->custom_optind == 0)
1039 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
1040 custom_getopt_initialize(d);
1042 if (d->nextchar == NULL || *d->nextchar == '\0') {
1043 ret = shuffle_argv(argc, argv, longopts, d);
1047 if (longopts && (argv[d->custom_optind][1] == '-' ))
1048 return check_long_opt(argc, argv, optstring, longopts,
1049 longind, print_errors, d);
1050 return check_short_opt(argc, argv, optstring, print_errors, d);
1053 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1054 const struct option *longopts, int *longind)
1057 /* Keep a global copy of all internal members of d */
1058 static struct custom_getopt_data d;
1060 d.custom_optind = custom_optind;
1061 d.custom_opterr = custom_opterr;
1062 result = getopt_internal_r(argc, argv, optstring, longopts,
1064 custom_optind = d.custom_optind;
1065 custom_optarg = d.custom_optarg;
1066 custom_optopt = d.custom_optopt;
1070 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1071 const struct option *long_options, int *opt_index)
1073 return custom_getopt_internal(argc, argv, options, long_options,
1078 static char *package_name = 0;
1081 * @brief updates an option
1082 * @param field the generic pointer to the field to update
1083 * @param orig_field the pointer to the orig field
1084 * @param field_given the pointer to the number of occurrence of this option
1085 * @param prev_given the pointer to the number of occurrence already seen
1086 * @param value the argument for this option (if null no arg was specified)
1087 * @param possible_values the possible values for this option (if specified)
1088 * @param default_value the default value (in case the option only accepts fixed values)
1089 * @param arg_type the type of this option
1090 * @param check_ambiguity @see RNALfold_cmdline_parser_params.check_ambiguity
1091 * @param override @see RNALfold_cmdline_parser_params.override
1092 * @param no_free whether to free a possible previous value
1093 * @param multiple_option whether this is a multiple option
1094 * @param long_opt the corresponding long option
1095 * @param short_opt the corresponding short option (or '-' if none)
1096 * @param additional_error possible further error specification
1099 int update_arg(void *field, char **orig_field,
1100 unsigned int *field_given, unsigned int *prev_given,
1101 char *value, const char *possible_values[],
1102 const char *default_value,
1103 RNALfold_cmdline_parser_arg_type arg_type,
1104 int check_ambiguity, int override,
1105 int no_free, int multiple_option,
1106 const char *long_opt, char short_opt,
1107 const char *additional_error)
1109 char *stop_char = 0;
1110 const char *val = value;
1112 char **string_field;
1118 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1120 if (short_opt != '-')
1121 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1122 package_name, long_opt, short_opt,
1123 (additional_error ? additional_error : ""));
1125 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1126 package_name, long_opt,
1127 (additional_error ? additional_error : ""));
1128 return 1; /* failure */
1131 FIX_UNUSED (default_value);
1133 if (field_given && *field_given && ! override)
1139 if (possible_values)
1140 val = possible_values[found];
1144 *((int *)field) = !*((int *)field);
1147 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1150 if (val) *((double *)field) = strtod (val, &stop_char);
1154 string_field = (char **)field;
1155 if (!no_free && *string_field)
1156 free (*string_field); /* free previous string */
1157 *string_field = gengetopt_strdup (val);
1164 /* check numeric conversion */
1168 if (val && !(stop_char && *stop_char == '\0')) {
1169 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1170 return 1; /* failure */
1177 /* store the original value */
1183 if (value && orig_field) {
1185 *orig_field = value;
1188 free (*orig_field); /* free previous string */
1189 *orig_field = gengetopt_strdup (value);
1199 RNALfold_cmdline_parser_internal (
1200 int argc, char **argv, struct RNALfold_args_info *args_info,
1201 struct RNALfold_cmdline_parser_params *params, const char *additional_error)
1203 int c; /* Character of the parsed option. */
1206 struct RNALfold_args_info local_args_info;
1211 int check_ambiguity;
1218 package_name = argv[0];
1220 override = params->override;
1221 initialize = params->initialize;
1222 check_required = params->check_required;
1223 check_ambiguity = params->check_ambiguity;
1226 RNALfold_cmdline_parser_init (args_info);
1228 RNALfold_cmdline_parser_init (&local_args_info);
1232 opterr = params->print_errors;
1237 int option_index = 0;
1239 static struct option long_options[] = {
1240 { "help", 0, NULL, 'h' },
1241 { "detailed-help", 0, NULL, 0 },
1242 { "full-help", 0, NULL, 0 },
1243 { "version", 0, NULL, 'V' },
1244 { "span", 1, NULL, 'L' },
1245 { "noconv", 0, NULL, 0 },
1246 { "zscore", 2, NULL, 'z' },
1247 { "gquad", 0, NULL, 'g' },
1248 { "temp", 1, NULL, 'T' },
1249 { "noTetra", 0, NULL, '4' },
1250 { "dangles", 1, NULL, 'd' },
1251 { "noLP", 0, NULL, 0 },
1252 { "noGU", 0, NULL, 0 },
1253 { "noClosingGU", 0, NULL, 0 },
1254 { "paramFile", 1, NULL, 'P' },
1255 { "nsp", 1, NULL, 0 },
1256 { "energyModel", 1, NULL, 'e' },
1260 custom_optarg = optarg;
1261 custom_optind = optind;
1262 custom_opterr = opterr;
1263 custom_optopt = optopt;
1265 c = custom_getopt_long (argc, argv, "hVL:z::gT:4d:P:e:", long_options, &option_index);
1267 optarg = custom_optarg;
1268 optind = custom_optind;
1269 opterr = custom_opterr;
1270 optopt = custom_optopt;
1272 if (c == -1) break; /* Exit from `while (1)' loop. */
1276 case 'h': /* Print help and exit. */
1277 RNALfold_cmdline_parser_print_help ();
1278 RNALfold_cmdline_parser_free (&local_args_info);
1279 exit (EXIT_SUCCESS);
1281 case 'V': /* Print version and exit. */
1282 RNALfold_cmdline_parser_print_version ();
1283 RNALfold_cmdline_parser_free (&local_args_info);
1284 exit (EXIT_SUCCESS);
1286 case 'L': /* Set the maximum allowed separation of a base pair to span. I.e. no pairs (i,j) with j-i>span will be allowed.
1291 if (update_arg( (void *)&(args_info->span_arg),
1292 &(args_info->span_orig), &(args_info->span_given),
1293 &(local_args_info.span_given), optarg, 0, "150", ARG_INT,
1294 check_ambiguity, override, 0, 0,
1300 case 'z': /* Activate z-score computation. An optional argument may be supplied to set the threshold
1301 Due to parsing the commandline parameters a negative value should be given immediately after \"z\" without spaces e.g. -z-4.9
1306 if (update_arg( (void *)&(args_info->zscore_arg),
1307 &(args_info->zscore_orig), &(args_info->zscore_given),
1308 &(local_args_info.zscore_given), optarg, 0, "-2", ARG_DOUBLE,
1309 check_ambiguity, override, 0, 0,
1315 case 'g': /* Incoorporate G-Quadruplex formation into the structure prediction algorithm
1319 if (update_arg((void *)&(args_info->gquad_flag), 0, &(args_info->gquad_given),
1320 &(local_args_info.gquad_given), optarg, 0, 0, ARG_FLAG,
1321 check_ambiguity, override, 1, 0, "gquad", 'g',
1326 case 'T': /* Rescale energy parameters to a temperature of temp C. Default is 37C.
1331 if (update_arg( (void *)&(args_info->temp_arg),
1332 &(args_info->temp_orig), &(args_info->temp_given),
1333 &(local_args_info.temp_given), optarg, 0, 0, ARG_DOUBLE,
1334 check_ambiguity, override, 0, 0,
1340 case '4': /* Do not include special tabulated stabilizing energies for tri-, tetra- and hexaloop hairpins. Mostly for testing.
1345 if (update_arg((void *)&(args_info->noTetra_flag), 0, &(args_info->noTetra_given),
1346 &(local_args_info.noTetra_given), optarg, 0, 0, ARG_FLAG,
1347 check_ambiguity, override, 1, 0, "noTetra", '4',
1352 case 'd': /* How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops
1356 if (update_arg( (void *)&(args_info->dangles_arg),
1357 &(args_info->dangles_orig), &(args_info->dangles_given),
1358 &(local_args_info.dangles_given), optarg, 0, "2", ARG_INT,
1359 check_ambiguity, override, 0, 0,
1365 case 'P': /* Read energy parameters from paramfile, instead of using the default parameter set.
1369 if (update_arg( (void *)&(args_info->paramFile_arg),
1370 &(args_info->paramFile_orig), &(args_info->paramFile_given),
1371 &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1372 check_ambiguity, override, 0, 0,
1378 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.
1383 if (update_arg( (void *)&(args_info->energyModel_arg),
1384 &(args_info->energyModel_orig), &(args_info->energyModel_given),
1385 &(local_args_info.energyModel_given), optarg, 0, 0, ARG_INT,
1386 check_ambiguity, override, 0, 0,
1393 case 0: /* Long option with no short option */
1394 if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1395 RNALfold_cmdline_parser_print_detailed_help ();
1396 RNALfold_cmdline_parser_free (&local_args_info);
1397 exit (EXIT_SUCCESS);
1400 if (strcmp (long_options[option_index].name, "full-help") == 0) {
1401 RNALfold_cmdline_parser_print_full_help ();
1402 RNALfold_cmdline_parser_free (&local_args_info);
1403 exit (EXIT_SUCCESS);
1406 /* Do not automatically substitude nucleotide \"T\" with \"U\"
1409 if (strcmp (long_options[option_index].name, "noconv") == 0)
1413 if (update_arg((void *)&(args_info->noconv_flag), 0, &(args_info->noconv_given),
1414 &(local_args_info.noconv_given), optarg, 0, 0, ARG_FLAG,
1415 check_ambiguity, override, 1, 0, "noconv", '-',
1420 /* Produce structures without lonely pairs (helices of length 1).
1422 else if (strcmp (long_options[option_index].name, "noLP") == 0)
1426 if (update_arg((void *)&(args_info->noLP_flag), 0, &(args_info->noLP_given),
1427 &(local_args_info.noLP_given), optarg, 0, 0, ARG_FLAG,
1428 check_ambiguity, override, 1, 0, "noLP", '-',
1433 /* Do not allow GU pairs
1436 else if (strcmp (long_options[option_index].name, "noGU") == 0)
1440 if (update_arg((void *)&(args_info->noGU_flag), 0, &(args_info->noGU_given),
1441 &(local_args_info.noGU_given), optarg, 0, 0, ARG_FLAG,
1442 check_ambiguity, override, 1, 0, "noGU", '-',
1447 /* Do not allow GU pairs at the end of helices
1450 else if (strcmp (long_options[option_index].name, "noClosingGU") == 0)
1454 if (update_arg((void *)&(args_info->noClosingGU_flag), 0, &(args_info->noClosingGU_given),
1455 &(local_args_info.noClosingGU_given), optarg, 0, 0, ARG_FLAG,
1456 check_ambiguity, override, 1, 0, "noClosingGU", '-',
1461 /* Allow other pairs in addition to the usual AU,GC,and GU pairs.
1463 else if (strcmp (long_options[option_index].name, "nsp") == 0)
1467 if (update_arg( (void *)&(args_info->nsp_arg),
1468 &(args_info->nsp_orig), &(args_info->nsp_given),
1469 &(local_args_info.nsp_given), optarg, 0, 0, ARG_STRING,
1470 check_ambiguity, override, 0, 0,
1478 case '?': /* Invalid option. */
1479 /* `getopt_long' already printed an error message. */
1482 default: /* bug: option not considered. */
1483 fprintf (stderr, "%s: option unknown: %c%s\n", RNALFOLD_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1491 RNALfold_cmdline_parser_release (&local_args_info);
1494 return (EXIT_FAILURE);
1500 RNALfold_cmdline_parser_release (&local_args_info);
1501 return (EXIT_FAILURE);