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