Add missing binaty and statis library
[jabaws.git] / binaries / src / ViennaRNA / Progs / RNAalifold_cmdl.c
1 /*
2   File autogenerated by gengetopt version 2.22.5
3   generated with the following command:
4   gengetopt -i RNAalifold.ggo --file-name=RNAalifold_cmdl --include-getopt --default-optional --unamed-opts --func-name=RNAalifold_cmdline_parser --arg-struct-name=RNAalifold_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 "RNAalifold_cmdl.h"
26
27 const char *RNAalifold_args_info_purpose = "calculate secondary structures for a set of aligned RNAs";
28
29 const char *RNAalifold_args_info_usage = "Usage: RNAalifold [options] <file1.aln>";
30
31 const char *RNAalifold_args_info_description = "Read aligned RNA sequences from stdin or file.aln and calculate their minimum \nfree energy (mfe) structure, partition function (pf) and base pairing \nprobability matrix. Currently, the input alignment has to be in CLUSTAL format. \nIt returns the mfe structure in bracket notation, its energy, the free energy \nof the thermodynamic ensemble and the frequency of the mfe structure in the \nensemble to stdout.  It also produces Postscript files with plots of the \nresulting secondary structure graph (\"alirna.ps\") and a \"dot plot\" of the \nbase pairing matrix (\"alidot.ps\"). The file \"alifold.out\" will contain a \nlist of likely pairs sorted by credibility, suitable for viewing  with \n\"AliDot.pl\". Be warned that output file will overwrite any existing files of \nthe same name.\n\n";
32
33 const char *RNAalifold_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                                  The constraining structure will be read from \n                                  'stdin', the alignment has to be given as a \n                                  file name on the command line.\n                                    (default=off)",
41   "  The program reads first the sequence, then a string containing constraints on \n  the structure encoded with the symbols:\n\n  . (no constraint for this base)\n\n  | (the corresponding base has to be paired\n\n  x (the base is unpaired)\n\n  < (base i is paired with a base j>i)\n\n  > (base i is paired with a base j<i)\n\n  and matching brackets ( ) (base i pairs base j)\n\n  With the exception of \"|\", constraints will disallow all pairs conflicting \n  with the constraint. This is usually sufficient to enforce the constraint, \n  but occasionally a base may stay unpaired in spite of constraints. PF folding \n  ignores constraints of type \"|\".\n\n",
42   "      --color                   Produce a colored version of the consensus \n                                  strcture plot \"alirna.ps\" (default b&w \n                                  only)\n\n                                    (default=off)",
43   "      --aln                     Produce a colored and structure annotated \n                                  alignment in PostScript format in the file \n                                  \"aln.ps\" in the current directory.\n\n                                    (default=off)",
44   "      --noPS                    Do not produce postscript output\n\n                                    (default=off)",
45   "\nAlgorithms:",
46   "  Select additional algorithms which should be included in the calculations.\n  The Minimum free energy (MFE) and a structure representative are calculated \n  in any case.\n\n",
47   "  -p, --partfunc[=INT]          Calculate the partition function and base \n                                  pairing probability matrix in addition to the \n                                  mfe structure. Default is calculation of mfe \n                                  structure only.\n                                    (default=`1')",
48   "  In addition to the MFE structure we print a coarse representation of the pair \n  probabilities in form of a pseudo bracket notation, followed by the ensemble \n  free energy, as well as the centroid structure derived from the pair \n  probabilities together with its free energy and distance to the ensemble. \n  Finally it prints the frequency of the mfe structure.\n\n  An additionally passed value to this option changes the behavior of partition \n  function calculation:\n  -p0 deactivates the calculation of the pair probabilities, saving about 50% \n  in runtime. This prints the ensemble free energy -kT ln(Z).\n\n",
49   "      --MEA[=gamma]             Calculate an MEA (maximum expected accuracy) \n                                  structure.\n                                    (default=`1.')",
50   "  If gamma is not specified a default of gamma=1 is used.\n  Using --MEA implies -p\n  See also RNAfold man page for details.\n\n",
51   "      --mis                     Output \"most informative sequence\" instead of \n                                  simple consensus: For each column of the \n                                  alignment output the set of nucleotides with \n                                  frequence greater than average in IUPAC \n                                  notation.\n\n                                    (default=off)",
52   "  -s, --stochBT=INT             Stochastic backtrack. Compute a certain number \n                                  of random structures with a probability \n                                  dependend on the partition function. See -p \n                                  option in RNAsubopt.\n\n",
53   "      --stochBT_en=INT          same as \"-s\" but also print out the energies \n                                  and probabilities of the backtraced \n                                  structures.\n\n",
54   "  -S, --pfScale=scaling factor  In the calculation of the pf use scale*mfe as \n                                  an estimate for the ensemble free energy \n                                  (used to avoid overflows).\n",
55   "  The default is 1.07, useful values are 1.0 to 1.2. Occasionally needed for \n  long sequences.\n  You can also recompile the program to use double precision (see the README \n  file).\n\n",
56   "  -c, --circ                    Assume a circular (instead of linear) RNA \n                                  molecule.\n\n                                    (default=off)",
57   "      --bppmThreshold=<value>   Set the threshold for base pair probabilities \n                                  included in the postscript output\n                                    (default=`1e-6')",
58   "  By setting the threshold the base pair probabilities that are included in the \n  output can be varied. By default only those exceeding 1e-5 in probability \n  will be shown as squares in the dot plot. Changing the threshold to any other \n  value allows for increase or decrease of data.\n\n",
59   "  -g, --gquad                   Incoorporate G-Quadruplex formation into the \n                                  structure prediction algorithm\n                                    (default=off)",
60   "\nModel Details:",
61   "  -T, --temp=DOUBLE             Rescale energy parameters to a temperature of \n                                  temp C. Default is 37C.\n\n",
62   "  -4, --noTetra                 Do not include special tabulated stabilizing \n                                  energies for tri-, tetra- and hexaloop \n                                  hairpins. Mostly for testing.\n\n                                    (default=off)",
63   "  -d, --dangles=INT             How to treat \"dangling end\" energies for \n                                  bases adjacent to helices in free ends and \n                                  multi-loops\n                                    (default=`2')",
64   "  \n  With -d2 dangling energies will be added for the bases adjacent to a helix on \n  both sides\n   in any case.\n  The option -d0 ignores dangling ends altogether (mostly for debugging).\n\n",
65   "      --noLP                    Produce structures without lonely pairs \n                                  (helices of length 1).\n                                    (default=off)",
66   "  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",
67   "      --noGU                    Do not allow GU pairs\n\n                                    (default=off)",
68   "      --noClosingGU             Do not allow GU pairs at the end of helices\n\n                                    (default=off)",
69   "      --cfactor=DOUBLE          Set the weight of the covariance term in the \n                                  energy function\n\n                                    (default=`1.0')",
70   "      --nfactor=DOUBLE          Set the penalty for non-compatible sequences in \n                                  the covariance term of the energy function\n\n                                    (default=`1.0')",
71   "  -E, --endgaps                 Score pairs with endgaps same as gap-gap pairs.\n\n                                    (default=off)",
72   "  -R, --ribosum_file=ribosumfile\n                                use specified Ribosum Matrix instead of normal \n                                  energy model. Matrixes to use should be 6x6 \n                                  matrices, the order of the terms is AU, CG, \n                                  GC, GU, UA, UG.\n\n",
73   "  -r, --ribosum_scoring         use ribosum scoring matrix. The matrix is \n                                  chosen according to the minimal and maximal \n                                  pairwise identities of the sequences in the \n                                  file.\n\n                                    (default=off)",
74   "      --old                     use old energy evaluation, treating gaps as \n                                  characters.\n\n                                    (default=off)",
75   "  -P, --paramFile=paramfile     Read energy parameters from paramfile, instead \n                                  of using the default parameter set.\n",
76   "  A sample parameter file should accompany your distribution.\n  See the RNAlib documentation for details on the file format.\n\n",
77   "      --nsp=STRING              Allow other pairs in addition to the usual \n                                  AU,GC,and GU pairs.\n",
78   "  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",
79   "  -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 \n                                  (-e 1) or AU (-e 2) pairs.\n\n",
80   "      --betaScale=DOUBLE        Set the scaling of the Boltzmann factors\n                                    (default=`1.')",
81   "  The argument provided with this option enables to scale the thermodynamic \n  temperature used in the Boltzmann factors independently from the temperature \n  used to scale the individual energy contributions of the loop types. The \n  Boltzmann factors then become exp(-dG/(kTn*betaScale)) where k is the \n  Boltzmann constant, dG the free energy contribution of the state, T the \n  absolute temperature and n the number of sequences.\n\n",
82   "Caveats:\n\nSequences are not weighted. If possible, do not mix very similar and dissimilar \nsequences. Duplicate sequences, for example, can distort the prediction.\n\n\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
83     0
84 };
85 static void
86 init_full_help_array(void)
87 {
88   RNAalifold_args_info_full_help[0] = RNAalifold_args_info_detailed_help[0];
89   RNAalifold_args_info_full_help[1] = RNAalifold_args_info_detailed_help[1];
90   RNAalifold_args_info_full_help[2] = RNAalifold_args_info_detailed_help[2];
91   RNAalifold_args_info_full_help[3] = RNAalifold_args_info_detailed_help[3];
92   RNAalifold_args_info_full_help[4] = RNAalifold_args_info_detailed_help[4];
93   RNAalifold_args_info_full_help[5] = RNAalifold_args_info_detailed_help[5];
94   RNAalifold_args_info_full_help[6] = RNAalifold_args_info_detailed_help[6];
95   RNAalifold_args_info_full_help[7] = RNAalifold_args_info_detailed_help[8];
96   RNAalifold_args_info_full_help[8] = RNAalifold_args_info_detailed_help[9];
97   RNAalifold_args_info_full_help[9] = RNAalifold_args_info_detailed_help[10];
98   RNAalifold_args_info_full_help[10] = RNAalifold_args_info_detailed_help[11];
99   RNAalifold_args_info_full_help[11] = RNAalifold_args_info_detailed_help[12];
100   RNAalifold_args_info_full_help[12] = RNAalifold_args_info_detailed_help[13];
101   RNAalifold_args_info_full_help[13] = RNAalifold_args_info_detailed_help[15];
102   RNAalifold_args_info_full_help[14] = RNAalifold_args_info_detailed_help[17];
103   RNAalifold_args_info_full_help[15] = RNAalifold_args_info_detailed_help[18];
104   RNAalifold_args_info_full_help[16] = RNAalifold_args_info_detailed_help[19];
105   RNAalifold_args_info_full_help[17] = RNAalifold_args_info_detailed_help[20];
106   RNAalifold_args_info_full_help[18] = RNAalifold_args_info_detailed_help[22];
107   RNAalifold_args_info_full_help[19] = RNAalifold_args_info_detailed_help[23];
108   RNAalifold_args_info_full_help[20] = RNAalifold_args_info_detailed_help[25];
109   RNAalifold_args_info_full_help[21] = RNAalifold_args_info_detailed_help[26];
110   RNAalifold_args_info_full_help[22] = RNAalifold_args_info_detailed_help[27];
111   RNAalifold_args_info_full_help[23] = RNAalifold_args_info_detailed_help[28];
112   RNAalifold_args_info_full_help[24] = RNAalifold_args_info_detailed_help[29];
113   RNAalifold_args_info_full_help[25] = RNAalifold_args_info_detailed_help[31];
114   RNAalifold_args_info_full_help[26] = RNAalifold_args_info_detailed_help[33];
115   RNAalifold_args_info_full_help[27] = RNAalifold_args_info_detailed_help[34];
116   RNAalifold_args_info_full_help[28] = RNAalifold_args_info_detailed_help[35];
117   RNAalifold_args_info_full_help[29] = RNAalifold_args_info_detailed_help[36];
118   RNAalifold_args_info_full_help[30] = RNAalifold_args_info_detailed_help[37];
119   RNAalifold_args_info_full_help[31] = RNAalifold_args_info_detailed_help[38];
120   RNAalifold_args_info_full_help[32] = RNAalifold_args_info_detailed_help[39];
121   RNAalifold_args_info_full_help[33] = RNAalifold_args_info_detailed_help[40];
122   RNAalifold_args_info_full_help[34] = RNAalifold_args_info_detailed_help[41];
123   RNAalifold_args_info_full_help[35] = RNAalifold_args_info_detailed_help[43];
124   RNAalifold_args_info_full_help[36] = RNAalifold_args_info_detailed_help[45];
125   RNAalifold_args_info_full_help[37] = RNAalifold_args_info_detailed_help[46];
126   RNAalifold_args_info_full_help[38] = RNAalifold_args_info_detailed_help[48];
127   RNAalifold_args_info_full_help[39] = 0; 
128   
129 }
130
131 const char *RNAalifold_args_info_full_help[40];
132
133 static void
134 init_help_array(void)
135 {
136   RNAalifold_args_info_help[0] = RNAalifold_args_info_detailed_help[0];
137   RNAalifold_args_info_help[1] = RNAalifold_args_info_detailed_help[1];
138   RNAalifold_args_info_help[2] = RNAalifold_args_info_detailed_help[2];
139   RNAalifold_args_info_help[3] = RNAalifold_args_info_detailed_help[3];
140   RNAalifold_args_info_help[4] = RNAalifold_args_info_detailed_help[4];
141   RNAalifold_args_info_help[5] = RNAalifold_args_info_detailed_help[5];
142   RNAalifold_args_info_help[6] = RNAalifold_args_info_detailed_help[6];
143   RNAalifold_args_info_help[7] = RNAalifold_args_info_detailed_help[8];
144   RNAalifold_args_info_help[8] = RNAalifold_args_info_detailed_help[9];
145   RNAalifold_args_info_help[9] = RNAalifold_args_info_detailed_help[10];
146   RNAalifold_args_info_help[10] = RNAalifold_args_info_detailed_help[11];
147   RNAalifold_args_info_help[11] = RNAalifold_args_info_detailed_help[12];
148   RNAalifold_args_info_help[12] = RNAalifold_args_info_detailed_help[13];
149   RNAalifold_args_info_help[13] = RNAalifold_args_info_detailed_help[15];
150   RNAalifold_args_info_help[14] = RNAalifold_args_info_detailed_help[17];
151   RNAalifold_args_info_help[15] = RNAalifold_args_info_detailed_help[18];
152   RNAalifold_args_info_help[16] = RNAalifold_args_info_detailed_help[19];
153   RNAalifold_args_info_help[17] = RNAalifold_args_info_detailed_help[22];
154   RNAalifold_args_info_help[18] = RNAalifold_args_info_detailed_help[25];
155   RNAalifold_args_info_help[19] = RNAalifold_args_info_detailed_help[26];
156   RNAalifold_args_info_help[20] = RNAalifold_args_info_detailed_help[27];
157   RNAalifold_args_info_help[21] = RNAalifold_args_info_detailed_help[28];
158   RNAalifold_args_info_help[22] = RNAalifold_args_info_detailed_help[29];
159   RNAalifold_args_info_help[23] = RNAalifold_args_info_detailed_help[31];
160   RNAalifold_args_info_help[24] = RNAalifold_args_info_detailed_help[33];
161   RNAalifold_args_info_help[25] = RNAalifold_args_info_detailed_help[34];
162   RNAalifold_args_info_help[26] = RNAalifold_args_info_detailed_help[35];
163   RNAalifold_args_info_help[27] = RNAalifold_args_info_detailed_help[36];
164   RNAalifold_args_info_help[28] = RNAalifold_args_info_detailed_help[37];
165   RNAalifold_args_info_help[29] = RNAalifold_args_info_detailed_help[38];
166   RNAalifold_args_info_help[30] = RNAalifold_args_info_detailed_help[39];
167   RNAalifold_args_info_help[31] = RNAalifold_args_info_detailed_help[40];
168   RNAalifold_args_info_help[32] = RNAalifold_args_info_detailed_help[41];
169   RNAalifold_args_info_help[33] = RNAalifold_args_info_detailed_help[48];
170   RNAalifold_args_info_help[34] = 0; 
171   
172 }
173
174 const char *RNAalifold_args_info_help[35];
175
176 typedef enum {ARG_NO
177   , ARG_FLAG
178   , ARG_STRING
179   , ARG_INT
180   , ARG_FLOAT
181   , ARG_DOUBLE
182 } RNAalifold_cmdline_parser_arg_type;
183
184 static
185 void clear_given (struct RNAalifold_args_info *args_info);
186 static
187 void clear_args (struct RNAalifold_args_info *args_info);
188
189 static int
190 RNAalifold_cmdline_parser_internal (int argc, char **argv, struct RNAalifold_args_info *args_info,
191                         struct RNAalifold_cmdline_parser_params *params, const char *additional_error);
192
193 static int
194 RNAalifold_cmdline_parser_required2 (struct RNAalifold_args_info *args_info, const char *prog_name, const char *additional_error);
195
196 static char *
197 gengetopt_strdup (const char *s);
198
199 static
200 void clear_given (struct RNAalifold_args_info *args_info)
201 {
202   args_info->help_given = 0 ;
203   args_info->detailed_help_given = 0 ;
204   args_info->full_help_given = 0 ;
205   args_info->version_given = 0 ;
206   args_info->constraint_given = 0 ;
207   args_info->color_given = 0 ;
208   args_info->aln_given = 0 ;
209   args_info->noPS_given = 0 ;
210   args_info->partfunc_given = 0 ;
211   args_info->MEA_given = 0 ;
212   args_info->mis_given = 0 ;
213   args_info->stochBT_given = 0 ;
214   args_info->stochBT_en_given = 0 ;
215   args_info->pfScale_given = 0 ;
216   args_info->circ_given = 0 ;
217   args_info->bppmThreshold_given = 0 ;
218   args_info->gquad_given = 0 ;
219   args_info->temp_given = 0 ;
220   args_info->noTetra_given = 0 ;
221   args_info->dangles_given = 0 ;
222   args_info->noLP_given = 0 ;
223   args_info->noGU_given = 0 ;
224   args_info->noClosingGU_given = 0 ;
225   args_info->cfactor_given = 0 ;
226   args_info->nfactor_given = 0 ;
227   args_info->endgaps_given = 0 ;
228   args_info->ribosum_file_given = 0 ;
229   args_info->ribosum_scoring_given = 0 ;
230   args_info->old_given = 0 ;
231   args_info->paramFile_given = 0 ;
232   args_info->nsp_given = 0 ;
233   args_info->energyModel_given = 0 ;
234   args_info->betaScale_given = 0 ;
235 }
236
237 static
238 void clear_args (struct RNAalifold_args_info *args_info)
239 {
240   FIX_UNUSED (args_info);
241   args_info->constraint_flag = 0;
242   args_info->color_flag = 0;
243   args_info->aln_flag = 0;
244   args_info->noPS_flag = 0;
245   args_info->partfunc_arg = 1;
246   args_info->partfunc_orig = NULL;
247   args_info->MEA_arg = 1.;
248   args_info->MEA_orig = NULL;
249   args_info->mis_flag = 0;
250   args_info->stochBT_orig = NULL;
251   args_info->stochBT_en_orig = NULL;
252   args_info->pfScale_orig = NULL;
253   args_info->circ_flag = 0;
254   args_info->bppmThreshold_arg = 1e-6;
255   args_info->bppmThreshold_orig = NULL;
256   args_info->gquad_flag = 0;
257   args_info->temp_orig = NULL;
258   args_info->noTetra_flag = 0;
259   args_info->dangles_arg = 2;
260   args_info->dangles_orig = NULL;
261   args_info->noLP_flag = 0;
262   args_info->noGU_flag = 0;
263   args_info->noClosingGU_flag = 0;
264   args_info->cfactor_arg = 1.0;
265   args_info->cfactor_orig = NULL;
266   args_info->nfactor_arg = 1.0;
267   args_info->nfactor_orig = NULL;
268   args_info->endgaps_flag = 0;
269   args_info->ribosum_file_arg = NULL;
270   args_info->ribosum_file_orig = NULL;
271   args_info->ribosum_scoring_flag = 0;
272   args_info->old_flag = 0;
273   args_info->paramFile_arg = NULL;
274   args_info->paramFile_orig = NULL;
275   args_info->nsp_arg = NULL;
276   args_info->nsp_orig = NULL;
277   args_info->energyModel_orig = NULL;
278   args_info->betaScale_arg = 1.;
279   args_info->betaScale_orig = NULL;
280   
281 }
282
283 static
284 void init_args_info(struct RNAalifold_args_info *args_info)
285 {
286   init_full_help_array(); 
287   init_help_array(); 
288   args_info->help_help = RNAalifold_args_info_detailed_help[0] ;
289   args_info->detailed_help_help = RNAalifold_args_info_detailed_help[1] ;
290   args_info->full_help_help = RNAalifold_args_info_detailed_help[2] ;
291   args_info->version_help = RNAalifold_args_info_detailed_help[3] ;
292   args_info->constraint_help = RNAalifold_args_info_detailed_help[6] ;
293   args_info->color_help = RNAalifold_args_info_detailed_help[8] ;
294   args_info->aln_help = RNAalifold_args_info_detailed_help[9] ;
295   args_info->noPS_help = RNAalifold_args_info_detailed_help[10] ;
296   args_info->partfunc_help = RNAalifold_args_info_detailed_help[13] ;
297   args_info->MEA_help = RNAalifold_args_info_detailed_help[15] ;
298   args_info->mis_help = RNAalifold_args_info_detailed_help[17] ;
299   args_info->stochBT_help = RNAalifold_args_info_detailed_help[18] ;
300   args_info->stochBT_en_help = RNAalifold_args_info_detailed_help[19] ;
301   args_info->pfScale_help = RNAalifold_args_info_detailed_help[20] ;
302   args_info->circ_help = RNAalifold_args_info_detailed_help[22] ;
303   args_info->bppmThreshold_help = RNAalifold_args_info_detailed_help[23] ;
304   args_info->gquad_help = RNAalifold_args_info_detailed_help[25] ;
305   args_info->temp_help = RNAalifold_args_info_detailed_help[27] ;
306   args_info->noTetra_help = RNAalifold_args_info_detailed_help[28] ;
307   args_info->dangles_help = RNAalifold_args_info_detailed_help[29] ;
308   args_info->noLP_help = RNAalifold_args_info_detailed_help[31] ;
309   args_info->noGU_help = RNAalifold_args_info_detailed_help[33] ;
310   args_info->noClosingGU_help = RNAalifold_args_info_detailed_help[34] ;
311   args_info->cfactor_help = RNAalifold_args_info_detailed_help[35] ;
312   args_info->nfactor_help = RNAalifold_args_info_detailed_help[36] ;
313   args_info->endgaps_help = RNAalifold_args_info_detailed_help[37] ;
314   args_info->ribosum_file_help = RNAalifold_args_info_detailed_help[38] ;
315   args_info->ribosum_scoring_help = RNAalifold_args_info_detailed_help[39] ;
316   args_info->old_help = RNAalifold_args_info_detailed_help[40] ;
317   args_info->paramFile_help = RNAalifold_args_info_detailed_help[41] ;
318   args_info->nsp_help = RNAalifold_args_info_detailed_help[43] ;
319   args_info->energyModel_help = RNAalifold_args_info_detailed_help[45] ;
320   args_info->betaScale_help = RNAalifold_args_info_detailed_help[46] ;
321   
322 }
323
324 void
325 RNAalifold_cmdline_parser_print_version (void)
326 {
327   printf ("%s %s\n",
328      (strlen(RNAALIFOLD_CMDLINE_PARSER_PACKAGE_NAME) ? RNAALIFOLD_CMDLINE_PARSER_PACKAGE_NAME : RNAALIFOLD_CMDLINE_PARSER_PACKAGE),
329      RNAALIFOLD_CMDLINE_PARSER_VERSION);
330 }
331
332 static void print_help_common(void) {
333   RNAalifold_cmdline_parser_print_version ();
334
335   if (strlen(RNAalifold_args_info_purpose) > 0)
336     printf("\n%s\n", RNAalifold_args_info_purpose);
337
338   if (strlen(RNAalifold_args_info_usage) > 0)
339     printf("\n%s\n", RNAalifold_args_info_usage);
340
341   printf("\n");
342
343   if (strlen(RNAalifold_args_info_description) > 0)
344     printf("%s\n\n", RNAalifold_args_info_description);
345 }
346
347 void
348 RNAalifold_cmdline_parser_print_help (void)
349 {
350   int i = 0;
351   print_help_common();
352   while (RNAalifold_args_info_help[i])
353     printf("%s\n", RNAalifold_args_info_help[i++]);
354 }
355
356 void
357 RNAalifold_cmdline_parser_print_full_help (void)
358 {
359   int i = 0;
360   print_help_common();
361   while (RNAalifold_args_info_full_help[i])
362     printf("%s\n", RNAalifold_args_info_full_help[i++]);
363 }
364
365 void
366 RNAalifold_cmdline_parser_print_detailed_help (void)
367 {
368   int i = 0;
369   print_help_common();
370   while (RNAalifold_args_info_detailed_help[i])
371     printf("%s\n", RNAalifold_args_info_detailed_help[i++]);
372 }
373
374 void
375 RNAalifold_cmdline_parser_init (struct RNAalifold_args_info *args_info)
376 {
377   clear_given (args_info);
378   clear_args (args_info);
379   init_args_info (args_info);
380
381   args_info->inputs = 0;
382   args_info->inputs_num = 0;
383 }
384
385 void
386 RNAalifold_cmdline_parser_params_init(struct RNAalifold_cmdline_parser_params *params)
387 {
388   if (params)
389     { 
390       params->override = 0;
391       params->initialize = 1;
392       params->check_required = 1;
393       params->check_ambiguity = 0;
394       params->print_errors = 1;
395     }
396 }
397
398 struct RNAalifold_cmdline_parser_params *
399 RNAalifold_cmdline_parser_params_create(void)
400 {
401   struct RNAalifold_cmdline_parser_params *params = 
402     (struct RNAalifold_cmdline_parser_params *)malloc(sizeof(struct RNAalifold_cmdline_parser_params));
403   RNAalifold_cmdline_parser_params_init(params);  
404   return params;
405 }
406
407 static void
408 free_string_field (char **s)
409 {
410   if (*s)
411     {
412       free (*s);
413       *s = 0;
414     }
415 }
416
417
418 static void
419 RNAalifold_cmdline_parser_release (struct RNAalifold_args_info *args_info)
420 {
421   unsigned int i;
422   free_string_field (&(args_info->partfunc_orig));
423   free_string_field (&(args_info->MEA_orig));
424   free_string_field (&(args_info->stochBT_orig));
425   free_string_field (&(args_info->stochBT_en_orig));
426   free_string_field (&(args_info->pfScale_orig));
427   free_string_field (&(args_info->bppmThreshold_orig));
428   free_string_field (&(args_info->temp_orig));
429   free_string_field (&(args_info->dangles_orig));
430   free_string_field (&(args_info->cfactor_orig));
431   free_string_field (&(args_info->nfactor_orig));
432   free_string_field (&(args_info->ribosum_file_arg));
433   free_string_field (&(args_info->ribosum_file_orig));
434   free_string_field (&(args_info->paramFile_arg));
435   free_string_field (&(args_info->paramFile_orig));
436   free_string_field (&(args_info->nsp_arg));
437   free_string_field (&(args_info->nsp_orig));
438   free_string_field (&(args_info->energyModel_orig));
439   free_string_field (&(args_info->betaScale_orig));
440   
441   
442   for (i = 0; i < args_info->inputs_num; ++i)
443     free (args_info->inputs [i]);
444
445   if (args_info->inputs_num)
446     free (args_info->inputs);
447
448   clear_given (args_info);
449 }
450
451
452 static void
453 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
454 {
455   FIX_UNUSED (values);
456   if (arg) {
457     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
458   } else {
459     fprintf(outfile, "%s\n", opt);
460   }
461 }
462
463
464 int
465 RNAalifold_cmdline_parser_dump(FILE *outfile, struct RNAalifold_args_info *args_info)
466 {
467   int i = 0;
468
469   if (!outfile)
470     {
471       fprintf (stderr, "%s: cannot dump options to stream\n", RNAALIFOLD_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->color_given)
486     write_into_file(outfile, "color", 0, 0 );
487   if (args_info->aln_given)
488     write_into_file(outfile, "aln", 0, 0 );
489   if (args_info->noPS_given)
490     write_into_file(outfile, "noPS", 0, 0 );
491   if (args_info->partfunc_given)
492     write_into_file(outfile, "partfunc", args_info->partfunc_orig, 0);
493   if (args_info->MEA_given)
494     write_into_file(outfile, "MEA", args_info->MEA_orig, 0);
495   if (args_info->mis_given)
496     write_into_file(outfile, "mis", 0, 0 );
497   if (args_info->stochBT_given)
498     write_into_file(outfile, "stochBT", args_info->stochBT_orig, 0);
499   if (args_info->stochBT_en_given)
500     write_into_file(outfile, "stochBT_en", args_info->stochBT_en_orig, 0);
501   if (args_info->pfScale_given)
502     write_into_file(outfile, "pfScale", args_info->pfScale_orig, 0);
503   if (args_info->circ_given)
504     write_into_file(outfile, "circ", 0, 0 );
505   if (args_info->bppmThreshold_given)
506     write_into_file(outfile, "bppmThreshold", args_info->bppmThreshold_orig, 0);
507   if (args_info->gquad_given)
508     write_into_file(outfile, "gquad", 0, 0 );
509   if (args_info->temp_given)
510     write_into_file(outfile, "temp", args_info->temp_orig, 0);
511   if (args_info->noTetra_given)
512     write_into_file(outfile, "noTetra", 0, 0 );
513   if (args_info->dangles_given)
514     write_into_file(outfile, "dangles", args_info->dangles_orig, 0);
515   if (args_info->noLP_given)
516     write_into_file(outfile, "noLP", 0, 0 );
517   if (args_info->noGU_given)
518     write_into_file(outfile, "noGU", 0, 0 );
519   if (args_info->noClosingGU_given)
520     write_into_file(outfile, "noClosingGU", 0, 0 );
521   if (args_info->cfactor_given)
522     write_into_file(outfile, "cfactor", args_info->cfactor_orig, 0);
523   if (args_info->nfactor_given)
524     write_into_file(outfile, "nfactor", args_info->nfactor_orig, 0);
525   if (args_info->endgaps_given)
526     write_into_file(outfile, "endgaps", 0, 0 );
527   if (args_info->ribosum_file_given)
528     write_into_file(outfile, "ribosum_file", args_info->ribosum_file_orig, 0);
529   if (args_info->ribosum_scoring_given)
530     write_into_file(outfile, "ribosum_scoring", 0, 0 );
531   if (args_info->old_given)
532     write_into_file(outfile, "old", 0, 0 );
533   if (args_info->paramFile_given)
534     write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
535   if (args_info->nsp_given)
536     write_into_file(outfile, "nsp", args_info->nsp_orig, 0);
537   if (args_info->energyModel_given)
538     write_into_file(outfile, "energyModel", args_info->energyModel_orig, 0);
539   if (args_info->betaScale_given)
540     write_into_file(outfile, "betaScale", args_info->betaScale_orig, 0);
541   
542
543   i = EXIT_SUCCESS;
544   return i;
545 }
546
547 int
548 RNAalifold_cmdline_parser_file_save(const char *filename, struct RNAalifold_args_info *args_info)
549 {
550   FILE *outfile;
551   int i = 0;
552
553   outfile = fopen(filename, "w");
554
555   if (!outfile)
556     {
557       fprintf (stderr, "%s: cannot open file for writing: %s\n", RNAALIFOLD_CMDLINE_PARSER_PACKAGE, filename);
558       return EXIT_FAILURE;
559     }
560
561   i = RNAalifold_cmdline_parser_dump(outfile, args_info);
562   fclose (outfile);
563
564   return i;
565 }
566
567 void
568 RNAalifold_cmdline_parser_free (struct RNAalifold_args_info *args_info)
569 {
570   RNAalifold_cmdline_parser_release (args_info);
571 }
572
573 /** @brief replacement of strdup, which is not standard */
574 char *
575 gengetopt_strdup (const char *s)
576 {
577   char *result = 0;
578   if (!s)
579     return result;
580
581   result = (char*)malloc(strlen(s) + 1);
582   if (result == (char*)0)
583     return (char*)0;
584   strcpy(result, s);
585   return result;
586 }
587
588 int
589 RNAalifold_cmdline_parser (int argc, char **argv, struct RNAalifold_args_info *args_info)
590 {
591   return RNAalifold_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
592 }
593
594 int
595 RNAalifold_cmdline_parser_ext (int argc, char **argv, struct RNAalifold_args_info *args_info,
596                    struct RNAalifold_cmdline_parser_params *params)
597 {
598   int result;
599   result = RNAalifold_cmdline_parser_internal (argc, argv, args_info, params, 0);
600
601   if (result == EXIT_FAILURE)
602     {
603       RNAalifold_cmdline_parser_free (args_info);
604       exit (EXIT_FAILURE);
605     }
606   
607   return result;
608 }
609
610 int
611 RNAalifold_cmdline_parser2 (int argc, char **argv, struct RNAalifold_args_info *args_info, int override, int initialize, int check_required)
612 {
613   int result;
614   struct RNAalifold_cmdline_parser_params params;
615   
616   params.override = override;
617   params.initialize = initialize;
618   params.check_required = check_required;
619   params.check_ambiguity = 0;
620   params.print_errors = 1;
621
622   result = RNAalifold_cmdline_parser_internal (argc, argv, args_info, &params, 0);
623
624   if (result == EXIT_FAILURE)
625     {
626       RNAalifold_cmdline_parser_free (args_info);
627       exit (EXIT_FAILURE);
628     }
629   
630   return result;
631 }
632
633 int
634 RNAalifold_cmdline_parser_required (struct RNAalifold_args_info *args_info, const char *prog_name)
635 {
636   int result = EXIT_SUCCESS;
637
638   if (RNAalifold_cmdline_parser_required2(args_info, prog_name, 0) > 0)
639     result = EXIT_FAILURE;
640
641   if (result == EXIT_FAILURE)
642     {
643       RNAalifold_cmdline_parser_free (args_info);
644       exit (EXIT_FAILURE);
645     }
646   
647   return result;
648 }
649
650 int
651 RNAalifold_cmdline_parser_required2 (struct RNAalifold_args_info *args_info, const char *prog_name, const char *additional_error)
652 {
653   int error = 0;
654   FIX_UNUSED (additional_error);
655
656   /* checks for required options */
657   
658   /* checks for dependences among options */
659   if (args_info->betaScale_given && ! args_info->partfunc_given)
660     {
661       fprintf (stderr, "%s: '--betaScale' option depends on option 'partfunc'%s\n", prog_name, (additional_error ? additional_error : ""));
662       error = 1;
663     }
664
665   return error;
666 }
667
668 /*
669  * Extracted from the glibc source tree, version 2.3.6
670  *
671  * Licensed under the GPL as per the whole glibc source tree.
672  *
673  * This file was modified so that getopt_long can be called
674  * many times without risking previous memory to be spoiled.
675  *
676  * Modified by Andre Noll and Lorenzo Bettini for use in
677  * GNU gengetopt generated files.
678  *
679  */
680
681 /* 
682  * we must include anything we need since this file is not thought to be
683  * inserted in a file already using getopt.h
684  *
685  * Lorenzo
686  */
687
688 struct option
689 {
690   const char *name;
691   /* has_arg can't be an enum because some compilers complain about
692      type mismatches in all the code that assumes it is an int.  */
693   int has_arg;
694   int *flag;
695   int val;
696 };
697
698 /* This version of `getopt' appears to the caller like standard Unix `getopt'
699    but it behaves differently for the user, since it allows the user
700    to intersperse the options with the other arguments.
701
702    As `getopt' works, it permutes the elements of ARGV so that,
703    when it is done, all the options precede everything else.  Thus
704    all application programs are extended to handle flexible argument order.
705 */
706 /*
707    If the field `flag' is not NULL, it points to a variable that is set
708    to the value given in the field `val' when the option is found, but
709    left unchanged if the option is not found.
710
711    To have a long-named option do something other than set an `int' to
712    a compiled-in constant, such as set a value from `custom_optarg', set the
713    option's `flag' field to zero and its `val' field to a nonzero
714    value (the equivalent single-letter option character, if there is
715    one).  For long options that have a zero `flag' field, `getopt'
716    returns the contents of the `val' field.  */
717
718 /* Names for the values of the `has_arg' field of `struct option'.  */
719 #ifndef no_argument
720 #define no_argument             0
721 #endif
722
723 #ifndef required_argument
724 #define required_argument       1
725 #endif
726
727 #ifndef optional_argument
728 #define optional_argument       2
729 #endif
730
731 struct custom_getopt_data {
732         /*
733          * These have exactly the same meaning as the corresponding global variables,
734          * except that they are used for the reentrant versions of getopt.
735          */
736         int custom_optind;
737         int custom_opterr;
738         int custom_optopt;
739         char *custom_optarg;
740
741         /* True if the internal members have been initialized.  */
742         int initialized;
743
744         /*
745          * The next char to be scanned in the option-element in which the last option
746          * character we returned was found.  This allows us to pick up the scan where
747          * we left off.  If this is zero, or a null string, it means resume the scan by
748          * advancing to the next ARGV-element.
749          */
750         char *nextchar;
751
752         /*
753          * Describe the part of ARGV that contains non-options that have been skipped.
754          * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
755          * the index after the last of them.
756          */
757         int first_nonopt;
758         int last_nonopt;
759 };
760
761 /*
762  * the variables optarg, optind, opterr and optopt are renamed with
763  * the custom_ prefix so that they don't interfere with getopt ones.
764  *
765  * Moreover they're static so they are visible only from within the
766  * file where this very file will be included.
767  */
768
769 /*
770  * For communication from `custom_getopt' to the caller.  When `custom_getopt' finds an
771  * option that takes an argument, the argument value is returned here.
772  */
773 static char *custom_optarg;
774
775 /*
776  * Index in ARGV of the next element to be scanned.  This is used for
777  * communication to and from the caller and for communication between
778  * successive calls to `custom_getopt'.
779  *
780  * On entry to `custom_getopt', 1 means this is the first call; initialize.
781  *
782  * When `custom_getopt' returns -1, this is the index of the first of the non-option
783  * elements that the caller should itself scan.
784  *
785  * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
786  * has been scanned so far.
787  *
788  * 1003.2 says this must be 1 before any call.
789  */
790 static int custom_optind = 1;
791
792 /*
793  * Callers store zero here to inhibit the error message for unrecognized
794  * options.
795  */
796 static int custom_opterr = 1;
797
798 /*
799  * Set to an option character which was unrecognized.  This must be initialized
800  * on some systems to avoid linking in the system's own getopt implementation.
801  */
802 static int custom_optopt = '?';
803
804 /*
805  * Exchange two adjacent subsequences of ARGV.  One subsequence is elements
806  * [first_nonopt,last_nonopt) which contains all the non-options that have been
807  * skipped so far.  The other is elements [last_nonopt,custom_optind), which contains
808  * all the options processed since those non-options were skipped.
809  * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
810  * indices of the non-options in ARGV after they are moved.
811  */
812 static void exchange(char **argv, struct custom_getopt_data *d)
813 {
814         int bottom = d->first_nonopt;
815         int middle = d->last_nonopt;
816         int top = d->custom_optind;
817         char *tem;
818
819         /*
820          * Exchange the shorter segment with the far end of the longer segment.
821          * That puts the shorter segment into the right place.  It leaves the
822          * longer segment in the right place overall, but it consists of two
823          * parts that need to be swapped next.
824          */
825         while (top > middle && middle > bottom) {
826                 if (top - middle > middle - bottom) {
827                         /* Bottom segment is the short one.  */
828                         int len = middle - bottom;
829                         int i;
830
831                         /* Swap it with the top part of the top segment.  */
832                         for (i = 0; i < len; i++) {
833                                 tem = argv[bottom + i];
834                                 argv[bottom + i] =
835                                         argv[top - (middle - bottom) + i];
836                                 argv[top - (middle - bottom) + i] = tem;
837                         }
838                         /* Exclude the moved bottom segment from further swapping.  */
839                         top -= len;
840                 } else {
841                         /* Top segment is the short one.  */
842                         int len = top - middle;
843                         int i;
844
845                         /* Swap it with the bottom part of the bottom segment.  */
846                         for (i = 0; i < len; i++) {
847                                 tem = argv[bottom + i];
848                                 argv[bottom + i] = argv[middle + i];
849                                 argv[middle + i] = tem;
850                         }
851                         /* Exclude the moved top segment from further swapping.  */
852                         bottom += len;
853                 }
854         }
855         /* Update records for the slots the non-options now occupy.  */
856         d->first_nonopt += (d->custom_optind - d->last_nonopt);
857         d->last_nonopt = d->custom_optind;
858 }
859
860 /* Initialize the internal data when the first call is made.  */
861 static void custom_getopt_initialize(struct custom_getopt_data *d)
862 {
863         /*
864          * Start processing options with ARGV-element 1 (since ARGV-element 0
865          * is the program name); the sequence of previously skipped non-option
866          * ARGV-elements is empty.
867          */
868         d->first_nonopt = d->last_nonopt = d->custom_optind;
869         d->nextchar = NULL;
870         d->initialized = 1;
871 }
872
873 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
874
875 /* return: zero: continue, nonzero: return given value to user */
876 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
877         struct custom_getopt_data *d)
878 {
879         /*
880          * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
881          * moved back by the user (who may also have changed the arguments).
882          */
883         if (d->last_nonopt > d->custom_optind)
884                 d->last_nonopt = d->custom_optind;
885         if (d->first_nonopt > d->custom_optind)
886                 d->first_nonopt = d->custom_optind;
887         /*
888          * If we have just processed some options following some
889          * non-options, exchange them so that the options come first.
890          */
891         if (d->first_nonopt != d->last_nonopt &&
892                         d->last_nonopt != d->custom_optind)
893                 exchange((char **) argv, d);
894         else if (d->last_nonopt != d->custom_optind)
895                 d->first_nonopt = d->custom_optind;
896         /*
897          * Skip any additional non-options and extend the range of
898          * non-options previously skipped.
899          */
900         while (d->custom_optind < argc && NONOPTION_P)
901                 d->custom_optind++;
902         d->last_nonopt = d->custom_optind;
903         /*
904          * The special ARGV-element `--' means premature end of options.  Skip
905          * it like a null option, then exchange with previous non-options as if
906          * it were an option, then skip everything else like a non-option.
907          */
908         if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
909                 d->custom_optind++;
910                 if (d->first_nonopt != d->last_nonopt
911                                 && d->last_nonopt != d->custom_optind)
912                         exchange((char **) argv, d);
913                 else if (d->first_nonopt == d->last_nonopt)
914                         d->first_nonopt = d->custom_optind;
915                 d->last_nonopt = argc;
916                 d->custom_optind = argc;
917         }
918         /*
919          * If we have done all the ARGV-elements, stop the scan and back over
920          * any non-options that we skipped and permuted.
921          */
922         if (d->custom_optind == argc) {
923                 /*
924                  * Set the next-arg-index to point at the non-options that we
925                  * previously skipped, so the caller will digest them.
926                  */
927                 if (d->first_nonopt != d->last_nonopt)
928                         d->custom_optind = d->first_nonopt;
929                 return -1;
930         }
931         /*
932          * If we have come to a non-option and did not permute it, either stop
933          * the scan or describe it to the caller and pass it by.
934          */
935         if (NONOPTION_P) {
936                 d->custom_optarg = argv[d->custom_optind++];
937                 return 1;
938         }
939         /*
940          * We have found another option-ARGV-element. Skip the initial
941          * punctuation.
942          */
943         d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
944         return 0;
945 }
946
947 /*
948  * Check whether the ARGV-element is a long option.
949  *
950  * If there's a long option "fubar" and the ARGV-element is "-fu", consider
951  * that an abbreviation of the long option, just like "--fu", and not "-f" with
952  * arg "u".
953  *
954  * This distinction seems to be the most useful approach.
955  *
956  */
957 static int check_long_opt(int argc, char *const *argv, const char *optstring,
958                 const struct option *longopts, int *longind,
959                 int print_errors, struct custom_getopt_data *d)
960 {
961         char *nameend;
962         const struct option *p;
963         const struct option *pfound = NULL;
964         int exact = 0;
965         int ambig = 0;
966         int indfound = -1;
967         int option_index;
968
969         for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
970                 /* Do nothing.  */ ;
971
972         /* Test all long options for either exact match or abbreviated matches */
973         for (p = longopts, option_index = 0; p->name; p++, option_index++)
974                 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
975                         if ((unsigned int) (nameend - d->nextchar)
976                                         == (unsigned int) strlen(p->name)) {
977                                 /* Exact match found.  */
978                                 pfound = p;
979                                 indfound = option_index;
980                                 exact = 1;
981                                 break;
982                         } else if (pfound == NULL) {
983                                 /* First nonexact match found.  */
984                                 pfound = p;
985                                 indfound = option_index;
986                         } else if (pfound->has_arg != p->has_arg
987                                         || pfound->flag != p->flag
988                                         || pfound->val != p->val)
989                                 /* Second or later nonexact match found.  */
990                                 ambig = 1;
991                 }
992         if (ambig && !exact) {
993                 if (print_errors) {
994                         fprintf(stderr,
995                                 "%s: option `%s' is ambiguous\n",
996                                 argv[0], argv[d->custom_optind]);
997                 }
998                 d->nextchar += strlen(d->nextchar);
999                 d->custom_optind++;
1000                 d->custom_optopt = 0;
1001                 return '?';
1002         }
1003         if (pfound) {
1004                 option_index = indfound;
1005                 d->custom_optind++;
1006                 if (*nameend) {
1007                         if (pfound->has_arg != no_argument)
1008                                 d->custom_optarg = nameend + 1;
1009                         else {
1010                                 if (print_errors) {
1011                                         if (argv[d->custom_optind - 1][1] == '-') {
1012                                                 /* --option */
1013                                                 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
1014                                                         argv[0], pfound->name);
1015                                         } else {
1016                                                 /* +option or -option */
1017                                                 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
1018                                                         argv[0], argv[d->custom_optind - 1][0], pfound->name);
1019                                         }
1020
1021                                 }
1022                                 d->nextchar += strlen(d->nextchar);
1023                                 d->custom_optopt = pfound->val;
1024                                 return '?';
1025                         }
1026                 } else if (pfound->has_arg == required_argument) {
1027                         if (d->custom_optind < argc)
1028                                 d->custom_optarg = argv[d->custom_optind++];
1029                         else {
1030                                 if (print_errors) {
1031                                         fprintf(stderr,
1032                                                 "%s: option `%s' requires an argument\n",
1033                                                 argv[0],
1034                                                 argv[d->custom_optind - 1]);
1035                                 }
1036                                 d->nextchar += strlen(d->nextchar);
1037                                 d->custom_optopt = pfound->val;
1038                                 return optstring[0] == ':' ? ':' : '?';
1039                         }
1040                 }
1041                 d->nextchar += strlen(d->nextchar);
1042                 if (longind != NULL)
1043                         *longind = option_index;
1044                 if (pfound->flag) {
1045                         *(pfound->flag) = pfound->val;
1046                         return 0;
1047                 }
1048                 return pfound->val;
1049         }
1050         /*
1051          * Can't find it as a long option.  If this is not getopt_long_only, or
1052          * the option starts with '--' or is not a valid short option, then
1053          * it's an error.  Otherwise interpret it as a short option.
1054          */
1055         if (print_errors) {
1056                 if (argv[d->custom_optind][1] == '-') {
1057                         /* --option */
1058                         fprintf(stderr,
1059                                 "%s: unrecognized option `--%s'\n",
1060                                 argv[0], d->nextchar);
1061                 } else {
1062                         /* +option or -option */
1063                         fprintf(stderr,
1064                                 "%s: unrecognized option `%c%s'\n",
1065                                 argv[0], argv[d->custom_optind][0],
1066                                 d->nextchar);
1067                 }
1068         }
1069         d->nextchar = (char *) "";
1070         d->custom_optind++;
1071         d->custom_optopt = 0;
1072         return '?';
1073 }
1074
1075 static int check_short_opt(int argc, char *const *argv, const char *optstring,
1076                 int print_errors, struct custom_getopt_data *d)
1077 {
1078         char c = *d->nextchar++;
1079         const char *temp = strchr(optstring, c);
1080
1081         /* Increment `custom_optind' when we start to process its last character.  */
1082         if (*d->nextchar == '\0')
1083                 ++d->custom_optind;
1084         if (!temp || c == ':') {
1085                 if (print_errors)
1086                         fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
1087
1088                 d->custom_optopt = c;
1089                 return '?';
1090         }
1091         if (temp[1] == ':') {
1092                 if (temp[2] == ':') {
1093                         /* This is an option that accepts an argument optionally.  */
1094                         if (*d->nextchar != '\0') {
1095                                 d->custom_optarg = d->nextchar;
1096                                 d->custom_optind++;
1097                         } else
1098                                 d->custom_optarg = NULL;
1099                         d->nextchar = NULL;
1100                 } else {
1101                         /* This is an option that requires an argument.  */
1102                         if (*d->nextchar != '\0') {
1103                                 d->custom_optarg = d->nextchar;
1104                                 /*
1105                                  * If we end this ARGV-element by taking the
1106                                  * rest as an arg, we must advance to the next
1107                                  * element now.
1108                                  */
1109                                 d->custom_optind++;
1110                         } else if (d->custom_optind == argc) {
1111                                 if (print_errors) {
1112                                         fprintf(stderr,
1113                                                 "%s: option requires an argument -- %c\n",
1114                                                 argv[0], c);
1115                                 }
1116                                 d->custom_optopt = c;
1117                                 if (optstring[0] == ':')
1118                                         c = ':';
1119                                 else
1120                                         c = '?';
1121                         } else
1122                                 /*
1123                                  * We already incremented `custom_optind' once;
1124                                  * increment it again when taking next ARGV-elt
1125                                  * as argument.
1126                                  */
1127                                 d->custom_optarg = argv[d->custom_optind++];
1128                         d->nextchar = NULL;
1129                 }
1130         }
1131         return c;
1132 }
1133
1134 /*
1135  * Scan elements of ARGV for option characters given in OPTSTRING.
1136  *
1137  * If an element of ARGV starts with '-', and is not exactly "-" or "--",
1138  * then it is an option element.  The characters of this element
1139  * (aside from the initial '-') are option characters.  If `getopt'
1140  * is called repeatedly, it returns successively each of the option characters
1141  * from each of the option elements.
1142  *
1143  * If `getopt' finds another option character, it returns that character,
1144  * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
1145  * resume the scan with the following option character or ARGV-element.
1146  *
1147  * If there are no more option characters, `getopt' returns -1.
1148  * Then `custom_optind' is the index in ARGV of the first ARGV-element
1149  * that is not an option.  (The ARGV-elements have been permuted
1150  * so that those that are not options now come last.)
1151  *
1152  * OPTSTRING is a string containing the legitimate option characters.
1153  * If an option character is seen that is not listed in OPTSTRING,
1154  * return '?' after printing an error message.  If you set `custom_opterr' to
1155  * zero, the error message is suppressed but we still return '?'.
1156  *
1157  * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
1158  * so the following text in the same ARGV-element, or the text of the following
1159  * ARGV-element, is returned in `custom_optarg'.  Two colons mean an option that
1160  * wants an optional arg; if there is text in the current ARGV-element,
1161  * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
1162  *
1163  * If OPTSTRING starts with `-' or `+', it requests different methods of
1164  * handling the non-option ARGV-elements.
1165  * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
1166  *
1167  * Long-named options begin with `--' instead of `-'.
1168  * Their names may be abbreviated as long as the abbreviation is unique
1169  * or is an exact match for some defined option.  If they have an
1170  * argument, it follows the option name in the same ARGV-element, separated
1171  * from the option name by a `=', or else the in next ARGV-element.
1172  * When `getopt' finds a long-named option, it returns 0 if that option's
1173  * `flag' field is nonzero, the value of the option's `val' field
1174  * if the `flag' field is zero.
1175  *
1176  * The elements of ARGV aren't really const, because we permute them.
1177  * But we pretend they're const in the prototype to be compatible
1178  * with other systems.
1179  *
1180  * LONGOPTS is a vector of `struct option' terminated by an
1181  * element containing a name which is zero.
1182  *
1183  * LONGIND returns the index in LONGOPT of the long-named option found.
1184  * It is only valid when a long-named option has been found by the most
1185  * recent call.
1186  *
1187  * Return the option character from OPTS just read.  Return -1 when there are
1188  * no more options.  For unrecognized options, or options missing arguments,
1189  * `custom_optopt' is set to the option letter, and '?' is returned.
1190  *
1191  * The OPTS string is a list of characters which are recognized option letters,
1192  * optionally followed by colons, specifying that that letter takes an
1193  * argument, to be placed in `custom_optarg'.
1194  *
1195  * If a letter in OPTS is followed by two colons, its argument is optional.
1196  * This behavior is specific to the GNU `getopt'.
1197  *
1198  * The argument `--' causes premature termination of argument scanning,
1199  * explicitly telling `getopt' that there are no more options.  If OPTS begins
1200  * with `--', then non-option arguments are treated as arguments to the option
1201  * '\0'.  This behavior is specific to the GNU `getopt'.
1202  */
1203
1204 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1205                 const struct option *longopts, int *longind,
1206                 struct custom_getopt_data *d)
1207 {
1208         int ret, print_errors = d->custom_opterr;
1209
1210         if (optstring[0] == ':')
1211                 print_errors = 0;
1212         if (argc < 1)
1213                 return -1;
1214         d->custom_optarg = NULL;
1215
1216         /* 
1217          * This is a big difference with GNU getopt, since optind == 0
1218          * means initialization while here 1 means first call.
1219          */
1220         if (d->custom_optind == 0 || !d->initialized) {
1221                 if (d->custom_optind == 0)
1222                         d->custom_optind = 1;   /* Don't scan ARGV[0], the program name.  */
1223                 custom_getopt_initialize(d);
1224         }
1225         if (d->nextchar == NULL || *d->nextchar == '\0') {
1226                 ret = shuffle_argv(argc, argv, longopts, d);
1227                 if (ret)
1228                         return ret;
1229         }
1230         if (longopts && (argv[d->custom_optind][1] == '-' ))
1231                 return check_long_opt(argc, argv, optstring, longopts,
1232                         longind, print_errors, d);
1233         return check_short_opt(argc, argv, optstring, print_errors, d);
1234 }
1235
1236 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1237         const struct option *longopts, int *longind)
1238 {
1239         int result;
1240         /* Keep a global copy of all internal members of d */
1241         static struct custom_getopt_data d;
1242
1243         d.custom_optind = custom_optind;
1244         d.custom_opterr = custom_opterr;
1245         result = getopt_internal_r(argc, argv, optstring, longopts,
1246                 longind, &d);
1247         custom_optind = d.custom_optind;
1248         custom_optarg = d.custom_optarg;
1249         custom_optopt = d.custom_optopt;
1250         return result;
1251 }
1252
1253 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1254         const struct option *long_options, int *opt_index)
1255 {
1256         return custom_getopt_internal(argc, argv, options, long_options,
1257                 opt_index);
1258 }
1259
1260
1261 static char *package_name = 0;
1262
1263 /**
1264  * @brief updates an option
1265  * @param field the generic pointer to the field to update
1266  * @param orig_field the pointer to the orig field
1267  * @param field_given the pointer to the number of occurrence of this option
1268  * @param prev_given the pointer to the number of occurrence already seen
1269  * @param value the argument for this option (if null no arg was specified)
1270  * @param possible_values the possible values for this option (if specified)
1271  * @param default_value the default value (in case the option only accepts fixed values)
1272  * @param arg_type the type of this option
1273  * @param check_ambiguity @see RNAalifold_cmdline_parser_params.check_ambiguity
1274  * @param override @see RNAalifold_cmdline_parser_params.override
1275  * @param no_free whether to free a possible previous value
1276  * @param multiple_option whether this is a multiple option
1277  * @param long_opt the corresponding long option
1278  * @param short_opt the corresponding short option (or '-' if none)
1279  * @param additional_error possible further error specification
1280  */
1281 static
1282 int update_arg(void *field, char **orig_field,
1283                unsigned int *field_given, unsigned int *prev_given, 
1284                char *value, const char *possible_values[],
1285                const char *default_value,
1286                RNAalifold_cmdline_parser_arg_type arg_type,
1287                int check_ambiguity, int override,
1288                int no_free, int multiple_option,
1289                const char *long_opt, char short_opt,
1290                const char *additional_error)
1291 {
1292   char *stop_char = 0;
1293   const char *val = value;
1294   int found;
1295   char **string_field;
1296   FIX_UNUSED (field);
1297
1298   stop_char = 0;
1299   found = 0;
1300
1301   if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1302     {
1303       if (short_opt != '-')
1304         fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", 
1305                package_name, long_opt, short_opt,
1306                (additional_error ? additional_error : ""));
1307       else
1308         fprintf (stderr, "%s: `--%s' option given more than once%s\n", 
1309                package_name, long_opt,
1310                (additional_error ? additional_error : ""));
1311       return 1; /* failure */
1312     }
1313
1314   FIX_UNUSED (default_value);
1315     
1316   if (field_given && *field_given && ! override)
1317     return 0;
1318   if (prev_given)
1319     (*prev_given)++;
1320   if (field_given)
1321     (*field_given)++;
1322   if (possible_values)
1323     val = possible_values[found];
1324
1325   switch(arg_type) {
1326   case ARG_FLAG:
1327     *((int *)field) = !*((int *)field);
1328     break;
1329   case ARG_INT:
1330     if (val) *((int *)field) = strtol (val, &stop_char, 0);
1331     break;
1332   case ARG_FLOAT:
1333     if (val) *((float *)field) = (float)strtod (val, &stop_char);
1334     break;
1335   case ARG_DOUBLE:
1336     if (val) *((double *)field) = strtod (val, &stop_char);
1337     break;
1338   case ARG_STRING:
1339     if (val) {
1340       string_field = (char **)field;
1341       if (!no_free && *string_field)
1342         free (*string_field); /* free previous string */
1343       *string_field = gengetopt_strdup (val);
1344     }
1345     break;
1346   default:
1347     break;
1348   };
1349
1350   /* check numeric conversion */
1351   switch(arg_type) {
1352   case ARG_INT:
1353   case ARG_FLOAT:
1354   case ARG_DOUBLE:
1355     if (val && !(stop_char && *stop_char == '\0')) {
1356       fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1357       return 1; /* failure */
1358     }
1359     break;
1360   default:
1361     ;
1362   };
1363
1364   /* store the original value */
1365   switch(arg_type) {
1366   case ARG_NO:
1367   case ARG_FLAG:
1368     break;
1369   default:
1370     if (value && orig_field) {
1371       if (no_free) {
1372         *orig_field = value;
1373       } else {
1374         if (*orig_field)
1375           free (*orig_field); /* free previous string */
1376         *orig_field = gengetopt_strdup (value);
1377       }
1378     }
1379   };
1380
1381   return 0; /* OK */
1382 }
1383
1384
1385 int
1386 RNAalifold_cmdline_parser_internal (
1387   int argc, char **argv, struct RNAalifold_args_info *args_info,
1388                         struct RNAalifold_cmdline_parser_params *params, const char *additional_error)
1389 {
1390   int c;        /* Character of the parsed option.  */
1391
1392   int error = 0;
1393   struct RNAalifold_args_info local_args_info;
1394   
1395   int override;
1396   int initialize;
1397   int check_required;
1398   int check_ambiguity;
1399
1400   char *optarg;
1401   int optind;
1402   int opterr;
1403   int optopt;
1404   
1405   package_name = argv[0];
1406   
1407   override = params->override;
1408   initialize = params->initialize;
1409   check_required = params->check_required;
1410   check_ambiguity = params->check_ambiguity;
1411
1412   if (initialize)
1413     RNAalifold_cmdline_parser_init (args_info);
1414
1415   RNAalifold_cmdline_parser_init (&local_args_info);
1416
1417   optarg = 0;
1418   optind = 0;
1419   opterr = params->print_errors;
1420   optopt = '?';
1421
1422   while (1)
1423     {
1424       int option_index = 0;
1425
1426       static struct option long_options[] = {
1427         { "help",       0, NULL, 'h' },
1428         { "detailed-help",      0, NULL, 0 },
1429         { "full-help",  0, NULL, 0 },
1430         { "version",    0, NULL, 'V' },
1431         { "constraint", 0, NULL, 'C' },
1432         { "color",      0, NULL, 0 },
1433         { "aln",        0, NULL, 0 },
1434         { "noPS",       0, NULL, 0 },
1435         { "partfunc",   2, NULL, 'p' },
1436         { "MEA",        2, NULL, 0 },
1437         { "mis",        0, NULL, 0 },
1438         { "stochBT",    1, NULL, 's' },
1439         { "stochBT_en", 1, NULL, 0 },
1440         { "pfScale",    1, NULL, 'S' },
1441         { "circ",       0, NULL, 'c' },
1442         { "bppmThreshold",      1, NULL, 0 },
1443         { "gquad",      0, NULL, 'g' },
1444         { "temp",       1, NULL, 'T' },
1445         { "noTetra",    0, NULL, '4' },
1446         { "dangles",    1, NULL, 'd' },
1447         { "noLP",       0, NULL, 0 },
1448         { "noGU",       0, NULL, 0 },
1449         { "noClosingGU",        0, NULL, 0 },
1450         { "cfactor",    1, NULL, 0 },
1451         { "nfactor",    1, NULL, 0 },
1452         { "endgaps",    0, NULL, 'E' },
1453         { "ribosum_file",       1, NULL, 'R' },
1454         { "ribosum_scoring",    0, NULL, 'r' },
1455         { "old",        0, NULL, 0 },
1456         { "paramFile",  1, NULL, 'P' },
1457         { "nsp",        1, NULL, 0 },
1458         { "energyModel",        1, NULL, 'e' },
1459         { "betaScale",  1, NULL, 0 },
1460         { 0,  0, 0, 0 }
1461       };
1462
1463       custom_optarg = optarg;
1464       custom_optind = optind;
1465       custom_opterr = opterr;
1466       custom_optopt = optopt;
1467
1468       c = custom_getopt_long (argc, argv, "hVCp::s:S:cgT:4d:ER:rP:e:", long_options, &option_index);
1469
1470       optarg = custom_optarg;
1471       optind = custom_optind;
1472       opterr = custom_opterr;
1473       optopt = custom_optopt;
1474
1475       if (c == -1) break;       /* Exit from `while (1)' loop.  */
1476
1477       switch (c)
1478         {
1479         case 'h':       /* Print help and exit.  */
1480           RNAalifold_cmdline_parser_print_help ();
1481           RNAalifold_cmdline_parser_free (&local_args_info);
1482           exit (EXIT_SUCCESS);
1483
1484         case 'V':       /* Print version and exit.  */
1485           RNAalifold_cmdline_parser_print_version ();
1486           RNAalifold_cmdline_parser_free (&local_args_info);
1487           exit (EXIT_SUCCESS);
1488
1489         case 'C':       /* Calculate structures subject to constraints.
1490         The constraining structure will be read from 'stdin', the alignment has to be given as a file name on the command line.
1491 .  */
1492         
1493         
1494           if (update_arg((void *)&(args_info->constraint_flag), 0, &(args_info->constraint_given),
1495               &(local_args_info.constraint_given), optarg, 0, 0, ARG_FLAG,
1496               check_ambiguity, override, 1, 0, "constraint", 'C',
1497               additional_error))
1498             goto failure;
1499         
1500           break;
1501         case 'p':       /* Calculate the partition function and base pairing probability matrix in addition to the mfe structure. Default is calculation of mfe structure only.
1502 .  */
1503         
1504         
1505           if (update_arg( (void *)&(args_info->partfunc_arg), 
1506                &(args_info->partfunc_orig), &(args_info->partfunc_given),
1507               &(local_args_info.partfunc_given), optarg, 0, "1", ARG_INT,
1508               check_ambiguity, override, 0, 0,
1509               "partfunc", 'p',
1510               additional_error))
1511             goto failure;
1512         
1513           break;
1514         case 's':       /* Stochastic backtrack. Compute a certain number of random structures with a probability dependend on the partition function. See -p option in RNAsubopt.
1515         
1516 .  */
1517         
1518         
1519           if (update_arg( (void *)&(args_info->stochBT_arg), 
1520                &(args_info->stochBT_orig), &(args_info->stochBT_given),
1521               &(local_args_info.stochBT_given), optarg, 0, 0, ARG_INT,
1522               check_ambiguity, override, 0, 0,
1523               "stochBT", 's',
1524               additional_error))
1525             goto failure;
1526         
1527           break;
1528         case 'S':       /* In the calculation of the pf use scale*mfe as an estimate for the ensemble free energy (used to avoid overflows).
1529 .  */
1530         
1531         
1532           if (update_arg( (void *)&(args_info->pfScale_arg), 
1533                &(args_info->pfScale_orig), &(args_info->pfScale_given),
1534               &(local_args_info.pfScale_given), optarg, 0, 0, ARG_DOUBLE,
1535               check_ambiguity, override, 0, 0,
1536               "pfScale", 'S',
1537               additional_error))
1538             goto failure;
1539         
1540           break;
1541         case 'c':       /* Assume a circular (instead of linear) RNA molecule.
1542         
1543 .  */
1544         
1545         
1546           if (update_arg((void *)&(args_info->circ_flag), 0, &(args_info->circ_given),
1547               &(local_args_info.circ_given), optarg, 0, 0, ARG_FLAG,
1548               check_ambiguity, override, 1, 0, "circ", 'c',
1549               additional_error))
1550             goto failure;
1551         
1552           break;
1553         case 'g':       /* Incoorporate G-Quadruplex formation into the structure prediction algorithm
1554 .  */
1555         
1556         
1557           if (update_arg((void *)&(args_info->gquad_flag), 0, &(args_info->gquad_given),
1558               &(local_args_info.gquad_given), optarg, 0, 0, ARG_FLAG,
1559               check_ambiguity, override, 1, 0, "gquad", 'g',
1560               additional_error))
1561             goto failure;
1562         
1563           break;
1564         case 'T':       /* Rescale energy parameters to a temperature of temp C. Default is 37C.
1565         
1566 .  */
1567         
1568         
1569           if (update_arg( (void *)&(args_info->temp_arg), 
1570                &(args_info->temp_orig), &(args_info->temp_given),
1571               &(local_args_info.temp_given), optarg, 0, 0, ARG_DOUBLE,
1572               check_ambiguity, override, 0, 0,
1573               "temp", 'T',
1574               additional_error))
1575             goto failure;
1576         
1577           break;
1578         case '4':       /* Do not include special tabulated stabilizing energies for tri-, tetra- and hexaloop hairpins. Mostly for testing.
1579         
1580 .  */
1581         
1582         
1583           if (update_arg((void *)&(args_info->noTetra_flag), 0, &(args_info->noTetra_given),
1584               &(local_args_info.noTetra_given), optarg, 0, 0, ARG_FLAG,
1585               check_ambiguity, override, 1, 0, "noTetra", '4',
1586               additional_error))
1587             goto failure;
1588         
1589           break;
1590         case 'd':       /* How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops
1591 .  */
1592         
1593         
1594           if (update_arg( (void *)&(args_info->dangles_arg), 
1595                &(args_info->dangles_orig), &(args_info->dangles_given),
1596               &(local_args_info.dangles_given), optarg, 0, "2", ARG_INT,
1597               check_ambiguity, override, 0, 0,
1598               "dangles", 'd',
1599               additional_error))
1600             goto failure;
1601         
1602           break;
1603         case 'E':       /* Score pairs with endgaps same as gap-gap pairs.
1604         
1605 .  */
1606         
1607         
1608           if (update_arg((void *)&(args_info->endgaps_flag), 0, &(args_info->endgaps_given),
1609               &(local_args_info.endgaps_given), optarg, 0, 0, ARG_FLAG,
1610               check_ambiguity, override, 1, 0, "endgaps", 'E',
1611               additional_error))
1612             goto failure;
1613         
1614           break;
1615         case 'R':       /* use specified Ribosum Matrix instead of normal energy model. Matrixes to use should be 6x6 matrices, the order of the terms is AU, CG, GC, GU, UA, UG.
1616         
1617 .  */
1618         
1619         
1620           if (update_arg( (void *)&(args_info->ribosum_file_arg), 
1621                &(args_info->ribosum_file_orig), &(args_info->ribosum_file_given),
1622               &(local_args_info.ribosum_file_given), optarg, 0, 0, ARG_STRING,
1623               check_ambiguity, override, 0, 0,
1624               "ribosum_file", 'R',
1625               additional_error))
1626             goto failure;
1627         
1628           break;
1629         case 'r':       /* use ribosum scoring matrix. The matrix is chosen according to the minimal and maximal pairwise identities of the sequences in the file.
1630         
1631 .  */
1632         
1633         
1634           if (update_arg((void *)&(args_info->ribosum_scoring_flag), 0, &(args_info->ribosum_scoring_given),
1635               &(local_args_info.ribosum_scoring_given), optarg, 0, 0, ARG_FLAG,
1636               check_ambiguity, override, 1, 0, "ribosum_scoring", 'r',
1637               additional_error))
1638             goto failure;
1639         
1640           break;
1641         case 'P':       /* Read energy parameters from paramfile, instead of using the default parameter set.
1642 .  */
1643         
1644         
1645           if (update_arg( (void *)&(args_info->paramFile_arg), 
1646                &(args_info->paramFile_orig), &(args_info->paramFile_given),
1647               &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1648               check_ambiguity, override, 0, 0,
1649               "paramFile", 'P',
1650               additional_error))
1651             goto failure;
1652         
1653           break;
1654         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.
1655         
1656 .  */
1657         
1658         
1659           if (update_arg( (void *)&(args_info->energyModel_arg), 
1660                &(args_info->energyModel_orig), &(args_info->energyModel_given),
1661               &(local_args_info.energyModel_given), optarg, 0, 0, ARG_INT,
1662               check_ambiguity, override, 0, 0,
1663               "energyModel", 'e',
1664               additional_error))
1665             goto failure;
1666         
1667           break;
1668
1669         case 0: /* Long option with no short option */
1670           if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1671             RNAalifold_cmdline_parser_print_detailed_help ();
1672             RNAalifold_cmdline_parser_free (&local_args_info);
1673             exit (EXIT_SUCCESS);
1674           }
1675
1676           if (strcmp (long_options[option_index].name, "full-help") == 0) {
1677             RNAalifold_cmdline_parser_print_full_help ();
1678             RNAalifold_cmdline_parser_free (&local_args_info);
1679             exit (EXIT_SUCCESS);
1680           }
1681
1682           /* Produce a colored version of the consensus strcture plot \"alirna.ps\" (default b&w only)
1683           
1684 .  */
1685           if (strcmp (long_options[option_index].name, "color") == 0)
1686           {
1687           
1688           
1689             if (update_arg((void *)&(args_info->color_flag), 0, &(args_info->color_given),
1690                 &(local_args_info.color_given), optarg, 0, 0, ARG_FLAG,
1691                 check_ambiguity, override, 1, 0, "color", '-',
1692                 additional_error))
1693               goto failure;
1694           
1695           }
1696           /* Produce a colored and structure annotated alignment in PostScript format in the file \"aln.ps\" in the current directory.
1697           
1698 .  */
1699           else if (strcmp (long_options[option_index].name, "aln") == 0)
1700           {
1701           
1702           
1703             if (update_arg((void *)&(args_info->aln_flag), 0, &(args_info->aln_given),
1704                 &(local_args_info.aln_given), optarg, 0, 0, ARG_FLAG,
1705                 check_ambiguity, override, 1, 0, "aln", '-',
1706                 additional_error))
1707               goto failure;
1708           
1709           }
1710           /* Do not produce postscript output
1711           
1712 .  */
1713           else if (strcmp (long_options[option_index].name, "noPS") == 0)
1714           {
1715           
1716           
1717             if (update_arg((void *)&(args_info->noPS_flag), 0, &(args_info->noPS_given),
1718                 &(local_args_info.noPS_given), optarg, 0, 0, ARG_FLAG,
1719                 check_ambiguity, override, 1, 0, "noPS", '-',
1720                 additional_error))
1721               goto failure;
1722           
1723           }
1724           /* Calculate an MEA (maximum expected accuracy) structure.
1725 .  */
1726           else if (strcmp (long_options[option_index].name, "MEA") == 0)
1727           {
1728           
1729           
1730             if (update_arg( (void *)&(args_info->MEA_arg), 
1731                  &(args_info->MEA_orig), &(args_info->MEA_given),
1732                 &(local_args_info.MEA_given), optarg, 0, "1.", ARG_FLOAT,
1733                 check_ambiguity, override, 0, 0,
1734                 "MEA", '-',
1735                 additional_error))
1736               goto failure;
1737           
1738           }
1739           /* Output \"most informative sequence\" instead of simple consensus: For each column of the alignment output the set of nucleotides with frequence greater than average in IUPAC notation.
1740           
1741 .  */
1742           else if (strcmp (long_options[option_index].name, "mis") == 0)
1743           {
1744           
1745           
1746             if (update_arg((void *)&(args_info->mis_flag), 0, &(args_info->mis_given),
1747                 &(local_args_info.mis_given), optarg, 0, 0, ARG_FLAG,
1748                 check_ambiguity, override, 1, 0, "mis", '-',
1749                 additional_error))
1750               goto failure;
1751           
1752           }
1753           /* same as \"-s\" but also print out the energies and probabilities of the backtraced structures.
1754           
1755 .  */
1756           else if (strcmp (long_options[option_index].name, "stochBT_en") == 0)
1757           {
1758           
1759           
1760             if (update_arg( (void *)&(args_info->stochBT_en_arg), 
1761                  &(args_info->stochBT_en_orig), &(args_info->stochBT_en_given),
1762                 &(local_args_info.stochBT_en_given), optarg, 0, 0, ARG_INT,
1763                 check_ambiguity, override, 0, 0,
1764                 "stochBT_en", '-',
1765                 additional_error))
1766               goto failure;
1767           
1768           }
1769           /* Set the threshold for base pair probabilities included in the postscript output
1770 .  */
1771           else if (strcmp (long_options[option_index].name, "bppmThreshold") == 0)
1772           {
1773           
1774           
1775             if (update_arg( (void *)&(args_info->bppmThreshold_arg), 
1776                  &(args_info->bppmThreshold_orig), &(args_info->bppmThreshold_given),
1777                 &(local_args_info.bppmThreshold_given), optarg, 0, "1e-6", ARG_DOUBLE,
1778                 check_ambiguity, override, 0, 0,
1779                 "bppmThreshold", '-',
1780                 additional_error))
1781               goto failure;
1782           
1783           }
1784           /* Produce structures without lonely pairs (helices of length 1).
1785 .  */
1786           else if (strcmp (long_options[option_index].name, "noLP") == 0)
1787           {
1788           
1789           
1790             if (update_arg((void *)&(args_info->noLP_flag), 0, &(args_info->noLP_given),
1791                 &(local_args_info.noLP_given), optarg, 0, 0, ARG_FLAG,
1792                 check_ambiguity, override, 1, 0, "noLP", '-',
1793                 additional_error))
1794               goto failure;
1795           
1796           }
1797           /* Do not allow GU pairs
1798           
1799 .  */
1800           else if (strcmp (long_options[option_index].name, "noGU") == 0)
1801           {
1802           
1803           
1804             if (update_arg((void *)&(args_info->noGU_flag), 0, &(args_info->noGU_given),
1805                 &(local_args_info.noGU_given), optarg, 0, 0, ARG_FLAG,
1806                 check_ambiguity, override, 1, 0, "noGU", '-',
1807                 additional_error))
1808               goto failure;
1809           
1810           }
1811           /* Do not allow GU pairs at the end of helices
1812           
1813 .  */
1814           else if (strcmp (long_options[option_index].name, "noClosingGU") == 0)
1815           {
1816           
1817           
1818             if (update_arg((void *)&(args_info->noClosingGU_flag), 0, &(args_info->noClosingGU_given),
1819                 &(local_args_info.noClosingGU_given), optarg, 0, 0, ARG_FLAG,
1820                 check_ambiguity, override, 1, 0, "noClosingGU", '-',
1821                 additional_error))
1822               goto failure;
1823           
1824           }
1825           /* Set the weight of the covariance term in the energy function
1826           
1827 .  */
1828           else if (strcmp (long_options[option_index].name, "cfactor") == 0)
1829           {
1830           
1831           
1832             if (update_arg( (void *)&(args_info->cfactor_arg), 
1833                  &(args_info->cfactor_orig), &(args_info->cfactor_given),
1834                 &(local_args_info.cfactor_given), optarg, 0, "1.0", ARG_DOUBLE,
1835                 check_ambiguity, override, 0, 0,
1836                 "cfactor", '-',
1837                 additional_error))
1838               goto failure;
1839           
1840           }
1841           /* Set the penalty for non-compatible sequences in the covariance term of the energy function
1842           
1843 .  */
1844           else if (strcmp (long_options[option_index].name, "nfactor") == 0)
1845           {
1846           
1847           
1848             if (update_arg( (void *)&(args_info->nfactor_arg), 
1849                  &(args_info->nfactor_orig), &(args_info->nfactor_given),
1850                 &(local_args_info.nfactor_given), optarg, 0, "1.0", ARG_DOUBLE,
1851                 check_ambiguity, override, 0, 0,
1852                 "nfactor", '-',
1853                 additional_error))
1854               goto failure;
1855           
1856           }
1857           /* use old energy evaluation, treating gaps as characters.
1858           
1859 .  */
1860           else if (strcmp (long_options[option_index].name, "old") == 0)
1861           {
1862           
1863           
1864             if (update_arg((void *)&(args_info->old_flag), 0, &(args_info->old_given),
1865                 &(local_args_info.old_given), optarg, 0, 0, ARG_FLAG,
1866                 check_ambiguity, override, 1, 0, "old", '-',
1867                 additional_error))
1868               goto failure;
1869           
1870           }
1871           /* Allow other pairs in addition to the usual AU,GC,and GU pairs.
1872 .  */
1873           else if (strcmp (long_options[option_index].name, "nsp") == 0)
1874           {
1875           
1876           
1877             if (update_arg( (void *)&(args_info->nsp_arg), 
1878                  &(args_info->nsp_orig), &(args_info->nsp_given),
1879                 &(local_args_info.nsp_given), optarg, 0, 0, ARG_STRING,
1880                 check_ambiguity, override, 0, 0,
1881                 "nsp", '-',
1882                 additional_error))
1883               goto failure;
1884           
1885           }
1886           /* Set the scaling of the Boltzmann factors
1887 .  */
1888           else if (strcmp (long_options[option_index].name, "betaScale") == 0)
1889           {
1890           
1891           
1892             if (update_arg( (void *)&(args_info->betaScale_arg), 
1893                  &(args_info->betaScale_orig), &(args_info->betaScale_given),
1894                 &(local_args_info.betaScale_given), optarg, 0, "1.", ARG_DOUBLE,
1895                 check_ambiguity, override, 0, 0,
1896                 "betaScale", '-',
1897                 additional_error))
1898               goto failure;
1899           
1900           }
1901           
1902           break;
1903         case '?':       /* Invalid option.  */
1904           /* `getopt_long' already printed an error message.  */
1905           goto failure;
1906
1907         default:        /* bug: option not considered.  */
1908           fprintf (stderr, "%s: option unknown: %c%s\n", RNAALIFOLD_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1909           abort ();
1910         } /* switch */
1911     } /* while */
1912
1913
1914
1915   if (check_required)
1916     {
1917       error += RNAalifold_cmdline_parser_required2 (args_info, argv[0], additional_error);
1918     }
1919
1920   RNAalifold_cmdline_parser_release (&local_args_info);
1921
1922   if ( error )
1923     return (EXIT_FAILURE);
1924
1925   if (optind < argc)
1926     {
1927       int i = 0 ;
1928       int found_prog_name = 0;
1929       /* whether program name, i.e., argv[0], is in the remaining args
1930          (this may happen with some implementations of getopt,
1931           but surely not with the one included by gengetopt) */
1932
1933
1934       args_info->inputs_num = argc - optind - found_prog_name;
1935       args_info->inputs =
1936         (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1937       while (optind < argc)
1938         args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1939     }
1940
1941   return 0;
1942
1943 failure:
1944   
1945   RNAalifold_cmdline_parser_release (&local_args_info);
1946   return (EXIT_FAILURE);
1947 }