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
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.
11 /* If we use autoconf. */
21 #include "clitkImageArithm_ggo.h"
23 const char *args_info_clitkImageArithm_purpose = "Perform an arithmetic operation (+-*/ ...) using two images or using an image \nand a scalar value.";
25 const char *args_info_clitkImageArithm_usage = "Usage: clitkImageArithm [OPTIONS]... [FILES]...";
27 const char *args_info_clitkImageArithm_description = "";
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)",
50 } cmdline_parser_clitkImageArithm_arg_type;
53 void clear_given (struct args_info_clitkImageArithm *args_info);
55 void clear_args (struct args_info_clitkImageArithm *args_info);
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);
62 cmdline_parser_clitkImageArithm_required2 (struct args_info_clitkImageArithm *args_info, const char *prog_name, const char *additional_error);
66 struct line_list * next;
69 static struct line_list *cmd_line_list = 0;
70 static struct line_list *cmd_line_list_tmp = 0;
75 /* free the list of a previous call */
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);
89 gengetopt_strdup (const char *s);
92 void clear_given (struct args_info_clitkImageArithm *args_info)
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 ;
109 void clear_args (struct args_info_clitkImageArithm *args_info)
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;
131 void init_args_info(struct args_info_clitkImageArithm *args_info)
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] ;
151 cmdline_parser_clitkImageArithm_print_version (void)
153 printf ("%s %s\n", CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, CMDLINE_PARSER_CLITKIMAGEARITHM_VERSION);
156 static void print_help_common(void) {
157 cmdline_parser_clitkImageArithm_print_version ();
159 if (strlen(args_info_clitkImageArithm_purpose) > 0)
160 printf("\n%s\n", args_info_clitkImageArithm_purpose);
162 if (strlen(args_info_clitkImageArithm_usage) > 0)
163 printf("\n%s\n", args_info_clitkImageArithm_usage);
167 if (strlen(args_info_clitkImageArithm_description) > 0)
168 printf("%s\n", args_info_clitkImageArithm_description);
172 cmdline_parser_clitkImageArithm_print_help (void)
176 while (args_info_clitkImageArithm_help[i])
177 printf("%s\n", args_info_clitkImageArithm_help[i++]);
181 cmdline_parser_clitkImageArithm_init (struct args_info_clitkImageArithm *args_info)
183 clear_given (args_info);
184 clear_args (args_info);
185 init_args_info (args_info);
187 args_info->inputs = NULL;
188 args_info->inputs_num = 0;
192 cmdline_parser_clitkImageArithm_params_init(struct cmdline_parser_clitkImageArithm_params *params)
196 params->override = 0;
197 params->initialize = 1;
198 params->check_required = 1;
199 params->check_ambiguity = 0;
200 params->print_errors = 1;
204 struct cmdline_parser_clitkImageArithm_params *
205 cmdline_parser_clitkImageArithm_params_create(void)
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);
214 free_string_field (char **s)
225 cmdline_parser_clitkImageArithm_release (struct args_info_clitkImageArithm *args_info)
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));
241 for (i = 0; i < args_info->inputs_num; ++i)
242 free (args_info->inputs [i]);
244 if (args_info->inputs_num)
245 free (args_info->inputs);
247 clear_given (args_info);
252 write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
255 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
257 fprintf(outfile, "%s\n", opt);
263 cmdline_parser_clitkImageArithm_dump(FILE *outfile, struct args_info_clitkImageArithm *args_info)
269 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE);
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 );
304 cmdline_parser_clitkImageArithm_file_save(const char *filename, struct args_info_clitkImageArithm *args_info)
309 outfile = fopen(filename, "w");
313 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename);
317 i = cmdline_parser_clitkImageArithm_dump(outfile, args_info);
324 cmdline_parser_clitkImageArithm_free (struct args_info_clitkImageArithm *args_info)
326 cmdline_parser_clitkImageArithm_release (args_info);
329 /** @brief replacement of strdup, which is not standard */
331 gengetopt_strdup (const char *s)
337 result = (char*)malloc(strlen(s) + 1);
338 if (result == (char*)0)
345 cmdline_parser_clitkImageArithm (int argc, char * const *argv, struct args_info_clitkImageArithm *args_info)
347 return cmdline_parser_clitkImageArithm2 (argc, argv, args_info, 0, 1, 1);
351 cmdline_parser_clitkImageArithm_ext (int argc, char * const *argv, struct args_info_clitkImageArithm *args_info,
352 struct cmdline_parser_clitkImageArithm_params *params)
355 result = cmdline_parser_clitkImageArithm_internal (argc, argv, args_info, params, NULL);
357 if (result == EXIT_FAILURE)
359 cmdline_parser_clitkImageArithm_free (args_info);
367 cmdline_parser_clitkImageArithm2 (int argc, char * const *argv, struct args_info_clitkImageArithm *args_info, int override, int initialize, int check_required)
370 struct cmdline_parser_clitkImageArithm_params params;
372 params.override = override;
373 params.initialize = initialize;
374 params.check_required = check_required;
375 params.check_ambiguity = 0;
376 params.print_errors = 1;
378 result = cmdline_parser_clitkImageArithm_internal (argc, argv, args_info, ¶ms, NULL);
380 if (result == EXIT_FAILURE)
382 cmdline_parser_clitkImageArithm_free (args_info);
390 cmdline_parser_clitkImageArithm_required (struct args_info_clitkImageArithm *args_info, const char *prog_name)
392 int result = EXIT_SUCCESS;
394 if (cmdline_parser_clitkImageArithm_required2(args_info, prog_name, NULL) > 0)
395 result = EXIT_FAILURE;
397 if (result == EXIT_FAILURE)
399 cmdline_parser_clitkImageArithm_free (args_info);
407 cmdline_parser_clitkImageArithm_required2 (struct args_info_clitkImageArithm *args_info, const char *prog_name, const char *additional_error)
411 /* checks for required options */
412 if (! args_info->input1_given)
414 fprintf (stderr, "%s: '--input1' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
418 if (! args_info->output_given)
420 fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
425 /* checks for dependences among options */
431 * Extracted from the glibc source tree, version 2.3.6
433 * Licensed under the GPL as per the whole glibc source tree.
435 * This file was modified so that getopt_long can be called
436 * many times without risking previous memory to be spoiled.
438 * Modified by Andre Noll and Lorenzo Bettini for use in
439 * GNU gengetopt generated files.
444 * we must include anything we need since this file is not thought to be
445 * inserted in a file already using getopt.h
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. */
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. */
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'.
472 On entry to `getopt', zero means this is the first call; initialize.
474 When `getopt' returns -1, this is the index of the first of the
475 non-option elements that the caller should itself scan.
477 Otherwise, `optind' communicates from one call to the next
478 how much of ARGV has been scanned so far. */
482 /* Callers store zero here to inhibit the error message `getopt' prints
483 for unrecognized options. */
487 /* Set to an option character which was unrecognized. */
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.
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.
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.
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. */
511 /* Names for the values of the `has_arg' field of `struct option'. */
513 #define no_argument 0
516 #ifndef required_argument
517 #define required_argument 1
520 #ifndef optional_argument
521 #define optional_argument 2
524 struct custom_getopt_data {
526 * These have exactly the same meaning as the corresponding global variables,
527 * except that they are used for the reentrant versions of getopt.
534 /* True if the internal members have been initialized. */
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.
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.
555 * the variables optarg, optind, opterr and optopt are renamed with
556 * the custom_ prefix so that they don't interfere with getopt ones.
558 * Moreover they're static so they are visible only from within the
559 * file where this very file will be included.
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.
566 static char *custom_optarg;
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'.
573 * On entry to `custom_getopt', 1 means this is the first call; initialize.
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.
578 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
579 * has been scanned so far.
581 * 1003.2 says this must be 1 before any call.
583 static int custom_optind = 1;
586 * Callers store zero here to inhibit the error message for unrecognized
589 static int custom_opterr = 1;
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.
595 static int custom_optopt = '?';
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.
605 static void exchange(char **argv, struct custom_getopt_data *d)
607 int bottom = d->first_nonopt;
608 int middle = d->last_nonopt;
609 int top = d->custom_optind;
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.
618 while (top > middle && middle > bottom) {
619 if (top - middle > middle - bottom) {
620 /* Bottom segment is the short one. */
621 int len = middle - bottom;
624 /* Swap it with the top part of the top segment. */
625 for (i = 0; i < len; i++) {
626 tem = argv[bottom + i];
628 argv[top - (middle - bottom) + i];
629 argv[top - (middle - bottom) + i] = tem;
631 /* Exclude the moved bottom segment from further swapping. */
634 /* Top segment is the short one. */
635 int len = top - middle;
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;
644 /* Exclude the moved top segment from further swapping. */
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;
653 /* Initialize the internal data when the first call is made. */
654 static void custom_getopt_initialize(struct custom_getopt_data *d)
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.
661 d->first_nonopt = d->last_nonopt = d->custom_optind;
666 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
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)
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).
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;
681 * If we have just processed some options following some
682 * non-options, exchange them so that the options come first.
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;
690 * Skip any additional non-options and extend the range of
691 * non-options previously skipped.
693 while (d->custom_optind < argc && NONOPTION_P)
695 d->last_nonopt = d->custom_optind;
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.
701 if (d->custom_optind != argc && !strcmp(argv[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;
712 * If we have done all the ARGV-elements, stop the scan and back over
713 * any non-options that we skipped and permuted.
715 if (d->custom_optind == argc) {
717 * Set the next-arg-index to point at the non-options that we
718 * previously skipped, so the caller will digest them.
720 if (d->first_nonopt != d->last_nonopt)
721 d->custom_optind = d->first_nonopt;
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.
729 d->custom_optarg = argv[d->custom_optind++];
733 * We have found another option-ARGV-element. Skip the initial
736 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
741 * Check whether the ARGV-element is a long option.
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
747 * This distinction seems to be the most useful approach.
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)
755 const struct option *p;
756 const struct option *pfound = NULL;
762 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
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. */
772 indfound = option_index;
775 } else if (pfound == NULL) {
776 /* First nonexact match found. */
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. */
785 if (ambig && !exact) {
788 "%s: option `%s' is ambiguous\n",
789 argv[0], argv[d->custom_optind]);
791 d->nextchar += strlen(d->nextchar);
793 d->custom_optopt = 0;
797 option_index = indfound;
800 if (pfound->has_arg != no_argument)
801 d->custom_optarg = nameend + 1;
804 if (argv[d->custom_optind - 1][1] == '-') {
806 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
807 argv[0], pfound->name);
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);
815 d->nextchar += strlen(d->nextchar);
816 d->custom_optopt = pfound->val;
819 } else if (pfound->has_arg == required_argument) {
820 if (d->custom_optind < argc)
821 d->custom_optarg = argv[d->custom_optind++];
825 "%s: option `%s' requires an argument\n",
827 argv[d->custom_optind - 1]);
829 d->nextchar += strlen(d->nextchar);
830 d->custom_optopt = pfound->val;
831 return optstring[0] == ':' ? ':' : '?';
834 d->nextchar += strlen(d->nextchar);
836 *longind = option_index;
838 *(pfound->flag) = pfound->val;
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.
849 if (argv[d->custom_optind][1] == '-') {
852 "%s: unrecognized option `--%s'\n",
853 argv[0], d->nextchar);
855 /* +option or -option */
857 "%s: unrecognized option `%c%s'\n",
858 argv[0], argv[d->custom_optind][0],
862 d->nextchar = (char *) "";
864 d->custom_optopt = 0;
868 static int check_short_opt(int argc, char *const *argv, const char *optstring,
869 int print_errors, struct custom_getopt_data *d)
871 char c = *d->nextchar++;
872 char *temp = strchr(optstring, c);
874 /* Increment `custom_optind' when we start to process its last character. */
875 if (*d->nextchar == '\0')
877 if (!temp || c == ':') {
879 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
881 d->custom_optopt = c;
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;
891 d->custom_optarg = NULL;
894 /* This is an option that requires an argument. */
895 if (*d->nextchar != '\0') {
896 d->custom_optarg = d->nextchar;
898 * If we end this ARGV-element by taking the
899 * rest as an arg, we must advance to the next
903 } else if (d->custom_optind == argc) {
906 "%s: option requires an argument -- %c\n",
909 d->custom_optopt = c;
910 if (optstring[0] == ':')
916 * We already incremented `custom_optind' once;
917 * increment it again when taking next ARGV-elt
920 d->custom_optarg = argv[d->custom_optind++];
928 * Scan elements of ARGV for option characters given in OPTSTRING.
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.
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.
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.)
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 '?'.
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.
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.
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.
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.
973 * LONGOPTS is a vector of `struct option' terminated by an
974 * element containing a name which is zero.
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
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.
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'.
988 * If a letter in OPTS is followed by two colons, its argument is optional.
989 * This behavior is specific to the GNU `getopt'.
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'.
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)
1001 int ret, print_errors = d->custom_opterr;
1003 if (optstring[0] == ':')
1007 d->custom_optarg = NULL;
1010 * This is a big difference with GNU getopt, since optind == 0
1011 * means initialization while here 1 means first call.
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);
1018 if (d->nextchar == NULL || *d->nextchar == '\0') {
1019 ret = shuffle_argv(argc, argv, longopts, d);
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);
1029 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1030 const struct option *longopts, int *longind)
1033 /* Keep a global copy of all internal members of d */
1034 static struct custom_getopt_data d;
1036 d.custom_optind = custom_optind;
1037 d.custom_opterr = custom_opterr;
1038 result = getopt_internal_r(argc, argv, optstring, longopts,
1040 custom_optind = d.custom_optind;
1041 custom_optarg = d.custom_optarg;
1042 custom_optopt = d.custom_optopt;
1046 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1047 const struct option *long_options, int *opt_index)
1049 return custom_getopt_internal(argc, argv, options, long_options,
1054 static char *package_name = 0;
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
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)
1084 char *stop_char = 0;
1085 const char *val = value;
1087 char **string_field;
1092 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
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 : ""));
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 */
1106 if (field_given && *field_given && ! override)
1112 if (possible_values)
1113 val = possible_values[found];
1117 *((int *)field) = !*((int *)field);
1120 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1123 if (val) *((double *)field) = strtod (val, &stop_char);
1127 string_field = (char **)field;
1128 if (!no_free && *string_field)
1129 free (*string_field); /* free previous string */
1130 *string_field = gengetopt_strdup (val);
1137 /* check numeric conversion */
1141 if (val && !(stop_char && *stop_char == '\0')) {
1142 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1143 return 1; /* failure */
1150 /* store the original value */
1156 if (value && orig_field) {
1158 *orig_field = value;
1161 free (*orig_field); /* free previous string */
1162 *orig_field = gengetopt_strdup (value);
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)
1175 int c; /* Character of the parsed option. */
1178 struct args_info_clitkImageArithm local_args_info;
1183 int check_ambiguity;
1185 package_name = argv[0];
1187 override = params->override;
1188 initialize = params->initialize;
1189 check_required = params->check_required;
1190 check_ambiguity = params->check_ambiguity;
1193 cmdline_parser_clitkImageArithm_init (args_info);
1195 cmdline_parser_clitkImageArithm_init (&local_args_info);
1199 opterr = params->print_errors;
1204 int option_index = 0;
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 }
1222 custom_optarg = optarg;
1223 custom_optind = optind;
1224 custom_opterr = opterr;
1225 custom_optopt = optopt;
1227 c = custom_getopt_long (argc, argv, "hVvi:j:o:s:t:f", long_options, &option_index);
1229 optarg = custom_optarg;
1230 optind = custom_optind;
1231 opterr = custom_opterr;
1232 optopt = custom_optopt;
1234 if (c == -1) break; /* Exit from `while (1)' loop. */
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);
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);
1248 case 'v': /* Verbose. */
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',
1258 case 'i': /* Input first image filename. */
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,
1270 case 'j': /* Input second image filename. */
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,
1282 case 'o': /* Output image filename. */
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,
1294 case 's': /* Scalar value. */
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,
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. */
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,
1318 case 'f': /* Set output to float pixel type. */
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',
1329 case 0: /* Long option with no short option */
1331 if (strcmp (long_options[option_index].name, "config") == 0)
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,
1344 /* Display allowed image types. */
1345 else if (strcmp (long_options[option_index].name, "imagetypes") == 0)
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", '-',
1356 /* Default value for NaN/Inf. */
1357 else if (strcmp (long_options[option_index].name, "pixelValue") == 0)
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,
1372 case '?': /* Invalid option. */
1373 /* `getopt_long' already printed an error message. */
1376 default: /* bug: option not considered. */
1377 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, c, (additional_error ? additional_error : ""));
1386 error += cmdline_parser_clitkImageArithm_required2 (args_info, argv[0], additional_error);
1389 cmdline_parser_clitkImageArithm_release (&local_args_info);
1392 return (EXIT_FAILURE);
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) */
1403 args_info->inputs_num = argc - optind - found_prog_name;
1405 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1406 while (optind < argc)
1407 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1414 cmdline_parser_clitkImageArithm_release (&local_args_info);
1415 return (EXIT_FAILURE);
1418 #ifndef CONFIG_FILE_LINE_SIZE
1419 #define CONFIG_FILE_LINE_SIZE 2048
1421 #define ADDITIONAL_ERROR " in configuration file "
1423 #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1424 /* 3 is for "--" and "=" */
1427 _cmdline_parser_clitkImageArithm_configfile (char * const filename, int *my_argc)
1430 char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
1431 char linebuf[CONFIG_FILE_LINE_SIZE];
1433 int result = 0, equal;
1436 size_t len, next_token;
1439 if ((file = fopen(filename, "r")) == NULL)
1441 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
1442 CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename);
1443 return EXIT_FAILURE;
1446 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
1450 len = strlen(linebuf);
1451 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
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;
1459 /* find first non-whitespace character in the line */
1460 next_token = strspn (linebuf, " \t\r\n");
1461 str_index = linebuf + next_token;
1463 if ( str_index[0] == '\0' || str_index[0] == '#')
1464 continue; /* empty line or comment line is skipped */
1468 /* truncate fopt at the end of the first non-valid character */
1469 next_token = strcspn (fopt, " \t\r\n=");
1471 if (fopt[next_token] == '\0') /* the line is over */
1478 /* remember if equal sign is present */
1479 equal = (fopt[next_token] == '=');
1480 fopt[next_token++] = '\0';
1482 /* advance pointers to the next token after the end of fopt */
1483 next_token += strspn (fopt + next_token, " \t\r\n");
1485 /* check for the presence of equal sign, and if so, skip it */
1487 if ((equal = (fopt[next_token] == '=')))
1490 next_token += strspn (fopt + next_token, " \t\r\n");
1492 str_index += next_token;
1496 if ( farg[0] == '\"' || farg[0] == '\'' )
1497 { /* quoted argument */
1498 str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
1503 "%s:%s:%d: unterminated string in configuration file\n",
1504 CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename, line_num);
1505 result = EXIT_FAILURE;
1510 { /* read up the remaining part up to a delimiter */
1511 next_token = strcspn (farg, " \t\r\n#\'\"");
1512 str_index += next_token;
1515 /* truncate farg at the delimiter and store it for further check */
1516 delimiter = *str_index, *str_index++ = '\0';
1518 /* everything but comment is illegal at the end of line */
1519 if (delimiter != '\0' && delimiter != '#')
1521 str_index += strspn(str_index, " \t\r\n");
1522 if (*str_index != '\0' && *str_index != '#')
1526 "%s:%s:%d: malformed string in configuration file\n",
1527 CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename, line_num);
1528 result = EXIT_FAILURE;
1534 if (!strcmp(fopt,"include")) {
1535 if (farg && *farg) {
1536 result = _cmdline_parser_clitkImageArithm_configfile(farg, my_argc);
1538 fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n",
1539 CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename, line_num);
1544 strcat (my_argv, len > 1 ? "--" : "-");
1545 strcat (my_argv, fopt);
1546 if (len > 1 && ((farg && *farg) || equal))
1547 strcat (my_argv, "=");
1549 strcat (my_argv, farg);
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);
1564 cmdline_parser_clitkImageArithm_configfile (char * const filename,
1565 struct args_info_clitkImageArithm *args_info,
1566 int override, int initialize, int check_required)
1568 struct cmdline_parser_clitkImageArithm_params params;
1570 params.override = override;
1571 params.initialize = initialize;
1572 params.check_required = check_required;
1573 params.check_ambiguity = 0;
1574 params.print_errors = 1;
1576 return cmdline_parser_clitkImageArithm_config_file (filename, args_info, ¶ms);
1580 cmdline_parser_clitkImageArithm_config_file (char * const filename,
1581 struct args_info_clitkImageArithm *args_info,
1582 struct cmdline_parser_clitkImageArithm_params *params)
1587 char *additional_error;
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);
1595 result = _cmdline_parser_clitkImageArithm_configfile(filename, &my_argc);
1597 if (result != EXIT_FAILURE) {
1598 my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
1599 cmd_line_list_tmp = cmd_line_list;
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;
1606 my_argv_arg[my_argc] = 0;
1608 additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
1609 strcpy (additional_error, ADDITIONAL_ERROR);
1610 strcat (additional_error, filename);
1612 cmdline_parser_clitkImageArithm_internal (my_argc, my_argv_arg, args_info,
1616 free (additional_error);
1621 if (result == EXIT_FAILURE)
1623 cmdline_parser_clitkImageArithm_free (args_info);
1624 exit (EXIT_FAILURE);