Add missing binaty and statis library
[jabaws.git] / binaries / src / ViennaRNA / Progs / RNAsnoop_cmdl.c
1 /*
2   File autogenerated by gengetopt version 2.22.5
3   generated with the following command:
4   gengetopt -i RNAsnoop.ggo --file-name=RNAsnoop_cmdl --include-getopt --default-optional --func-name=RNAsnoop_cmdline_parser --arg-struct-name=RNAsnoop_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 "RNAsnoop_cmdl.h"
26
27 const char *RNAsnoop_args_info_purpose = "Find targets of a query H/ACA snoRNA";
28
29 const char *RNAsnoop_args_info_usage = "Usage: RNAsnoop [options]\n";
30
31 const char *RNAsnoop_args_info_description = "reads a target RNA sequence and a H/ACA snoRNA sequence\nfrom a target and query file, respectively and computes optimal\nand suboptimal secondary structures for their hybridization. The\ncalculation can be done roughly done in O(nm), where is n the length\nof the target sequence and m is the length of the snoRNA stem, as it\nis specially tailored to the special case of H/ACA snoRNA. For general\npurpose target predictions, please have a look at RNAduplex, RNAup,\nRNAcofold and RNAplex. Accessibility effects can be estimated by\nRNAsnoop if a RNAplfold accessibility profile is provided. \n\nThe computed optimal and suboptimal structure are written to\nstdout, one structure per line. Each line consist\nof: The structure in dot bracket format with a \"&\" separating the\ntwo strands. The '<>' brackets represent snoRNA intramolecular\ninteractions, while the '()' brackets represent intermolecular\ninteractions between the snoRNA and its target.\n\nThe range of the structure in the two sequences in the format\n\"from,to : from,to\"; the energy of duplex structure in\nkcal/mol. If available the opening energy are also returned.\n";
32
33 const char *RNAsnoop_args_info_detailed_help[] = {
34   "      --help                    Print help and exit",
35   "      --detailed-help           Print help, including all details and hidden \n                                  options, and exit",
36   "  -V, --version                 Print version and exit",
37   "\nInput Options:",
38   "  Below are command line options which alter the general input behavior of \n  RNAsnoop\n",
39   "  -L, --alignmentLength=INT     Limit the extent of the interactions to L \n                                  nucleotides  (default=`25')",
40   "  -C, --constraint              Calculate the stem structure subject to \n                                  constraints.\n                                    (default=off)",
41   "  The program reads first the stem sequence, then a string containing \n  constraints on 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   "  -s, --query=STRING            File containing the query sequence.\n",
43   "  Input sequences can be given piped to RNAsnoop or given in a query file with \n  the -s option. Note that the -s option implies that the -t option is also \n  used\n\n",
44   "  -t, --target=STRING           File containing the target sequence.\n",
45   "  Input sequences can be given piped to RNAsnoop or given in a target file with \n  the -t optionNote that the -t option implies that the -s option is also used\n\n",
46   "  -S, --suffix=STRING           Specificy the suffix that was added by RNAup to \n                                  the accessibility files\n\n                                    (default=`_u1_to_30.out')",
47   "  -P, --from-RNAplfold=STRING   Specify the directory where accessibility \n                                  profile generated by RNAplfold are found\n\n",
48   "\nAlgorithms:",
49   "  Options which alter the computing behaviour of RNAplex.\n  Please note that the options allowing to filter out snoRNA-RNA\n  duplexes expect the energy to be given in decacal/mol instead of\n  kcal/mol. A threshold of -2.8(kcal/mol) should be given as -280(decacal/mol)\n",
50   "  -A, --alignment-mode          Specify if RNAsnoop gets alignments or single \n                                  sequences as input\n\n                                    (default=off)",
51   "  -f, --fast-folding=INT        Speedup of the target search  (default=`1')",
52   "  This option allows to decide if the backtracking has to be\n  done (-f 1) or not (-f 0). For -f 1 the structure is computed based\n  on the standard energy model. This is the slowest mode of RNAsnoop. -f\n  0 is the fastest mode, as no structure are recomputed and only the\n  interaction energy is returned\n\n",
53   "  -c, --extension-cost=INT      Cost to add to each nucleotide in a duplex  \n                                  (default=`0')",
54   "  Cost of extending a duplex by one nucleotide. Allows to find\n  compact duplexes, having few/small bulges or interior loops. Only\n  useful when no accessibility profiles are available. This option is\n  disabled if accessibility profiles are used (-P option)\n\n",
55   "  -o, --minimal-right-duplex=INT\n                                Minimal Right Duplex Energy\n\n                                    (default=`-270')",
56   "  -l, --minimal-loop-energy=INT Minimal Right Duplex Energy\n                                    (default=`-280')",
57   "  Minimal Stem Loop Energy of the snoRNA. The energy should be\n  given in decacalories, i.e. a minimal stem-loop energy of -2.8\n  kcal/mol corresponds to -280 decacal/mol\n\n",
58   "  -p, --minimal-left-duplex=INT Minimal Left Duplex Energy\n\n                                    (default=`-170')",
59   "  -q, --minimal-duplex=INT      Minimal Duplex Energy\n\n                                    (default=`-1090')",
60   "  -d, --duplex-distance=INT     Distance between target 3' ends of two \n                                  consecutive duplexes\n                                    (default=`2')",
61   "  Distance between the target 3'ends of two consecutive\n  duplexes. Should be set to the maximal length of interaction to get\n  good results. Smaller d leads to larger overlaps between consecutive\n  duplexes\n\n",
62   "  -h, --minimal-stem-length=INT Minimal snoRNA stem length\n\n                                    (default=`5')",
63   "  -i, --maximal-stem-length=INT Maximal snoRNA stem length\n\n                                    (default=`120')",
64   "  -j, --minimal-duplex-box-length=INT\n                                Minimal distance between the duplex end and the \n                                  H/ACA box\n\n                                    (default=`11')",
65   "  -k, --maximal-duplex-box-length=INT\n                                Maximal distance between the duplex end and the \n                                  H/ACA box\n\n                                    (default=`16')",
66   "  -m, --minimal-snoRNA-stem-loop-length=INT\n                                Minimal number of nucleotides between the \n                                  beginning of stem loop and\n                                  beginning of the snoRNA sequence\n\n                                    (default=`1')",
67   "  -n, --maximal-snoRNA-stem-loop-length=INT\n                                Maximal number of nucleotides between the \n                                  beginning of stem loop and\n                                  beginning of the snoRNA sequence\n\n                                    (default=`100000')",
68   "  -v, --minimal-snoRNA-duplex-length=INT\n                                Minimal distance between duplex start and \n                                  snoRNA\n\n                                    (default=`0')",
69   "  -w, --maximal-snoRNA-duplex-length=INT\n                                Maximal distance between duplex start and \n                                  snoRNA\n\n                                    (default=`0')",
70   "  -x, --minimal-duplex-stem-energy=INT\n                                Minimal duplex stem energy\n\n                                    (default=`-1370')",
71   "  -y, --minimal-total-energy=INT\n                                Minimal total energy\n\n                                    (default=`100000')",
72   "  -a, --maximal-stem-asymmetry=INT\n                                Maximal snoRNA stem asymmetry\n\n                                    (default=`30')",
73   "  -b, --minimal-lower-stem-energy=INT\n                                Minimal lower stem energy\n\n                                    (default=`100000')",
74   "\nOutput options:",
75   "  Options that modifies the output\n\n",
76   "  -e, --energy-threshold=DOUBLE Maximal energy difference between the mfe and \n                                  the desired suboptimal\n                                    (default=`-1')",
77   "  Energy range for a duplex to be returned. The threshold is set on the total \n  energy of interaction, i.e. the hybridizationenergy corrected for opening \n  energy if -a is set or the energy corrected by -c. If unset, only the mfe \n  will be returned\n\n",
78   "  -I, --produce-ps              Draw annotated 2D structures for a list of \n                                  dot-bracket structures\n                                    (default=off)",
79   "  This option allows to produce interaction figures in PS-format with \n  conservation/accessibility annotation, if available\n\n",
80   "  -O, --output_directory=STRING Set where the generated figures should be \n                                  stored\n\n                                    (default=`./')",
81   "  -N, --direct-redraw           Outputs 2D interactions concurrently with the \n                                  interaction calculation for each suboptimal \n                                  interaction. The -I option should be \n                                  preferred.\n\n                                    (default=off)",
82   "  -U, --from-RNAup=STRING       Specify the directory where accessibility \n                                  profiles generated by RNAup are found\n\n",
83   "\nIf in doubt our program is right, nature is at fault.\nComments should be sent to rna@tbi.univie.ac.at.\n",
84     0
85 };
86
87 static void
88 init_help_array(void)
89 {
90   RNAsnoop_args_info_help[0] = RNAsnoop_args_info_detailed_help[0];
91   RNAsnoop_args_info_help[1] = RNAsnoop_args_info_detailed_help[1];
92   RNAsnoop_args_info_help[2] = RNAsnoop_args_info_detailed_help[2];
93   RNAsnoop_args_info_help[3] = RNAsnoop_args_info_detailed_help[3];
94   RNAsnoop_args_info_help[4] = RNAsnoop_args_info_detailed_help[4];
95   RNAsnoop_args_info_help[5] = RNAsnoop_args_info_detailed_help[5];
96   RNAsnoop_args_info_help[6] = RNAsnoop_args_info_detailed_help[6];
97   RNAsnoop_args_info_help[7] = RNAsnoop_args_info_detailed_help[8];
98   RNAsnoop_args_info_help[8] = RNAsnoop_args_info_detailed_help[10];
99   RNAsnoop_args_info_help[9] = RNAsnoop_args_info_detailed_help[12];
100   RNAsnoop_args_info_help[10] = RNAsnoop_args_info_detailed_help[13];
101   RNAsnoop_args_info_help[11] = RNAsnoop_args_info_detailed_help[14];
102   RNAsnoop_args_info_help[12] = RNAsnoop_args_info_detailed_help[15];
103   RNAsnoop_args_info_help[13] = RNAsnoop_args_info_detailed_help[16];
104   RNAsnoop_args_info_help[14] = RNAsnoop_args_info_detailed_help[17];
105   RNAsnoop_args_info_help[15] = RNAsnoop_args_info_detailed_help[19];
106   RNAsnoop_args_info_help[16] = RNAsnoop_args_info_detailed_help[21];
107   RNAsnoop_args_info_help[17] = RNAsnoop_args_info_detailed_help[22];
108   RNAsnoop_args_info_help[18] = RNAsnoop_args_info_detailed_help[24];
109   RNAsnoop_args_info_help[19] = RNAsnoop_args_info_detailed_help[25];
110   RNAsnoop_args_info_help[20] = RNAsnoop_args_info_detailed_help[26];
111   RNAsnoop_args_info_help[21] = RNAsnoop_args_info_detailed_help[28];
112   RNAsnoop_args_info_help[22] = RNAsnoop_args_info_detailed_help[29];
113   RNAsnoop_args_info_help[23] = RNAsnoop_args_info_detailed_help[30];
114   RNAsnoop_args_info_help[24] = RNAsnoop_args_info_detailed_help[31];
115   RNAsnoop_args_info_help[25] = RNAsnoop_args_info_detailed_help[32];
116   RNAsnoop_args_info_help[26] = RNAsnoop_args_info_detailed_help[33];
117   RNAsnoop_args_info_help[27] = RNAsnoop_args_info_detailed_help[34];
118   RNAsnoop_args_info_help[28] = RNAsnoop_args_info_detailed_help[35];
119   RNAsnoop_args_info_help[29] = RNAsnoop_args_info_detailed_help[36];
120   RNAsnoop_args_info_help[30] = RNAsnoop_args_info_detailed_help[37];
121   RNAsnoop_args_info_help[31] = RNAsnoop_args_info_detailed_help[38];
122   RNAsnoop_args_info_help[32] = RNAsnoop_args_info_detailed_help[39];
123   RNAsnoop_args_info_help[33] = RNAsnoop_args_info_detailed_help[40];
124   RNAsnoop_args_info_help[34] = RNAsnoop_args_info_detailed_help[41];
125   RNAsnoop_args_info_help[35] = RNAsnoop_args_info_detailed_help[42];
126   RNAsnoop_args_info_help[36] = RNAsnoop_args_info_detailed_help[44];
127   RNAsnoop_args_info_help[37] = RNAsnoop_args_info_detailed_help[46];
128   RNAsnoop_args_info_help[38] = RNAsnoop_args_info_detailed_help[47];
129   RNAsnoop_args_info_help[39] = RNAsnoop_args_info_detailed_help[48];
130   RNAsnoop_args_info_help[40] = RNAsnoop_args_info_detailed_help[49];
131   RNAsnoop_args_info_help[41] = 0; 
132   
133 }
134
135 const char *RNAsnoop_args_info_help[42];
136
137 typedef enum {ARG_NO
138   , ARG_FLAG
139   , ARG_STRING
140   , ARG_INT
141   , ARG_DOUBLE
142 } RNAsnoop_cmdline_parser_arg_type;
143
144 static
145 void clear_given (struct RNAsnoop_args_info *args_info);
146 static
147 void clear_args (struct RNAsnoop_args_info *args_info);
148
149 static int
150 RNAsnoop_cmdline_parser_internal (int argc, char **argv, struct RNAsnoop_args_info *args_info,
151                         struct RNAsnoop_cmdline_parser_params *params, const char *additional_error);
152
153
154 static char *
155 gengetopt_strdup (const char *s);
156
157 static
158 void clear_given (struct RNAsnoop_args_info *args_info)
159 {
160   args_info->help_given = 0 ;
161   args_info->detailed_help_given = 0 ;
162   args_info->version_given = 0 ;
163   args_info->alignmentLength_given = 0 ;
164   args_info->constraint_given = 0 ;
165   args_info->query_given = 0 ;
166   args_info->target_given = 0 ;
167   args_info->suffix_given = 0 ;
168   args_info->from_RNAplfold_given = 0 ;
169   args_info->alignment_mode_given = 0 ;
170   args_info->fast_folding_given = 0 ;
171   args_info->extension_cost_given = 0 ;
172   args_info->minimal_right_duplex_given = 0 ;
173   args_info->minimal_loop_energy_given = 0 ;
174   args_info->minimal_left_duplex_given = 0 ;
175   args_info->minimal_duplex_given = 0 ;
176   args_info->duplex_distance_given = 0 ;
177   args_info->minimal_stem_length_given = 0 ;
178   args_info->maximal_stem_length_given = 0 ;
179   args_info->minimal_duplex_box_length_given = 0 ;
180   args_info->maximal_duplex_box_length_given = 0 ;
181   args_info->minimal_snoRNA_stem_loop_length_given = 0 ;
182   args_info->maximal_snoRNA_stem_loop_length_given = 0 ;
183   args_info->minimal_snoRNA_duplex_length_given = 0 ;
184   args_info->maximal_snoRNA_duplex_length_given = 0 ;
185   args_info->minimal_duplex_stem_energy_given = 0 ;
186   args_info->minimal_total_energy_given = 0 ;
187   args_info->maximal_stem_asymmetry_given = 0 ;
188   args_info->minimal_lower_stem_energy_given = 0 ;
189   args_info->energy_threshold_given = 0 ;
190   args_info->produce_ps_given = 0 ;
191   args_info->output_directory_given = 0 ;
192   args_info->direct_redraw_given = 0 ;
193   args_info->from_RNAup_given = 0 ;
194 }
195
196 static
197 void clear_args (struct RNAsnoop_args_info *args_info)
198 {
199   FIX_UNUSED (args_info);
200   args_info->alignmentLength_arg = 25;
201   args_info->alignmentLength_orig = NULL;
202   args_info->constraint_flag = 0;
203   args_info->query_arg = NULL;
204   args_info->query_orig = NULL;
205   args_info->target_arg = NULL;
206   args_info->target_orig = NULL;
207   args_info->suffix_arg = gengetopt_strdup ("_u1_to_30.out");
208   args_info->suffix_orig = NULL;
209   args_info->from_RNAplfold_arg = NULL;
210   args_info->from_RNAplfold_orig = NULL;
211   args_info->alignment_mode_flag = 0;
212   args_info->fast_folding_arg = 1;
213   args_info->fast_folding_orig = NULL;
214   args_info->extension_cost_arg = 0;
215   args_info->extension_cost_orig = NULL;
216   args_info->minimal_right_duplex_arg = -270;
217   args_info->minimal_right_duplex_orig = NULL;
218   args_info->minimal_loop_energy_arg = -280;
219   args_info->minimal_loop_energy_orig = NULL;
220   args_info->minimal_left_duplex_arg = -170;
221   args_info->minimal_left_duplex_orig = NULL;
222   args_info->minimal_duplex_arg = -1090;
223   args_info->minimal_duplex_orig = NULL;
224   args_info->duplex_distance_arg = 2;
225   args_info->duplex_distance_orig = NULL;
226   args_info->minimal_stem_length_arg = 5;
227   args_info->minimal_stem_length_orig = NULL;
228   args_info->maximal_stem_length_arg = 120;
229   args_info->maximal_stem_length_orig = NULL;
230   args_info->minimal_duplex_box_length_arg = 11;
231   args_info->minimal_duplex_box_length_orig = NULL;
232   args_info->maximal_duplex_box_length_arg = 16;
233   args_info->maximal_duplex_box_length_orig = NULL;
234   args_info->minimal_snoRNA_stem_loop_length_arg = 1;
235   args_info->minimal_snoRNA_stem_loop_length_orig = NULL;
236   args_info->maximal_snoRNA_stem_loop_length_arg = 100000;
237   args_info->maximal_snoRNA_stem_loop_length_orig = NULL;
238   args_info->minimal_snoRNA_duplex_length_arg = 0;
239   args_info->minimal_snoRNA_duplex_length_orig = NULL;
240   args_info->maximal_snoRNA_duplex_length_arg = 0;
241   args_info->maximal_snoRNA_duplex_length_orig = NULL;
242   args_info->minimal_duplex_stem_energy_arg = -1370;
243   args_info->minimal_duplex_stem_energy_orig = NULL;
244   args_info->minimal_total_energy_arg = 100000;
245   args_info->minimal_total_energy_orig = NULL;
246   args_info->maximal_stem_asymmetry_arg = 30;
247   args_info->maximal_stem_asymmetry_orig = NULL;
248   args_info->minimal_lower_stem_energy_arg = 100000;
249   args_info->minimal_lower_stem_energy_orig = NULL;
250   args_info->energy_threshold_arg = -1;
251   args_info->energy_threshold_orig = NULL;
252   args_info->produce_ps_flag = 0;
253   args_info->output_directory_arg = gengetopt_strdup ("./");
254   args_info->output_directory_orig = NULL;
255   args_info->direct_redraw_flag = 0;
256   args_info->from_RNAup_arg = NULL;
257   args_info->from_RNAup_orig = NULL;
258   
259 }
260
261 static
262 void init_args_info(struct RNAsnoop_args_info *args_info)
263 {
264
265   init_help_array(); 
266   args_info->help_help = RNAsnoop_args_info_detailed_help[0] ;
267   args_info->detailed_help_help = RNAsnoop_args_info_detailed_help[1] ;
268   args_info->version_help = RNAsnoop_args_info_detailed_help[2] ;
269   args_info->alignmentLength_help = RNAsnoop_args_info_detailed_help[5] ;
270   args_info->constraint_help = RNAsnoop_args_info_detailed_help[6] ;
271   args_info->query_help = RNAsnoop_args_info_detailed_help[8] ;
272   args_info->target_help = RNAsnoop_args_info_detailed_help[10] ;
273   args_info->suffix_help = RNAsnoop_args_info_detailed_help[12] ;
274   args_info->from_RNAplfold_help = RNAsnoop_args_info_detailed_help[13] ;
275   args_info->alignment_mode_help = RNAsnoop_args_info_detailed_help[16] ;
276   args_info->fast_folding_help = RNAsnoop_args_info_detailed_help[17] ;
277   args_info->extension_cost_help = RNAsnoop_args_info_detailed_help[19] ;
278   args_info->minimal_right_duplex_help = RNAsnoop_args_info_detailed_help[21] ;
279   args_info->minimal_loop_energy_help = RNAsnoop_args_info_detailed_help[22] ;
280   args_info->minimal_left_duplex_help = RNAsnoop_args_info_detailed_help[24] ;
281   args_info->minimal_duplex_help = RNAsnoop_args_info_detailed_help[25] ;
282   args_info->duplex_distance_help = RNAsnoop_args_info_detailed_help[26] ;
283   args_info->minimal_stem_length_help = RNAsnoop_args_info_detailed_help[28] ;
284   args_info->maximal_stem_length_help = RNAsnoop_args_info_detailed_help[29] ;
285   args_info->minimal_duplex_box_length_help = RNAsnoop_args_info_detailed_help[30] ;
286   args_info->maximal_duplex_box_length_help = RNAsnoop_args_info_detailed_help[31] ;
287   args_info->minimal_snoRNA_stem_loop_length_help = RNAsnoop_args_info_detailed_help[32] ;
288   args_info->maximal_snoRNA_stem_loop_length_help = RNAsnoop_args_info_detailed_help[33] ;
289   args_info->minimal_snoRNA_duplex_length_help = RNAsnoop_args_info_detailed_help[34] ;
290   args_info->maximal_snoRNA_duplex_length_help = RNAsnoop_args_info_detailed_help[35] ;
291   args_info->minimal_duplex_stem_energy_help = RNAsnoop_args_info_detailed_help[36] ;
292   args_info->minimal_total_energy_help = RNAsnoop_args_info_detailed_help[37] ;
293   args_info->maximal_stem_asymmetry_help = RNAsnoop_args_info_detailed_help[38] ;
294   args_info->minimal_lower_stem_energy_help = RNAsnoop_args_info_detailed_help[39] ;
295   args_info->energy_threshold_help = RNAsnoop_args_info_detailed_help[42] ;
296   args_info->produce_ps_help = RNAsnoop_args_info_detailed_help[44] ;
297   args_info->output_directory_help = RNAsnoop_args_info_detailed_help[46] ;
298   args_info->direct_redraw_help = RNAsnoop_args_info_detailed_help[47] ;
299   args_info->from_RNAup_help = RNAsnoop_args_info_detailed_help[48] ;
300   
301 }
302
303 void
304 RNAsnoop_cmdline_parser_print_version (void)
305 {
306   printf ("%s %s\n",
307      (strlen(RNASNOOP_CMDLINE_PARSER_PACKAGE_NAME) ? RNASNOOP_CMDLINE_PARSER_PACKAGE_NAME : RNASNOOP_CMDLINE_PARSER_PACKAGE),
308      RNASNOOP_CMDLINE_PARSER_VERSION);
309 }
310
311 static void print_help_common(void) {
312   RNAsnoop_cmdline_parser_print_version ();
313
314   if (strlen(RNAsnoop_args_info_purpose) > 0)
315     printf("\n%s\n", RNAsnoop_args_info_purpose);
316
317   if (strlen(RNAsnoop_args_info_usage) > 0)
318     printf("\n%s\n", RNAsnoop_args_info_usage);
319
320   printf("\n");
321
322   if (strlen(RNAsnoop_args_info_description) > 0)
323     printf("%s\n\n", RNAsnoop_args_info_description);
324 }
325
326 void
327 RNAsnoop_cmdline_parser_print_help (void)
328 {
329   int i = 0;
330   print_help_common();
331   while (RNAsnoop_args_info_help[i])
332     printf("%s\n", RNAsnoop_args_info_help[i++]);
333 }
334
335 void
336 RNAsnoop_cmdline_parser_print_detailed_help (void)
337 {
338   int i = 0;
339   print_help_common();
340   while (RNAsnoop_args_info_detailed_help[i])
341     printf("%s\n", RNAsnoop_args_info_detailed_help[i++]);
342 }
343
344 void
345 RNAsnoop_cmdline_parser_init (struct RNAsnoop_args_info *args_info)
346 {
347   clear_given (args_info);
348   clear_args (args_info);
349   init_args_info (args_info);
350 }
351
352 void
353 RNAsnoop_cmdline_parser_params_init(struct RNAsnoop_cmdline_parser_params *params)
354 {
355   if (params)
356     { 
357       params->override = 0;
358       params->initialize = 1;
359       params->check_required = 1;
360       params->check_ambiguity = 0;
361       params->print_errors = 1;
362     }
363 }
364
365 struct RNAsnoop_cmdline_parser_params *
366 RNAsnoop_cmdline_parser_params_create(void)
367 {
368   struct RNAsnoop_cmdline_parser_params *params = 
369     (struct RNAsnoop_cmdline_parser_params *)malloc(sizeof(struct RNAsnoop_cmdline_parser_params));
370   RNAsnoop_cmdline_parser_params_init(params);  
371   return params;
372 }
373
374 static void
375 free_string_field (char **s)
376 {
377   if (*s)
378     {
379       free (*s);
380       *s = 0;
381     }
382 }
383
384
385 static void
386 RNAsnoop_cmdline_parser_release (struct RNAsnoop_args_info *args_info)
387 {
388
389   free_string_field (&(args_info->alignmentLength_orig));
390   free_string_field (&(args_info->query_arg));
391   free_string_field (&(args_info->query_orig));
392   free_string_field (&(args_info->target_arg));
393   free_string_field (&(args_info->target_orig));
394   free_string_field (&(args_info->suffix_arg));
395   free_string_field (&(args_info->suffix_orig));
396   free_string_field (&(args_info->from_RNAplfold_arg));
397   free_string_field (&(args_info->from_RNAplfold_orig));
398   free_string_field (&(args_info->fast_folding_orig));
399   free_string_field (&(args_info->extension_cost_orig));
400   free_string_field (&(args_info->minimal_right_duplex_orig));
401   free_string_field (&(args_info->minimal_loop_energy_orig));
402   free_string_field (&(args_info->minimal_left_duplex_orig));
403   free_string_field (&(args_info->minimal_duplex_orig));
404   free_string_field (&(args_info->duplex_distance_orig));
405   free_string_field (&(args_info->minimal_stem_length_orig));
406   free_string_field (&(args_info->maximal_stem_length_orig));
407   free_string_field (&(args_info->minimal_duplex_box_length_orig));
408   free_string_field (&(args_info->maximal_duplex_box_length_orig));
409   free_string_field (&(args_info->minimal_snoRNA_stem_loop_length_orig));
410   free_string_field (&(args_info->maximal_snoRNA_stem_loop_length_orig));
411   free_string_field (&(args_info->minimal_snoRNA_duplex_length_orig));
412   free_string_field (&(args_info->maximal_snoRNA_duplex_length_orig));
413   free_string_field (&(args_info->minimal_duplex_stem_energy_orig));
414   free_string_field (&(args_info->minimal_total_energy_orig));
415   free_string_field (&(args_info->maximal_stem_asymmetry_orig));
416   free_string_field (&(args_info->minimal_lower_stem_energy_orig));
417   free_string_field (&(args_info->energy_threshold_orig));
418   free_string_field (&(args_info->output_directory_arg));
419   free_string_field (&(args_info->output_directory_orig));
420   free_string_field (&(args_info->from_RNAup_arg));
421   free_string_field (&(args_info->from_RNAup_orig));
422   
423   
424
425   clear_given (args_info);
426 }
427
428
429 static void
430 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
431 {
432   FIX_UNUSED (values);
433   if (arg) {
434     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
435   } else {
436     fprintf(outfile, "%s\n", opt);
437   }
438 }
439
440
441 int
442 RNAsnoop_cmdline_parser_dump(FILE *outfile, struct RNAsnoop_args_info *args_info)
443 {
444   int i = 0;
445
446   if (!outfile)
447     {
448       fprintf (stderr, "%s: cannot dump options to stream\n", RNASNOOP_CMDLINE_PARSER_PACKAGE);
449       return EXIT_FAILURE;
450     }
451
452   if (args_info->help_given)
453     write_into_file(outfile, "help", 0, 0 );
454   if (args_info->detailed_help_given)
455     write_into_file(outfile, "detailed-help", 0, 0 );
456   if (args_info->version_given)
457     write_into_file(outfile, "version", 0, 0 );
458   if (args_info->alignmentLength_given)
459     write_into_file(outfile, "alignmentLength", args_info->alignmentLength_orig, 0);
460   if (args_info->constraint_given)
461     write_into_file(outfile, "constraint", 0, 0 );
462   if (args_info->query_given)
463     write_into_file(outfile, "query", args_info->query_orig, 0);
464   if (args_info->target_given)
465     write_into_file(outfile, "target", args_info->target_orig, 0);
466   if (args_info->suffix_given)
467     write_into_file(outfile, "suffix", args_info->suffix_orig, 0);
468   if (args_info->from_RNAplfold_given)
469     write_into_file(outfile, "from-RNAplfold", args_info->from_RNAplfold_orig, 0);
470   if (args_info->alignment_mode_given)
471     write_into_file(outfile, "alignment-mode", 0, 0 );
472   if (args_info->fast_folding_given)
473     write_into_file(outfile, "fast-folding", args_info->fast_folding_orig, 0);
474   if (args_info->extension_cost_given)
475     write_into_file(outfile, "extension-cost", args_info->extension_cost_orig, 0);
476   if (args_info->minimal_right_duplex_given)
477     write_into_file(outfile, "minimal-right-duplex", args_info->minimal_right_duplex_orig, 0);
478   if (args_info->minimal_loop_energy_given)
479     write_into_file(outfile, "minimal-loop-energy", args_info->minimal_loop_energy_orig, 0);
480   if (args_info->minimal_left_duplex_given)
481     write_into_file(outfile, "minimal-left-duplex", args_info->minimal_left_duplex_orig, 0);
482   if (args_info->minimal_duplex_given)
483     write_into_file(outfile, "minimal-duplex", args_info->minimal_duplex_orig, 0);
484   if (args_info->duplex_distance_given)
485     write_into_file(outfile, "duplex-distance", args_info->duplex_distance_orig, 0);
486   if (args_info->minimal_stem_length_given)
487     write_into_file(outfile, "minimal-stem-length", args_info->minimal_stem_length_orig, 0);
488   if (args_info->maximal_stem_length_given)
489     write_into_file(outfile, "maximal-stem-length", args_info->maximal_stem_length_orig, 0);
490   if (args_info->minimal_duplex_box_length_given)
491     write_into_file(outfile, "minimal-duplex-box-length", args_info->minimal_duplex_box_length_orig, 0);
492   if (args_info->maximal_duplex_box_length_given)
493     write_into_file(outfile, "maximal-duplex-box-length", args_info->maximal_duplex_box_length_orig, 0);
494   if (args_info->minimal_snoRNA_stem_loop_length_given)
495     write_into_file(outfile, "minimal-snoRNA-stem-loop-length", args_info->minimal_snoRNA_stem_loop_length_orig, 0);
496   if (args_info->maximal_snoRNA_stem_loop_length_given)
497     write_into_file(outfile, "maximal-snoRNA-stem-loop-length", args_info->maximal_snoRNA_stem_loop_length_orig, 0);
498   if (args_info->minimal_snoRNA_duplex_length_given)
499     write_into_file(outfile, "minimal-snoRNA-duplex-length", args_info->minimal_snoRNA_duplex_length_orig, 0);
500   if (args_info->maximal_snoRNA_duplex_length_given)
501     write_into_file(outfile, "maximal-snoRNA-duplex-length", args_info->maximal_snoRNA_duplex_length_orig, 0);
502   if (args_info->minimal_duplex_stem_energy_given)
503     write_into_file(outfile, "minimal-duplex-stem-energy", args_info->minimal_duplex_stem_energy_orig, 0);
504   if (args_info->minimal_total_energy_given)
505     write_into_file(outfile, "minimal-total-energy", args_info->minimal_total_energy_orig, 0);
506   if (args_info->maximal_stem_asymmetry_given)
507     write_into_file(outfile, "maximal-stem-asymmetry", args_info->maximal_stem_asymmetry_orig, 0);
508   if (args_info->minimal_lower_stem_energy_given)
509     write_into_file(outfile, "minimal-lower-stem-energy", args_info->minimal_lower_stem_energy_orig, 0);
510   if (args_info->energy_threshold_given)
511     write_into_file(outfile, "energy-threshold", args_info->energy_threshold_orig, 0);
512   if (args_info->produce_ps_given)
513     write_into_file(outfile, "produce-ps", 0, 0 );
514   if (args_info->output_directory_given)
515     write_into_file(outfile, "output_directory", args_info->output_directory_orig, 0);
516   if (args_info->direct_redraw_given)
517     write_into_file(outfile, "direct-redraw", 0, 0 );
518   if (args_info->from_RNAup_given)
519     write_into_file(outfile, "from-RNAup", args_info->from_RNAup_orig, 0);
520   
521
522   i = EXIT_SUCCESS;
523   return i;
524 }
525
526 int
527 RNAsnoop_cmdline_parser_file_save(const char *filename, struct RNAsnoop_args_info *args_info)
528 {
529   FILE *outfile;
530   int i = 0;
531
532   outfile = fopen(filename, "w");
533
534   if (!outfile)
535     {
536       fprintf (stderr, "%s: cannot open file for writing: %s\n", RNASNOOP_CMDLINE_PARSER_PACKAGE, filename);
537       return EXIT_FAILURE;
538     }
539
540   i = RNAsnoop_cmdline_parser_dump(outfile, args_info);
541   fclose (outfile);
542
543   return i;
544 }
545
546 void
547 RNAsnoop_cmdline_parser_free (struct RNAsnoop_args_info *args_info)
548 {
549   RNAsnoop_cmdline_parser_release (args_info);
550 }
551
552 /** @brief replacement of strdup, which is not standard */
553 char *
554 gengetopt_strdup (const char *s)
555 {
556   char *result = 0;
557   if (!s)
558     return result;
559
560   result = (char*)malloc(strlen(s) + 1);
561   if (result == (char*)0)
562     return (char*)0;
563   strcpy(result, s);
564   return result;
565 }
566
567 int
568 RNAsnoop_cmdline_parser (int argc, char **argv, struct RNAsnoop_args_info *args_info)
569 {
570   return RNAsnoop_cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
571 }
572
573 int
574 RNAsnoop_cmdline_parser_ext (int argc, char **argv, struct RNAsnoop_args_info *args_info,
575                    struct RNAsnoop_cmdline_parser_params *params)
576 {
577   int result;
578   result = RNAsnoop_cmdline_parser_internal (argc, argv, args_info, params, 0);
579
580   if (result == EXIT_FAILURE)
581     {
582       RNAsnoop_cmdline_parser_free (args_info);
583       exit (EXIT_FAILURE);
584     }
585   
586   return result;
587 }
588
589 int
590 RNAsnoop_cmdline_parser2 (int argc, char **argv, struct RNAsnoop_args_info *args_info, int override, int initialize, int check_required)
591 {
592   int result;
593   struct RNAsnoop_cmdline_parser_params params;
594   
595   params.override = override;
596   params.initialize = initialize;
597   params.check_required = check_required;
598   params.check_ambiguity = 0;
599   params.print_errors = 1;
600
601   result = RNAsnoop_cmdline_parser_internal (argc, argv, args_info, &params, 0);
602
603   if (result == EXIT_FAILURE)
604     {
605       RNAsnoop_cmdline_parser_free (args_info);
606       exit (EXIT_FAILURE);
607     }
608   
609   return result;
610 }
611
612 int
613 RNAsnoop_cmdline_parser_required (struct RNAsnoop_args_info *args_info, const char *prog_name)
614 {
615   FIX_UNUSED (args_info);
616   FIX_UNUSED (prog_name);
617   return EXIT_SUCCESS;
618 }
619
620 /*
621  * Extracted from the glibc source tree, version 2.3.6
622  *
623  * Licensed under the GPL as per the whole glibc source tree.
624  *
625  * This file was modified so that getopt_long can be called
626  * many times without risking previous memory to be spoiled.
627  *
628  * Modified by Andre Noll and Lorenzo Bettini for use in
629  * GNU gengetopt generated files.
630  *
631  */
632
633 /* 
634  * we must include anything we need since this file is not thought to be
635  * inserted in a file already using getopt.h
636  *
637  * Lorenzo
638  */
639
640 struct option
641 {
642   const char *name;
643   /* has_arg can't be an enum because some compilers complain about
644      type mismatches in all the code that assumes it is an int.  */
645   int has_arg;
646   int *flag;
647   int val;
648 };
649
650 /* This version of `getopt' appears to the caller like standard Unix `getopt'
651    but it behaves differently for the user, since it allows the user
652    to intersperse the options with the other arguments.
653
654    As `getopt' works, it permutes the elements of ARGV so that,
655    when it is done, all the options precede everything else.  Thus
656    all application programs are extended to handle flexible argument order.
657 */
658 /*
659    If the field `flag' is not NULL, it points to a variable that is set
660    to the value given in the field `val' when the option is found, but
661    left unchanged if the option is not found.
662
663    To have a long-named option do something other than set an `int' to
664    a compiled-in constant, such as set a value from `custom_optarg', set the
665    option's `flag' field to zero and its `val' field to a nonzero
666    value (the equivalent single-letter option character, if there is
667    one).  For long options that have a zero `flag' field, `getopt'
668    returns the contents of the `val' field.  */
669
670 /* Names for the values of the `has_arg' field of `struct option'.  */
671 #ifndef no_argument
672 #define no_argument             0
673 #endif
674
675 #ifndef required_argument
676 #define required_argument       1
677 #endif
678
679 #ifndef optional_argument
680 #define optional_argument       2
681 #endif
682
683 struct custom_getopt_data {
684         /*
685          * These have exactly the same meaning as the corresponding global variables,
686          * except that they are used for the reentrant versions of getopt.
687          */
688         int custom_optind;
689         int custom_opterr;
690         int custom_optopt;
691         char *custom_optarg;
692
693         /* True if the internal members have been initialized.  */
694         int initialized;
695
696         /*
697          * The next char to be scanned in the option-element in which the last option
698          * character we returned was found.  This allows us to pick up the scan where
699          * we left off.  If this is zero, or a null string, it means resume the scan by
700          * advancing to the next ARGV-element.
701          */
702         char *nextchar;
703
704         /*
705          * Describe the part of ARGV that contains non-options that have been skipped.
706          * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
707          * the index after the last of them.
708          */
709         int first_nonopt;
710         int last_nonopt;
711 };
712
713 /*
714  * the variables optarg, optind, opterr and optopt are renamed with
715  * the custom_ prefix so that they don't interfere with getopt ones.
716  *
717  * Moreover they're static so they are visible only from within the
718  * file where this very file will be included.
719  */
720
721 /*
722  * For communication from `custom_getopt' to the caller.  When `custom_getopt' finds an
723  * option that takes an argument, the argument value is returned here.
724  */
725 static char *custom_optarg;
726
727 /*
728  * Index in ARGV of the next element to be scanned.  This is used for
729  * communication to and from the caller and for communication between
730  * successive calls to `custom_getopt'.
731  *
732  * On entry to `custom_getopt', 1 means this is the first call; initialize.
733  *
734  * When `custom_getopt' returns -1, this is the index of the first of the non-option
735  * elements that the caller should itself scan.
736  *
737  * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
738  * has been scanned so far.
739  *
740  * 1003.2 says this must be 1 before any call.
741  */
742 static int custom_optind = 1;
743
744 /*
745  * Callers store zero here to inhibit the error message for unrecognized
746  * options.
747  */
748 static int custom_opterr = 1;
749
750 /*
751  * Set to an option character which was unrecognized.  This must be initialized
752  * on some systems to avoid linking in the system's own getopt implementation.
753  */
754 static int custom_optopt = '?';
755
756 /*
757  * Exchange two adjacent subsequences of ARGV.  One subsequence is elements
758  * [first_nonopt,last_nonopt) which contains all the non-options that have been
759  * skipped so far.  The other is elements [last_nonopt,custom_optind), which contains
760  * all the options processed since those non-options were skipped.
761  * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
762  * indices of the non-options in ARGV after they are moved.
763  */
764 static void exchange(char **argv, struct custom_getopt_data *d)
765 {
766         int bottom = d->first_nonopt;
767         int middle = d->last_nonopt;
768         int top = d->custom_optind;
769         char *tem;
770
771         /*
772          * Exchange the shorter segment with the far end of the longer segment.
773          * That puts the shorter segment into the right place.  It leaves the
774          * longer segment in the right place overall, but it consists of two
775          * parts that need to be swapped next.
776          */
777         while (top > middle && middle > bottom) {
778                 if (top - middle > middle - bottom) {
779                         /* Bottom segment is the short one.  */
780                         int len = middle - bottom;
781                         int i;
782
783                         /* Swap it with the top part of the top segment.  */
784                         for (i = 0; i < len; i++) {
785                                 tem = argv[bottom + i];
786                                 argv[bottom + i] =
787                                         argv[top - (middle - bottom) + i];
788                                 argv[top - (middle - bottom) + i] = tem;
789                         }
790                         /* Exclude the moved bottom segment from further swapping.  */
791                         top -= len;
792                 } else {
793                         /* Top segment is the short one.  */
794                         int len = top - middle;
795                         int i;
796
797                         /* Swap it with the bottom part of the bottom segment.  */
798                         for (i = 0; i < len; i++) {
799                                 tem = argv[bottom + i];
800                                 argv[bottom + i] = argv[middle + i];
801                                 argv[middle + i] = tem;
802                         }
803                         /* Exclude the moved top segment from further swapping.  */
804                         bottom += len;
805                 }
806         }
807         /* Update records for the slots the non-options now occupy.  */
808         d->first_nonopt += (d->custom_optind - d->last_nonopt);
809         d->last_nonopt = d->custom_optind;
810 }
811
812 /* Initialize the internal data when the first call is made.  */
813 static void custom_getopt_initialize(struct custom_getopt_data *d)
814 {
815         /*
816          * Start processing options with ARGV-element 1 (since ARGV-element 0
817          * is the program name); the sequence of previously skipped non-option
818          * ARGV-elements is empty.
819          */
820         d->first_nonopt = d->last_nonopt = d->custom_optind;
821         d->nextchar = NULL;
822         d->initialized = 1;
823 }
824
825 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
826
827 /* return: zero: continue, nonzero: return given value to user */
828 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
829         struct custom_getopt_data *d)
830 {
831         /*
832          * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
833          * moved back by the user (who may also have changed the arguments).
834          */
835         if (d->last_nonopt > d->custom_optind)
836                 d->last_nonopt = d->custom_optind;
837         if (d->first_nonopt > d->custom_optind)
838                 d->first_nonopt = d->custom_optind;
839         /*
840          * If we have just processed some options following some
841          * non-options, exchange them so that the options come first.
842          */
843         if (d->first_nonopt != d->last_nonopt &&
844                         d->last_nonopt != d->custom_optind)
845                 exchange((char **) argv, d);
846         else if (d->last_nonopt != d->custom_optind)
847                 d->first_nonopt = d->custom_optind;
848         /*
849          * Skip any additional non-options and extend the range of
850          * non-options previously skipped.
851          */
852         while (d->custom_optind < argc && NONOPTION_P)
853                 d->custom_optind++;
854         d->last_nonopt = d->custom_optind;
855         /*
856          * The special ARGV-element `--' means premature end of options.  Skip
857          * it like a null option, then exchange with previous non-options as if
858          * it were an option, then skip everything else like a non-option.
859          */
860         if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
861                 d->custom_optind++;
862                 if (d->first_nonopt != d->last_nonopt
863                                 && d->last_nonopt != d->custom_optind)
864                         exchange((char **) argv, d);
865                 else if (d->first_nonopt == d->last_nonopt)
866                         d->first_nonopt = d->custom_optind;
867                 d->last_nonopt = argc;
868                 d->custom_optind = argc;
869         }
870         /*
871          * If we have done all the ARGV-elements, stop the scan and back over
872          * any non-options that we skipped and permuted.
873          */
874         if (d->custom_optind == argc) {
875                 /*
876                  * Set the next-arg-index to point at the non-options that we
877                  * previously skipped, so the caller will digest them.
878                  */
879                 if (d->first_nonopt != d->last_nonopt)
880                         d->custom_optind = d->first_nonopt;
881                 return -1;
882         }
883         /*
884          * If we have come to a non-option and did not permute it, either stop
885          * the scan or describe it to the caller and pass it by.
886          */
887         if (NONOPTION_P) {
888                 d->custom_optarg = argv[d->custom_optind++];
889                 return 1;
890         }
891         /*
892          * We have found another option-ARGV-element. Skip the initial
893          * punctuation.
894          */
895         d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
896         return 0;
897 }
898
899 /*
900  * Check whether the ARGV-element is a long option.
901  *
902  * If there's a long option "fubar" and the ARGV-element is "-fu", consider
903  * that an abbreviation of the long option, just like "--fu", and not "-f" with
904  * arg "u".
905  *
906  * This distinction seems to be the most useful approach.
907  *
908  */
909 static int check_long_opt(int argc, char *const *argv, const char *optstring,
910                 const struct option *longopts, int *longind,
911                 int print_errors, struct custom_getopt_data *d)
912 {
913         char *nameend;
914         const struct option *p;
915         const struct option *pfound = NULL;
916         int exact = 0;
917         int ambig = 0;
918         int indfound = -1;
919         int option_index;
920
921         for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
922                 /* Do nothing.  */ ;
923
924         /* Test all long options for either exact match or abbreviated matches */
925         for (p = longopts, option_index = 0; p->name; p++, option_index++)
926                 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
927                         if ((unsigned int) (nameend - d->nextchar)
928                                         == (unsigned int) strlen(p->name)) {
929                                 /* Exact match found.  */
930                                 pfound = p;
931                                 indfound = option_index;
932                                 exact = 1;
933                                 break;
934                         } else if (pfound == NULL) {
935                                 /* First nonexact match found.  */
936                                 pfound = p;
937                                 indfound = option_index;
938                         } else if (pfound->has_arg != p->has_arg
939                                         || pfound->flag != p->flag
940                                         || pfound->val != p->val)
941                                 /* Second or later nonexact match found.  */
942                                 ambig = 1;
943                 }
944         if (ambig && !exact) {
945                 if (print_errors) {
946                         fprintf(stderr,
947                                 "%s: option `%s' is ambiguous\n",
948                                 argv[0], argv[d->custom_optind]);
949                 }
950                 d->nextchar += strlen(d->nextchar);
951                 d->custom_optind++;
952                 d->custom_optopt = 0;
953                 return '?';
954         }
955         if (pfound) {
956                 option_index = indfound;
957                 d->custom_optind++;
958                 if (*nameend) {
959                         if (pfound->has_arg != no_argument)
960                                 d->custom_optarg = nameend + 1;
961                         else {
962                                 if (print_errors) {
963                                         if (argv[d->custom_optind - 1][1] == '-') {
964                                                 /* --option */
965                                                 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
966                                                         argv[0], pfound->name);
967                                         } else {
968                                                 /* +option or -option */
969                                                 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
970                                                         argv[0], argv[d->custom_optind - 1][0], pfound->name);
971                                         }
972
973                                 }
974                                 d->nextchar += strlen(d->nextchar);
975                                 d->custom_optopt = pfound->val;
976                                 return '?';
977                         }
978                 } else if (pfound->has_arg == required_argument) {
979                         if (d->custom_optind < argc)
980                                 d->custom_optarg = argv[d->custom_optind++];
981                         else {
982                                 if (print_errors) {
983                                         fprintf(stderr,
984                                                 "%s: option `%s' requires an argument\n",
985                                                 argv[0],
986                                                 argv[d->custom_optind - 1]);
987                                 }
988                                 d->nextchar += strlen(d->nextchar);
989                                 d->custom_optopt = pfound->val;
990                                 return optstring[0] == ':' ? ':' : '?';
991                         }
992                 }
993                 d->nextchar += strlen(d->nextchar);
994                 if (longind != NULL)
995                         *longind = option_index;
996                 if (pfound->flag) {
997                         *(pfound->flag) = pfound->val;
998                         return 0;
999                 }
1000                 return pfound->val;
1001         }
1002         /*
1003          * Can't find it as a long option.  If this is not getopt_long_only, or
1004          * the option starts with '--' or is not a valid short option, then
1005          * it's an error.  Otherwise interpret it as a short option.
1006          */
1007         if (print_errors) {
1008                 if (argv[d->custom_optind][1] == '-') {
1009                         /* --option */
1010                         fprintf(stderr,
1011                                 "%s: unrecognized option `--%s'\n",
1012                                 argv[0], d->nextchar);
1013                 } else {
1014                         /* +option or -option */
1015                         fprintf(stderr,
1016                                 "%s: unrecognized option `%c%s'\n",
1017                                 argv[0], argv[d->custom_optind][0],
1018                                 d->nextchar);
1019                 }
1020         }
1021         d->nextchar = (char *) "";
1022         d->custom_optind++;
1023         d->custom_optopt = 0;
1024         return '?';
1025 }
1026
1027 static int check_short_opt(int argc, char *const *argv, const char *optstring,
1028                 int print_errors, struct custom_getopt_data *d)
1029 {
1030         char c = *d->nextchar++;
1031         const char *temp = strchr(optstring, c);
1032
1033         /* Increment `custom_optind' when we start to process its last character.  */
1034         if (*d->nextchar == '\0')
1035                 ++d->custom_optind;
1036         if (!temp || c == ':') {
1037                 if (print_errors)
1038                         fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
1039
1040                 d->custom_optopt = c;
1041                 return '?';
1042         }
1043         if (temp[1] == ':') {
1044                 if (temp[2] == ':') {
1045                         /* This is an option that accepts an argument optionally.  */
1046                         if (*d->nextchar != '\0') {
1047                                 d->custom_optarg = d->nextchar;
1048                                 d->custom_optind++;
1049                         } else
1050                                 d->custom_optarg = NULL;
1051                         d->nextchar = NULL;
1052                 } else {
1053                         /* This is an option that requires an argument.  */
1054                         if (*d->nextchar != '\0') {
1055                                 d->custom_optarg = d->nextchar;
1056                                 /*
1057                                  * If we end this ARGV-element by taking the
1058                                  * rest as an arg, we must advance to the next
1059                                  * element now.
1060                                  */
1061                                 d->custom_optind++;
1062                         } else if (d->custom_optind == argc) {
1063                                 if (print_errors) {
1064                                         fprintf(stderr,
1065                                                 "%s: option requires an argument -- %c\n",
1066                                                 argv[0], c);
1067                                 }
1068                                 d->custom_optopt = c;
1069                                 if (optstring[0] == ':')
1070                                         c = ':';
1071                                 else
1072                                         c = '?';
1073                         } else
1074                                 /*
1075                                  * We already incremented `custom_optind' once;
1076                                  * increment it again when taking next ARGV-elt
1077                                  * as argument.
1078                                  */
1079                                 d->custom_optarg = argv[d->custom_optind++];
1080                         d->nextchar = NULL;
1081                 }
1082         }
1083         return c;
1084 }
1085
1086 /*
1087  * Scan elements of ARGV for option characters given in OPTSTRING.
1088  *
1089  * If an element of ARGV starts with '-', and is not exactly "-" or "--",
1090  * then it is an option element.  The characters of this element
1091  * (aside from the initial '-') are option characters.  If `getopt'
1092  * is called repeatedly, it returns successively each of the option characters
1093  * from each of the option elements.
1094  *
1095  * If `getopt' finds another option character, it returns that character,
1096  * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
1097  * resume the scan with the following option character or ARGV-element.
1098  *
1099  * If there are no more option characters, `getopt' returns -1.
1100  * Then `custom_optind' is the index in ARGV of the first ARGV-element
1101  * that is not an option.  (The ARGV-elements have been permuted
1102  * so that those that are not options now come last.)
1103  *
1104  * OPTSTRING is a string containing the legitimate option characters.
1105  * If an option character is seen that is not listed in OPTSTRING,
1106  * return '?' after printing an error message.  If you set `custom_opterr' to
1107  * zero, the error message is suppressed but we still return '?'.
1108  *
1109  * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
1110  * so the following text in the same ARGV-element, or the text of the following
1111  * ARGV-element, is returned in `custom_optarg'.  Two colons mean an option that
1112  * wants an optional arg; if there is text in the current ARGV-element,
1113  * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
1114  *
1115  * If OPTSTRING starts with `-' or `+', it requests different methods of
1116  * handling the non-option ARGV-elements.
1117  * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
1118  *
1119  * Long-named options begin with `--' instead of `-'.
1120  * Their names may be abbreviated as long as the abbreviation is unique
1121  * or is an exact match for some defined option.  If they have an
1122  * argument, it follows the option name in the same ARGV-element, separated
1123  * from the option name by a `=', or else the in next ARGV-element.
1124  * When `getopt' finds a long-named option, it returns 0 if that option's
1125  * `flag' field is nonzero, the value of the option's `val' field
1126  * if the `flag' field is zero.
1127  *
1128  * The elements of ARGV aren't really const, because we permute them.
1129  * But we pretend they're const in the prototype to be compatible
1130  * with other systems.
1131  *
1132  * LONGOPTS is a vector of `struct option' terminated by an
1133  * element containing a name which is zero.
1134  *
1135  * LONGIND returns the index in LONGOPT of the long-named option found.
1136  * It is only valid when a long-named option has been found by the most
1137  * recent call.
1138  *
1139  * Return the option character from OPTS just read.  Return -1 when there are
1140  * no more options.  For unrecognized options, or options missing arguments,
1141  * `custom_optopt' is set to the option letter, and '?' is returned.
1142  *
1143  * The OPTS string is a list of characters which are recognized option letters,
1144  * optionally followed by colons, specifying that that letter takes an
1145  * argument, to be placed in `custom_optarg'.
1146  *
1147  * If a letter in OPTS is followed by two colons, its argument is optional.
1148  * This behavior is specific to the GNU `getopt'.
1149  *
1150  * The argument `--' causes premature termination of argument scanning,
1151  * explicitly telling `getopt' that there are no more options.  If OPTS begins
1152  * with `--', then non-option arguments are treated as arguments to the option
1153  * '\0'.  This behavior is specific to the GNU `getopt'.
1154  */
1155
1156 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1157                 const struct option *longopts, int *longind,
1158                 struct custom_getopt_data *d)
1159 {
1160         int ret, print_errors = d->custom_opterr;
1161
1162         if (optstring[0] == ':')
1163                 print_errors = 0;
1164         if (argc < 1)
1165                 return -1;
1166         d->custom_optarg = NULL;
1167
1168         /* 
1169          * This is a big difference with GNU getopt, since optind == 0
1170          * means initialization while here 1 means first call.
1171          */
1172         if (d->custom_optind == 0 || !d->initialized) {
1173                 if (d->custom_optind == 0)
1174                         d->custom_optind = 1;   /* Don't scan ARGV[0], the program name.  */
1175                 custom_getopt_initialize(d);
1176         }
1177         if (d->nextchar == NULL || *d->nextchar == '\0') {
1178                 ret = shuffle_argv(argc, argv, longopts, d);
1179                 if (ret)
1180                         return ret;
1181         }
1182         if (longopts && (argv[d->custom_optind][1] == '-' ))
1183                 return check_long_opt(argc, argv, optstring, longopts,
1184                         longind, print_errors, d);
1185         return check_short_opt(argc, argv, optstring, print_errors, d);
1186 }
1187
1188 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1189         const struct option *longopts, int *longind)
1190 {
1191         int result;
1192         /* Keep a global copy of all internal members of d */
1193         static struct custom_getopt_data d;
1194
1195         d.custom_optind = custom_optind;
1196         d.custom_opterr = custom_opterr;
1197         result = getopt_internal_r(argc, argv, optstring, longopts,
1198                 longind, &d);
1199         custom_optind = d.custom_optind;
1200         custom_optarg = d.custom_optarg;
1201         custom_optopt = d.custom_optopt;
1202         return result;
1203 }
1204
1205 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1206         const struct option *long_options, int *opt_index)
1207 {
1208         return custom_getopt_internal(argc, argv, options, long_options,
1209                 opt_index);
1210 }
1211
1212
1213 static char *package_name = 0;
1214
1215 /**
1216  * @brief updates an option
1217  * @param field the generic pointer to the field to update
1218  * @param orig_field the pointer to the orig field
1219  * @param field_given the pointer to the number of occurrence of this option
1220  * @param prev_given the pointer to the number of occurrence already seen
1221  * @param value the argument for this option (if null no arg was specified)
1222  * @param possible_values the possible values for this option (if specified)
1223  * @param default_value the default value (in case the option only accepts fixed values)
1224  * @param arg_type the type of this option
1225  * @param check_ambiguity @see RNAsnoop_cmdline_parser_params.check_ambiguity
1226  * @param override @see RNAsnoop_cmdline_parser_params.override
1227  * @param no_free whether to free a possible previous value
1228  * @param multiple_option whether this is a multiple option
1229  * @param long_opt the corresponding long option
1230  * @param short_opt the corresponding short option (or '-' if none)
1231  * @param additional_error possible further error specification
1232  */
1233 static
1234 int update_arg(void *field, char **orig_field,
1235                unsigned int *field_given, unsigned int *prev_given, 
1236                char *value, const char *possible_values[],
1237                const char *default_value,
1238                RNAsnoop_cmdline_parser_arg_type arg_type,
1239                int check_ambiguity, int override,
1240                int no_free, int multiple_option,
1241                const char *long_opt, char short_opt,
1242                const char *additional_error)
1243 {
1244   char *stop_char = 0;
1245   const char *val = value;
1246   int found;
1247   char **string_field;
1248   FIX_UNUSED (field);
1249
1250   stop_char = 0;
1251   found = 0;
1252
1253   if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1254     {
1255       if (short_opt != '-')
1256         fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", 
1257                package_name, long_opt, short_opt,
1258                (additional_error ? additional_error : ""));
1259       else
1260         fprintf (stderr, "%s: `--%s' option given more than once%s\n", 
1261                package_name, long_opt,
1262                (additional_error ? additional_error : ""));
1263       return 1; /* failure */
1264     }
1265
1266   FIX_UNUSED (default_value);
1267     
1268   if (field_given && *field_given && ! override)
1269     return 0;
1270   if (prev_given)
1271     (*prev_given)++;
1272   if (field_given)
1273     (*field_given)++;
1274   if (possible_values)
1275     val = possible_values[found];
1276
1277   switch(arg_type) {
1278   case ARG_FLAG:
1279     *((int *)field) = !*((int *)field);
1280     break;
1281   case ARG_INT:
1282     if (val) *((int *)field) = strtol (val, &stop_char, 0);
1283     break;
1284   case ARG_DOUBLE:
1285     if (val) *((double *)field) = strtod (val, &stop_char);
1286     break;
1287   case ARG_STRING:
1288     if (val) {
1289       string_field = (char **)field;
1290       if (!no_free && *string_field)
1291         free (*string_field); /* free previous string */
1292       *string_field = gengetopt_strdup (val);
1293     }
1294     break;
1295   default:
1296     break;
1297   };
1298
1299   /* check numeric conversion */
1300   switch(arg_type) {
1301   case ARG_INT:
1302   case ARG_DOUBLE:
1303     if (val && !(stop_char && *stop_char == '\0')) {
1304       fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1305       return 1; /* failure */
1306     }
1307     break;
1308   default:
1309     ;
1310   };
1311
1312   /* store the original value */
1313   switch(arg_type) {
1314   case ARG_NO:
1315   case ARG_FLAG:
1316     break;
1317   default:
1318     if (value && orig_field) {
1319       if (no_free) {
1320         *orig_field = value;
1321       } else {
1322         if (*orig_field)
1323           free (*orig_field); /* free previous string */
1324         *orig_field = gengetopt_strdup (value);
1325       }
1326     }
1327   };
1328
1329   return 0; /* OK */
1330 }
1331
1332
1333 int
1334 RNAsnoop_cmdline_parser_internal (
1335   int argc, char **argv, struct RNAsnoop_args_info *args_info,
1336                         struct RNAsnoop_cmdline_parser_params *params, const char *additional_error)
1337 {
1338   int c;        /* Character of the parsed option.  */
1339
1340   int error = 0;
1341   struct RNAsnoop_args_info local_args_info;
1342   
1343   int override;
1344   int initialize;
1345   int check_required;
1346   int check_ambiguity;
1347
1348   char *optarg;
1349   int optind;
1350   int opterr;
1351   int optopt;
1352   
1353   package_name = argv[0];
1354   
1355   override = params->override;
1356   initialize = params->initialize;
1357   check_required = params->check_required;
1358   check_ambiguity = params->check_ambiguity;
1359
1360   if (initialize)
1361     RNAsnoop_cmdline_parser_init (args_info);
1362
1363   RNAsnoop_cmdline_parser_init (&local_args_info);
1364
1365   optarg = 0;
1366   optind = 0;
1367   opterr = params->print_errors;
1368   optopt = '?';
1369
1370   while (1)
1371     {
1372       int option_index = 0;
1373
1374       static struct option long_options[] = {
1375         { "help",       0, NULL, 0 },
1376         { "detailed-help",      0, NULL, 0 },
1377         { "version",    0, NULL, 'V' },
1378         { "alignmentLength",    1, NULL, 'L' },
1379         { "constraint", 0, NULL, 'C' },
1380         { "query",      1, NULL, 's' },
1381         { "target",     1, NULL, 't' },
1382         { "suffix",     1, NULL, 'S' },
1383         { "from-RNAplfold",     1, NULL, 'P' },
1384         { "alignment-mode",     0, NULL, 'A' },
1385         { "fast-folding",       1, NULL, 'f' },
1386         { "extension-cost",     1, NULL, 'c' },
1387         { "minimal-right-duplex",       1, NULL, 'o' },
1388         { "minimal-loop-energy",        1, NULL, 'l' },
1389         { "minimal-left-duplex",        1, NULL, 'p' },
1390         { "minimal-duplex",     1, NULL, 'q' },
1391         { "duplex-distance",    1, NULL, 'd' },
1392         { "minimal-stem-length",        1, NULL, 'h' },
1393         { "maximal-stem-length",        1, NULL, 'i' },
1394         { "minimal-duplex-box-length",  1, NULL, 'j' },
1395         { "maximal-duplex-box-length",  1, NULL, 'k' },
1396         { "minimal-snoRNA-stem-loop-length",    1, NULL, 'm' },
1397         { "maximal-snoRNA-stem-loop-length",    1, NULL, 'n' },
1398         { "minimal-snoRNA-duplex-length",       1, NULL, 'v' },
1399         { "maximal-snoRNA-duplex-length",       1, NULL, 'w' },
1400         { "minimal-duplex-stem-energy", 1, NULL, 'x' },
1401         { "minimal-total-energy",       1, NULL, 'y' },
1402         { "maximal-stem-asymmetry",     1, NULL, 'a' },
1403         { "minimal-lower-stem-energy",  1, NULL, 'b' },
1404         { "energy-threshold",   1, NULL, 'e' },
1405         { "produce-ps", 0, NULL, 'I' },
1406         { "output_directory",   1, NULL, 'O' },
1407         { "direct-redraw",      0, NULL, 'N' },
1408         { "from-RNAup", 1, NULL, 'U' },
1409         { 0,  0, 0, 0 }
1410       };
1411
1412       custom_optarg = optarg;
1413       custom_optind = optind;
1414       custom_opterr = opterr;
1415       custom_optopt = optopt;
1416
1417       c = custom_getopt_long (argc, argv, "VL:Cs:t:S:P:Af:c:o:l:p:q:d:h:i:j:k:m:n:v:w:x:y:a:b:e:IO:NU:", long_options, &option_index);
1418
1419       optarg = custom_optarg;
1420       optind = custom_optind;
1421       opterr = custom_opterr;
1422       optopt = custom_optopt;
1423
1424       if (c == -1) break;       /* Exit from `while (1)' loop.  */
1425
1426       switch (c)
1427         {
1428         case 'V':       /* Print version and exit.  */
1429           RNAsnoop_cmdline_parser_print_version ();
1430           RNAsnoop_cmdline_parser_free (&local_args_info);
1431           exit (EXIT_SUCCESS);
1432
1433         case 'L':       /* Limit the extent of the interactions to L nucleotides.  */
1434         
1435         
1436           if (update_arg( (void *)&(args_info->alignmentLength_arg), 
1437                &(args_info->alignmentLength_orig), &(args_info->alignmentLength_given),
1438               &(local_args_info.alignmentLength_given), optarg, 0, "25", ARG_INT,
1439               check_ambiguity, override, 0, 0,
1440               "alignmentLength", 'L',
1441               additional_error))
1442             goto failure;
1443         
1444           break;
1445         case 'C':       /* Calculate the stem structure subject to constraints.
1446 .  */
1447         
1448         
1449           if (update_arg((void *)&(args_info->constraint_flag), 0, &(args_info->constraint_given),
1450               &(local_args_info.constraint_given), optarg, 0, 0, ARG_FLAG,
1451               check_ambiguity, override, 1, 0, "constraint", 'C',
1452               additional_error))
1453             goto failure;
1454         
1455           break;
1456         case 's':       /* File containing the query sequence.
1457 .  */
1458         
1459         
1460           if (update_arg( (void *)&(args_info->query_arg), 
1461                &(args_info->query_orig), &(args_info->query_given),
1462               &(local_args_info.query_given), optarg, 0, 0, ARG_STRING,
1463               check_ambiguity, override, 0, 0,
1464               "query", 's',
1465               additional_error))
1466             goto failure;
1467         
1468           break;
1469         case 't':       /* File containing the target sequence.
1470 .  */
1471         
1472         
1473           if (update_arg( (void *)&(args_info->target_arg), 
1474                &(args_info->target_orig), &(args_info->target_given),
1475               &(local_args_info.target_given), optarg, 0, 0, ARG_STRING,
1476               check_ambiguity, override, 0, 0,
1477               "target", 't',
1478               additional_error))
1479             goto failure;
1480         
1481           break;
1482         case 'S':       /* Specificy the suffix that was added by RNAup to the accessibility files
1483         
1484 .  */
1485         
1486         
1487           if (update_arg( (void *)&(args_info->suffix_arg), 
1488                &(args_info->suffix_orig), &(args_info->suffix_given),
1489               &(local_args_info.suffix_given), optarg, 0, "_u1_to_30.out", ARG_STRING,
1490               check_ambiguity, override, 0, 0,
1491               "suffix", 'S',
1492               additional_error))
1493             goto failure;
1494         
1495           break;
1496         case 'P':       /* Specify the directory where accessibility profile generated by RNAplfold are found
1497         
1498 .  */
1499         
1500         
1501           if (update_arg( (void *)&(args_info->from_RNAplfold_arg), 
1502                &(args_info->from_RNAplfold_orig), &(args_info->from_RNAplfold_given),
1503               &(local_args_info.from_RNAplfold_given), optarg, 0, 0, ARG_STRING,
1504               check_ambiguity, override, 0, 0,
1505               "from-RNAplfold", 'P',
1506               additional_error))
1507             goto failure;
1508         
1509           break;
1510         case 'A':       /* Specify if RNAsnoop gets alignments or single sequences as input
1511         
1512 .  */
1513         
1514         
1515           if (update_arg((void *)&(args_info->alignment_mode_flag), 0, &(args_info->alignment_mode_given),
1516               &(local_args_info.alignment_mode_given), optarg, 0, 0, ARG_FLAG,
1517               check_ambiguity, override, 1, 0, "alignment-mode", 'A',
1518               additional_error))
1519             goto failure;
1520         
1521           break;
1522         case 'f':       /* Speedup of the target search.  */
1523         
1524         
1525           if (update_arg( (void *)&(args_info->fast_folding_arg), 
1526                &(args_info->fast_folding_orig), &(args_info->fast_folding_given),
1527               &(local_args_info.fast_folding_given), optarg, 0, "1", ARG_INT,
1528               check_ambiguity, override, 0, 0,
1529               "fast-folding", 'f',
1530               additional_error))
1531             goto failure;
1532         
1533           break;
1534         case 'c':       /* Cost to add to each nucleotide in a duplex.  */
1535         
1536         
1537           if (update_arg( (void *)&(args_info->extension_cost_arg), 
1538                &(args_info->extension_cost_orig), &(args_info->extension_cost_given),
1539               &(local_args_info.extension_cost_given), optarg, 0, "0", ARG_INT,
1540               check_ambiguity, override, 0, 0,
1541               "extension-cost", 'c',
1542               additional_error))
1543             goto failure;
1544         
1545           break;
1546         case 'o':       /* Minimal Right Duplex Energy
1547         
1548 .  */
1549         
1550         
1551           if (update_arg( (void *)&(args_info->minimal_right_duplex_arg), 
1552                &(args_info->minimal_right_duplex_orig), &(args_info->minimal_right_duplex_given),
1553               &(local_args_info.minimal_right_duplex_given), optarg, 0, "-270", ARG_INT,
1554               check_ambiguity, override, 0, 0,
1555               "minimal-right-duplex", 'o',
1556               additional_error))
1557             goto failure;
1558         
1559           break;
1560         case 'l':       /* Minimal Right Duplex Energy
1561 .  */
1562         
1563         
1564           if (update_arg( (void *)&(args_info->minimal_loop_energy_arg), 
1565                &(args_info->minimal_loop_energy_orig), &(args_info->minimal_loop_energy_given),
1566               &(local_args_info.minimal_loop_energy_given), optarg, 0, "-280", ARG_INT,
1567               check_ambiguity, override, 0, 0,
1568               "minimal-loop-energy", 'l',
1569               additional_error))
1570             goto failure;
1571         
1572           break;
1573         case 'p':       /* Minimal Left Duplex Energy
1574         
1575 .  */
1576         
1577         
1578           if (update_arg( (void *)&(args_info->minimal_left_duplex_arg), 
1579                &(args_info->minimal_left_duplex_orig), &(args_info->minimal_left_duplex_given),
1580               &(local_args_info.minimal_left_duplex_given), optarg, 0, "-170", ARG_INT,
1581               check_ambiguity, override, 0, 0,
1582               "minimal-left-duplex", 'p',
1583               additional_error))
1584             goto failure;
1585         
1586           break;
1587         case 'q':       /* Minimal Duplex Energy
1588         
1589 .  */
1590         
1591         
1592           if (update_arg( (void *)&(args_info->minimal_duplex_arg), 
1593                &(args_info->minimal_duplex_orig), &(args_info->minimal_duplex_given),
1594               &(local_args_info.minimal_duplex_given), optarg, 0, "-1090", ARG_INT,
1595               check_ambiguity, override, 0, 0,
1596               "minimal-duplex", 'q',
1597               additional_error))
1598             goto failure;
1599         
1600           break;
1601         case 'd':       /* Distance between target 3' ends of two consecutive duplexes
1602 .  */
1603         
1604         
1605           if (update_arg( (void *)&(args_info->duplex_distance_arg), 
1606                &(args_info->duplex_distance_orig), &(args_info->duplex_distance_given),
1607               &(local_args_info.duplex_distance_given), optarg, 0, "2", ARG_INT,
1608               check_ambiguity, override, 0, 0,
1609               "duplex-distance", 'd',
1610               additional_error))
1611             goto failure;
1612         
1613           break;
1614         case 'h':       /* Minimal snoRNA stem length
1615         
1616 .  */
1617         
1618         
1619           if (update_arg( (void *)&(args_info->minimal_stem_length_arg), 
1620                &(args_info->minimal_stem_length_orig), &(args_info->minimal_stem_length_given),
1621               &(local_args_info.minimal_stem_length_given), optarg, 0, "5", ARG_INT,
1622               check_ambiguity, override, 0, 0,
1623               "minimal-stem-length", 'h',
1624               additional_error))
1625             goto failure;
1626         
1627           break;
1628         case 'i':       /* Maximal snoRNA stem length
1629         
1630 .  */
1631         
1632         
1633           if (update_arg( (void *)&(args_info->maximal_stem_length_arg), 
1634                &(args_info->maximal_stem_length_orig), &(args_info->maximal_stem_length_given),
1635               &(local_args_info.maximal_stem_length_given), optarg, 0, "120", ARG_INT,
1636               check_ambiguity, override, 0, 0,
1637               "maximal-stem-length", 'i',
1638               additional_error))
1639             goto failure;
1640         
1641           break;
1642         case 'j':       /* Minimal distance between the duplex end and the H/ACA box
1643         
1644 .  */
1645         
1646         
1647           if (update_arg( (void *)&(args_info->minimal_duplex_box_length_arg), 
1648                &(args_info->minimal_duplex_box_length_orig), &(args_info->minimal_duplex_box_length_given),
1649               &(local_args_info.minimal_duplex_box_length_given), optarg, 0, "11", ARG_INT,
1650               check_ambiguity, override, 0, 0,
1651               "minimal-duplex-box-length", 'j',
1652               additional_error))
1653             goto failure;
1654         
1655           break;
1656         case 'k':       /* Maximal distance between the duplex end and the H/ACA box
1657         
1658 .  */
1659         
1660         
1661           if (update_arg( (void *)&(args_info->maximal_duplex_box_length_arg), 
1662                &(args_info->maximal_duplex_box_length_orig), &(args_info->maximal_duplex_box_length_given),
1663               &(local_args_info.maximal_duplex_box_length_given), optarg, 0, "16", ARG_INT,
1664               check_ambiguity, override, 0, 0,
1665               "maximal-duplex-box-length", 'k',
1666               additional_error))
1667             goto failure;
1668         
1669           break;
1670         case 'm':       /* Minimal number of nucleotides between the beginning of stem loop and
1671         beginning of the snoRNA sequence
1672         
1673 .  */
1674         
1675         
1676           if (update_arg( (void *)&(args_info->minimal_snoRNA_stem_loop_length_arg), 
1677                &(args_info->minimal_snoRNA_stem_loop_length_orig), &(args_info->minimal_snoRNA_stem_loop_length_given),
1678               &(local_args_info.minimal_snoRNA_stem_loop_length_given), optarg, 0, "1", ARG_INT,
1679               check_ambiguity, override, 0, 0,
1680               "minimal-snoRNA-stem-loop-length", 'm',
1681               additional_error))
1682             goto failure;
1683         
1684           break;
1685         case 'n':       /* Maximal number of nucleotides between the beginning of stem loop and
1686         beginning of the snoRNA sequence
1687         
1688 .  */
1689         
1690         
1691           if (update_arg( (void *)&(args_info->maximal_snoRNA_stem_loop_length_arg), 
1692                &(args_info->maximal_snoRNA_stem_loop_length_orig), &(args_info->maximal_snoRNA_stem_loop_length_given),
1693               &(local_args_info.maximal_snoRNA_stem_loop_length_given), optarg, 0, "100000", ARG_INT,
1694               check_ambiguity, override, 0, 0,
1695               "maximal-snoRNA-stem-loop-length", 'n',
1696               additional_error))
1697             goto failure;
1698         
1699           break;
1700         case 'v':       /* Minimal distance between duplex start and snoRNA
1701         
1702 .  */
1703         
1704         
1705           if (update_arg( (void *)&(args_info->minimal_snoRNA_duplex_length_arg), 
1706                &(args_info->minimal_snoRNA_duplex_length_orig), &(args_info->minimal_snoRNA_duplex_length_given),
1707               &(local_args_info.minimal_snoRNA_duplex_length_given), optarg, 0, "0", ARG_INT,
1708               check_ambiguity, override, 0, 0,
1709               "minimal-snoRNA-duplex-length", 'v',
1710               additional_error))
1711             goto failure;
1712         
1713           break;
1714         case 'w':       /* Maximal distance between duplex start and snoRNA
1715         
1716 .  */
1717         
1718         
1719           if (update_arg( (void *)&(args_info->maximal_snoRNA_duplex_length_arg), 
1720                &(args_info->maximal_snoRNA_duplex_length_orig), &(args_info->maximal_snoRNA_duplex_length_given),
1721               &(local_args_info.maximal_snoRNA_duplex_length_given), optarg, 0, "0", ARG_INT,
1722               check_ambiguity, override, 0, 0,
1723               "maximal-snoRNA-duplex-length", 'w',
1724               additional_error))
1725             goto failure;
1726         
1727           break;
1728         case 'x':       /* Minimal duplex stem energy
1729         
1730 .  */
1731         
1732         
1733           if (update_arg( (void *)&(args_info->minimal_duplex_stem_energy_arg), 
1734                &(args_info->minimal_duplex_stem_energy_orig), &(args_info->minimal_duplex_stem_energy_given),
1735               &(local_args_info.minimal_duplex_stem_energy_given), optarg, 0, "-1370", ARG_INT,
1736               check_ambiguity, override, 0, 0,
1737               "minimal-duplex-stem-energy", 'x',
1738               additional_error))
1739             goto failure;
1740         
1741           break;
1742         case 'y':       /* Minimal total energy
1743         
1744 .  */
1745         
1746         
1747           if (update_arg( (void *)&(args_info->minimal_total_energy_arg), 
1748                &(args_info->minimal_total_energy_orig), &(args_info->minimal_total_energy_given),
1749               &(local_args_info.minimal_total_energy_given), optarg, 0, "100000", ARG_INT,
1750               check_ambiguity, override, 0, 0,
1751               "minimal-total-energy", 'y',
1752               additional_error))
1753             goto failure;
1754         
1755           break;
1756         case 'a':       /* Maximal snoRNA stem asymmetry
1757         
1758 .  */
1759         
1760         
1761           if (update_arg( (void *)&(args_info->maximal_stem_asymmetry_arg), 
1762                &(args_info->maximal_stem_asymmetry_orig), &(args_info->maximal_stem_asymmetry_given),
1763               &(local_args_info.maximal_stem_asymmetry_given), optarg, 0, "30", ARG_INT,
1764               check_ambiguity, override, 0, 0,
1765               "maximal-stem-asymmetry", 'a',
1766               additional_error))
1767             goto failure;
1768         
1769           break;
1770         case 'b':       /* Minimal lower stem energy
1771         
1772 .  */
1773         
1774         
1775           if (update_arg( (void *)&(args_info->minimal_lower_stem_energy_arg), 
1776                &(args_info->minimal_lower_stem_energy_orig), &(args_info->minimal_lower_stem_energy_given),
1777               &(local_args_info.minimal_lower_stem_energy_given), optarg, 0, "100000", ARG_INT,
1778               check_ambiguity, override, 0, 0,
1779               "minimal-lower-stem-energy", 'b',
1780               additional_error))
1781             goto failure;
1782         
1783           break;
1784         case 'e':       /* Maximal energy difference between the mfe and the desired suboptimal
1785 .  */
1786         
1787         
1788           if (update_arg( (void *)&(args_info->energy_threshold_arg), 
1789                &(args_info->energy_threshold_orig), &(args_info->energy_threshold_given),
1790               &(local_args_info.energy_threshold_given), optarg, 0, "-1", ARG_DOUBLE,
1791               check_ambiguity, override, 0, 0,
1792               "energy-threshold", 'e',
1793               additional_error))
1794             goto failure;
1795         
1796           break;
1797         case 'I':       /* Draw annotated 2D structures for a list of dot-bracket structures
1798 .  */
1799         
1800         
1801           if (update_arg((void *)&(args_info->produce_ps_flag), 0, &(args_info->produce_ps_given),
1802               &(local_args_info.produce_ps_given), optarg, 0, 0, ARG_FLAG,
1803               check_ambiguity, override, 1, 0, "produce-ps", 'I',
1804               additional_error))
1805             goto failure;
1806         
1807           break;
1808         case 'O':       /* Set where the generated figures should be stored
1809         
1810 .  */
1811         
1812         
1813           if (update_arg( (void *)&(args_info->output_directory_arg), 
1814                &(args_info->output_directory_orig), &(args_info->output_directory_given),
1815               &(local_args_info.output_directory_given), optarg, 0, "./", ARG_STRING,
1816               check_ambiguity, override, 0, 0,
1817               "output_directory", 'O',
1818               additional_error))
1819             goto failure;
1820         
1821           break;
1822         case 'N':       /* Outputs 2D interactions concurrently with the interaction calculation for each suboptimal interaction. The -I option should be preferred.
1823         
1824 .  */
1825         
1826         
1827           if (update_arg((void *)&(args_info->direct_redraw_flag), 0, &(args_info->direct_redraw_given),
1828               &(local_args_info.direct_redraw_given), optarg, 0, 0, ARG_FLAG,
1829               check_ambiguity, override, 1, 0, "direct-redraw", 'N',
1830               additional_error))
1831             goto failure;
1832         
1833           break;
1834         case 'U':       /* Specify the directory where accessibility profiles generated by RNAup are found
1835         
1836 .  */
1837         
1838         
1839           if (update_arg( (void *)&(args_info->from_RNAup_arg), 
1840                &(args_info->from_RNAup_orig), &(args_info->from_RNAup_given),
1841               &(local_args_info.from_RNAup_given), optarg, 0, 0, ARG_STRING,
1842               check_ambiguity, override, 0, 0,
1843               "from-RNAup", 'U',
1844               additional_error))
1845             goto failure;
1846         
1847           break;
1848
1849         case 0: /* Long option with no short option */
1850           if (strcmp (long_options[option_index].name, "help") == 0) {
1851             RNAsnoop_cmdline_parser_print_help ();
1852             RNAsnoop_cmdline_parser_free (&local_args_info);
1853             exit (EXIT_SUCCESS);
1854           }
1855
1856           if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1857             RNAsnoop_cmdline_parser_print_detailed_help ();
1858             RNAsnoop_cmdline_parser_free (&local_args_info);
1859             exit (EXIT_SUCCESS);
1860           }
1861
1862         case '?':       /* Invalid option.  */
1863           /* `getopt_long' already printed an error message.  */
1864           goto failure;
1865
1866         default:        /* bug: option not considered.  */
1867           fprintf (stderr, "%s: option unknown: %c%s\n", RNASNOOP_CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1868           abort ();
1869         } /* switch */
1870     } /* while */
1871
1872
1873
1874
1875   RNAsnoop_cmdline_parser_release (&local_args_info);
1876
1877   if ( error )
1878     return (EXIT_FAILURE);
1879
1880   return 0;
1881
1882 failure:
1883   
1884   RNAsnoop_cmdline_parser_release (&local_args_info);
1885   return (EXIT_FAILURE);
1886 }