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