]> Creatis software - clitk.git/blob - vv/tools_ggo/clitkMIP_ggo.c
Add _ggo files for static compilation with .pro file
[clitk.git] / vv / tools_ggo / clitkMIP_ggo.c
1 /*
2   File autogenerated by gengetopt version 2.22
3   generated with the following command:
4   /usr/local/bin/gengetopt --output-dir=/home/tbaudier/vv/vv_static/vv/vv_bin/tools --arg-struct-name=args_info_clitkMIP --func-name=cmdline_parser_clitkMIP --file-name=clitkMIP_ggo --unamed-opts --conf-parser --include-getopt 
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
21 #include "clitkMIP_ggo.h"
22
23 const char *args_info_clitkMIP_purpose = "";
24
25 const char *args_info_clitkMIP_usage = "Usage: clitkMIP [OPTIONS]... [FILES]...";
26
27 const char *args_info_clitkMIP_description = "";
28
29 const char *args_info_clitkMIP_help[] = {
30   "  -h, --help           Print help and exit",
31   "  -V, --version        Print version and exit",
32   "      --config=STRING  Config file",
33   "  -v, --verbose        Verbose  (default=off)",
34   "      --imagetypes     Display allowed image types  (default=off)",
35   "  -i, --input=STRING   Input image filename",
36   "  -o, --output=STRING  Output image filename",
37   "  -d, --dimension=INT  Dimension along which to projetct",
38     0
39 };
40
41 typedef enum {ARG_NO
42   , ARG_FLAG
43   , ARG_STRING
44   , ARG_INT
45 } cmdline_parser_clitkMIP_arg_type;
46
47 static
48 void clear_given (struct args_info_clitkMIP *args_info);
49 static
50 void clear_args (struct args_info_clitkMIP *args_info);
51
52 static int
53 cmdline_parser_clitkMIP_internal (int argc, char * const *argv, struct args_info_clitkMIP *args_info,
54                         struct cmdline_parser_clitkMIP_params *params, const char *additional_error);
55
56 static int
57 cmdline_parser_clitkMIP_required2 (struct args_info_clitkMIP *args_info, const char *prog_name, const char *additional_error);
58 struct line_list
59 {
60   char * string_arg;
61   struct line_list * next;
62 };
63
64 static struct line_list *cmd_line_list = 0;
65 static struct line_list *cmd_line_list_tmp = 0;
66
67 static void
68 free_cmd_list(void)
69 {
70   /* free the list of a previous call */
71   if (cmd_line_list)
72     {
73       while (cmd_line_list) {
74         cmd_line_list_tmp = cmd_line_list;
75         cmd_line_list = cmd_line_list->next;
76         free (cmd_line_list_tmp->string_arg);
77         free (cmd_line_list_tmp);
78       }
79     }
80 }
81
82
83 static char *
84 gengetopt_strdup (const char *s);
85
86 static
87 void clear_given (struct args_info_clitkMIP *args_info)
88 {
89   args_info->help_given = 0 ;
90   args_info->version_given = 0 ;
91   args_info->config_given = 0 ;
92   args_info->verbose_given = 0 ;
93   args_info->imagetypes_given = 0 ;
94   args_info->input_given = 0 ;
95   args_info->output_given = 0 ;
96   args_info->dimension_given = 0 ;
97 }
98
99 static
100 void clear_args (struct args_info_clitkMIP *args_info)
101 {
102   args_info->config_arg = NULL;
103   args_info->config_orig = NULL;
104   args_info->verbose_flag = 0;
105   args_info->imagetypes_flag = 0;
106   args_info->input_arg = NULL;
107   args_info->input_orig = NULL;
108   args_info->output_arg = NULL;
109   args_info->output_orig = NULL;
110   args_info->dimension_orig = NULL;
111   
112 }
113
114 static
115 void init_args_info(struct args_info_clitkMIP *args_info)
116 {
117
118
119   args_info->help_help = args_info_clitkMIP_help[0] ;
120   args_info->version_help = args_info_clitkMIP_help[1] ;
121   args_info->config_help = args_info_clitkMIP_help[2] ;
122   args_info->verbose_help = args_info_clitkMIP_help[3] ;
123   args_info->imagetypes_help = args_info_clitkMIP_help[4] ;
124   args_info->input_help = args_info_clitkMIP_help[5] ;
125   args_info->output_help = args_info_clitkMIP_help[6] ;
126   args_info->dimension_help = args_info_clitkMIP_help[7] ;
127   
128 }
129
130 void
131 cmdline_parser_clitkMIP_print_version (void)
132 {
133   printf ("%s %s\n", CMDLINE_PARSER_CLITKMIP_PACKAGE, CMDLINE_PARSER_CLITKMIP_VERSION);
134 }
135
136 static void print_help_common(void) {
137   cmdline_parser_clitkMIP_print_version ();
138
139   if (strlen(args_info_clitkMIP_purpose) > 0)
140     printf("\n%s\n", args_info_clitkMIP_purpose);
141
142   if (strlen(args_info_clitkMIP_usage) > 0)
143     printf("\n%s\n", args_info_clitkMIP_usage);
144
145   printf("\n");
146
147   if (strlen(args_info_clitkMIP_description) > 0)
148     printf("%s\n", args_info_clitkMIP_description);
149 }
150
151 void
152 cmdline_parser_clitkMIP_print_help (void)
153 {
154   int i = 0;
155   print_help_common();
156   while (args_info_clitkMIP_help[i])
157     printf("%s\n", args_info_clitkMIP_help[i++]);
158 }
159
160 void
161 cmdline_parser_clitkMIP_init (struct args_info_clitkMIP *args_info)
162 {
163   clear_given (args_info);
164   clear_args (args_info);
165   init_args_info (args_info);
166
167   args_info->inputs = NULL;
168   args_info->inputs_num = 0;
169 }
170
171 void
172 cmdline_parser_clitkMIP_params_init(struct cmdline_parser_clitkMIP_params *params)
173 {
174   if (params)
175     { 
176       params->override = 0;
177       params->initialize = 1;
178       params->check_required = 1;
179       params->check_ambiguity = 0;
180       params->print_errors = 1;
181     }
182 }
183
184 struct cmdline_parser_clitkMIP_params *
185 cmdline_parser_clitkMIP_params_create(void)
186 {
187   struct cmdline_parser_clitkMIP_params *params = 
188     (struct cmdline_parser_clitkMIP_params *)malloc(sizeof(struct cmdline_parser_clitkMIP_params));
189   cmdline_parser_clitkMIP_params_init(params);  
190   return params;
191 }
192
193 static void
194 free_string_field (char **s)
195 {
196   if (*s)
197     {
198       free (*s);
199       *s = 0;
200     }
201 }
202
203
204 static void
205 cmdline_parser_clitkMIP_release (struct args_info_clitkMIP *args_info)
206 {
207   unsigned int i;
208   free_string_field (&(args_info->config_arg));
209   free_string_field (&(args_info->config_orig));
210   free_string_field (&(args_info->input_arg));
211   free_string_field (&(args_info->input_orig));
212   free_string_field (&(args_info->output_arg));
213   free_string_field (&(args_info->output_orig));
214   free_string_field (&(args_info->dimension_orig));
215   
216   
217   for (i = 0; i < args_info->inputs_num; ++i)
218     free (args_info->inputs [i]);
219
220   if (args_info->inputs_num)
221     free (args_info->inputs);
222
223   clear_given (args_info);
224 }
225
226
227 static void
228 write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
229 {
230   if (arg) {
231     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
232   } else {
233     fprintf(outfile, "%s\n", opt);
234   }
235 }
236
237
238 int
239 cmdline_parser_clitkMIP_dump(FILE *outfile, struct args_info_clitkMIP *args_info)
240 {
241   int i = 0;
242
243   if (!outfile)
244     {
245       fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKMIP_PACKAGE);
246       return EXIT_FAILURE;
247     }
248
249   if (args_info->help_given)
250     write_into_file(outfile, "help", 0, 0 );
251   if (args_info->version_given)
252     write_into_file(outfile, "version", 0, 0 );
253   if (args_info->config_given)
254     write_into_file(outfile, "config", args_info->config_orig, 0);
255   if (args_info->verbose_given)
256     write_into_file(outfile, "verbose", 0, 0 );
257   if (args_info->imagetypes_given)
258     write_into_file(outfile, "imagetypes", 0, 0 );
259   if (args_info->input_given)
260     write_into_file(outfile, "input", args_info->input_orig, 0);
261   if (args_info->output_given)
262     write_into_file(outfile, "output", args_info->output_orig, 0);
263   if (args_info->dimension_given)
264     write_into_file(outfile, "dimension", args_info->dimension_orig, 0);
265   
266
267   i = EXIT_SUCCESS;
268   return i;
269 }
270
271 int
272 cmdline_parser_clitkMIP_file_save(const char *filename, struct args_info_clitkMIP *args_info)
273 {
274   FILE *outfile;
275   int i = 0;
276
277   outfile = fopen(filename, "w");
278
279   if (!outfile)
280     {
281       fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKMIP_PACKAGE, filename);
282       return EXIT_FAILURE;
283     }
284
285   i = cmdline_parser_clitkMIP_dump(outfile, args_info);
286   fclose (outfile);
287
288   return i;
289 }
290
291 void
292 cmdline_parser_clitkMIP_free (struct args_info_clitkMIP *args_info)
293 {
294   cmdline_parser_clitkMIP_release (args_info);
295 }
296
297 /** @brief replacement of strdup, which is not standard */
298 char *
299 gengetopt_strdup (const char *s)
300 {
301   char *result = NULL;
302   if (!s)
303     return result;
304
305   result = (char*)malloc(strlen(s) + 1);
306   if (result == (char*)0)
307     return (char*)0;
308   strcpy(result, s);
309   return result;
310 }
311
312 int
313 cmdline_parser_clitkMIP (int argc, char * const *argv, struct args_info_clitkMIP *args_info)
314 {
315   return cmdline_parser_clitkMIP2 (argc, argv, args_info, 0, 1, 1);
316 }
317
318 int
319 cmdline_parser_clitkMIP_ext (int argc, char * const *argv, struct args_info_clitkMIP *args_info,
320                    struct cmdline_parser_clitkMIP_params *params)
321 {
322   int result;
323   result = cmdline_parser_clitkMIP_internal (argc, argv, args_info, params, NULL);
324
325   if (result == EXIT_FAILURE)
326     {
327       cmdline_parser_clitkMIP_free (args_info);
328       exit (EXIT_FAILURE);
329     }
330   
331   return result;
332 }
333
334 int
335 cmdline_parser_clitkMIP2 (int argc, char * const *argv, struct args_info_clitkMIP *args_info, int override, int initialize, int check_required)
336 {
337   int result;
338   struct cmdline_parser_clitkMIP_params params;
339   
340   params.override = override;
341   params.initialize = initialize;
342   params.check_required = check_required;
343   params.check_ambiguity = 0;
344   params.print_errors = 1;
345
346   result = cmdline_parser_clitkMIP_internal (argc, argv, args_info, &params, NULL);
347
348   if (result == EXIT_FAILURE)
349     {
350       cmdline_parser_clitkMIP_free (args_info);
351       exit (EXIT_FAILURE);
352     }
353   
354   return result;
355 }
356
357 int
358 cmdline_parser_clitkMIP_required (struct args_info_clitkMIP *args_info, const char *prog_name)
359 {
360   int result = EXIT_SUCCESS;
361
362   if (cmdline_parser_clitkMIP_required2(args_info, prog_name, NULL) > 0)
363     result = EXIT_FAILURE;
364
365   if (result == EXIT_FAILURE)
366     {
367       cmdline_parser_clitkMIP_free (args_info);
368       exit (EXIT_FAILURE);
369     }
370   
371   return result;
372 }
373
374 int
375 cmdline_parser_clitkMIP_required2 (struct args_info_clitkMIP *args_info, const char *prog_name, const char *additional_error)
376 {
377   int error = 0;
378
379   /* checks for required options */
380   if (! args_info->input_given)
381     {
382       fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
383       error = 1;
384     }
385   
386   if (! args_info->output_given)
387     {
388       fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
389       error = 1;
390     }
391   
392   if (! args_info->dimension_given)
393     {
394       fprintf (stderr, "%s: '--dimension' ('-d') option required%s\n", prog_name, (additional_error ? additional_error : ""));
395       error = 1;
396     }
397   
398   
399   /* checks for dependences among options */
400
401   return error;
402 }
403
404 /*
405  * Extracted from the glibc source tree, version 2.3.6
406  *
407  * Licensed under the GPL as per the whole glibc source tree.
408  *
409  * This file was modified so that getopt_long can be called
410  * many times without risking previous memory to be spoiled.
411  *
412  * Modified by Andre Noll and Lorenzo Bettini for use in
413  * GNU gengetopt generated files.
414  *
415  */
416
417 /* 
418  * we must include anything we need since this file is not thought to be
419  * inserted in a file already using getopt.h
420  *
421  * Lorenzo
422  */
423
424 struct option
425 {
426   const char *name;
427   /* has_arg can't be an enum because some compilers complain about
428      type mismatches in all the code that assumes it is an int.  */
429   int has_arg;
430   int *flag;
431   int val;
432 };
433
434 /* For communication from `getopt' to the caller.
435    When `getopt' finds an option that takes an argument,
436    the argument value is returned here.
437    Also, when `ordering' is RETURN_IN_ORDER,
438    each non-option ARGV-element is returned here.  */
439
440 static char *optarg;
441
442 /* Index in ARGV of the next element to be scanned.
443    This is used for communication to and from the caller
444    and for communication between successive calls to `getopt'.
445
446    On entry to `getopt', zero means this is the first call; initialize.
447
448    When `getopt' returns -1, this is the index of the first of the
449    non-option elements that the caller should itself scan.
450
451    Otherwise, `optind' communicates from one call to the next
452    how much of ARGV has been scanned so far.  */
453
454 static int optind;
455
456 /* Callers store zero here to inhibit the error message `getopt' prints
457    for unrecognized options.  */
458
459 static int opterr;
460
461 /* Set to an option character which was unrecognized.  */
462
463 static int optopt;
464
465 /* This version of `getopt' appears to the caller like standard Unix `getopt'
466    but it behaves differently for the user, since it allows the user
467    to intersperse the options with the other arguments.
468
469    As `getopt' works, it permutes the elements of ARGV so that,
470    when it is done, all the options precede everything else.  Thus
471    all application programs are extended to handle flexible argument order.
472 */
473 /*
474    If the field `flag' is not NULL, it points to a variable that is set
475    to the value given in the field `val' when the option is found, but
476    left unchanged if the option is not found.
477
478    To have a long-named option do something other than set an `int' to
479    a compiled-in constant, such as set a value from `custom_optarg', set the
480    option's `flag' field to zero and its `val' field to a nonzero
481    value (the equivalent single-letter option character, if there is
482    one).  For long options that have a zero `flag' field, `getopt'
483    returns the contents of the `val' field.  */
484
485 /* Names for the values of the `has_arg' field of `struct option'.  */
486 #ifndef no_argument
487 #define no_argument             0
488 #endif
489
490 #ifndef required_argument
491 #define required_argument       1
492 #endif
493
494 #ifndef optional_argument
495 #define optional_argument       2
496 #endif
497
498 struct custom_getopt_data {
499         /*
500          * These have exactly the same meaning as the corresponding global variables,
501          * except that they are used for the reentrant versions of getopt.
502          */
503         int custom_optind;
504         int custom_opterr;
505         int custom_optopt;
506         char *custom_optarg;
507
508         /* True if the internal members have been initialized.  */
509         int initialized;
510
511         /*
512          * The next char to be scanned in the option-element in which the last option
513          * character we returned was found.  This allows us to pick up the scan where
514          * we left off.  If this is zero, or a null string, it means resume the scan by
515          * advancing to the next ARGV-element.
516          */
517         char *nextchar;
518
519         /*
520          * Describe the part of ARGV that contains non-options that have been skipped.
521          * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
522          * the index after the last of them.
523          */
524         int first_nonopt;
525         int last_nonopt;
526 };
527
528 /*
529  * the variables optarg, optind, opterr and optopt are renamed with
530  * the custom_ prefix so that they don't interfere with getopt ones.
531  *
532  * Moreover they're static so they are visible only from within the
533  * file where this very file will be included.
534  */
535
536 /*
537  * For communication from `custom_getopt' to the caller.  When `custom_getopt' finds an
538  * option that takes an argument, the argument value is returned here.
539  */
540 static char *custom_optarg;
541
542 /*
543  * Index in ARGV of the next element to be scanned.  This is used for
544  * communication to and from the caller and for communication between
545  * successive calls to `custom_getopt'.
546  *
547  * On entry to `custom_getopt', 1 means this is the first call; initialize.
548  *
549  * When `custom_getopt' returns -1, this is the index of the first of the non-option
550  * elements that the caller should itself scan.
551  *
552  * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
553  * has been scanned so far.
554  *
555  * 1003.2 says this must be 1 before any call.
556  */
557 static int custom_optind = 1;
558
559 /*
560  * Callers store zero here to inhibit the error message for unrecognized
561  * options.
562  */
563 static int custom_opterr = 1;
564
565 /*
566  * Set to an option character which was unrecognized.  This must be initialized
567  * on some systems to avoid linking in the system's own getopt implementation.
568  */
569 static int custom_optopt = '?';
570
571 /*
572  * Exchange two adjacent subsequences of ARGV.  One subsequence is elements
573  * [first_nonopt,last_nonopt) which contains all the non-options that have been
574  * skipped so far.  The other is elements [last_nonopt,custom_optind), which contains
575  * all the options processed since those non-options were skipped.
576  * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
577  * indices of the non-options in ARGV after they are moved.
578  */
579 static void exchange(char **argv, struct custom_getopt_data *d)
580 {
581         int bottom = d->first_nonopt;
582         int middle = d->last_nonopt;
583         int top = d->custom_optind;
584         char *tem;
585
586         /*
587          * Exchange the shorter segment with the far end of the longer segment.
588          * That puts the shorter segment into the right place.  It leaves the
589          * longer segment in the right place overall, but it consists of two
590          * parts that need to be swapped next.
591          */
592         while (top > middle && middle > bottom) {
593                 if (top - middle > middle - bottom) {
594                         /* Bottom segment is the short one.  */
595                         int len = middle - bottom;
596                         int i;
597
598                         /* Swap it with the top part of the top segment.  */
599                         for (i = 0; i < len; i++) {
600                                 tem = argv[bottom + i];
601                                 argv[bottom + i] =
602                                         argv[top - (middle - bottom) + i];
603                                 argv[top - (middle - bottom) + i] = tem;
604                         }
605                         /* Exclude the moved bottom segment from further swapping.  */
606                         top -= len;
607                 } else {
608                         /* Top segment is the short one.  */
609                         int len = top - middle;
610                         int i;
611
612                         /* Swap it with the bottom part of the bottom segment.  */
613                         for (i = 0; i < len; i++) {
614                                 tem = argv[bottom + i];
615                                 argv[bottom + i] = argv[middle + i];
616                                 argv[middle + i] = tem;
617                         }
618                         /* Exclude the moved top segment from further swapping.  */
619                         bottom += len;
620                 }
621         }
622         /* Update records for the slots the non-options now occupy.  */
623         d->first_nonopt += (d->custom_optind - d->last_nonopt);
624         d->last_nonopt = d->custom_optind;
625 }
626
627 /* Initialize the internal data when the first call is made.  */
628 static void custom_getopt_initialize(struct custom_getopt_data *d)
629 {
630         /*
631          * Start processing options with ARGV-element 1 (since ARGV-element 0
632          * is the program name); the sequence of previously skipped non-option
633          * ARGV-elements is empty.
634          */
635         d->first_nonopt = d->last_nonopt = d->custom_optind;
636         d->nextchar = NULL;
637         d->initialized = 1;
638 }
639
640 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
641
642 /* return: zero: continue, nonzero: return given value to user */
643 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
644         struct custom_getopt_data *d)
645 {
646         /*
647          * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
648          * moved back by the user (who may also have changed the arguments).
649          */
650         if (d->last_nonopt > d->custom_optind)
651                 d->last_nonopt = d->custom_optind;
652         if (d->first_nonopt > d->custom_optind)
653                 d->first_nonopt = d->custom_optind;
654         /*
655          * If we have just processed some options following some
656          * non-options, exchange them so that the options come first.
657          */
658         if (d->first_nonopt != d->last_nonopt &&
659                         d->last_nonopt != d->custom_optind)
660                 exchange((char **) argv, d);
661         else if (d->last_nonopt != d->custom_optind)
662                 d->first_nonopt = d->custom_optind;
663         /*
664          * Skip any additional non-options and extend the range of
665          * non-options previously skipped.
666          */
667         while (d->custom_optind < argc && NONOPTION_P)
668                 d->custom_optind++;
669         d->last_nonopt = d->custom_optind;
670         /*
671          * The special ARGV-element `--' means premature end of options.  Skip
672          * it like a null option, then exchange with previous non-options as if
673          * it were an option, then skip everything else like a non-option.
674          */
675         if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
676                 d->custom_optind++;
677                 if (d->first_nonopt != d->last_nonopt
678                                 && d->last_nonopt != d->custom_optind)
679                         exchange((char **) argv, d);
680                 else if (d->first_nonopt == d->last_nonopt)
681                         d->first_nonopt = d->custom_optind;
682                 d->last_nonopt = argc;
683                 d->custom_optind = argc;
684         }
685         /*
686          * If we have done all the ARGV-elements, stop the scan and back over
687          * any non-options that we skipped and permuted.
688          */
689         if (d->custom_optind == argc) {
690                 /*
691                  * Set the next-arg-index to point at the non-options that we
692                  * previously skipped, so the caller will digest them.
693                  */
694                 if (d->first_nonopt != d->last_nonopt)
695                         d->custom_optind = d->first_nonopt;
696                 return -1;
697         }
698         /*
699          * If we have come to a non-option and did not permute it, either stop
700          * the scan or describe it to the caller and pass it by.
701          */
702         if (NONOPTION_P) {
703                 d->custom_optarg = argv[d->custom_optind++];
704                 return 1;
705         }
706         /*
707          * We have found another option-ARGV-element. Skip the initial
708          * punctuation.
709          */
710         d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
711         return 0;
712 }
713
714 /*
715  * Check whether the ARGV-element is a long option.
716  *
717  * If there's a long option "fubar" and the ARGV-element is "-fu", consider
718  * that an abbreviation of the long option, just like "--fu", and not "-f" with
719  * arg "u".
720  *
721  * This distinction seems to be the most useful approach.
722  *
723  */
724 static int check_long_opt(int argc, char *const *argv, const char *optstring,
725                 const struct option *longopts, int *longind,
726                 int print_errors, struct custom_getopt_data *d)
727 {
728         char *nameend;
729         const struct option *p;
730         const struct option *pfound = NULL;
731         int exact = 0;
732         int ambig = 0;
733         int indfound = -1;
734         int option_index;
735
736         for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
737                 /* Do nothing.  */ ;
738
739         /* Test all long options for either exact match or abbreviated matches */
740         for (p = longopts, option_index = 0; p->name; p++, option_index++)
741                 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
742                         if ((unsigned int) (nameend - d->nextchar)
743                                         == (unsigned int) strlen(p->name)) {
744                                 /* Exact match found.  */
745                                 pfound = p;
746                                 indfound = option_index;
747                                 exact = 1;
748                                 break;
749                         } else if (pfound == NULL) {
750                                 /* First nonexact match found.  */
751                                 pfound = p;
752                                 indfound = option_index;
753                         } else if (pfound->has_arg != p->has_arg
754                                         || pfound->flag != p->flag
755                                         || pfound->val != p->val)
756                                 /* Second or later nonexact match found.  */
757                                 ambig = 1;
758                 }
759         if (ambig && !exact) {
760                 if (print_errors) {
761                         fprintf(stderr,
762                                 "%s: option `%s' is ambiguous\n",
763                                 argv[0], argv[d->custom_optind]);
764                 }
765                 d->nextchar += strlen(d->nextchar);
766                 d->custom_optind++;
767                 d->custom_optopt = 0;
768                 return '?';
769         }
770         if (pfound) {
771                 option_index = indfound;
772                 d->custom_optind++;
773                 if (*nameend) {
774                         if (pfound->has_arg != no_argument)
775                                 d->custom_optarg = nameend + 1;
776                         else {
777                                 if (print_errors) {
778                                         if (argv[d->custom_optind - 1][1] == '-') {
779                                                 /* --option */
780                                                 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
781                                                         argv[0], pfound->name);
782                                         } else {
783                                                 /* +option or -option */
784                                                 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
785                                                         argv[0], argv[d->custom_optind - 1][0], pfound->name);
786                                         }
787
788                                 }
789                                 d->nextchar += strlen(d->nextchar);
790                                 d->custom_optopt = pfound->val;
791                                 return '?';
792                         }
793                 } else if (pfound->has_arg == required_argument) {
794                         if (d->custom_optind < argc)
795                                 d->custom_optarg = argv[d->custom_optind++];
796                         else {
797                                 if (print_errors) {
798                                         fprintf(stderr,
799                                                 "%s: option `%s' requires an argument\n",
800                                                 argv[0],
801                                                 argv[d->custom_optind - 1]);
802                                 }
803                                 d->nextchar += strlen(d->nextchar);
804                                 d->custom_optopt = pfound->val;
805                                 return optstring[0] == ':' ? ':' : '?';
806                         }
807                 }
808                 d->nextchar += strlen(d->nextchar);
809                 if (longind != NULL)
810                         *longind = option_index;
811                 if (pfound->flag) {
812                         *(pfound->flag) = pfound->val;
813                         return 0;
814                 }
815                 return pfound->val;
816         }
817         /*
818          * Can't find it as a long option.  If this is not getopt_long_only, or
819          * the option starts with '--' or is not a valid short option, then
820          * it's an error.  Otherwise interpret it as a short option.
821          */
822         if (print_errors) {
823                 if (argv[d->custom_optind][1] == '-') {
824                         /* --option */
825                         fprintf(stderr,
826                                 "%s: unrecognized option `--%s'\n",
827                                 argv[0], d->nextchar);
828                 } else {
829                         /* +option or -option */
830                         fprintf(stderr,
831                                 "%s: unrecognized option `%c%s'\n",
832                                 argv[0], argv[d->custom_optind][0],
833                                 d->nextchar);
834                 }
835         }
836         d->nextchar = (char *) "";
837         d->custom_optind++;
838         d->custom_optopt = 0;
839         return '?';
840 }
841
842 static int check_short_opt(int argc, char *const *argv, const char *optstring,
843                 int print_errors, struct custom_getopt_data *d)
844 {
845         char c = *d->nextchar++;
846         char *temp = strchr(optstring, c);
847
848         /* Increment `custom_optind' when we start to process its last character.  */
849         if (*d->nextchar == '\0')
850                 ++d->custom_optind;
851         if (!temp || c == ':') {
852                 if (print_errors)
853                         fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
854
855                 d->custom_optopt = c;
856                 return '?';
857         }
858         if (temp[1] == ':') {
859                 if (temp[2] == ':') {
860                         /* This is an option that accepts an argument optionally.  */
861                         if (*d->nextchar != '\0') {
862                                 d->custom_optarg = d->nextchar;
863                                 d->custom_optind++;
864                         } else
865                                 d->custom_optarg = NULL;
866                         d->nextchar = NULL;
867                 } else {
868                         /* This is an option that requires an argument.  */
869                         if (*d->nextchar != '\0') {
870                                 d->custom_optarg = d->nextchar;
871                                 /*
872                                  * If we end this ARGV-element by taking the
873                                  * rest as an arg, we must advance to the next
874                                  * element now.
875                                  */
876                                 d->custom_optind++;
877                         } else if (d->custom_optind == argc) {
878                                 if (print_errors) {
879                                         fprintf(stderr,
880                                                 "%s: option requires an argument -- %c\n",
881                                                 argv[0], c);
882                                 }
883                                 d->custom_optopt = c;
884                                 if (optstring[0] == ':')
885                                         c = ':';
886                                 else
887                                         c = '?';
888                         } else
889                                 /*
890                                  * We already incremented `custom_optind' once;
891                                  * increment it again when taking next ARGV-elt
892                                  * as argument.
893                                  */
894                                 d->custom_optarg = argv[d->custom_optind++];
895                         d->nextchar = NULL;
896                 }
897         }
898         return c;
899 }
900
901 /*
902  * Scan elements of ARGV for option characters given in OPTSTRING.
903  *
904  * If an element of ARGV starts with '-', and is not exactly "-" or "--",
905  * then it is an option element.  The characters of this element
906  * (aside from the initial '-') are option characters.  If `getopt'
907  * is called repeatedly, it returns successively each of the option characters
908  * from each of the option elements.
909  *
910  * If `getopt' finds another option character, it returns that character,
911  * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
912  * resume the scan with the following option character or ARGV-element.
913  *
914  * If there are no more option characters, `getopt' returns -1.
915  * Then `custom_optind' is the index in ARGV of the first ARGV-element
916  * that is not an option.  (The ARGV-elements have been permuted
917  * so that those that are not options now come last.)
918  *
919  * OPTSTRING is a string containing the legitimate option characters.
920  * If an option character is seen that is not listed in OPTSTRING,
921  * return '?' after printing an error message.  If you set `custom_opterr' to
922  * zero, the error message is suppressed but we still return '?'.
923  *
924  * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
925  * so the following text in the same ARGV-element, or the text of the following
926  * ARGV-element, is returned in `custom_optarg'.  Two colons mean an option that
927  * wants an optional arg; if there is text in the current ARGV-element,
928  * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
929  *
930  * If OPTSTRING starts with `-' or `+', it requests different methods of
931  * handling the non-option ARGV-elements.
932  * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
933  *
934  * Long-named options begin with `--' instead of `-'.
935  * Their names may be abbreviated as long as the abbreviation is unique
936  * or is an exact match for some defined option.  If they have an
937  * argument, it follows the option name in the same ARGV-element, separated
938  * from the option name by a `=', or else the in next ARGV-element.
939  * When `getopt' finds a long-named option, it returns 0 if that option's
940  * `flag' field is nonzero, the value of the option's `val' field
941  * if the `flag' field is zero.
942  *
943  * The elements of ARGV aren't really const, because we permute them.
944  * But we pretend they're const in the prototype to be compatible
945  * with other systems.
946  *
947  * LONGOPTS is a vector of `struct option' terminated by an
948  * element containing a name which is zero.
949  *
950  * LONGIND returns the index in LONGOPT of the long-named option found.
951  * It is only valid when a long-named option has been found by the most
952  * recent call.
953  *
954  * Return the option character from OPTS just read.  Return -1 when there are
955  * no more options.  For unrecognized options, or options missing arguments,
956  * `custom_optopt' is set to the option letter, and '?' is returned.
957  *
958  * The OPTS string is a list of characters which are recognized option letters,
959  * optionally followed by colons, specifying that that letter takes an
960  * argument, to be placed in `custom_optarg'.
961  *
962  * If a letter in OPTS is followed by two colons, its argument is optional.
963  * This behavior is specific to the GNU `getopt'.
964  *
965  * The argument `--' causes premature termination of argument scanning,
966  * explicitly telling `getopt' that there are no more options.  If OPTS begins
967  * with `--', then non-option arguments are treated as arguments to the option
968  * '\0'.  This behavior is specific to the GNU `getopt'.
969  */
970
971 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
972                 const struct option *longopts, int *longind,
973                 struct custom_getopt_data *d)
974 {
975         int ret, print_errors = d->custom_opterr;
976
977         if (optstring[0] == ':')
978                 print_errors = 0;
979         if (argc < 1)
980                 return -1;
981         d->custom_optarg = NULL;
982
983         /* 
984          * This is a big difference with GNU getopt, since optind == 0
985          * means initialization while here 1 means first call.
986          */
987         if (d->custom_optind == 0 || !d->initialized) {
988                 if (d->custom_optind == 0)
989                         d->custom_optind = 1;   /* Don't scan ARGV[0], the program name.  */
990                 custom_getopt_initialize(d);
991         }
992         if (d->nextchar == NULL || *d->nextchar == '\0') {
993                 ret = shuffle_argv(argc, argv, longopts, d);
994                 if (ret)
995                         return ret;
996         }
997         if (longopts && (argv[d->custom_optind][1] == '-' ))
998                 return check_long_opt(argc, argv, optstring, longopts,
999                         longind, print_errors, d);
1000         return check_short_opt(argc, argv, optstring, print_errors, d);
1001 }
1002
1003 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1004         const struct option *longopts, int *longind)
1005 {
1006         int result;
1007         /* Keep a global copy of all internal members of d */
1008         static struct custom_getopt_data d;
1009
1010         d.custom_optind = custom_optind;
1011         d.custom_opterr = custom_opterr;
1012         result = getopt_internal_r(argc, argv, optstring, longopts,
1013                 longind, &d);
1014         custom_optind = d.custom_optind;
1015         custom_optarg = d.custom_optarg;
1016         custom_optopt = d.custom_optopt;
1017         return result;
1018 }
1019
1020 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1021         const struct option *long_options, int *opt_index)
1022 {
1023         return custom_getopt_internal(argc, argv, options, long_options,
1024                 opt_index);
1025 }
1026
1027
1028 static char *package_name = 0;
1029
1030 /**
1031  * @brief updates an option
1032  * @param field the generic pointer to the field to update
1033  * @param orig_field the pointer to the orig field
1034  * @param field_given the pointer to the number of occurrence of this option
1035  * @param prev_given the pointer to the number of occurrence already seen
1036  * @param value the argument for this option (if null no arg was specified)
1037  * @param possible_values the possible values for this option (if specified)
1038  * @param default_value the default value (in case the option only accepts fixed values)
1039  * @param arg_type the type of this option
1040  * @param check_ambiguity @see cmdline_parser_clitkMIP_params.check_ambiguity
1041  * @param override @see cmdline_parser_clitkMIP_params.override
1042  * @param no_free whether to free a possible previous value
1043  * @param multiple_option whether this is a multiple option
1044  * @param long_opt the corresponding long option
1045  * @param short_opt the corresponding short option (or '-' if none)
1046  * @param additional_error possible further error specification
1047  */
1048 static
1049 int update_arg(void *field, char **orig_field,
1050                unsigned int *field_given, unsigned int *prev_given, 
1051                char *value, char *possible_values[], const char *default_value,
1052                cmdline_parser_clitkMIP_arg_type arg_type,
1053                int check_ambiguity, int override,
1054                int no_free, int multiple_option,
1055                const char *long_opt, char short_opt,
1056                const char *additional_error)
1057 {
1058   char *stop_char = 0;
1059   const char *val = value;
1060   int found;
1061   char **string_field;
1062
1063   stop_char = 0;
1064   found = 0;
1065
1066   if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1067     {
1068       if (short_opt != '-')
1069         fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", 
1070                package_name, long_opt, short_opt,
1071                (additional_error ? additional_error : ""));
1072       else
1073         fprintf (stderr, "%s: `--%s' option given more than once%s\n", 
1074                package_name, long_opt,
1075                (additional_error ? additional_error : ""));
1076       return 1; /* failure */
1077     }
1078
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_STRING:
1097     if (val) {
1098       string_field = (char **)field;
1099       if (!no_free && *string_field)
1100         free (*string_field); /* free previous string */
1101       *string_field = gengetopt_strdup (val);
1102     }
1103     break;
1104   default:
1105     break;
1106   };
1107
1108   /* check numeric conversion */
1109   switch(arg_type) {
1110   case ARG_INT:
1111     if (val && !(stop_char && *stop_char == '\0')) {
1112       fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1113       return 1; /* failure */
1114     }
1115     break;
1116   default:
1117     ;
1118   };
1119
1120   /* store the original value */
1121   switch(arg_type) {
1122   case ARG_NO:
1123   case ARG_FLAG:
1124     break;
1125   default:
1126     if (value && orig_field) {
1127       if (no_free) {
1128         *orig_field = value;
1129       } else {
1130         if (*orig_field)
1131           free (*orig_field); /* free previous string */
1132         *orig_field = gengetopt_strdup (value);
1133       }
1134     }
1135   };
1136
1137   return 0; /* OK */
1138 }
1139
1140
1141 int
1142 cmdline_parser_clitkMIP_internal (int argc, char * const *argv, struct args_info_clitkMIP *args_info,
1143                         struct cmdline_parser_clitkMIP_params *params, const char *additional_error)
1144 {
1145   int c;        /* Character of the parsed option.  */
1146
1147   int error = 0;
1148   struct args_info_clitkMIP local_args_info;
1149   
1150   int override;
1151   int initialize;
1152   int check_required;
1153   int check_ambiguity;
1154   
1155   package_name = argv[0];
1156   
1157   override = params->override;
1158   initialize = params->initialize;
1159   check_required = params->check_required;
1160   check_ambiguity = params->check_ambiguity;
1161
1162   if (initialize)
1163     cmdline_parser_clitkMIP_init (args_info);
1164
1165   cmdline_parser_clitkMIP_init (&local_args_info);
1166
1167   optarg = 0;
1168   optind = 0;
1169   opterr = params->print_errors;
1170   optopt = '?';
1171
1172   while (1)
1173     {
1174       int option_index = 0;
1175
1176       static struct option long_options[] = {
1177         { "help",       0, NULL, 'h' },
1178         { "version",    0, NULL, 'V' },
1179         { "config",     1, NULL, 0 },
1180         { "verbose",    0, NULL, 'v' },
1181         { "imagetypes", 0, NULL, 0 },
1182         { "input",      1, NULL, 'i' },
1183         { "output",     1, NULL, 'o' },
1184         { "dimension",  1, NULL, 'd' },
1185         { NULL, 0, NULL, 0 }
1186       };
1187
1188       custom_optarg = optarg;
1189       custom_optind = optind;
1190       custom_opterr = opterr;
1191       custom_optopt = optopt;
1192
1193       c = custom_getopt_long (argc, argv, "hVvi:o:d:", long_options, &option_index);
1194
1195       optarg = custom_optarg;
1196       optind = custom_optind;
1197       opterr = custom_opterr;
1198       optopt = custom_optopt;
1199
1200       if (c == -1) break;       /* Exit from `while (1)' loop.  */
1201
1202       switch (c)
1203         {
1204         case 'h':       /* Print help and exit.  */
1205           cmdline_parser_clitkMIP_print_help ();
1206           cmdline_parser_clitkMIP_free (&local_args_info);
1207           exit (EXIT_SUCCESS);
1208
1209         case 'V':       /* Print version and exit.  */
1210           cmdline_parser_clitkMIP_print_version ();
1211           cmdline_parser_clitkMIP_free (&local_args_info);
1212           exit (EXIT_SUCCESS);
1213
1214         case 'v':       /* Verbose.  */
1215         
1216         
1217           if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
1218               &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
1219               check_ambiguity, override, 1, 0, "verbose", 'v',
1220               additional_error))
1221             goto failure;
1222         
1223           break;
1224         case 'i':       /* Input image filename.  */
1225         
1226         
1227           if (update_arg( (void *)&(args_info->input_arg), 
1228                &(args_info->input_orig), &(args_info->input_given),
1229               &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1230               check_ambiguity, override, 0, 0,
1231               "input", 'i',
1232               additional_error))
1233             goto failure;
1234         
1235           break;
1236         case 'o':       /* Output image filename.  */
1237         
1238         
1239           if (update_arg( (void *)&(args_info->output_arg), 
1240                &(args_info->output_orig), &(args_info->output_given),
1241               &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1242               check_ambiguity, override, 0, 0,
1243               "output", 'o',
1244               additional_error))
1245             goto failure;
1246         
1247           break;
1248         case 'd':       /* Dimension along which to projetct.  */
1249         
1250         
1251           if (update_arg( (void *)&(args_info->dimension_arg), 
1252                &(args_info->dimension_orig), &(args_info->dimension_given),
1253               &(local_args_info.dimension_given), optarg, 0, 0, ARG_INT,
1254               check_ambiguity, override, 0, 0,
1255               "dimension", 'd',
1256               additional_error))
1257             goto failure;
1258         
1259           break;
1260
1261         case 0: /* Long option with no short option */
1262           /* Config file.  */
1263           if (strcmp (long_options[option_index].name, "config") == 0)
1264           {
1265           
1266           
1267             if (update_arg( (void *)&(args_info->config_arg), 
1268                  &(args_info->config_orig), &(args_info->config_given),
1269                 &(local_args_info.config_given), optarg, 0, 0, ARG_STRING,
1270                 check_ambiguity, override, 0, 0,
1271                 "config", '-',
1272                 additional_error))
1273               goto failure;
1274           
1275           }
1276           /* Display allowed image types.  */
1277           else if (strcmp (long_options[option_index].name, "imagetypes") == 0)
1278           {
1279           
1280           
1281             if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given),
1282                 &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG,
1283                 check_ambiguity, override, 1, 0, "imagetypes", '-',
1284                 additional_error))
1285               goto failure;
1286           
1287           }
1288           
1289           break;
1290         case '?':       /* Invalid option.  */
1291           /* `getopt_long' already printed an error message.  */
1292           goto failure;
1293
1294         default:        /* bug: option not considered.  */
1295           fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKMIP_PACKAGE, c, (additional_error ? additional_error : ""));
1296           abort ();
1297         } /* switch */
1298     } /* while */
1299
1300
1301
1302   if (check_required)
1303     {
1304       error += cmdline_parser_clitkMIP_required2 (args_info, argv[0], additional_error);
1305     }
1306
1307   cmdline_parser_clitkMIP_release (&local_args_info);
1308
1309   if ( error )
1310     return (EXIT_FAILURE);
1311
1312   if (optind < argc)
1313     {
1314       int i = 0 ;
1315       int found_prog_name = 0;
1316       /* whether program name, i.e., argv[0], is in the remaining args
1317          (this may happen with some implementations of getopt,
1318           but surely not with the one included by gengetopt) */
1319
1320
1321       args_info->inputs_num = argc - optind - found_prog_name;
1322       args_info->inputs =
1323         (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1324       while (optind < argc)
1325         args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1326     }
1327
1328   return 0;
1329
1330 failure:
1331   
1332   cmdline_parser_clitkMIP_release (&local_args_info);
1333   return (EXIT_FAILURE);
1334 }
1335
1336 #ifndef CONFIG_FILE_LINE_SIZE
1337 #define CONFIG_FILE_LINE_SIZE 2048
1338 #endif
1339 #define ADDITIONAL_ERROR " in configuration file "
1340
1341 #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1342 /* 3 is for "--" and "=" */
1343
1344 static int
1345 _cmdline_parser_clitkMIP_configfile (char * const filename, int *my_argc)
1346 {
1347   FILE* file;
1348   char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
1349   char linebuf[CONFIG_FILE_LINE_SIZE];
1350   int line_num = 0;
1351   int result = 0, equal;
1352   char *fopt, *farg;
1353   char *str_index;
1354   size_t len, next_token;
1355   char delimiter;
1356
1357   if ((file = fopen(filename, "r")) == NULL)
1358     {
1359       fprintf (stderr, "%s: Error opening configuration file '%s'\n",
1360                CMDLINE_PARSER_CLITKMIP_PACKAGE, filename);
1361       return EXIT_FAILURE;
1362     }
1363
1364   while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
1365     {
1366       ++line_num;
1367       my_argv[0] = '\0';
1368       len = strlen(linebuf);
1369       if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
1370         {
1371           fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
1372                    CMDLINE_PARSER_CLITKMIP_PACKAGE, filename, line_num);
1373           result = EXIT_FAILURE;
1374           break;
1375         }
1376
1377       /* find first non-whitespace character in the line */
1378       next_token = strspn (linebuf, " \t\r\n");
1379       str_index  = linebuf + next_token;
1380
1381       if ( str_index[0] == '\0' || str_index[0] == '#')
1382         continue; /* empty line or comment line is skipped */
1383
1384       fopt = str_index;
1385
1386       /* truncate fopt at the end of the first non-valid character */
1387       next_token = strcspn (fopt, " \t\r\n=");
1388
1389       if (fopt[next_token] == '\0') /* the line is over */
1390         {
1391           farg  = NULL;
1392           equal = 0;
1393           goto noarg;
1394         }
1395
1396       /* remember if equal sign is present */
1397       equal = (fopt[next_token] == '=');
1398       fopt[next_token++] = '\0';
1399
1400       /* advance pointers to the next token after the end of fopt */
1401       next_token += strspn (fopt + next_token, " \t\r\n");
1402
1403       /* check for the presence of equal sign, and if so, skip it */
1404       if ( !equal )
1405         if ((equal = (fopt[next_token] == '=')))
1406           {
1407             next_token++;
1408             next_token += strspn (fopt + next_token, " \t\r\n");
1409           }
1410       str_index  += next_token;
1411
1412       /* find argument */
1413       farg = str_index;
1414       if ( farg[0] == '\"' || farg[0] == '\'' )
1415         { /* quoted argument */
1416           str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
1417           if (! str_index)
1418             {
1419               fprintf
1420                 (stderr,
1421                  "%s:%s:%d: unterminated string in configuration file\n",
1422                  CMDLINE_PARSER_CLITKMIP_PACKAGE, filename, line_num);
1423               result = EXIT_FAILURE;
1424               break;
1425             }
1426         }
1427       else
1428         { /* read up the remaining part up to a delimiter */
1429           next_token = strcspn (farg, " \t\r\n#\'\"");
1430           str_index += next_token;
1431         }
1432
1433       /* truncate farg at the delimiter and store it for further check */
1434       delimiter = *str_index, *str_index++ = '\0';
1435
1436       /* everything but comment is illegal at the end of line */
1437       if (delimiter != '\0' && delimiter != '#')
1438         {
1439           str_index += strspn(str_index, " \t\r\n");
1440           if (*str_index != '\0' && *str_index != '#')
1441             {
1442               fprintf
1443                 (stderr,
1444                  "%s:%s:%d: malformed string in configuration file\n",
1445                  CMDLINE_PARSER_CLITKMIP_PACKAGE, filename, line_num);
1446               result = EXIT_FAILURE;
1447               break;
1448             }
1449         }
1450
1451     noarg:
1452       if (!strcmp(fopt,"include")) {
1453         if (farg && *farg) {
1454           result = _cmdline_parser_clitkMIP_configfile(farg, my_argc);
1455         } else {
1456           fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n",
1457                   CMDLINE_PARSER_CLITKMIP_PACKAGE, filename, line_num);
1458         }
1459         continue;
1460       }
1461       len = strlen(fopt);
1462       strcat (my_argv, len > 1 ? "--" : "-");
1463       strcat (my_argv, fopt);
1464       if (len > 1 && ((farg && *farg) || equal))
1465         strcat (my_argv, "=");
1466       if (farg && *farg)
1467         strcat (my_argv, farg);
1468       ++(*my_argc);
1469
1470       cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1471       cmd_line_list_tmp->next = cmd_line_list;
1472       cmd_line_list = cmd_line_list_tmp;
1473       cmd_line_list->string_arg = gengetopt_strdup(my_argv);
1474     } /* while */
1475
1476   if (file)
1477     fclose(file);
1478   return result;
1479 }
1480
1481 int
1482 cmdline_parser_clitkMIP_configfile (char * const filename,
1483                            struct args_info_clitkMIP *args_info,
1484                            int override, int initialize, int check_required)
1485 {
1486   struct cmdline_parser_clitkMIP_params params;
1487
1488   params.override = override;
1489   params.initialize = initialize;
1490   params.check_required = check_required;
1491   params.check_ambiguity = 0;
1492   params.print_errors = 1;
1493   
1494   return cmdline_parser_clitkMIP_config_file (filename, args_info, &params);
1495 }
1496
1497 int
1498 cmdline_parser_clitkMIP_config_file (char * const filename,
1499                            struct args_info_clitkMIP *args_info,
1500                            struct cmdline_parser_clitkMIP_params *params)
1501 {
1502   int i, result;
1503   int my_argc = 1;
1504   char **my_argv_arg;
1505   char *additional_error;
1506
1507   /* store the program name */
1508   cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1509   cmd_line_list_tmp->next = cmd_line_list;
1510   cmd_line_list = cmd_line_list_tmp;
1511   cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKMIP_PACKAGE);
1512
1513   result = _cmdline_parser_clitkMIP_configfile(filename, &my_argc);
1514
1515   if (result != EXIT_FAILURE) {
1516     my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
1517     cmd_line_list_tmp = cmd_line_list;
1518
1519     for (i = my_argc - 1; i >= 0; --i) {
1520       my_argv_arg[i] = cmd_line_list_tmp->string_arg;
1521       cmd_line_list_tmp = cmd_line_list_tmp->next;
1522     }
1523
1524     my_argv_arg[my_argc] = 0;
1525
1526     additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
1527     strcpy (additional_error, ADDITIONAL_ERROR);
1528     strcat (additional_error, filename);
1529     result =
1530       cmdline_parser_clitkMIP_internal (my_argc, my_argv_arg, args_info,
1531                               params,
1532                               additional_error);
1533
1534     free (additional_error);
1535     free (my_argv_arg);
1536   }
1537
1538   free_cmd_list();
1539   if (result == EXIT_FAILURE)
1540     {
1541       cmdline_parser_clitkMIP_free (args_info);
1542       exit (EXIT_FAILURE);
1543     }
1544   
1545   return result;
1546 }