1 /*
2   File autogenerated by gengetopt version 2.23
3   generated with the following command:
4   gengetopt -i RNAlocmin.ggo --file-name=RNAlocmin_cmdline --include-getopt --default-optional --unamed-opts
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 "RNAlocmin_cmdline.h"
26 
27 const char *gengetopt_args_info_purpose = "Calculate local minima from structures via gradient walks. Example usage: \n    RNAsubopt -p 10000 < \"sequence.txt\" > \"suboptp.txt\"\n    RNAlocmin -s \"sequence.txt\" [OPTIONS] < \"suboptp.txt\"";
28 
29 const char *gengetopt_args_info_usage = "Usage: RNAlocmin [OPTION]... [FILE]...";
30 
31 const char *gengetopt_args_info_versiontext = "";
32 
33 const char *gengetopt_args_info_description = "";
34 
35 const char *gengetopt_args_info_detailed_help[] = {
36   "  -h, --help                 Print help and exit",
37   "      --detailed-help        Print help, including all details and hidden\n                               options, and exit",
38   "      --full-help            Print help, including hidden options, and exit",
39   "  -V, --version              Print version and exit",
40   "\nGeneral options:",
41   "  -s, --seq=STRING           Sequence file in FASTA format. If the sequence is\n                               the first line of the input file, this is not\n                               needed  (default=`seq.txt')",
42   "  -p, --previous=STRING      Previously found LM (output from RNAlocmin or\n                               barriers), if specified does not need --seq\n                               option",
43   "  -m, --move=STRING          Move set:\n                               I ==> insertion & deletion of base pairs\n                               S ==> I&D& switch of base pairs  (possible\n                               values=\"I\", \"S\" default=`I')",
44   "  -n, --min-num=INT          Maximal number of local minima returned\n                               (0 == unlimited)  (default=`100000')",
45   "      --find-num=INT         Maximal number of local minima found\n                               (default = unlimited - crawl through whole input\n                               file)",
46   "  -v, --verbose-lvl=INT      Level of verbosity (0 = nothing, 4 = full)\n                               WARNING: higher verbose levels increase the\n                               computation time  (default=`0')",
47   "      --depth=INT            Depth of findpath search (higher value increases\n                               running time linearly)  (default=`10')",
48   "      --minh=DOUBLE          Print only minima with energy barrier greater than\n                               this  (default=`0.0')",
49   "      --minh-lite            When flooding with --minh option, search for only\n                               saddle (do not search for a LM that is lower).\n                               Increases efficiency a tiny bit, but when turned\n                               on, the results may omit some non-shallow\n                               minima, especially with higher --minh value.\n                               (default=off)",
50   "  -w, --walk=STRING          Walking method used\n                               D ==> gradient descent\n                               F ==> use first found lower energy structure\n                               R ==> use random lower energy structure (does\n                               not work with --noLP and -m S options)\n                               (possible values=\"D\", \"F\", \"R\"\n                               default=`D')",
51   "      --noLP                 Work only with canonical RNA structures (w/o\n                               isolated base pairs, cannot be combined with\n                               ranodm walk (-w R option) and shift move set (-m\n                               S))  (default=off)",
52   "  -e, --useEOS               Use energy_of_structure_pt calculation instead of\n                               energy_of_move (slower, it should not affect\n                               results)  (default=off)",
53   "  -P, --paramFile=STRING     Read energy parameters from paramfile, instead of\n                               using the default parameter set",
54   "  -d, --dangles=INT          How to treat \"dangling end\" energies for bases\n                               adjacent to helices in free ends and multi-loops\n                                 (default=`2')",
55   "  \n  With -d1 only unpaired bases can participate in at most one dangling end,\n  this is the default for mfe folding but unsupported for the partition\n  function folding.\n\n  With -d2 this check is ignored, dangling energies will be added for the bases\n  adjacent to a helix on both sides in any case; this is the default for\n  partition function folding (-p).\n  The option -d0 ignores dangling ends altogether (mostly for debugging).\n  With -d3 mfe folding will allow coaxial stacking of adjacent helices in\n  multi-loops. At the moment the implementation will not allow coaxial stacking\n  of the two interior pairs in a loop of degree 3 and works only for mfe\n  folding.\n\n  Note that by default (as well as with -d1 and -d3) pf and mfe folding treat\n  dangling ends differently. Use -d2 in addition to -p to ensure that both\n  algorithms use the same energy model.\n\n",
56   "      --fix-barriers=STRING  Fix barrier file for interior loops (just\n                               recompute if all LM in barrier output are LM),\n                               if specified, does not need neither --previous\n                               nor --seq option",
57   "  -k, --pseudoknots          Allow for pseudoknots according to \"gfold\" model\n                               - H, K, L, and M types (genus one) of\n                               pseudoknots are allowed (increases computation\n                               time greatly), cannot be combined with shift\n                               move set (-m S)  (default=off)",
58   "      --just-read            Do not expect input from stdin, just do\n                               postprocessing.  (default=off)",
59   "  -N, --neighborhood         Use the Neighborhood routines to perform gradient\n                               descend. Cannot be combined with shift move set\n                               (-m S) and pseudoknots (-k). Test option.\n                               (default=off)",
60   "      --degeneracy-off       Do not deal with degeneracy, select the\n                               lexicographically first from the same energy\n                               neighbors.  (default=off)",
61   "      --just-output          Do not store the minima and optimize, just compute\n                               directly minima and output them. Output file can\n                               contain duplicates.  (default=off)",
62   "\nBarrier tree:",
63   "  -b, --bartree              Generate an approximate barrier tree.\n                               (default=off)",
64   "      --barr-name=STRING     Name of barrier tree output file, switches on -b\n                               flag.  (default=`treeRNAloc.ps')",
65   "\nKinetics (rates for treekin program):",
66   "      --barrier-file=STRING  File for saddle heights between LM (simulates the\n                               output format of barriers program)",
67   "  -r, --rates                Create rates for treekin  (default=off)",
68   "  -f, --rates-file=STRING    File where to write rates, switches on -r flag\n                               (default=`rates.out')",
69   "  -T, --temp=DOUBLE          Temperature in Celsius (only for rates)\n                               (default=`37.0')",
70   "\nFlooding parameters (flooding occurs only with -r, -b, or --minh option):",
71   "      --floodPortion=DOUBLE  Fraction of minima to flood (floods first minima\n                               with low number of inwalking sample structures)\n                               (0.0 -> no flood; 1.0 -> try to flood all)\n                               Usable only with -r or -b options.\n                               (default=`0.95')",
72   "      --floodMax=INT         Flood cap - how many structures to flood in one\n                               basin  (default=`1000')",
73   "\nMiscelaneous:",
74   "      --numIntervals=INT     Number of intervals for Jing's visualisation\n                               (default=`0')",
75   "      --eRange=FLOAT         Report only LM, which energy is in range <MFE (or\n                               lowest found LM), MFE+eRange> in kcal/mol.",
76   "      --allegiance=STRING    Filename where to output the allegiance of\n                               structures. Works properly only with RNAsubopt\n                               -e list.",
77     0
78 };
79 static void
init_full_help_array(void)80 init_full_help_array(void)
81 {
82   gengetopt_args_info_full_help[0] = gengetopt_args_info_detailed_help[0];
83   gengetopt_args_info_full_help[1] = gengetopt_args_info_detailed_help[1];
84   gengetopt_args_info_full_help[2] = gengetopt_args_info_detailed_help[2];
85   gengetopt_args_info_full_help[3] = gengetopt_args_info_detailed_help[3];
86   gengetopt_args_info_full_help[4] = gengetopt_args_info_detailed_help[4];
87   gengetopt_args_info_full_help[5] = gengetopt_args_info_detailed_help[5];
88   gengetopt_args_info_full_help[6] = gengetopt_args_info_detailed_help[6];
89   gengetopt_args_info_full_help[7] = gengetopt_args_info_detailed_help[7];
90   gengetopt_args_info_full_help[8] = gengetopt_args_info_detailed_help[8];
91   gengetopt_args_info_full_help[9] = gengetopt_args_info_detailed_help[9];
92   gengetopt_args_info_full_help[10] = gengetopt_args_info_detailed_help[10];
93   gengetopt_args_info_full_help[11] = gengetopt_args_info_detailed_help[11];
94   gengetopt_args_info_full_help[12] = gengetopt_args_info_detailed_help[12];
95   gengetopt_args_info_full_help[13] = gengetopt_args_info_detailed_help[13];
96   gengetopt_args_info_full_help[14] = gengetopt_args_info_detailed_help[14];
97   gengetopt_args_info_full_help[15] = gengetopt_args_info_detailed_help[15];
98   gengetopt_args_info_full_help[16] = gengetopt_args_info_detailed_help[16];
99   gengetopt_args_info_full_help[17] = gengetopt_args_info_detailed_help[17];
100   gengetopt_args_info_full_help[18] = gengetopt_args_info_detailed_help[18];
101   gengetopt_args_info_full_help[19] = gengetopt_args_info_detailed_help[20];
102   gengetopt_args_info_full_help[20] = gengetopt_args_info_detailed_help[21];
103   gengetopt_args_info_full_help[21] = gengetopt_args_info_detailed_help[22];
104   gengetopt_args_info_full_help[22] = gengetopt_args_info_detailed_help[23];
105   gengetopt_args_info_full_help[23] = gengetopt_args_info_detailed_help[24];
106   gengetopt_args_info_full_help[24] = gengetopt_args_info_detailed_help[25];
107   gengetopt_args_info_full_help[25] = gengetopt_args_info_detailed_help[26];
108   gengetopt_args_info_full_help[26] = gengetopt_args_info_detailed_help[27];
109   gengetopt_args_info_full_help[27] = gengetopt_args_info_detailed_help[28];
110   gengetopt_args_info_full_help[28] = gengetopt_args_info_detailed_help[29];
111   gengetopt_args_info_full_help[29] = gengetopt_args_info_detailed_help[30];
112   gengetopt_args_info_full_help[30] = gengetopt_args_info_detailed_help[31];
113   gengetopt_args_info_full_help[31] = gengetopt_args_info_detailed_help[32];
114   gengetopt_args_info_full_help[32] = gengetopt_args_info_detailed_help[33];
115   gengetopt_args_info_full_help[33] = gengetopt_args_info_detailed_help[34];
116   gengetopt_args_info_full_help[34] = gengetopt_args_info_detailed_help[35];
117   gengetopt_args_info_full_help[35] = gengetopt_args_info_detailed_help[36];
118   gengetopt_args_info_full_help[36] = gengetopt_args_info_detailed_help[37];
119   gengetopt_args_info_full_help[37] = gengetopt_args_info_detailed_help[38];
120   gengetopt_args_info_full_help[38] = gengetopt_args_info_detailed_help[39];
121   gengetopt_args_info_full_help[39] = gengetopt_args_info_detailed_help[40];
122   gengetopt_args_info_full_help[40] = 0;
123 
124 }
125 
126 const char *gengetopt_args_info_full_help[41];
127 
128 static void
init_help_array(void)129 init_help_array(void)
130 {
131   gengetopt_args_info_help[0] = gengetopt_args_info_detailed_help[0];
132   gengetopt_args_info_help[1] = gengetopt_args_info_detailed_help[1];
133   gengetopt_args_info_help[2] = gengetopt_args_info_detailed_help[2];
134   gengetopt_args_info_help[3] = gengetopt_args_info_detailed_help[3];
135   gengetopt_args_info_help[4] = gengetopt_args_info_detailed_help[4];
136   gengetopt_args_info_help[5] = gengetopt_args_info_detailed_help[5];
137   gengetopt_args_info_help[6] = gengetopt_args_info_detailed_help[6];
138   gengetopt_args_info_help[7] = gengetopt_args_info_detailed_help[7];
139   gengetopt_args_info_help[8] = gengetopt_args_info_detailed_help[8];
140   gengetopt_args_info_help[9] = gengetopt_args_info_detailed_help[9];
141   gengetopt_args_info_help[10] = gengetopt_args_info_detailed_help[10];
142   gengetopt_args_info_help[11] = gengetopt_args_info_detailed_help[11];
143   gengetopt_args_info_help[12] = gengetopt_args_info_detailed_help[12];
144   gengetopt_args_info_help[13] = gengetopt_args_info_detailed_help[14];
145   gengetopt_args_info_help[14] = gengetopt_args_info_detailed_help[15];
146   gengetopt_args_info_help[15] = gengetopt_args_info_detailed_help[17];
147   gengetopt_args_info_help[16] = gengetopt_args_info_detailed_help[18];
148   gengetopt_args_info_help[17] = gengetopt_args_info_detailed_help[21];
149   gengetopt_args_info_help[18] = gengetopt_args_info_detailed_help[22];
150   gengetopt_args_info_help[19] = gengetopt_args_info_detailed_help[23];
151   gengetopt_args_info_help[20] = gengetopt_args_info_detailed_help[24];
152   gengetopt_args_info_help[21] = gengetopt_args_info_detailed_help[25];
153   gengetopt_args_info_help[22] = gengetopt_args_info_detailed_help[26];
154   gengetopt_args_info_help[23] = gengetopt_args_info_detailed_help[27];
155   gengetopt_args_info_help[24] = gengetopt_args_info_detailed_help[28];
156   gengetopt_args_info_help[25] = gengetopt_args_info_detailed_help[29];
157   gengetopt_args_info_help[26] = gengetopt_args_info_detailed_help[30];
158   gengetopt_args_info_help[27] = gengetopt_args_info_detailed_help[31];
159   gengetopt_args_info_help[28] = gengetopt_args_info_detailed_help[32];
160   gengetopt_args_info_help[29] = gengetopt_args_info_detailed_help[33];
161   gengetopt_args_info_help[30] = gengetopt_args_info_detailed_help[34];
162   gengetopt_args_info_help[31] = gengetopt_args_info_detailed_help[35];
163   gengetopt_args_info_help[32] = gengetopt_args_info_detailed_help[36];
164   gengetopt_args_info_help[33] = gengetopt_args_info_detailed_help[37];
165   gengetopt_args_info_help[34] = gengetopt_args_info_detailed_help[39];
166   gengetopt_args_info_help[35] = 0;
167 
168 }
169 
170 const char *gengetopt_args_info_help[36];
171 
172 typedef enum {ARG_NO
173   , ARG_FLAG
174   , ARG_STRING
175   , ARG_INT
176   , ARG_FLOAT
177   , ARG_DOUBLE
178 } cmdline_parser_arg_type;
179 
180 static
181 void clear_given (struct gengetopt_args_info *args_info);
182 static
183 void clear_args (struct gengetopt_args_info *args_info);
184 
185 static int
186 cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
187                         struct cmdline_parser_params *params, const char *additional_error);
188 
189 
190 const char *cmdline_parser_move_values[] = {"I", "S", 0}; /*< Possible values for move. */
191 const char *cmdline_parser_walk_values[] = {"D", "F", "R", 0}; /*< Possible values for walk. */
192 
193 static char *
194 gengetopt_strdup (const char *s);
195 
196 static
clear_given(struct gengetopt_args_info * args_info)197 void clear_given (struct gengetopt_args_info *args_info)
198 {
199   args_info->help_given = 0 ;
200   args_info->detailed_help_given = 0 ;
201   args_info->full_help_given = 0 ;
202   args_info->version_given = 0 ;
203   args_info->seq_given = 0 ;
204   args_info->previous_given = 0 ;
205   args_info->move_given = 0 ;
206   args_info->min_num_given = 0 ;
207   args_info->find_num_given = 0 ;
208   args_info->verbose_lvl_given = 0 ;
209   args_info->depth_given = 0 ;
210   args_info->minh_given = 0 ;
211   args_info->minh_lite_given = 0 ;
212   args_info->walk_given = 0 ;
213   args_info->noLP_given = 0 ;
214   args_info->useEOS_given = 0 ;
215   args_info->paramFile_given = 0 ;
216   args_info->dangles_given = 0 ;
217   args_info->fix_barriers_given = 0 ;
218   args_info->pseudoknots_given = 0 ;
219   args_info->just_read_given = 0 ;
220   args_info->neighborhood_given = 0 ;
221   args_info->degeneracy_off_given = 0 ;
222   args_info->just_output_given = 0 ;
223   args_info->bartree_given = 0 ;
224   args_info->barr_name_given = 0 ;
225   args_info->barrier_file_given = 0 ;
226   args_info->rates_given = 0 ;
227   args_info->rates_file_given = 0 ;
228   args_info->temp_given = 0 ;
229   args_info->floodPortion_given = 0 ;
230   args_info->floodMax_given = 0 ;
231   args_info->numIntervals_given = 0 ;
232   args_info->eRange_given = 0 ;
233   args_info->allegiance_given = 0 ;
234 }
235 
236 static
clear_args(struct gengetopt_args_info * args_info)237 void clear_args (struct gengetopt_args_info *args_info)
238 {
239   FIX_UNUSED (args_info);
240   args_info->seq_arg = gengetopt_strdup ("seq.txt");
241   args_info->seq_orig = NULL;
242   args_info->previous_arg = NULL;
243   args_info->previous_orig = NULL;
244   args_info->move_arg = gengetopt_strdup ("I");
245   args_info->move_orig = NULL;
246   args_info->min_num_arg = 100000;
247   args_info->min_num_orig = NULL;
248   args_info->find_num_orig = NULL;
249   args_info->verbose_lvl_arg = 0;
250   args_info->verbose_lvl_orig = NULL;
251   args_info->depth_arg = 10;
252   args_info->depth_orig = NULL;
253   args_info->minh_arg = 0.0;
254   args_info->minh_orig = NULL;
255   args_info->minh_lite_flag = 0;
256   args_info->walk_arg = gengetopt_strdup ("D");
257   args_info->walk_orig = NULL;
258   args_info->noLP_flag = 0;
259   args_info->useEOS_flag = 0;
260   args_info->paramFile_arg = NULL;
261   args_info->paramFile_orig = NULL;
262   args_info->dangles_arg = 2;
263   args_info->dangles_orig = NULL;
264   args_info->fix_barriers_arg = NULL;
265   args_info->fix_barriers_orig = NULL;
266   args_info->pseudoknots_flag = 0;
267   args_info->just_read_flag = 0;
268   args_info->neighborhood_flag = 0;
269   args_info->degeneracy_off_flag = 0;
270   args_info->just_output_flag = 0;
271   args_info->bartree_flag = 0;
272   args_info->barr_name_arg = gengetopt_strdup ("treeRNAloc.ps");
273   args_info->barr_name_orig = NULL;
274   args_info->barrier_file_arg = NULL;
275   args_info->barrier_file_orig = NULL;
276   args_info->rates_flag = 0;
277   args_info->rates_file_arg = gengetopt_strdup ("rates.out");
278   args_info->rates_file_orig = NULL;
279   args_info->temp_arg = 37.0;
280   args_info->temp_orig = NULL;
281   args_info->floodPortion_arg = 0.95;
282   args_info->floodPortion_orig = NULL;
283   args_info->floodMax_arg = 1000;
284   args_info->floodMax_orig = NULL;
285   args_info->numIntervals_arg = 0;
286   args_info->numIntervals_orig = NULL;
287   args_info->eRange_orig = NULL;
288   args_info->allegiance_arg = NULL;
289   args_info->allegiance_orig = NULL;
290 
291 }
292 
293 static
init_args_info(struct gengetopt_args_info * args_info)294 void init_args_info(struct gengetopt_args_info *args_info)
295 {
296   init_full_help_array();
297   init_help_array();
298   args_info->help_help = gengetopt_args_info_detailed_help[0] ;
299   args_info->detailed_help_help = gengetopt_args_info_detailed_help[1] ;
300   args_info->full_help_help = gengetopt_args_info_detailed_help[2] ;
301   args_info->version_help = gengetopt_args_info_detailed_help[3] ;
302   args_info->seq_help = gengetopt_args_info_detailed_help[5] ;
303   args_info->previous_help = gengetopt_args_info_detailed_help[6] ;
304   args_info->move_help = gengetopt_args_info_detailed_help[7] ;
305   args_info->min_num_help = gengetopt_args_info_detailed_help[8] ;
306   args_info->find_num_help = gengetopt_args_info_detailed_help[9] ;
307   args_info->verbose_lvl_help = gengetopt_args_info_detailed_help[10] ;
308   args_info->depth_help = gengetopt_args_info_detailed_help[11] ;
309   args_info->minh_help = gengetopt_args_info_detailed_help[12] ;
310   args_info->minh_lite_help = gengetopt_args_info_detailed_help[13] ;
311   args_info->walk_help = gengetopt_args_info_detailed_help[14] ;
312   args_info->noLP_help = gengetopt_args_info_detailed_help[15] ;
313   args_info->useEOS_help = gengetopt_args_info_detailed_help[16] ;
314   args_info->paramFile_help = gengetopt_args_info_detailed_help[17] ;
315   args_info->dangles_help = gengetopt_args_info_detailed_help[18] ;
316   args_info->fix_barriers_help = gengetopt_args_info_detailed_help[20] ;
317   args_info->pseudoknots_help = gengetopt_args_info_detailed_help[21] ;
318   args_info->just_read_help = gengetopt_args_info_detailed_help[22] ;
319   args_info->neighborhood_help = gengetopt_args_info_detailed_help[23] ;
320   args_info->degeneracy_off_help = gengetopt_args_info_detailed_help[24] ;
321   args_info->just_output_help = gengetopt_args_info_detailed_help[25] ;
322   args_info->bartree_help = gengetopt_args_info_detailed_help[27] ;
323   args_info->barr_name_help = gengetopt_args_info_detailed_help[28] ;
324   args_info->barrier_file_help = gengetopt_args_info_detailed_help[30] ;
325   args_info->rates_help = gengetopt_args_info_detailed_help[31] ;
326   args_info->rates_file_help = gengetopt_args_info_detailed_help[32] ;
327   args_info->temp_help = gengetopt_args_info_detailed_help[33] ;
328   args_info->floodPortion_help = gengetopt_args_info_detailed_help[35] ;
329   args_info->floodMax_help = gengetopt_args_info_detailed_help[36] ;
330   args_info->numIntervals_help = gengetopt_args_info_detailed_help[38] ;
331   args_info->eRange_help = gengetopt_args_info_detailed_help[39] ;
332   args_info->allegiance_help = gengetopt_args_info_detailed_help[40] ;
333 
334 }
335 
336 void
cmdline_parser_print_version(void)337 cmdline_parser_print_version (void)
338 {
339   printf ("%s %s\n",
340      (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
341      CMDLINE_PARSER_VERSION);
342 
343   if (strlen(gengetopt_args_info_versiontext) > 0)
344     printf("\n%s\n", gengetopt_args_info_versiontext);
345 }
346 
print_help_common(void)347 static void print_help_common(void)
348 {
349 	size_t len_purpose = strlen(gengetopt_args_info_purpose);
350 	size_t len_usage = strlen(gengetopt_args_info_usage);
351 
352 	if (len_usage > 0) {
353 		printf("%s\n", gengetopt_args_info_usage);
354 	}
355 	if (len_purpose > 0) {
356 		printf("%s\n", gengetopt_args_info_purpose);
357 	}
358 
359 	if (len_usage || len_purpose) {
360 		printf("\n");
361 	}
362 
363 	if (strlen(gengetopt_args_info_description) > 0) {
364 		printf("%s\n\n", gengetopt_args_info_description);
365 	}
366 }
367 
368 void
cmdline_parser_print_help(void)369 cmdline_parser_print_help (void)
370 {
371   int i = 0;
372   print_help_common();
373   while (gengetopt_args_info_help[i])
374     printf("%s\n", gengetopt_args_info_help[i++]);
375 }
376 
377 void
cmdline_parser_print_full_help(void)378 cmdline_parser_print_full_help (void)
379 {
380   int i = 0;
381   print_help_common();
382   while (gengetopt_args_info_full_help[i])
383     printf("%s\n", gengetopt_args_info_full_help[i++]);
384 }
385 
386 void
cmdline_parser_print_detailed_help(void)387 cmdline_parser_print_detailed_help (void)
388 {
389   int i = 0;
390   print_help_common();
391   while (gengetopt_args_info_detailed_help[i])
392     printf("%s\n", gengetopt_args_info_detailed_help[i++]);
393 }
394 
395 void
cmdline_parser_init(struct gengetopt_args_info * args_info)396 cmdline_parser_init (struct gengetopt_args_info *args_info)
397 {
398   clear_given (args_info);
399   clear_args (args_info);
400   init_args_info (args_info);
401 
402   args_info->inputs = 0;
403   args_info->inputs_num = 0;
404 }
405 
406 void
cmdline_parser_params_init(struct cmdline_parser_params * params)407 cmdline_parser_params_init(struct cmdline_parser_params *params)
408 {
409   if (params)
410     {
411       params->override = 0;
412       params->initialize = 1;
413       params->check_required = 1;
414       params->check_ambiguity = 0;
415       params->print_errors = 1;
416     }
417 }
418 
419 struct cmdline_parser_params *
cmdline_parser_params_create(void)420 cmdline_parser_params_create(void)
421 {
422   struct cmdline_parser_params *params =
423     (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
424   cmdline_parser_params_init(params);
425   return params;
426 }
427 
428 static void
free_string_field(char ** s)429 free_string_field (char **s)
430 {
431   if (*s)
432     {
433       free (*s);
434       *s = 0;
435     }
436 }
437 
438 
439 static void
cmdline_parser_release(struct gengetopt_args_info * args_info)440 cmdline_parser_release (struct gengetopt_args_info *args_info)
441 {
442   unsigned int i;
443   free_string_field (&(args_info->seq_arg));
444   free_string_field (&(args_info->seq_orig));
445   free_string_field (&(args_info->previous_arg));
446   free_string_field (&(args_info->previous_orig));
447   free_string_field (&(args_info->move_arg));
448   free_string_field (&(args_info->move_orig));
449   free_string_field (&(args_info->min_num_orig));
450   free_string_field (&(args_info->find_num_orig));
451   free_string_field (&(args_info->verbose_lvl_orig));
452   free_string_field (&(args_info->depth_orig));
453   free_string_field (&(args_info->minh_orig));
454   free_string_field (&(args_info->walk_arg));
455   free_string_field (&(args_info->walk_orig));
456   free_string_field (&(args_info->paramFile_arg));
457   free_string_field (&(args_info->paramFile_orig));
458   free_string_field (&(args_info->dangles_orig));
459   free_string_field (&(args_info->fix_barriers_arg));
460   free_string_field (&(args_info->fix_barriers_orig));
461   free_string_field (&(args_info->barr_name_arg));
462   free_string_field (&(args_info->barr_name_orig));
463   free_string_field (&(args_info->barrier_file_arg));
464   free_string_field (&(args_info->barrier_file_orig));
465   free_string_field (&(args_info->rates_file_arg));
466   free_string_field (&(args_info->rates_file_orig));
467   free_string_field (&(args_info->temp_orig));
468   free_string_field (&(args_info->floodPortion_orig));
469   free_string_field (&(args_info->floodMax_orig));
470   free_string_field (&(args_info->numIntervals_orig));
471   free_string_field (&(args_info->eRange_orig));
472   free_string_field (&(args_info->allegiance_arg));
473   free_string_field (&(args_info->allegiance_orig));
474 
475 
476   for (i = 0; i < args_info->inputs_num; ++i)
477     free (args_info->inputs [i]);
478 
479   if (args_info->inputs_num)
480     free (args_info->inputs);
481 
482   clear_given (args_info);
483 }
484 
485 /**
486  * @param val the value to check
487  * @param values the possible values
488  * @return the index of the matched value:
489  * -1 if no value matched,
490  * -2 if more than one value has matched
491  */
492 static int
check_possible_values(const char * val,const char * values[])493 check_possible_values(const char *val, const char *values[])
494 {
495   int i, found, last;
496   size_t len;
497 
498   if (!val)   /* otherwise strlen() crashes below */
499     return -1; /* -1 means no argument for the option */
500 
501   found = last = 0;
502 
503   for (i = 0, len = strlen(val); values[i]; ++i)
504     {
505       if (strncmp(val, values[i], len) == 0)
506         {
507           ++found;
508           last = i;
509           if (strlen(values[i]) == len)
510             return i; /* exact macth no need to check more */
511         }
512     }
513 
514   if (found == 1) /* one match: OK */
515     return last;
516 
517   return (found ? -2 : -1); /* return many values or none matched */
518 }
519 
520 
521 static void
write_into_file(FILE * outfile,const char * opt,const char * arg,const char * values[])522 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
523 {
524   int found = -1;
525   if (arg) {
526     if (values) {
527       found = check_possible_values(arg, values);
528     }
529     if (found >= 0)
530       fprintf(outfile, "%s=\"%s\" # %s\n", opt, arg, values[found]);
531     else
532       fprintf(outfile, "%s=\"%s\"\n", opt, arg);
533   } else {
534     fprintf(outfile, "%s\n", opt);
535   }
536 }
537 
538 
539 int
cmdline_parser_dump(FILE * outfile,struct gengetopt_args_info * args_info)540 cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
541 {
542   int i = 0;
543 
544   if (!outfile)
545     {
546       fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
547       return EXIT_FAILURE;
548     }
549 
550   if (args_info->help_given)
551     write_into_file(outfile, "help", 0, 0 );
552   if (args_info->detailed_help_given)
553     write_into_file(outfile, "detailed-help", 0, 0 );
554   if (args_info->full_help_given)
555     write_into_file(outfile, "full-help", 0, 0 );
556   if (args_info->version_given)
557     write_into_file(outfile, "version", 0, 0 );
558   if (args_info->seq_given)
559     write_into_file(outfile, "seq", args_info->seq_orig, 0);
560   if (args_info->previous_given)
561     write_into_file(outfile, "previous", args_info->previous_orig, 0);
562   if (args_info->move_given)
563     write_into_file(outfile, "move", args_info->move_orig, cmdline_parser_move_values);
564   if (args_info->min_num_given)
565     write_into_file(outfile, "min-num", args_info->min_num_orig, 0);
566   if (args_info->find_num_given)
567     write_into_file(outfile, "find-num", args_info->find_num_orig, 0);
568   if (args_info->verbose_lvl_given)
569     write_into_file(outfile, "verbose-lvl", args_info->verbose_lvl_orig, 0);
570   if (args_info->depth_given)
571     write_into_file(outfile, "depth", args_info->depth_orig, 0);
572   if (args_info->minh_given)
573     write_into_file(outfile, "minh", args_info->minh_orig, 0);
574   if (args_info->minh_lite_given)
575     write_into_file(outfile, "minh-lite", 0, 0 );
576   if (args_info->walk_given)
577     write_into_file(outfile, "walk", args_info->walk_orig, cmdline_parser_walk_values);
578   if (args_info->noLP_given)
579     write_into_file(outfile, "noLP", 0, 0 );
580   if (args_info->useEOS_given)
581     write_into_file(outfile, "useEOS", 0, 0 );
582   if (args_info->paramFile_given)
583     write_into_file(outfile, "paramFile", args_info->paramFile_orig, 0);
584   if (args_info->dangles_given)
585     write_into_file(outfile, "dangles", args_info->dangles_orig, 0);
586   if (args_info->fix_barriers_given)
587     write_into_file(outfile, "fix-barriers", args_info->fix_barriers_orig, 0);
588   if (args_info->pseudoknots_given)
589     write_into_file(outfile, "pseudoknots", 0, 0 );
590   if (args_info->just_read_given)
591     write_into_file(outfile, "just-read", 0, 0 );
592   if (args_info->neighborhood_given)
593     write_into_file(outfile, "neighborhood", 0, 0 );
594   if (args_info->degeneracy_off_given)
595     write_into_file(outfile, "degeneracy-off", 0, 0 );
596   if (args_info->just_output_given)
597     write_into_file(outfile, "just-output", 0, 0 );
598   if (args_info->bartree_given)
599     write_into_file(outfile, "bartree", 0, 0 );
600   if (args_info->barr_name_given)
601     write_into_file(outfile, "barr-name", args_info->barr_name_orig, 0);
602   if (args_info->barrier_file_given)
603     write_into_file(outfile, "barrier-file", args_info->barrier_file_orig, 0);
604   if (args_info->rates_given)
605     write_into_file(outfile, "rates", 0, 0 );
606   if (args_info->rates_file_given)
607     write_into_file(outfile, "rates-file", args_info->rates_file_orig, 0);
608   if (args_info->temp_given)
609     write_into_file(outfile, "temp", args_info->temp_orig, 0);
610   if (args_info->floodPortion_given)
611     write_into_file(outfile, "floodPortion", args_info->floodPortion_orig, 0);
612   if (args_info->floodMax_given)
613     write_into_file(outfile, "floodMax", args_info->floodMax_orig, 0);
614   if (args_info->numIntervals_given)
615     write_into_file(outfile, "numIntervals", args_info->numIntervals_orig, 0);
616   if (args_info->eRange_given)
617     write_into_file(outfile, "eRange", args_info->eRange_orig, 0);
618   if (args_info->allegiance_given)
619     write_into_file(outfile, "allegiance", args_info->allegiance_orig, 0);
620 
621 
622   i = EXIT_SUCCESS;
623   return i;
624 }
625 
626 int
cmdline_parser_file_save(const char * filename,struct gengetopt_args_info * args_info)627 cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
628 {
629   FILE *outfile;
630   int i = 0;
631 
632   outfile = fopen(filename, "w");
633 
634   if (!outfile)
635     {
636       fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
637       return EXIT_FAILURE;
638     }
639 
640   i = cmdline_parser_dump(outfile, args_info);
641   fclose (outfile);
642 
643   return i;
644 }
645 
646 void
cmdline_parser_free(struct gengetopt_args_info * args_info)647 cmdline_parser_free (struct gengetopt_args_info *args_info)
648 {
649   cmdline_parser_release (args_info);
650 }
651 
652 /** @brief replacement of strdup, which is not standard */
653 char *
gengetopt_strdup(const char * s)654 gengetopt_strdup (const char *s)
655 {
656   char *result = 0;
657   if (!s)
658     return result;
659 
660   result = (char*)malloc(strlen(s) + 1);
661   if (result == (char*)0)
662     return (char*)0;
663   strcpy(result, s);
664   return result;
665 }
666 
667 int
cmdline_parser(int argc,char ** argv,struct gengetopt_args_info * args_info)668 cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
669 {
670   return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
671 }
672 
673 int
cmdline_parser_ext(int argc,char ** argv,struct gengetopt_args_info * args_info,struct cmdline_parser_params * params)674 cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
675                    struct cmdline_parser_params *params)
676 {
677   int result;
678   result = cmdline_parser_internal (argc, argv, args_info, params, 0);
679 
680   if (result == EXIT_FAILURE)
681     {
682       cmdline_parser_free (args_info);
683       exit (EXIT_FAILURE);
684     }
685 
686   return result;
687 }
688 
689 int
cmdline_parser2(int argc,char ** argv,struct gengetopt_args_info * args_info,int override,int initialize,int check_required)690 cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
691 {
692   int result;
693   struct cmdline_parser_params params;
694 
695   params.override = override;
696   params.initialize = initialize;
697   params.check_required = check_required;
698   params.check_ambiguity = 0;
699   params.print_errors = 1;
700 
701   result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
702 
703   if (result == EXIT_FAILURE)
704     {
705       cmdline_parser_free (args_info);
706       exit (EXIT_FAILURE);
707     }
708 
709   return result;
710 }
711 
712 int
cmdline_parser_required(struct gengetopt_args_info * args_info,const char * prog_name)713 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
714 {
715   FIX_UNUSED (args_info);
716   FIX_UNUSED (prog_name);
717   return EXIT_SUCCESS;
718 }
719 
720 /*
721  * Extracted from the glibc source tree, version 2.3.6
722  *
723  * Licensed under the GPL as per the whole glibc source tree.
724  *
725  * This file was modified so that getopt_long can be called
726  * many times without risking previous memory to be spoiled.
727  *
728  * Modified by Andre Noll and Lorenzo Bettini for use in
729  * GNU gengetopt generated files.
730  *
731  */
732 
733 /*
734  * we must include anything we need since this file is not thought to be
735  * inserted in a file already using getopt.h
736  *
737  * Lorenzo
738  */
739 
740 struct option
741 {
742   const char *name;
743   /* has_arg can't be an enum because some compilers complain about
744      type mismatches in all the code that assumes it is an int.  */
745   int has_arg;
746   int *flag;
747   int val;
748 };
749 
750 /* This version of `getopt' appears to the caller like standard Unix `getopt'
751    but it behaves differently for the user, since it allows the user
752    to intersperse the options with the other arguments.
753 
754    As `getopt' works, it permutes the elements of ARGV so that,
755    when it is done, all the options precede everything else.  Thus
756    all application programs are extended to handle flexible argument order.
757 */
758 /*
759    If the field `flag' is not NULL, it points to a variable that is set
760    to the value given in the field `val' when the option is found, but
761    left unchanged if the option is not found.
762 
763    To have a long-named option do something other than set an `int' to
764    a compiled-in constant, such as set a value from `custom_optarg', set the
765    option's `flag' field to zero and its `val' field to a nonzero
766    value (the equivalent single-letter option character, if there is
767    one).  For long options that have a zero `flag' field, `getopt'
768    returns the contents of the `val' field.  */
769 
770 /* Names for the values of the `has_arg' field of `struct option'.  */
771 #ifndef no_argument
772 #define no_argument		0
773 #endif
774 
775 #ifndef required_argument
776 #define required_argument	1
777 #endif
778 
779 #ifndef optional_argument
780 #define optional_argument	2
781 #endif
782 
783 struct custom_getopt_data {
784 	/*
785 	 * These have exactly the same meaning as the corresponding global variables,
786 	 * except that they are used for the reentrant versions of getopt.
787 	 */
788 	int custom_optind;
789 	int custom_opterr;
790 	int custom_optopt;
791 	char *custom_optarg;
792 
793 	/* True if the internal members have been initialized.  */
794 	int initialized;
795 
796 	/*
797 	 * The next char to be scanned in the option-element in which the last option
798 	 * character we returned was found.  This allows us to pick up the scan where
799 	 * we left off.  If this is zero, or a null string, it means resume the scan by
800 	 * advancing to the next ARGV-element.
801 	 */
802 	char *nextchar;
803 
804 	/*
805 	 * Describe the part of ARGV that contains non-options that have been skipped.
806 	 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
807 	 * the index after the last of them.
808 	 */
809 	int first_nonopt;
810 	int last_nonopt;
811 };
812 
813 /*
814  * the variables optarg, optind, opterr and optopt are renamed with
815  * the custom_ prefix so that they don't interfere with getopt ones.
816  *
817  * Moreover they're static so they are visible only from within the
818  * file where this very file will be included.
819  */
820 
821 /*
822  * For communication from `custom_getopt' to the caller.  When `custom_getopt' finds an
823  * option that takes an argument, the argument value is returned here.
824  */
825 static char *custom_optarg;
826 
827 /*
828  * Index in ARGV of the next element to be scanned.  This is used for
829  * communication to and from the caller and for communication between
830  * successive calls to `custom_getopt'.
831  *
832  * On entry to `custom_getopt', 1 means this is the first call; initialize.
833  *
834  * When `custom_getopt' returns -1, this is the index of the first of the non-option
835  * elements that the caller should itself scan.
836  *
837  * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
838  * has been scanned so far.
839  *
840  * 1003.2 says this must be 1 before any call.
841  */
842 static int custom_optind = 1;
843 
844 /*
845  * Callers store zero here to inhibit the error message for unrecognized
846  * options.
847  */
848 static int custom_opterr = 1;
849 
850 /*
851  * Set to an option character which was unrecognized.  This must be initialized
852  * on some systems to avoid linking in the system's own getopt implementation.
853  */
854 static int custom_optopt = '?';
855 
856 /*
857  * Exchange two adjacent subsequences of ARGV.  One subsequence is elements
858  * [first_nonopt,last_nonopt) which contains all the non-options that have been
859  * skipped so far.  The other is elements [last_nonopt,custom_optind), which contains
860  * all the options processed since those non-options were skipped.
861  * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
862  * indices of the non-options in ARGV after they are moved.
863  */
exchange(char ** argv,struct custom_getopt_data * d)864 static void exchange(char **argv, struct custom_getopt_data *d)
865 {
866 	int bottom = d->first_nonopt;
867 	int middle = d->last_nonopt;
868 	int top = d->custom_optind;
869 	char *tem;
870 
871 	/*
872 	 * Exchange the shorter segment with the far end of the longer segment.
873 	 * That puts the shorter segment into the right place.  It leaves the
874 	 * longer segment in the right place overall, but it consists of two
875 	 * parts that need to be swapped next.
876 	 */
877 	while (top > middle && middle > bottom) {
878 		if (top - middle > middle - bottom) {
879 			/* Bottom segment is the short one.  */
880 			int len = middle - bottom;
881 			int i;
882 
883 			/* Swap it with the top part of the top segment.  */
884 			for (i = 0; i < len; i++) {
885 				tem = argv[bottom + i];
886 				argv[bottom + i] =
887 					argv[top - (middle - bottom) + i];
888 				argv[top - (middle - bottom) + i] = tem;
889 			}
890 			/* Exclude the moved bottom segment from further swapping.  */
891 			top -= len;
892 		} else {
893 			/* Top segment is the short one.  */
894 			int len = top - middle;
895 			int i;
896 
897 			/* Swap it with the bottom part of the bottom segment.  */
898 			for (i = 0; i < len; i++) {
899 				tem = argv[bottom + i];
900 				argv[bottom + i] = argv[middle + i];
901 				argv[middle + i] = tem;
902 			}
903 			/* Exclude the moved top segment from further swapping.  */
904 			bottom += len;
905 		}
906 	}
907 	/* Update records for the slots the non-options now occupy.  */
908 	d->first_nonopt += (d->custom_optind - d->last_nonopt);
909 	d->last_nonopt = d->custom_optind;
910 }
911 
912 /* Initialize the internal data when the first call is made.  */
custom_getopt_initialize(struct custom_getopt_data * d)913 static void custom_getopt_initialize(struct custom_getopt_data *d)
914 {
915 	/*
916 	 * Start processing options with ARGV-element 1 (since ARGV-element 0
917 	 * is the program name); the sequence of previously skipped non-option
918 	 * ARGV-elements is empty.
919 	 */
920 	d->first_nonopt = d->last_nonopt = d->custom_optind;
921 	d->nextchar = NULL;
922 	d->initialized = 1;
923 }
924 
925 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
926 
927 /* return: zero: continue, nonzero: return given value to user */
shuffle_argv(int argc,char * const * argv,const struct option * longopts,struct custom_getopt_data * d)928 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
929 	struct custom_getopt_data *d)
930 {
931 	/*
932 	 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
933 	 * moved back by the user (who may also have changed the arguments).
934 	 */
935 	if (d->last_nonopt > d->custom_optind)
936 		d->last_nonopt = d->custom_optind;
937 	if (d->first_nonopt > d->custom_optind)
938 		d->first_nonopt = d->custom_optind;
939 	/*
940 	 * If we have just processed some options following some
941 	 * non-options, exchange them so that the options come first.
942 	 */
943 	if (d->first_nonopt != d->last_nonopt &&
944 			d->last_nonopt != d->custom_optind)
945 		exchange((char **) argv, d);
946 	else if (d->last_nonopt != d->custom_optind)
947 		d->first_nonopt = d->custom_optind;
948 	/*
949 	 * Skip any additional non-options and extend the range of
950 	 * non-options previously skipped.
951 	 */
952 	while (d->custom_optind < argc && NONOPTION_P)
953 		d->custom_optind++;
954 	d->last_nonopt = d->custom_optind;
955 	/*
956 	 * The special ARGV-element `--' means premature end of options.  Skip
957 	 * it like a null option, then exchange with previous non-options as if
958 	 * it were an option, then skip everything else like a non-option.
959 	 */
960 	if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
961 		d->custom_optind++;
962 		if (d->first_nonopt != d->last_nonopt
963 				&& d->last_nonopt != d->custom_optind)
964 			exchange((char **) argv, d);
965 		else if (d->first_nonopt == d->last_nonopt)
966 			d->first_nonopt = d->custom_optind;
967 		d->last_nonopt = argc;
968 		d->custom_optind = argc;
969 	}
970 	/*
971 	 * If we have done all the ARGV-elements, stop the scan and back over
972 	 * any non-options that we skipped and permuted.
973 	 */
974 	if (d->custom_optind == argc) {
975 		/*
976 		 * Set the next-arg-index to point at the non-options that we
977 		 * previously skipped, so the caller will digest them.
978 		 */
979 		if (d->first_nonopt != d->last_nonopt)
980 			d->custom_optind = d->first_nonopt;
981 		return -1;
982 	}
983 	/*
984 	 * If we have come to a non-option and did not permute it, either stop
985 	 * the scan or describe it to the caller and pass it by.
986 	 */
987 	if (NONOPTION_P) {
988 		d->custom_optarg = argv[d->custom_optind++];
989 		return 1;
990 	}
991 	/*
992 	 * We have found another option-ARGV-element. Skip the initial
993 	 * punctuation.
994 	 */
995 	d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
996 	return 0;
997 }
998 
999 /*
1000  * Check whether the ARGV-element is a long option.
1001  *
1002  * If there's a long option "fubar" and the ARGV-element is "-fu", consider
1003  * that an abbreviation of the long option, just like "--fu", and not "-f" with
1004  * arg "u".
1005  *
1006  * This distinction seems to be the most useful approach.
1007  *
1008  */
check_long_opt(int argc,char * const * argv,const char * optstring,const struct option * longopts,int * longind,int print_errors,struct custom_getopt_data * d)1009 static int check_long_opt(int argc, char *const *argv, const char *optstring,
1010 		const struct option *longopts, int *longind,
1011 		int print_errors, struct custom_getopt_data *d)
1012 {
1013 	char *nameend;
1014 	const struct option *p;
1015 	const struct option *pfound = NULL;
1016 	int exact = 0;
1017 	int ambig = 0;
1018 	int indfound = -1;
1019 	int option_index;
1020 
1021 	for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
1022 		/* Do nothing.  */ ;
1023 
1024 	/* Test all long options for either exact match or abbreviated matches */
1025 	for (p = longopts, option_index = 0; p->name; p++, option_index++)
1026 		if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
1027 			if ((unsigned int) (nameend - d->nextchar)
1028 					== (unsigned int) strlen(p->name)) {
1029 				/* Exact match found.  */
1030 				pfound = p;
1031 				indfound = option_index;
1032 				exact = 1;
1033 				break;
1034 			} else if (pfound == NULL) {
1035 				/* First nonexact match found.  */
1036 				pfound = p;
1037 				indfound = option_index;
1038 			} else if (pfound->has_arg != p->has_arg
1039 					|| pfound->flag != p->flag
1040 					|| pfound->val != p->val)
1041 				/* Second or later nonexact match found.  */
1042 				ambig = 1;
1043 		}
1044 	if (ambig && !exact) {
1045 		if (print_errors) {
1046 			fprintf(stderr,
1047 				"%s: option `%s' is ambiguous\n",
1048 				argv[0], argv[d->custom_optind]);
1049 		}
1050 		d->nextchar += strlen(d->nextchar);
1051 		d->custom_optind++;
1052 		d->custom_optopt = 0;
1053 		return '?';
1054 	}
1055 	if (pfound) {
1056 		option_index = indfound;
1057 		d->custom_optind++;
1058 		if (*nameend) {
1059 			if (pfound->has_arg != no_argument)
1060 				d->custom_optarg = nameend + 1;
1061 			else {
1062 				if (print_errors) {
1063 					if (argv[d->custom_optind - 1][1] == '-') {
1064 						/* --option */
1065 						fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
1066 							argv[0], pfound->name);
1067 					} else {
1068 						/* +option or -option */
1069 						fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
1070 							argv[0], argv[d->custom_optind - 1][0], pfound->name);
1071 					}
1072 
1073 				}
1074 				d->nextchar += strlen(d->nextchar);
1075 				d->custom_optopt = pfound->val;
1076 				return '?';
1077 			}
1078 		} else if (pfound->has_arg == required_argument) {
1079 			if (d->custom_optind < argc)
1080 				d->custom_optarg = argv[d->custom_optind++];
1081 			else {
1082 				if (print_errors) {
1083 					fprintf(stderr,
1084 						"%s: option `%s' requires an argument\n",
1085 						argv[0],
1086 						argv[d->custom_optind - 1]);
1087 				}
1088 				d->nextchar += strlen(d->nextchar);
1089 				d->custom_optopt = pfound->val;
1090 				return optstring[0] == ':' ? ':' : '?';
1091 			}
1092 		}
1093 		d->nextchar += strlen(d->nextchar);
1094 		if (longind != NULL)
1095 			*longind = option_index;
1096 		if (pfound->flag) {
1097 			*(pfound->flag) = pfound->val;
1098 			return 0;
1099 		}
1100 		return pfound->val;
1101 	}
1102 	/*
1103 	 * Can't find it as a long option.  If this is not getopt_long_only, or
1104 	 * the option starts with '--' or is not a valid short option, then
1105 	 * it's an error.  Otherwise interpret it as a short option.
1106 	 */
1107 	if (print_errors) {
1108 		if (argv[d->custom_optind][1] == '-') {
1109 			/* --option */
1110 			fprintf(stderr,
1111 				"%s: unrecognized option `--%s'\n",
1112 				argv[0], d->nextchar);
1113 		} else {
1114 			/* +option or -option */
1115 			fprintf(stderr,
1116 				"%s: unrecognized option `%c%s'\n",
1117 				argv[0], argv[d->custom_optind][0],
1118 				d->nextchar);
1119 		}
1120 	}
1121 	d->nextchar = (char *) "";
1122 	d->custom_optind++;
1123 	d->custom_optopt = 0;
1124 	return '?';
1125 }
1126 
check_short_opt(int argc,char * const * argv,const char * optstring,int print_errors,struct custom_getopt_data * d)1127 static int check_short_opt(int argc, char *const *argv, const char *optstring,
1128 		int print_errors, struct custom_getopt_data *d)
1129 {
1130 	char c = *d->nextchar++;
1131 	const char *temp = strchr(optstring, c);
1132 
1133 	/* Increment `custom_optind' when we start to process its last character.  */
1134 	if (*d->nextchar == '\0')
1135 		++d->custom_optind;
1136 	if (!temp || c == ':') {
1137 		if (print_errors)
1138 			fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
1139 
1140 		d->custom_optopt = c;
1141 		return '?';
1142 	}
1143 	if (temp[1] == ':') {
1144 		if (temp[2] == ':') {
1145 			/* This is an option that accepts an argument optionally.  */
1146 			if (*d->nextchar != '\0') {
1147 				d->custom_optarg = d->nextchar;
1148 				d->custom_optind++;
1149 			} else
1150 				d->custom_optarg = NULL;
1151 			d->nextchar = NULL;
1152 		} else {
1153 			/* This is an option that requires an argument.  */
1154 			if (*d->nextchar != '\0') {
1155 				d->custom_optarg = d->nextchar;
1156 				/*
1157 				 * If we end this ARGV-element by taking the
1158 				 * rest as an arg, we must advance to the next
1159 				 * element now.
1160 				 */
1161 				d->custom_optind++;
1162 			} else if (d->custom_optind == argc) {
1163 				if (print_errors) {
1164 					fprintf(stderr,
1165 						"%s: option requires an argument -- %c\n",
1166 						argv[0], c);
1167 				}
1168 				d->custom_optopt = c;
1169 				if (optstring[0] == ':')
1170 					c = ':';
1171 				else
1172 					c = '?';
1173 			} else
1174 				/*
1175 				 * We already incremented `custom_optind' once;
1176 				 * increment it again when taking next ARGV-elt
1177 				 * as argument.
1178 				 */
1179 				d->custom_optarg = argv[d->custom_optind++];
1180 			d->nextchar = NULL;
1181 		}
1182 	}
1183 	return c;
1184 }
1185 
1186 /*
1187  * Scan elements of ARGV for option characters given in OPTSTRING.
1188  *
1189  * If an element of ARGV starts with '-', and is not exactly "-" or "--",
1190  * then it is an option element.  The characters of this element
1191  * (aside from the initial '-') are option characters.  If `getopt'
1192  * is called repeatedly, it returns successively each of the option characters
1193  * from each of the option elements.
1194  *
1195  * If `getopt' finds another option character, it returns that character,
1196  * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
1197  * resume the scan with the following option character or ARGV-element.
1198  *
1199  * If there are no more option characters, `getopt' returns -1.
1200  * Then `custom_optind' is the index in ARGV of the first ARGV-element
1201  * that is not an option.  (The ARGV-elements have been permuted
1202  * so that those that are not options now come last.)
1203  *
1204  * OPTSTRING is a string containing the legitimate option characters.
1205  * If an option character is seen that is not listed in OPTSTRING,
1206  * return '?' after printing an error message.  If you set `custom_opterr' to
1207  * zero, the error message is suppressed but we still return '?'.
1208  *
1209  * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
1210  * so the following text in the same ARGV-element, or the text of the following
1211  * ARGV-element, is returned in `custom_optarg'.  Two colons mean an option that
1212  * wants an optional arg; if there is text in the current ARGV-element,
1213  * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
1214  *
1215  * If OPTSTRING starts with `-' or `+', it requests different methods of
1216  * handling the non-option ARGV-elements.
1217  * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
1218  *
1219  * Long-named options begin with `--' instead of `-'.
1220  * Their names may be abbreviated as long as the abbreviation is unique
1221  * or is an exact match for some defined option.  If they have an
1222  * argument, it follows the option name in the same ARGV-element, separated
1223  * from the option name by a `=', or else the in next ARGV-element.
1224  * When `getopt' finds a long-named option, it returns 0 if that option's
1225  * `flag' field is nonzero, the value of the option's `val' field
1226  * if the `flag' field is zero.
1227  *
1228  * The elements of ARGV aren't really const, because we permute them.
1229  * But we pretend they're const in the prototype to be compatible
1230  * with other systems.
1231  *
1232  * LONGOPTS is a vector of `struct option' terminated by an
1233  * element containing a name which is zero.
1234  *
1235  * LONGIND returns the index in LONGOPT of the long-named option found.
1236  * It is only valid when a long-named option has been found by the most
1237  * recent call.
1238  *
1239  * Return the option character from OPTS just read.  Return -1 when there are
1240  * no more options.  For unrecognized options, or options missing arguments,
1241  * `custom_optopt' is set to the option letter, and '?' is returned.
1242  *
1243  * The OPTS string is a list of characters which are recognized option letters,
1244  * optionally followed by colons, specifying that that letter takes an
1245  * argument, to be placed in `custom_optarg'.
1246  *
1247  * If a letter in OPTS is followed by two colons, its argument is optional.
1248  * This behavior is specific to the GNU `getopt'.
1249  *
1250  * The argument `--' causes premature termination of argument scanning,
1251  * explicitly telling `getopt' that there are no more options.  If OPTS begins
1252  * with `--', then non-option arguments are treated as arguments to the option
1253  * '\0'.  This behavior is specific to the GNU `getopt'.
1254  */
1255 
getopt_internal_r(int argc,char * const * argv,const char * optstring,const struct option * longopts,int * longind,struct custom_getopt_data * d)1256 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1257 		const struct option *longopts, int *longind,
1258 		struct custom_getopt_data *d)
1259 {
1260 	int ret, print_errors = d->custom_opterr;
1261 
1262 	if (optstring[0] == ':')
1263 		print_errors = 0;
1264 	if (argc < 1)
1265 		return -1;
1266 	d->custom_optarg = NULL;
1267 
1268 	/*
1269 	 * This is a big difference with GNU getopt, since optind == 0
1270 	 * means initialization while here 1 means first call.
1271 	 */
1272 	if (d->custom_optind == 0 || !d->initialized) {
1273 		if (d->custom_optind == 0)
1274 			d->custom_optind = 1;	/* Don't scan ARGV[0], the program name.  */
1275 		custom_getopt_initialize(d);
1276 	}
1277 	if (d->nextchar == NULL || *d->nextchar == '\0') {
1278 		ret = shuffle_argv(argc, argv, longopts, d);
1279 		if (ret)
1280 			return ret;
1281 	}
1282 	if (longopts && (argv[d->custom_optind][1] == '-' ))
1283 		return check_long_opt(argc, argv, optstring, longopts,
1284 			longind, print_errors, d);
1285 	return check_short_opt(argc, argv, optstring, print_errors, d);
1286 }
1287 
custom_getopt_internal(int argc,char * const * argv,const char * optstring,const struct option * longopts,int * longind)1288 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1289 	const struct option *longopts, int *longind)
1290 {
1291 	int result;
1292 	/* Keep a global copy of all internal members of d */
1293 	static struct custom_getopt_data d;
1294 
1295 	d.custom_optind = custom_optind;
1296 	d.custom_opterr = custom_opterr;
1297 	result = getopt_internal_r(argc, argv, optstring, longopts,
1298 		longind, &d);
1299 	custom_optind = d.custom_optind;
1300 	custom_optarg = d.custom_optarg;
1301 	custom_optopt = d.custom_optopt;
1302 	return result;
1303 }
1304 
custom_getopt_long(int argc,char * const * argv,const char * options,const struct option * long_options,int * opt_index)1305 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1306 	const struct option *long_options, int *opt_index)
1307 {
1308 	return custom_getopt_internal(argc, argv, options, long_options,
1309 		opt_index);
1310 }
1311 
1312 
1313 static char *package_name = 0;
1314 
1315 /**
1316  * @brief updates an option
1317  * @param field the generic pointer to the field to update
1318  * @param orig_field the pointer to the orig field
1319  * @param field_given the pointer to the number of occurrence of this option
1320  * @param prev_given the pointer to the number of occurrence already seen
1321  * @param value the argument for this option (if null no arg was specified)
1322  * @param possible_values the possible values for this option (if specified)
1323  * @param default_value the default value (in case the option only accepts fixed values)
1324  * @param arg_type the type of this option
1325  * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
1326  * @param override @see cmdline_parser_params.override
1327  * @param no_free whether to free a possible previous value
1328  * @param multiple_option whether this is a multiple option
1329  * @param long_opt the corresponding long option
1330  * @param short_opt the corresponding short option (or '-' if none)
1331  * @param additional_error possible further error specification
1332  */
1333 static
update_arg(void * field,char ** orig_field,unsigned int * field_given,unsigned int * prev_given,char * value,const char * possible_values[],const char * default_value,cmdline_parser_arg_type arg_type,int check_ambiguity,int override,int no_free,int multiple_option,const char * long_opt,char short_opt,const char * additional_error)1334 int update_arg(void *field, char **orig_field,
1335                unsigned int *field_given, unsigned int *prev_given,
1336                char *value, const char *possible_values[],
1337                const char *default_value,
1338                cmdline_parser_arg_type arg_type,
1339                int check_ambiguity, int override,
1340                int no_free, int multiple_option,
1341                const char *long_opt, char short_opt,
1342                const char *additional_error)
1343 {
1344   char *stop_char = 0;
1345   const char *val = value;
1346   int found;
1347   char **string_field;
1348   FIX_UNUSED (field);
1349 
1350   stop_char = 0;
1351   found = 0;
1352 
1353   if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1354     {
1355       if (short_opt != '-')
1356         fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1357                package_name, long_opt, short_opt,
1358                (additional_error ? additional_error : ""));
1359       else
1360         fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1361                package_name, long_opt,
1362                (additional_error ? additional_error : ""));
1363       return 1; /* failure */
1364     }
1365 
1366   if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0)
1367     {
1368       if (short_opt != '-')
1369         fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n",
1370           package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, short_opt,
1371           (additional_error ? additional_error : ""));
1372       else
1373         fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n",
1374           package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt,
1375           (additional_error ? additional_error : ""));
1376       return 1; /* failure */
1377     }
1378 
1379   if (field_given && *field_given && ! override)
1380     return 0;
1381   if (prev_given)
1382     (*prev_given)++;
1383   if (field_given)
1384     (*field_given)++;
1385   if (possible_values)
1386     val = possible_values[found];
1387 
1388   switch(arg_type) {
1389   case ARG_FLAG:
1390     *((int *)field) = !*((int *)field);
1391     break;
1392   case ARG_INT:
1393     if (val) *((int *)field) = strtol (val, &stop_char, 0);
1394     break;
1395   case ARG_FLOAT:
1396     if (val) *((float *)field) = (float)strtod (val, &stop_char);
1397     break;
1398   case ARG_DOUBLE:
1399     if (val) *((double *)field) = strtod (val, &stop_char);
1400     break;
1401   case ARG_STRING:
1402     if (val) {
1403       string_field = (char **)field;
1404       if (!no_free && *string_field)
1405         free (*string_field); /* free previous string */
1406       *string_field = gengetopt_strdup (val);
1407     }
1408     break;
1409   default:
1410     break;
1411   };
1412 
1413   /* check numeric conversion */
1414   switch(arg_type) {
1415   case ARG_INT:
1416   case ARG_FLOAT:
1417   case ARG_DOUBLE:
1418     if (val && !(stop_char && *stop_char == '\0')) {
1419       fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1420       return 1; /* failure */
1421     }
1422     break;
1423   default:
1424     ;
1425   };
1426 
1427   /* store the original value */
1428   switch(arg_type) {
1429   case ARG_NO:
1430   case ARG_FLAG:
1431     break;
1432   default:
1433     if (value && orig_field) {
1434       if (no_free) {
1435         *orig_field = value;
1436       } else {
1437         if (*orig_field)
1438           free (*orig_field); /* free previous string */
1439         *orig_field = gengetopt_strdup (value);
1440       }
1441     }
1442   };
1443 
1444   return 0; /* OK */
1445 }
1446 
1447 
1448 int
cmdline_parser_internal(int argc,char ** argv,struct gengetopt_args_info * args_info,struct cmdline_parser_params * params,const char * additional_error)1449 cmdline_parser_internal (
1450   int argc, char **argv, struct gengetopt_args_info *args_info,
1451                         struct cmdline_parser_params *params, const char *additional_error)
1452 {
1453   int c;	/* Character of the parsed option.  */
1454 
1455   int error_occurred = 0;
1456   struct gengetopt_args_info local_args_info;
1457 
1458   int override;
1459   int initialize;
1460   int check_required;
1461   int check_ambiguity;
1462 
1463   char *optarg;
1464   int optind;
1465   int opterr;
1466   int optopt;
1467 
1468   package_name = argv[0];
1469 
1470   /* TODO: Why is this here? It is not used anywhere. */
1471   override = params->override;
1472   FIX_UNUSED(override);
1473 
1474   initialize = params->initialize;
1475   check_required = params->check_required;
1476 
1477   /* TODO: Why is this here? It is not used anywhere. */
1478   check_ambiguity = params->check_ambiguity;
1479   FIX_UNUSED(check_ambiguity);
1480 
1481   if (initialize)
1482     cmdline_parser_init (args_info);
1483 
1484   cmdline_parser_init (&local_args_info);
1485 
1486   optarg = 0;
1487   optind = 0;
1488   opterr = params->print_errors;
1489   optopt = '?';
1490 
1491   while (1)
1492     {
1493       int option_index = 0;
1494 
1495       static struct option long_options[] = {
1496         { "help",	0, NULL, 'h' },
1497         { "detailed-help",	0, NULL, 0 },
1498         { "full-help",	0, NULL, 0 },
1499         { "version",	0, NULL, 'V' },
1500         { "seq",	1, NULL, 's' },
1501         { "previous",	1, NULL, 'p' },
1502         { "move",	1, NULL, 'm' },
1503         { "min-num",	1, NULL, 'n' },
1504         { "find-num",	1, NULL, 0 },
1505         { "verbose-lvl",	1, NULL, 'v' },
1506         { "depth",	1, NULL, 0 },
1507         { "minh",	1, NULL, 0 },
1508         { "minh-lite",	0, NULL, 0 },
1509         { "walk",	1, NULL, 'w' },
1510         { "noLP",	0, NULL, 0 },
1511         { "useEOS",	0, NULL, 'e' },
1512         { "paramFile",	1, NULL, 'P' },
1513         { "dangles",	1, NULL, 'd' },
1514         { "fix-barriers",	1, NULL, 0 },
1515         { "pseudoknots",	0, NULL, 'k' },
1516         { "just-read",	0, NULL, 0 },
1517         { "neighborhood",	0, NULL, 'N' },
1518         { "degeneracy-off",	0, NULL, 0 },
1519         { "just-output",	0, NULL, 0 },
1520         { "bartree",	0, NULL, 'b' },
1521         { "barr-name",	1, NULL, 0 },
1522         { "barrier-file",	1, NULL, 0 },
1523         { "rates",	0, NULL, 'r' },
1524         { "rates-file",	1, NULL, 'f' },
1525         { "temp",	1, NULL, 'T' },
1526         { "floodPortion",	1, NULL, 0 },
1527         { "floodMax",	1, NULL, 0 },
1528         { "numIntervals",	1, NULL, 0 },
1529         { "eRange",	1, NULL, 0 },
1530         { "allegiance",	1, NULL, 0 },
1531         { 0,  0, 0, 0 }
1532       };
1533 
1534       custom_optarg = optarg;
1535       custom_optind = optind;
1536       custom_opterr = opterr;
1537       custom_optopt = optopt;
1538 
1539       c = custom_getopt_long (argc, argv, "hVs:p:m:n:v:w:eP:d:kNbrf:T:", long_options, &option_index);
1540 
1541       optarg = custom_optarg;
1542       optind = custom_optind;
1543       opterr = custom_opterr;
1544       optopt = custom_optopt;
1545 
1546       if (c == -1) break;	/* Exit from `while (1)' loop.  */
1547 
1548       switch (c)
1549         {
1550         case 'h':	/* Print help and exit.  */
1551           cmdline_parser_print_help ();
1552           cmdline_parser_free (&local_args_info);
1553           exit (EXIT_SUCCESS);
1554 
1555         case 'V':	/* Print version and exit.  */
1556           cmdline_parser_print_version ();
1557           cmdline_parser_free (&local_args_info);
1558           exit (EXIT_SUCCESS);
1559 
1560         case 's':	/* Sequence file in FASTA format. If the sequence is the first line of the input file, this is not needed.  */
1561 
1562 
1563           if (update_arg( (void *)&(args_info->seq_arg),
1564                &(args_info->seq_orig), &(args_info->seq_given),
1565               &(local_args_info.seq_given), optarg, 0, "seq.txt", ARG_STRING,
1566               check_ambiguity, override, 0, 0,
1567               "seq", 's',
1568               additional_error))
1569             goto failure;
1570 
1571           break;
1572         case 'p':	/* Previously found LM (output from RNAlocmin or barriers), if specified does not need --seq option.  */
1573 
1574 
1575           if (update_arg( (void *)&(args_info->previous_arg),
1576                &(args_info->previous_orig), &(args_info->previous_given),
1577               &(local_args_info.previous_given), optarg, 0, 0, ARG_STRING,
1578               check_ambiguity, override, 0, 0,
1579               "previous", 'p',
1580               additional_error))
1581             goto failure;
1582 
1583           break;
1584         case 'm':	/* Move set:
1585         I ==> insertion & deletion of base pairs
1586         S ==> I&D& switch of base pairs.  */
1587 
1588 
1589           if (update_arg( (void *)&(args_info->move_arg),
1590                &(args_info->move_orig), &(args_info->move_given),
1591               &(local_args_info.move_given), optarg, cmdline_parser_move_values, "I", ARG_STRING,
1592               check_ambiguity, override, 0, 0,
1593               "move", 'm',
1594               additional_error))
1595             goto failure;
1596 
1597           break;
1598         case 'n':	/* Maximal number of local minima returned
1599         (0 == unlimited).  */
1600 
1601 
1602           if (update_arg( (void *)&(args_info->min_num_arg),
1603                &(args_info->min_num_orig), &(args_info->min_num_given),
1604               &(local_args_info.min_num_given), optarg, 0, "100000", ARG_INT,
1605               check_ambiguity, override, 0, 0,
1606               "min-num", 'n',
1607               additional_error))
1608             goto failure;
1609 
1610           break;
1611         case 'v':	/* Level of verbosity (0 = nothing, 4 = full)
1612         WARNING: higher verbose levels increase the computation time.  */
1613 
1614 
1615           if (update_arg( (void *)&(args_info->verbose_lvl_arg),
1616                &(args_info->verbose_lvl_orig), &(args_info->verbose_lvl_given),
1617               &(local_args_info.verbose_lvl_given), optarg, 0, "0", ARG_INT,
1618               check_ambiguity, override, 0, 0,
1619               "verbose-lvl", 'v',
1620               additional_error))
1621             goto failure;
1622 
1623           break;
1624         case 'w':	/* Walking method used
1625         D ==> gradient descent
1626         F ==> use first found lower energy structure
1627         R ==> use random lower energy structure (does not work with --noLP and -m S options).  */
1628 
1629 
1630           if (update_arg( (void *)&(args_info->walk_arg),
1631                &(args_info->walk_orig), &(args_info->walk_given),
1632               &(local_args_info.walk_given), optarg, cmdline_parser_walk_values, "D", ARG_STRING,
1633               check_ambiguity, override, 0, 0,
1634               "walk", 'w',
1635               additional_error))
1636             goto failure;
1637 
1638           break;
1639         case 'e':	/* Use energy_of_structure_pt calculation instead of energy_of_move (slower, it should not affect results).  */
1640 
1641 
1642           if (update_arg((void *)&(args_info->useEOS_flag), 0, &(args_info->useEOS_given),
1643               &(local_args_info.useEOS_given), optarg, 0, 0, ARG_FLAG,
1644               check_ambiguity, override, 1, 0, "useEOS", 'e',
1645               additional_error))
1646             goto failure;
1647 
1648           break;
1649         case 'P':	/* Read energy parameters from paramfile, instead of using the default parameter set.  */
1650 
1651 
1652           if (update_arg( (void *)&(args_info->paramFile_arg),
1653                &(args_info->paramFile_orig), &(args_info->paramFile_given),
1654               &(local_args_info.paramFile_given), optarg, 0, 0, ARG_STRING,
1655               check_ambiguity, override, 0, 0,
1656               "paramFile", 'P',
1657               additional_error))
1658             goto failure;
1659 
1660           break;
1661         case 'd':	/* How to treat \"dangling end\" energies for bases adjacent to helices in free ends and multi-loops
1662 .  */
1663 
1664 
1665           if (update_arg( (void *)&(args_info->dangles_arg),
1666                &(args_info->dangles_orig), &(args_info->dangles_given),
1667               &(local_args_info.dangles_given), optarg, 0, "2", ARG_INT,
1668               check_ambiguity, override, 0, 0,
1669               "dangles", 'd',
1670               additional_error))
1671             goto failure;
1672 
1673           break;
1674         case 'k':	/* Allow for pseudoknots according to \"gfold\" model - H, K, L, and M types (genus one) of pseudoknots are allowed (increases computation time greatly), cannot be combined with shift move set (-m S).  */
1675 
1676 
1677           if (update_arg((void *)&(args_info->pseudoknots_flag), 0, &(args_info->pseudoknots_given),
1678               &(local_args_info.pseudoknots_given), optarg, 0, 0, ARG_FLAG,
1679               check_ambiguity, override, 1, 0, "pseudoknots", 'k',
1680               additional_error))
1681             goto failure;
1682 
1683           break;
1684         case 'N':	/* Use the Neighborhood routines to perform gradient descend. Cannot be combined with shift move set (-m S) and pseudoknots (-k). Test option..  */
1685 
1686 
1687           if (update_arg((void *)&(args_info->neighborhood_flag), 0, &(args_info->neighborhood_given),
1688               &(local_args_info.neighborhood_given), optarg, 0, 0, ARG_FLAG,
1689               check_ambiguity, override, 1, 0, "neighborhood", 'N',
1690               additional_error))
1691             goto failure;
1692 
1693           break;
1694         case 'b':	/* Generate an approximate barrier tree..  */
1695 
1696 
1697           if (update_arg((void *)&(args_info->bartree_flag), 0, &(args_info->bartree_given),
1698               &(local_args_info.bartree_given), optarg, 0, 0, ARG_FLAG,
1699               check_ambiguity, override, 1, 0, "bartree", 'b',
1700               additional_error))
1701             goto failure;
1702 
1703           break;
1704         case 'r':	/* Create rates for treekin.  */
1705 
1706 
1707           if (update_arg((void *)&(args_info->rates_flag), 0, &(args_info->rates_given),
1708               &(local_args_info.rates_given), optarg, 0, 0, ARG_FLAG,
1709               check_ambiguity, override, 1, 0, "rates", 'r',
1710               additional_error))
1711             goto failure;
1712 
1713           break;
1714         case 'f':	/* File where to write rates, switches on -r flag.  */
1715 
1716 
1717           if (update_arg( (void *)&(args_info->rates_file_arg),
1718                &(args_info->rates_file_orig), &(args_info->rates_file_given),
1719               &(local_args_info.rates_file_given), optarg, 0, "rates.out", ARG_STRING,
1720               check_ambiguity, override, 0, 0,
1721               "rates-file", 'f',
1722               additional_error))
1723             goto failure;
1724 
1725           break;
1726         case 'T':	/* Temperature in Celsius (only for rates).  */
1727 
1728 
1729           if (update_arg( (void *)&(args_info->temp_arg),
1730                &(args_info->temp_orig), &(args_info->temp_given),
1731               &(local_args_info.temp_given), optarg, 0, "37.0", ARG_DOUBLE,
1732               check_ambiguity, override, 0, 0,
1733               "temp", 'T',
1734               additional_error))
1735             goto failure;
1736 
1737           break;
1738 
1739         case 0:	/* Long option with no short option */
1740           if (strcmp (long_options[option_index].name, "detailed-help") == 0) {
1741             cmdline_parser_print_detailed_help ();
1742             cmdline_parser_free (&local_args_info);
1743             exit (EXIT_SUCCESS);
1744           }
1745 
1746           if (strcmp (long_options[option_index].name, "full-help") == 0) {
1747             cmdline_parser_print_full_help ();
1748             cmdline_parser_free (&local_args_info);
1749             exit (EXIT_SUCCESS);
1750           }
1751 
1752           /* Maximal number of local minima found
1753           (default = unlimited - crawl through whole input file).  */
1754           if (strcmp (long_options[option_index].name, "find-num") == 0)
1755           {
1756 
1757 
1758             if (update_arg( (void *)&(args_info->find_num_arg),
1759                  &(args_info->find_num_orig), &(args_info->find_num_given),
1760                 &(local_args_info.find_num_given), optarg, 0, 0, ARG_INT,
1761                 check_ambiguity, override, 0, 0,
1762                 "find-num", '-',
1763                 additional_error))
1764               goto failure;
1765 
1766           }
1767           /* Depth of findpath search (higher value increases running time linearly).  */
1768           else if (strcmp (long_options[option_index].name, "depth") == 0)
1769           {
1770 
1771 
1772             if (update_arg( (void *)&(args_info->depth_arg),
1773                  &(args_info->depth_orig), &(args_info->depth_given),
1774                 &(local_args_info.depth_given), optarg, 0, "10", ARG_INT,
1775                 check_ambiguity, override, 0, 0,
1776                 "depth", '-',
1777                 additional_error))
1778               goto failure;
1779 
1780           }
1781           /* Print only minima with energy barrier greater than this.  */
1782           else if (strcmp (long_options[option_index].name, "minh") == 0)
1783           {
1784 
1785 
1786             if (update_arg( (void *)&(args_info->minh_arg),
1787                  &(args_info->minh_orig), &(args_info->minh_given),
1788                 &(local_args_info.minh_given), optarg, 0, "0.0", ARG_DOUBLE,
1789                 check_ambiguity, override, 0, 0,
1790                 "minh", '-',
1791                 additional_error))
1792               goto failure;
1793 
1794           }
1795           /* When flooding with --minh option, search for only saddle (do not search for a LM that is lower). Increases efficiency a tiny bit, but when turned on, the results may omit some non-shallow minima, especially with higher --minh value..  */
1796           else if (strcmp (long_options[option_index].name, "minh-lite") == 0)
1797           {
1798 
1799 
1800             if (update_arg((void *)&(args_info->minh_lite_flag), 0, &(args_info->minh_lite_given),
1801                 &(local_args_info.minh_lite_given), optarg, 0, 0, ARG_FLAG,
1802                 check_ambiguity, override, 1, 0, "minh-lite", '-',
1803                 additional_error))
1804               goto failure;
1805 
1806           }
1807           /* Work only with canonical RNA structures (w/o isolated base pairs, cannot be combined with ranodm walk (-w R option) and shift move set (-m S)).  */
1808           else if (strcmp (long_options[option_index].name, "noLP") == 0)
1809           {
1810 
1811 
1812             if (update_arg((void *)&(args_info->noLP_flag), 0, &(args_info->noLP_given),
1813                 &(local_args_info.noLP_given), optarg, 0, 0, ARG_FLAG,
1814                 check_ambiguity, override, 1, 0, "noLP", '-',
1815                 additional_error))
1816               goto failure;
1817 
1818           }
1819           /* Fix barrier file for interior loops (just recompute if all LM in barrier output are LM), if specified, does not need neither --previous nor --seq option.  */
1820           else if (strcmp (long_options[option_index].name, "fix-barriers") == 0)
1821           {
1822 
1823 
1824             if (update_arg( (void *)&(args_info->fix_barriers_arg),
1825                  &(args_info->fix_barriers_orig), &(args_info->fix_barriers_given),
1826                 &(local_args_info.fix_barriers_given), optarg, 0, 0, ARG_STRING,
1827                 check_ambiguity, override, 0, 0,
1828                 "fix-barriers", '-',
1829                 additional_error))
1830               goto failure;
1831 
1832           }
1833           /* Do not expect input from stdin, just do postprocessing..  */
1834           else if (strcmp (long_options[option_index].name, "just-read") == 0)
1835           {
1836 
1837 
1838             if (update_arg((void *)&(args_info->just_read_flag), 0, &(args_info->just_read_given),
1839                 &(local_args_info.just_read_given), optarg, 0, 0, ARG_FLAG,
1840                 check_ambiguity, override, 1, 0, "just-read", '-',
1841                 additional_error))
1842               goto failure;
1843 
1844           }
1845           /* Do not deal with degeneracy, select the lexicographically first from the same energy neighbors..  */
1846           else if (strcmp (long_options[option_index].name, "degeneracy-off") == 0)
1847           {
1848 
1849 
1850             if (update_arg((void *)&(args_info->degeneracy_off_flag), 0, &(args_info->degeneracy_off_given),
1851                 &(local_args_info.degeneracy_off_given), optarg, 0, 0, ARG_FLAG,
1852                 check_ambiguity, override, 1, 0, "degeneracy-off", '-',
1853                 additional_error))
1854               goto failure;
1855 
1856           }
1857           /* Do not store the minima and optimize, just compute directly minima and output them. Output file can contain duplicates..  */
1858           else if (strcmp (long_options[option_index].name, "just-output") == 0)
1859           {
1860 
1861 
1862             if (update_arg((void *)&(args_info->just_output_flag), 0, &(args_info->just_output_given),
1863                 &(local_args_info.just_output_given), optarg, 0, 0, ARG_FLAG,
1864                 check_ambiguity, override, 1, 0, "just-output", '-',
1865                 additional_error))
1866               goto failure;
1867 
1868           }
1869           /* Name of barrier tree output file, switches on -b flag..  */
1870           else if (strcmp (long_options[option_index].name, "barr-name") == 0)
1871           {
1872 
1873 
1874             if (update_arg( (void *)&(args_info->barr_name_arg),
1875                  &(args_info->barr_name_orig), &(args_info->barr_name_given),
1876                 &(local_args_info.barr_name_given), optarg, 0, "treeRNAloc.ps", ARG_STRING,
1877                 check_ambiguity, override, 0, 0,
1878                 "barr-name", '-',
1879                 additional_error))
1880               goto failure;
1881 
1882           }
1883           /* File for saddle heights between LM (simulates the output format of barriers program).  */
1884           else if (strcmp (long_options[option_index].name, "barrier-file") == 0)
1885           {
1886 
1887 
1888             if (update_arg( (void *)&(args_info->barrier_file_arg),
1889                  &(args_info->barrier_file_orig), &(args_info->barrier_file_given),
1890                 &(local_args_info.barrier_file_given), optarg, 0, 0, ARG_STRING,
1891                 check_ambiguity, override, 0, 0,
1892                 "barrier-file", '-',
1893                 additional_error))
1894               goto failure;
1895 
1896           }
1897           /* Fraction of minima to flood (floods first minima with low number of inwalking sample structures)
1898           (0.0 -> no flood; 1.0 -> try to flood all) Usable only with -r or -b options..  */
1899           else if (strcmp (long_options[option_index].name, "floodPortion") == 0)
1900           {
1901 
1902 
1903             if (update_arg( (void *)&(args_info->floodPortion_arg),
1904                  &(args_info->floodPortion_orig), &(args_info->floodPortion_given),
1905                 &(local_args_info.floodPortion_given), optarg, 0, "0.95", ARG_DOUBLE,
1906                 check_ambiguity, override, 0, 0,
1907                 "floodPortion", '-',
1908                 additional_error))
1909               goto failure;
1910 
1911           }
1912           /* Flood cap - how many structures to flood in one basin.  */
1913           else if (strcmp (long_options[option_index].name, "floodMax") == 0)
1914           {
1915 
1916 
1917             if (update_arg( (void *)&(args_info->floodMax_arg),
1918                  &(args_info->floodMax_orig), &(args_info->floodMax_given),
1919                 &(local_args_info.floodMax_given), optarg, 0, "1000", ARG_INT,
1920                 check_ambiguity, override, 0, 0,
1921                 "floodMax", '-',
1922                 additional_error))
1923               goto failure;
1924 
1925           }
1926           /* Number of intervals for Jing's visualisation.  */
1927           else if (strcmp (long_options[option_index].name, "numIntervals") == 0)
1928           {
1929 
1930 
1931             if (update_arg( (void *)&(args_info->numIntervals_arg),
1932                  &(args_info->numIntervals_orig), &(args_info->numIntervals_given),
1933                 &(local_args_info.numIntervals_given), optarg, 0, "0", ARG_INT,
1934                 check_ambiguity, override, 0, 0,
1935                 "numIntervals", '-',
1936                 additional_error))
1937               goto failure;
1938 
1939           }
1940           /* Report only LM, which energy is in range <MFE (or lowest found LM), MFE+eRange> in kcal/mol..  */
1941           else if (strcmp (long_options[option_index].name, "eRange") == 0)
1942           {
1943 
1944 
1945             if (update_arg( (void *)&(args_info->eRange_arg),
1946                  &(args_info->eRange_orig), &(args_info->eRange_given),
1947                 &(local_args_info.eRange_given), optarg, 0, 0, ARG_FLOAT,
1948                 check_ambiguity, override, 0, 0,
1949                 "eRange", '-',
1950                 additional_error))
1951               goto failure;
1952 
1953           }
1954           /* Filename where to output the allegiance of structures. Works properly only with RNAsubopt -e list..  */
1955           else if (strcmp (long_options[option_index].name, "allegiance") == 0)
1956           {
1957 
1958 
1959             if (update_arg( (void *)&(args_info->allegiance_arg),
1960                  &(args_info->allegiance_orig), &(args_info->allegiance_given),
1961                 &(local_args_info.allegiance_given), optarg, 0, 0, ARG_STRING,
1962                 check_ambiguity, override, 0, 0,
1963                 "allegiance", '-',
1964                 additional_error))
1965               goto failure;
1966 
1967           }
1968 
1969           break;
1970         case '?':	/* Invalid option.  */
1971           /* `getopt_long' already printed an error message.  */
1972           goto failure;
1973 
1974         default:	/* bug: option not considered.  */
1975           fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1976           abort ();
1977         } /* switch */
1978     } /* while */
1979 
1980 
1981 
1982 	FIX_UNUSED(check_required);
1983 
1984   cmdline_parser_release (&local_args_info);
1985 
1986   if ( error_occurred )
1987     return (EXIT_FAILURE);
1988 
1989   if (optind < argc)
1990     {
1991       int i = 0 ;
1992       int found_prog_name = 0;
1993       /* whether program name, i.e., argv[0], is in the remaining args
1994          (this may happen with some implementations of getopt,
1995           but surely not with the one included by gengetopt) */
1996 
1997 
1998       args_info->inputs_num = argc - optind - found_prog_name;
1999       args_info->inputs =
2000         (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
2001       while (optind < argc)
2002         args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
2003     }
2004 
2005   return 0;
2006 
2007 failure:
2008 
2009   cmdline_parser_release (&local_args_info);
2010   return (EXIT_FAILURE);
2011 }
2012 /* vim: set ft=c noet ts=8 sts=8 sw=8 tw=80 nojs spell : */
2013