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