New Linux binaries for ViennaRNA
[jabaws.git] / binaries / src / ViennaRNA / Progs / RNAup_cmdl.c
1 /*
2   File autogenerated by gengetopt version 2.22.5
3   generated with the following command:
4   gengetopt -i RNAup.ggo --file-name=RNAup_cmdl --include-getopt --default-optional --func-name=RNAup_cmdline_parser --arg-struct-name=RNAup_args_info
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 "RNAup_cmdl.h"
26
27 const char *RNAup_args_info_purpose = "Calculate the thermodynamics of RNA-RNA interactions";
28
29 const char *RNAup_args_info_usage = "Usage: RNAup [OPTIONS]...";
30
31 const char *RNAup_args_info_description = "RNAup calculates the thermodynamics of RNA-RNA interactions, by decomposing the \nbinding into two stages. (1) First the probability that a potential binding \nsites remains unpaired (equivalent to the free energy needed to open the site) \nis computed. (2) Then this accessibility is combined with the interaction \nenergy to obtain the total binding energy. All calculations are done by \ncomputing partition functions over all possible conformations.\n";
32
33 const char *RNAup_args_info_detailed_help[] = {
34   "  -h, --help                  Print help and exit",
35   "      --detailed-help         Print help, including all details and hidden \n                                options, and exit",
36   "      --full-help             Print help, including hidden options, and exit",
37   "  -V, --version               Print version and exit",
38   "\nGeneral Options:",
39   "  Below are command line options which alter the general behavior of this \n  program\n",
40   "  -C, --constraint            Calculate structures subject to constraints.\n                                  (default=off)",
41   "  The program reads first the sequence(s), then a string containing constraints \n  on the structure encoded with the symbols:\n   . (no constraint for this base)\n\n   x (the base is unpaired)\n   < (base i is paired with a base j>i) (solely used for calculation of \n  unpaired regions)\n   > (base i is paired with a base j<i) (solely used for calculation of \n  unpaired regions)\n   ( ) (base i pairs base j)\n   | (the corresponding base has to be paired intermolecularily (works only in \n  interaction mode)\n\n",
42   "  -o, --no_output_file        Do not produce an output file\n\n                                  (default=off)",
43   "      --no_header             Do not produce a header with the command line \n                                parameters used in the outputfile\n\n                                  (default=off)",
44   "      --noconv                Do not automatically substitude nucleotide \"T\" \n                                with \"U\"\n\n                                  (default=off)",
45   "\nCalculations of opening energies:",
46   "  -u, --ulength=length        specifies the length of the unstructured region \n                                in the output.\n                                  (default=`4')",
47   "  The probability of being unpaired is plotted on the right border of the \n  unpaired region. You can specify up to 20 different length values: use \"-\" \n  to specify a range of continuous values (e.g. -u 4-8) or specify a list of \n  comma separated values (e.g. -u 4,8,15).\n\n",
48   "  -c, --contributions=SHIME   Specify the contributions listed in the output\n                                  (default=`S')",
49   "  By default only the full probability of being unpaired is plotted. The -c \n  option allows to get the different contributions (c) to the probability of \n  being unpaired: The full probability of being unpaired (\"S\" is the sum of \n  the probability of being unpaired in the exterior loop (\"E\"), within a \n  hairpin loop (\"H\"), within an interior loop (\"I\") and within a multiloop \n  (\"M\"). Any combination of these letters may be given.\n\n",
50   "\nCalculations of RNA-RNA interactions:",
51   "  -w, --window=INT            Determine the maximal length of the region of \n                                interaction\n\n                                  (default=`25')",
52   "  -b, --include_both          Include the probability of unpaired regions in \n                                both (b) RNAs. By default\n                                only the probability of being unpaired in the \n                                longer RNA (target) is used.\n\n                                  (default=off)",
53   "  -5, --extend5=INT           Extend the region of interaction in the target to \n                                some residues on the 5' side\n",
54   "  The underlying assumption is that it is favorable for an interaction if not \n  only the direct region of contact is unpaired but also a few residues 5'\n\n",
55   "  -3, --extend3=INT           Extend the region of interaction in the target to \n                                some residues on the 3' side\n",
56   "  The underlying assumption is that it is favorable for an interaction if not \n  only the direct region of contact is unpaired but also a few residues 3'\n\n",
57   "      --interaction_pairwise  Activate pairwise interaction mode\n                                  (default=off)",
58   "  The first sequence interacts with the 2nd, the third with the 4th etc. If \n  activated, two interacting sequences may be given in a single line separated \n  by \"&\" or each sequence may be given on an extra line.\n\n",
59   "      --interaction_first     Activate interaction mode using first sequence \n                                only\n                                  (default=off)",
60   "  The interaction of each sequence with the first one is calculated (e.g. \n  interaction of one mRNA with many small RNAs). Each sequence has to be given \n  on an extra line\n\n",
61   "\nModel Details:",
62   "  -S, --pfScale=DOUBLE        In the calculation of the pf use scale*mfe as an \n                                estimate for the ensemble free energy (used to \n                                avoid overflows). The default is 1.07, useful \n                                values are 1.0 to 1.2. Occasionally needed for \n                                long sequences.\n                                You can also recompile the program to use \n                                double precision (see the README file).\n\n",
63   "  -T, --temp=DOUBLE           Rescale energy parameters to a temperature of \n                                temp C. Default is 37C.\n\n",
64   "  -4, --noTetra               Do not include special tabulated stabilizing \n                                energies for tri-, tetra- and hexaloop \n                                hairpins. Mostly for testing.\n\n                                  (default=off)",
65   "  -d, --dangles=INT           How to treat \"dangling end\" energies for bases \n                                adjacent to helices in free ends and \n                                multi-loops\n                                  (default=`2')",
66   "  \n  With -d2 dangling energies will be added for the bases adjacent to a helix on \n  both sides in any case.\n   The option -d0 ignores dangling ends altogether (mostly for debugging).\n\n",
67   "      --noLP                  Produce structures without lonely pairs (helices \n                                of length 1).\n                                  (default=off)",
68   "  For partition function folding this only disallows pairs that can only occur \n  isolated. Other pairs may still occasionally occur as helices of length 1.\n\n",
69   "      --noGU                  Do not allow GU pairs\n\n                                  (default=off)",
70   "      --noClosingGU           Do not allow GU pairs at the end of helices\n\n                                  (default=off)",
71   "  -P, --paramFile=paramfile   Read energy parameters from paramfile, instead of \n                                using the default parameter set.\n",
72   "  A sample parameter file should accompany your distribution.\n  See the RNAlib documentation for details on the file format.\n\n",
73   "      --nsp=STRING            Allow other pairs in addition to the usual \n                                AU,GC,and GU pairs.\n",
74   "  Its argument is a comma separated list of additionally allowed pairs. If the \n  first character is a \"-\" then AB will imply that AB and BA are allowed \n  pairs.\n  e.g. RNAfold -nsp -GA  will allow GA and AG pairs. Nonstandard pairs are \n  given 0 stacking energy.\n\n",
75   "  -e, --energyModel=INT       Rarely used option to fold sequences from the \n                                artificial ABCD... alphabet, where A pairs B, \n                                C-D etc.  Use the energy parameters for GC (-e \n                                1) or AU (-e 2) pairs.\n\n",
76   "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
77     0
78 };
79 static void
80 init_full_help_array(void)
81 {
82   RNAup_args_info_full_help[0] = RNAup_args_info_detailed_help[0];
83   RNAup_args_info_full_help[1] = RNAup_args_info_detailed_help[1];
84   RNAup_args_info_full_help[2] = RNAup_args_info_detailed_help[2];
85   RNAup_args_info_full_help[3] = RNAup_args_info_detailed_help[3];
86   RNAup_args_info_full_help[4] = RNAup_args_info_detailed_help[4];
87   RNAup_args_info_full_help[5] = RNAup_args_info_detailed_help[5];
88   RNAup_args_info_full_help[6] = RNAup_args_info_detailed_help[6];
89   RNAup_args_info_full_help[7] = RNAup_args_info_detailed_help[8];
90   RNAup_args_info_full_help[8] = RNAup_args_info_detailed_help[9];
91   RNAup_args_info_full_help[9] = RNAup_args_info_detailed_help[10];
92   RNAup_args_info_full_help[10] = RNAup_args_info_detailed_help[11];
93   RNAup_args_info_full_help[11] = RNAup_args_info_detailed_help[12];
94   RNAup_args_info_full_help[12] = RNAup_args_info_detailed_help[14];
95   RNAup_args_info_full_help[13] = RNAup_args_info_detailed_help[16];
96   RNAup_args_info_full_help[14] = RNAup_args_info_detailed_help[17];
97   RNAup_args_info_full_help[15] = RNAup_args_info_detailed_help[18];
98   RNAup_args_info_full_help[16] = RNAup_args_info_detailed_help[19];
99   RNAup_args_info_full_help[17] = RNAup_args_info_detailed_help[21];
100   RNAup_args_info_full_help[18] = RNAup_args_info_detailed_help[23];
101   RNAup_args_info_full_help[19] = RNAup_args_info_detailed_help[25];
102   RNAup_args_info_full_help[20] = RNAup_args_info_detailed_help[27];
103   RNAup_args_info_full_help[21] = RNAup_args_info_detailed_help[28];
104   RNAup_args_info_full_help[22] = RNAup_args_info_detailed_help[29];
105   RNAup_args_info_full_help[23] = RNAup_args_info_detailed_help[30];
106   RNAup_args_info_full_help[24] = RNAup_args_info_detailed_help[31];
107   RNAup_args_info_full_help[25] = RNAup_args_info_detailed_help[33];
108   RNAup_args_info_full_help[26] = RNAup_args_info_detailed_help[35];
109   RNAup_args_info_full_help[27] = RNAup_args_info_detailed_help[36];
110   RNAup_args_info_full_help[28] = RNAup_args_info_detailed_help[37];
111   RNAup_args_info_full_help[29] = RNAup_args_info_detailed_help[39];
112   RNAup_args_info_full_help[30] = RNAup_args_info_detailed_help[41];
113   RNAup_args_info_full_help[31] = RNAup_args_info_detailed_help[42];
114   RNAup_args_info_full_help[32] = 0; 
115   
116 }
117
118 const char *RNAup_args_info_full_help[33];
119
120 static void
121 init_help_array(void)
122 {
123   RNAup_args_info_help[0] = RNAup_args_info_detailed_help[0];
124   RNAup_args_info_help[1] = RNAup_args_info_detailed_help[1];
125   RNAup_args_info_help[2] = RNAup_args_info_detailed_help[2];
126   RNAup_args_info_help[3] = RNAup_args_info_detailed_help[3];
127   RNAup_args_info_help[4] = RNAup_args_info_detailed_help[4];
128   RNAup_args_info_help[5] = RNAup_args_info_detailed_help[5];
129   RNAup_args_info_help[6] = RNAup_args_info_detailed_help[6];
130   RNAup_args_info_help[7] = RNAup_args_info_detailed_help[8];
131   RNAup_args_info_help[8] = RNAup_args_info_detailed_help[9];
132   RNAup_args_info_help[9] = RNAup_args_info_detailed_help[10];
133   RNAup_args_info_help[10] = RNAup_args_info_detailed_help[11];
134   RNAup_args_info_help[11] = RNAup_args_info_detailed_help[12];
135   RNAup_args_info_help[12] = RNAup_args_info_detailed_help[14];
136   RNAup_args_info_help[13] = RNAup_args_info_detailed_help[16];
137   RNAup_args_info_help[14] = RNAup_args_info_detailed_help[17];
138   RNAup_args_info_help[15] = RNAup_args_info_detailed_help[18];
139   RNAup_args_info_help[16] = RNAup_args_info_detailed_help[19];
140   RNAup_args_info_help[17] = RNAup_args_info_detailed_help[21];
141   RNAup_args_info_help[18] = RNAup_args_info_detailed_help[23];
142   RNAup_args_info_help[19] = RNAup_args_info_detailed_help[25];
143   RNAup_args_info_help[20] = RNAup_args_info_detailed_help[27];
144   RNAup_args_info_help[21] = RNAup_args_info_detailed_help[29];
145   RNAup_args_info_help[22] = RNAup_args_info_detailed_help[30];
146   RNAup_args_info_help[23] = RNAup_args_info_detailed_help[31];
147   RNAup_args_info_help[24] = RNAup_args_info_detailed_help[33];
148   RNAup_args_info_help[25] = RNAup_args_info_detailed_help[35];
149   RNAup_args_info_help[26] = RNAup_args_info_detailed_help[36];
150   RNAup_args_info_help[27] = RNAup_args_info_detailed_help[37];
151   RNAup_args_info_help[28] = RNAup_args_info_detailed_help[42];
152   RNAup_args_info_help[29] = 0; 
153   
154 }
155
156 const char *RNAup_args_info_help[30];
157
158 typedef enum {ARG_NO
159   , ARG_FLAG
160   , ARG_STRING
161   , ARG_INT
162   , ARG_DOUBLE
163 } RNAup_cmdline_parser_arg_type;
164
165 static
166 void clear_given (struct RNAup_args_info *args_info);
167 static
168 void clear_args (struct RNAup_args_info *args_info);
169
170 static int
171 RNAup_cmdline_parser_internal (int argc, char **argv, struct RNAup_args_info *args_info,
172                         struct RNAup_cmdline_parser_params *params, const char *additional_error);
173
174 static int
175 RNAup_cmdline_parser_required2 (struct RNAup_args_info *args_info, const char *prog_name, const char *additional_error);
176
177 static char *
178 gengetopt_strdup (const char *s);
179
180 static
181 void clear_given (struct RNAup_args_info *args_info)
182 {
183   args_info->help_given = 0 ;
184   args_info->detailed_help_given = 0 ;
185   args_info->full_help_given = 0 ;
186   args_info->version_given = 0 ;
187   args_info->constraint_given = 0 ;
188   args_info->no_output_file_given = 0 ;
189   args_info->no_header_given = 0 ;
190   args_info->noconv_given = 0 ;
191   args_info->ulength_given = 0 ;
192   args_info->contributions_given = 0 ;
193   args_info->window_given = 0 ;
194   args_info->include_both_given = 0 ;
195   args_info->extend5_given = 0 ;
196   args_info->extend3_given = 0 ;
197   args_info->interaction_pairwise_given = 0 ;
198   args_info->interaction_first_given = 0 ;
199   args_info->pfScale_given = 0 ;
200   args_info->temp_given = 0 ;
201   args_info->noTetra_given = 0 ;
202   args_info->dangles_given = 0 ;
203   args_info->noLP_given = 0 ;
204   args_info->noGU_given = 0 ;
205   args_info->noClosingGU_given = 0 ;
206   args_info->paramFile_given = 0 ;
207   args_info->nsp_given = 0 ;
208   args_info->energyModel_given = 0 ;
209 }
210
211 static
212 void clear_args (struct RNAup_args_info *args_info)
213 {
214   FIX_UNUSED (args_info);
215   args_info->constraint_flag = 0;
216   args_info->no_output_file_flag = 0;
217   args_info->no_header_flag = 0;
218   args_info->noconv_flag = 0;
219   args_info->ulength_arg = NULL;
220   args_info->ulength_orig = NULL;
221   args_info->contributions_arg = gengetopt_strdup ("S");
222   args_info->contributions_orig = NULL;
223   args_info->window_arg = 25;
224   args_info->window_orig = NULL;
225   args_info->include_both_flag = 0;
226   args_info->extend5_orig = NULL;
227   args_info->extend3_orig = NULL;
228   args_info->interaction_pairwise_flag = 0;
229   args_info->interaction_first_flag = 0;
230   args_info->pfScale_orig = NULL;
231   args_info->temp_orig = NULL;
232   args_info->noTetra_flag = 0;
233   args_info->dangles_arg = 2;
234   args_info->dangles_orig = NULL;
235   args_info->noLP_flag = 0;
236   args_info->noGU_flag = 0;
237   args_info->noClosingGU_flag = 0;
238   args_info->paramFile_arg = NULL;
239   args_info->paramFile_orig = NULL;
240   args_info->nsp_arg = NULL;
241   args_info->nsp_orig = NULL;
242   args_info->energyModel_orig = NULL;
243   
244 }
245
246 static
247 void init_args_info(struct RNAup_args_info *args_info)
248 {
249   init_full_help_array(); 
250   init_help_array(); 
251   args_info->help_help = RNAup_args_info_detailed_help[0] ;
252   args_info->detailed_help_help = RNAup_args_info_detailed_help[1] ;
253   args_info->full_help_help = RNAup_args_info_detailed_help[2] ;
254   args_info->version_help = RNAup_args_info_detailed_help[3] ;
255   args_info->constraint_help = RNAup_args_info_detailed_help[6] ;
256   args_info->no_output_file_help = RNAup_args_info_detailed_help[8] ;
257   args_info->no_header_help = RNAup_args_info_detailed_help[9] ;
258   args_info->noconv_help = RNAup_args_info_detailed_help[10] ;
259   args_info->ulength_help = RNAup_args_info_detailed_help[12] ;
260   args_info->ulength_min = 0;
261   args_info->ulength_max = 0;
262   args_info->contributions_help = RNAup_args_info_detailed_help[14] ;
263   args_info->window_help = RNAup_args_info_detailed_help[17] ;
264   args_info->include_both_help = RNAup_args_info_detailed_help[18] ;
265   args_info->extend5_help = RNAup_args_info_detailed_help[19] ;
266   args_info->extend3_help = RNAup_args_info_detailed_help[21] ;
267   args_info->interaction_pairwise_help = RNAup_args_info_detailed_help[23] ;
268   args_info->interaction_first_help = RNAup_args_info_detailed_help[25] ;
269   args_info->pfScale_help = RNAup_args_info_detailed_help[28] ;
270   args_info->temp_help = RNAup_args_info_detailed_help[29] ;
271   args_info->noTetra_help = RNAup_args_info_detailed_help[30] ;
272   args_info->dangles_help = RNAup_args_info_detailed_help[31] ;
273   args_info->noLP_help = RNAup_args_info_detailed_help[33] ;
274   args_info->noGU_help = RNAup_args_info_detailed_help[35] ;
275   args_info->noClosingGU_help = RNAup_args_info_detailed_help[36] ;
276   args_info->paramFile_help = RNAup_args_info_detailed_help[37] ;
277   args_info->nsp_help = RNAup_args_info_detailed_help[39] ;
278   args_info->energyModel_help = RNAup_args_info_detailed_help[41] ;
279   
280 }
281
282 void
283 RNAup_cmdline_parser_print_version (void)
284 {
285   printf ("%s %s\n",
286      (strlen(RNAUP_CMDLINE_PARSER_PACKAGE_NAME) ? RNAUP_CMDLINE_PARSER_PACKAGE_NAME : RNAUP_CMDLINE_PARSER_PACKAGE),
287      RNAUP_CMDLINE_PARSER_VERSION);
288 }
289
290 static void print_help_common(void) {
291   RNAup_cmdline_parser_print_version ();
292
293   if (strlen(RNAup_args_info_purpose) > 0)
294     printf("\n%s\n", RNAup_args_info_purpose);
295
296   if (strlen(RNAup_args_info_usage) > 0)
297     printf("\n%s\n", RNAup_args_info_usage);
298
299   printf("\n");
300
301   if (strlen(RNAup_args_info_description) > 0)
302     printf("%s\n\n", RNAup_args_info_description);
303 }
304
305 void
306 RNAup_cmdline_parser_print_help (void)
307 {
308   int i = 0;
309   print_help_common();
310   while (RNAup_args_info_help[i])
311     printf("%s\n", RNAup_args_info_help[i++]);
312 }
313
314 void
315 RNAup_cmdline_parser_print_full_help (void)
316 {
317   int i = 0;
318   print_help_common();
319   while (RNAup_args_info_full_help[i])
320     printf("%s\n", RNAup_args_info_full_help[i++]);
321 }
322
323 void
324 RNAup_cmdline_parser_print_detailed_help (void)
325 {
326   int i = 0;
327   print_help_common();
328   while (RNAup_args_info_detailed_help[i])
329     printf("%s\n", RNAup_args_info_detailed_help[i++]);
330 }
331
332 void
333 RNAup_cmdline_parser_init (struct RNAup_args_info *args_info)
334 {
335   clear_given (args_info);
336   clear_args (args_info);
337   init_args_info (args_info);
338 }
339
340 void
341 RNAup_cmdline_parser_params_init(struct RNAup_cmdline_parser_params *params)
342 {
343   if (params)
344     { 
345       params->override = 0;
346       params->initialize = 1;
347       params->check_required = 1;
348       params->check_ambiguity = 0;
349       params->print_errors = 1;
350     }
351 }
352
353 struct RNAup_cmdline_parser_params *
354 RNAup_cmdline_parser_params_create(void)
355 {
356   struct RNAup_cmdline_parser_params *params = 
357     (struct RNAup_cmdline_parser_params *)malloc(sizeof(struct RNAup_cmdline_parser_params));
358   RNAup_cmdline_parser_params_init(params);  
359   return params;
360 }
361
362 static void
363 free_string_field (char **s)
364 {
365   if (*s)
366     {
367       free (*s);
368       *s = 0;
369     }
370 }
371
372 /** @brief generic value variable */
373 union generic_value {
374     int int_arg;
375     double double_arg;
376     char *string_arg;
377     const char *default_string_arg;
378 };
379
380 /** @brief holds temporary values for multiple options */
381 struct generic_list
382 {
383   union generic_value arg;
384   char *orig;
385   struct generic_list *next;
386 };
387
388 /**
389  * @brief add a node at the head of the list 
390  */
391 static void add_node(struct generic_list **list) {
392   struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list));
393   new_node->next = *list;
394   *list = new_node;
395   new_node->arg.string_arg = 0;
396   new_node->orig = 0;
397 }
398
399
400 static void
401 free_multiple_string_field(unsigned int len, char ***arg, char ***orig)
402 {
403   unsigned int i;
404   if (*arg) {
405     for (i = 0; i < len; ++i)
406       {
407         free_string_field(&((*arg)[i]));
408         free_string_field(&((*orig)[i]));
409       }
410     free_string_field(&((*arg)[0])); /* free default string */
411
412     free (*arg);
413     *arg = 0;
414     free (*orig);
415     *orig = 0;
416   }
417 }
418
419 static void
420 RNAup_cmdline_parser_release (struct RNAup_args_info *args_info)
421 {
422
423   free_multiple_string_field (args_info->ulength_given, &(args_info->ulength_arg), &(args_info->ulength_orig));
424   free_string_field (&(args_info->contributions_arg));
425   free_string_field (&(args_info->contributions_orig));
426   free_string_field (&(args_info->window_orig));
427   free_string_field (&(args_info->extend5_orig));
428   free_string_field (&(args_info->extend3_orig));
429   free_string_field (&(args_info->pfScale_orig));
430   free_string_field (&(args_info->temp_orig));
431   free_string_field (&(args_info->dangles_orig));
432   free_string_field (&(args_info->paramFile_arg));
433   free_string_field (&(args_info->paramFile_orig));
434   free_string_field (&(args_info->nsp_arg));
435   free_string_field (&(args_info->nsp_orig));
436   free_string_field (&(args_info->energyModel_orig));
437   
438   
439
440   clear_given (args_info);
441 }
442
443
444 static void
445 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
446 {
447   FIX_UNUSED (values);
448   if (arg) {
449     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
450   } else {
451     fprintf(outfile, "%s\n", opt);
452   }
453 }
454
455 static void
456 write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[])
457 {
458   int i;
459   
460   for (i = 0; i < len; ++i)
461     write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
462 }
463
464 int
465 RNAup_cmdline_parser_dump(FILE *outfile, struct RNAup_args_info *args_info)
466 {
467   int i = 0;
468
469   if (!outfile)
470     {
471       fprintf (stderr, "%s: cannot dump options to stream\n", RNAUP_CMDLINE_PARSER_PACKAGE);
472       return EXIT_FAILURE;
473     }
474
475   if (args_info->help_given)
476     write_into_file(outfile, "help", 0, 0 );
477   if (args_info->detailed_help_given)
478     write_into_file(outfile, "detailed-help", 0, 0 );
479   if (args_info->full_help_given)
480     write_into_file(outfile, "full-help", 0, 0 );
481   if (args_info->version_given)
482     write_into_file(outfile, "version", 0, 0 );
483   if (args_info->constraint_given)
484     write_into_file(outfile, "constraint", 0, 0 );
485   if (args_info->no_output_file_given)
486     write_into_file(outfile, "no_output_file", 0, 0 );
487   if (args_info->no_header_given)
488     write_into_file(outfile, "no_header", 0, 0 );
489   if (args_info->noconv_given)
490     write_into_file(outfile, "noconv", 0, 0 );
491   write_multiple_into_file(outfile, args_info->ulength_given, "ulength", args_info->ulength_orig, 0);
492   if (args_info->contributions_given)
493     write_into_file(outfile, "contributions", args_info->contributions_orig, 0);
494   if (args_info->window_given)
495     write_into_file(outfile, "window", args_info->window_orig, 0);
496   if (args_info->include_both_given)
497     write_into_file(outfile, "include_both", 0, 0 );
498   if (args_info->extend5_given)
499     write_into_file(outfile, "extend5", args_info->extend5_orig, 0);
500   if (args_info->extend3_given)
501     write_into_file(outfile, "extend3", args_info->extend3_orig, 0);
502   if (args_info->interaction_pairwise_given)
503     write_into_file(outfile, "interaction_pairwise", 0, 0 );
504   if (args_info->interaction_first_given)
505     write_into_file(outfile, "interaction_first", 0, 0 );
506   if (args_info->pfScale_given)
507     write_into_file(outfile, "pfScale", args_info->pfScale_orig, 0);
508   if (args_info->temp_given)
509     write_into_file(outfile, "temp", args_info->temp_orig, 0);
510   if (args_info->noTetra_given)
511     write_into_file(outfile, "noTetra", 0, 0 );
512   if (args_info->dangles_given)
513     write_into_file(outfile, "dangles", args_info->dangles_orig, 0);
514   if (args_info->noLP_given)
515     write_into_file(outfile, "noLP", 0, 0 );
516   if (args_info->noGU_given)
517     write_into_file(outfile, "noGU", 0, 0 );
518   if (args_info->noClosingGU_given)
519     write_into_file(outfile, "noClosingGU", 0, 0 );
520   if (args_info->paramFile_given)
521     write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
522   if (args_info->nsp_given)
523     write_into_file(outfile, "nsp", args_info->nsp_orig, 0);
524   if (args_info->energyModel_given)
525     write_into_file(outfile, "energyModel", args_info->energyModel_orig, 0);
526   
527
528   i = EXIT_SUCCESS;
529   return i;
530 }
531
532 int
533 RNAup_cmdline_parser_file_save(const char *filename, struct RNAup_args_info *args_info)
534 {
535   FILE *outfile;
536   int i = 0;
537
538   outfile = fopen(filename, "w");
539
540   if (!outfile)
541     {
542       fprintf (stderr, "%s: cannot open file for writing: %s\n", RNAUP_CMDLINE_PARSER_PACKAGE, filename);
543       return EXIT_FAILURE;
544     }
545
546   i = RNAup_cmdline_parser_dump(outfile, args_info);
547   fclose (outfile);
548
549   return i;
550 }
551
552 void
553 RNAup_cmdline_parser_free (struct RNAup_args_info *args_info)
554 {
555   RNAup_cmdline_parser_release (args_info);
556 }
557
558 /** @brief replacement of strdup, which is not standard */
559 char *
560 gengetopt_strdup (const char *s)
561 {
562   char *result = 0;
563   if (!s)
564     return result;
565
566   result = (char*)malloc(strlen(s) + 1);
567   if (result == (char*)0)
568     return (char*)0;
569   strcpy(result, s);
570   return result;
571 }
572
573 static char *
574 get_multiple_arg_token(const char *arg)
575 {
576   const char *tok;
577   char *ret;
578   size_t len, num_of_escape, i, j;
579
580   if (!arg)
581     return 0;
582
583   tok = strchr (arg, ',');
584   num_of_escape = 0;
585
586   /* make sure it is not escaped */
587   while (tok)
588     {
589       if (*(tok-1) == '\\')
590         {
591           /* find the next one */
592           tok = strchr (tok+1, ',');
593           ++num_of_escape;
594         }
595       else
596         break;
597     }
598
599   if (tok)
600     len = (size_t)(tok - arg + 1);
601   else
602     len = strlen (arg) + 1;
603
604   len -= num_of_escape;
605
606   ret = (char *) malloc (len);
607
608   i = 0;
609   j = 0;
610   while (arg[i] && (j < len-1))
611     {
612       if (arg[i] == '\\' && 
613           arg[ i + 1 ] && 
614           arg[ i + 1 ] == ',')
615         ++i;
616
617       ret[j++] = arg[i++];
618     }
619
620   ret[len-1] = '\0';
621
622   return ret;
623 }
624
625 static const char *
626 get_multiple_arg_token_next(const char *arg)
627 {
628   const char *tok;
629
630   if (!arg)
631     return 0;
632
633   tok = strchr (arg, ',');
634
635   /* make sure it is not escaped */
636   while (tok)
637     {
638       if (*(tok-1) == '\\')
639         {
640           /* find the next one */
641           tok = strchr (tok+1, ',');
642         }
643       else
644         break;
645     }
646
647   if (! tok || strlen(tok) == 1)
648     return 0;
649
650   return tok+1;
651 }
652
653 static int
654 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc);
655
656 int
657 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc)
658 {
659   int error = 0;
660
661   if (option_given && (min > 0 || max > 0))
662     {
663       if (min > 0 && max > 0)
664         {
665           if (min == max)
666             {
667               /* specific occurrences */
668               if (option_given != (unsigned int) min)
669                 {
670                   fprintf (stderr, "%s: %s option occurrences must be %d\n",
671                     prog_name, option_desc, min);
672                   error = 1;
673                 }
674             }
675           else if (option_given < (unsigned int) min
676                 || option_given > (unsigned int) max)
677             {
678               /* range occurrences */
679               fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n",
680                 prog_name, option_desc, min, max);
681               error = 1;
682             }
683         }
684       else if (min > 0)
685         {
686           /* at least check */
687           if (option_given < min)
688             {
689               fprintf (stderr, "%s: %s option occurrences must be at least %d\n",
690                 prog_name, option_desc, min);
691               error = 1;
692             }
693         }
694       else if (max > 0)
695         {
696           /* at most check */
697           if (option_given > max)
698             {
699               fprintf (stderr, "%s: %s option occurrences must be at most %d\n",
700                 prog_name, option_desc, max);
701               error = 1;
702             }
703         }
704     }
705     
706   return error;
707 }
708 int
709 RNAup_cmdline_parser (int argc, char **argv, struct RNAup_args_info *args_info)
710 {
711   return RNAup_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
712 }
713
714 int
715 RNAup_cmdline_parser_ext (int argc, char **argv, struct RNAup_args_info *args_info,
716                    struct RNAup_cmdline_parser_params *params)
717 {
718   int result;
719   result = RNAup_cmdline_parser_internal (argc, argv, args_info, params, 0);
720
721   if (result == EXIT_FAILURE)
722     {
723       RNAup_cmdline_parser_free (args_info);
724       exit (EXIT_FAILURE);
725     }
726   
727   return result;
728 }
729
730 int
731 RNAup_cmdline_parser2 (int argc, char **argv, struct RNAup_args_info *args_info, int override, int initialize, int check_required)
732 {
733   int result;
734   struct RNAup_cmdline_parser_params params;
735   
736   params.override = override;
737   params.initialize = initialize;
738   params.check_required = check_required;
739   params.check_ambiguity = 0;
740   params.print_errors = 1;
741
742   result = RNAup_cmdline_parser_internal (argc, argv, args_info, &params, 0);
743
744   if (result == EXIT_FAILURE)
745     {
746       RNAup_cmdline_parser_free (args_info);
747       exit (EXIT_FAILURE);
748     }
749   
750   return result;
751 }
752
753 int
754 RNAup_cmdline_parser_required (struct RNAup_args_info *args_info, const char *prog_name)
755 {
756   int result = EXIT_SUCCESS;
757
758   if (RNAup_cmdline_parser_required2(args_info, prog_name, 0) > 0)
759     result = EXIT_FAILURE;
760
761   if (result == EXIT_FAILURE)
762     {
763       RNAup_cmdline_parser_free (args_info);
764       exit (EXIT_FAILURE);
765     }
766   
767   return result;
768 }
769
770 int
771 RNAup_cmdline_parser_required2 (struct RNAup_args_info *args_info, const char *prog_name, const char *additional_error)
772 {
773   int error = 0;
774   FIX_UNUSED (additional_error);
775
776   /* checks for required options */
777   if (check_multiple_option_occurrences(prog_name, args_info->ulength_given, args_info->ulength_min, args_info->ulength_max, "'--ulength' ('-u')"))
778      error = 1;
779   
780   
781   /* checks for dependences among options */
782
783   return error;
784 }
785
786 /*
787  * Extracted from the glibc source tree, version 2.3.6
788  *
789  * Licensed under the GPL as per the whole glibc source tree.
790  *
791  * This file was modified so that getopt_long can be called
792  * many times without risking previous memory to be spoiled.
793  *
794  * Modified by Andre Noll and Lorenzo Bettini for use in
795  * GNU gengetopt generated files.
796  *
797  */
798
799 /* 
800  * we must include anything we need since this file is not thought to be
801  * inserted in a file already using getopt.h
802  *
803  * Lorenzo
804  */
805
806 struct option
807 {
808   const char *name;
809   /* has_arg can't be an enum because some compilers complain about
810      type mismatches in all the code that assumes it is an int.  */
811   int has_arg;
812   int *flag;
813   int val;
814 };
815
816 /* This version of `getopt' appears to the caller like standard Unix `getopt'
817    but it behaves differently for the user, since it allows the user
818    to intersperse the options with the other arguments.
819
820    As `getopt' works, it permutes the elements of ARGV so that,
821    when it is done, all the options precede everything else.  Thus
822    all application programs are extended to handle flexible argument order.
823 */
824 /*
825    If the field `flag' is not NULL, it points to a variable that is set
826    to the value given in the field `val' when the option is found, but
827    left unchanged if the option is not found.
828
829    To have a long-named option do something other than set an `int' to
830    a compiled-in constant, such as set a value from `custom_optarg', set the
831    option's `flag' field to zero and its `val' field to a nonzero
832    value (the equivalent single-letter option character, if there is
833    one).  For long options that have a zero `flag' field, `getopt'
834    returns the contents of the `val' field.  */
835
836 /* Names for the values of the `has_arg' field of `struct option'.  */
837 #ifndef no_argument
838 #define no_argument             0
839 #endif
840
841 #ifndef required_argument
842 #define required_argument       1
843 #endif
844
845 #ifndef optional_argument
846 #define optional_argument       2
847 #endif
848
849 struct custom_getopt_data {
850         /*
851          * These have exactly the same meaning as the corresponding global variables,
852          * except that they are used for the reentrant versions of getopt.
853          */
854         int custom_optind;
855         int custom_opterr;
856         int custom_optopt;
857         char *custom_optarg;
858
859         /* True if the internal members have been initialized.  */
860         int initialized;
861
862         /*
863          * The next char to be scanned in the option-element in which the last option
864          * character we returned was found.  This allows us to pick up the scan where
865          * we left off.  If this is zero, or a null string, it means resume the scan by
866          * advancing to the next ARGV-element.
867          */
868         char *nextchar;
869
870         /*
871          * Describe the part of ARGV that contains non-options that have been skipped.
872          * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
873          * the index after the last of them.
874          */
875         int first_nonopt;
876         int last_nonopt;
877 };
878
879 /*
880  * the variables optarg, optind, opterr and optopt are renamed with
881  * the custom_ prefix so that they don't interfere with getopt ones.
882  *
883  * Moreover they're static so they are visible only from within the
884  * file where this very file will be included.
885  */
886
887 /*
888  * For communication from `custom_getopt' to the caller.  When `custom_getopt' finds an
889  * option that takes an argument, the argument value is returned here.
890  */
891 static char *custom_optarg;
892
893 /*
894  * Index in ARGV of the next element to be scanned.  This is used for
895  * communication to and from the caller and for communication between
896  * successive calls to `custom_getopt'.
897  *
898  * On entry to `custom_getopt', 1 means this is the first call; initialize.
899  *
900  * When `custom_getopt' returns -1, this is the index of the first of the non-option
901  * elements that the caller should itself scan.
902  *
903  * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
904  * has been scanned so far.
905  *
906  * 1003.2 says this must be 1 before any call.
907  */
908 static int custom_optind = 1;
909
910 /*
911  * Callers store zero here to inhibit the error message for unrecognized
912  * options.
913  */
914 static int custom_opterr = 1;
915
916 /*
917  * Set to an option character which was unrecognized.  This must be initialized
918  * on some systems to avoid linking in the system's own getopt implementation.
919  */
920 static int custom_optopt = '?';
921
922 /*
923  * Exchange two adjacent subsequences of ARGV.  One subsequence is elements
924  * [first_nonopt,last_nonopt) which contains all the non-options that have been
925  * skipped so far.  The other is elements [last_nonopt,custom_optind), which contains
926  * all the options processed since those non-options were skipped.
927  * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
928  * indices of the non-options in ARGV after they are moved.
929  */
930 static void exchange(char **argv, struct custom_getopt_data *d)
931 {
932         int bottom = d->first_nonopt;
933         int middle = d->last_nonopt;
934         int top = d->custom_optind;
935         char *tem;
936
937         /*
938          * Exchange the shorter segment with the far end of the longer segment.
939          * That puts the shorter segment into the right place.  It leaves the
940          * longer segment in the right place overall, but it consists of two
941          * parts that need to be swapped next.
942          */
943         while (top > middle && middle > bottom) {
944                 if (top - middle > middle - bottom) {
945                         /* Bottom segment is the short one.  */
946                         int len = middle - bottom;
947                         int i;
948
949                         /* Swap it with the top part of the top segment.  */
950                         for (i = 0; i < len; i++) {
951                                 tem = argv[bottom + i];
952                                 argv[bottom + i] =
953                                         argv[top - (middle - bottom) + i];
954                                 argv[top - (middle - bottom) + i] = tem;
955                         }
956                         /* Exclude the moved bottom segment from further swapping.  */
957                         top -= len;
958                 } else {
959                         /* Top segment is the short one.  */
960                         int len = top - middle;
961                         int i;
962
963                         /* Swap it with the bottom part of the bottom segment.  */
964                         for (i = 0; i < len; i++) {
965                                 tem = argv[bottom + i];
966                                 argv[bottom + i] = argv[middle + i];
967                                 argv[middle + i] = tem;
968                         }
969                         /* Exclude the moved top segment from further swapping.  */
970                         bottom += len;
971                 }
972         }
973         /* Update records for the slots the non-options now occupy.  */
974         d->first_nonopt += (d->custom_optind - d->last_nonopt);
975         d->last_nonopt = d->custom_optind;
976 }
977
978 /* Initialize the internal data when the first call is made.  */
979 static void custom_getopt_initialize(struct custom_getopt_data *d)
980 {
981         /*
982          * Start processing options with ARGV-element 1 (since ARGV-element 0
983          * is the program name); the sequence of previously skipped non-option
984          * ARGV-elements is empty.
985          */
986         d->first_nonopt = d->last_nonopt = d->custom_optind;
987         d->nextchar = NULL;
988         d->initialized = 1;
989 }
990
991 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
992
993 /* return: zero: continue, nonzero: return given value to user */
994 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
995         struct custom_getopt_data *d)
996 {
997         /*
998          * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
999          * moved back by the user (who may also have changed the arguments).
1000          */
1001         if (d->last_nonopt > d->custom_optind)
1002                 d->last_nonopt = d->custom_optind;
1003         if (d->first_nonopt > d->custom_optind)
1004                 d->first_nonopt = d->custom_optind;
1005         /*
1006          * If we have just processed some options following some
1007          * non-options, exchange them so that the options come first.
1008          */
1009         if (d->first_nonopt != d->last_nonopt &&
1010                         d->last_nonopt != d->custom_optind)
1011                 exchange((char **) argv, d);
1012         else if (d->last_nonopt != d->custom_optind)
1013                 d->first_nonopt = d->custom_optind;
1014         /*
1015          * Skip any additional non-options and extend the range of
1016          * non-options previously skipped.
1017          */
1018         while (d->custom_optind < argc && NONOPTION_P)
1019                 d->custom_optind++;
1020         d->last_nonopt = d->custom_optind;
1021         /*
1022          * The special ARGV-element `--' means premature end of options.  Skip
1023          * it like a null option, then exchange with previous non-options as if
1024          * it were an option, then skip everything else like a non-option.
1025          */
1026         if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
1027                 d->custom_optind++;
1028                 if (d->first_nonopt != d->last_nonopt
1029                                 && d->last_nonopt != d->custom_optind)
1030                         exchange((char **) argv, d);
1031                 else if (d->first_nonopt == d->last_nonopt)
1032                         d->first_nonopt = d->custom_optind;
1033                 d->last_nonopt = argc;
1034                 d->custom_optind = argc;
1035         }
1036         /*
1037          * If we have done all the ARGV-elements, stop the scan and back over
1038          * any non-options that we skipped and permuted.
1039          */
1040         if (d->custom_optind == argc) {
1041                 /*
1042                  * Set the next-arg-index to point at the non-options that we
1043                  * previously skipped, so the caller will digest them.
1044                  */
1045                 if (d->first_nonopt != d->last_nonopt)
1046                         d->custom_optind = d->first_nonopt;
1047                 return -1;
1048         }
1049         /*
1050          * If we have come to a non-option and did not permute it, either stop
1051          * the scan or describe it to the caller and pass it by.
1052          */
1053         if (NONOPTION_P) {
1054                 d->custom_optarg = argv[d->custom_optind++];
1055                 return 1;
1056         }
1057         /*
1058          * We have found another option-ARGV-element. Skip the initial
1059          * punctuation.
1060          */
1061         d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
1062         return 0;
1063 }
1064
1065 /*
1066  * Check whether the ARGV-element is a long option.
1067  *
1068  * If there's a long option "fubar" and the ARGV-element is "-fu", consider
1069  * that an abbreviation of the long option, just like "--fu", and not "-f" with
1070  * arg "u".
1071  *
1072  * This distinction seems to be the most useful approach.
1073  *
1074  */
1075 static int check_long_opt(int argc, char *const *argv, const char *optstring,
1076                 const struct option *longopts, int *longind,
1077                 int print_errors, struct custom_getopt_data *d)
1078 {
1079         char *nameend;
1080         const struct option *p;
1081         const struct option *pfound = NULL;
1082         int exact = 0;
1083         int ambig = 0;
1084         int indfound = -1;
1085         int option_index;
1086
1087         for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
1088                 /* Do nothing.  */ ;
1089
1090         /* Test all long options for either exact match or abbreviated matches */
1091         for (p = longopts, option_index = 0; p->name; p++, option_index++)
1092                 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
1093                         if ((unsigned int) (nameend - d->nextchar)
1094                                         == (unsigned int) strlen(p->name)) {
1095                                 /* Exact match found.  */
1096                                 pfound = p;
1097                                 indfound = option_index;
1098                                 exact = 1;
1099                                 break;
1100                         } else if (pfound == NULL) {
1101                                 /* First nonexact match found.  */
1102                                 pfound = p;
1103                                 indfound = option_index;
1104                         } else if (pfound->has_arg != p->has_arg
1105                                         || pfound->flag != p->flag
1106                                         || pfound->val != p->val)
1107                                 /* Second or later nonexact match found.  */
1108                                 ambig = 1;
1109                 }
1110         if (ambig && !exact) {
1111                 if (print_errors) {
1112                         fprintf(stderr,
1113                                 "%s: option `%s' is ambiguous\n",
1114                                 argv[0], argv[d->custom_optind]);
1115                 }
1116                 d->nextchar += strlen(d->nextchar);
1117                 d->custom_optind++;
1118                 d->custom_optopt = 0;
1119                 return '?';
1120         }
1121         if (pfound) {
1122                 option_index = indfound;
1123                 d->custom_optind++;
1124                 if (*nameend) {
1125                         if (pfound->has_arg != no_argument)
1126                                 d->custom_optarg = nameend + 1;
1127                         else {
1128                                 if (print_errors) {
1129                                         if (argv[d->custom_optind - 1][1] == '-') {
1130                                                 /* --option */
1131                                                 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
1132                                                         argv[0], pfound->name);
1133                                         } else {
1134                                                 /* +option or -option */
1135                                                 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
1136                                                         argv[0], argv[d->custom_optind - 1][0], pfound->name);
1137                                         }
1138
1139                                 }
1140                                 d->nextchar += strlen(d->nextchar);
1141                                 d->custom_optopt = pfound->val;
1142                                 return '?';
1143                         }
1144                 } else if (pfound->has_arg == required_argument) {
1145                         if (d->custom_optind < argc)
1146                                 d->custom_optarg = argv[d->custom_optind++];
1147                         else {
1148                                 if (print_errors) {
1149                                         fprintf(stderr,
1150                                                 "%s: option `%s' requires an argument\n",
1151                                                 argv[0],
1152                                                 argv[d->custom_optind - 1]);
1153                                 }
1154                                 d->nextchar += strlen(d->nextchar);
1155                                 d->custom_optopt = pfound->val;
1156                                 return optstring[0] == ':' ? ':' : '?';
1157                         }
1158                 }
1159                 d->nextchar += strlen(d->nextchar);
1160                 if (longind != NULL)
1161                         *longind = option_index;
1162                 if (pfound->flag) {
1163                         *(pfound->flag) = pfound->val;
1164                         return 0;
1165                 }
1166                 return pfound->val;
1167         }
1168         /*
1169          * Can't find it as a long option.  If this is not getopt_long_only, or
1170          * the option starts with '--' or is not a valid short option, then
1171          * it's an error.  Otherwise interpret it as a short option.
1172          */
1173         if (print_errors) {
1174                 if (argv[d->custom_optind][1] == '-') {
1175                         /* --option */
1176                         fprintf(stderr,
1177                                 "%s: unrecognized option `--%s'\n",
1178                                 argv[0], d->nextchar);
1179                 } else {
1180                         /* +option or -option */
1181                         fprintf(stderr,
1182                                 "%s: unrecognized option `%c%s'\n",
1183                                 argv[0], argv[d->custom_optind][0],
1184                                 d->nextchar);
1185                 }
1186         }
1187         d->nextchar = (char *) "";
1188         d->custom_optind++;
1189         d->custom_optopt = 0;
1190         return '?';
1191 }
1192
1193 static int check_short_opt(int argc, char *const *argv, const char *optstring,
1194                 int print_errors, struct custom_getopt_data *d)
1195 {
1196         char c = *d->nextchar++;
1197         const char *temp = strchr(optstring, c);
1198
1199         /* Increment `custom_optind' when we start to process its last character.  */
1200         if (*d->nextchar == '\0')
1201                 ++d->custom_optind;
1202         if (!temp || c == ':') {
1203                 if (print_errors)
1204                         fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
1205
1206                 d->custom_optopt = c;
1207                 return '?';
1208         }
1209         if (temp[1] == ':') {
1210                 if (temp[2] == ':') {
1211                         /* This is an option that accepts an argument optionally.  */
1212                         if (*d->nextchar != '\0') {
1213                                 d->custom_optarg = d->nextchar;
1214                                 d->custom_optind++;
1215                         } else
1216                                 d->custom_optarg = NULL;
1217                         d->nextchar = NULL;
1218                 } else {
1219                         /* This is an option that requires an argument.  */
1220                         if (*d->nextchar != '\0') {
1221                                 d->custom_optarg = d->nextchar;
1222                                 /*
1223                                  * If we end this ARGV-element by taking the
1224                                  * rest as an arg, we must advance to the next
1225                                  * element now.
1226                                  */
1227                                 d->custom_optind++;
1228                         } else if (d->custom_optind == argc) {
1229                                 if (print_errors) {
1230                                         fprintf(stderr,
1231                                                 "%s: option requires an argument -- %c\n",
1232                                                 argv[0], c);
1233                                 }
1234                                 d->custom_optopt = c;
1235                                 if (optstring[0] == ':')
1236                                         c = ':';
1237                                 else
1238                                         c = '?';
1239                         } else
1240                                 /*
1241                                  * We already incremented `custom_optind' once;
1242                                  * increment it again when taking next ARGV-elt
1243                                  * as argument.
1244                                  */
1245                                 d->custom_optarg = argv[d->custom_optind++];
1246                         d->nextchar = NULL;
1247                 }
1248         }
1249         return c;
1250 }
1251
1252 /*
1253  * Scan elements of ARGV for option characters given in OPTSTRING.
1254  *
1255  * If an element of ARGV starts with '-', and is not exactly "-" or "--",
1256  * then it is an option element.  The characters of this element
1257  * (aside from the initial '-') are option characters.  If `getopt'
1258  * is called repeatedly, it returns successively each of the option characters
1259  * from each of the option elements.
1260  *
1261  * If `getopt' finds another option character, it returns that character,
1262  * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
1263  * resume the scan with the following option character or ARGV-element.
1264  *
1265  * If there are no more option characters, `getopt' returns -1.
1266  * Then `custom_optind' is the index in ARGV of the first ARGV-element
1267  * that is not an option.  (The ARGV-elements have been permuted
1268  * so that those that are not options now come last.)
1269  *
1270  * OPTSTRING is a string containing the legitimate option characters.
1271  * If an option character is seen that is not listed in OPTSTRING,
1272  * return '?' after printing an error message.  If you set `custom_opterr' to
1273  * zero, the error message is suppressed but we still return '?'.
1274  *
1275  * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
1276  * so the following text in the same ARGV-element, or the text of the following
1277  * ARGV-element, is returned in `custom_optarg'.  Two colons mean an option that
1278  * wants an optional arg; if there is text in the current ARGV-element,
1279  * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
1280  *
1281  * If OPTSTRING starts with `-' or `+', it requests different methods of
1282  * handling the non-option ARGV-elements.
1283  * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
1284  *
1285  * Long-named options begin with `--' instead of `-'.
1286  * Their names may be abbreviated as long as the abbreviation is unique
1287  * or is an exact match for some defined option.  If they have an
1288  * argument, it follows the option name in the same ARGV-element, separated
1289  * from the option name by a `=', or else the in next ARGV-element.
1290  * When `getopt' finds a long-named option, it returns 0 if that option's
1291  * `flag' field is nonzero, the value of the option's `val' field
1292  * if the `flag' field is zero.
1293  *
1294  * The elements of ARGV aren't really const, because we permute them.
1295  * But we pretend they're const in the prototype to be compatible
1296  * with other systems.
1297  *
1298  * LONGOPTS is a vector of `struct option' terminated by an
1299  * element containing a name which is zero.
1300  *
1301  * LONGIND returns the index in LONGOPT of the long-named option found.
1302  * It is only valid when a long-named option has been found by the most
1303  * recent call.
1304  *
1305  * Return the option character from OPTS just read.  Return -1 when there are
1306  * no more options.  For unrecognized options, or options missing arguments,
1307  * `custom_optopt' is set to the option letter, and '?' is returned.
1308  *
1309  * The OPTS string is a list of characters which are recognized option letters,
1310  * optionally followed by colons, specifying that that letter takes an
1311  * argument, to be placed in `custom_optarg'.
1312  *
1313  * If a letter in OPTS is followed by two colons, its argument is optional.
1314  * This behavior is specific to the GNU `getopt'.
1315  *
1316  * The argument `--' causes premature termination of argument scanning,
1317  * explicitly telling `getopt' that there are no more options.  If OPTS begins
1318  * with `--', then non-option arguments are treated as arguments to the option
1319  * '\0'.  This behavior is specific to the GNU `getopt'.
1320  */
1321
1322 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1323                 const struct option *longopts, int *longind,
1324                 struct custom_getopt_data *d)
1325 {
1326         int ret, print_errors = d->custom_opterr;
1327
1328         if (optstring[0] == ':')
1329                 print_errors = 0;
1330         if (argc < 1)
1331                 return -1;
1332         d->custom_optarg = NULL;
1333
1334         /* 
1335          * This is a big difference with GNU getopt, since optind == 0
1336          * means initialization while here 1 means first call.
1337          */
1338         if (d->custom_optind == 0 || !d->initialized) {
1339                 if (d->custom_optind == 0)
1340                         d->custom_optind = 1;   /* Don't scan ARGV[0], the program name.  */
1341                 custom_getopt_initialize(d);
1342         }
1343         if (d->nextchar == NULL || *d->nextchar == '\0') {
1344                 ret = shuffle_argv(argc, argv, longopts, d);
1345                 if (ret)
1346                         return ret;
1347         }
1348         if (longopts && (argv[d->custom_optind][1] == '-' ))
1349                 return check_long_opt(argc, argv, optstring, longopts,
1350                         longind, print_errors, d);
1351         return check_short_opt(argc, argv, optstring, print_errors, d);
1352 }
1353
1354 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1355         const struct option *longopts, int *longind)
1356 {
1357         int result;
1358         /* Keep a global copy of all internal members of d */
1359         static struct custom_getopt_data d;
1360
1361         d.custom_optind = custom_optind;
1362         d.custom_opterr = custom_opterr;
1363         result = getopt_internal_r(argc, argv, optstring, longopts,
1364                 longind, &d);
1365         custom_optind = d.custom_optind;
1366         custom_optarg = d.custom_optarg;
1367         custom_optopt = d.custom_optopt;
1368         return result;
1369 }
1370
1371 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1372         const struct option *long_options, int *opt_index)
1373 {
1374         return custom_getopt_internal(argc, argv, options, long_options,
1375                 opt_index);
1376 }
1377
1378
1379 static char *package_name = 0;
1380
1381 /**
1382  * @brief updates an option
1383  * @param field the generic pointer to the field to update
1384  * @param orig_field the pointer to the orig field
1385  * @param field_given the pointer to the number of occurrence of this option
1386  * @param prev_given the pointer to the number of occurrence already seen
1387  * @param value the argument for this option (if null no arg was specified)
1388  * @param possible_values the possible values for this option (if specified)
1389  * @param default_value the default value (in case the option only accepts fixed values)
1390  * @param arg_type the type of this option
1391  * @param check_ambiguity @see RNAup_cmdline_parser_params.check_ambiguity
1392  * @param override @see RNAup_cmdline_parser_params.override
1393  * @param no_free whether to free a possible previous value
1394  * @param multiple_option whether this is a multiple option
1395  * @param long_opt the corresponding long option
1396  * @param short_opt the corresponding short option (or '-' if none)
1397  * @param additional_error possible further error specification
1398  */
1399 static
1400 int update_arg(void *field, char **orig_field,
1401                unsigned int *field_given, unsigned int *prev_given, 
1402                char *value, const char *possible_values[],
1403                const char *default_value,
1404                RNAup_cmdline_parser_arg_type arg_type,
1405                int check_ambiguity, int override,
1406                int no_free, int multiple_option,
1407                const char *long_opt, char short_opt,
1408                const char *additional_error)
1409 {
1410   char *stop_char = 0;
1411   const char *val = value;
1412   int found;
1413   char **string_field;
1414   FIX_UNUSED (field);
1415
1416   stop_char = 0;
1417   found = 0;
1418
1419   if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1420     {
1421       if (short_opt != '-')
1422         fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", 
1423                package_name, long_opt, short_opt,
1424                (additional_error ? additional_error : ""));
1425       else
1426         fprintf (stderr, "%s: `--%s' option given more than once%s\n", 
1427                package_name, long_opt,
1428                (additional_error ? additional_error : ""));
1429       return 1; /* failure */
1430     }
1431
1432   FIX_UNUSED (default_value);
1433     
1434   if (field_given && *field_given && ! override)
1435     return 0;
1436   if (prev_given)
1437     (*prev_given)++;
1438   if (field_given)
1439     (*field_given)++;
1440   if (possible_values)
1441     val = possible_values[found];
1442
1443   switch(arg_type) {
1444   case ARG_FLAG:
1445     *((int *)field) = !*((int *)field);
1446     break;
1447   case ARG_INT:
1448     if (val) *((int *)field) = strtol (val, &stop_char, 0);
1449     break;
1450   case ARG_DOUBLE:
1451     if (val) *((double *)field) = strtod (val, &stop_char);
1452     break;
1453   case ARG_STRING:
1454     if (val) {
1455       string_field = (char **)field;
1456       if (!no_free && *string_field)
1457         free (*string_field); /* free previous string */
1458       *string_field = gengetopt_strdup (val);
1459     }
1460     break;
1461   default:
1462     break;
1463   };
1464
1465   /* check numeric conversion */
1466   switch(arg_type) {
1467   case ARG_INT:
1468   case ARG_DOUBLE:
1469     if (val && !(stop_char && *stop_char == '\0')) {
1470       fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1471       return 1; /* failure */
1472     }
1473     break;
1474   default:
1475     ;
1476   };
1477
1478   /* store the original value */
1479   switch(arg_type) {
1480   case ARG_NO:
1481   case ARG_FLAG:
1482     break;
1483   default:
1484     if (value && orig_field) {
1485       if (no_free) {
1486         *orig_field = value;
1487       } else {
1488         if (*orig_field)
1489           free (*orig_field); /* free previous string */
1490         *orig_field = gengetopt_strdup (value);
1491       }
1492     }
1493   };
1494
1495   return 0; /* OK */
1496 }
1497
1498 /**
1499  * @brief store information about a multiple option in a temporary list
1500  * @param list where to (temporarily) store multiple options
1501  */
1502 static
1503 int update_multiple_arg_temp(struct generic_list **list,
1504                unsigned int *prev_given, const char *val,
1505                const char *possible_values[], const char *default_value,
1506                RNAup_cmdline_parser_arg_type arg_type,
1507                const char *long_opt, char short_opt,
1508                const char *additional_error)
1509 {
1510   /* store single arguments */
1511   char *multi_token;
1512   const char *multi_next;
1513
1514   if (arg_type == ARG_NO) {
1515     (*prev_given)++;
1516     return 0; /* OK */
1517   }
1518
1519   multi_token = get_multiple_arg_token(val);
1520   multi_next = get_multiple_arg_token_next (val);
1521
1522   while (1)
1523     {
1524       add_node (list);
1525       if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0,
1526           prev_given, multi_token, possible_values, default_value, 
1527           arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
1528         if (multi_token) free(multi_token);
1529         return 1; /* failure */
1530       }
1531
1532       if (multi_next)
1533         {
1534           multi_token = get_multiple_arg_token(multi_next);
1535           multi_next = get_multiple_arg_token_next (multi_next);
1536         }
1537       else
1538         break;
1539     }
1540
1541   return 0; /* OK */
1542 }
1543
1544 /**
1545  * @brief free the passed list (including possible string argument)
1546  */
1547 static
1548 void free_list(struct generic_list *list, short string_arg)
1549 {
1550   if (list) {
1551     struct generic_list *tmp;
1552     while (list)
1553       {
1554         tmp = list;
1555         if (string_arg && list->arg.string_arg)
1556           free (list->arg.string_arg);
1557         if (list->orig)
1558           free (list->orig);
1559         list = list->next;
1560         free (tmp);
1561       }
1562   }
1563 }
1564
1565 /**
1566  * @brief updates a multiple option starting from the passed list
1567  */
1568 static
1569 void update_multiple_arg(void *field, char ***orig_field,
1570                unsigned int field_given, unsigned int prev_given, union generic_value *default_value,
1571                RNAup_cmdline_parser_arg_type arg_type,
1572                struct generic_list *list)
1573 {
1574   int i;
1575   struct generic_list *tmp;
1576
1577   if (prev_given && list) {
1578     *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *));
1579
1580     switch(arg_type) {
1581     case ARG_INT:
1582       *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break;
1583     case ARG_DOUBLE:
1584       *((double **)field) = (double *)realloc (*((double **)field), (field_given + prev_given) * sizeof (double)); break;
1585     case ARG_STRING:
1586       *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break;
1587     default:
1588       break;
1589     };
1590     
1591     for (i = (prev_given - 1); i >= 0; --i)
1592       {
1593         tmp = list;
1594         
1595         switch(arg_type) {
1596         case ARG_INT:
1597           (*((int **)field))[i + field_given] = tmp->arg.int_arg; break;
1598         case ARG_DOUBLE:
1599           (*((double **)field))[i + field_given] = tmp->arg.double_arg; break;
1600         case ARG_STRING:
1601           (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break;
1602         default:
1603           break;
1604         }        
1605         (*orig_field) [i + field_given] = list->orig;
1606         list = list->next;
1607         free (tmp);
1608       }
1609   } else { /* set the default value */
1610     if (default_value && ! field_given) {
1611       switch(arg_type) {
1612       case ARG_INT:
1613         if (! *((int **)field)) {
1614           *((int **)field) = (int *)malloc (sizeof (int));
1615           (*((int **)field))[0] = default_value->int_arg; 
1616         }
1617         break;
1618       case ARG_DOUBLE:
1619         if (! *((double **)field)) {
1620           *((double **)field) = (double *)malloc (sizeof (double));
1621           (*((double **)field))[0] = default_value->double_arg;
1622         }
1623         break;
1624       case ARG_STRING:
1625         if (! *((char ***)field)) {
1626           *((char ***)field) = (char **)malloc (sizeof (char *));
1627           (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg);
1628         }
1629         break;
1630       default: break;
1631       }
1632       if (!(*orig_field)) {
1633         *orig_field = (char **) malloc (sizeof (char *));
1634         (*orig_field)[0] = 0;
1635       }
1636     }
1637   }
1638 }
1639
1640 int
1641 RNAup_cmdline_parser_internal (
1642   int argc, char **argv, struct RNAup_args_info *args_info,
1643                         struct RNAup_cmdline_parser_params *params, const char *additional_error)
1644 {
1645   int c;        /* Character of the parsed option.  */
1646   union generic_value multiple_default_value;
1647
1648   struct generic_list * ulength_list = NULL;
1649   int error = 0;
1650   struct RNAup_args_info local_args_info;
1651   
1652   int override;
1653   int initialize;
1654   int check_required;
1655   int check_ambiguity;
1656
1657   char *optarg;
1658   int optind;
1659   int opterr;
1660   int optopt;
1661   
1662   package_name = argv[0];
1663   
1664   override = params->override;
1665   initialize = params->initialize;
1666   check_required = params->check_required;
1667   check_ambiguity = params->check_ambiguity;
1668
1669   if (initialize)
1670     RNAup_cmdline_parser_init (args_info);
1671
1672   RNAup_cmdline_parser_init (&local_args_info);
1673
1674   optarg = 0;
1675   optind = 0;
1676   opterr = params->print_errors;
1677   optopt = '?';
1678
1679   while (1)
1680     {
1681       int option_index = 0;
1682
1683       static struct option long_options[] = {
1684         { "help",       0, NULL, 'h' },
1685         { "detailed-help",      0, NULL, 0 },
1686         { "full-help",  0, NULL, 0 },
1687         { "version",    0, NULL, 'V' },
1688         { "constraint", 0, NULL, 'C' },
1689         { "no_output_file",     0, NULL, 'o' },
1690         { "no_header",  0, NULL, 0 },
1691         { "noconv",     0, NULL, 0 },
1692         { "ulength",    1, NULL, 'u' },
1693         { "contributions",      1, NULL, 'c' },
1694         { "window",     1, NULL, 'w' },
1695         { "include_both",       0, NULL, 'b' },
1696         { "extend5",    1, NULL, '5' },
1697         { "extend3",    1, NULL, '3' },
1698         { "interaction_pairwise",       0, NULL, 0 },
1699         { "interaction_first",  0, NULL, 0 },
1700         { "pfScale",    1, NULL, 'S' },
1701         { "temp",       1, NULL, 'T' },
1702         { "noTetra",    0, NULL, '4' },
1703         { "dangles",    1, NULL, 'd' },
1704         { "noLP",       0, NULL, 0 },
1705         { "noGU",       0, NULL, 0 },
1706         { "noClosingGU",        0, NULL, 0 },
1707         { "paramFile",  1, NULL, 'P' },
1708         { "nsp",        1, NULL, 0 },
1709         { "energyModel",        1, NULL, 'e' },
1710         { 0,  0, 0, 0 }
1711       };
1712
1713       custom_optarg = optarg;
1714       custom_optind = optind;
1715       custom_opterr = opterr;
1716       custom_optopt = optopt;
1717
1718       c = custom_getopt_long (argc, argv, "hVCou:c:w:b5:3:S:T:4d:P:e:", long_options, &option_index);
1719
1720       optarg = custom_optarg;
1721       optind = custom_optind;
1722       opterr = custom_opterr;
1723       optopt = custom_optopt;
1724
1725       if (c == -1) break;       /* Exit from `while (1)' loop.  */
1726
1727       switch (c)
1728         {
1729         case 'h':       /* Print help and exit.  */
1730           RNAup_cmdline_parser_print_help ();
1731           RNAup_cmdline_parser_free (&local_args_info);
1732           exit (EXIT_SUCCESS);
1733
1734         case 'V':       /* Print version and exit.  */
1735           RNAup_cmdline_parser_print_version ();
1736           RNAup_cmdline_parser_free (&local_args_info);
1737           exit (EXIT_SUCCESS);
1738
1739         case 'C':       /* Calculate structures subject to constraints.
1740 .  */
1741         
1742         
1743           if (update_arg((void *)&(args_info->constraint_flag), 0, &(args_info->constraint_given),
1744               &(local_args_info.constraint_given), optarg, 0, 0, ARG_FLAG,
1745               check_ambiguity, override, 1, 0, "constraint", 'C',
1746               additional_error))
1747             goto failure;
1748         
1749           break;
1750         case 'o':       /* Do not produce an output file
1751         
1752 .  */
1753         
1754         
1755           if (update_arg((void *)&(args_info->no_output_file_flag), 0, &(args_info->no_output_file_given),
1756               &(local_args_info.no_output_file_given), optarg, 0, 0, ARG_FLAG,
1757               check_ambiguity, override, 1, 0, "no_output_file", 'o',
1758               additional_error))
1759             goto failure;
1760         
1761           break;
1762         case 'u':       /* specifies the length of the unstructured region in the output.
1763 .  */
1764         
1765           if (update_multiple_arg_temp(&ulength_list, 
1766               &(local_args_info.ulength_given), optarg, 0, "4", ARG_STRING,
1767               "ulength", 'u',
1768               additional_error))
1769             goto failure;
1770         
1771           break;
1772         case 'c':       /* Specify the contributions listed in the output
1773 .  */
1774         
1775         
1776           if (update_arg( (void *)&(args_info->contributions_arg), 
1777                &(args_info->contributions_orig), &(args_info->contributions_given),
1778               &(local_args_info.contributions_given), optarg, 0, "S", ARG_STRING,
1779               check_ambiguity, override, 0, 0,
1780               "contributions", 'c',
1781               additional_error))
1782             goto failure;
1783         
1784           break;
1785         case 'w':       /* Determine the maximal length of the region of interaction
1786         
1787 .  */
1788         
1789         
1790           if (update_arg( (void *)&(args_info->window_arg), 
1791                &(args_info->window_orig), &(args_info->window_given),
1792               &(local_args_info.window_given), optarg, 0, "25", ARG_INT,
1793               check_ambiguity, override, 0, 0,
1794               "window", 'w',
1795               additional_error))
1796             goto failure;
1797         
1798           break;
1799         case 'b':       /* Include the probability of unpaired regions in both (b) RNAs. By default
1800         only the probability of being unpaired in the longer RNA (target) is used.
1801         
1802 .  */
1803         
1804         
1805           if (update_arg((void *)&(args_info->include_both_flag), 0, &(args_info->include_both_given),
1806               &(local_args_info.include_both_given), optarg, 0, 0, ARG_FLAG,
1807               check_ambiguity, override, 1, 0, "include_both", 'b',
1808               additional_error))
1809             goto failure;
1810         
1811           break;
1812         case '5':       /* Extend the region of interaction in the target to some residues on the 5' side
1813 .  */
1814         
1815         
1816           if (update_arg( (void *)&(args_info->extend5_arg), 
1817                &(args_info->extend5_orig), &(args_info->extend5_given),
1818               &(local_args_info.extend5_given), optarg, 0, 0, ARG_INT,
1819               check_ambiguity, override, 0, 0,
1820               "extend5", '5',
1821               additional_error))
1822             goto failure;
1823         
1824           break;
1825         case '3':       /* Extend the region of interaction in the target to some residues on the 3' side
1826 .  */
1827         
1828         
1829           if (update_arg( (void *)&(args_info->extend3_arg), 
1830                &(args_info->extend3_orig), &(args_info->extend3_given),
1831               &(local_args_info.extend3_given), optarg, 0, 0, ARG_INT,
1832               check_ambiguity, override, 0, 0,
1833               "extend3", '3',
1834               additional_error))
1835             goto failure;
1836         
1837           break;
1838         case 'S':       /* In the calculation of the pf use scale*mfe as an estimate for the ensemble free energy (used to avoid overflows). The default is 1.07, useful values are 1.0 to 1.2. Occasionally needed for long sequences.
1839         You can also recompile the program to use double precision (see the README file).
1840         
1841 .  */
1842         
1843         
1844           if (update_arg( (void *)&(args_info->pfScale_arg), 
1845                &(args_info->pfScale_orig), &(args_info->pfScale_given),
1846               &(local_args_info.pfScale_given), optarg, 0, 0, ARG_DOUBLE,
1847               check_ambiguity, override, 0, 0,
1848               "pfScale", 'S',
1849               additional_error))
1850             goto failure;
1851         
1852           break;
1853         case 'T':       /* Rescale energy parameters to a temperature of temp C. Default is 37C.
1854         
1855 .  */
1856         
1857         
1858           if (update_arg( (void *)&(args_info->temp_arg), 
1859                &(args_info->temp_orig), &(args_info->temp_given),
1860               &(local_args_info.temp_given), optarg, 0, 0, ARG_DOUBLE,
1861               check_ambiguity, override, 0, 0,
1862               "temp", 'T',
1863               additional_error))
1864             goto failure;
1865         
1866           break;
1867         case '4':       /* Do not include special tabulated stabilizing energies for tri-, tetra- and hexaloop hairpins. Mostly for testing.
1868         
1869 .  */
1870         
1871         
1872           if (update_arg((void *)&(args_info->noTetra_flag), 0, &(args_info->noTetra_given),
1873               &(local_args_info.noTetra_given), optarg, 0, 0, ARG_FLAG,
1874               check_ambiguity, override, 1, 0, "noTetra", '4',
1875               additional_error))
1876             goto failure;
1877         
1878           break;
1879         case 'd':       /* How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops
1880 .  */
1881         
1882         
1883           if (update_arg( (void *)&(args_info->dangles_arg), 
1884                &(args_info->dangles_orig), &(args_info->dangles_given),
1885               &(local_args_info.dangles_given), optarg, 0, "2", ARG_INT,
1886               check_ambiguity, override, 0, 0,
1887               "dangles", 'd',
1888               additional_error))
1889             goto failure;
1890         
1891           break;
1892         case 'P':       /* Read energy parameters from paramfile, instead of using the default parameter set.
1893 .  */
1894         
1895         
1896           if (update_arg( (void *)&(args_info->paramFile_arg), 
1897                &(args_info->paramFile_orig), &(args_info->paramFile_given),
1898               &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1899               check_ambiguity, override, 0, 0,
1900               "paramFile", 'P',
1901               additional_error))
1902             goto failure;
1903         
1904           break;
1905         case 'e':       /* Rarely used option to fold sequences from the artificial ABCD... alphabet, where A pairs B, C-D etc.  Use the energy parameters for GC (-e 1) or AU (-e 2) pairs.
1906         
1907 .  */
1908         
1909         
1910           if (update_arg( (void *)&(args_info->energyModel_arg), 
1911                &(args_info->energyModel_orig), &(args_info->energyModel_given),
1912               &(local_args_info.energyModel_given), optarg, 0, 0, ARG_INT,
1913               check_ambiguity, override, 0, 0,
1914               "energyModel", 'e',
1915               additional_error))
1916             goto failure;
1917         
1918           break;
1919
1920         case 0: /* Long option with no short option */
1921           if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1922             RNAup_cmdline_parser_print_detailed_help ();
1923             RNAup_cmdline_parser_free (&local_args_info);
1924             exit (EXIT_SUCCESS);
1925           }
1926
1927           if (strcmp (long_options[option_index].name, "full-help") == 0) {
1928             RNAup_cmdline_parser_print_full_help ();
1929             RNAup_cmdline_parser_free (&local_args_info);
1930             exit (EXIT_SUCCESS);
1931           }
1932
1933           /* Do not produce a header with the command line parameters used in the outputfile
1934           
1935 .  */
1936           if (strcmp (long_options[option_index].name, "no_header") == 0)
1937           {
1938           
1939           
1940             if (update_arg((void *)&(args_info->no_header_flag), 0, &(args_info->no_header_given),
1941                 &(local_args_info.no_header_given), optarg, 0, 0, ARG_FLAG,
1942                 check_ambiguity, override, 1, 0, "no_header", '-',
1943                 additional_error))
1944               goto failure;
1945           
1946           }
1947           /* Do not automatically substitude nucleotide \"T\" with \"U\"
1948           
1949 .  */
1950           else if (strcmp (long_options[option_index].name, "noconv") == 0)
1951           {
1952           
1953           
1954             if (update_arg((void *)&(args_info->noconv_flag), 0, &(args_info->noconv_given),
1955                 &(local_args_info.noconv_given), optarg, 0, 0, ARG_FLAG,
1956                 check_ambiguity, override, 1, 0, "noconv", '-',
1957                 additional_error))
1958               goto failure;
1959           
1960           }
1961           /* Activate pairwise interaction mode
1962 .  */
1963           else if (strcmp (long_options[option_index].name, "interaction_pairwise") == 0)
1964           {
1965           
1966           
1967             if (update_arg((void *)&(args_info->interaction_pairwise_flag), 0, &(args_info->interaction_pairwise_given),
1968                 &(local_args_info.interaction_pairwise_given), optarg, 0, 0, ARG_FLAG,
1969                 check_ambiguity, override, 1, 0, "interaction_pairwise", '-',
1970                 additional_error))
1971               goto failure;
1972           
1973           }
1974           /* Activate interaction mode using first sequence only
1975 .  */
1976           else if (strcmp (long_options[option_index].name, "interaction_first") == 0)
1977           {
1978           
1979           
1980             if (update_arg((void *)&(args_info->interaction_first_flag), 0, &(args_info->interaction_first_given),
1981                 &(local_args_info.interaction_first_given), optarg, 0, 0, ARG_FLAG,
1982                 check_ambiguity, override, 1, 0, "interaction_first", '-',
1983                 additional_error))
1984               goto failure;
1985           
1986           }
1987           /* Produce structures without lonely pairs (helices of length 1).
1988 .  */
1989           else if (strcmp (long_options[option_index].name, "noLP") == 0)
1990           {
1991           
1992           
1993             if (update_arg((void *)&(args_info->noLP_flag), 0, &(args_info->noLP_given),
1994                 &(local_args_info.noLP_given), optarg, 0, 0, ARG_FLAG,
1995                 check_ambiguity, override, 1, 0, "noLP", '-',
1996                 additional_error))
1997               goto failure;
1998           
1999           }
2000           /* Do not allow GU pairs
2001           
2002 .  */
2003           else if (strcmp (long_options[option_index].name, "noGU") == 0)
2004           {
2005           
2006           
2007             if (update_arg((void *)&(args_info->noGU_flag), 0, &(args_info->noGU_given),
2008                 &(local_args_info.noGU_given), optarg, 0, 0, ARG_FLAG,
2009                 check_ambiguity, override, 1, 0, "noGU", '-',
2010                 additional_error))
2011               goto failure;
2012           
2013           }
2014           /* Do not allow GU pairs at the end of helices
2015           
2016 .  */
2017           else if (strcmp (long_options[option_index].name, "noClosingGU") == 0)
2018           {
2019           
2020           
2021             if (update_arg((void *)&(args_info->noClosingGU_flag), 0, &(args_info->noClosingGU_given),
2022                 &(local_args_info.noClosingGU_given), optarg, 0, 0, ARG_FLAG,
2023                 check_ambiguity, override, 1, 0, "noClosingGU", '-',
2024                 additional_error))
2025               goto failure;
2026           
2027           }
2028           /* Allow other pairs in addition to the usual AU,GC,and GU pairs.
2029 .  */
2030           else if (strcmp (long_options[option_index].name, "nsp") == 0)
2031           {
2032           
2033           
2034             if (update_arg( (void *)&(args_info->nsp_arg), 
2035                  &(args_info->nsp_orig), &(args_info->nsp_given),
2036                 &(local_args_info.nsp_given), optarg, 0, 0, ARG_STRING,
2037                 check_ambiguity, override, 0, 0,
2038                 "nsp", '-',
2039                 additional_error))
2040               goto failure;
2041           
2042           }
2043           
2044           break;
2045         case '?':       /* Invalid option.  */
2046           /* `getopt_long' already printed an error message.  */
2047           goto failure;
2048
2049         default:        /* bug: option not considered.  */
2050           fprintf (stderr, "%s: option unknown: %c%s\n", RNAUP_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
2051           abort ();
2052         } /* switch */
2053     } /* while */
2054
2055
2056   multiple_default_value.default_string_arg = "4";
2057   update_multiple_arg((void *)&(args_info->ulength_arg),
2058     &(args_info->ulength_orig), args_info->ulength_given,
2059     local_args_info.ulength_given, &multiple_default_value,
2060     ARG_STRING, ulength_list);
2061
2062   args_info->ulength_given += local_args_info.ulength_given;
2063   local_args_info.ulength_given = 0;
2064   
2065   if (check_required)
2066     {
2067       error += RNAup_cmdline_parser_required2 (args_info, argv[0], additional_error);
2068     }
2069
2070   RNAup_cmdline_parser_release (&local_args_info);
2071
2072   if ( error )
2073     return (EXIT_FAILURE);
2074
2075   return 0;
2076
2077 failure:
2078   free_list (ulength_list, 1 );
2079   
2080   RNAup_cmdline_parser_release (&local_args_info);
2081   return (EXIT_FAILURE);
2082 }