2 File autogenerated by gengetopt version 2.22.5
3 generated with the following command:
4 gengetopt -i RNAparconv.ggo --file-name=RNAparconv_cmdl --include-getopt --default-optional --unamed-opts --func-name=RNAparconv_cmdline_parser --arg-struct-name=RNAparconv_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 "RNAparconv_cmdl.h"
27 const char *RNAparconv_args_info_purpose = "Convert energy parameter files from ViennaRNA 1.8.4 to 2.0 format";
29 const char *RNAparconv_args_info_usage = "Usage: RNAparconv [options] [<input file>] [<output file>]\n";
31 const char *RNAparconv_args_info_description = "Converts energy parameter files from \"old\" ViennaRNAPackage 1.8.4 format to \nthe new format used since ViennaRNAPackage 2.0.\nThe Program reads a valid energy parameter file or valid energy parameters from \nstdin and prints the converted energy parameters to stdout or a specified \noutput file. Per default, the converted output file contains the whole set of \nenergy parameters used throughout ViennaRNAPackage 1.8.4. The user can specify \nsets of energy parameters that should not be included in the output.\n";
33 const char *RNAparconv_args_info_full_help[] = {
34 " -h, --help Print help and exit",
35 " --full-help Print help, including hidden options, and exit",
36 " -V, --version Print version and exit",
37 " -o, --output=filename Specify an output file name. If argument is missing \n the converted energy parameters are printed to \n 'stdout'.\n\n",
38 " -i, --input=filename Specify an input file name. If argument is missing \n the energy parameter input can be supplied via \n 'stdin'.\n\n",
39 " --vanilla Print just as much as needed to represent the given \n energy parameters data set.\n This option overrides all other output settings!\n\n (default=off)",
40 " --dump Just dump Vienna 1.8.4 energy parameters in format \n used since 2.0.\n This option skips any energy parameter input!\n\n (default=off)",
41 " --silent Print just energy parameters and appropriate comment \n lines but suppress all other output\n\n (default=off)",
42 " --without-HairpinE Do not print converted hairpin energies and \n enthalpies\n\n (default=off)",
43 " --without-StackE Do not print converted stacking energies and \n enthalpies\n\n (default=off)",
44 " --without-IntE Do not print converted interior loop energies, \n enthalpies and asymetry factors\n\n (default=off)",
45 " --without-BulgeE Do not print converted bulge loop energies and \n enthalpies\n\n (default=off)",
46 " --without-MultiE Do not print converted multi loop energies and \n enthalpies\n\n (default=off)",
47 " --without-MismatchE Do not print converted exterior loop mismatch \n energies and enthalpies\n\n (default=off)",
48 " --without-MismatchH Do not print converted hairpin mismatch energies and \n enthalpies\n\n (default=off)",
49 " --without-MismatchI Do not print converted interior loop mismatch \n energies and enthalpies\n\n (default=off)",
50 " --without-MismatchM Do not print converted multi loop mismatch energies \n and enthalpies\n\n (default=off)",
51 " --without-Dangle5 Do not print converted 5' dangle energies and \n enthalpies\n\n (default=off)",
52 " --without-Dangle3 Do not print converted 3' dangle energies and \n enthalpies\n\n (default=off)",
53 " --without-Misc Do not print converted Misc energies and enthalpies \n (TerminalAU, DuplexInit, lxc)\n\n (default=off)",
54 "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
61 RNAparconv_args_info_help[0] = RNAparconv_args_info_full_help[0];
62 RNAparconv_args_info_help[1] = RNAparconv_args_info_full_help[1];
63 RNAparconv_args_info_help[2] = RNAparconv_args_info_full_help[2];
64 RNAparconv_args_info_help[3] = RNAparconv_args_info_full_help[3];
65 RNAparconv_args_info_help[4] = RNAparconv_args_info_full_help[4];
66 RNAparconv_args_info_help[5] = RNAparconv_args_info_full_help[5];
67 RNAparconv_args_info_help[6] = RNAparconv_args_info_full_help[6];
68 RNAparconv_args_info_help[7] = RNAparconv_args_info_full_help[7];
69 RNAparconv_args_info_help[8] = RNAparconv_args_info_full_help[20];
70 RNAparconv_args_info_help[9] = 0;
74 const char *RNAparconv_args_info_help[10];
79 } RNAparconv_cmdline_parser_arg_type;
82 void clear_given (struct RNAparconv_args_info *args_info);
84 void clear_args (struct RNAparconv_args_info *args_info);
87 RNAparconv_cmdline_parser_internal (int argc, char **argv, struct RNAparconv_args_info *args_info,
88 struct RNAparconv_cmdline_parser_params *params, const char *additional_error);
92 gengetopt_strdup (const char *s);
95 void clear_given (struct RNAparconv_args_info *args_info)
97 args_info->help_given = 0 ;
98 args_info->full_help_given = 0 ;
99 args_info->version_given = 0 ;
100 args_info->output_given = 0 ;
101 args_info->input_given = 0 ;
102 args_info->vanilla_given = 0 ;
103 args_info->dump_given = 0 ;
104 args_info->silent_given = 0 ;
105 args_info->without_HairpinE_given = 0 ;
106 args_info->without_StackE_given = 0 ;
107 args_info->without_IntE_given = 0 ;
108 args_info->without_BulgeE_given = 0 ;
109 args_info->without_MultiE_given = 0 ;
110 args_info->without_MismatchE_given = 0 ;
111 args_info->without_MismatchH_given = 0 ;
112 args_info->without_MismatchI_given = 0 ;
113 args_info->without_MismatchM_given = 0 ;
114 args_info->without_Dangle5_given = 0 ;
115 args_info->without_Dangle3_given = 0 ;
116 args_info->without_Misc_given = 0 ;
120 void clear_args (struct RNAparconv_args_info *args_info)
122 FIX_UNUSED (args_info);
123 args_info->output_arg = NULL;
124 args_info->output_orig = NULL;
125 args_info->input_arg = NULL;
126 args_info->input_orig = NULL;
127 args_info->vanilla_flag = 0;
128 args_info->dump_flag = 0;
129 args_info->silent_flag = 0;
130 args_info->without_HairpinE_flag = 0;
131 args_info->without_StackE_flag = 0;
132 args_info->without_IntE_flag = 0;
133 args_info->without_BulgeE_flag = 0;
134 args_info->without_MultiE_flag = 0;
135 args_info->without_MismatchE_flag = 0;
136 args_info->without_MismatchH_flag = 0;
137 args_info->without_MismatchI_flag = 0;
138 args_info->without_MismatchM_flag = 0;
139 args_info->without_Dangle5_flag = 0;
140 args_info->without_Dangle3_flag = 0;
141 args_info->without_Misc_flag = 0;
146 void init_args_info(struct RNAparconv_args_info *args_info)
150 args_info->help_help = RNAparconv_args_info_full_help[0] ;
151 args_info->full_help_help = RNAparconv_args_info_full_help[1] ;
152 args_info->version_help = RNAparconv_args_info_full_help[2] ;
153 args_info->output_help = RNAparconv_args_info_full_help[3] ;
154 args_info->input_help = RNAparconv_args_info_full_help[4] ;
155 args_info->vanilla_help = RNAparconv_args_info_full_help[5] ;
156 args_info->dump_help = RNAparconv_args_info_full_help[6] ;
157 args_info->silent_help = RNAparconv_args_info_full_help[7] ;
158 args_info->without_HairpinE_help = RNAparconv_args_info_full_help[8] ;
159 args_info->without_StackE_help = RNAparconv_args_info_full_help[9] ;
160 args_info->without_IntE_help = RNAparconv_args_info_full_help[10] ;
161 args_info->without_BulgeE_help = RNAparconv_args_info_full_help[11] ;
162 args_info->without_MultiE_help = RNAparconv_args_info_full_help[12] ;
163 args_info->without_MismatchE_help = RNAparconv_args_info_full_help[13] ;
164 args_info->without_MismatchH_help = RNAparconv_args_info_full_help[14] ;
165 args_info->without_MismatchI_help = RNAparconv_args_info_full_help[15] ;
166 args_info->without_MismatchM_help = RNAparconv_args_info_full_help[16] ;
167 args_info->without_Dangle5_help = RNAparconv_args_info_full_help[17] ;
168 args_info->without_Dangle3_help = RNAparconv_args_info_full_help[18] ;
169 args_info->without_Misc_help = RNAparconv_args_info_full_help[19] ;
174 RNAparconv_cmdline_parser_print_version (void)
177 (strlen(RNAPARCONV_CMDLINE_PARSER_PACKAGE_NAME) ? RNAPARCONV_CMDLINE_PARSER_PACKAGE_NAME : RNAPARCONV_CMDLINE_PARSER_PACKAGE),
178 RNAPARCONV_CMDLINE_PARSER_VERSION);
181 static void print_help_common(void) {
182 RNAparconv_cmdline_parser_print_version ();
184 if (strlen(RNAparconv_args_info_purpose) > 0)
185 printf("\n%s\n", RNAparconv_args_info_purpose);
187 if (strlen(RNAparconv_args_info_usage) > 0)
188 printf("\n%s\n", RNAparconv_args_info_usage);
192 if (strlen(RNAparconv_args_info_description) > 0)
193 printf("%s\n\n", RNAparconv_args_info_description);
197 RNAparconv_cmdline_parser_print_help (void)
201 while (RNAparconv_args_info_help[i])
202 printf("%s\n", RNAparconv_args_info_help[i++]);
206 RNAparconv_cmdline_parser_print_full_help (void)
210 while (RNAparconv_args_info_full_help[i])
211 printf("%s\n", RNAparconv_args_info_full_help[i++]);
215 RNAparconv_cmdline_parser_init (struct RNAparconv_args_info *args_info)
217 clear_given (args_info);
218 clear_args (args_info);
219 init_args_info (args_info);
221 args_info->inputs = 0;
222 args_info->inputs_num = 0;
226 RNAparconv_cmdline_parser_params_init(struct RNAparconv_cmdline_parser_params *params)
230 params->override = 0;
231 params->initialize = 1;
232 params->check_required = 1;
233 params->check_ambiguity = 0;
234 params->print_errors = 1;
238 struct RNAparconv_cmdline_parser_params *
239 RNAparconv_cmdline_parser_params_create(void)
241 struct RNAparconv_cmdline_parser_params *params =
242 (struct RNAparconv_cmdline_parser_params *)malloc(sizeof(struct RNAparconv_cmdline_parser_params));
243 RNAparconv_cmdline_parser_params_init(params);
248 free_string_field (char **s)
259 RNAparconv_cmdline_parser_release (struct RNAparconv_args_info *args_info)
262 free_string_field (&(args_info->output_arg));
263 free_string_field (&(args_info->output_orig));
264 free_string_field (&(args_info->input_arg));
265 free_string_field (&(args_info->input_orig));
268 for (i = 0; i < args_info->inputs_num; ++i)
269 free (args_info->inputs [i]);
271 if (args_info->inputs_num)
272 free (args_info->inputs);
274 clear_given (args_info);
279 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
283 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
285 fprintf(outfile, "%s\n", opt);
291 RNAparconv_cmdline_parser_dump(FILE *outfile, struct RNAparconv_args_info *args_info)
297 fprintf (stderr, "%s: cannot dump options to stream\n", RNAPARCONV_CMDLINE_PARSER_PACKAGE);
301 if (args_info->help_given)
302 write_into_file(outfile, "help", 0, 0 );
303 if (args_info->full_help_given)
304 write_into_file(outfile, "full-help", 0, 0 );
305 if (args_info->version_given)
306 write_into_file(outfile, "version", 0, 0 );
307 if (args_info->output_given)
308 write_into_file(outfile, "output", args_info->output_orig, 0);
309 if (args_info->input_given)
310 write_into_file(outfile, "input", args_info->input_orig, 0);
311 if (args_info->vanilla_given)
312 write_into_file(outfile, "vanilla", 0, 0 );
313 if (args_info->dump_given)
314 write_into_file(outfile, "dump", 0, 0 );
315 if (args_info->silent_given)
316 write_into_file(outfile, "silent", 0, 0 );
317 if (args_info->without_HairpinE_given)
318 write_into_file(outfile, "without-HairpinE", 0, 0 );
319 if (args_info->without_StackE_given)
320 write_into_file(outfile, "without-StackE", 0, 0 );
321 if (args_info->without_IntE_given)
322 write_into_file(outfile, "without-IntE", 0, 0 );
323 if (args_info->without_BulgeE_given)
324 write_into_file(outfile, "without-BulgeE", 0, 0 );
325 if (args_info->without_MultiE_given)
326 write_into_file(outfile, "without-MultiE", 0, 0 );
327 if (args_info->without_MismatchE_given)
328 write_into_file(outfile, "without-MismatchE", 0, 0 );
329 if (args_info->without_MismatchH_given)
330 write_into_file(outfile, "without-MismatchH", 0, 0 );
331 if (args_info->without_MismatchI_given)
332 write_into_file(outfile, "without-MismatchI", 0, 0 );
333 if (args_info->without_MismatchM_given)
334 write_into_file(outfile, "without-MismatchM", 0, 0 );
335 if (args_info->without_Dangle5_given)
336 write_into_file(outfile, "without-Dangle5", 0, 0 );
337 if (args_info->without_Dangle3_given)
338 write_into_file(outfile, "without-Dangle3", 0, 0 );
339 if (args_info->without_Misc_given)
340 write_into_file(outfile, "without-Misc", 0, 0 );
348 RNAparconv_cmdline_parser_file_save(const char *filename, struct RNAparconv_args_info *args_info)
353 outfile = fopen(filename, "w");
357 fprintf (stderr, "%s: cannot open file for writing: %s\n", RNAPARCONV_CMDLINE_PARSER_PACKAGE, filename);
361 i = RNAparconv_cmdline_parser_dump(outfile, args_info);
368 RNAparconv_cmdline_parser_free (struct RNAparconv_args_info *args_info)
370 RNAparconv_cmdline_parser_release (args_info);
373 /** @brief replacement of strdup, which is not standard */
375 gengetopt_strdup (const char *s)
381 result = (char*)malloc(strlen(s) + 1);
382 if (result == (char*)0)
389 RNAparconv_cmdline_parser (int argc, char **argv, struct RNAparconv_args_info *args_info)
391 return RNAparconv_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
395 RNAparconv_cmdline_parser_ext (int argc, char **argv, struct RNAparconv_args_info *args_info,
396 struct RNAparconv_cmdline_parser_params *params)
399 result = RNAparconv_cmdline_parser_internal (argc, argv, args_info, params, 0);
401 if (result == EXIT_FAILURE)
403 RNAparconv_cmdline_parser_free (args_info);
411 RNAparconv_cmdline_parser2 (int argc, char **argv, struct RNAparconv_args_info *args_info, int override, int initialize, int check_required)
414 struct RNAparconv_cmdline_parser_params params;
416 params.override = override;
417 params.initialize = initialize;
418 params.check_required = check_required;
419 params.check_ambiguity = 0;
420 params.print_errors = 1;
422 result = RNAparconv_cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
424 if (result == EXIT_FAILURE)
426 RNAparconv_cmdline_parser_free (args_info);
434 RNAparconv_cmdline_parser_required (struct RNAparconv_args_info *args_info, const char *prog_name)
436 FIX_UNUSED (args_info);
437 FIX_UNUSED (prog_name);
442 * Extracted from the glibc source tree, version 2.3.6
444 * Licensed under the GPL as per the whole glibc source tree.
446 * This file was modified so that getopt_long can be called
447 * many times without risking previous memory to be spoiled.
449 * Modified by Andre Noll and Lorenzo Bettini for use in
450 * GNU gengetopt generated files.
455 * we must include anything we need since this file is not thought to be
456 * inserted in a file already using getopt.h
464 /* has_arg can't be an enum because some compilers complain about
465 type mismatches in all the code that assumes it is an int. */
471 /* This version of `getopt' appears to the caller like standard Unix `getopt'
472 but it behaves differently for the user, since it allows the user
473 to intersperse the options with the other arguments.
475 As `getopt' works, it permutes the elements of ARGV so that,
476 when it is done, all the options precede everything else. Thus
477 all application programs are extended to handle flexible argument order.
480 If the field `flag' is not NULL, it points to a variable that is set
481 to the value given in the field `val' when the option is found, but
482 left unchanged if the option is not found.
484 To have a long-named option do something other than set an `int' to
485 a compiled-in constant, such as set a value from `custom_optarg', set the
486 option's `flag' field to zero and its `val' field to a nonzero
487 value (the equivalent single-letter option character, if there is
488 one). For long options that have a zero `flag' field, `getopt'
489 returns the contents of the `val' field. */
491 /* Names for the values of the `has_arg' field of `struct option'. */
493 #define no_argument 0
496 #ifndef required_argument
497 #define required_argument 1
500 #ifndef optional_argument
501 #define optional_argument 2
504 struct custom_getopt_data {
506 * These have exactly the same meaning as the corresponding global variables,
507 * except that they are used for the reentrant versions of getopt.
514 /* True if the internal members have been initialized. */
518 * The next char to be scanned in the option-element in which the last option
519 * character we returned was found. This allows us to pick up the scan where
520 * we left off. If this is zero, or a null string, it means resume the scan by
521 * advancing to the next ARGV-element.
526 * Describe the part of ARGV that contains non-options that have been skipped.
527 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
528 * the index after the last of them.
535 * the variables optarg, optind, opterr and optopt are renamed with
536 * the custom_ prefix so that they don't interfere with getopt ones.
538 * Moreover they're static so they are visible only from within the
539 * file where this very file will be included.
543 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
544 * option that takes an argument, the argument value is returned here.
546 static char *custom_optarg;
549 * Index in ARGV of the next element to be scanned. This is used for
550 * communication to and from the caller and for communication between
551 * successive calls to `custom_getopt'.
553 * On entry to `custom_getopt', 1 means this is the first call; initialize.
555 * When `custom_getopt' returns -1, this is the index of the first of the non-option
556 * elements that the caller should itself scan.
558 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
559 * has been scanned so far.
561 * 1003.2 says this must be 1 before any call.
563 static int custom_optind = 1;
566 * Callers store zero here to inhibit the error message for unrecognized
569 static int custom_opterr = 1;
572 * Set to an option character which was unrecognized. This must be initialized
573 * on some systems to avoid linking in the system's own getopt implementation.
575 static int custom_optopt = '?';
578 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
579 * [first_nonopt,last_nonopt) which contains all the non-options that have been
580 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
581 * all the options processed since those non-options were skipped.
582 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
583 * indices of the non-options in ARGV after they are moved.
585 static void exchange(char **argv, struct custom_getopt_data *d)
587 int bottom = d->first_nonopt;
588 int middle = d->last_nonopt;
589 int top = d->custom_optind;
593 * Exchange the shorter segment with the far end of the longer segment.
594 * That puts the shorter segment into the right place. It leaves the
595 * longer segment in the right place overall, but it consists of two
596 * parts that need to be swapped next.
598 while (top > middle && middle > bottom) {
599 if (top - middle > middle - bottom) {
600 /* Bottom segment is the short one. */
601 int len = middle - bottom;
604 /* Swap it with the top part of the top segment. */
605 for (i = 0; i < len; i++) {
606 tem = argv[bottom + i];
608 argv[top - (middle - bottom) + i];
609 argv[top - (middle - bottom) + i] = tem;
611 /* Exclude the moved bottom segment from further swapping. */
614 /* Top segment is the short one. */
615 int len = top - middle;
618 /* Swap it with the bottom part of the bottom segment. */
619 for (i = 0; i < len; i++) {
620 tem = argv[bottom + i];
621 argv[bottom + i] = argv[middle + i];
622 argv[middle + i] = tem;
624 /* Exclude the moved top segment from further swapping. */
628 /* Update records for the slots the non-options now occupy. */
629 d->first_nonopt += (d->custom_optind - d->last_nonopt);
630 d->last_nonopt = d->custom_optind;
633 /* Initialize the internal data when the first call is made. */
634 static void custom_getopt_initialize(struct custom_getopt_data *d)
637 * Start processing options with ARGV-element 1 (since ARGV-element 0
638 * is the program name); the sequence of previously skipped non-option
639 * ARGV-elements is empty.
641 d->first_nonopt = d->last_nonopt = d->custom_optind;
646 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
648 /* return: zero: continue, nonzero: return given value to user */
649 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
650 struct custom_getopt_data *d)
653 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
654 * moved back by the user (who may also have changed the arguments).
656 if (d->last_nonopt > d->custom_optind)
657 d->last_nonopt = d->custom_optind;
658 if (d->first_nonopt > d->custom_optind)
659 d->first_nonopt = d->custom_optind;
661 * If we have just processed some options following some
662 * non-options, exchange them so that the options come first.
664 if (d->first_nonopt != d->last_nonopt &&
665 d->last_nonopt != d->custom_optind)
666 exchange((char **) argv, d);
667 else if (d->last_nonopt != d->custom_optind)
668 d->first_nonopt = d->custom_optind;
670 * Skip any additional non-options and extend the range of
671 * non-options previously skipped.
673 while (d->custom_optind < argc && NONOPTION_P)
675 d->last_nonopt = d->custom_optind;
677 * The special ARGV-element `--' means premature end of options. Skip
678 * it like a null option, then exchange with previous non-options as if
679 * it were an option, then skip everything else like a non-option.
681 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
683 if (d->first_nonopt != d->last_nonopt
684 && d->last_nonopt != d->custom_optind)
685 exchange((char **) argv, d);
686 else if (d->first_nonopt == d->last_nonopt)
687 d->first_nonopt = d->custom_optind;
688 d->last_nonopt = argc;
689 d->custom_optind = argc;
692 * If we have done all the ARGV-elements, stop the scan and back over
693 * any non-options that we skipped and permuted.
695 if (d->custom_optind == argc) {
697 * Set the next-arg-index to point at the non-options that we
698 * previously skipped, so the caller will digest them.
700 if (d->first_nonopt != d->last_nonopt)
701 d->custom_optind = d->first_nonopt;
705 * If we have come to a non-option and did not permute it, either stop
706 * the scan or describe it to the caller and pass it by.
709 d->custom_optarg = argv[d->custom_optind++];
713 * We have found another option-ARGV-element. Skip the initial
716 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
721 * Check whether the ARGV-element is a long option.
723 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
724 * that an abbreviation of the long option, just like "--fu", and not "-f" with
727 * This distinction seems to be the most useful approach.
730 static int check_long_opt(int argc, char *const *argv, const char *optstring,
731 const struct option *longopts, int *longind,
732 int print_errors, struct custom_getopt_data *d)
735 const struct option *p;
736 const struct option *pfound = NULL;
742 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
745 /* Test all long options for either exact match or abbreviated matches */
746 for (p = longopts, option_index = 0; p->name; p++, option_index++)
747 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
748 if ((unsigned int) (nameend - d->nextchar)
749 == (unsigned int) strlen(p->name)) {
750 /* Exact match found. */
752 indfound = option_index;
755 } else if (pfound == NULL) {
756 /* First nonexact match found. */
758 indfound = option_index;
759 } else if (pfound->has_arg != p->has_arg
760 || pfound->flag != p->flag
761 || pfound->val != p->val)
762 /* Second or later nonexact match found. */
765 if (ambig && !exact) {
768 "%s: option `%s' is ambiguous\n",
769 argv[0], argv[d->custom_optind]);
771 d->nextchar += strlen(d->nextchar);
773 d->custom_optopt = 0;
777 option_index = indfound;
780 if (pfound->has_arg != no_argument)
781 d->custom_optarg = nameend + 1;
784 if (argv[d->custom_optind - 1][1] == '-') {
786 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
787 argv[0], pfound->name);
789 /* +option or -option */
790 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
791 argv[0], argv[d->custom_optind - 1][0], pfound->name);
795 d->nextchar += strlen(d->nextchar);
796 d->custom_optopt = pfound->val;
799 } else if (pfound->has_arg == required_argument) {
800 if (d->custom_optind < argc)
801 d->custom_optarg = argv[d->custom_optind++];
805 "%s: option `%s' requires an argument\n",
807 argv[d->custom_optind - 1]);
809 d->nextchar += strlen(d->nextchar);
810 d->custom_optopt = pfound->val;
811 return optstring[0] == ':' ? ':' : '?';
814 d->nextchar += strlen(d->nextchar);
816 *longind = option_index;
818 *(pfound->flag) = pfound->val;
824 * Can't find it as a long option. If this is not getopt_long_only, or
825 * the option starts with '--' or is not a valid short option, then
826 * it's an error. Otherwise interpret it as a short option.
829 if (argv[d->custom_optind][1] == '-') {
832 "%s: unrecognized option `--%s'\n",
833 argv[0], d->nextchar);
835 /* +option or -option */
837 "%s: unrecognized option `%c%s'\n",
838 argv[0], argv[d->custom_optind][0],
842 d->nextchar = (char *) "";
844 d->custom_optopt = 0;
848 static int check_short_opt(int argc, char *const *argv, const char *optstring,
849 int print_errors, struct custom_getopt_data *d)
851 char c = *d->nextchar++;
852 const char *temp = strchr(optstring, c);
854 /* Increment `custom_optind' when we start to process its last character. */
855 if (*d->nextchar == '\0')
857 if (!temp || c == ':') {
859 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
861 d->custom_optopt = c;
864 if (temp[1] == ':') {
865 if (temp[2] == ':') {
866 /* This is an option that accepts an argument optionally. */
867 if (*d->nextchar != '\0') {
868 d->custom_optarg = d->nextchar;
871 d->custom_optarg = NULL;
874 /* This is an option that requires an argument. */
875 if (*d->nextchar != '\0') {
876 d->custom_optarg = d->nextchar;
878 * If we end this ARGV-element by taking the
879 * rest as an arg, we must advance to the next
883 } else if (d->custom_optind == argc) {
886 "%s: option requires an argument -- %c\n",
889 d->custom_optopt = c;
890 if (optstring[0] == ':')
896 * We already incremented `custom_optind' once;
897 * increment it again when taking next ARGV-elt
900 d->custom_optarg = argv[d->custom_optind++];
908 * Scan elements of ARGV for option characters given in OPTSTRING.
910 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
911 * then it is an option element. The characters of this element
912 * (aside from the initial '-') are option characters. If `getopt'
913 * is called repeatedly, it returns successively each of the option characters
914 * from each of the option elements.
916 * If `getopt' finds another option character, it returns that character,
917 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
918 * resume the scan with the following option character or ARGV-element.
920 * If there are no more option characters, `getopt' returns -1.
921 * Then `custom_optind' is the index in ARGV of the first ARGV-element
922 * that is not an option. (The ARGV-elements have been permuted
923 * so that those that are not options now come last.)
925 * OPTSTRING is a string containing the legitimate option characters.
926 * If an option character is seen that is not listed in OPTSTRING,
927 * return '?' after printing an error message. If you set `custom_opterr' to
928 * zero, the error message is suppressed but we still return '?'.
930 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
931 * so the following text in the same ARGV-element, or the text of the following
932 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
933 * wants an optional arg; if there is text in the current ARGV-element,
934 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
936 * If OPTSTRING starts with `-' or `+', it requests different methods of
937 * handling the non-option ARGV-elements.
938 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
940 * Long-named options begin with `--' instead of `-'.
941 * Their names may be abbreviated as long as the abbreviation is unique
942 * or is an exact match for some defined option. If they have an
943 * argument, it follows the option name in the same ARGV-element, separated
944 * from the option name by a `=', or else the in next ARGV-element.
945 * When `getopt' finds a long-named option, it returns 0 if that option's
946 * `flag' field is nonzero, the value of the option's `val' field
947 * if the `flag' field is zero.
949 * The elements of ARGV aren't really const, because we permute them.
950 * But we pretend they're const in the prototype to be compatible
951 * with other systems.
953 * LONGOPTS is a vector of `struct option' terminated by an
954 * element containing a name which is zero.
956 * LONGIND returns the index in LONGOPT of the long-named option found.
957 * It is only valid when a long-named option has been found by the most
960 * Return the option character from OPTS just read. Return -1 when there are
961 * no more options. For unrecognized options, or options missing arguments,
962 * `custom_optopt' is set to the option letter, and '?' is returned.
964 * The OPTS string is a list of characters which are recognized option letters,
965 * optionally followed by colons, specifying that that letter takes an
966 * argument, to be placed in `custom_optarg'.
968 * If a letter in OPTS is followed by two colons, its argument is optional.
969 * This behavior is specific to the GNU `getopt'.
971 * The argument `--' causes premature termination of argument scanning,
972 * explicitly telling `getopt' that there are no more options. If OPTS begins
973 * with `--', then non-option arguments are treated as arguments to the option
974 * '\0'. This behavior is specific to the GNU `getopt'.
977 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
978 const struct option *longopts, int *longind,
979 struct custom_getopt_data *d)
981 int ret, print_errors = d->custom_opterr;
983 if (optstring[0] == ':')
987 d->custom_optarg = NULL;
990 * This is a big difference with GNU getopt, since optind == 0
991 * means initialization while here 1 means first call.
993 if (d->custom_optind == 0 || !d->initialized) {
994 if (d->custom_optind == 0)
995 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
996 custom_getopt_initialize(d);
998 if (d->nextchar == NULL || *d->nextchar == '\0') {
999 ret = shuffle_argv(argc, argv, longopts, d);
1003 if (longopts && (argv[d->custom_optind][1] == '-' ))
1004 return check_long_opt(argc, argv, optstring, longopts,
1005 longind, print_errors, d);
1006 return check_short_opt(argc, argv, optstring, print_errors, d);
1009 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1010 const struct option *longopts, int *longind)
1013 /* Keep a global copy of all internal members of d */
1014 static struct custom_getopt_data d;
1016 d.custom_optind = custom_optind;
1017 d.custom_opterr = custom_opterr;
1018 result = getopt_internal_r(argc, argv, optstring, longopts,
1020 custom_optind = d.custom_optind;
1021 custom_optarg = d.custom_optarg;
1022 custom_optopt = d.custom_optopt;
1026 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1027 const struct option *long_options, int *opt_index)
1029 return custom_getopt_internal(argc, argv, options, long_options,
1034 static char *package_name = 0;
1037 * @brief updates an option
1038 * @param field the generic pointer to the field to update
1039 * @param orig_field the pointer to the orig field
1040 * @param field_given the pointer to the number of occurrence of this option
1041 * @param prev_given the pointer to the number of occurrence already seen
1042 * @param value the argument for this option (if null no arg was specified)
1043 * @param possible_values the possible values for this option (if specified)
1044 * @param default_value the default value (in case the option only accepts fixed values)
1045 * @param arg_type the type of this option
1046 * @param check_ambiguity @see RNAparconv_cmdline_parser_params.check_ambiguity
1047 * @param override @see RNAparconv_cmdline_parser_params.override
1048 * @param no_free whether to free a possible previous value
1049 * @param multiple_option whether this is a multiple option
1050 * @param long_opt the corresponding long option
1051 * @param short_opt the corresponding short option (or '-' if none)
1052 * @param additional_error possible further error specification
1055 int update_arg(void *field, char **orig_field,
1056 unsigned int *field_given, unsigned int *prev_given,
1057 char *value, const char *possible_values[],
1058 const char *default_value,
1059 RNAparconv_cmdline_parser_arg_type arg_type,
1060 int check_ambiguity, int override,
1061 int no_free, int multiple_option,
1062 const char *long_opt, char short_opt,
1063 const char *additional_error)
1065 char *stop_char = 0;
1066 const char *val = value;
1068 char **string_field;
1074 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1076 if (short_opt != '-')
1077 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1078 package_name, long_opt, short_opt,
1079 (additional_error ? additional_error : ""));
1081 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1082 package_name, long_opt,
1083 (additional_error ? additional_error : ""));
1084 return 1; /* failure */
1087 FIX_UNUSED (default_value);
1089 if (field_given && *field_given && ! override)
1095 if (possible_values)
1096 val = possible_values[found];
1100 *((int *)field) = !*((int *)field);
1104 string_field = (char **)field;
1105 if (!no_free && *string_field)
1106 free (*string_field); /* free previous string */
1107 *string_field = gengetopt_strdup (val);
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 RNAparconv_cmdline_parser_internal (
1138 int argc, char **argv, struct RNAparconv_args_info *args_info,
1139 struct RNAparconv_cmdline_parser_params *params, const char *additional_error)
1141 int c; /* Character of the parsed option. */
1144 struct RNAparconv_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 RNAparconv_cmdline_parser_init (args_info);
1166 RNAparconv_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 { "full-help", 0, NULL, 0 },
1180 { "version", 0, NULL, 'V' },
1181 { "output", 1, NULL, 'o' },
1182 { "input", 1, NULL, 'i' },
1183 { "vanilla", 0, NULL, 0 },
1184 { "dump", 0, NULL, 0 },
1185 { "silent", 0, NULL, 0 },
1186 { "without-HairpinE", 0, NULL, 0 },
1187 { "without-StackE", 0, NULL, 0 },
1188 { "without-IntE", 0, NULL, 0 },
1189 { "without-BulgeE", 0, NULL, 0 },
1190 { "without-MultiE", 0, NULL, 0 },
1191 { "without-MismatchE", 0, NULL, 0 },
1192 { "without-MismatchH", 0, NULL, 0 },
1193 { "without-MismatchI", 0, NULL, 0 },
1194 { "without-MismatchM", 0, NULL, 0 },
1195 { "without-Dangle5", 0, NULL, 0 },
1196 { "without-Dangle3", 0, NULL, 0 },
1197 { "without-Misc", 0, NULL, 0 },
1201 custom_optarg = optarg;
1202 custom_optind = optind;
1203 custom_opterr = opterr;
1204 custom_optopt = optopt;
1206 c = custom_getopt_long (argc, argv, "hVo:i:", long_options, &option_index);
1208 optarg = custom_optarg;
1209 optind = custom_optind;
1210 opterr = custom_opterr;
1211 optopt = custom_optopt;
1213 if (c == -1) break; /* Exit from `while (1)' loop. */
1217 case 'h': /* Print help and exit. */
1218 RNAparconv_cmdline_parser_print_help ();
1219 RNAparconv_cmdline_parser_free (&local_args_info);
1220 exit (EXIT_SUCCESS);
1222 case 'V': /* Print version and exit. */
1223 RNAparconv_cmdline_parser_print_version ();
1224 RNAparconv_cmdline_parser_free (&local_args_info);
1225 exit (EXIT_SUCCESS);
1227 case 'o': /* Specify an output file name. If argument is missing the converted energy parameters are printed to 'stdout'.
1232 if (update_arg( (void *)&(args_info->output_arg),
1233 &(args_info->output_orig), &(args_info->output_given),
1234 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1235 check_ambiguity, override, 0, 0,
1241 case 'i': /* Specify an input file name. If argument is missing the energy parameter input can be supplied via 'stdin'.
1246 if (update_arg( (void *)&(args_info->input_arg),
1247 &(args_info->input_orig), &(args_info->input_given),
1248 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1249 check_ambiguity, override, 0, 0,
1256 case 0: /* Long option with no short option */
1257 if (strcmp (long_options[option_index].name, "full-help") == 0) {
1258 RNAparconv_cmdline_parser_print_full_help ();
1259 RNAparconv_cmdline_parser_free (&local_args_info);
1260 exit (EXIT_SUCCESS);
1263 /* Print just as much as needed to represent the given energy parameters data set.
1264 This option overrides all other output settings!
1267 if (strcmp (long_options[option_index].name, "vanilla") == 0)
1271 if (update_arg((void *)&(args_info->vanilla_flag), 0, &(args_info->vanilla_given),
1272 &(local_args_info.vanilla_given), optarg, 0, 0, ARG_FLAG,
1273 check_ambiguity, override, 1, 0, "vanilla", '-',
1278 /* Just dump Vienna 1.8.4 energy parameters in format used since 2.0.
1279 This option skips any energy parameter input!
1282 else if (strcmp (long_options[option_index].name, "dump") == 0)
1286 if (update_arg((void *)&(args_info->dump_flag), 0, &(args_info->dump_given),
1287 &(local_args_info.dump_given), optarg, 0, 0, ARG_FLAG,
1288 check_ambiguity, override, 1, 0, "dump", '-',
1293 /* Print just energy parameters and appropriate comment lines but suppress all other output
1296 else if (strcmp (long_options[option_index].name, "silent") == 0)
1300 if (update_arg((void *)&(args_info->silent_flag), 0, &(args_info->silent_given),
1301 &(local_args_info.silent_given), optarg, 0, 0, ARG_FLAG,
1302 check_ambiguity, override, 1, 0, "silent", '-',
1307 /* Do not print converted hairpin energies and enthalpies
1310 else if (strcmp (long_options[option_index].name, "without-HairpinE") == 0)
1314 if (update_arg((void *)&(args_info->without_HairpinE_flag), 0, &(args_info->without_HairpinE_given),
1315 &(local_args_info.without_HairpinE_given), optarg, 0, 0, ARG_FLAG,
1316 check_ambiguity, override, 1, 0, "without-HairpinE", '-',
1321 /* Do not print converted stacking energies and enthalpies
1324 else if (strcmp (long_options[option_index].name, "without-StackE") == 0)
1328 if (update_arg((void *)&(args_info->without_StackE_flag), 0, &(args_info->without_StackE_given),
1329 &(local_args_info.without_StackE_given), optarg, 0, 0, ARG_FLAG,
1330 check_ambiguity, override, 1, 0, "without-StackE", '-',
1335 /* Do not print converted interior loop energies, enthalpies and asymetry factors
1338 else if (strcmp (long_options[option_index].name, "without-IntE") == 0)
1342 if (update_arg((void *)&(args_info->without_IntE_flag), 0, &(args_info->without_IntE_given),
1343 &(local_args_info.without_IntE_given), optarg, 0, 0, ARG_FLAG,
1344 check_ambiguity, override, 1, 0, "without-IntE", '-',
1349 /* Do not print converted bulge loop energies and enthalpies
1352 else if (strcmp (long_options[option_index].name, "without-BulgeE") == 0)
1356 if (update_arg((void *)&(args_info->without_BulgeE_flag), 0, &(args_info->without_BulgeE_given),
1357 &(local_args_info.without_BulgeE_given), optarg, 0, 0, ARG_FLAG,
1358 check_ambiguity, override, 1, 0, "without-BulgeE", '-',
1363 /* Do not print converted multi loop energies and enthalpies
1366 else if (strcmp (long_options[option_index].name, "without-MultiE") == 0)
1370 if (update_arg((void *)&(args_info->without_MultiE_flag), 0, &(args_info->without_MultiE_given),
1371 &(local_args_info.without_MultiE_given), optarg, 0, 0, ARG_FLAG,
1372 check_ambiguity, override, 1, 0, "without-MultiE", '-',
1377 /* Do not print converted exterior loop mismatch energies and enthalpies
1380 else if (strcmp (long_options[option_index].name, "without-MismatchE") == 0)
1384 if (update_arg((void *)&(args_info->without_MismatchE_flag), 0, &(args_info->without_MismatchE_given),
1385 &(local_args_info.without_MismatchE_given), optarg, 0, 0, ARG_FLAG,
1386 check_ambiguity, override, 1, 0, "without-MismatchE", '-',
1391 /* Do not print converted hairpin mismatch energies and enthalpies
1394 else if (strcmp (long_options[option_index].name, "without-MismatchH") == 0)
1398 if (update_arg((void *)&(args_info->without_MismatchH_flag), 0, &(args_info->without_MismatchH_given),
1399 &(local_args_info.without_MismatchH_given), optarg, 0, 0, ARG_FLAG,
1400 check_ambiguity, override, 1, 0, "without-MismatchH", '-',
1405 /* Do not print converted interior loop mismatch energies and enthalpies
1408 else if (strcmp (long_options[option_index].name, "without-MismatchI") == 0)
1412 if (update_arg((void *)&(args_info->without_MismatchI_flag), 0, &(args_info->without_MismatchI_given),
1413 &(local_args_info.without_MismatchI_given), optarg, 0, 0, ARG_FLAG,
1414 check_ambiguity, override, 1, 0, "without-MismatchI", '-',
1419 /* Do not print converted multi loop mismatch energies and enthalpies
1422 else if (strcmp (long_options[option_index].name, "without-MismatchM") == 0)
1426 if (update_arg((void *)&(args_info->without_MismatchM_flag), 0, &(args_info->without_MismatchM_given),
1427 &(local_args_info.without_MismatchM_given), optarg, 0, 0, ARG_FLAG,
1428 check_ambiguity, override, 1, 0, "without-MismatchM", '-',
1433 /* Do not print converted 5' dangle energies and enthalpies
1436 else if (strcmp (long_options[option_index].name, "without-Dangle5") == 0)
1440 if (update_arg((void *)&(args_info->without_Dangle5_flag), 0, &(args_info->without_Dangle5_given),
1441 &(local_args_info.without_Dangle5_given), optarg, 0, 0, ARG_FLAG,
1442 check_ambiguity, override, 1, 0, "without-Dangle5", '-',
1447 /* Do not print converted 3' dangle energies and enthalpies
1450 else if (strcmp (long_options[option_index].name, "without-Dangle3") == 0)
1454 if (update_arg((void *)&(args_info->without_Dangle3_flag), 0, &(args_info->without_Dangle3_given),
1455 &(local_args_info.without_Dangle3_given), optarg, 0, 0, ARG_FLAG,
1456 check_ambiguity, override, 1, 0, "without-Dangle3", '-',
1461 /* Do not print converted Misc energies and enthalpies (TerminalAU, DuplexInit, lxc)
1464 else if (strcmp (long_options[option_index].name, "without-Misc") == 0)
1468 if (update_arg((void *)&(args_info->without_Misc_flag), 0, &(args_info->without_Misc_given),
1469 &(local_args_info.without_Misc_given), optarg, 0, 0, ARG_FLAG,
1470 check_ambiguity, override, 1, 0, "without-Misc", '-',
1477 case '?': /* Invalid option. */
1478 /* `getopt_long' already printed an error message. */
1481 default: /* bug: option not considered. */
1482 fprintf (stderr, "%s: option unknown: %c%s\n", RNAPARCONV_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1490 RNAparconv_cmdline_parser_release (&local_args_info);
1493 return (EXIT_FAILURE);
1498 int found_prog_name = 0;
1499 /* whether program name, i.e., argv[0], is in the remaining args
1500 (this may happen with some implementations of getopt,
1501 but surely not with the one included by gengetopt) */
1504 args_info->inputs_num = argc - optind - found_prog_name;
1506 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1507 while (optind < argc)
1508 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1515 RNAparconv_cmdline_parser_release (&local_args_info);
1516 return (EXIT_FAILURE);