New Linux binaries for ViennaRNA
[jabaws.git] / binaries / src / ViennaRNA / Progs / RNAplfold_cmdl.c
1 /*
2   File autogenerated by gengetopt version 2.22.5
3   generated with the following command:
4   gengetopt -i RNAplfold.ggo --file-name=RNAplfold_cmdl --include-getopt --default-optional --func-name=RNAplfold_cmdline_parser --arg-struct-name=RNAplfold_args_info
5
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.
9 */
10
11 /* If we use autoconf.  */
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #ifndef FIX_UNUSED
21 #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
22 #endif
23
24
25 #include "RNAplfold_cmdl.h"
26
27 const char *RNAplfold_args_info_purpose = "calculate locally stable secondary structure - pair probabilities";
28
29 const char *RNAplfold_args_info_usage = "Usage: RNAplfold [OPTIONS]...";
30
31 const char *RNAplfold_args_info_description = "Computes local pair probabilities for base pairs with a maximal span of L. The \nprobabilities are averaged over all windows of size L that contain the base \npair. For a sequence of length n and a window size of L the algorithm uses only \nO(n+L*L) memory and O(n*L*L) CPU time. Thus it is practical to \"scan\" very \nlarge genomes for short stable RNA structures.\n";
32
33 const char *RNAplfold_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",
38   "\nGeneral Options:",
39   "  Below are command line options which alter the general behavior of this \n  program\n",
40   "  -W, --winsize=size         Average the pair probabilities over windows of \n                               given size\n\n                                 (default=`70')",
41   "  -L, --span=size            Set the maximum allowed separation of a base pair \n                               to span. I.e. no pairs (i,j) with j-i > span \n                               will be allowed. Defaults to winsize if \n                               parameter is omitted\n\n",
42   "  -c, --cutoff=FLOAT         Report only base pairs with an average probability \n                               > cutoff in the dot plot\n\n                                 (default=`0.01')",
43   "  -o, --print_onthefly       Save memory by printing out everything during \n                               computation.\n                               NOTE: activated per default for sequences over \n                               1M bp.\n\n                                 (default=off)",
44   "  -u, --ulength=length       Compute the mean probability that regions of \n                               length 1 to a given length are unpaired. Output \n                               is saved in a _lunp file.\n\n                                 (default=`31')",
45   "  -O, --opening_energies     Switch output from probabilities to their \n                               logarithms, which are NOT exactly the mean \n                               energies needed to the respective stretch of \n                               bases!\n                               NOTE: This actives -u option.\n\n                                 (default=off)",
46   "      --plex_output          Create additional output files for RNAplex.\n\n                                 (default=off)",
47   "      --noconv               Do not automatically substitude nucleotide \"T\" \n                               with \"U\"\n\n                                 (default=off)",
48   "\nModel Details:",
49   "  -T, --temp=DOUBLE          Rescale energy parameters to a temperature of temp \n                               C. Default is 37C.\n\n",
50   "  -4, --noTetra              Do not include special tabulated stabilizing \n                               energies for tri-, tetra- and hexaloop hairpins. \n                               Mostly for testing.\n\n                                 (default=off)",
51   "  -d, --dangles=INT          How to treat \"dangling end\" energies for bases \n                               adjacent to helices in free ends and multi-loops\n                                 (default=`2')",
52   "  With -d2 dangling energies will be added for the bases adjacent to a helix on \n  both sides in any case.\n\n  -d0 ignores dangling ends altogether (mostly for debugging).\n\n",
53   "      --noLP                 Produce structures without lonely pairs (helices \n                               of length 1).\n                                 (default=off)",
54   "  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",
55   "      --noGU                 Do not allow GU pairs\n\n                                 (default=off)",
56   "      --noClosingGU          Do not allow GU pairs at the end of helices\n\n                                 (default=off)",
57   "  -P, --paramFile=paramfile  Read energy parameters from paramfile, instead of \n                               using the default parameter set.\n",
58   "  A sample parameter file should accompany your distribution.\n  See the RNAlib documentation for details on the file format.\n\n",
59   "  -b, --binaries             Output accessibility profiles in binary format\n                               .  (default=off)",
60   "   The binary files produced by RNAplfold do not need to be parsed by RNAplex, \n  so that they are directly loaded into memory. This is useful when large \n  sequences have to be searched for putative hybridization sites. An other \n  advantage of the binary format is the 50% file size decrease.\n\n",
61   "      --nsp=STRING           Allow other pairs in addition to the usual \n                               AU,GC,and GU pairs.\n",
62   "  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",
63   "  -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",
64   "      --betaScale=DOUBLE     Set the scaling of the Boltzmann factors\n                                 (default=`1.')",
65   "  The argument provided with this option enables to scale the thermodynamic \n  temperature used in the Boltzmann factors independently from the temperature \n  used to scale the individual energy contributions of the loop types. The \n  Boltzmann factors then become exp(-dG/(kT*betaScale)) where k is the \n  Boltzmann constant, dG the free energy contribution of the state and T the \n  absolute temperature.\n\n",
66   "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
67     0
68 };
69 static void
70 init_full_help_array(void)
71 {
72   RNAplfold_args_info_full_help[0] = RNAplfold_args_info_detailed_help[0];
73   RNAplfold_args_info_full_help[1] = RNAplfold_args_info_detailed_help[1];
74   RNAplfold_args_info_full_help[2] = RNAplfold_args_info_detailed_help[2];
75   RNAplfold_args_info_full_help[3] = RNAplfold_args_info_detailed_help[3];
76   RNAplfold_args_info_full_help[4] = RNAplfold_args_info_detailed_help[4];
77   RNAplfold_args_info_full_help[5] = RNAplfold_args_info_detailed_help[5];
78   RNAplfold_args_info_full_help[6] = RNAplfold_args_info_detailed_help[6];
79   RNAplfold_args_info_full_help[7] = RNAplfold_args_info_detailed_help[7];
80   RNAplfold_args_info_full_help[8] = RNAplfold_args_info_detailed_help[8];
81   RNAplfold_args_info_full_help[9] = RNAplfold_args_info_detailed_help[9];
82   RNAplfold_args_info_full_help[10] = RNAplfold_args_info_detailed_help[10];
83   RNAplfold_args_info_full_help[11] = RNAplfold_args_info_detailed_help[11];
84   RNAplfold_args_info_full_help[12] = RNAplfold_args_info_detailed_help[12];
85   RNAplfold_args_info_full_help[13] = RNAplfold_args_info_detailed_help[13];
86   RNAplfold_args_info_full_help[14] = RNAplfold_args_info_detailed_help[14];
87   RNAplfold_args_info_full_help[15] = RNAplfold_args_info_detailed_help[15];
88   RNAplfold_args_info_full_help[16] = RNAplfold_args_info_detailed_help[16];
89   RNAplfold_args_info_full_help[17] = RNAplfold_args_info_detailed_help[17];
90   RNAplfold_args_info_full_help[18] = RNAplfold_args_info_detailed_help[19];
91   RNAplfold_args_info_full_help[19] = RNAplfold_args_info_detailed_help[21];
92   RNAplfold_args_info_full_help[20] = RNAplfold_args_info_detailed_help[22];
93   RNAplfold_args_info_full_help[21] = RNAplfold_args_info_detailed_help[23];
94   RNAplfold_args_info_full_help[22] = RNAplfold_args_info_detailed_help[25];
95   RNAplfold_args_info_full_help[23] = RNAplfold_args_info_detailed_help[27];
96   RNAplfold_args_info_full_help[24] = RNAplfold_args_info_detailed_help[29];
97   RNAplfold_args_info_full_help[25] = RNAplfold_args_info_detailed_help[30];
98   RNAplfold_args_info_full_help[26] = RNAplfold_args_info_detailed_help[32];
99   RNAplfold_args_info_full_help[27] = 0; 
100   
101 }
102
103 const char *RNAplfold_args_info_full_help[28];
104
105 static void
106 init_help_array(void)
107 {
108   RNAplfold_args_info_help[0] = RNAplfold_args_info_detailed_help[0];
109   RNAplfold_args_info_help[1] = RNAplfold_args_info_detailed_help[1];
110   RNAplfold_args_info_help[2] = RNAplfold_args_info_detailed_help[2];
111   RNAplfold_args_info_help[3] = RNAplfold_args_info_detailed_help[3];
112   RNAplfold_args_info_help[4] = RNAplfold_args_info_detailed_help[4];
113   RNAplfold_args_info_help[5] = RNAplfold_args_info_detailed_help[5];
114   RNAplfold_args_info_help[6] = RNAplfold_args_info_detailed_help[6];
115   RNAplfold_args_info_help[7] = RNAplfold_args_info_detailed_help[7];
116   RNAplfold_args_info_help[8] = RNAplfold_args_info_detailed_help[8];
117   RNAplfold_args_info_help[9] = RNAplfold_args_info_detailed_help[9];
118   RNAplfold_args_info_help[10] = RNAplfold_args_info_detailed_help[10];
119   RNAplfold_args_info_help[11] = RNAplfold_args_info_detailed_help[11];
120   RNAplfold_args_info_help[12] = RNAplfold_args_info_detailed_help[13];
121   RNAplfold_args_info_help[13] = RNAplfold_args_info_detailed_help[14];
122   RNAplfold_args_info_help[14] = RNAplfold_args_info_detailed_help[15];
123   RNAplfold_args_info_help[15] = RNAplfold_args_info_detailed_help[16];
124   RNAplfold_args_info_help[16] = RNAplfold_args_info_detailed_help[17];
125   RNAplfold_args_info_help[17] = RNAplfold_args_info_detailed_help[19];
126   RNAplfold_args_info_help[18] = RNAplfold_args_info_detailed_help[21];
127   RNAplfold_args_info_help[19] = RNAplfold_args_info_detailed_help[22];
128   RNAplfold_args_info_help[20] = RNAplfold_args_info_detailed_help[23];
129   RNAplfold_args_info_help[21] = RNAplfold_args_info_detailed_help[25];
130   RNAplfold_args_info_help[22] = RNAplfold_args_info_detailed_help[32];
131   RNAplfold_args_info_help[23] = 0; 
132   
133 }
134
135 const char *RNAplfold_args_info_help[24];
136
137 typedef enum {ARG_NO
138   , ARG_FLAG
139   , ARG_STRING
140   , ARG_INT
141   , ARG_FLOAT
142   , ARG_DOUBLE
143 } RNAplfold_cmdline_parser_arg_type;
144
145 static
146 void clear_given (struct RNAplfold_args_info *args_info);
147 static
148 void clear_args (struct RNAplfold_args_info *args_info);
149
150 static int
151 RNAplfold_cmdline_parser_internal (int argc, char **argv, struct RNAplfold_args_info *args_info,
152                         struct RNAplfold_cmdline_parser_params *params, const char *additional_error);
153
154
155 static char *
156 gengetopt_strdup (const char *s);
157
158 static
159 void clear_given (struct RNAplfold_args_info *args_info)
160 {
161   args_info->help_given = 0 ;
162   args_info->detailed_help_given = 0 ;
163   args_info->full_help_given = 0 ;
164   args_info->version_given = 0 ;
165   args_info->winsize_given = 0 ;
166   args_info->span_given = 0 ;
167   args_info->cutoff_given = 0 ;
168   args_info->print_onthefly_given = 0 ;
169   args_info->ulength_given = 0 ;
170   args_info->opening_energies_given = 0 ;
171   args_info->plex_output_given = 0 ;
172   args_info->noconv_given = 0 ;
173   args_info->temp_given = 0 ;
174   args_info->noTetra_given = 0 ;
175   args_info->dangles_given = 0 ;
176   args_info->noLP_given = 0 ;
177   args_info->noGU_given = 0 ;
178   args_info->noClosingGU_given = 0 ;
179   args_info->paramFile_given = 0 ;
180   args_info->binaries_given = 0 ;
181   args_info->nsp_given = 0 ;
182   args_info->energyModel_given = 0 ;
183   args_info->betaScale_given = 0 ;
184 }
185
186 static
187 void clear_args (struct RNAplfold_args_info *args_info)
188 {
189   FIX_UNUSED (args_info);
190   args_info->winsize_arg = 70;
191   args_info->winsize_orig = NULL;
192   args_info->span_orig = NULL;
193   args_info->cutoff_arg = 0.01;
194   args_info->cutoff_orig = NULL;
195   args_info->print_onthefly_flag = 0;
196   args_info->ulength_arg = 31;
197   args_info->ulength_orig = NULL;
198   args_info->opening_energies_flag = 0;
199   args_info->plex_output_flag = 0;
200   args_info->noconv_flag = 0;
201   args_info->temp_orig = NULL;
202   args_info->noTetra_flag = 0;
203   args_info->dangles_arg = 2;
204   args_info->dangles_orig = NULL;
205   args_info->noLP_flag = 0;
206   args_info->noGU_flag = 0;
207   args_info->noClosingGU_flag = 0;
208   args_info->paramFile_arg = NULL;
209   args_info->paramFile_orig = NULL;
210   args_info->binaries_flag = 0;
211   args_info->nsp_arg = NULL;
212   args_info->nsp_orig = NULL;
213   args_info->energyModel_orig = NULL;
214   args_info->betaScale_arg = 1.;
215   args_info->betaScale_orig = NULL;
216   
217 }
218
219 static
220 void init_args_info(struct RNAplfold_args_info *args_info)
221 {
222   init_full_help_array(); 
223   init_help_array(); 
224   args_info->help_help = RNAplfold_args_info_detailed_help[0] ;
225   args_info->detailed_help_help = RNAplfold_args_info_detailed_help[1] ;
226   args_info->full_help_help = RNAplfold_args_info_detailed_help[2] ;
227   args_info->version_help = RNAplfold_args_info_detailed_help[3] ;
228   args_info->winsize_help = RNAplfold_args_info_detailed_help[6] ;
229   args_info->span_help = RNAplfold_args_info_detailed_help[7] ;
230   args_info->cutoff_help = RNAplfold_args_info_detailed_help[8] ;
231   args_info->print_onthefly_help = RNAplfold_args_info_detailed_help[9] ;
232   args_info->ulength_help = RNAplfold_args_info_detailed_help[10] ;
233   args_info->opening_energies_help = RNAplfold_args_info_detailed_help[11] ;
234   args_info->plex_output_help = RNAplfold_args_info_detailed_help[12] ;
235   args_info->noconv_help = RNAplfold_args_info_detailed_help[13] ;
236   args_info->temp_help = RNAplfold_args_info_detailed_help[15] ;
237   args_info->noTetra_help = RNAplfold_args_info_detailed_help[16] ;
238   args_info->dangles_help = RNAplfold_args_info_detailed_help[17] ;
239   args_info->noLP_help = RNAplfold_args_info_detailed_help[19] ;
240   args_info->noGU_help = RNAplfold_args_info_detailed_help[21] ;
241   args_info->noClosingGU_help = RNAplfold_args_info_detailed_help[22] ;
242   args_info->paramFile_help = RNAplfold_args_info_detailed_help[23] ;
243   args_info->binaries_help = RNAplfold_args_info_detailed_help[25] ;
244   args_info->nsp_help = RNAplfold_args_info_detailed_help[27] ;
245   args_info->energyModel_help = RNAplfold_args_info_detailed_help[29] ;
246   args_info->betaScale_help = RNAplfold_args_info_detailed_help[30] ;
247   
248 }
249
250 void
251 RNAplfold_cmdline_parser_print_version (void)
252 {
253   printf ("%s %s\n",
254      (strlen(RNAPLFOLD_CMDLINE_PARSER_PACKAGE_NAME) ? RNAPLFOLD_CMDLINE_PARSER_PACKAGE_NAME : RNAPLFOLD_CMDLINE_PARSER_PACKAGE),
255      RNAPLFOLD_CMDLINE_PARSER_VERSION);
256 }
257
258 static void print_help_common(void) {
259   RNAplfold_cmdline_parser_print_version ();
260
261   if (strlen(RNAplfold_args_info_purpose) > 0)
262     printf("\n%s\n", RNAplfold_args_info_purpose);
263
264   if (strlen(RNAplfold_args_info_usage) > 0)
265     printf("\n%s\n", RNAplfold_args_info_usage);
266
267   printf("\n");
268
269   if (strlen(RNAplfold_args_info_description) > 0)
270     printf("%s\n\n", RNAplfold_args_info_description);
271 }
272
273 void
274 RNAplfold_cmdline_parser_print_help (void)
275 {
276   int i = 0;
277   print_help_common();
278   while (RNAplfold_args_info_help[i])
279     printf("%s\n", RNAplfold_args_info_help[i++]);
280 }
281
282 void
283 RNAplfold_cmdline_parser_print_full_help (void)
284 {
285   int i = 0;
286   print_help_common();
287   while (RNAplfold_args_info_full_help[i])
288     printf("%s\n", RNAplfold_args_info_full_help[i++]);
289 }
290
291 void
292 RNAplfold_cmdline_parser_print_detailed_help (void)
293 {
294   int i = 0;
295   print_help_common();
296   while (RNAplfold_args_info_detailed_help[i])
297     printf("%s\n", RNAplfold_args_info_detailed_help[i++]);
298 }
299
300 void
301 RNAplfold_cmdline_parser_init (struct RNAplfold_args_info *args_info)
302 {
303   clear_given (args_info);
304   clear_args (args_info);
305   init_args_info (args_info);
306 }
307
308 void
309 RNAplfold_cmdline_parser_params_init(struct RNAplfold_cmdline_parser_params *params)
310 {
311   if (params)
312     { 
313       params->override = 0;
314       params->initialize = 1;
315       params->check_required = 1;
316       params->check_ambiguity = 0;
317       params->print_errors = 1;
318     }
319 }
320
321 struct RNAplfold_cmdline_parser_params *
322 RNAplfold_cmdline_parser_params_create(void)
323 {
324   struct RNAplfold_cmdline_parser_params *params = 
325     (struct RNAplfold_cmdline_parser_params *)malloc(sizeof(struct RNAplfold_cmdline_parser_params));
326   RNAplfold_cmdline_parser_params_init(params);  
327   return params;
328 }
329
330 static void
331 free_string_field (char **s)
332 {
333   if (*s)
334     {
335       free (*s);
336       *s = 0;
337     }
338 }
339
340
341 static void
342 RNAplfold_cmdline_parser_release (struct RNAplfold_args_info *args_info)
343 {
344
345   free_string_field (&(args_info->winsize_orig));
346   free_string_field (&(args_info->span_orig));
347   free_string_field (&(args_info->cutoff_orig));
348   free_string_field (&(args_info->ulength_orig));
349   free_string_field (&(args_info->temp_orig));
350   free_string_field (&(args_info->dangles_orig));
351   free_string_field (&(args_info->paramFile_arg));
352   free_string_field (&(args_info->paramFile_orig));
353   free_string_field (&(args_info->nsp_arg));
354   free_string_field (&(args_info->nsp_orig));
355   free_string_field (&(args_info->energyModel_orig));
356   free_string_field (&(args_info->betaScale_orig));
357   
358   
359
360   clear_given (args_info);
361 }
362
363
364 static void
365 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
366 {
367   FIX_UNUSED (values);
368   if (arg) {
369     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
370   } else {
371     fprintf(outfile, "%s\n", opt);
372   }
373 }
374
375
376 int
377 RNAplfold_cmdline_parser_dump(FILE *outfile, struct RNAplfold_args_info *args_info)
378 {
379   int i = 0;
380
381   if (!outfile)
382     {
383       fprintf (stderr, "%s: cannot dump options to stream\n", RNAPLFOLD_CMDLINE_PARSER_PACKAGE);
384       return EXIT_FAILURE;
385     }
386
387   if (args_info->help_given)
388     write_into_file(outfile, "help", 0, 0 );
389   if (args_info->detailed_help_given)
390     write_into_file(outfile, "detailed-help", 0, 0 );
391   if (args_info->full_help_given)
392     write_into_file(outfile, "full-help", 0, 0 );
393   if (args_info->version_given)
394     write_into_file(outfile, "version", 0, 0 );
395   if (args_info->winsize_given)
396     write_into_file(outfile, "winsize", args_info->winsize_orig, 0);
397   if (args_info->span_given)
398     write_into_file(outfile, "span", args_info->span_orig, 0);
399   if (args_info->cutoff_given)
400     write_into_file(outfile, "cutoff", args_info->cutoff_orig, 0);
401   if (args_info->print_onthefly_given)
402     write_into_file(outfile, "print_onthefly", 0, 0 );
403   if (args_info->ulength_given)
404     write_into_file(outfile, "ulength", args_info->ulength_orig, 0);
405   if (args_info->opening_energies_given)
406     write_into_file(outfile, "opening_energies", 0, 0 );
407   if (args_info->plex_output_given)
408     write_into_file(outfile, "plex_output", 0, 0 );
409   if (args_info->noconv_given)
410     write_into_file(outfile, "noconv", 0, 0 );
411   if (args_info->temp_given)
412     write_into_file(outfile, "temp", args_info->temp_orig, 0);
413   if (args_info->noTetra_given)
414     write_into_file(outfile, "noTetra", 0, 0 );
415   if (args_info->dangles_given)
416     write_into_file(outfile, "dangles", args_info->dangles_orig, 0);
417   if (args_info->noLP_given)
418     write_into_file(outfile, "noLP", 0, 0 );
419   if (args_info->noGU_given)
420     write_into_file(outfile, "noGU", 0, 0 );
421   if (args_info->noClosingGU_given)
422     write_into_file(outfile, "noClosingGU", 0, 0 );
423   if (args_info->paramFile_given)
424     write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
425   if (args_info->binaries_given)
426     write_into_file(outfile, "binaries", 0, 0 );
427   if (args_info->nsp_given)
428     write_into_file(outfile, "nsp", args_info->nsp_orig, 0);
429   if (args_info->energyModel_given)
430     write_into_file(outfile, "energyModel", args_info->energyModel_orig, 0);
431   if (args_info->betaScale_given)
432     write_into_file(outfile, "betaScale", args_info->betaScale_orig, 0);
433   
434
435   i = EXIT_SUCCESS;
436   return i;
437 }
438
439 int
440 RNAplfold_cmdline_parser_file_save(const char *filename, struct RNAplfold_args_info *args_info)
441 {
442   FILE *outfile;
443   int i = 0;
444
445   outfile = fopen(filename, "w");
446
447   if (!outfile)
448     {
449       fprintf (stderr, "%s: cannot open file for writing: %s\n", RNAPLFOLD_CMDLINE_PARSER_PACKAGE, filename);
450       return EXIT_FAILURE;
451     }
452
453   i = RNAplfold_cmdline_parser_dump(outfile, args_info);
454   fclose (outfile);
455
456   return i;
457 }
458
459 void
460 RNAplfold_cmdline_parser_free (struct RNAplfold_args_info *args_info)
461 {
462   RNAplfold_cmdline_parser_release (args_info);
463 }
464
465 /** @brief replacement of strdup, which is not standard */
466 char *
467 gengetopt_strdup (const char *s)
468 {
469   char *result = 0;
470   if (!s)
471     return result;
472
473   result = (char*)malloc(strlen(s) + 1);
474   if (result == (char*)0)
475     return (char*)0;
476   strcpy(result, s);
477   return result;
478 }
479
480 int
481 RNAplfold_cmdline_parser (int argc, char **argv, struct RNAplfold_args_info *args_info)
482 {
483   return RNAplfold_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
484 }
485
486 int
487 RNAplfold_cmdline_parser_ext (int argc, char **argv, struct RNAplfold_args_info *args_info,
488                    struct RNAplfold_cmdline_parser_params *params)
489 {
490   int result;
491   result = RNAplfold_cmdline_parser_internal (argc, argv, args_info, params, 0);
492
493   if (result == EXIT_FAILURE)
494     {
495       RNAplfold_cmdline_parser_free (args_info);
496       exit (EXIT_FAILURE);
497     }
498   
499   return result;
500 }
501
502 int
503 RNAplfold_cmdline_parser2 (int argc, char **argv, struct RNAplfold_args_info *args_info, int override, int initialize, int check_required)
504 {
505   int result;
506   struct RNAplfold_cmdline_parser_params params;
507   
508   params.override = override;
509   params.initialize = initialize;
510   params.check_required = check_required;
511   params.check_ambiguity = 0;
512   params.print_errors = 1;
513
514   result = RNAplfold_cmdline_parser_internal (argc, argv, args_info, &params, 0);
515
516   if (result == EXIT_FAILURE)
517     {
518       RNAplfold_cmdline_parser_free (args_info);
519       exit (EXIT_FAILURE);
520     }
521   
522   return result;
523 }
524
525 int
526 RNAplfold_cmdline_parser_required (struct RNAplfold_args_info *args_info, const char *prog_name)
527 {
528   FIX_UNUSED (args_info);
529   FIX_UNUSED (prog_name);
530   return EXIT_SUCCESS;
531 }
532
533 /*
534  * Extracted from the glibc source tree, version 2.3.6
535  *
536  * Licensed under the GPL as per the whole glibc source tree.
537  *
538  * This file was modified so that getopt_long can be called
539  * many times without risking previous memory to be spoiled.
540  *
541  * Modified by Andre Noll and Lorenzo Bettini for use in
542  * GNU gengetopt generated files.
543  *
544  */
545
546 /* 
547  * we must include anything we need since this file is not thought to be
548  * inserted in a file already using getopt.h
549  *
550  * Lorenzo
551  */
552
553 struct option
554 {
555   const char *name;
556   /* has_arg can't be an enum because some compilers complain about
557      type mismatches in all the code that assumes it is an int.  */
558   int has_arg;
559   int *flag;
560   int val;
561 };
562
563 /* This version of `getopt' appears to the caller like standard Unix `getopt'
564    but it behaves differently for the user, since it allows the user
565    to intersperse the options with the other arguments.
566
567    As `getopt' works, it permutes the elements of ARGV so that,
568    when it is done, all the options precede everything else.  Thus
569    all application programs are extended to handle flexible argument order.
570 */
571 /*
572    If the field `flag' is not NULL, it points to a variable that is set
573    to the value given in the field `val' when the option is found, but
574    left unchanged if the option is not found.
575
576    To have a long-named option do something other than set an `int' to
577    a compiled-in constant, such as set a value from `custom_optarg', set the
578    option's `flag' field to zero and its `val' field to a nonzero
579    value (the equivalent single-letter option character, if there is
580    one).  For long options that have a zero `flag' field, `getopt'
581    returns the contents of the `val' field.  */
582
583 /* Names for the values of the `has_arg' field of `struct option'.  */
584 #ifndef no_argument
585 #define no_argument             0
586 #endif
587
588 #ifndef required_argument
589 #define required_argument       1
590 #endif
591
592 #ifndef optional_argument
593 #define optional_argument       2
594 #endif
595
596 struct custom_getopt_data {
597         /*
598          * These have exactly the same meaning as the corresponding global variables,
599          * except that they are used for the reentrant versions of getopt.
600          */
601         int custom_optind;
602         int custom_opterr;
603         int custom_optopt;
604         char *custom_optarg;
605
606         /* True if the internal members have been initialized.  */
607         int initialized;
608
609         /*
610          * The next char to be scanned in the option-element in which the last option
611          * character we returned was found.  This allows us to pick up the scan where
612          * we left off.  If this is zero, or a null string, it means resume the scan by
613          * advancing to the next ARGV-element.
614          */
615         char *nextchar;
616
617         /*
618          * Describe the part of ARGV that contains non-options that have been skipped.
619          * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
620          * the index after the last of them.
621          */
622         int first_nonopt;
623         int last_nonopt;
624 };
625
626 /*
627  * the variables optarg, optind, opterr and optopt are renamed with
628  * the custom_ prefix so that they don't interfere with getopt ones.
629  *
630  * Moreover they're static so they are visible only from within the
631  * file where this very file will be included.
632  */
633
634 /*
635  * For communication from `custom_getopt' to the caller.  When `custom_getopt' finds an
636  * option that takes an argument, the argument value is returned here.
637  */
638 static char *custom_optarg;
639
640 /*
641  * Index in ARGV of the next element to be scanned.  This is used for
642  * communication to and from the caller and for communication between
643  * successive calls to `custom_getopt'.
644  *
645  * On entry to `custom_getopt', 1 means this is the first call; initialize.
646  *
647  * When `custom_getopt' returns -1, this is the index of the first of the non-option
648  * elements that the caller should itself scan.
649  *
650  * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
651  * has been scanned so far.
652  *
653  * 1003.2 says this must be 1 before any call.
654  */
655 static int custom_optind = 1;
656
657 /*
658  * Callers store zero here to inhibit the error message for unrecognized
659  * options.
660  */
661 static int custom_opterr = 1;
662
663 /*
664  * Set to an option character which was unrecognized.  This must be initialized
665  * on some systems to avoid linking in the system's own getopt implementation.
666  */
667 static int custom_optopt = '?';
668
669 /*
670  * Exchange two adjacent subsequences of ARGV.  One subsequence is elements
671  * [first_nonopt,last_nonopt) which contains all the non-options that have been
672  * skipped so far.  The other is elements [last_nonopt,custom_optind), which contains
673  * all the options processed since those non-options were skipped.
674  * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
675  * indices of the non-options in ARGV after they are moved.
676  */
677 static void exchange(char **argv, struct custom_getopt_data *d)
678 {
679         int bottom = d->first_nonopt;
680         int middle = d->last_nonopt;
681         int top = d->custom_optind;
682         char *tem;
683
684         /*
685          * Exchange the shorter segment with the far end of the longer segment.
686          * That puts the shorter segment into the right place.  It leaves the
687          * longer segment in the right place overall, but it consists of two
688          * parts that need to be swapped next.
689          */
690         while (top > middle && middle > bottom) {
691                 if (top - middle > middle - bottom) {
692                         /* Bottom segment is the short one.  */
693                         int len = middle - bottom;
694                         int i;
695
696                         /* Swap it with the top part of the top segment.  */
697                         for (i = 0; i < len; i++) {
698                                 tem = argv[bottom + i];
699                                 argv[bottom + i] =
700                                         argv[top - (middle - bottom) + i];
701                                 argv[top - (middle - bottom) + i] = tem;
702                         }
703                         /* Exclude the moved bottom segment from further swapping.  */
704                         top -= len;
705                 } else {
706                         /* Top segment is the short one.  */
707                         int len = top - middle;
708                         int i;
709
710                         /* Swap it with the bottom part of the bottom segment.  */
711                         for (i = 0; i < len; i++) {
712                                 tem = argv[bottom + i];
713                                 argv[bottom + i] = argv[middle + i];
714                                 argv[middle + i] = tem;
715                         }
716                         /* Exclude the moved top segment from further swapping.  */
717                         bottom += len;
718                 }
719         }
720         /* Update records for the slots the non-options now occupy.  */
721         d->first_nonopt += (d->custom_optind - d->last_nonopt);
722         d->last_nonopt = d->custom_optind;
723 }
724
725 /* Initialize the internal data when the first call is made.  */
726 static void custom_getopt_initialize(struct custom_getopt_data *d)
727 {
728         /*
729          * Start processing options with ARGV-element 1 (since ARGV-element 0
730          * is the program name); the sequence of previously skipped non-option
731          * ARGV-elements is empty.
732          */
733         d->first_nonopt = d->last_nonopt = d->custom_optind;
734         d->nextchar = NULL;
735         d->initialized = 1;
736 }
737
738 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
739
740 /* return: zero: continue, nonzero: return given value to user */
741 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
742         struct custom_getopt_data *d)
743 {
744         /*
745          * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
746          * moved back by the user (who may also have changed the arguments).
747          */
748         if (d->last_nonopt > d->custom_optind)
749                 d->last_nonopt = d->custom_optind;
750         if (d->first_nonopt > d->custom_optind)
751                 d->first_nonopt = d->custom_optind;
752         /*
753          * If we have just processed some options following some
754          * non-options, exchange them so that the options come first.
755          */
756         if (d->first_nonopt != d->last_nonopt &&
757                         d->last_nonopt != d->custom_optind)
758                 exchange((char **) argv, d);
759         else if (d->last_nonopt != d->custom_optind)
760                 d->first_nonopt = d->custom_optind;
761         /*
762          * Skip any additional non-options and extend the range of
763          * non-options previously skipped.
764          */
765         while (d->custom_optind < argc && NONOPTION_P)
766                 d->custom_optind++;
767         d->last_nonopt = d->custom_optind;
768         /*
769          * The special ARGV-element `--' means premature end of options.  Skip
770          * it like a null option, then exchange with previous non-options as if
771          * it were an option, then skip everything else like a non-option.
772          */
773         if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
774                 d->custom_optind++;
775                 if (d->first_nonopt != d->last_nonopt
776                                 && d->last_nonopt != d->custom_optind)
777                         exchange((char **) argv, d);
778                 else if (d->first_nonopt == d->last_nonopt)
779                         d->first_nonopt = d->custom_optind;
780                 d->last_nonopt = argc;
781                 d->custom_optind = argc;
782         }
783         /*
784          * If we have done all the ARGV-elements, stop the scan and back over
785          * any non-options that we skipped and permuted.
786          */
787         if (d->custom_optind == argc) {
788                 /*
789                  * Set the next-arg-index to point at the non-options that we
790                  * previously skipped, so the caller will digest them.
791                  */
792                 if (d->first_nonopt != d->last_nonopt)
793                         d->custom_optind = d->first_nonopt;
794                 return -1;
795         }
796         /*
797          * If we have come to a non-option and did not permute it, either stop
798          * the scan or describe it to the caller and pass it by.
799          */
800         if (NONOPTION_P) {
801                 d->custom_optarg = argv[d->custom_optind++];
802                 return 1;
803         }
804         /*
805          * We have found another option-ARGV-element. Skip the initial
806          * punctuation.
807          */
808         d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
809         return 0;
810 }
811
812 /*
813  * Check whether the ARGV-element is a long option.
814  *
815  * If there's a long option "fubar" and the ARGV-element is "-fu", consider
816  * that an abbreviation of the long option, just like "--fu", and not "-f" with
817  * arg "u".
818  *
819  * This distinction seems to be the most useful approach.
820  *
821  */
822 static int check_long_opt(int argc, char *const *argv, const char *optstring,
823                 const struct option *longopts, int *longind,
824                 int print_errors, struct custom_getopt_data *d)
825 {
826         char *nameend;
827         const struct option *p;
828         const struct option *pfound = NULL;
829         int exact = 0;
830         int ambig = 0;
831         int indfound = -1;
832         int option_index;
833
834         for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
835                 /* Do nothing.  */ ;
836
837         /* Test all long options for either exact match or abbreviated matches */
838         for (p = longopts, option_index = 0; p->name; p++, option_index++)
839                 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
840                         if ((unsigned int) (nameend - d->nextchar)
841                                         == (unsigned int) strlen(p->name)) {
842                                 /* Exact match found.  */
843                                 pfound = p;
844                                 indfound = option_index;
845                                 exact = 1;
846                                 break;
847                         } else if (pfound == NULL) {
848                                 /* First nonexact match found.  */
849                                 pfound = p;
850                                 indfound = option_index;
851                         } else if (pfound->has_arg != p->has_arg
852                                         || pfound->flag != p->flag
853                                         || pfound->val != p->val)
854                                 /* Second or later nonexact match found.  */
855                                 ambig = 1;
856                 }
857         if (ambig && !exact) {
858                 if (print_errors) {
859                         fprintf(stderr,
860                                 "%s: option `%s' is ambiguous\n",
861                                 argv[0], argv[d->custom_optind]);
862                 }
863                 d->nextchar += strlen(d->nextchar);
864                 d->custom_optind++;
865                 d->custom_optopt = 0;
866                 return '?';
867         }
868         if (pfound) {
869                 option_index = indfound;
870                 d->custom_optind++;
871                 if (*nameend) {
872                         if (pfound->has_arg != no_argument)
873                                 d->custom_optarg = nameend + 1;
874                         else {
875                                 if (print_errors) {
876                                         if (argv[d->custom_optind - 1][1] == '-') {
877                                                 /* --option */
878                                                 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
879                                                         argv[0], pfound->name);
880                                         } else {
881                                                 /* +option or -option */
882                                                 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
883                                                         argv[0], argv[d->custom_optind - 1][0], pfound->name);
884                                         }
885
886                                 }
887                                 d->nextchar += strlen(d->nextchar);
888                                 d->custom_optopt = pfound->val;
889                                 return '?';
890                         }
891                 } else if (pfound->has_arg == required_argument) {
892                         if (d->custom_optind < argc)
893                                 d->custom_optarg = argv[d->custom_optind++];
894                         else {
895                                 if (print_errors) {
896                                         fprintf(stderr,
897                                                 "%s: option `%s' requires an argument\n",
898                                                 argv[0],
899                                                 argv[d->custom_optind - 1]);
900                                 }
901                                 d->nextchar += strlen(d->nextchar);
902                                 d->custom_optopt = pfound->val;
903                                 return optstring[0] == ':' ? ':' : '?';
904                         }
905                 }
906                 d->nextchar += strlen(d->nextchar);
907                 if (longind != NULL)
908                         *longind = option_index;
909                 if (pfound->flag) {
910                         *(pfound->flag) = pfound->val;
911                         return 0;
912                 }
913                 return pfound->val;
914         }
915         /*
916          * Can't find it as a long option.  If this is not getopt_long_only, or
917          * the option starts with '--' or is not a valid short option, then
918          * it's an error.  Otherwise interpret it as a short option.
919          */
920         if (print_errors) {
921                 if (argv[d->custom_optind][1] == '-') {
922                         /* --option */
923                         fprintf(stderr,
924                                 "%s: unrecognized option `--%s'\n",
925                                 argv[0], d->nextchar);
926                 } else {
927                         /* +option or -option */
928                         fprintf(stderr,
929                                 "%s: unrecognized option `%c%s'\n",
930                                 argv[0], argv[d->custom_optind][0],
931                                 d->nextchar);
932                 }
933         }
934         d->nextchar = (char *) "";
935         d->custom_optind++;
936         d->custom_optopt = 0;
937         return '?';
938 }
939
940 static int check_short_opt(int argc, char *const *argv, const char *optstring,
941                 int print_errors, struct custom_getopt_data *d)
942 {
943         char c = *d->nextchar++;
944         const char *temp = strchr(optstring, c);
945
946         /* Increment `custom_optind' when we start to process its last character.  */
947         if (*d->nextchar == '\0')
948                 ++d->custom_optind;
949         if (!temp || c == ':') {
950                 if (print_errors)
951                         fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
952
953                 d->custom_optopt = c;
954                 return '?';
955         }
956         if (temp[1] == ':') {
957                 if (temp[2] == ':') {
958                         /* This is an option that accepts an argument optionally.  */
959                         if (*d->nextchar != '\0') {
960                                 d->custom_optarg = d->nextchar;
961                                 d->custom_optind++;
962                         } else
963                                 d->custom_optarg = NULL;
964                         d->nextchar = NULL;
965                 } else {
966                         /* This is an option that requires an argument.  */
967                         if (*d->nextchar != '\0') {
968                                 d->custom_optarg = d->nextchar;
969                                 /*
970                                  * If we end this ARGV-element by taking the
971                                  * rest as an arg, we must advance to the next
972                                  * element now.
973                                  */
974                                 d->custom_optind++;
975                         } else if (d->custom_optind == argc) {
976                                 if (print_errors) {
977                                         fprintf(stderr,
978                                                 "%s: option requires an argument -- %c\n",
979                                                 argv[0], c);
980                                 }
981                                 d->custom_optopt = c;
982                                 if (optstring[0] == ':')
983                                         c = ':';
984                                 else
985                                         c = '?';
986                         } else
987                                 /*
988                                  * We already incremented `custom_optind' once;
989                                  * increment it again when taking next ARGV-elt
990                                  * as argument.
991                                  */
992                                 d->custom_optarg = argv[d->custom_optind++];
993                         d->nextchar = NULL;
994                 }
995         }
996         return c;
997 }
998
999 /*
1000  * Scan elements of ARGV for option characters given in OPTSTRING.
1001  *
1002  * If an element of ARGV starts with '-', and is not exactly "-" or "--",
1003  * then it is an option element.  The characters of this element
1004  * (aside from the initial '-') are option characters.  If `getopt'
1005  * is called repeatedly, it returns successively each of the option characters
1006  * from each of the option elements.
1007  *
1008  * If `getopt' finds another option character, it returns that character,
1009  * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
1010  * resume the scan with the following option character or ARGV-element.
1011  *
1012  * If there are no more option characters, `getopt' returns -1.
1013  * Then `custom_optind' is the index in ARGV of the first ARGV-element
1014  * that is not an option.  (The ARGV-elements have been permuted
1015  * so that those that are not options now come last.)
1016  *
1017  * OPTSTRING is a string containing the legitimate option characters.
1018  * If an option character is seen that is not listed in OPTSTRING,
1019  * return '?' after printing an error message.  If you set `custom_opterr' to
1020  * zero, the error message is suppressed but we still return '?'.
1021  *
1022  * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
1023  * so the following text in the same ARGV-element, or the text of the following
1024  * ARGV-element, is returned in `custom_optarg'.  Two colons mean an option that
1025  * wants an optional arg; if there is text in the current ARGV-element,
1026  * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
1027  *
1028  * If OPTSTRING starts with `-' or `+', it requests different methods of
1029  * handling the non-option ARGV-elements.
1030  * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
1031  *
1032  * Long-named options begin with `--' instead of `-'.
1033  * Their names may be abbreviated as long as the abbreviation is unique
1034  * or is an exact match for some defined option.  If they have an
1035  * argument, it follows the option name in the same ARGV-element, separated
1036  * from the option name by a `=', or else the in next ARGV-element.
1037  * When `getopt' finds a long-named option, it returns 0 if that option's
1038  * `flag' field is nonzero, the value of the option's `val' field
1039  * if the `flag' field is zero.
1040  *
1041  * The elements of ARGV aren't really const, because we permute them.
1042  * But we pretend they're const in the prototype to be compatible
1043  * with other systems.
1044  *
1045  * LONGOPTS is a vector of `struct option' terminated by an
1046  * element containing a name which is zero.
1047  *
1048  * LONGIND returns the index in LONGOPT of the long-named option found.
1049  * It is only valid when a long-named option has been found by the most
1050  * recent call.
1051  *
1052  * Return the option character from OPTS just read.  Return -1 when there are
1053  * no more options.  For unrecognized options, or options missing arguments,
1054  * `custom_optopt' is set to the option letter, and '?' is returned.
1055  *
1056  * The OPTS string is a list of characters which are recognized option letters,
1057  * optionally followed by colons, specifying that that letter takes an
1058  * argument, to be placed in `custom_optarg'.
1059  *
1060  * If a letter in OPTS is followed by two colons, its argument is optional.
1061  * This behavior is specific to the GNU `getopt'.
1062  *
1063  * The argument `--' causes premature termination of argument scanning,
1064  * explicitly telling `getopt' that there are no more options.  If OPTS begins
1065  * with `--', then non-option arguments are treated as arguments to the option
1066  * '\0'.  This behavior is specific to the GNU `getopt'.
1067  */
1068
1069 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1070                 const struct option *longopts, int *longind,
1071                 struct custom_getopt_data *d)
1072 {
1073         int ret, print_errors = d->custom_opterr;
1074
1075         if (optstring[0] == ':')
1076                 print_errors = 0;
1077         if (argc < 1)
1078                 return -1;
1079         d->custom_optarg = NULL;
1080
1081         /* 
1082          * This is a big difference with GNU getopt, since optind == 0
1083          * means initialization while here 1 means first call.
1084          */
1085         if (d->custom_optind == 0 || !d->initialized) {
1086                 if (d->custom_optind == 0)
1087                         d->custom_optind = 1;   /* Don't scan ARGV[0], the program name.  */
1088                 custom_getopt_initialize(d);
1089         }
1090         if (d->nextchar == NULL || *d->nextchar == '\0') {
1091                 ret = shuffle_argv(argc, argv, longopts, d);
1092                 if (ret)
1093                         return ret;
1094         }
1095         if (longopts && (argv[d->custom_optind][1] == '-' ))
1096                 return check_long_opt(argc, argv, optstring, longopts,
1097                         longind, print_errors, d);
1098         return check_short_opt(argc, argv, optstring, print_errors, d);
1099 }
1100
1101 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1102         const struct option *longopts, int *longind)
1103 {
1104         int result;
1105         /* Keep a global copy of all internal members of d */
1106         static struct custom_getopt_data d;
1107
1108         d.custom_optind = custom_optind;
1109         d.custom_opterr = custom_opterr;
1110         result = getopt_internal_r(argc, argv, optstring, longopts,
1111                 longind, &d);
1112         custom_optind = d.custom_optind;
1113         custom_optarg = d.custom_optarg;
1114         custom_optopt = d.custom_optopt;
1115         return result;
1116 }
1117
1118 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1119         const struct option *long_options, int *opt_index)
1120 {
1121         return custom_getopt_internal(argc, argv, options, long_options,
1122                 opt_index);
1123 }
1124
1125
1126 static char *package_name = 0;
1127
1128 /**
1129  * @brief updates an option
1130  * @param field the generic pointer to the field to update
1131  * @param orig_field the pointer to the orig field
1132  * @param field_given the pointer to the number of occurrence of this option
1133  * @param prev_given the pointer to the number of occurrence already seen
1134  * @param value the argument for this option (if null no arg was specified)
1135  * @param possible_values the possible values for this option (if specified)
1136  * @param default_value the default value (in case the option only accepts fixed values)
1137  * @param arg_type the type of this option
1138  * @param check_ambiguity @see RNAplfold_cmdline_parser_params.check_ambiguity
1139  * @param override @see RNAplfold_cmdline_parser_params.override
1140  * @param no_free whether to free a possible previous value
1141  * @param multiple_option whether this is a multiple option
1142  * @param long_opt the corresponding long option
1143  * @param short_opt the corresponding short option (or '-' if none)
1144  * @param additional_error possible further error specification
1145  */
1146 static
1147 int update_arg(void *field, char **orig_field,
1148                unsigned int *field_given, unsigned int *prev_given, 
1149                char *value, const char *possible_values[],
1150                const char *default_value,
1151                RNAplfold_cmdline_parser_arg_type arg_type,
1152                int check_ambiguity, int override,
1153                int no_free, int multiple_option,
1154                const char *long_opt, char short_opt,
1155                const char *additional_error)
1156 {
1157   char *stop_char = 0;
1158   const char *val = value;
1159   int found;
1160   char **string_field;
1161   FIX_UNUSED (field);
1162
1163   stop_char = 0;
1164   found = 0;
1165
1166   if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1167     {
1168       if (short_opt != '-')
1169         fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", 
1170                package_name, long_opt, short_opt,
1171                (additional_error ? additional_error : ""));
1172       else
1173         fprintf (stderr, "%s: `--%s' option given more than once%s\n", 
1174                package_name, long_opt,
1175                (additional_error ? additional_error : ""));
1176       return 1; /* failure */
1177     }
1178
1179   FIX_UNUSED (default_value);
1180     
1181   if (field_given && *field_given && ! override)
1182     return 0;
1183   if (prev_given)
1184     (*prev_given)++;
1185   if (field_given)
1186     (*field_given)++;
1187   if (possible_values)
1188     val = possible_values[found];
1189
1190   switch(arg_type) {
1191   case ARG_FLAG:
1192     *((int *)field) = !*((int *)field);
1193     break;
1194   case ARG_INT:
1195     if (val) *((int *)field) = strtol (val, &stop_char, 0);
1196     break;
1197   case ARG_FLOAT:
1198     if (val) *((float *)field) = (float)strtod (val, &stop_char);
1199     break;
1200   case ARG_DOUBLE:
1201     if (val) *((double *)field) = strtod (val, &stop_char);
1202     break;
1203   case ARG_STRING:
1204     if (val) {
1205       string_field = (char **)field;
1206       if (!no_free && *string_field)
1207         free (*string_field); /* free previous string */
1208       *string_field = gengetopt_strdup (val);
1209     }
1210     break;
1211   default:
1212     break;
1213   };
1214
1215   /* check numeric conversion */
1216   switch(arg_type) {
1217   case ARG_INT:
1218   case ARG_FLOAT:
1219   case ARG_DOUBLE:
1220     if (val && !(stop_char && *stop_char == '\0')) {
1221       fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1222       return 1; /* failure */
1223     }
1224     break;
1225   default:
1226     ;
1227   };
1228
1229   /* store the original value */
1230   switch(arg_type) {
1231   case ARG_NO:
1232   case ARG_FLAG:
1233     break;
1234   default:
1235     if (value && orig_field) {
1236       if (no_free) {
1237         *orig_field = value;
1238       } else {
1239         if (*orig_field)
1240           free (*orig_field); /* free previous string */
1241         *orig_field = gengetopt_strdup (value);
1242       }
1243     }
1244   };
1245
1246   return 0; /* OK */
1247 }
1248
1249
1250 int
1251 RNAplfold_cmdline_parser_internal (
1252   int argc, char **argv, struct RNAplfold_args_info *args_info,
1253                         struct RNAplfold_cmdline_parser_params *params, const char *additional_error)
1254 {
1255   int c;        /* Character of the parsed option.  */
1256
1257   int error = 0;
1258   struct RNAplfold_args_info local_args_info;
1259   
1260   int override;
1261   int initialize;
1262   int check_required;
1263   int check_ambiguity;
1264
1265   char *optarg;
1266   int optind;
1267   int opterr;
1268   int optopt;
1269   
1270   package_name = argv[0];
1271   
1272   override = params->override;
1273   initialize = params->initialize;
1274   check_required = params->check_required;
1275   check_ambiguity = params->check_ambiguity;
1276
1277   if (initialize)
1278     RNAplfold_cmdline_parser_init (args_info);
1279
1280   RNAplfold_cmdline_parser_init (&local_args_info);
1281
1282   optarg = 0;
1283   optind = 0;
1284   opterr = params->print_errors;
1285   optopt = '?';
1286
1287   while (1)
1288     {
1289       int option_index = 0;
1290
1291       static struct option long_options[] = {
1292         { "help",       0, NULL, 'h' },
1293         { "detailed-help",      0, NULL, 0 },
1294         { "full-help",  0, NULL, 0 },
1295         { "version",    0, NULL, 'V' },
1296         { "winsize",    1, NULL, 'W' },
1297         { "span",       1, NULL, 'L' },
1298         { "cutoff",     1, NULL, 'c' },
1299         { "print_onthefly",     0, NULL, 'o' },
1300         { "ulength",    1, NULL, 'u' },
1301         { "opening_energies",   0, NULL, 'O' },
1302         { "plex_output",        0, NULL, 0 },
1303         { "noconv",     0, NULL, 0 },
1304         { "temp",       1, NULL, 'T' },
1305         { "noTetra",    0, NULL, '4' },
1306         { "dangles",    1, NULL, 'd' },
1307         { "noLP",       0, NULL, 0 },
1308         { "noGU",       0, NULL, 0 },
1309         { "noClosingGU",        0, NULL, 0 },
1310         { "paramFile",  1, NULL, 'P' },
1311         { "binaries",   0, NULL, 'b' },
1312         { "nsp",        1, NULL, 0 },
1313         { "energyModel",        1, NULL, 'e' },
1314         { "betaScale",  1, NULL, 0 },
1315         { 0,  0, 0, 0 }
1316       };
1317
1318       custom_optarg = optarg;
1319       custom_optind = optind;
1320       custom_opterr = opterr;
1321       custom_optopt = optopt;
1322
1323       c = custom_getopt_long (argc, argv, "hVW:L:c:ou:OT:4d:P:be:", long_options, &option_index);
1324
1325       optarg = custom_optarg;
1326       optind = custom_optind;
1327       opterr = custom_opterr;
1328       optopt = custom_optopt;
1329
1330       if (c == -1) break;       /* Exit from `while (1)' loop.  */
1331
1332       switch (c)
1333         {
1334         case 'h':       /* Print help and exit.  */
1335           RNAplfold_cmdline_parser_print_help ();
1336           RNAplfold_cmdline_parser_free (&local_args_info);
1337           exit (EXIT_SUCCESS);
1338
1339         case 'V':       /* Print version and exit.  */
1340           RNAplfold_cmdline_parser_print_version ();
1341           RNAplfold_cmdline_parser_free (&local_args_info);
1342           exit (EXIT_SUCCESS);
1343
1344         case 'W':       /* Average the pair probabilities over windows of given size
1345         
1346 .  */
1347         
1348         
1349           if (update_arg( (void *)&(args_info->winsize_arg), 
1350                &(args_info->winsize_orig), &(args_info->winsize_given),
1351               &(local_args_info.winsize_given), optarg, 0, "70", ARG_INT,
1352               check_ambiguity, override, 0, 0,
1353               "winsize", 'W',
1354               additional_error))
1355             goto failure;
1356         
1357           break;
1358         case 'L':       /* Set the maximum allowed separation of a base pair to span. I.e. no pairs (i,j) with j-i > span will be allowed. Defaults to winsize if parameter is omitted
1359         
1360 .  */
1361         
1362         
1363           if (update_arg( (void *)&(args_info->span_arg), 
1364                &(args_info->span_orig), &(args_info->span_given),
1365               &(local_args_info.span_given), optarg, 0, 0, ARG_INT,
1366               check_ambiguity, override, 0, 0,
1367               "span", 'L',
1368               additional_error))
1369             goto failure;
1370         
1371           break;
1372         case 'c':       /* Report only base pairs with an average probability > cutoff in the dot plot
1373         
1374 .  */
1375         
1376         
1377           if (update_arg( (void *)&(args_info->cutoff_arg), 
1378                &(args_info->cutoff_orig), &(args_info->cutoff_given),
1379               &(local_args_info.cutoff_given), optarg, 0, "0.01", ARG_FLOAT,
1380               check_ambiguity, override, 0, 0,
1381               "cutoff", 'c',
1382               additional_error))
1383             goto failure;
1384         
1385           break;
1386         case 'o':       /* Save memory by printing out everything during computation.
1387         NOTE: activated per default for sequences over 1M bp.
1388         
1389 .  */
1390         
1391         
1392           if (update_arg((void *)&(args_info->print_onthefly_flag), 0, &(args_info->print_onthefly_given),
1393               &(local_args_info.print_onthefly_given), optarg, 0, 0, ARG_FLAG,
1394               check_ambiguity, override, 1, 0, "print_onthefly", 'o',
1395               additional_error))
1396             goto failure;
1397         
1398           break;
1399         case 'u':       /* Compute the mean probability that regions of length 1 to a given length are unpaired. Output is saved in a _lunp file.
1400         
1401 .  */
1402         
1403         
1404           if (update_arg( (void *)&(args_info->ulength_arg), 
1405                &(args_info->ulength_orig), &(args_info->ulength_given),
1406               &(local_args_info.ulength_given), optarg, 0, "31", ARG_INT,
1407               check_ambiguity, override, 0, 0,
1408               "ulength", 'u',
1409               additional_error))
1410             goto failure;
1411         
1412           break;
1413         case 'O':       /* Switch output from probabilities to their logarithms, which are NOT exactly the mean energies needed to the respective stretch of bases!
1414         NOTE: This actives -u option.
1415         
1416 .  */
1417         
1418         
1419           if (update_arg((void *)&(args_info->opening_energies_flag), 0, &(args_info->opening_energies_given),
1420               &(local_args_info.opening_energies_given), optarg, 0, 0, ARG_FLAG,
1421               check_ambiguity, override, 1, 0, "opening_energies", 'O',
1422               additional_error))
1423             goto failure;
1424         
1425           break;
1426         case 'T':       /* Rescale energy parameters to a temperature of temp C. Default is 37C.
1427         
1428 .  */
1429         
1430         
1431           if (update_arg( (void *)&(args_info->temp_arg), 
1432                &(args_info->temp_orig), &(args_info->temp_given),
1433               &(local_args_info.temp_given), optarg, 0, 0, ARG_DOUBLE,
1434               check_ambiguity, override, 0, 0,
1435               "temp", 'T',
1436               additional_error))
1437             goto failure;
1438         
1439           break;
1440         case '4':       /* Do not include special tabulated stabilizing energies for tri-, tetra- and hexaloop hairpins. Mostly for testing.
1441         
1442 .  */
1443         
1444         
1445           if (update_arg((void *)&(args_info->noTetra_flag), 0, &(args_info->noTetra_given),
1446               &(local_args_info.noTetra_given), optarg, 0, 0, ARG_FLAG,
1447               check_ambiguity, override, 1, 0, "noTetra", '4',
1448               additional_error))
1449             goto failure;
1450         
1451           break;
1452         case 'd':       /* How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops
1453 .  */
1454         
1455         
1456           if (update_arg( (void *)&(args_info->dangles_arg), 
1457                &(args_info->dangles_orig), &(args_info->dangles_given),
1458               &(local_args_info.dangles_given), optarg, 0, "2", ARG_INT,
1459               check_ambiguity, override, 0, 0,
1460               "dangles", 'd',
1461               additional_error))
1462             goto failure;
1463         
1464           break;
1465         case 'P':       /* Read energy parameters from paramfile, instead of using the default parameter set.
1466 .  */
1467         
1468         
1469           if (update_arg( (void *)&(args_info->paramFile_arg), 
1470                &(args_info->paramFile_orig), &(args_info->paramFile_given),
1471               &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1472               check_ambiguity, override, 0, 0,
1473               "paramFile", 'P',
1474               additional_error))
1475             goto failure;
1476         
1477           break;
1478         case 'b':       /* Output accessibility profiles in binary format
1479         ..  */
1480         
1481         
1482           if (update_arg((void *)&(args_info->binaries_flag), 0, &(args_info->binaries_given),
1483               &(local_args_info.binaries_given), optarg, 0, 0, ARG_FLAG,
1484               check_ambiguity, override, 1, 0, "binaries", 'b',
1485               additional_error))
1486             goto failure;
1487         
1488           break;
1489         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.
1490         
1491 .  */
1492         
1493         
1494           if (update_arg( (void *)&(args_info->energyModel_arg), 
1495                &(args_info->energyModel_orig), &(args_info->energyModel_given),
1496               &(local_args_info.energyModel_given), optarg, 0, 0, ARG_INT,
1497               check_ambiguity, override, 0, 0,
1498               "energyModel", 'e',
1499               additional_error))
1500             goto failure;
1501         
1502           break;
1503
1504         case 0: /* Long option with no short option */
1505           if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1506             RNAplfold_cmdline_parser_print_detailed_help ();
1507             RNAplfold_cmdline_parser_free (&local_args_info);
1508             exit (EXIT_SUCCESS);
1509           }
1510
1511           if (strcmp (long_options[option_index].name, "full-help") == 0) {
1512             RNAplfold_cmdline_parser_print_full_help ();
1513             RNAplfold_cmdline_parser_free (&local_args_info);
1514             exit (EXIT_SUCCESS);
1515           }
1516
1517           /* Create additional output files for RNAplex.
1518           
1519 .  */
1520           if (strcmp (long_options[option_index].name, "plex_output") == 0)
1521           {
1522           
1523           
1524             if (update_arg((void *)&(args_info->plex_output_flag), 0, &(args_info->plex_output_given),
1525                 &(local_args_info.plex_output_given), optarg, 0, 0, ARG_FLAG,
1526                 check_ambiguity, override, 1, 0, "plex_output", '-',
1527                 additional_error))
1528               goto failure;
1529           
1530           }
1531           /* Do not automatically substitude nucleotide \"T\" with \"U\"
1532           
1533 .  */
1534           else if (strcmp (long_options[option_index].name, "noconv") == 0)
1535           {
1536           
1537           
1538             if (update_arg((void *)&(args_info->noconv_flag), 0, &(args_info->noconv_given),
1539                 &(local_args_info.noconv_given), optarg, 0, 0, ARG_FLAG,
1540                 check_ambiguity, override, 1, 0, "noconv", '-',
1541                 additional_error))
1542               goto failure;
1543           
1544           }
1545           /* Produce structures without lonely pairs (helices of length 1).
1546 .  */
1547           else if (strcmp (long_options[option_index].name, "noLP") == 0)
1548           {
1549           
1550           
1551             if (update_arg((void *)&(args_info->noLP_flag), 0, &(args_info->noLP_given),
1552                 &(local_args_info.noLP_given), optarg, 0, 0, ARG_FLAG,
1553                 check_ambiguity, override, 1, 0, "noLP", '-',
1554                 additional_error))
1555               goto failure;
1556           
1557           }
1558           /* Do not allow GU pairs
1559           
1560 .  */
1561           else if (strcmp (long_options[option_index].name, "noGU") == 0)
1562           {
1563           
1564           
1565             if (update_arg((void *)&(args_info->noGU_flag), 0, &(args_info->noGU_given),
1566                 &(local_args_info.noGU_given), optarg, 0, 0, ARG_FLAG,
1567                 check_ambiguity, override, 1, 0, "noGU", '-',
1568                 additional_error))
1569               goto failure;
1570           
1571           }
1572           /* Do not allow GU pairs at the end of helices
1573           
1574 .  */
1575           else if (strcmp (long_options[option_index].name, "noClosingGU") == 0)
1576           {
1577           
1578           
1579             if (update_arg((void *)&(args_info->noClosingGU_flag), 0, &(args_info->noClosingGU_given),
1580                 &(local_args_info.noClosingGU_given), optarg, 0, 0, ARG_FLAG,
1581                 check_ambiguity, override, 1, 0, "noClosingGU", '-',
1582                 additional_error))
1583               goto failure;
1584           
1585           }
1586           /* Allow other pairs in addition to the usual AU,GC,and GU pairs.
1587 .  */
1588           else if (strcmp (long_options[option_index].name, "nsp") == 0)
1589           {
1590           
1591           
1592             if (update_arg( (void *)&(args_info->nsp_arg), 
1593                  &(args_info->nsp_orig), &(args_info->nsp_given),
1594                 &(local_args_info.nsp_given), optarg, 0, 0, ARG_STRING,
1595                 check_ambiguity, override, 0, 0,
1596                 "nsp", '-',
1597                 additional_error))
1598               goto failure;
1599           
1600           }
1601           /* Set the scaling of the Boltzmann factors
1602 .  */
1603           else if (strcmp (long_options[option_index].name, "betaScale") == 0)
1604           {
1605           
1606           
1607             if (update_arg( (void *)&(args_info->betaScale_arg), 
1608                  &(args_info->betaScale_orig), &(args_info->betaScale_given),
1609                 &(local_args_info.betaScale_given), optarg, 0, "1.", ARG_DOUBLE,
1610                 check_ambiguity, override, 0, 0,
1611                 "betaScale", '-',
1612                 additional_error))
1613               goto failure;
1614           
1615           }
1616           
1617           break;
1618         case '?':       /* Invalid option.  */
1619           /* `getopt_long' already printed an error message.  */
1620           goto failure;
1621
1622         default:        /* bug: option not considered.  */
1623           fprintf (stderr, "%s: option unknown: %c%s\n", RNAPLFOLD_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1624           abort ();
1625         } /* switch */
1626     } /* while */
1627
1628
1629
1630
1631   RNAplfold_cmdline_parser_release (&local_args_info);
1632
1633   if ( error )
1634     return (EXIT_FAILURE);
1635
1636   return 0;
1637
1638 failure:
1639   
1640   RNAplfold_cmdline_parser_release (&local_args_info);
1641   return (EXIT_FAILURE);
1642 }