2 File autogenerated by gengetopt version 2.22.5
3 generated with the following command:
4 gengetopt -i RNAPKplex.ggo --file-name=RNAPKplex_cmdl --include-getopt --default-optional --func-name=PKplex_cmdline_parser --arg-struct-name=PKplex_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 "RNAPKplex_cmdl.h"
27 const char *PKplex_args_info_purpose = "predicts RNA secondary structures including pseudoknots";
29 const char *PKplex_args_info_usage = "Usage: RNAPKplex [OPTIONS]...";
31 const char *PKplex_args_info_description = "Computes RNA secondary structures by first making two sequence intervals \naccessible and unpaired using the algorithm of RNAplfold and then calculating \nthe energy of the interaction of those two intervals. The algorithm uses \nO(n^2*w^4) CPU time and O(n*w^2) memory space.\nThe algorithm furthermore always considers dangle=2 model.\n";
33 const char *PKplex_args_info_detailed_help[] = {
34 " -h, --help Print help and exit",
35 " --detailed-help Print help, including all details and hidden \n options, and exit",
36 " -V, --version Print version and exit",
37 " -c, --cutoff=FLOAT Report only base pairs with an average probability \n > cutoff in the dot plot\n\n (default=`0.01')",
38 " -T, --temp=DOUBLE Rescale energy parameters to a temperature of temp \n C. Default is 37C.\n\n",
39 " -4, --noTetra Do not include special stabilizing energies for \n certain tetra-loops. Mostly for testing.\n\n (default=off)",
40 " --noLP Produce structures without lonely pairs (helices \n of length 1).\n (default=off)",
41 " 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",
42 " --noGU Do not allow GU pairs\n\n (default=off)",
43 " --noClosingGU Do not allow GU pairs at the end of helices\n\n (default=off)",
44 " --noconv Do not automatically substitude nucleotide \"T\" \n with \"U\"\n\n (default=off)",
45 " --nsp=STRING Allow other pairs in addition to the usual \n AU,GC,and GU pairs.\n (default=`empty')",
46 " 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",
47 " -e, --energyCutoff=DOUBLE Energy cutoff or pseudoknot initiation cost. \n Minimum energy gain of a pseudoknot interaction \n for it to be returned. Pseudoknots with smaller \n energy gains are rejected.\n\n (default=`-8.10')",
48 " -P, --paramFile=paramfile Read energy parameters from paramfile, instead of \n using the default parameter set.\n",
49 " A sample parameter file should accompany your distribution.\n See the RNAlib documentation for details on the file format.\n\n",
50 " -v, --verbose print verbose output\n (default=off)",
51 " -s, --subopts=DOUBLE print suboptimal structures whose energy \n difference of the pseudoknot to the optimum \n pseudoknot is smaller than the given value.\n (default=`0.0')",
52 " NOTE: The final energy of a structure is calculated as the sum of the \n pseudoknot interaction energy, the penalty for initiating a pseudoknot and \n the energy of the pseudoknot-free part of the structure. The -s option only \n takes the pseudoknot interaction energy into account, so the final energy \n differences may be bigger than the specified value (default=0.).\n\n",
53 "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
60 PKplex_args_info_help[0] = PKplex_args_info_detailed_help[0];
61 PKplex_args_info_help[1] = PKplex_args_info_detailed_help[1];
62 PKplex_args_info_help[2] = PKplex_args_info_detailed_help[2];
63 PKplex_args_info_help[3] = PKplex_args_info_detailed_help[3];
64 PKplex_args_info_help[4] = PKplex_args_info_detailed_help[4];
65 PKplex_args_info_help[5] = PKplex_args_info_detailed_help[5];
66 PKplex_args_info_help[6] = PKplex_args_info_detailed_help[6];
67 PKplex_args_info_help[7] = PKplex_args_info_detailed_help[8];
68 PKplex_args_info_help[8] = PKplex_args_info_detailed_help[9];
69 PKplex_args_info_help[9] = PKplex_args_info_detailed_help[10];
70 PKplex_args_info_help[10] = PKplex_args_info_detailed_help[11];
71 PKplex_args_info_help[11] = PKplex_args_info_detailed_help[13];
72 PKplex_args_info_help[12] = PKplex_args_info_detailed_help[14];
73 PKplex_args_info_help[13] = PKplex_args_info_detailed_help[16];
74 PKplex_args_info_help[14] = PKplex_args_info_detailed_help[17];
75 PKplex_args_info_help[15] = PKplex_args_info_detailed_help[19];
76 PKplex_args_info_help[16] = 0;
80 const char *PKplex_args_info_help[17];
87 } PKplex_cmdline_parser_arg_type;
90 void clear_given (struct PKplex_args_info *args_info);
92 void clear_args (struct PKplex_args_info *args_info);
95 PKplex_cmdline_parser_internal (int argc, char **argv, struct PKplex_args_info *args_info,
96 struct PKplex_cmdline_parser_params *params, const char *additional_error);
100 gengetopt_strdup (const char *s);
103 void clear_given (struct PKplex_args_info *args_info)
105 args_info->help_given = 0 ;
106 args_info->detailed_help_given = 0 ;
107 args_info->version_given = 0 ;
108 args_info->cutoff_given = 0 ;
109 args_info->temp_given = 0 ;
110 args_info->noTetra_given = 0 ;
111 args_info->noLP_given = 0 ;
112 args_info->noGU_given = 0 ;
113 args_info->noClosingGU_given = 0 ;
114 args_info->noconv_given = 0 ;
115 args_info->nsp_given = 0 ;
116 args_info->energyCutoff_given = 0 ;
117 args_info->paramFile_given = 0 ;
118 args_info->verbose_given = 0 ;
119 args_info->subopts_given = 0 ;
123 void clear_args (struct PKplex_args_info *args_info)
125 FIX_UNUSED (args_info);
126 args_info->cutoff_arg = 0.01;
127 args_info->cutoff_orig = NULL;
128 args_info->temp_orig = NULL;
129 args_info->noTetra_flag = 0;
130 args_info->noLP_flag = 0;
131 args_info->noGU_flag = 0;
132 args_info->noClosingGU_flag = 0;
133 args_info->noconv_flag = 0;
134 args_info->nsp_arg = gengetopt_strdup ("empty");
135 args_info->nsp_orig = NULL;
136 args_info->energyCutoff_arg = -8.10;
137 args_info->energyCutoff_orig = NULL;
138 args_info->paramFile_arg = NULL;
139 args_info->paramFile_orig = NULL;
140 args_info->verbose_flag = 0;
141 args_info->subopts_arg = 0.0;
142 args_info->subopts_orig = NULL;
147 void init_args_info(struct PKplex_args_info *args_info)
151 args_info->help_help = PKplex_args_info_detailed_help[0] ;
152 args_info->detailed_help_help = PKplex_args_info_detailed_help[1] ;
153 args_info->version_help = PKplex_args_info_detailed_help[2] ;
154 args_info->cutoff_help = PKplex_args_info_detailed_help[3] ;
155 args_info->temp_help = PKplex_args_info_detailed_help[4] ;
156 args_info->noTetra_help = PKplex_args_info_detailed_help[5] ;
157 args_info->noLP_help = PKplex_args_info_detailed_help[6] ;
158 args_info->noGU_help = PKplex_args_info_detailed_help[8] ;
159 args_info->noClosingGU_help = PKplex_args_info_detailed_help[9] ;
160 args_info->noconv_help = PKplex_args_info_detailed_help[10] ;
161 args_info->nsp_help = PKplex_args_info_detailed_help[11] ;
162 args_info->energyCutoff_help = PKplex_args_info_detailed_help[13] ;
163 args_info->paramFile_help = PKplex_args_info_detailed_help[14] ;
164 args_info->verbose_help = PKplex_args_info_detailed_help[16] ;
165 args_info->subopts_help = PKplex_args_info_detailed_help[17] ;
170 PKplex_cmdline_parser_print_version (void)
173 (strlen(PKPLEX_CMDLINE_PARSER_PACKAGE_NAME) ? PKPLEX_CMDLINE_PARSER_PACKAGE_NAME : PKPLEX_CMDLINE_PARSER_PACKAGE),
174 PKPLEX_CMDLINE_PARSER_VERSION);
177 static void print_help_common(void) {
178 PKplex_cmdline_parser_print_version ();
180 if (strlen(PKplex_args_info_purpose) > 0)
181 printf("\n%s\n", PKplex_args_info_purpose);
183 if (strlen(PKplex_args_info_usage) > 0)
184 printf("\n%s\n", PKplex_args_info_usage);
188 if (strlen(PKplex_args_info_description) > 0)
189 printf("%s\n\n", PKplex_args_info_description);
193 PKplex_cmdline_parser_print_help (void)
197 while (PKplex_args_info_help[i])
198 printf("%s\n", PKplex_args_info_help[i++]);
202 PKplex_cmdline_parser_print_detailed_help (void)
206 while (PKplex_args_info_detailed_help[i])
207 printf("%s\n", PKplex_args_info_detailed_help[i++]);
211 PKplex_cmdline_parser_init (struct PKplex_args_info *args_info)
213 clear_given (args_info);
214 clear_args (args_info);
215 init_args_info (args_info);
219 PKplex_cmdline_parser_params_init(struct PKplex_cmdline_parser_params *params)
223 params->override = 0;
224 params->initialize = 1;
225 params->check_required = 1;
226 params->check_ambiguity = 0;
227 params->print_errors = 1;
231 struct PKplex_cmdline_parser_params *
232 PKplex_cmdline_parser_params_create(void)
234 struct PKplex_cmdline_parser_params *params =
235 (struct PKplex_cmdline_parser_params *)malloc(sizeof(struct PKplex_cmdline_parser_params));
236 PKplex_cmdline_parser_params_init(params);
241 free_string_field (char **s)
252 PKplex_cmdline_parser_release (struct PKplex_args_info *args_info)
255 free_string_field (&(args_info->cutoff_orig));
256 free_string_field (&(args_info->temp_orig));
257 free_string_field (&(args_info->nsp_arg));
258 free_string_field (&(args_info->nsp_orig));
259 free_string_field (&(args_info->energyCutoff_orig));
260 free_string_field (&(args_info->paramFile_arg));
261 free_string_field (&(args_info->paramFile_orig));
262 free_string_field (&(args_info->subopts_orig));
266 clear_given (args_info);
271 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
275 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
277 fprintf(outfile, "%s\n", opt);
283 PKplex_cmdline_parser_dump(FILE *outfile, struct PKplex_args_info *args_info)
289 fprintf (stderr, "%s: cannot dump options to stream\n", PKPLEX_CMDLINE_PARSER_PACKAGE);
293 if (args_info->help_given)
294 write_into_file(outfile, "help", 0, 0 );
295 if (args_info->detailed_help_given)
296 write_into_file(outfile, "detailed-help", 0, 0 );
297 if (args_info->version_given)
298 write_into_file(outfile, "version", 0, 0 );
299 if (args_info->cutoff_given)
300 write_into_file(outfile, "cutoff", args_info->cutoff_orig, 0);
301 if (args_info->temp_given)
302 write_into_file(outfile, "temp", args_info->temp_orig, 0);
303 if (args_info->noTetra_given)
304 write_into_file(outfile, "noTetra", 0, 0 );
305 if (args_info->noLP_given)
306 write_into_file(outfile, "noLP", 0, 0 );
307 if (args_info->noGU_given)
308 write_into_file(outfile, "noGU", 0, 0 );
309 if (args_info->noClosingGU_given)
310 write_into_file(outfile, "noClosingGU", 0, 0 );
311 if (args_info->noconv_given)
312 write_into_file(outfile, "noconv", 0, 0 );
313 if (args_info->nsp_given)
314 write_into_file(outfile, "nsp", args_info->nsp_orig, 0);
315 if (args_info->energyCutoff_given)
316 write_into_file(outfile, "energyCutoff", args_info->energyCutoff_orig, 0);
317 if (args_info->paramFile_given)
318 write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
319 if (args_info->verbose_given)
320 write_into_file(outfile, "verbose", 0, 0 );
321 if (args_info->subopts_given)
322 write_into_file(outfile, "subopts", args_info->subopts_orig, 0);
330 PKplex_cmdline_parser_file_save(const char *filename, struct PKplex_args_info *args_info)
335 outfile = fopen(filename, "w");
339 fprintf (stderr, "%s: cannot open file for writing: %s\n", PKPLEX_CMDLINE_PARSER_PACKAGE, filename);
343 i = PKplex_cmdline_parser_dump(outfile, args_info);
350 PKplex_cmdline_parser_free (struct PKplex_args_info *args_info)
352 PKplex_cmdline_parser_release (args_info);
355 /** @brief replacement of strdup, which is not standard */
357 gengetopt_strdup (const char *s)
363 result = (char*)malloc(strlen(s) + 1);
364 if (result == (char*)0)
371 PKplex_cmdline_parser (int argc, char **argv, struct PKplex_args_info *args_info)
373 return PKplex_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
377 PKplex_cmdline_parser_ext (int argc, char **argv, struct PKplex_args_info *args_info,
378 struct PKplex_cmdline_parser_params *params)
381 result = PKplex_cmdline_parser_internal (argc, argv, args_info, params, 0);
383 if (result == EXIT_FAILURE)
385 PKplex_cmdline_parser_free (args_info);
393 PKplex_cmdline_parser2 (int argc, char **argv, struct PKplex_args_info *args_info, int override, int initialize, int check_required)
396 struct PKplex_cmdline_parser_params params;
398 params.override = override;
399 params.initialize = initialize;
400 params.check_required = check_required;
401 params.check_ambiguity = 0;
402 params.print_errors = 1;
404 result = PKplex_cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
406 if (result == EXIT_FAILURE)
408 PKplex_cmdline_parser_free (args_info);
416 PKplex_cmdline_parser_required (struct PKplex_args_info *args_info, const char *prog_name)
418 FIX_UNUSED (args_info);
419 FIX_UNUSED (prog_name);
424 * Extracted from the glibc source tree, version 2.3.6
426 * Licensed under the GPL as per the whole glibc source tree.
428 * This file was modified so that getopt_long can be called
429 * many times without risking previous memory to be spoiled.
431 * Modified by Andre Noll and Lorenzo Bettini for use in
432 * GNU gengetopt generated files.
437 * we must include anything we need since this file is not thought to be
438 * inserted in a file already using getopt.h
446 /* has_arg can't be an enum because some compilers complain about
447 type mismatches in all the code that assumes it is an int. */
453 /* This version of `getopt' appears to the caller like standard Unix `getopt'
454 but it behaves differently for the user, since it allows the user
455 to intersperse the options with the other arguments.
457 As `getopt' works, it permutes the elements of ARGV so that,
458 when it is done, all the options precede everything else. Thus
459 all application programs are extended to handle flexible argument order.
462 If the field `flag' is not NULL, it points to a variable that is set
463 to the value given in the field `val' when the option is found, but
464 left unchanged if the option is not found.
466 To have a long-named option do something other than set an `int' to
467 a compiled-in constant, such as set a value from `custom_optarg', set the
468 option's `flag' field to zero and its `val' field to a nonzero
469 value (the equivalent single-letter option character, if there is
470 one). For long options that have a zero `flag' field, `getopt'
471 returns the contents of the `val' field. */
473 /* Names for the values of the `has_arg' field of `struct option'. */
475 #define no_argument 0
478 #ifndef required_argument
479 #define required_argument 1
482 #ifndef optional_argument
483 #define optional_argument 2
486 struct custom_getopt_data {
488 * These have exactly the same meaning as the corresponding global variables,
489 * except that they are used for the reentrant versions of getopt.
496 /* True if the internal members have been initialized. */
500 * The next char to be scanned in the option-element in which the last option
501 * character we returned was found. This allows us to pick up the scan where
502 * we left off. If this is zero, or a null string, it means resume the scan by
503 * advancing to the next ARGV-element.
508 * Describe the part of ARGV that contains non-options that have been skipped.
509 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
510 * the index after the last of them.
517 * the variables optarg, optind, opterr and optopt are renamed with
518 * the custom_ prefix so that they don't interfere with getopt ones.
520 * Moreover they're static so they are visible only from within the
521 * file where this very file will be included.
525 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
526 * option that takes an argument, the argument value is returned here.
528 static char *custom_optarg;
531 * Index in ARGV of the next element to be scanned. This is used for
532 * communication to and from the caller and for communication between
533 * successive calls to `custom_getopt'.
535 * On entry to `custom_getopt', 1 means this is the first call; initialize.
537 * When `custom_getopt' returns -1, this is the index of the first of the non-option
538 * elements that the caller should itself scan.
540 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
541 * has been scanned so far.
543 * 1003.2 says this must be 1 before any call.
545 static int custom_optind = 1;
548 * Callers store zero here to inhibit the error message for unrecognized
551 static int custom_opterr = 1;
554 * Set to an option character which was unrecognized. This must be initialized
555 * on some systems to avoid linking in the system's own getopt implementation.
557 static int custom_optopt = '?';
560 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
561 * [first_nonopt,last_nonopt) which contains all the non-options that have been
562 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
563 * all the options processed since those non-options were skipped.
564 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
565 * indices of the non-options in ARGV after they are moved.
567 static void exchange(char **argv, struct custom_getopt_data *d)
569 int bottom = d->first_nonopt;
570 int middle = d->last_nonopt;
571 int top = d->custom_optind;
575 * Exchange the shorter segment with the far end of the longer segment.
576 * That puts the shorter segment into the right place. It leaves the
577 * longer segment in the right place overall, but it consists of two
578 * parts that need to be swapped next.
580 while (top > middle && middle > bottom) {
581 if (top - middle > middle - bottom) {
582 /* Bottom segment is the short one. */
583 int len = middle - bottom;
586 /* Swap it with the top part of the top segment. */
587 for (i = 0; i < len; i++) {
588 tem = argv[bottom + i];
590 argv[top - (middle - bottom) + i];
591 argv[top - (middle - bottom) + i] = tem;
593 /* Exclude the moved bottom segment from further swapping. */
596 /* Top segment is the short one. */
597 int len = top - middle;
600 /* Swap it with the bottom part of the bottom segment. */
601 for (i = 0; i < len; i++) {
602 tem = argv[bottom + i];
603 argv[bottom + i] = argv[middle + i];
604 argv[middle + i] = tem;
606 /* Exclude the moved top segment from further swapping. */
610 /* Update records for the slots the non-options now occupy. */
611 d->first_nonopt += (d->custom_optind - d->last_nonopt);
612 d->last_nonopt = d->custom_optind;
615 /* Initialize the internal data when the first call is made. */
616 static void custom_getopt_initialize(struct custom_getopt_data *d)
619 * Start processing options with ARGV-element 1 (since ARGV-element 0
620 * is the program name); the sequence of previously skipped non-option
621 * ARGV-elements is empty.
623 d->first_nonopt = d->last_nonopt = d->custom_optind;
628 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
630 /* return: zero: continue, nonzero: return given value to user */
631 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
632 struct custom_getopt_data *d)
635 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
636 * moved back by the user (who may also have changed the arguments).
638 if (d->last_nonopt > d->custom_optind)
639 d->last_nonopt = d->custom_optind;
640 if (d->first_nonopt > d->custom_optind)
641 d->first_nonopt = d->custom_optind;
643 * If we have just processed some options following some
644 * non-options, exchange them so that the options come first.
646 if (d->first_nonopt != d->last_nonopt &&
647 d->last_nonopt != d->custom_optind)
648 exchange((char **) argv, d);
649 else if (d->last_nonopt != d->custom_optind)
650 d->first_nonopt = d->custom_optind;
652 * Skip any additional non-options and extend the range of
653 * non-options previously skipped.
655 while (d->custom_optind < argc && NONOPTION_P)
657 d->last_nonopt = d->custom_optind;
659 * The special ARGV-element `--' means premature end of options. Skip
660 * it like a null option, then exchange with previous non-options as if
661 * it were an option, then skip everything else like a non-option.
663 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
665 if (d->first_nonopt != d->last_nonopt
666 && d->last_nonopt != d->custom_optind)
667 exchange((char **) argv, d);
668 else if (d->first_nonopt == d->last_nonopt)
669 d->first_nonopt = d->custom_optind;
670 d->last_nonopt = argc;
671 d->custom_optind = argc;
674 * If we have done all the ARGV-elements, stop the scan and back over
675 * any non-options that we skipped and permuted.
677 if (d->custom_optind == argc) {
679 * Set the next-arg-index to point at the non-options that we
680 * previously skipped, so the caller will digest them.
682 if (d->first_nonopt != d->last_nonopt)
683 d->custom_optind = d->first_nonopt;
687 * If we have come to a non-option and did not permute it, either stop
688 * the scan or describe it to the caller and pass it by.
691 d->custom_optarg = argv[d->custom_optind++];
695 * We have found another option-ARGV-element. Skip the initial
698 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
703 * Check whether the ARGV-element is a long option.
705 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
706 * that an abbreviation of the long option, just like "--fu", and not "-f" with
709 * This distinction seems to be the most useful approach.
712 static int check_long_opt(int argc, char *const *argv, const char *optstring,
713 const struct option *longopts, int *longind,
714 int print_errors, struct custom_getopt_data *d)
717 const struct option *p;
718 const struct option *pfound = NULL;
724 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
727 /* Test all long options for either exact match or abbreviated matches */
728 for (p = longopts, option_index = 0; p->name; p++, option_index++)
729 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
730 if ((unsigned int) (nameend - d->nextchar)
731 == (unsigned int) strlen(p->name)) {
732 /* Exact match found. */
734 indfound = option_index;
737 } else if (pfound == NULL) {
738 /* First nonexact match found. */
740 indfound = option_index;
741 } else if (pfound->has_arg != p->has_arg
742 || pfound->flag != p->flag
743 || pfound->val != p->val)
744 /* Second or later nonexact match found. */
747 if (ambig && !exact) {
750 "%s: option `%s' is ambiguous\n",
751 argv[0], argv[d->custom_optind]);
753 d->nextchar += strlen(d->nextchar);
755 d->custom_optopt = 0;
759 option_index = indfound;
762 if (pfound->has_arg != no_argument)
763 d->custom_optarg = nameend + 1;
766 if (argv[d->custom_optind - 1][1] == '-') {
768 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
769 argv[0], pfound->name);
771 /* +option or -option */
772 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
773 argv[0], argv[d->custom_optind - 1][0], pfound->name);
777 d->nextchar += strlen(d->nextchar);
778 d->custom_optopt = pfound->val;
781 } else if (pfound->has_arg == required_argument) {
782 if (d->custom_optind < argc)
783 d->custom_optarg = argv[d->custom_optind++];
787 "%s: option `%s' requires an argument\n",
789 argv[d->custom_optind - 1]);
791 d->nextchar += strlen(d->nextchar);
792 d->custom_optopt = pfound->val;
793 return optstring[0] == ':' ? ':' : '?';
796 d->nextchar += strlen(d->nextchar);
798 *longind = option_index;
800 *(pfound->flag) = pfound->val;
806 * Can't find it as a long option. If this is not getopt_long_only, or
807 * the option starts with '--' or is not a valid short option, then
808 * it's an error. Otherwise interpret it as a short option.
811 if (argv[d->custom_optind][1] == '-') {
814 "%s: unrecognized option `--%s'\n",
815 argv[0], d->nextchar);
817 /* +option or -option */
819 "%s: unrecognized option `%c%s'\n",
820 argv[0], argv[d->custom_optind][0],
824 d->nextchar = (char *) "";
826 d->custom_optopt = 0;
830 static int check_short_opt(int argc, char *const *argv, const char *optstring,
831 int print_errors, struct custom_getopt_data *d)
833 char c = *d->nextchar++;
834 const char *temp = strchr(optstring, c);
836 /* Increment `custom_optind' when we start to process its last character. */
837 if (*d->nextchar == '\0')
839 if (!temp || c == ':') {
841 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
843 d->custom_optopt = c;
846 if (temp[1] == ':') {
847 if (temp[2] == ':') {
848 /* This is an option that accepts an argument optionally. */
849 if (*d->nextchar != '\0') {
850 d->custom_optarg = d->nextchar;
853 d->custom_optarg = NULL;
856 /* This is an option that requires an argument. */
857 if (*d->nextchar != '\0') {
858 d->custom_optarg = d->nextchar;
860 * If we end this ARGV-element by taking the
861 * rest as an arg, we must advance to the next
865 } else if (d->custom_optind == argc) {
868 "%s: option requires an argument -- %c\n",
871 d->custom_optopt = c;
872 if (optstring[0] == ':')
878 * We already incremented `custom_optind' once;
879 * increment it again when taking next ARGV-elt
882 d->custom_optarg = argv[d->custom_optind++];
890 * Scan elements of ARGV for option characters given in OPTSTRING.
892 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
893 * then it is an option element. The characters of this element
894 * (aside from the initial '-') are option characters. If `getopt'
895 * is called repeatedly, it returns successively each of the option characters
896 * from each of the option elements.
898 * If `getopt' finds another option character, it returns that character,
899 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
900 * resume the scan with the following option character or ARGV-element.
902 * If there are no more option characters, `getopt' returns -1.
903 * Then `custom_optind' is the index in ARGV of the first ARGV-element
904 * that is not an option. (The ARGV-elements have been permuted
905 * so that those that are not options now come last.)
907 * OPTSTRING is a string containing the legitimate option characters.
908 * If an option character is seen that is not listed in OPTSTRING,
909 * return '?' after printing an error message. If you set `custom_opterr' to
910 * zero, the error message is suppressed but we still return '?'.
912 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
913 * so the following text in the same ARGV-element, or the text of the following
914 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
915 * wants an optional arg; if there is text in the current ARGV-element,
916 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
918 * If OPTSTRING starts with `-' or `+', it requests different methods of
919 * handling the non-option ARGV-elements.
920 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
922 * Long-named options begin with `--' instead of `-'.
923 * Their names may be abbreviated as long as the abbreviation is unique
924 * or is an exact match for some defined option. If they have an
925 * argument, it follows the option name in the same ARGV-element, separated
926 * from the option name by a `=', or else the in next ARGV-element.
927 * When `getopt' finds a long-named option, it returns 0 if that option's
928 * `flag' field is nonzero, the value of the option's `val' field
929 * if the `flag' field is zero.
931 * The elements of ARGV aren't really const, because we permute them.
932 * But we pretend they're const in the prototype to be compatible
933 * with other systems.
935 * LONGOPTS is a vector of `struct option' terminated by an
936 * element containing a name which is zero.
938 * LONGIND returns the index in LONGOPT of the long-named option found.
939 * It is only valid when a long-named option has been found by the most
942 * Return the option character from OPTS just read. Return -1 when there are
943 * no more options. For unrecognized options, or options missing arguments,
944 * `custom_optopt' is set to the option letter, and '?' is returned.
946 * The OPTS string is a list of characters which are recognized option letters,
947 * optionally followed by colons, specifying that that letter takes an
948 * argument, to be placed in `custom_optarg'.
950 * If a letter in OPTS is followed by two colons, its argument is optional.
951 * This behavior is specific to the GNU `getopt'.
953 * The argument `--' causes premature termination of argument scanning,
954 * explicitly telling `getopt' that there are no more options. If OPTS begins
955 * with `--', then non-option arguments are treated as arguments to the option
956 * '\0'. This behavior is specific to the GNU `getopt'.
959 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
960 const struct option *longopts, int *longind,
961 struct custom_getopt_data *d)
963 int ret, print_errors = d->custom_opterr;
965 if (optstring[0] == ':')
969 d->custom_optarg = NULL;
972 * This is a big difference with GNU getopt, since optind == 0
973 * means initialization while here 1 means first call.
975 if (d->custom_optind == 0 || !d->initialized) {
976 if (d->custom_optind == 0)
977 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
978 custom_getopt_initialize(d);
980 if (d->nextchar == NULL || *d->nextchar == '\0') {
981 ret = shuffle_argv(argc, argv, longopts, d);
985 if (longopts && (argv[d->custom_optind][1] == '-' ))
986 return check_long_opt(argc, argv, optstring, longopts,
987 longind, print_errors, d);
988 return check_short_opt(argc, argv, optstring, print_errors, d);
991 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
992 const struct option *longopts, int *longind)
995 /* Keep a global copy of all internal members of d */
996 static struct custom_getopt_data d;
998 d.custom_optind = custom_optind;
999 d.custom_opterr = custom_opterr;
1000 result = getopt_internal_r(argc, argv, optstring, longopts,
1002 custom_optind = d.custom_optind;
1003 custom_optarg = d.custom_optarg;
1004 custom_optopt = d.custom_optopt;
1008 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1009 const struct option *long_options, int *opt_index)
1011 return custom_getopt_internal(argc, argv, options, long_options,
1016 static char *package_name = 0;
1019 * @brief updates an option
1020 * @param field the generic pointer to the field to update
1021 * @param orig_field the pointer to the orig field
1022 * @param field_given the pointer to the number of occurrence of this option
1023 * @param prev_given the pointer to the number of occurrence already seen
1024 * @param value the argument for this option (if null no arg was specified)
1025 * @param possible_values the possible values for this option (if specified)
1026 * @param default_value the default value (in case the option only accepts fixed values)
1027 * @param arg_type the type of this option
1028 * @param check_ambiguity @see PKplex_cmdline_parser_params.check_ambiguity
1029 * @param override @see PKplex_cmdline_parser_params.override
1030 * @param no_free whether to free a possible previous value
1031 * @param multiple_option whether this is a multiple option
1032 * @param long_opt the corresponding long option
1033 * @param short_opt the corresponding short option (or '-' if none)
1034 * @param additional_error possible further error specification
1037 int update_arg(void *field, char **orig_field,
1038 unsigned int *field_given, unsigned int *prev_given,
1039 char *value, const char *possible_values[],
1040 const char *default_value,
1041 PKplex_cmdline_parser_arg_type arg_type,
1042 int check_ambiguity, int override,
1043 int no_free, int multiple_option,
1044 const char *long_opt, char short_opt,
1045 const char *additional_error)
1047 char *stop_char = 0;
1048 const char *val = value;
1050 char **string_field;
1056 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1058 if (short_opt != '-')
1059 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1060 package_name, long_opt, short_opt,
1061 (additional_error ? additional_error : ""));
1063 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1064 package_name, long_opt,
1065 (additional_error ? additional_error : ""));
1066 return 1; /* failure */
1069 FIX_UNUSED (default_value);
1071 if (field_given && *field_given && ! override)
1077 if (possible_values)
1078 val = possible_values[found];
1082 *((int *)field) = !*((int *)field);
1085 if (val) *((float *)field) = (float)strtod (val, &stop_char);
1088 if (val) *((double *)field) = strtod (val, &stop_char);
1092 string_field = (char **)field;
1093 if (!no_free && *string_field)
1094 free (*string_field); /* free previous string */
1095 *string_field = gengetopt_strdup (val);
1102 /* check numeric conversion */
1106 if (val && !(stop_char && *stop_char == '\0')) {
1107 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1108 return 1; /* failure */
1115 /* store the original value */
1121 if (value && orig_field) {
1123 *orig_field = value;
1126 free (*orig_field); /* free previous string */
1127 *orig_field = gengetopt_strdup (value);
1137 PKplex_cmdline_parser_internal (
1138 int argc, char **argv, struct PKplex_args_info *args_info,
1139 struct PKplex_cmdline_parser_params *params, const char *additional_error)
1141 int c; /* Character of the parsed option. */
1144 struct PKplex_args_info local_args_info;
1149 int check_ambiguity;
1156 package_name = argv[0];
1158 override = params->override;
1159 initialize = params->initialize;
1160 check_required = params->check_required;
1161 check_ambiguity = params->check_ambiguity;
1164 PKplex_cmdline_parser_init (args_info);
1166 PKplex_cmdline_parser_init (&local_args_info);
1170 opterr = params->print_errors;
1175 int option_index = 0;
1177 static struct option long_options[] = {
1178 { "help", 0, NULL, 'h' },
1179 { "detailed-help", 0, NULL, 0 },
1180 { "version", 0, NULL, 'V' },
1181 { "cutoff", 1, NULL, 'c' },
1182 { "temp", 1, NULL, 'T' },
1183 { "noTetra", 0, NULL, '4' },
1184 { "noLP", 0, NULL, 0 },
1185 { "noGU", 0, NULL, 0 },
1186 { "noClosingGU", 0, NULL, 0 },
1187 { "noconv", 0, NULL, 0 },
1188 { "nsp", 1, NULL, 0 },
1189 { "energyCutoff", 1, NULL, 'e' },
1190 { "paramFile", 1, NULL, 'P' },
1191 { "verbose", 0, NULL, 'v' },
1192 { "subopts", 1, NULL, 's' },
1196 custom_optarg = optarg;
1197 custom_optind = optind;
1198 custom_opterr = opterr;
1199 custom_optopt = optopt;
1201 c = custom_getopt_long (argc, argv, "hVc:T:4e:P:vs:", long_options, &option_index);
1203 optarg = custom_optarg;
1204 optind = custom_optind;
1205 opterr = custom_opterr;
1206 optopt = custom_optopt;
1208 if (c == -1) break; /* Exit from `while (1)' loop. */
1212 case 'h': /* Print help and exit. */
1213 PKplex_cmdline_parser_print_help ();
1214 PKplex_cmdline_parser_free (&local_args_info);
1215 exit (EXIT_SUCCESS);
1217 case 'V': /* Print version and exit. */
1218 PKplex_cmdline_parser_print_version ();
1219 PKplex_cmdline_parser_free (&local_args_info);
1220 exit (EXIT_SUCCESS);
1222 case 'c': /* Report only base pairs with an average probability > cutoff in the dot plot
1227 if (update_arg( (void *)&(args_info->cutoff_arg),
1228 &(args_info->cutoff_orig), &(args_info->cutoff_given),
1229 &(local_args_info.cutoff_given), optarg, 0, "0.01", ARG_FLOAT,
1230 check_ambiguity, override, 0, 0,
1236 case 'T': /* Rescale energy parameters to a temperature of temp C. Default is 37C.
1241 if (update_arg( (void *)&(args_info->temp_arg),
1242 &(args_info->temp_orig), &(args_info->temp_given),
1243 &(local_args_info.temp_given), optarg, 0, 0, ARG_DOUBLE,
1244 check_ambiguity, override, 0, 0,
1250 case '4': /* Do not include special stabilizing energies for certain tetra-loops. Mostly for testing.
1255 if (update_arg((void *)&(args_info->noTetra_flag), 0, &(args_info->noTetra_given),
1256 &(local_args_info.noTetra_given), optarg, 0, 0, ARG_FLAG,
1257 check_ambiguity, override, 1, 0, "noTetra", '4',
1262 case 'e': /* Energy cutoff or pseudoknot initiation cost. Minimum energy gain of a pseudoknot interaction for it to be returned. Pseudoknots with smaller energy gains are rejected.
1267 if (update_arg( (void *)&(args_info->energyCutoff_arg),
1268 &(args_info->energyCutoff_orig), &(args_info->energyCutoff_given),
1269 &(local_args_info.energyCutoff_given), optarg, 0, "-8.10", ARG_DOUBLE,
1270 check_ambiguity, override, 0, 0,
1271 "energyCutoff", 'e',
1276 case 'P': /* Read energy parameters from paramfile, instead of using the default parameter set.
1280 if (update_arg( (void *)&(args_info->paramFile_arg),
1281 &(args_info->paramFile_orig), &(args_info->paramFile_given),
1282 &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1283 check_ambiguity, override, 0, 0,
1289 case 'v': /* print verbose output
1293 if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
1294 &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
1295 check_ambiguity, override, 1, 0, "verbose", 'v',
1300 case 's': /* print suboptimal structures whose energy difference of the pseudoknot to the optimum pseudoknot is smaller than the given value.
1304 if (update_arg( (void *)&(args_info->subopts_arg),
1305 &(args_info->subopts_orig), &(args_info->subopts_given),
1306 &(local_args_info.subopts_given), optarg, 0, "0.0", ARG_DOUBLE,
1307 check_ambiguity, override, 0, 0,
1314 case 0: /* Long option with no short option */
1315 if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1316 PKplex_cmdline_parser_print_detailed_help ();
1317 PKplex_cmdline_parser_free (&local_args_info);
1318 exit (EXIT_SUCCESS);
1321 /* Produce structures without lonely pairs (helices of length 1).
1323 if (strcmp (long_options[option_index].name, "noLP") == 0)
1327 if (update_arg((void *)&(args_info->noLP_flag), 0, &(args_info->noLP_given),
1328 &(local_args_info.noLP_given), optarg, 0, 0, ARG_FLAG,
1329 check_ambiguity, override, 1, 0, "noLP", '-',
1334 /* Do not allow GU pairs
1337 else if (strcmp (long_options[option_index].name, "noGU") == 0)
1341 if (update_arg((void *)&(args_info->noGU_flag), 0, &(args_info->noGU_given),
1342 &(local_args_info.noGU_given), optarg, 0, 0, ARG_FLAG,
1343 check_ambiguity, override, 1, 0, "noGU", '-',
1348 /* Do not allow GU pairs at the end of helices
1351 else if (strcmp (long_options[option_index].name, "noClosingGU") == 0)
1355 if (update_arg((void *)&(args_info->noClosingGU_flag), 0, &(args_info->noClosingGU_given),
1356 &(local_args_info.noClosingGU_given), optarg, 0, 0, ARG_FLAG,
1357 check_ambiguity, override, 1, 0, "noClosingGU", '-',
1362 /* Do not automatically substitude nucleotide \"T\" with \"U\"
1365 else if (strcmp (long_options[option_index].name, "noconv") == 0)
1369 if (update_arg((void *)&(args_info->noconv_flag), 0, &(args_info->noconv_given),
1370 &(local_args_info.noconv_given), optarg, 0, 0, ARG_FLAG,
1371 check_ambiguity, override, 1, 0, "noconv", '-',
1376 /* Allow other pairs in addition to the usual AU,GC,and GU pairs.
1378 else if (strcmp (long_options[option_index].name, "nsp") == 0)
1382 if (update_arg( (void *)&(args_info->nsp_arg),
1383 &(args_info->nsp_orig), &(args_info->nsp_given),
1384 &(local_args_info.nsp_given), optarg, 0, "empty", ARG_STRING,
1385 check_ambiguity, override, 0, 0,
1393 case '?': /* Invalid option. */
1394 /* `getopt_long' already printed an error message. */
1397 default: /* bug: option not considered. */
1398 fprintf (stderr, "%s: option unknown: %c%s\n", PKPLEX_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1406 PKplex_cmdline_parser_release (&local_args_info);
1409 return (EXIT_FAILURE);
1415 PKplex_cmdline_parser_release (&local_args_info);
1416 return (EXIT_FAILURE);