2 File autogenerated by gengetopt version 2.22.5
3 generated with the following command:
4 gengetopt -i RNAup.ggo --file-name=RNAup_cmdl --include-getopt --default-optional --func-name=RNAup_cmdline_parser --arg-struct-name=RNAup_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 "RNAup_cmdl.h"
27 const char *RNAup_args_info_purpose = "Calculate the thermodynamics of RNA-RNA interactions";
29 const char *RNAup_args_info_usage = "Usage: RNAup [OPTIONS]...";
31 const char *RNAup_args_info_description = "RNAup calculates the thermodynamics of RNA-RNA interactions, by decomposing the \nbinding into two stages. (1) First the probability that a potential binding \nsites remains unpaired (equivalent to the free energy needed to open the site) \nis computed. (2) Then this accessibility is combined with the interaction \nenergy to obtain the total binding energy. All calculations are done by \ncomputing partition functions over all possible conformations.\n";
33 const char *RNAup_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 " -C, --constraint Calculate structures subject to constraints.\n (default=off)",
41 " The program reads first the sequence(s), then a string containing constraints \n on the structure encoded with the symbols:\n . (no constraint for this base)\n\n x (the base is unpaired)\n < (base i is paired with a base j>i) (solely used for calculation of \n unpaired regions)\n > (base i is paired with a base j<i) (solely used for calculation of \n unpaired regions)\n ( ) (base i pairs base j)\n | (the corresponding base has to be paired intermolecularily (works only in \n interaction mode)\n\n",
42 " -o, --no_output_file Do not produce an output file\n\n (default=off)",
43 " --no_header Do not produce a header with the command line \n parameters used in the outputfile\n\n (default=off)",
44 " --noconv Do not automatically substitude nucleotide \"T\" \n with \"U\"\n\n (default=off)",
45 "\nCalculations of opening energies:",
46 " -u, --ulength=length specifies the length of the unstructured region \n in the output.\n (default=`4')",
47 " The probability of being unpaired is plotted on the right border of the \n unpaired region. You can specify up to 20 different length values: use \"-\" \n to specify a range of continuous values (e.g. -u 4-8) or specify a list of \n comma separated values (e.g. -u 4,8,15).\n\n",
48 " -c, --contributions=SHIME Specify the contributions listed in the output\n (default=`S')",
49 " By default only the full probability of being unpaired is plotted. The -c \n option allows to get the different contributions (c) to the probability of \n being unpaired: The full probability of being unpaired (\"S\" is the sum of \n the probability of being unpaired in the exterior loop (\"E\"), within a \n hairpin loop (\"H\"), within an interior loop (\"I\") and within a multiloop \n (\"M\"). Any combination of these letters may be given.\n\n",
50 "\nCalculations of RNA-RNA interactions:",
51 " -w, --window=INT Determine the maximal length of the region of \n interaction\n\n (default=`25')",
52 " -b, --include_both Include the probability of unpaired regions in \n both (b) RNAs. By default\n only the probability of being unpaired in the \n longer RNA (target) is used.\n\n (default=off)",
53 " -5, --extend5=INT Extend the region of interaction in the target to \n some residues on the 5' side\n",
54 " The underlying assumption is that it is favorable for an interaction if not \n only the direct region of contact is unpaired but also a few residues 5'\n\n",
55 " -3, --extend3=INT Extend the region of interaction in the target to \n some residues on the 3' side\n",
56 " The underlying assumption is that it is favorable for an interaction if not \n only the direct region of contact is unpaired but also a few residues 3'\n\n",
57 " --interaction_pairwise Activate pairwise interaction mode\n (default=off)",
58 " The first sequence interacts with the 2nd, the third with the 4th etc. If \n activated, two interacting sequences may be given in a single line separated \n by \"&\" or each sequence may be given on an extra line.\n\n",
59 " --interaction_first Activate interaction mode using first sequence \n only\n (default=off)",
60 " The interaction of each sequence with the first one is calculated (e.g. \n interaction of one mRNA with many small RNAs). Each sequence has to be given \n on an extra line\n\n",
62 " -S, --pfScale=DOUBLE In the calculation of the pf use scale*mfe as an \n estimate for the ensemble free energy (used to \n avoid overflows). The default is 1.07, useful \n values are 1.0 to 1.2. Occasionally needed for \n long sequences.\n You can also recompile the program to use \n double precision (see the README file).\n\n",
63 " -T, --temp=DOUBLE Rescale energy parameters to a temperature of \n temp C. Default is 37C.\n\n",
64 " -4, --noTetra Do not include special tabulated stabilizing \n energies for tri-, tetra- and hexaloop \n hairpins. Mostly for testing.\n\n (default=off)",
65 " -d, --dangles=INT How to treat \"dangling end\" energies for bases \n adjacent to helices in free ends and \n multi-loops\n (default=`2')",
66 " \n With -d2 dangling energies will be added for the bases adjacent to a helix on \n both sides in any case.\n The option -d0 ignores dangling ends altogether (mostly for debugging).\n\n",
67 " --noLP Produce structures without lonely pairs (helices \n of length 1).\n (default=off)",
68 " 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",
69 " --noGU Do not allow GU pairs\n\n (default=off)",
70 " --noClosingGU Do not allow GU pairs at the end of helices\n\n (default=off)",
71 " -P, --paramFile=paramfile Read energy parameters from paramfile, instead of \n using the default parameter set.\n",
72 " A sample parameter file should accompany your distribution.\n See the RNAlib documentation for details on the file format.\n\n",
73 " --nsp=STRING Allow other pairs in addition to the usual \n AU,GC,and GU pairs.\n",
74 " 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",
75 " -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",
76 "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
80 init_full_help_array(void)
82 RNAup_args_info_full_help[0] = RNAup_args_info_detailed_help[0];
83 RNAup_args_info_full_help[1] = RNAup_args_info_detailed_help[1];
84 RNAup_args_info_full_help[2] = RNAup_args_info_detailed_help[2];
85 RNAup_args_info_full_help[3] = RNAup_args_info_detailed_help[3];
86 RNAup_args_info_full_help[4] = RNAup_args_info_detailed_help[4];
87 RNAup_args_info_full_help[5] = RNAup_args_info_detailed_help[5];
88 RNAup_args_info_full_help[6] = RNAup_args_info_detailed_help[6];
89 RNAup_args_info_full_help[7] = RNAup_args_info_detailed_help[8];
90 RNAup_args_info_full_help[8] = RNAup_args_info_detailed_help[9];
91 RNAup_args_info_full_help[9] = RNAup_args_info_detailed_help[10];
92 RNAup_args_info_full_help[10] = RNAup_args_info_detailed_help[11];
93 RNAup_args_info_full_help[11] = RNAup_args_info_detailed_help[12];
94 RNAup_args_info_full_help[12] = RNAup_args_info_detailed_help[14];
95 RNAup_args_info_full_help[13] = RNAup_args_info_detailed_help[16];
96 RNAup_args_info_full_help[14] = RNAup_args_info_detailed_help[17];
97 RNAup_args_info_full_help[15] = RNAup_args_info_detailed_help[18];
98 RNAup_args_info_full_help[16] = RNAup_args_info_detailed_help[19];
99 RNAup_args_info_full_help[17] = RNAup_args_info_detailed_help[21];
100 RNAup_args_info_full_help[18] = RNAup_args_info_detailed_help[23];
101 RNAup_args_info_full_help[19] = RNAup_args_info_detailed_help[25];
102 RNAup_args_info_full_help[20] = RNAup_args_info_detailed_help[27];
103 RNAup_args_info_full_help[21] = RNAup_args_info_detailed_help[28];
104 RNAup_args_info_full_help[22] = RNAup_args_info_detailed_help[29];
105 RNAup_args_info_full_help[23] = RNAup_args_info_detailed_help[30];
106 RNAup_args_info_full_help[24] = RNAup_args_info_detailed_help[31];
107 RNAup_args_info_full_help[25] = RNAup_args_info_detailed_help[33];
108 RNAup_args_info_full_help[26] = RNAup_args_info_detailed_help[35];
109 RNAup_args_info_full_help[27] = RNAup_args_info_detailed_help[36];
110 RNAup_args_info_full_help[28] = RNAup_args_info_detailed_help[37];
111 RNAup_args_info_full_help[29] = RNAup_args_info_detailed_help[39];
112 RNAup_args_info_full_help[30] = RNAup_args_info_detailed_help[41];
113 RNAup_args_info_full_help[31] = RNAup_args_info_detailed_help[42];
114 RNAup_args_info_full_help[32] = 0;
118 const char *RNAup_args_info_full_help[33];
121 init_help_array(void)
123 RNAup_args_info_help[0] = RNAup_args_info_detailed_help[0];
124 RNAup_args_info_help[1] = RNAup_args_info_detailed_help[1];
125 RNAup_args_info_help[2] = RNAup_args_info_detailed_help[2];
126 RNAup_args_info_help[3] = RNAup_args_info_detailed_help[3];
127 RNAup_args_info_help[4] = RNAup_args_info_detailed_help[4];
128 RNAup_args_info_help[5] = RNAup_args_info_detailed_help[5];
129 RNAup_args_info_help[6] = RNAup_args_info_detailed_help[6];
130 RNAup_args_info_help[7] = RNAup_args_info_detailed_help[8];
131 RNAup_args_info_help[8] = RNAup_args_info_detailed_help[9];
132 RNAup_args_info_help[9] = RNAup_args_info_detailed_help[10];
133 RNAup_args_info_help[10] = RNAup_args_info_detailed_help[11];
134 RNAup_args_info_help[11] = RNAup_args_info_detailed_help[12];
135 RNAup_args_info_help[12] = RNAup_args_info_detailed_help[14];
136 RNAup_args_info_help[13] = RNAup_args_info_detailed_help[16];
137 RNAup_args_info_help[14] = RNAup_args_info_detailed_help[17];
138 RNAup_args_info_help[15] = RNAup_args_info_detailed_help[18];
139 RNAup_args_info_help[16] = RNAup_args_info_detailed_help[19];
140 RNAup_args_info_help[17] = RNAup_args_info_detailed_help[21];
141 RNAup_args_info_help[18] = RNAup_args_info_detailed_help[23];
142 RNAup_args_info_help[19] = RNAup_args_info_detailed_help[25];
143 RNAup_args_info_help[20] = RNAup_args_info_detailed_help[27];
144 RNAup_args_info_help[21] = RNAup_args_info_detailed_help[29];
145 RNAup_args_info_help[22] = RNAup_args_info_detailed_help[30];
146 RNAup_args_info_help[23] = RNAup_args_info_detailed_help[31];
147 RNAup_args_info_help[24] = RNAup_args_info_detailed_help[33];
148 RNAup_args_info_help[25] = RNAup_args_info_detailed_help[35];
149 RNAup_args_info_help[26] = RNAup_args_info_detailed_help[36];
150 RNAup_args_info_help[27] = RNAup_args_info_detailed_help[37];
151 RNAup_args_info_help[28] = RNAup_args_info_detailed_help[42];
152 RNAup_args_info_help[29] = 0;
156 const char *RNAup_args_info_help[30];
163 } RNAup_cmdline_parser_arg_type;
166 void clear_given (struct RNAup_args_info *args_info);
168 void clear_args (struct RNAup_args_info *args_info);
171 RNAup_cmdline_parser_internal (int argc, char **argv, struct RNAup_args_info *args_info,
172 struct RNAup_cmdline_parser_params *params, const char *additional_error);
175 RNAup_cmdline_parser_required2 (struct RNAup_args_info *args_info, const char *prog_name, const char *additional_error);
178 gengetopt_strdup (const char *s);
181 void clear_given (struct RNAup_args_info *args_info)
183 args_info->help_given = 0 ;
184 args_info->detailed_help_given = 0 ;
185 args_info->full_help_given = 0 ;
186 args_info->version_given = 0 ;
187 args_info->constraint_given = 0 ;
188 args_info->no_output_file_given = 0 ;
189 args_info->no_header_given = 0 ;
190 args_info->noconv_given = 0 ;
191 args_info->ulength_given = 0 ;
192 args_info->contributions_given = 0 ;
193 args_info->window_given = 0 ;
194 args_info->include_both_given = 0 ;
195 args_info->extend5_given = 0 ;
196 args_info->extend3_given = 0 ;
197 args_info->interaction_pairwise_given = 0 ;
198 args_info->interaction_first_given = 0 ;
199 args_info->pfScale_given = 0 ;
200 args_info->temp_given = 0 ;
201 args_info->noTetra_given = 0 ;
202 args_info->dangles_given = 0 ;
203 args_info->noLP_given = 0 ;
204 args_info->noGU_given = 0 ;
205 args_info->noClosingGU_given = 0 ;
206 args_info->paramFile_given = 0 ;
207 args_info->nsp_given = 0 ;
208 args_info->energyModel_given = 0 ;
212 void clear_args (struct RNAup_args_info *args_info)
214 FIX_UNUSED (args_info);
215 args_info->constraint_flag = 0;
216 args_info->no_output_file_flag = 0;
217 args_info->no_header_flag = 0;
218 args_info->noconv_flag = 0;
219 args_info->ulength_arg = NULL;
220 args_info->ulength_orig = NULL;
221 args_info->contributions_arg = gengetopt_strdup ("S");
222 args_info->contributions_orig = NULL;
223 args_info->window_arg = 25;
224 args_info->window_orig = NULL;
225 args_info->include_both_flag = 0;
226 args_info->extend5_orig = NULL;
227 args_info->extend3_orig = NULL;
228 args_info->interaction_pairwise_flag = 0;
229 args_info->interaction_first_flag = 0;
230 args_info->pfScale_orig = NULL;
231 args_info->temp_orig = NULL;
232 args_info->noTetra_flag = 0;
233 args_info->dangles_arg = 2;
234 args_info->dangles_orig = NULL;
235 args_info->noLP_flag = 0;
236 args_info->noGU_flag = 0;
237 args_info->noClosingGU_flag = 0;
238 args_info->paramFile_arg = NULL;
239 args_info->paramFile_orig = NULL;
240 args_info->nsp_arg = NULL;
241 args_info->nsp_orig = NULL;
242 args_info->energyModel_orig = NULL;
247 void init_args_info(struct RNAup_args_info *args_info)
249 init_full_help_array();
251 args_info->help_help = RNAup_args_info_detailed_help[0] ;
252 args_info->detailed_help_help = RNAup_args_info_detailed_help[1] ;
253 args_info->full_help_help = RNAup_args_info_detailed_help[2] ;
254 args_info->version_help = RNAup_args_info_detailed_help[3] ;
255 args_info->constraint_help = RNAup_args_info_detailed_help[6] ;
256 args_info->no_output_file_help = RNAup_args_info_detailed_help[8] ;
257 args_info->no_header_help = RNAup_args_info_detailed_help[9] ;
258 args_info->noconv_help = RNAup_args_info_detailed_help[10] ;
259 args_info->ulength_help = RNAup_args_info_detailed_help[12] ;
260 args_info->ulength_min = 0;
261 args_info->ulength_max = 0;
262 args_info->contributions_help = RNAup_args_info_detailed_help[14] ;
263 args_info->window_help = RNAup_args_info_detailed_help[17] ;
264 args_info->include_both_help = RNAup_args_info_detailed_help[18] ;
265 args_info->extend5_help = RNAup_args_info_detailed_help[19] ;
266 args_info->extend3_help = RNAup_args_info_detailed_help[21] ;
267 args_info->interaction_pairwise_help = RNAup_args_info_detailed_help[23] ;
268 args_info->interaction_first_help = RNAup_args_info_detailed_help[25] ;
269 args_info->pfScale_help = RNAup_args_info_detailed_help[28] ;
270 args_info->temp_help = RNAup_args_info_detailed_help[29] ;
271 args_info->noTetra_help = RNAup_args_info_detailed_help[30] ;
272 args_info->dangles_help = RNAup_args_info_detailed_help[31] ;
273 args_info->noLP_help = RNAup_args_info_detailed_help[33] ;
274 args_info->noGU_help = RNAup_args_info_detailed_help[35] ;
275 args_info->noClosingGU_help = RNAup_args_info_detailed_help[36] ;
276 args_info->paramFile_help = RNAup_args_info_detailed_help[37] ;
277 args_info->nsp_help = RNAup_args_info_detailed_help[39] ;
278 args_info->energyModel_help = RNAup_args_info_detailed_help[41] ;
283 RNAup_cmdline_parser_print_version (void)
286 (strlen(RNAUP_CMDLINE_PARSER_PACKAGE_NAME) ? RNAUP_CMDLINE_PARSER_PACKAGE_NAME : RNAUP_CMDLINE_PARSER_PACKAGE),
287 RNAUP_CMDLINE_PARSER_VERSION);
290 static void print_help_common(void) {
291 RNAup_cmdline_parser_print_version ();
293 if (strlen(RNAup_args_info_purpose) > 0)
294 printf("\n%s\n", RNAup_args_info_purpose);
296 if (strlen(RNAup_args_info_usage) > 0)
297 printf("\n%s\n", RNAup_args_info_usage);
301 if (strlen(RNAup_args_info_description) > 0)
302 printf("%s\n\n", RNAup_args_info_description);
306 RNAup_cmdline_parser_print_help (void)
310 while (RNAup_args_info_help[i])
311 printf("%s\n", RNAup_args_info_help[i++]);
315 RNAup_cmdline_parser_print_full_help (void)
319 while (RNAup_args_info_full_help[i])
320 printf("%s\n", RNAup_args_info_full_help[i++]);
324 RNAup_cmdline_parser_print_detailed_help (void)
328 while (RNAup_args_info_detailed_help[i])
329 printf("%s\n", RNAup_args_info_detailed_help[i++]);
333 RNAup_cmdline_parser_init (struct RNAup_args_info *args_info)
335 clear_given (args_info);
336 clear_args (args_info);
337 init_args_info (args_info);
341 RNAup_cmdline_parser_params_init(struct RNAup_cmdline_parser_params *params)
345 params->override = 0;
346 params->initialize = 1;
347 params->check_required = 1;
348 params->check_ambiguity = 0;
349 params->print_errors = 1;
353 struct RNAup_cmdline_parser_params *
354 RNAup_cmdline_parser_params_create(void)
356 struct RNAup_cmdline_parser_params *params =
357 (struct RNAup_cmdline_parser_params *)malloc(sizeof(struct RNAup_cmdline_parser_params));
358 RNAup_cmdline_parser_params_init(params);
363 free_string_field (char **s)
372 /** @brief generic value variable */
373 union generic_value {
377 const char *default_string_arg;
380 /** @brief holds temporary values for multiple options */
383 union generic_value arg;
385 struct generic_list *next;
389 * @brief add a node at the head of the list
391 static void add_node(struct generic_list **list) {
392 struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list));
393 new_node->next = *list;
395 new_node->arg.string_arg = 0;
401 free_multiple_string_field(unsigned int len, char ***arg, char ***orig)
405 for (i = 0; i < len; ++i)
407 free_string_field(&((*arg)[i]));
408 free_string_field(&((*orig)[i]));
410 free_string_field(&((*arg)[0])); /* free default string */
420 RNAup_cmdline_parser_release (struct RNAup_args_info *args_info)
423 free_multiple_string_field (args_info->ulength_given, &(args_info->ulength_arg), &(args_info->ulength_orig));
424 free_string_field (&(args_info->contributions_arg));
425 free_string_field (&(args_info->contributions_orig));
426 free_string_field (&(args_info->window_orig));
427 free_string_field (&(args_info->extend5_orig));
428 free_string_field (&(args_info->extend3_orig));
429 free_string_field (&(args_info->pfScale_orig));
430 free_string_field (&(args_info->temp_orig));
431 free_string_field (&(args_info->dangles_orig));
432 free_string_field (&(args_info->paramFile_arg));
433 free_string_field (&(args_info->paramFile_orig));
434 free_string_field (&(args_info->nsp_arg));
435 free_string_field (&(args_info->nsp_orig));
436 free_string_field (&(args_info->energyModel_orig));
440 clear_given (args_info);
445 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
449 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
451 fprintf(outfile, "%s\n", opt);
456 write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[])
460 for (i = 0; i < len; ++i)
461 write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
465 RNAup_cmdline_parser_dump(FILE *outfile, struct RNAup_args_info *args_info)
471 fprintf (stderr, "%s: cannot dump options to stream\n", RNAUP_CMDLINE_PARSER_PACKAGE);
475 if (args_info->help_given)
476 write_into_file(outfile, "help", 0, 0 );
477 if (args_info->detailed_help_given)
478 write_into_file(outfile, "detailed-help", 0, 0 );
479 if (args_info->full_help_given)
480 write_into_file(outfile, "full-help", 0, 0 );
481 if (args_info->version_given)
482 write_into_file(outfile, "version", 0, 0 );
483 if (args_info->constraint_given)
484 write_into_file(outfile, "constraint", 0, 0 );
485 if (args_info->no_output_file_given)
486 write_into_file(outfile, "no_output_file", 0, 0 );
487 if (args_info->no_header_given)
488 write_into_file(outfile, "no_header", 0, 0 );
489 if (args_info->noconv_given)
490 write_into_file(outfile, "noconv", 0, 0 );
491 write_multiple_into_file(outfile, args_info->ulength_given, "ulength", args_info->ulength_orig, 0);
492 if (args_info->contributions_given)
493 write_into_file(outfile, "contributions", args_info->contributions_orig, 0);
494 if (args_info->window_given)
495 write_into_file(outfile, "window", args_info->window_orig, 0);
496 if (args_info->include_both_given)
497 write_into_file(outfile, "include_both", 0, 0 );
498 if (args_info->extend5_given)
499 write_into_file(outfile, "extend5", args_info->extend5_orig, 0);
500 if (args_info->extend3_given)
501 write_into_file(outfile, "extend3", args_info->extend3_orig, 0);
502 if (args_info->interaction_pairwise_given)
503 write_into_file(outfile, "interaction_pairwise", 0, 0 );
504 if (args_info->interaction_first_given)
505 write_into_file(outfile, "interaction_first", 0, 0 );
506 if (args_info->pfScale_given)
507 write_into_file(outfile, "pfScale", args_info->pfScale_orig, 0);
508 if (args_info->temp_given)
509 write_into_file(outfile, "temp", args_info->temp_orig, 0);
510 if (args_info->noTetra_given)
511 write_into_file(outfile, "noTetra", 0, 0 );
512 if (args_info->dangles_given)
513 write_into_file(outfile, "dangles", args_info->dangles_orig, 0);
514 if (args_info->noLP_given)
515 write_into_file(outfile, "noLP", 0, 0 );
516 if (args_info->noGU_given)
517 write_into_file(outfile, "noGU", 0, 0 );
518 if (args_info->noClosingGU_given)
519 write_into_file(outfile, "noClosingGU", 0, 0 );
520 if (args_info->paramFile_given)
521 write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
522 if (args_info->nsp_given)
523 write_into_file(outfile, "nsp", args_info->nsp_orig, 0);
524 if (args_info->energyModel_given)
525 write_into_file(outfile, "energyModel", args_info->energyModel_orig, 0);
533 RNAup_cmdline_parser_file_save(const char *filename, struct RNAup_args_info *args_info)
538 outfile = fopen(filename, "w");
542 fprintf (stderr, "%s: cannot open file for writing: %s\n", RNAUP_CMDLINE_PARSER_PACKAGE, filename);
546 i = RNAup_cmdline_parser_dump(outfile, args_info);
553 RNAup_cmdline_parser_free (struct RNAup_args_info *args_info)
555 RNAup_cmdline_parser_release (args_info);
558 /** @brief replacement of strdup, which is not standard */
560 gengetopt_strdup (const char *s)
566 result = (char*)malloc(strlen(s) + 1);
567 if (result == (char*)0)
574 get_multiple_arg_token(const char *arg)
578 size_t len, num_of_escape, i, j;
583 tok = strchr (arg, ',');
586 /* make sure it is not escaped */
589 if (*(tok-1) == '\\')
591 /* find the next one */
592 tok = strchr (tok+1, ',');
600 len = (size_t)(tok - arg + 1);
602 len = strlen (arg) + 1;
604 len -= num_of_escape;
606 ret = (char *) malloc (len);
610 while (arg[i] && (j < len-1))
612 if (arg[i] == '\\' &&
626 get_multiple_arg_token_next(const char *arg)
633 tok = strchr (arg, ',');
635 /* make sure it is not escaped */
638 if (*(tok-1) == '\\')
640 /* find the next one */
641 tok = strchr (tok+1, ',');
647 if (! tok || strlen(tok) == 1)
654 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc);
657 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc)
661 if (option_given && (min > 0 || max > 0))
663 if (min > 0 && max > 0)
667 /* specific occurrences */
668 if (option_given != (unsigned int) min)
670 fprintf (stderr, "%s: %s option occurrences must be %d\n",
671 prog_name, option_desc, min);
675 else if (option_given < (unsigned int) min
676 || option_given > (unsigned int) max)
678 /* range occurrences */
679 fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n",
680 prog_name, option_desc, min, max);
687 if (option_given < min)
689 fprintf (stderr, "%s: %s option occurrences must be at least %d\n",
690 prog_name, option_desc, min);
697 if (option_given > max)
699 fprintf (stderr, "%s: %s option occurrences must be at most %d\n",
700 prog_name, option_desc, max);
709 RNAup_cmdline_parser (int argc, char **argv, struct RNAup_args_info *args_info)
711 return RNAup_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
715 RNAup_cmdline_parser_ext (int argc, char **argv, struct RNAup_args_info *args_info,
716 struct RNAup_cmdline_parser_params *params)
719 result = RNAup_cmdline_parser_internal (argc, argv, args_info, params, 0);
721 if (result == EXIT_FAILURE)
723 RNAup_cmdline_parser_free (args_info);
731 RNAup_cmdline_parser2 (int argc, char **argv, struct RNAup_args_info *args_info, int override, int initialize, int check_required)
734 struct RNAup_cmdline_parser_params params;
736 params.override = override;
737 params.initialize = initialize;
738 params.check_required = check_required;
739 params.check_ambiguity = 0;
740 params.print_errors = 1;
742 result = RNAup_cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
744 if (result == EXIT_FAILURE)
746 RNAup_cmdline_parser_free (args_info);
754 RNAup_cmdline_parser_required (struct RNAup_args_info *args_info, const char *prog_name)
756 int result = EXIT_SUCCESS;
758 if (RNAup_cmdline_parser_required2(args_info, prog_name, 0) > 0)
759 result = EXIT_FAILURE;
761 if (result == EXIT_FAILURE)
763 RNAup_cmdline_parser_free (args_info);
771 RNAup_cmdline_parser_required2 (struct RNAup_args_info *args_info, const char *prog_name, const char *additional_error)
774 FIX_UNUSED (additional_error);
776 /* checks for required options */
777 if (check_multiple_option_occurrences(prog_name, args_info->ulength_given, args_info->ulength_min, args_info->ulength_max, "'--ulength' ('-u')"))
781 /* checks for dependences among options */
787 * Extracted from the glibc source tree, version 2.3.6
789 * Licensed under the GPL as per the whole glibc source tree.
791 * This file was modified so that getopt_long can be called
792 * many times without risking previous memory to be spoiled.
794 * Modified by Andre Noll and Lorenzo Bettini for use in
795 * GNU gengetopt generated files.
800 * we must include anything we need since this file is not thought to be
801 * inserted in a file already using getopt.h
809 /* has_arg can't be an enum because some compilers complain about
810 type mismatches in all the code that assumes it is an int. */
816 /* This version of `getopt' appears to the caller like standard Unix `getopt'
817 but it behaves differently for the user, since it allows the user
818 to intersperse the options with the other arguments.
820 As `getopt' works, it permutes the elements of ARGV so that,
821 when it is done, all the options precede everything else. Thus
822 all application programs are extended to handle flexible argument order.
825 If the field `flag' is not NULL, it points to a variable that is set
826 to the value given in the field `val' when the option is found, but
827 left unchanged if the option is not found.
829 To have a long-named option do something other than set an `int' to
830 a compiled-in constant, such as set a value from `custom_optarg', set the
831 option's `flag' field to zero and its `val' field to a nonzero
832 value (the equivalent single-letter option character, if there is
833 one). For long options that have a zero `flag' field, `getopt'
834 returns the contents of the `val' field. */
836 /* Names for the values of the `has_arg' field of `struct option'. */
838 #define no_argument 0
841 #ifndef required_argument
842 #define required_argument 1
845 #ifndef optional_argument
846 #define optional_argument 2
849 struct custom_getopt_data {
851 * These have exactly the same meaning as the corresponding global variables,
852 * except that they are used for the reentrant versions of getopt.
859 /* True if the internal members have been initialized. */
863 * The next char to be scanned in the option-element in which the last option
864 * character we returned was found. This allows us to pick up the scan where
865 * we left off. If this is zero, or a null string, it means resume the scan by
866 * advancing to the next ARGV-element.
871 * Describe the part of ARGV that contains non-options that have been skipped.
872 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
873 * the index after the last of them.
880 * the variables optarg, optind, opterr and optopt are renamed with
881 * the custom_ prefix so that they don't interfere with getopt ones.
883 * Moreover they're static so they are visible only from within the
884 * file where this very file will be included.
888 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
889 * option that takes an argument, the argument value is returned here.
891 static char *custom_optarg;
894 * Index in ARGV of the next element to be scanned. This is used for
895 * communication to and from the caller and for communication between
896 * successive calls to `custom_getopt'.
898 * On entry to `custom_getopt', 1 means this is the first call; initialize.
900 * When `custom_getopt' returns -1, this is the index of the first of the non-option
901 * elements that the caller should itself scan.
903 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
904 * has been scanned so far.
906 * 1003.2 says this must be 1 before any call.
908 static int custom_optind = 1;
911 * Callers store zero here to inhibit the error message for unrecognized
914 static int custom_opterr = 1;
917 * Set to an option character which was unrecognized. This must be initialized
918 * on some systems to avoid linking in the system's own getopt implementation.
920 static int custom_optopt = '?';
923 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
924 * [first_nonopt,last_nonopt) which contains all the non-options that have been
925 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
926 * all the options processed since those non-options were skipped.
927 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
928 * indices of the non-options in ARGV after they are moved.
930 static void exchange(char **argv, struct custom_getopt_data *d)
932 int bottom = d->first_nonopt;
933 int middle = d->last_nonopt;
934 int top = d->custom_optind;
938 * Exchange the shorter segment with the far end of the longer segment.
939 * That puts the shorter segment into the right place. It leaves the
940 * longer segment in the right place overall, but it consists of two
941 * parts that need to be swapped next.
943 while (top > middle && middle > bottom) {
944 if (top - middle > middle - bottom) {
945 /* Bottom segment is the short one. */
946 int len = middle - bottom;
949 /* Swap it with the top part of the top segment. */
950 for (i = 0; i < len; i++) {
951 tem = argv[bottom + i];
953 argv[top - (middle - bottom) + i];
954 argv[top - (middle - bottom) + i] = tem;
956 /* Exclude the moved bottom segment from further swapping. */
959 /* Top segment is the short one. */
960 int len = top - middle;
963 /* Swap it with the bottom part of the bottom segment. */
964 for (i = 0; i < len; i++) {
965 tem = argv[bottom + i];
966 argv[bottom + i] = argv[middle + i];
967 argv[middle + i] = tem;
969 /* Exclude the moved top segment from further swapping. */
973 /* Update records for the slots the non-options now occupy. */
974 d->first_nonopt += (d->custom_optind - d->last_nonopt);
975 d->last_nonopt = d->custom_optind;
978 /* Initialize the internal data when the first call is made. */
979 static void custom_getopt_initialize(struct custom_getopt_data *d)
982 * Start processing options with ARGV-element 1 (since ARGV-element 0
983 * is the program name); the sequence of previously skipped non-option
984 * ARGV-elements is empty.
986 d->first_nonopt = d->last_nonopt = d->custom_optind;
991 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
993 /* return: zero: continue, nonzero: return given value to user */
994 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
995 struct custom_getopt_data *d)
998 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
999 * moved back by the user (who may also have changed the arguments).
1001 if (d->last_nonopt > d->custom_optind)
1002 d->last_nonopt = d->custom_optind;
1003 if (d->first_nonopt > d->custom_optind)
1004 d->first_nonopt = d->custom_optind;
1006 * If we have just processed some options following some
1007 * non-options, exchange them so that the options come first.
1009 if (d->first_nonopt != d->last_nonopt &&
1010 d->last_nonopt != d->custom_optind)
1011 exchange((char **) argv, d);
1012 else if (d->last_nonopt != d->custom_optind)
1013 d->first_nonopt = d->custom_optind;
1015 * Skip any additional non-options and extend the range of
1016 * non-options previously skipped.
1018 while (d->custom_optind < argc && NONOPTION_P)
1020 d->last_nonopt = d->custom_optind;
1022 * The special ARGV-element `--' means premature end of options. Skip
1023 * it like a null option, then exchange with previous non-options as if
1024 * it were an option, then skip everything else like a non-option.
1026 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
1028 if (d->first_nonopt != d->last_nonopt
1029 && d->last_nonopt != d->custom_optind)
1030 exchange((char **) argv, d);
1031 else if (d->first_nonopt == d->last_nonopt)
1032 d->first_nonopt = d->custom_optind;
1033 d->last_nonopt = argc;
1034 d->custom_optind = argc;
1037 * If we have done all the ARGV-elements, stop the scan and back over
1038 * any non-options that we skipped and permuted.
1040 if (d->custom_optind == argc) {
1042 * Set the next-arg-index to point at the non-options that we
1043 * previously skipped, so the caller will digest them.
1045 if (d->first_nonopt != d->last_nonopt)
1046 d->custom_optind = d->first_nonopt;
1050 * If we have come to a non-option and did not permute it, either stop
1051 * the scan or describe it to the caller and pass it by.
1054 d->custom_optarg = argv[d->custom_optind++];
1058 * We have found another option-ARGV-element. Skip the initial
1061 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
1066 * Check whether the ARGV-element is a long option.
1068 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
1069 * that an abbreviation of the long option, just like "--fu", and not "-f" with
1072 * This distinction seems to be the most useful approach.
1075 static int check_long_opt(int argc, char *const *argv, const char *optstring,
1076 const struct option *longopts, int *longind,
1077 int print_errors, struct custom_getopt_data *d)
1080 const struct option *p;
1081 const struct option *pfound = NULL;
1087 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
1090 /* Test all long options for either exact match or abbreviated matches */
1091 for (p = longopts, option_index = 0; p->name; p++, option_index++)
1092 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
1093 if ((unsigned int) (nameend - d->nextchar)
1094 == (unsigned int) strlen(p->name)) {
1095 /* Exact match found. */
1097 indfound = option_index;
1100 } else if (pfound == NULL) {
1101 /* First nonexact match found. */
1103 indfound = option_index;
1104 } else if (pfound->has_arg != p->has_arg
1105 || pfound->flag != p->flag
1106 || pfound->val != p->val)
1107 /* Second or later nonexact match found. */
1110 if (ambig && !exact) {
1113 "%s: option `%s' is ambiguous\n",
1114 argv[0], argv[d->custom_optind]);
1116 d->nextchar += strlen(d->nextchar);
1118 d->custom_optopt = 0;
1122 option_index = indfound;
1125 if (pfound->has_arg != no_argument)
1126 d->custom_optarg = nameend + 1;
1129 if (argv[d->custom_optind - 1][1] == '-') {
1131 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
1132 argv[0], pfound->name);
1134 /* +option or -option */
1135 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
1136 argv[0], argv[d->custom_optind - 1][0], pfound->name);
1140 d->nextchar += strlen(d->nextchar);
1141 d->custom_optopt = pfound->val;
1144 } else if (pfound->has_arg == required_argument) {
1145 if (d->custom_optind < argc)
1146 d->custom_optarg = argv[d->custom_optind++];
1150 "%s: option `%s' requires an argument\n",
1152 argv[d->custom_optind - 1]);
1154 d->nextchar += strlen(d->nextchar);
1155 d->custom_optopt = pfound->val;
1156 return optstring[0] == ':' ? ':' : '?';
1159 d->nextchar += strlen(d->nextchar);
1160 if (longind != NULL)
1161 *longind = option_index;
1163 *(pfound->flag) = pfound->val;
1169 * Can't find it as a long option. If this is not getopt_long_only, or
1170 * the option starts with '--' or is not a valid short option, then
1171 * it's an error. Otherwise interpret it as a short option.
1174 if (argv[d->custom_optind][1] == '-') {
1177 "%s: unrecognized option `--%s'\n",
1178 argv[0], d->nextchar);
1180 /* +option or -option */
1182 "%s: unrecognized option `%c%s'\n",
1183 argv[0], argv[d->custom_optind][0],
1187 d->nextchar = (char *) "";
1189 d->custom_optopt = 0;
1193 static int check_short_opt(int argc, char *const *argv, const char *optstring,
1194 int print_errors, struct custom_getopt_data *d)
1196 char c = *d->nextchar++;
1197 const char *temp = strchr(optstring, c);
1199 /* Increment `custom_optind' when we start to process its last character. */
1200 if (*d->nextchar == '\0')
1202 if (!temp || c == ':') {
1204 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
1206 d->custom_optopt = c;
1209 if (temp[1] == ':') {
1210 if (temp[2] == ':') {
1211 /* This is an option that accepts an argument optionally. */
1212 if (*d->nextchar != '\0') {
1213 d->custom_optarg = d->nextchar;
1216 d->custom_optarg = NULL;
1219 /* This is an option that requires an argument. */
1220 if (*d->nextchar != '\0') {
1221 d->custom_optarg = d->nextchar;
1223 * If we end this ARGV-element by taking the
1224 * rest as an arg, we must advance to the next
1228 } else if (d->custom_optind == argc) {
1231 "%s: option requires an argument -- %c\n",
1234 d->custom_optopt = c;
1235 if (optstring[0] == ':')
1241 * We already incremented `custom_optind' once;
1242 * increment it again when taking next ARGV-elt
1245 d->custom_optarg = argv[d->custom_optind++];
1253 * Scan elements of ARGV for option characters given in OPTSTRING.
1255 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
1256 * then it is an option element. The characters of this element
1257 * (aside from the initial '-') are option characters. If `getopt'
1258 * is called repeatedly, it returns successively each of the option characters
1259 * from each of the option elements.
1261 * If `getopt' finds another option character, it returns that character,
1262 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
1263 * resume the scan with the following option character or ARGV-element.
1265 * If there are no more option characters, `getopt' returns -1.
1266 * Then `custom_optind' is the index in ARGV of the first ARGV-element
1267 * that is not an option. (The ARGV-elements have been permuted
1268 * so that those that are not options now come last.)
1270 * OPTSTRING is a string containing the legitimate option characters.
1271 * If an option character is seen that is not listed in OPTSTRING,
1272 * return '?' after printing an error message. If you set `custom_opterr' to
1273 * zero, the error message is suppressed but we still return '?'.
1275 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
1276 * so the following text in the same ARGV-element, or the text of the following
1277 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
1278 * wants an optional arg; if there is text in the current ARGV-element,
1279 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
1281 * If OPTSTRING starts with `-' or `+', it requests different methods of
1282 * handling the non-option ARGV-elements.
1283 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
1285 * Long-named options begin with `--' instead of `-'.
1286 * Their names may be abbreviated as long as the abbreviation is unique
1287 * or is an exact match for some defined option. If they have an
1288 * argument, it follows the option name in the same ARGV-element, separated
1289 * from the option name by a `=', or else the in next ARGV-element.
1290 * When `getopt' finds a long-named option, it returns 0 if that option's
1291 * `flag' field is nonzero, the value of the option's `val' field
1292 * if the `flag' field is zero.
1294 * The elements of ARGV aren't really const, because we permute them.
1295 * But we pretend they're const in the prototype to be compatible
1296 * with other systems.
1298 * LONGOPTS is a vector of `struct option' terminated by an
1299 * element containing a name which is zero.
1301 * LONGIND returns the index in LONGOPT of the long-named option found.
1302 * It is only valid when a long-named option has been found by the most
1305 * Return the option character from OPTS just read. Return -1 when there are
1306 * no more options. For unrecognized options, or options missing arguments,
1307 * `custom_optopt' is set to the option letter, and '?' is returned.
1309 * The OPTS string is a list of characters which are recognized option letters,
1310 * optionally followed by colons, specifying that that letter takes an
1311 * argument, to be placed in `custom_optarg'.
1313 * If a letter in OPTS is followed by two colons, its argument is optional.
1314 * This behavior is specific to the GNU `getopt'.
1316 * The argument `--' causes premature termination of argument scanning,
1317 * explicitly telling `getopt' that there are no more options. If OPTS begins
1318 * with `--', then non-option arguments are treated as arguments to the option
1319 * '\0'. This behavior is specific to the GNU `getopt'.
1322 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1323 const struct option *longopts, int *longind,
1324 struct custom_getopt_data *d)
1326 int ret, print_errors = d->custom_opterr;
1328 if (optstring[0] == ':')
1332 d->custom_optarg = NULL;
1335 * This is a big difference with GNU getopt, since optind == 0
1336 * means initialization while here 1 means first call.
1338 if (d->custom_optind == 0 || !d->initialized) {
1339 if (d->custom_optind == 0)
1340 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
1341 custom_getopt_initialize(d);
1343 if (d->nextchar == NULL || *d->nextchar == '\0') {
1344 ret = shuffle_argv(argc, argv, longopts, d);
1348 if (longopts && (argv[d->custom_optind][1] == '-' ))
1349 return check_long_opt(argc, argv, optstring, longopts,
1350 longind, print_errors, d);
1351 return check_short_opt(argc, argv, optstring, print_errors, d);
1354 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1355 const struct option *longopts, int *longind)
1358 /* Keep a global copy of all internal members of d */
1359 static struct custom_getopt_data d;
1361 d.custom_optind = custom_optind;
1362 d.custom_opterr = custom_opterr;
1363 result = getopt_internal_r(argc, argv, optstring, longopts,
1365 custom_optind = d.custom_optind;
1366 custom_optarg = d.custom_optarg;
1367 custom_optopt = d.custom_optopt;
1371 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1372 const struct option *long_options, int *opt_index)
1374 return custom_getopt_internal(argc, argv, options, long_options,
1379 static char *package_name = 0;
1382 * @brief updates an option
1383 * @param field the generic pointer to the field to update
1384 * @param orig_field the pointer to the orig field
1385 * @param field_given the pointer to the number of occurrence of this option
1386 * @param prev_given the pointer to the number of occurrence already seen
1387 * @param value the argument for this option (if null no arg was specified)
1388 * @param possible_values the possible values for this option (if specified)
1389 * @param default_value the default value (in case the option only accepts fixed values)
1390 * @param arg_type the type of this option
1391 * @param check_ambiguity @see RNAup_cmdline_parser_params.check_ambiguity
1392 * @param override @see RNAup_cmdline_parser_params.override
1393 * @param no_free whether to free a possible previous value
1394 * @param multiple_option whether this is a multiple option
1395 * @param long_opt the corresponding long option
1396 * @param short_opt the corresponding short option (or '-' if none)
1397 * @param additional_error possible further error specification
1400 int update_arg(void *field, char **orig_field,
1401 unsigned int *field_given, unsigned int *prev_given,
1402 char *value, const char *possible_values[],
1403 const char *default_value,
1404 RNAup_cmdline_parser_arg_type arg_type,
1405 int check_ambiguity, int override,
1406 int no_free, int multiple_option,
1407 const char *long_opt, char short_opt,
1408 const char *additional_error)
1410 char *stop_char = 0;
1411 const char *val = value;
1413 char **string_field;
1419 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1421 if (short_opt != '-')
1422 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1423 package_name, long_opt, short_opt,
1424 (additional_error ? additional_error : ""));
1426 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1427 package_name, long_opt,
1428 (additional_error ? additional_error : ""));
1429 return 1; /* failure */
1432 FIX_UNUSED (default_value);
1434 if (field_given && *field_given && ! override)
1440 if (possible_values)
1441 val = possible_values[found];
1445 *((int *)field) = !*((int *)field);
1448 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1451 if (val) *((double *)field) = strtod (val, &stop_char);
1455 string_field = (char **)field;
1456 if (!no_free && *string_field)
1457 free (*string_field); /* free previous string */
1458 *string_field = gengetopt_strdup (val);
1465 /* check numeric conversion */
1469 if (val && !(stop_char && *stop_char == '\0')) {
1470 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1471 return 1; /* failure */
1478 /* store the original value */
1484 if (value && orig_field) {
1486 *orig_field = value;
1489 free (*orig_field); /* free previous string */
1490 *orig_field = gengetopt_strdup (value);
1499 * @brief store information about a multiple option in a temporary list
1500 * @param list where to (temporarily) store multiple options
1503 int update_multiple_arg_temp(struct generic_list **list,
1504 unsigned int *prev_given, const char *val,
1505 const char *possible_values[], const char *default_value,
1506 RNAup_cmdline_parser_arg_type arg_type,
1507 const char *long_opt, char short_opt,
1508 const char *additional_error)
1510 /* store single arguments */
1512 const char *multi_next;
1514 if (arg_type == ARG_NO) {
1519 multi_token = get_multiple_arg_token(val);
1520 multi_next = get_multiple_arg_token_next (val);
1525 if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0,
1526 prev_given, multi_token, possible_values, default_value,
1527 arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
1528 if (multi_token) free(multi_token);
1529 return 1; /* failure */
1534 multi_token = get_multiple_arg_token(multi_next);
1535 multi_next = get_multiple_arg_token_next (multi_next);
1545 * @brief free the passed list (including possible string argument)
1548 void free_list(struct generic_list *list, short string_arg)
1551 struct generic_list *tmp;
1555 if (string_arg && list->arg.string_arg)
1556 free (list->arg.string_arg);
1566 * @brief updates a multiple option starting from the passed list
1569 void update_multiple_arg(void *field, char ***orig_field,
1570 unsigned int field_given, unsigned int prev_given, union generic_value *default_value,
1571 RNAup_cmdline_parser_arg_type arg_type,
1572 struct generic_list *list)
1575 struct generic_list *tmp;
1577 if (prev_given && list) {
1578 *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *));
1582 *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break;
1584 *((double **)field) = (double *)realloc (*((double **)field), (field_given + prev_given) * sizeof (double)); break;
1586 *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break;
1591 for (i = (prev_given - 1); i >= 0; --i)
1597 (*((int **)field))[i + field_given] = tmp->arg.int_arg; break;
1599 (*((double **)field))[i + field_given] = tmp->arg.double_arg; break;
1601 (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break;
1605 (*orig_field) [i + field_given] = list->orig;
1609 } else { /* set the default value */
1610 if (default_value && ! field_given) {
1613 if (! *((int **)field)) {
1614 *((int **)field) = (int *)malloc (sizeof (int));
1615 (*((int **)field))[0] = default_value->int_arg;
1619 if (! *((double **)field)) {
1620 *((double **)field) = (double *)malloc (sizeof (double));
1621 (*((double **)field))[0] = default_value->double_arg;
1625 if (! *((char ***)field)) {
1626 *((char ***)field) = (char **)malloc (sizeof (char *));
1627 (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg);
1632 if (!(*orig_field)) {
1633 *orig_field = (char **) malloc (sizeof (char *));
1634 (*orig_field)[0] = 0;
1641 RNAup_cmdline_parser_internal (
1642 int argc, char **argv, struct RNAup_args_info *args_info,
1643 struct RNAup_cmdline_parser_params *params, const char *additional_error)
1645 int c; /* Character of the parsed option. */
1646 union generic_value multiple_default_value;
1648 struct generic_list * ulength_list = NULL;
1650 struct RNAup_args_info local_args_info;
1655 int check_ambiguity;
1662 package_name = argv[0];
1664 override = params->override;
1665 initialize = params->initialize;
1666 check_required = params->check_required;
1667 check_ambiguity = params->check_ambiguity;
1670 RNAup_cmdline_parser_init (args_info);
1672 RNAup_cmdline_parser_init (&local_args_info);
1676 opterr = params->print_errors;
1681 int option_index = 0;
1683 static struct option long_options[] = {
1684 { "help", 0, NULL, 'h' },
1685 { "detailed-help", 0, NULL, 0 },
1686 { "full-help", 0, NULL, 0 },
1687 { "version", 0, NULL, 'V' },
1688 { "constraint", 0, NULL, 'C' },
1689 { "no_output_file", 0, NULL, 'o' },
1690 { "no_header", 0, NULL, 0 },
1691 { "noconv", 0, NULL, 0 },
1692 { "ulength", 1, NULL, 'u' },
1693 { "contributions", 1, NULL, 'c' },
1694 { "window", 1, NULL, 'w' },
1695 { "include_both", 0, NULL, 'b' },
1696 { "extend5", 1, NULL, '5' },
1697 { "extend3", 1, NULL, '3' },
1698 { "interaction_pairwise", 0, NULL, 0 },
1699 { "interaction_first", 0, NULL, 0 },
1700 { "pfScale", 1, NULL, 'S' },
1701 { "temp", 1, NULL, 'T' },
1702 { "noTetra", 0, NULL, '4' },
1703 { "dangles", 1, NULL, 'd' },
1704 { "noLP", 0, NULL, 0 },
1705 { "noGU", 0, NULL, 0 },
1706 { "noClosingGU", 0, NULL, 0 },
1707 { "paramFile", 1, NULL, 'P' },
1708 { "nsp", 1, NULL, 0 },
1709 { "energyModel", 1, NULL, 'e' },
1713 custom_optarg = optarg;
1714 custom_optind = optind;
1715 custom_opterr = opterr;
1716 custom_optopt = optopt;
1718 c = custom_getopt_long (argc, argv, "hVCou:c:w:b5:3:S:T:4d:P:e:", long_options, &option_index);
1720 optarg = custom_optarg;
1721 optind = custom_optind;
1722 opterr = custom_opterr;
1723 optopt = custom_optopt;
1725 if (c == -1) break; /* Exit from `while (1)' loop. */
1729 case 'h': /* Print help and exit. */
1730 RNAup_cmdline_parser_print_help ();
1731 RNAup_cmdline_parser_free (&local_args_info);
1732 exit (EXIT_SUCCESS);
1734 case 'V': /* Print version and exit. */
1735 RNAup_cmdline_parser_print_version ();
1736 RNAup_cmdline_parser_free (&local_args_info);
1737 exit (EXIT_SUCCESS);
1739 case 'C': /* Calculate structures subject to constraints.
1743 if (update_arg((void *)&(args_info->constraint_flag), 0, &(args_info->constraint_given),
1744 &(local_args_info.constraint_given), optarg, 0, 0, ARG_FLAG,
1745 check_ambiguity, override, 1, 0, "constraint", 'C',
1750 case 'o': /* Do not produce an output file
1755 if (update_arg((void *)&(args_info->no_output_file_flag), 0, &(args_info->no_output_file_given),
1756 &(local_args_info.no_output_file_given), optarg, 0, 0, ARG_FLAG,
1757 check_ambiguity, override, 1, 0, "no_output_file", 'o',
1762 case 'u': /* specifies the length of the unstructured region in the output.
1765 if (update_multiple_arg_temp(&ulength_list,
1766 &(local_args_info.ulength_given), optarg, 0, "4", ARG_STRING,
1772 case 'c': /* Specify the contributions listed in the output
1776 if (update_arg( (void *)&(args_info->contributions_arg),
1777 &(args_info->contributions_orig), &(args_info->contributions_given),
1778 &(local_args_info.contributions_given), optarg, 0, "S", ARG_STRING,
1779 check_ambiguity, override, 0, 0,
1780 "contributions", 'c',
1785 case 'w': /* Determine the maximal length of the region of interaction
1790 if (update_arg( (void *)&(args_info->window_arg),
1791 &(args_info->window_orig), &(args_info->window_given),
1792 &(local_args_info.window_given), optarg, 0, "25", ARG_INT,
1793 check_ambiguity, override, 0, 0,
1799 case 'b': /* Include the probability of unpaired regions in both (b) RNAs. By default
1800 only the probability of being unpaired in the longer RNA (target) is used.
1805 if (update_arg((void *)&(args_info->include_both_flag), 0, &(args_info->include_both_given),
1806 &(local_args_info.include_both_given), optarg, 0, 0, ARG_FLAG,
1807 check_ambiguity, override, 1, 0, "include_both", 'b',
1812 case '5': /* Extend the region of interaction in the target to some residues on the 5' side
1816 if (update_arg( (void *)&(args_info->extend5_arg),
1817 &(args_info->extend5_orig), &(args_info->extend5_given),
1818 &(local_args_info.extend5_given), optarg, 0, 0, ARG_INT,
1819 check_ambiguity, override, 0, 0,
1825 case '3': /* Extend the region of interaction in the target to some residues on the 3' side
1829 if (update_arg( (void *)&(args_info->extend3_arg),
1830 &(args_info->extend3_orig), &(args_info->extend3_given),
1831 &(local_args_info.extend3_given), optarg, 0, 0, ARG_INT,
1832 check_ambiguity, override, 0, 0,
1838 case 'S': /* In the calculation of the pf use scale*mfe as an estimate for the ensemble free energy (used to avoid overflows). The default is 1.07, useful values are 1.0 to 1.2. Occasionally needed for long sequences.
1839 You can also recompile the program to use double precision (see the README file).
1844 if (update_arg( (void *)&(args_info->pfScale_arg),
1845 &(args_info->pfScale_orig), &(args_info->pfScale_given),
1846 &(local_args_info.pfScale_given), optarg, 0, 0, ARG_DOUBLE,
1847 check_ambiguity, override, 0, 0,
1853 case 'T': /* Rescale energy parameters to a temperature of temp C. Default is 37C.
1858 if (update_arg( (void *)&(args_info->temp_arg),
1859 &(args_info->temp_orig), &(args_info->temp_given),
1860 &(local_args_info.temp_given), optarg, 0, 0, ARG_DOUBLE,
1861 check_ambiguity, override, 0, 0,
1867 case '4': /* Do not include special tabulated stabilizing energies for tri-, tetra- and hexaloop hairpins. Mostly for testing.
1872 if (update_arg((void *)&(args_info->noTetra_flag), 0, &(args_info->noTetra_given),
1873 &(local_args_info.noTetra_given), optarg, 0, 0, ARG_FLAG,
1874 check_ambiguity, override, 1, 0, "noTetra", '4',
1879 case 'd': /* How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops
1883 if (update_arg( (void *)&(args_info->dangles_arg),
1884 &(args_info->dangles_orig), &(args_info->dangles_given),
1885 &(local_args_info.dangles_given), optarg, 0, "2", ARG_INT,
1886 check_ambiguity, override, 0, 0,
1892 case 'P': /* Read energy parameters from paramfile, instead of using the default parameter set.
1896 if (update_arg( (void *)&(args_info->paramFile_arg),
1897 &(args_info->paramFile_orig), &(args_info->paramFile_given),
1898 &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1899 check_ambiguity, override, 0, 0,
1905 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.
1910 if (update_arg( (void *)&(args_info->energyModel_arg),
1911 &(args_info->energyModel_orig), &(args_info->energyModel_given),
1912 &(local_args_info.energyModel_given), optarg, 0, 0, ARG_INT,
1913 check_ambiguity, override, 0, 0,
1920 case 0: /* Long option with no short option */
1921 if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1922 RNAup_cmdline_parser_print_detailed_help ();
1923 RNAup_cmdline_parser_free (&local_args_info);
1924 exit (EXIT_SUCCESS);
1927 if (strcmp (long_options[option_index].name, "full-help") == 0) {
1928 RNAup_cmdline_parser_print_full_help ();
1929 RNAup_cmdline_parser_free (&local_args_info);
1930 exit (EXIT_SUCCESS);
1933 /* Do not produce a header with the command line parameters used in the outputfile
1936 if (strcmp (long_options[option_index].name, "no_header") == 0)
1940 if (update_arg((void *)&(args_info->no_header_flag), 0, &(args_info->no_header_given),
1941 &(local_args_info.no_header_given), optarg, 0, 0, ARG_FLAG,
1942 check_ambiguity, override, 1, 0, "no_header", '-',
1947 /* Do not automatically substitude nucleotide \"T\" with \"U\"
1950 else if (strcmp (long_options[option_index].name, "noconv") == 0)
1954 if (update_arg((void *)&(args_info->noconv_flag), 0, &(args_info->noconv_given),
1955 &(local_args_info.noconv_given), optarg, 0, 0, ARG_FLAG,
1956 check_ambiguity, override, 1, 0, "noconv", '-',
1961 /* Activate pairwise interaction mode
1963 else if (strcmp (long_options[option_index].name, "interaction_pairwise") == 0)
1967 if (update_arg((void *)&(args_info->interaction_pairwise_flag), 0, &(args_info->interaction_pairwise_given),
1968 &(local_args_info.interaction_pairwise_given), optarg, 0, 0, ARG_FLAG,
1969 check_ambiguity, override, 1, 0, "interaction_pairwise", '-',
1974 /* Activate interaction mode using first sequence only
1976 else if (strcmp (long_options[option_index].name, "interaction_first") == 0)
1980 if (update_arg((void *)&(args_info->interaction_first_flag), 0, &(args_info->interaction_first_given),
1981 &(local_args_info.interaction_first_given), optarg, 0, 0, ARG_FLAG,
1982 check_ambiguity, override, 1, 0, "interaction_first", '-',
1987 /* Produce structures without lonely pairs (helices of length 1).
1989 else if (strcmp (long_options[option_index].name, "noLP") == 0)
1993 if (update_arg((void *)&(args_info->noLP_flag), 0, &(args_info->noLP_given),
1994 &(local_args_info.noLP_given), optarg, 0, 0, ARG_FLAG,
1995 check_ambiguity, override, 1, 0, "noLP", '-',
2000 /* Do not allow GU pairs
2003 else if (strcmp (long_options[option_index].name, "noGU") == 0)
2007 if (update_arg((void *)&(args_info->noGU_flag), 0, &(args_info->noGU_given),
2008 &(local_args_info.noGU_given), optarg, 0, 0, ARG_FLAG,
2009 check_ambiguity, override, 1, 0, "noGU", '-',
2014 /* Do not allow GU pairs at the end of helices
2017 else if (strcmp (long_options[option_index].name, "noClosingGU") == 0)
2021 if (update_arg((void *)&(args_info->noClosingGU_flag), 0, &(args_info->noClosingGU_given),
2022 &(local_args_info.noClosingGU_given), optarg, 0, 0, ARG_FLAG,
2023 check_ambiguity, override, 1, 0, "noClosingGU", '-',
2028 /* Allow other pairs in addition to the usual AU,GC,and GU pairs.
2030 else if (strcmp (long_options[option_index].name, "nsp") == 0)
2034 if (update_arg( (void *)&(args_info->nsp_arg),
2035 &(args_info->nsp_orig), &(args_info->nsp_given),
2036 &(local_args_info.nsp_given), optarg, 0, 0, ARG_STRING,
2037 check_ambiguity, override, 0, 0,
2045 case '?': /* Invalid option. */
2046 /* `getopt_long' already printed an error message. */
2049 default: /* bug: option not considered. */
2050 fprintf (stderr, "%s: option unknown: %c%s\n", RNAUP_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
2056 multiple_default_value.default_string_arg = "4";
2057 update_multiple_arg((void *)&(args_info->ulength_arg),
2058 &(args_info->ulength_orig), args_info->ulength_given,
2059 local_args_info.ulength_given, &multiple_default_value,
2060 ARG_STRING, ulength_list);
2062 args_info->ulength_given += local_args_info.ulength_given;
2063 local_args_info.ulength_given = 0;
2067 error += RNAup_cmdline_parser_required2 (args_info, argv[0], additional_error);
2070 RNAup_cmdline_parser_release (&local_args_info);
2073 return (EXIT_FAILURE);
2078 free_list (ulength_list, 1 );
2080 RNAup_cmdline_parser_release (&local_args_info);
2081 return (EXIT_FAILURE);