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