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/segmentation --arg-struct-name=args_info_clitkConnectedComponentLabeling --func-name=cmdline_parser_clitkConnectedComponentLabeling --file-name=clitkConnectedComponentLabeling_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 "clitkConnectedComponentLabeling_ggo.h"
23 const char *args_info_clitkConnectedComponentLabeling_purpose = "Basic segmentation : connected component labeling ";
25 const char *args_info_clitkConnectedComponentLabeling_usage = "Usage: clitkConnectedComponentLabeling [OPTIONS]... [FILES]...";
27 const char *args_info_clitkConnectedComponentLabeling_description = "";
29 const char *args_info_clitkConnectedComponentLabeling_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 " --verboseOption Display options values (default=off)",
37 " -i, --input=STRING Input image filename",
38 " --inputBG=INT Input Background (default=`0')",
39 " -o, --output=STRING Output filename",
41 " --minSize=INT Minimum component size in voxels (default=`100')",
42 " --full Full connecticity (default=off)",
50 } cmdline_parser_clitkConnectedComponentLabeling_arg_type;
53 void clear_given (struct args_info_clitkConnectedComponentLabeling *args_info);
55 void clear_args (struct args_info_clitkConnectedComponentLabeling *args_info);
58 cmdline_parser_clitkConnectedComponentLabeling_internal (int argc, char * const *argv, struct args_info_clitkConnectedComponentLabeling *args_info,
59 struct cmdline_parser_clitkConnectedComponentLabeling_params *params, const char *additional_error);
62 cmdline_parser_clitkConnectedComponentLabeling_required2 (struct args_info_clitkConnectedComponentLabeling *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_clitkConnectedComponentLabeling *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->verboseOption_given = 0 ;
100 args_info->input_given = 0 ;
101 args_info->inputBG_given = 0 ;
102 args_info->output_given = 0 ;
103 args_info->minSize_given = 0 ;
104 args_info->full_given = 0 ;
108 void clear_args (struct args_info_clitkConnectedComponentLabeling *args_info)
110 args_info->config_arg = NULL;
111 args_info->config_orig = NULL;
112 args_info->verbose_flag = 0;
113 args_info->imagetypes_flag = 0;
114 args_info->verboseOption_flag = 0;
115 args_info->input_arg = NULL;
116 args_info->input_orig = NULL;
117 args_info->inputBG_arg = 0;
118 args_info->inputBG_orig = NULL;
119 args_info->output_arg = NULL;
120 args_info->output_orig = NULL;
121 args_info->minSize_arg = 100;
122 args_info->minSize_orig = NULL;
123 args_info->full_flag = 0;
128 void init_args_info(struct args_info_clitkConnectedComponentLabeling *args_info)
132 args_info->help_help = args_info_clitkConnectedComponentLabeling_help[0] ;
133 args_info->version_help = args_info_clitkConnectedComponentLabeling_help[1] ;
134 args_info->config_help = args_info_clitkConnectedComponentLabeling_help[2] ;
135 args_info->verbose_help = args_info_clitkConnectedComponentLabeling_help[3] ;
136 args_info->imagetypes_help = args_info_clitkConnectedComponentLabeling_help[4] ;
137 args_info->verboseOption_help = args_info_clitkConnectedComponentLabeling_help[5] ;
138 args_info->input_help = args_info_clitkConnectedComponentLabeling_help[7] ;
139 args_info->inputBG_help = args_info_clitkConnectedComponentLabeling_help[8] ;
140 args_info->output_help = args_info_clitkConnectedComponentLabeling_help[9] ;
141 args_info->minSize_help = args_info_clitkConnectedComponentLabeling_help[11] ;
142 args_info->full_help = args_info_clitkConnectedComponentLabeling_help[12] ;
147 cmdline_parser_clitkConnectedComponentLabeling_print_version (void)
149 printf ("%s %s\n", CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_VERSION);
152 static void print_help_common(void) {
153 cmdline_parser_clitkConnectedComponentLabeling_print_version ();
155 if (strlen(args_info_clitkConnectedComponentLabeling_purpose) > 0)
156 printf("\n%s\n", args_info_clitkConnectedComponentLabeling_purpose);
158 if (strlen(args_info_clitkConnectedComponentLabeling_usage) > 0)
159 printf("\n%s\n", args_info_clitkConnectedComponentLabeling_usage);
163 if (strlen(args_info_clitkConnectedComponentLabeling_description) > 0)
164 printf("%s\n", args_info_clitkConnectedComponentLabeling_description);
168 cmdline_parser_clitkConnectedComponentLabeling_print_help (void)
172 while (args_info_clitkConnectedComponentLabeling_help[i])
173 printf("%s\n", args_info_clitkConnectedComponentLabeling_help[i++]);
177 cmdline_parser_clitkConnectedComponentLabeling_init (struct args_info_clitkConnectedComponentLabeling *args_info)
179 clear_given (args_info);
180 clear_args (args_info);
181 init_args_info (args_info);
183 args_info->inputs = NULL;
184 args_info->inputs_num = 0;
188 cmdline_parser_clitkConnectedComponentLabeling_params_init(struct cmdline_parser_clitkConnectedComponentLabeling_params *params)
192 params->override = 0;
193 params->initialize = 1;
194 params->check_required = 1;
195 params->check_ambiguity = 0;
196 params->print_errors = 1;
200 struct cmdline_parser_clitkConnectedComponentLabeling_params *
201 cmdline_parser_clitkConnectedComponentLabeling_params_create(void)
203 struct cmdline_parser_clitkConnectedComponentLabeling_params *params =
204 (struct cmdline_parser_clitkConnectedComponentLabeling_params *)malloc(sizeof(struct cmdline_parser_clitkConnectedComponentLabeling_params));
205 cmdline_parser_clitkConnectedComponentLabeling_params_init(params);
210 free_string_field (char **s)
221 cmdline_parser_clitkConnectedComponentLabeling_release (struct args_info_clitkConnectedComponentLabeling *args_info)
224 free_string_field (&(args_info->config_arg));
225 free_string_field (&(args_info->config_orig));
226 free_string_field (&(args_info->input_arg));
227 free_string_field (&(args_info->input_orig));
228 free_string_field (&(args_info->inputBG_orig));
229 free_string_field (&(args_info->output_arg));
230 free_string_field (&(args_info->output_orig));
231 free_string_field (&(args_info->minSize_orig));
234 for (i = 0; i < args_info->inputs_num; ++i)
235 free (args_info->inputs [i]);
237 if (args_info->inputs_num)
238 free (args_info->inputs);
240 clear_given (args_info);
245 write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
248 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
250 fprintf(outfile, "%s\n", opt);
256 cmdline_parser_clitkConnectedComponentLabeling_dump(FILE *outfile, struct args_info_clitkConnectedComponentLabeling *args_info)
262 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE);
266 if (args_info->help_given)
267 write_into_file(outfile, "help", 0, 0 );
268 if (args_info->version_given)
269 write_into_file(outfile, "version", 0, 0 );
270 if (args_info->config_given)
271 write_into_file(outfile, "config", args_info->config_orig, 0);
272 if (args_info->verbose_given)
273 write_into_file(outfile, "verbose", 0, 0 );
274 if (args_info->imagetypes_given)
275 write_into_file(outfile, "imagetypes", 0, 0 );
276 if (args_info->verboseOption_given)
277 write_into_file(outfile, "verboseOption", 0, 0 );
278 if (args_info->input_given)
279 write_into_file(outfile, "input", args_info->input_orig, 0);
280 if (args_info->inputBG_given)
281 write_into_file(outfile, "inputBG", args_info->inputBG_orig, 0);
282 if (args_info->output_given)
283 write_into_file(outfile, "output", args_info->output_orig, 0);
284 if (args_info->minSize_given)
285 write_into_file(outfile, "minSize", args_info->minSize_orig, 0);
286 if (args_info->full_given)
287 write_into_file(outfile, "full", 0, 0 );
295 cmdline_parser_clitkConnectedComponentLabeling_file_save(const char *filename, struct args_info_clitkConnectedComponentLabeling *args_info)
300 outfile = fopen(filename, "w");
304 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename);
308 i = cmdline_parser_clitkConnectedComponentLabeling_dump(outfile, args_info);
315 cmdline_parser_clitkConnectedComponentLabeling_free (struct args_info_clitkConnectedComponentLabeling *args_info)
317 cmdline_parser_clitkConnectedComponentLabeling_release (args_info);
320 /** @brief replacement of strdup, which is not standard */
322 gengetopt_strdup (const char *s)
328 result = (char*)malloc(strlen(s) + 1);
329 if (result == (char*)0)
336 cmdline_parser_clitkConnectedComponentLabeling (int argc, char * const *argv, struct args_info_clitkConnectedComponentLabeling *args_info)
338 return cmdline_parser_clitkConnectedComponentLabeling2 (argc, argv, args_info, 0, 1, 1);
342 cmdline_parser_clitkConnectedComponentLabeling_ext (int argc, char * const *argv, struct args_info_clitkConnectedComponentLabeling *args_info,
343 struct cmdline_parser_clitkConnectedComponentLabeling_params *params)
346 result = cmdline_parser_clitkConnectedComponentLabeling_internal (argc, argv, args_info, params, NULL);
348 if (result == EXIT_FAILURE)
350 cmdline_parser_clitkConnectedComponentLabeling_free (args_info);
358 cmdline_parser_clitkConnectedComponentLabeling2 (int argc, char * const *argv, struct args_info_clitkConnectedComponentLabeling *args_info, int override, int initialize, int check_required)
361 struct cmdline_parser_clitkConnectedComponentLabeling_params params;
363 params.override = override;
364 params.initialize = initialize;
365 params.check_required = check_required;
366 params.check_ambiguity = 0;
367 params.print_errors = 1;
369 result = cmdline_parser_clitkConnectedComponentLabeling_internal (argc, argv, args_info, ¶ms, NULL);
371 if (result == EXIT_FAILURE)
373 cmdline_parser_clitkConnectedComponentLabeling_free (args_info);
381 cmdline_parser_clitkConnectedComponentLabeling_required (struct args_info_clitkConnectedComponentLabeling *args_info, const char *prog_name)
383 int result = EXIT_SUCCESS;
385 if (cmdline_parser_clitkConnectedComponentLabeling_required2(args_info, prog_name, NULL) > 0)
386 result = EXIT_FAILURE;
388 if (result == EXIT_FAILURE)
390 cmdline_parser_clitkConnectedComponentLabeling_free (args_info);
398 cmdline_parser_clitkConnectedComponentLabeling_required2 (struct args_info_clitkConnectedComponentLabeling *args_info, const char *prog_name, const char *additional_error)
402 /* checks for required options */
403 if (! args_info->input_given)
405 fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
409 if (! args_info->output_given)
411 fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
416 /* checks for dependences among options */
422 * Extracted from the glibc source tree, version 2.3.6
424 * Licensed under the GPL as per the whole glibc source tree.
426 * This file was modified so that getopt_long can be called
427 * many times without risking previous memory to be spoiled.
429 * Modified by Andre Noll and Lorenzo Bettini for use in
430 * GNU gengetopt generated files.
435 * we must include anything we need since this file is not thought to be
436 * inserted in a file already using getopt.h
444 /* has_arg can't be an enum because some compilers complain about
445 type mismatches in all the code that assumes it is an int. */
451 /* For communication from `getopt' to the caller.
452 When `getopt' finds an option that takes an argument,
453 the argument value is returned here.
454 Also, when `ordering' is RETURN_IN_ORDER,
455 each non-option ARGV-element is returned here. */
459 /* Index in ARGV of the next element to be scanned.
460 This is used for communication to and from the caller
461 and for communication between successive calls to `getopt'.
463 On entry to `getopt', zero means this is the first call; initialize.
465 When `getopt' returns -1, this is the index of the first of the
466 non-option elements that the caller should itself scan.
468 Otherwise, `optind' communicates from one call to the next
469 how much of ARGV has been scanned so far. */
473 /* Callers store zero here to inhibit the error message `getopt' prints
474 for unrecognized options. */
478 /* Set to an option character which was unrecognized. */
482 /* This version of `getopt' appears to the caller like standard Unix `getopt'
483 but it behaves differently for the user, since it allows the user
484 to intersperse the options with the other arguments.
486 As `getopt' works, it permutes the elements of ARGV so that,
487 when it is done, all the options precede everything else. Thus
488 all application programs are extended to handle flexible argument order.
491 If the field `flag' is not NULL, it points to a variable that is set
492 to the value given in the field `val' when the option is found, but
493 left unchanged if the option is not found.
495 To have a long-named option do something other than set an `int' to
496 a compiled-in constant, such as set a value from `custom_optarg', set the
497 option's `flag' field to zero and its `val' field to a nonzero
498 value (the equivalent single-letter option character, if there is
499 one). For long options that have a zero `flag' field, `getopt'
500 returns the contents of the `val' field. */
502 /* Names for the values of the `has_arg' field of `struct option'. */
504 #define no_argument 0
507 #ifndef required_argument
508 #define required_argument 1
511 #ifndef optional_argument
512 #define optional_argument 2
515 struct custom_getopt_data {
517 * These have exactly the same meaning as the corresponding global variables,
518 * except that they are used for the reentrant versions of getopt.
525 /* True if the internal members have been initialized. */
529 * The next char to be scanned in the option-element in which the last option
530 * character we returned was found. This allows us to pick up the scan where
531 * we left off. If this is zero, or a null string, it means resume the scan by
532 * advancing to the next ARGV-element.
537 * Describe the part of ARGV that contains non-options that have been skipped.
538 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
539 * the index after the last of them.
546 * the variables optarg, optind, opterr and optopt are renamed with
547 * the custom_ prefix so that they don't interfere with getopt ones.
549 * Moreover they're static so they are visible only from within the
550 * file where this very file will be included.
554 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
555 * option that takes an argument, the argument value is returned here.
557 static char *custom_optarg;
560 * Index in ARGV of the next element to be scanned. This is used for
561 * communication to and from the caller and for communication between
562 * successive calls to `custom_getopt'.
564 * On entry to `custom_getopt', 1 means this is the first call; initialize.
566 * When `custom_getopt' returns -1, this is the index of the first of the non-option
567 * elements that the caller should itself scan.
569 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
570 * has been scanned so far.
572 * 1003.2 says this must be 1 before any call.
574 static int custom_optind = 1;
577 * Callers store zero here to inhibit the error message for unrecognized
580 static int custom_opterr = 1;
583 * Set to an option character which was unrecognized. This must be initialized
584 * on some systems to avoid linking in the system's own getopt implementation.
586 static int custom_optopt = '?';
589 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
590 * [first_nonopt,last_nonopt) which contains all the non-options that have been
591 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
592 * all the options processed since those non-options were skipped.
593 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
594 * indices of the non-options in ARGV after they are moved.
596 static void exchange(char **argv, struct custom_getopt_data *d)
598 int bottom = d->first_nonopt;
599 int middle = d->last_nonopt;
600 int top = d->custom_optind;
604 * Exchange the shorter segment with the far end of the longer segment.
605 * That puts the shorter segment into the right place. It leaves the
606 * longer segment in the right place overall, but it consists of two
607 * parts that need to be swapped next.
609 while (top > middle && middle > bottom) {
610 if (top - middle > middle - bottom) {
611 /* Bottom segment is the short one. */
612 int len = middle - bottom;
615 /* Swap it with the top part of the top segment. */
616 for (i = 0; i < len; i++) {
617 tem = argv[bottom + i];
619 argv[top - (middle - bottom) + i];
620 argv[top - (middle - bottom) + i] = tem;
622 /* Exclude the moved bottom segment from further swapping. */
625 /* Top segment is the short one. */
626 int len = top - middle;
629 /* Swap it with the bottom part of the bottom segment. */
630 for (i = 0; i < len; i++) {
631 tem = argv[bottom + i];
632 argv[bottom + i] = argv[middle + i];
633 argv[middle + i] = tem;
635 /* Exclude the moved top segment from further swapping. */
639 /* Update records for the slots the non-options now occupy. */
640 d->first_nonopt += (d->custom_optind - d->last_nonopt);
641 d->last_nonopt = d->custom_optind;
644 /* Initialize the internal data when the first call is made. */
645 static void custom_getopt_initialize(struct custom_getopt_data *d)
648 * Start processing options with ARGV-element 1 (since ARGV-element 0
649 * is the program name); the sequence of previously skipped non-option
650 * ARGV-elements is empty.
652 d->first_nonopt = d->last_nonopt = d->custom_optind;
657 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
659 /* return: zero: continue, nonzero: return given value to user */
660 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
661 struct custom_getopt_data *d)
664 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
665 * moved back by the user (who may also have changed the arguments).
667 if (d->last_nonopt > d->custom_optind)
668 d->last_nonopt = d->custom_optind;
669 if (d->first_nonopt > d->custom_optind)
670 d->first_nonopt = d->custom_optind;
672 * If we have just processed some options following some
673 * non-options, exchange them so that the options come first.
675 if (d->first_nonopt != d->last_nonopt &&
676 d->last_nonopt != d->custom_optind)
677 exchange((char **) argv, d);
678 else if (d->last_nonopt != d->custom_optind)
679 d->first_nonopt = d->custom_optind;
681 * Skip any additional non-options and extend the range of
682 * non-options previously skipped.
684 while (d->custom_optind < argc && NONOPTION_P)
686 d->last_nonopt = d->custom_optind;
688 * The special ARGV-element `--' means premature end of options. Skip
689 * it like a null option, then exchange with previous non-options as if
690 * it were an option, then skip everything else like a non-option.
692 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
694 if (d->first_nonopt != d->last_nonopt
695 && d->last_nonopt != d->custom_optind)
696 exchange((char **) argv, d);
697 else if (d->first_nonopt == d->last_nonopt)
698 d->first_nonopt = d->custom_optind;
699 d->last_nonopt = argc;
700 d->custom_optind = argc;
703 * If we have done all the ARGV-elements, stop the scan and back over
704 * any non-options that we skipped and permuted.
706 if (d->custom_optind == argc) {
708 * Set the next-arg-index to point at the non-options that we
709 * previously skipped, so the caller will digest them.
711 if (d->first_nonopt != d->last_nonopt)
712 d->custom_optind = d->first_nonopt;
716 * If we have come to a non-option and did not permute it, either stop
717 * the scan or describe it to the caller and pass it by.
720 d->custom_optarg = argv[d->custom_optind++];
724 * We have found another option-ARGV-element. Skip the initial
727 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
732 * Check whether the ARGV-element is a long option.
734 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
735 * that an abbreviation of the long option, just like "--fu", and not "-f" with
738 * This distinction seems to be the most useful approach.
741 static int check_long_opt(int argc, char *const *argv, const char *optstring,
742 const struct option *longopts, int *longind,
743 int print_errors, struct custom_getopt_data *d)
746 const struct option *p;
747 const struct option *pfound = NULL;
753 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
756 /* Test all long options for either exact match or abbreviated matches */
757 for (p = longopts, option_index = 0; p->name; p++, option_index++)
758 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
759 if ((unsigned int) (nameend - d->nextchar)
760 == (unsigned int) strlen(p->name)) {
761 /* Exact match found. */
763 indfound = option_index;
766 } else if (pfound == NULL) {
767 /* First nonexact match found. */
769 indfound = option_index;
770 } else if (pfound->has_arg != p->has_arg
771 || pfound->flag != p->flag
772 || pfound->val != p->val)
773 /* Second or later nonexact match found. */
776 if (ambig && !exact) {
779 "%s: option `%s' is ambiguous\n",
780 argv[0], argv[d->custom_optind]);
782 d->nextchar += strlen(d->nextchar);
784 d->custom_optopt = 0;
788 option_index = indfound;
791 if (pfound->has_arg != no_argument)
792 d->custom_optarg = nameend + 1;
795 if (argv[d->custom_optind - 1][1] == '-') {
797 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
798 argv[0], pfound->name);
800 /* +option or -option */
801 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
802 argv[0], argv[d->custom_optind - 1][0], pfound->name);
806 d->nextchar += strlen(d->nextchar);
807 d->custom_optopt = pfound->val;
810 } else if (pfound->has_arg == required_argument) {
811 if (d->custom_optind < argc)
812 d->custom_optarg = argv[d->custom_optind++];
816 "%s: option `%s' requires an argument\n",
818 argv[d->custom_optind - 1]);
820 d->nextchar += strlen(d->nextchar);
821 d->custom_optopt = pfound->val;
822 return optstring[0] == ':' ? ':' : '?';
825 d->nextchar += strlen(d->nextchar);
827 *longind = option_index;
829 *(pfound->flag) = pfound->val;
835 * Can't find it as a long option. If this is not getopt_long_only, or
836 * the option starts with '--' or is not a valid short option, then
837 * it's an error. Otherwise interpret it as a short option.
840 if (argv[d->custom_optind][1] == '-') {
843 "%s: unrecognized option `--%s'\n",
844 argv[0], d->nextchar);
846 /* +option or -option */
848 "%s: unrecognized option `%c%s'\n",
849 argv[0], argv[d->custom_optind][0],
853 d->nextchar = (char *) "";
855 d->custom_optopt = 0;
859 static int check_short_opt(int argc, char *const *argv, const char *optstring,
860 int print_errors, struct custom_getopt_data *d)
862 char c = *d->nextchar++;
863 char *temp = strchr(optstring, c);
865 /* Increment `custom_optind' when we start to process its last character. */
866 if (*d->nextchar == '\0')
868 if (!temp || c == ':') {
870 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
872 d->custom_optopt = c;
875 if (temp[1] == ':') {
876 if (temp[2] == ':') {
877 /* This is an option that accepts an argument optionally. */
878 if (*d->nextchar != '\0') {
879 d->custom_optarg = d->nextchar;
882 d->custom_optarg = NULL;
885 /* This is an option that requires an argument. */
886 if (*d->nextchar != '\0') {
887 d->custom_optarg = d->nextchar;
889 * If we end this ARGV-element by taking the
890 * rest as an arg, we must advance to the next
894 } else if (d->custom_optind == argc) {
897 "%s: option requires an argument -- %c\n",
900 d->custom_optopt = c;
901 if (optstring[0] == ':')
907 * We already incremented `custom_optind' once;
908 * increment it again when taking next ARGV-elt
911 d->custom_optarg = argv[d->custom_optind++];
919 * Scan elements of ARGV for option characters given in OPTSTRING.
921 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
922 * then it is an option element. The characters of this element
923 * (aside from the initial '-') are option characters. If `getopt'
924 * is called repeatedly, it returns successively each of the option characters
925 * from each of the option elements.
927 * If `getopt' finds another option character, it returns that character,
928 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
929 * resume the scan with the following option character or ARGV-element.
931 * If there are no more option characters, `getopt' returns -1.
932 * Then `custom_optind' is the index in ARGV of the first ARGV-element
933 * that is not an option. (The ARGV-elements have been permuted
934 * so that those that are not options now come last.)
936 * OPTSTRING is a string containing the legitimate option characters.
937 * If an option character is seen that is not listed in OPTSTRING,
938 * return '?' after printing an error message. If you set `custom_opterr' to
939 * zero, the error message is suppressed but we still return '?'.
941 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
942 * so the following text in the same ARGV-element, or the text of the following
943 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
944 * wants an optional arg; if there is text in the current ARGV-element,
945 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
947 * If OPTSTRING starts with `-' or `+', it requests different methods of
948 * handling the non-option ARGV-elements.
949 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
951 * Long-named options begin with `--' instead of `-'.
952 * Their names may be abbreviated as long as the abbreviation is unique
953 * or is an exact match for some defined option. If they have an
954 * argument, it follows the option name in the same ARGV-element, separated
955 * from the option name by a `=', or else the in next ARGV-element.
956 * When `getopt' finds a long-named option, it returns 0 if that option's
957 * `flag' field is nonzero, the value of the option's `val' field
958 * if the `flag' field is zero.
960 * The elements of ARGV aren't really const, because we permute them.
961 * But we pretend they're const in the prototype to be compatible
962 * with other systems.
964 * LONGOPTS is a vector of `struct option' terminated by an
965 * element containing a name which is zero.
967 * LONGIND returns the index in LONGOPT of the long-named option found.
968 * It is only valid when a long-named option has been found by the most
971 * Return the option character from OPTS just read. Return -1 when there are
972 * no more options. For unrecognized options, or options missing arguments,
973 * `custom_optopt' is set to the option letter, and '?' is returned.
975 * The OPTS string is a list of characters which are recognized option letters,
976 * optionally followed by colons, specifying that that letter takes an
977 * argument, to be placed in `custom_optarg'.
979 * If a letter in OPTS is followed by two colons, its argument is optional.
980 * This behavior is specific to the GNU `getopt'.
982 * The argument `--' causes premature termination of argument scanning,
983 * explicitly telling `getopt' that there are no more options. If OPTS begins
984 * with `--', then non-option arguments are treated as arguments to the option
985 * '\0'. This behavior is specific to the GNU `getopt'.
988 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
989 const struct option *longopts, int *longind,
990 struct custom_getopt_data *d)
992 int ret, print_errors = d->custom_opterr;
994 if (optstring[0] == ':')
998 d->custom_optarg = NULL;
1001 * This is a big difference with GNU getopt, since optind == 0
1002 * means initialization while here 1 means first call.
1004 if (d->custom_optind == 0 || !d->initialized) {
1005 if (d->custom_optind == 0)
1006 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
1007 custom_getopt_initialize(d);
1009 if (d->nextchar == NULL || *d->nextchar == '\0') {
1010 ret = shuffle_argv(argc, argv, longopts, d);
1014 if (longopts && (argv[d->custom_optind][1] == '-' ))
1015 return check_long_opt(argc, argv, optstring, longopts,
1016 longind, print_errors, d);
1017 return check_short_opt(argc, argv, optstring, print_errors, d);
1020 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1021 const struct option *longopts, int *longind)
1024 /* Keep a global copy of all internal members of d */
1025 static struct custom_getopt_data d;
1027 d.custom_optind = custom_optind;
1028 d.custom_opterr = custom_opterr;
1029 result = getopt_internal_r(argc, argv, optstring, longopts,
1031 custom_optind = d.custom_optind;
1032 custom_optarg = d.custom_optarg;
1033 custom_optopt = d.custom_optopt;
1037 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1038 const struct option *long_options, int *opt_index)
1040 return custom_getopt_internal(argc, argv, options, long_options,
1045 static char *package_name = 0;
1048 * @brief updates an option
1049 * @param field the generic pointer to the field to update
1050 * @param orig_field the pointer to the orig field
1051 * @param field_given the pointer to the number of occurrence of this option
1052 * @param prev_given the pointer to the number of occurrence already seen
1053 * @param value the argument for this option (if null no arg was specified)
1054 * @param possible_values the possible values for this option (if specified)
1055 * @param default_value the default value (in case the option only accepts fixed values)
1056 * @param arg_type the type of this option
1057 * @param check_ambiguity @see cmdline_parser_clitkConnectedComponentLabeling_params.check_ambiguity
1058 * @param override @see cmdline_parser_clitkConnectedComponentLabeling_params.override
1059 * @param no_free whether to free a possible previous value
1060 * @param multiple_option whether this is a multiple option
1061 * @param long_opt the corresponding long option
1062 * @param short_opt the corresponding short option (or '-' if none)
1063 * @param additional_error possible further error specification
1066 int update_arg(void *field, char **orig_field,
1067 unsigned int *field_given, unsigned int *prev_given,
1068 char *value, char *possible_values[], const char *default_value,
1069 cmdline_parser_clitkConnectedComponentLabeling_arg_type arg_type,
1070 int check_ambiguity, int override,
1071 int no_free, int multiple_option,
1072 const char *long_opt, char short_opt,
1073 const char *additional_error)
1075 char *stop_char = 0;
1076 const char *val = value;
1078 char **string_field;
1083 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1085 if (short_opt != '-')
1086 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1087 package_name, long_opt, short_opt,
1088 (additional_error ? additional_error : ""));
1090 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1091 package_name, long_opt,
1092 (additional_error ? additional_error : ""));
1093 return 1; /* failure */
1097 if (field_given && *field_given && ! override)
1103 if (possible_values)
1104 val = possible_values[found];
1108 *((int *)field) = !*((int *)field);
1111 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1115 string_field = (char **)field;
1116 if (!no_free && *string_field)
1117 free (*string_field); /* free previous string */
1118 *string_field = gengetopt_strdup (val);
1125 /* check numeric conversion */
1128 if (val && !(stop_char && *stop_char == '\0')) {
1129 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1130 return 1; /* failure */
1137 /* store the original value */
1143 if (value && orig_field) {
1145 *orig_field = value;
1148 free (*orig_field); /* free previous string */
1149 *orig_field = gengetopt_strdup (value);
1159 cmdline_parser_clitkConnectedComponentLabeling_internal (int argc, char * const *argv, struct args_info_clitkConnectedComponentLabeling *args_info,
1160 struct cmdline_parser_clitkConnectedComponentLabeling_params *params, const char *additional_error)
1162 int c; /* Character of the parsed option. */
1165 struct args_info_clitkConnectedComponentLabeling local_args_info;
1170 int check_ambiguity;
1172 package_name = argv[0];
1174 override = params->override;
1175 initialize = params->initialize;
1176 check_required = params->check_required;
1177 check_ambiguity = params->check_ambiguity;
1180 cmdline_parser_clitkConnectedComponentLabeling_init (args_info);
1182 cmdline_parser_clitkConnectedComponentLabeling_init (&local_args_info);
1186 opterr = params->print_errors;
1191 int option_index = 0;
1193 static struct option long_options[] = {
1194 { "help", 0, NULL, 'h' },
1195 { "version", 0, NULL, 'V' },
1196 { "config", 1, NULL, 0 },
1197 { "verbose", 0, NULL, 'v' },
1198 { "imagetypes", 0, NULL, 0 },
1199 { "verboseOption", 0, NULL, 0 },
1200 { "input", 1, NULL, 'i' },
1201 { "inputBG", 1, NULL, 0 },
1202 { "output", 1, NULL, 'o' },
1203 { "minSize", 1, NULL, 0 },
1204 { "full", 0, NULL, 0 },
1205 { NULL, 0, NULL, 0 }
1208 custom_optarg = optarg;
1209 custom_optind = optind;
1210 custom_opterr = opterr;
1211 custom_optopt = optopt;
1213 c = custom_getopt_long (argc, argv, "hVvi:o:", long_options, &option_index);
1215 optarg = custom_optarg;
1216 optind = custom_optind;
1217 opterr = custom_opterr;
1218 optopt = custom_optopt;
1220 if (c == -1) break; /* Exit from `while (1)' loop. */
1224 case 'h': /* Print help and exit. */
1225 cmdline_parser_clitkConnectedComponentLabeling_print_help ();
1226 cmdline_parser_clitkConnectedComponentLabeling_free (&local_args_info);
1227 exit (EXIT_SUCCESS);
1229 case 'V': /* Print version and exit. */
1230 cmdline_parser_clitkConnectedComponentLabeling_print_version ();
1231 cmdline_parser_clitkConnectedComponentLabeling_free (&local_args_info);
1232 exit (EXIT_SUCCESS);
1234 case 'v': /* Verbose. */
1237 if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
1238 &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
1239 check_ambiguity, override, 1, 0, "verbose", 'v',
1244 case 'i': /* Input image filename. */
1247 if (update_arg( (void *)&(args_info->input_arg),
1248 &(args_info->input_orig), &(args_info->input_given),
1249 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1250 check_ambiguity, override, 0, 0,
1256 case 'o': /* Output filename. */
1259 if (update_arg( (void *)&(args_info->output_arg),
1260 &(args_info->output_orig), &(args_info->output_given),
1261 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1262 check_ambiguity, override, 0, 0,
1269 case 0: /* Long option with no short option */
1271 if (strcmp (long_options[option_index].name, "config") == 0)
1275 if (update_arg( (void *)&(args_info->config_arg),
1276 &(args_info->config_orig), &(args_info->config_given),
1277 &(local_args_info.config_given), optarg, 0, 0, ARG_STRING,
1278 check_ambiguity, override, 0, 0,
1284 /* Display allowed image types. */
1285 else if (strcmp (long_options[option_index].name, "imagetypes") == 0)
1289 if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given),
1290 &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG,
1291 check_ambiguity, override, 1, 0, "imagetypes", '-',
1296 /* Display options values. */
1297 else if (strcmp (long_options[option_index].name, "verboseOption") == 0)
1301 if (update_arg((void *)&(args_info->verboseOption_flag), 0, &(args_info->verboseOption_given),
1302 &(local_args_info.verboseOption_given), optarg, 0, 0, ARG_FLAG,
1303 check_ambiguity, override, 1, 0, "verboseOption", '-',
1308 /* Input Background. */
1309 else if (strcmp (long_options[option_index].name, "inputBG") == 0)
1313 if (update_arg( (void *)&(args_info->inputBG_arg),
1314 &(args_info->inputBG_orig), &(args_info->inputBG_given),
1315 &(local_args_info.inputBG_given), optarg, 0, "0", ARG_INT,
1316 check_ambiguity, override, 0, 0,
1322 /* Minimum component size in voxels. */
1323 else if (strcmp (long_options[option_index].name, "minSize") == 0)
1327 if (update_arg( (void *)&(args_info->minSize_arg),
1328 &(args_info->minSize_orig), &(args_info->minSize_given),
1329 &(local_args_info.minSize_given), optarg, 0, "100", ARG_INT,
1330 check_ambiguity, override, 0, 0,
1336 /* Full connecticity. */
1337 else if (strcmp (long_options[option_index].name, "full") == 0)
1341 if (update_arg((void *)&(args_info->full_flag), 0, &(args_info->full_given),
1342 &(local_args_info.full_given), optarg, 0, 0, ARG_FLAG,
1343 check_ambiguity, override, 1, 0, "full", '-',
1350 case '?': /* Invalid option. */
1351 /* `getopt_long' already printed an error message. */
1354 default: /* bug: option not considered. */
1355 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, c, (additional_error ? additional_error : ""));
1364 error += cmdline_parser_clitkConnectedComponentLabeling_required2 (args_info, argv[0], additional_error);
1367 cmdline_parser_clitkConnectedComponentLabeling_release (&local_args_info);
1370 return (EXIT_FAILURE);
1375 int found_prog_name = 0;
1376 /* whether program name, i.e., argv[0], is in the remaining args
1377 (this may happen with some implementations of getopt,
1378 but surely not with the one included by gengetopt) */
1381 args_info->inputs_num = argc - optind - found_prog_name;
1383 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1384 while (optind < argc)
1385 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1392 cmdline_parser_clitkConnectedComponentLabeling_release (&local_args_info);
1393 return (EXIT_FAILURE);
1396 #ifndef CONFIG_FILE_LINE_SIZE
1397 #define CONFIG_FILE_LINE_SIZE 2048
1399 #define ADDITIONAL_ERROR " in configuration file "
1401 #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1402 /* 3 is for "--" and "=" */
1405 _cmdline_parser_clitkConnectedComponentLabeling_configfile (char * const filename, int *my_argc)
1408 char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
1409 char linebuf[CONFIG_FILE_LINE_SIZE];
1411 int result = 0, equal;
1414 size_t len, next_token;
1417 if ((file = fopen(filename, "r")) == NULL)
1419 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
1420 CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename);
1421 return EXIT_FAILURE;
1424 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
1428 len = strlen(linebuf);
1429 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
1431 fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
1432 CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename, line_num);
1433 result = EXIT_FAILURE;
1437 /* find first non-whitespace character in the line */
1438 next_token = strspn (linebuf, " \t\r\n");
1439 str_index = linebuf + next_token;
1441 if ( str_index[0] == '\0' || str_index[0] == '#')
1442 continue; /* empty line or comment line is skipped */
1446 /* truncate fopt at the end of the first non-valid character */
1447 next_token = strcspn (fopt, " \t\r\n=");
1449 if (fopt[next_token] == '\0') /* the line is over */
1456 /* remember if equal sign is present */
1457 equal = (fopt[next_token] == '=');
1458 fopt[next_token++] = '\0';
1460 /* advance pointers to the next token after the end of fopt */
1461 next_token += strspn (fopt + next_token, " \t\r\n");
1463 /* check for the presence of equal sign, and if so, skip it */
1465 if ((equal = (fopt[next_token] == '=')))
1468 next_token += strspn (fopt + next_token, " \t\r\n");
1470 str_index += next_token;
1474 if ( farg[0] == '\"' || farg[0] == '\'' )
1475 { /* quoted argument */
1476 str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
1481 "%s:%s:%d: unterminated string in configuration file\n",
1482 CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename, line_num);
1483 result = EXIT_FAILURE;
1488 { /* read up the remaining part up to a delimiter */
1489 next_token = strcspn (farg, " \t\r\n#\'\"");
1490 str_index += next_token;
1493 /* truncate farg at the delimiter and store it for further check */
1494 delimiter = *str_index, *str_index++ = '\0';
1496 /* everything but comment is illegal at the end of line */
1497 if (delimiter != '\0' && delimiter != '#')
1499 str_index += strspn(str_index, " \t\r\n");
1500 if (*str_index != '\0' && *str_index != '#')
1504 "%s:%s:%d: malformed string in configuration file\n",
1505 CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename, line_num);
1506 result = EXIT_FAILURE;
1512 if (!strcmp(fopt,"include")) {
1513 if (farg && *farg) {
1514 result = _cmdline_parser_clitkConnectedComponentLabeling_configfile(farg, my_argc);
1516 fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n",
1517 CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename, line_num);
1522 strcat (my_argv, len > 1 ? "--" : "-");
1523 strcat (my_argv, fopt);
1524 if (len > 1 && ((farg && *farg) || equal))
1525 strcat (my_argv, "=");
1527 strcat (my_argv, farg);
1530 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1531 cmd_line_list_tmp->next = cmd_line_list;
1532 cmd_line_list = cmd_line_list_tmp;
1533 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
1542 cmdline_parser_clitkConnectedComponentLabeling_configfile (char * const filename,
1543 struct args_info_clitkConnectedComponentLabeling *args_info,
1544 int override, int initialize, int check_required)
1546 struct cmdline_parser_clitkConnectedComponentLabeling_params params;
1548 params.override = override;
1549 params.initialize = initialize;
1550 params.check_required = check_required;
1551 params.check_ambiguity = 0;
1552 params.print_errors = 1;
1554 return cmdline_parser_clitkConnectedComponentLabeling_config_file (filename, args_info, ¶ms);
1558 cmdline_parser_clitkConnectedComponentLabeling_config_file (char * const filename,
1559 struct args_info_clitkConnectedComponentLabeling *args_info,
1560 struct cmdline_parser_clitkConnectedComponentLabeling_params *params)
1565 char *additional_error;
1567 /* store the program name */
1568 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1569 cmd_line_list_tmp->next = cmd_line_list;
1570 cmd_line_list = cmd_line_list_tmp;
1571 cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE);
1573 result = _cmdline_parser_clitkConnectedComponentLabeling_configfile(filename, &my_argc);
1575 if (result != EXIT_FAILURE) {
1576 my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
1577 cmd_line_list_tmp = cmd_line_list;
1579 for (i = my_argc - 1; i >= 0; --i) {
1580 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
1581 cmd_line_list_tmp = cmd_line_list_tmp->next;
1584 my_argv_arg[my_argc] = 0;
1586 additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
1587 strcpy (additional_error, ADDITIONAL_ERROR);
1588 strcat (additional_error, filename);
1590 cmdline_parser_clitkConnectedComponentLabeling_internal (my_argc, my_argv_arg, args_info,
1594 free (additional_error);
1599 if (result == EXIT_FAILURE)
1601 cmdline_parser_clitkConnectedComponentLabeling_free (args_info);
1602 exit (EXIT_FAILURE);