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_clitkRegionGrowing --func-name=cmdline_parser_clitkRegionGrowing --file-name=clitkRegionGrowing_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 "clitkRegionGrowing_ggo.h"
23 const char *args_info_clitkRegionGrowing_purpose = "Region growing from a seed point using various types of conditions to control \nthe growing";
25 const char *args_info_clitkRegionGrowing_usage = "Usage: clitkRegionGrowing [OPTIONS]... [FILES]...";
27 const char *args_info_clitkRegionGrowing_description = "";
29 const char *args_info_clitkRegionGrowing_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)",
35 " -i, --input=STRING Input image filename",
36 " -o, --output=STRING Output image filename",
38 " -t, --type=INT Region growing filter type: 0=threshold , \n 1=neighborhood-threshold , 2=confidence , 3= \n locally-adaptive-threshold, 4= \n explosion-controlled-threshold (default=`0')",
39 " -l, --lower=DOUBLE 1,2,3,4: Lower threshold value (default=`310')",
40 " -u, --upper=DOUBLE 1,2,3,4: Upper threshold value (default=`4000')",
41 " --maxUpper=DOUBLE 4: Maximum upper threshold value (default=`2000')",
42 " --minLower=DOUBLE 4: Minimum lower threshold value (default=`-1000')",
43 " --step=DOUBLE 4: Threshold step size (default=`64.0')",
44 " --minStep=DOUBLE 4: Minimum threshold step size (default=`1')",
45 " --adaptLower 3,4: (locally) adapt lower thresholding \n (default=off)",
46 " --adaptUpper 3,4: (locally) adapt upper thresholding \n (default=off)",
47 " -m, --multiplier=DOUBLE 2-4: (2-3) accept if within mean+-mutiplier*SD, (4) \n explosion if size increases multiplier times \n (default=`2.0')",
48 " -s, --seed=INT Seed index postion (in voxels) (default=`0')",
49 " --seedRadius=INT Radius used for seed dilatation(in voxel) \n (default=`0')",
50 " -p, --pad=DOUBLE The replace padding value (default=`1.0')",
51 " -r, --radius=INT 1-3: The radius of the neighborhood (default=`1')",
52 " --maxSD=DOUBLE 3: Limit to SD",
53 " --full 4: use full connectivity (not implemented yet) \n (default=off)",
54 " --iter=INT 2: Iterations (default=`5')",
63 } cmdline_parser_clitkRegionGrowing_arg_type;
66 void clear_given (struct args_info_clitkRegionGrowing *args_info);
68 void clear_args (struct args_info_clitkRegionGrowing *args_info);
71 cmdline_parser_clitkRegionGrowing_internal (int argc, char * const *argv, struct args_info_clitkRegionGrowing *args_info,
72 struct cmdline_parser_clitkRegionGrowing_params *params, const char *additional_error);
75 cmdline_parser_clitkRegionGrowing_required2 (struct args_info_clitkRegionGrowing *args_info, const char *prog_name, const char *additional_error);
79 struct line_list * next;
82 static struct line_list *cmd_line_list = 0;
83 static struct line_list *cmd_line_list_tmp = 0;
88 /* free the list of a previous call */
91 while (cmd_line_list) {
92 cmd_line_list_tmp = cmd_line_list;
93 cmd_line_list = cmd_line_list->next;
94 free (cmd_line_list_tmp->string_arg);
95 free (cmd_line_list_tmp);
102 gengetopt_strdup (const char *s);
105 void clear_given (struct args_info_clitkRegionGrowing *args_info)
107 args_info->help_given = 0 ;
108 args_info->version_given = 0 ;
109 args_info->config_given = 0 ;
110 args_info->verbose_given = 0 ;
111 args_info->input_given = 0 ;
112 args_info->output_given = 0 ;
113 args_info->type_given = 0 ;
114 args_info->lower_given = 0 ;
115 args_info->upper_given = 0 ;
116 args_info->maxUpper_given = 0 ;
117 args_info->minLower_given = 0 ;
118 args_info->step_given = 0 ;
119 args_info->minStep_given = 0 ;
120 args_info->adaptLower_given = 0 ;
121 args_info->adaptUpper_given = 0 ;
122 args_info->multiplier_given = 0 ;
123 args_info->seed_given = 0 ;
124 args_info->seedRadius_given = 0 ;
125 args_info->pad_given = 0 ;
126 args_info->radius_given = 0 ;
127 args_info->maxSD_given = 0 ;
128 args_info->full_given = 0 ;
129 args_info->iter_given = 0 ;
133 void clear_args (struct args_info_clitkRegionGrowing *args_info)
135 args_info->config_arg = NULL;
136 args_info->config_orig = NULL;
137 args_info->verbose_flag = 0;
138 args_info->input_arg = NULL;
139 args_info->input_orig = NULL;
140 args_info->output_arg = NULL;
141 args_info->output_orig = NULL;
142 args_info->type_arg = 0;
143 args_info->type_orig = NULL;
144 args_info->lower_arg = 310;
145 args_info->lower_orig = NULL;
146 args_info->upper_arg = 4000;
147 args_info->upper_orig = NULL;
148 args_info->maxUpper_arg = 2000;
149 args_info->maxUpper_orig = NULL;
150 args_info->minLower_arg = -1000;
151 args_info->minLower_orig = NULL;
152 args_info->step_arg = 64.0;
153 args_info->step_orig = NULL;
154 args_info->minStep_arg = 1;
155 args_info->minStep_orig = NULL;
156 args_info->adaptLower_flag = 0;
157 args_info->adaptUpper_flag = 0;
158 args_info->multiplier_arg = 2.0;
159 args_info->multiplier_orig = NULL;
160 args_info->seed_arg = NULL;
161 args_info->seed_orig = NULL;
162 args_info->seedRadius_arg = NULL;
163 args_info->seedRadius_orig = NULL;
164 args_info->pad_arg = 1.0;
165 args_info->pad_orig = NULL;
166 args_info->radius_arg = NULL;
167 args_info->radius_orig = NULL;
168 args_info->maxSD_orig = NULL;
169 args_info->full_flag = 0;
170 args_info->iter_arg = 5;
171 args_info->iter_orig = NULL;
176 void init_args_info(struct args_info_clitkRegionGrowing *args_info)
180 args_info->help_help = args_info_clitkRegionGrowing_help[0] ;
181 args_info->version_help = args_info_clitkRegionGrowing_help[1] ;
182 args_info->config_help = args_info_clitkRegionGrowing_help[2] ;
183 args_info->verbose_help = args_info_clitkRegionGrowing_help[3] ;
184 args_info->input_help = args_info_clitkRegionGrowing_help[5] ;
185 args_info->output_help = args_info_clitkRegionGrowing_help[6] ;
186 args_info->type_help = args_info_clitkRegionGrowing_help[8] ;
187 args_info->lower_help = args_info_clitkRegionGrowing_help[9] ;
188 args_info->upper_help = args_info_clitkRegionGrowing_help[10] ;
189 args_info->maxUpper_help = args_info_clitkRegionGrowing_help[11] ;
190 args_info->minLower_help = args_info_clitkRegionGrowing_help[12] ;
191 args_info->step_help = args_info_clitkRegionGrowing_help[13] ;
192 args_info->minStep_help = args_info_clitkRegionGrowing_help[14] ;
193 args_info->adaptLower_help = args_info_clitkRegionGrowing_help[15] ;
194 args_info->adaptUpper_help = args_info_clitkRegionGrowing_help[16] ;
195 args_info->multiplier_help = args_info_clitkRegionGrowing_help[17] ;
196 args_info->seed_help = args_info_clitkRegionGrowing_help[18] ;
197 args_info->seed_min = -1;
198 args_info->seed_max = -1;
199 args_info->seedRadius_help = args_info_clitkRegionGrowing_help[19] ;
200 args_info->seedRadius_min = -1;
201 args_info->seedRadius_max = -1;
202 args_info->pad_help = args_info_clitkRegionGrowing_help[20] ;
203 args_info->radius_help = args_info_clitkRegionGrowing_help[21] ;
204 args_info->radius_min = -1;
205 args_info->radius_max = -1;
206 args_info->maxSD_help = args_info_clitkRegionGrowing_help[22] ;
207 args_info->full_help = args_info_clitkRegionGrowing_help[23] ;
208 args_info->iter_help = args_info_clitkRegionGrowing_help[24] ;
213 cmdline_parser_clitkRegionGrowing_print_version (void)
215 printf ("%s %s\n", CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, CMDLINE_PARSER_CLITKREGIONGROWING_VERSION);
218 static void print_help_common(void) {
219 cmdline_parser_clitkRegionGrowing_print_version ();
221 if (strlen(args_info_clitkRegionGrowing_purpose) > 0)
222 printf("\n%s\n", args_info_clitkRegionGrowing_purpose);
224 if (strlen(args_info_clitkRegionGrowing_usage) > 0)
225 printf("\n%s\n", args_info_clitkRegionGrowing_usage);
229 if (strlen(args_info_clitkRegionGrowing_description) > 0)
230 printf("%s\n", args_info_clitkRegionGrowing_description);
234 cmdline_parser_clitkRegionGrowing_print_help (void)
238 while (args_info_clitkRegionGrowing_help[i])
239 printf("%s\n", args_info_clitkRegionGrowing_help[i++]);
243 cmdline_parser_clitkRegionGrowing_init (struct args_info_clitkRegionGrowing *args_info)
245 clear_given (args_info);
246 clear_args (args_info);
247 init_args_info (args_info);
249 args_info->inputs = NULL;
250 args_info->inputs_num = 0;
254 cmdline_parser_clitkRegionGrowing_params_init(struct cmdline_parser_clitkRegionGrowing_params *params)
258 params->override = 0;
259 params->initialize = 1;
260 params->check_required = 1;
261 params->check_ambiguity = 0;
262 params->print_errors = 1;
266 struct cmdline_parser_clitkRegionGrowing_params *
267 cmdline_parser_clitkRegionGrowing_params_create(void)
269 struct cmdline_parser_clitkRegionGrowing_params *params =
270 (struct cmdline_parser_clitkRegionGrowing_params *)malloc(sizeof(struct cmdline_parser_clitkRegionGrowing_params));
271 cmdline_parser_clitkRegionGrowing_params_init(params);
276 free_string_field (char **s)
285 /** @brief generic value variable */
286 union generic_value {
292 /** @brief holds temporary values for multiple options */
295 union generic_value arg;
297 struct generic_list *next;
301 * @brief add a node at the head of the list
303 static void add_node(struct generic_list **list) {
304 struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list));
305 new_node->next = *list;
307 new_node->arg.string_arg = NULL;
308 new_node->orig = NULL;
312 free_multiple_field(unsigned int len, void **arg, char ***orig)
316 for (i = 0; i < len; ++i)
318 free_string_field(&((*orig)[i]));
330 cmdline_parser_clitkRegionGrowing_release (struct args_info_clitkRegionGrowing *args_info)
333 free_string_field (&(args_info->config_arg));
334 free_string_field (&(args_info->config_orig));
335 free_string_field (&(args_info->input_arg));
336 free_string_field (&(args_info->input_orig));
337 free_string_field (&(args_info->output_arg));
338 free_string_field (&(args_info->output_orig));
339 free_string_field (&(args_info->type_orig));
340 free_string_field (&(args_info->lower_orig));
341 free_string_field (&(args_info->upper_orig));
342 free_string_field (&(args_info->maxUpper_orig));
343 free_string_field (&(args_info->minLower_orig));
344 free_string_field (&(args_info->step_orig));
345 free_string_field (&(args_info->minStep_orig));
346 free_string_field (&(args_info->multiplier_orig));
347 free_multiple_field (args_info->seed_given, (void **)&(args_info->seed_arg), &(args_info->seed_orig));
348 free_multiple_field (args_info->seedRadius_given, (void **)&(args_info->seedRadius_arg), &(args_info->seedRadius_orig));
349 free_string_field (&(args_info->pad_orig));
350 free_multiple_field (args_info->radius_given, (void **)&(args_info->radius_arg), &(args_info->radius_orig));
351 free_string_field (&(args_info->maxSD_orig));
352 free_string_field (&(args_info->iter_orig));
355 for (i = 0; i < args_info->inputs_num; ++i)
356 free (args_info->inputs [i]);
358 if (args_info->inputs_num)
359 free (args_info->inputs);
361 clear_given (args_info);
366 write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
369 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
371 fprintf(outfile, "%s\n", opt);
376 write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[])
380 for (i = 0; i < len; ++i)
381 write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
385 cmdline_parser_clitkRegionGrowing_dump(FILE *outfile, struct args_info_clitkRegionGrowing *args_info)
391 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE);
395 if (args_info->help_given)
396 write_into_file(outfile, "help", 0, 0 );
397 if (args_info->version_given)
398 write_into_file(outfile, "version", 0, 0 );
399 if (args_info->config_given)
400 write_into_file(outfile, "config", args_info->config_orig, 0);
401 if (args_info->verbose_given)
402 write_into_file(outfile, "verbose", 0, 0 );
403 if (args_info->input_given)
404 write_into_file(outfile, "input", args_info->input_orig, 0);
405 if (args_info->output_given)
406 write_into_file(outfile, "output", args_info->output_orig, 0);
407 if (args_info->type_given)
408 write_into_file(outfile, "type", args_info->type_orig, 0);
409 if (args_info->lower_given)
410 write_into_file(outfile, "lower", args_info->lower_orig, 0);
411 if (args_info->upper_given)
412 write_into_file(outfile, "upper", args_info->upper_orig, 0);
413 if (args_info->maxUpper_given)
414 write_into_file(outfile, "maxUpper", args_info->maxUpper_orig, 0);
415 if (args_info->minLower_given)
416 write_into_file(outfile, "minLower", args_info->minLower_orig, 0);
417 if (args_info->step_given)
418 write_into_file(outfile, "step", args_info->step_orig, 0);
419 if (args_info->minStep_given)
420 write_into_file(outfile, "minStep", args_info->minStep_orig, 0);
421 if (args_info->adaptLower_given)
422 write_into_file(outfile, "adaptLower", 0, 0 );
423 if (args_info->adaptUpper_given)
424 write_into_file(outfile, "adaptUpper", 0, 0 );
425 if (args_info->multiplier_given)
426 write_into_file(outfile, "multiplier", args_info->multiplier_orig, 0);
427 write_multiple_into_file(outfile, args_info->seed_given, "seed", args_info->seed_orig, 0);
428 write_multiple_into_file(outfile, args_info->seedRadius_given, "seedRadius", args_info->seedRadius_orig, 0);
429 if (args_info->pad_given)
430 write_into_file(outfile, "pad", args_info->pad_orig, 0);
431 write_multiple_into_file(outfile, args_info->radius_given, "radius", args_info->radius_orig, 0);
432 if (args_info->maxSD_given)
433 write_into_file(outfile, "maxSD", args_info->maxSD_orig, 0);
434 if (args_info->full_given)
435 write_into_file(outfile, "full", 0, 0 );
436 if (args_info->iter_given)
437 write_into_file(outfile, "iter", args_info->iter_orig, 0);
445 cmdline_parser_clitkRegionGrowing_file_save(const char *filename, struct args_info_clitkRegionGrowing *args_info)
450 outfile = fopen(filename, "w");
454 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename);
458 i = cmdline_parser_clitkRegionGrowing_dump(outfile, args_info);
465 cmdline_parser_clitkRegionGrowing_free (struct args_info_clitkRegionGrowing *args_info)
467 cmdline_parser_clitkRegionGrowing_release (args_info);
470 /** @brief replacement of strdup, which is not standard */
472 gengetopt_strdup (const char *s)
478 result = (char*)malloc(strlen(s) + 1);
479 if (result == (char*)0)
486 get_multiple_arg_token(const char *arg)
489 size_t len, num_of_escape, i, j;
494 tok = strchr (arg, ',');
497 /* make sure it is not escaped */
500 if (*(tok-1) == '\\')
502 /* find the next one */
503 tok = strchr (tok+1, ',');
511 len = (size_t)(tok - arg + 1);
513 len = strlen (arg) + 1;
515 len -= num_of_escape;
517 ret = (char *) malloc (len);
521 while (arg[i] && (j < len-1))
523 if (arg[i] == '\\' &&
537 get_multiple_arg_token_next(const char *arg)
544 tok = strchr (arg, ',');
546 /* make sure it is not escaped */
549 if (*(tok-1) == '\\')
551 /* find the next one */
552 tok = strchr (tok+1, ',');
558 if (! tok || strlen(tok) == 1)
565 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc);
568 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc)
572 if (option_given && ! (min < 0 && max < 0))
574 if (min >= 0 && max >= 0)
578 /* specific occurrences */
579 if (option_given != min)
581 fprintf (stderr, "%s: %s option occurrences must be %d\n",
582 prog_name, option_desc, min);
586 else if (option_given < min
587 || option_given > max)
589 /* range occurrences */
590 fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n",
591 prog_name, option_desc, min, max);
598 if (option_given < min)
600 fprintf (stderr, "%s: %s option occurrences must be at least %d\n",
601 prog_name, option_desc, min);
608 if (option_given > max)
610 fprintf (stderr, "%s: %s option occurrences must be at most %d\n",
611 prog_name, option_desc, max);
620 cmdline_parser_clitkRegionGrowing (int argc, char * const *argv, struct args_info_clitkRegionGrowing *args_info)
622 return cmdline_parser_clitkRegionGrowing2 (argc, argv, args_info, 0, 1, 1);
626 cmdline_parser_clitkRegionGrowing_ext (int argc, char * const *argv, struct args_info_clitkRegionGrowing *args_info,
627 struct cmdline_parser_clitkRegionGrowing_params *params)
630 result = cmdline_parser_clitkRegionGrowing_internal (argc, argv, args_info, params, NULL);
632 if (result == EXIT_FAILURE)
634 cmdline_parser_clitkRegionGrowing_free (args_info);
642 cmdline_parser_clitkRegionGrowing2 (int argc, char * const *argv, struct args_info_clitkRegionGrowing *args_info, int override, int initialize, int check_required)
645 struct cmdline_parser_clitkRegionGrowing_params params;
647 params.override = override;
648 params.initialize = initialize;
649 params.check_required = check_required;
650 params.check_ambiguity = 0;
651 params.print_errors = 1;
653 result = cmdline_parser_clitkRegionGrowing_internal (argc, argv, args_info, ¶ms, NULL);
655 if (result == EXIT_FAILURE)
657 cmdline_parser_clitkRegionGrowing_free (args_info);
665 cmdline_parser_clitkRegionGrowing_required (struct args_info_clitkRegionGrowing *args_info, const char *prog_name)
667 int result = EXIT_SUCCESS;
669 if (cmdline_parser_clitkRegionGrowing_required2(args_info, prog_name, NULL) > 0)
670 result = EXIT_FAILURE;
672 if (result == EXIT_FAILURE)
674 cmdline_parser_clitkRegionGrowing_free (args_info);
682 cmdline_parser_clitkRegionGrowing_required2 (struct args_info_clitkRegionGrowing *args_info, const char *prog_name, const char *additional_error)
686 /* checks for required options */
687 if (! args_info->input_given)
689 fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
693 if (! args_info->output_given)
695 fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
699 if (check_multiple_option_occurrences(prog_name, args_info->seed_given, args_info->seed_min, args_info->seed_max, "'--seed' ('-s')"))
702 if (check_multiple_option_occurrences(prog_name, args_info->seedRadius_given, args_info->seedRadius_min, args_info->seedRadius_max, "'--seedRadius'"))
705 if (check_multiple_option_occurrences(prog_name, args_info->radius_given, args_info->radius_min, args_info->radius_max, "'--radius' ('-r')"))
709 /* checks for dependences among options */
715 * Extracted from the glibc source tree, version 2.3.6
717 * Licensed under the GPL as per the whole glibc source tree.
719 * This file was modified so that getopt_long can be called
720 * many times without risking previous memory to be spoiled.
722 * Modified by Andre Noll and Lorenzo Bettini for use in
723 * GNU gengetopt generated files.
728 * we must include anything we need since this file is not thought to be
729 * inserted in a file already using getopt.h
737 /* has_arg can't be an enum because some compilers complain about
738 type mismatches in all the code that assumes it is an int. */
744 /* For communication from `getopt' to the caller.
745 When `getopt' finds an option that takes an argument,
746 the argument value is returned here.
747 Also, when `ordering' is RETURN_IN_ORDER,
748 each non-option ARGV-element is returned here. */
752 /* Index in ARGV of the next element to be scanned.
753 This is used for communication to and from the caller
754 and for communication between successive calls to `getopt'.
756 On entry to `getopt', zero means this is the first call; initialize.
758 When `getopt' returns -1, this is the index of the first of the
759 non-option elements that the caller should itself scan.
761 Otherwise, `optind' communicates from one call to the next
762 how much of ARGV has been scanned so far. */
766 /* Callers store zero here to inhibit the error message `getopt' prints
767 for unrecognized options. */
771 /* Set to an option character which was unrecognized. */
775 /* This version of `getopt' appears to the caller like standard Unix `getopt'
776 but it behaves differently for the user, since it allows the user
777 to intersperse the options with the other arguments.
779 As `getopt' works, it permutes the elements of ARGV so that,
780 when it is done, all the options precede everything else. Thus
781 all application programs are extended to handle flexible argument order.
784 If the field `flag' is not NULL, it points to a variable that is set
785 to the value given in the field `val' when the option is found, but
786 left unchanged if the option is not found.
788 To have a long-named option do something other than set an `int' to
789 a compiled-in constant, such as set a value from `custom_optarg', set the
790 option's `flag' field to zero and its `val' field to a nonzero
791 value (the equivalent single-letter option character, if there is
792 one). For long options that have a zero `flag' field, `getopt'
793 returns the contents of the `val' field. */
795 /* Names for the values of the `has_arg' field of `struct option'. */
797 #define no_argument 0
800 #ifndef required_argument
801 #define required_argument 1
804 #ifndef optional_argument
805 #define optional_argument 2
808 struct custom_getopt_data {
810 * These have exactly the same meaning as the corresponding global variables,
811 * except that they are used for the reentrant versions of getopt.
818 /* True if the internal members have been initialized. */
822 * The next char to be scanned in the option-element in which the last option
823 * character we returned was found. This allows us to pick up the scan where
824 * we left off. If this is zero, or a null string, it means resume the scan by
825 * advancing to the next ARGV-element.
830 * Describe the part of ARGV that contains non-options that have been skipped.
831 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
832 * the index after the last of them.
839 * the variables optarg, optind, opterr and optopt are renamed with
840 * the custom_ prefix so that they don't interfere with getopt ones.
842 * Moreover they're static so they are visible only from within the
843 * file where this very file will be included.
847 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
848 * option that takes an argument, the argument value is returned here.
850 static char *custom_optarg;
853 * Index in ARGV of the next element to be scanned. This is used for
854 * communication to and from the caller and for communication between
855 * successive calls to `custom_getopt'.
857 * On entry to `custom_getopt', 1 means this is the first call; initialize.
859 * When `custom_getopt' returns -1, this is the index of the first of the non-option
860 * elements that the caller should itself scan.
862 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
863 * has been scanned so far.
865 * 1003.2 says this must be 1 before any call.
867 static int custom_optind = 1;
870 * Callers store zero here to inhibit the error message for unrecognized
873 static int custom_opterr = 1;
876 * Set to an option character which was unrecognized. This must be initialized
877 * on some systems to avoid linking in the system's own getopt implementation.
879 static int custom_optopt = '?';
882 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
883 * [first_nonopt,last_nonopt) which contains all the non-options that have been
884 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
885 * all the options processed since those non-options were skipped.
886 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
887 * indices of the non-options in ARGV after they are moved.
889 static void exchange(char **argv, struct custom_getopt_data *d)
891 int bottom = d->first_nonopt;
892 int middle = d->last_nonopt;
893 int top = d->custom_optind;
897 * Exchange the shorter segment with the far end of the longer segment.
898 * That puts the shorter segment into the right place. It leaves the
899 * longer segment in the right place overall, but it consists of two
900 * parts that need to be swapped next.
902 while (top > middle && middle > bottom) {
903 if (top - middle > middle - bottom) {
904 /* Bottom segment is the short one. */
905 int len = middle - bottom;
908 /* Swap it with the top part of the top segment. */
909 for (i = 0; i < len; i++) {
910 tem = argv[bottom + i];
912 argv[top - (middle - bottom) + i];
913 argv[top - (middle - bottom) + i] = tem;
915 /* Exclude the moved bottom segment from further swapping. */
918 /* Top segment is the short one. */
919 int len = top - middle;
922 /* Swap it with the bottom part of the bottom segment. */
923 for (i = 0; i < len; i++) {
924 tem = argv[bottom + i];
925 argv[bottom + i] = argv[middle + i];
926 argv[middle + i] = tem;
928 /* Exclude the moved top segment from further swapping. */
932 /* Update records for the slots the non-options now occupy. */
933 d->first_nonopt += (d->custom_optind - d->last_nonopt);
934 d->last_nonopt = d->custom_optind;
937 /* Initialize the internal data when the first call is made. */
938 static void custom_getopt_initialize(struct custom_getopt_data *d)
941 * Start processing options with ARGV-element 1 (since ARGV-element 0
942 * is the program name); the sequence of previously skipped non-option
943 * ARGV-elements is empty.
945 d->first_nonopt = d->last_nonopt = d->custom_optind;
950 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
952 /* return: zero: continue, nonzero: return given value to user */
953 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
954 struct custom_getopt_data *d)
957 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
958 * moved back by the user (who may also have changed the arguments).
960 if (d->last_nonopt > d->custom_optind)
961 d->last_nonopt = d->custom_optind;
962 if (d->first_nonopt > d->custom_optind)
963 d->first_nonopt = d->custom_optind;
965 * If we have just processed some options following some
966 * non-options, exchange them so that the options come first.
968 if (d->first_nonopt != d->last_nonopt &&
969 d->last_nonopt != d->custom_optind)
970 exchange((char **) argv, d);
971 else if (d->last_nonopt != d->custom_optind)
972 d->first_nonopt = d->custom_optind;
974 * Skip any additional non-options and extend the range of
975 * non-options previously skipped.
977 while (d->custom_optind < argc && NONOPTION_P)
979 d->last_nonopt = d->custom_optind;
981 * The special ARGV-element `--' means premature end of options. Skip
982 * it like a null option, then exchange with previous non-options as if
983 * it were an option, then skip everything else like a non-option.
985 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
987 if (d->first_nonopt != d->last_nonopt
988 && d->last_nonopt != d->custom_optind)
989 exchange((char **) argv, d);
990 else if (d->first_nonopt == d->last_nonopt)
991 d->first_nonopt = d->custom_optind;
992 d->last_nonopt = argc;
993 d->custom_optind = argc;
996 * If we have done all the ARGV-elements, stop the scan and back over
997 * any non-options that we skipped and permuted.
999 if (d->custom_optind == argc) {
1001 * Set the next-arg-index to point at the non-options that we
1002 * previously skipped, so the caller will digest them.
1004 if (d->first_nonopt != d->last_nonopt)
1005 d->custom_optind = d->first_nonopt;
1009 * If we have come to a non-option and did not permute it, either stop
1010 * the scan or describe it to the caller and pass it by.
1013 d->custom_optarg = argv[d->custom_optind++];
1017 * We have found another option-ARGV-element. Skip the initial
1020 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
1025 * Check whether the ARGV-element is a long option.
1027 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
1028 * that an abbreviation of the long option, just like "--fu", and not "-f" with
1031 * This distinction seems to be the most useful approach.
1034 static int check_long_opt(int argc, char *const *argv, const char *optstring,
1035 const struct option *longopts, int *longind,
1036 int print_errors, struct custom_getopt_data *d)
1039 const struct option *p;
1040 const struct option *pfound = NULL;
1046 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
1049 /* Test all long options for either exact match or abbreviated matches */
1050 for (p = longopts, option_index = 0; p->name; p++, option_index++)
1051 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
1052 if ((unsigned int) (nameend - d->nextchar)
1053 == (unsigned int) strlen(p->name)) {
1054 /* Exact match found. */
1056 indfound = option_index;
1059 } else if (pfound == NULL) {
1060 /* First nonexact match found. */
1062 indfound = option_index;
1063 } else if (pfound->has_arg != p->has_arg
1064 || pfound->flag != p->flag
1065 || pfound->val != p->val)
1066 /* Second or later nonexact match found. */
1069 if (ambig && !exact) {
1072 "%s: option `%s' is ambiguous\n",
1073 argv[0], argv[d->custom_optind]);
1075 d->nextchar += strlen(d->nextchar);
1077 d->custom_optopt = 0;
1081 option_index = indfound;
1084 if (pfound->has_arg != no_argument)
1085 d->custom_optarg = nameend + 1;
1088 if (argv[d->custom_optind - 1][1] == '-') {
1090 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
1091 argv[0], pfound->name);
1093 /* +option or -option */
1094 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
1095 argv[0], argv[d->custom_optind - 1][0], pfound->name);
1099 d->nextchar += strlen(d->nextchar);
1100 d->custom_optopt = pfound->val;
1103 } else if (pfound->has_arg == required_argument) {
1104 if (d->custom_optind < argc)
1105 d->custom_optarg = argv[d->custom_optind++];
1109 "%s: option `%s' requires an argument\n",
1111 argv[d->custom_optind - 1]);
1113 d->nextchar += strlen(d->nextchar);
1114 d->custom_optopt = pfound->val;
1115 return optstring[0] == ':' ? ':' : '?';
1118 d->nextchar += strlen(d->nextchar);
1119 if (longind != NULL)
1120 *longind = option_index;
1122 *(pfound->flag) = pfound->val;
1128 * Can't find it as a long option. If this is not getopt_long_only, or
1129 * the option starts with '--' or is not a valid short option, then
1130 * it's an error. Otherwise interpret it as a short option.
1133 if (argv[d->custom_optind][1] == '-') {
1136 "%s: unrecognized option `--%s'\n",
1137 argv[0], d->nextchar);
1139 /* +option or -option */
1141 "%s: unrecognized option `%c%s'\n",
1142 argv[0], argv[d->custom_optind][0],
1146 d->nextchar = (char *) "";
1148 d->custom_optopt = 0;
1152 static int check_short_opt(int argc, char *const *argv, const char *optstring,
1153 int print_errors, struct custom_getopt_data *d)
1155 char c = *d->nextchar++;
1156 char *temp = strchr(optstring, c);
1158 /* Increment `custom_optind' when we start to process its last character. */
1159 if (*d->nextchar == '\0')
1161 if (!temp || c == ':') {
1163 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
1165 d->custom_optopt = c;
1168 if (temp[1] == ':') {
1169 if (temp[2] == ':') {
1170 /* This is an option that accepts an argument optionally. */
1171 if (*d->nextchar != '\0') {
1172 d->custom_optarg = d->nextchar;
1175 d->custom_optarg = NULL;
1178 /* This is an option that requires an argument. */
1179 if (*d->nextchar != '\0') {
1180 d->custom_optarg = d->nextchar;
1182 * If we end this ARGV-element by taking the
1183 * rest as an arg, we must advance to the next
1187 } else if (d->custom_optind == argc) {
1190 "%s: option requires an argument -- %c\n",
1193 d->custom_optopt = c;
1194 if (optstring[0] == ':')
1200 * We already incremented `custom_optind' once;
1201 * increment it again when taking next ARGV-elt
1204 d->custom_optarg = argv[d->custom_optind++];
1212 * Scan elements of ARGV for option characters given in OPTSTRING.
1214 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
1215 * then it is an option element. The characters of this element
1216 * (aside from the initial '-') are option characters. If `getopt'
1217 * is called repeatedly, it returns successively each of the option characters
1218 * from each of the option elements.
1220 * If `getopt' finds another option character, it returns that character,
1221 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
1222 * resume the scan with the following option character or ARGV-element.
1224 * If there are no more option characters, `getopt' returns -1.
1225 * Then `custom_optind' is the index in ARGV of the first ARGV-element
1226 * that is not an option. (The ARGV-elements have been permuted
1227 * so that those that are not options now come last.)
1229 * OPTSTRING is a string containing the legitimate option characters.
1230 * If an option character is seen that is not listed in OPTSTRING,
1231 * return '?' after printing an error message. If you set `custom_opterr' to
1232 * zero, the error message is suppressed but we still return '?'.
1234 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
1235 * so the following text in the same ARGV-element, or the text of the following
1236 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
1237 * wants an optional arg; if there is text in the current ARGV-element,
1238 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
1240 * If OPTSTRING starts with `-' or `+', it requests different methods of
1241 * handling the non-option ARGV-elements.
1242 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
1244 * Long-named options begin with `--' instead of `-'.
1245 * Their names may be abbreviated as long as the abbreviation is unique
1246 * or is an exact match for some defined option. If they have an
1247 * argument, it follows the option name in the same ARGV-element, separated
1248 * from the option name by a `=', or else the in next ARGV-element.
1249 * When `getopt' finds a long-named option, it returns 0 if that option's
1250 * `flag' field is nonzero, the value of the option's `val' field
1251 * if the `flag' field is zero.
1253 * The elements of ARGV aren't really const, because we permute them.
1254 * But we pretend they're const in the prototype to be compatible
1255 * with other systems.
1257 * LONGOPTS is a vector of `struct option' terminated by an
1258 * element containing a name which is zero.
1260 * LONGIND returns the index in LONGOPT of the long-named option found.
1261 * It is only valid when a long-named option has been found by the most
1264 * Return the option character from OPTS just read. Return -1 when there are
1265 * no more options. For unrecognized options, or options missing arguments,
1266 * `custom_optopt' is set to the option letter, and '?' is returned.
1268 * The OPTS string is a list of characters which are recognized option letters,
1269 * optionally followed by colons, specifying that that letter takes an
1270 * argument, to be placed in `custom_optarg'.
1272 * If a letter in OPTS is followed by two colons, its argument is optional.
1273 * This behavior is specific to the GNU `getopt'.
1275 * The argument `--' causes premature termination of argument scanning,
1276 * explicitly telling `getopt' that there are no more options. If OPTS begins
1277 * with `--', then non-option arguments are treated as arguments to the option
1278 * '\0'. This behavior is specific to the GNU `getopt'.
1281 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1282 const struct option *longopts, int *longind,
1283 struct custom_getopt_data *d)
1285 int ret, print_errors = d->custom_opterr;
1287 if (optstring[0] == ':')
1291 d->custom_optarg = NULL;
1294 * This is a big difference with GNU getopt, since optind == 0
1295 * means initialization while here 1 means first call.
1297 if (d->custom_optind == 0 || !d->initialized) {
1298 if (d->custom_optind == 0)
1299 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
1300 custom_getopt_initialize(d);
1302 if (d->nextchar == NULL || *d->nextchar == '\0') {
1303 ret = shuffle_argv(argc, argv, longopts, d);
1307 if (longopts && (argv[d->custom_optind][1] == '-' ))
1308 return check_long_opt(argc, argv, optstring, longopts,
1309 longind, print_errors, d);
1310 return check_short_opt(argc, argv, optstring, print_errors, d);
1313 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1314 const struct option *longopts, int *longind)
1317 /* Keep a global copy of all internal members of d */
1318 static struct custom_getopt_data d;
1320 d.custom_optind = custom_optind;
1321 d.custom_opterr = custom_opterr;
1322 result = getopt_internal_r(argc, argv, optstring, longopts,
1324 custom_optind = d.custom_optind;
1325 custom_optarg = d.custom_optarg;
1326 custom_optopt = d.custom_optopt;
1330 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1331 const struct option *long_options, int *opt_index)
1333 return custom_getopt_internal(argc, argv, options, long_options,
1338 static char *package_name = 0;
1341 * @brief updates an option
1342 * @param field the generic pointer to the field to update
1343 * @param orig_field the pointer to the orig field
1344 * @param field_given the pointer to the number of occurrence of this option
1345 * @param prev_given the pointer to the number of occurrence already seen
1346 * @param value the argument for this option (if null no arg was specified)
1347 * @param possible_values the possible values for this option (if specified)
1348 * @param default_value the default value (in case the option only accepts fixed values)
1349 * @param arg_type the type of this option
1350 * @param check_ambiguity @see cmdline_parser_clitkRegionGrowing_params.check_ambiguity
1351 * @param override @see cmdline_parser_clitkRegionGrowing_params.override
1352 * @param no_free whether to free a possible previous value
1353 * @param multiple_option whether this is a multiple option
1354 * @param long_opt the corresponding long option
1355 * @param short_opt the corresponding short option (or '-' if none)
1356 * @param additional_error possible further error specification
1359 int update_arg(void *field, char **orig_field,
1360 unsigned int *field_given, unsigned int *prev_given,
1361 char *value, char *possible_values[], const char *default_value,
1362 cmdline_parser_clitkRegionGrowing_arg_type arg_type,
1363 int check_ambiguity, int override,
1364 int no_free, int multiple_option,
1365 const char *long_opt, char short_opt,
1366 const char *additional_error)
1368 char *stop_char = 0;
1369 const char *val = value;
1371 char **string_field;
1376 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1378 if (short_opt != '-')
1379 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1380 package_name, long_opt, short_opt,
1381 (additional_error ? additional_error : ""));
1383 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1384 package_name, long_opt,
1385 (additional_error ? additional_error : ""));
1386 return 1; /* failure */
1390 if (field_given && *field_given && ! override)
1396 if (possible_values)
1397 val = possible_values[found];
1401 *((int *)field) = !*((int *)field);
1404 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1407 if (val) *((double *)field) = strtod (val, &stop_char);
1411 string_field = (char **)field;
1412 if (!no_free && *string_field)
1413 free (*string_field); /* free previous string */
1414 *string_field = gengetopt_strdup (val);
1421 /* check numeric conversion */
1425 if (val && !(stop_char && *stop_char == '\0')) {
1426 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1427 return 1; /* failure */
1434 /* store the original value */
1440 if (value && orig_field) {
1442 *orig_field = value;
1445 free (*orig_field); /* free previous string */
1446 *orig_field = gengetopt_strdup (value);
1455 * @brief store information about a multiple option in a temporary list
1456 * @param list where to (temporarily) store multiple options
1459 int update_multiple_arg_temp(struct generic_list **list,
1460 unsigned int *prev_given, const char *val,
1461 char *possible_values[], const char *default_value,
1462 cmdline_parser_clitkRegionGrowing_arg_type arg_type,
1463 const char *long_opt, char short_opt,
1464 const char *additional_error)
1466 char *multi_token, *multi_next; /* store single arguments */
1468 if (arg_type == ARG_NO) {
1473 multi_token = get_multiple_arg_token(val);
1474 multi_next = get_multiple_arg_token_next (val);
1479 if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0,
1480 prev_given, multi_token, possible_values, default_value,
1481 arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
1482 if (multi_token) free(multi_token);
1483 return 1; /* failure */
1488 multi_token = get_multiple_arg_token(multi_next);
1489 multi_next = get_multiple_arg_token_next (multi_next);
1499 * @brief free the passed list (including possible string argument)
1502 void free_list(struct generic_list *list, short string_arg)
1505 struct generic_list *tmp;
1509 if (string_arg && list->arg.string_arg)
1510 free (list->arg.string_arg);
1520 * @brief updates a multiple option starting from the passed list
1523 void update_multiple_arg(void *field, char ***orig_field,
1524 unsigned int field_given, unsigned int prev_given, union generic_value *default_value,
1525 cmdline_parser_clitkRegionGrowing_arg_type arg_type,
1526 struct generic_list *list)
1529 struct generic_list *tmp;
1531 if (prev_given && list) {
1532 *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *));
1536 *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break;
1538 *((double **)field) = (double *)realloc (*((double **)field), (field_given + prev_given) * sizeof (double)); break;
1540 *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break;
1545 for (i = (prev_given - 1); i >= 0; --i)
1551 (*((int **)field))[i + field_given] = tmp->arg.int_arg; break;
1553 (*((double **)field))[i + field_given] = tmp->arg.double_arg; break;
1555 (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break;
1559 (*orig_field) [i + field_given] = list->orig;
1563 } else { /* set the default value */
1564 if (default_value && ! field_given) {
1567 if (! *((int **)field)) {
1568 *((int **)field) = (int *)malloc (sizeof (int));
1569 (*((int **)field))[0] = default_value->int_arg;
1573 if (! *((double **)field)) {
1574 *((double **)field) = (double *)malloc (sizeof (double));
1575 (*((double **)field))[0] = default_value->double_arg;
1579 if (! *((char ***)field)) {
1580 *((char ***)field) = (char **)malloc (sizeof (char *));
1581 (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg);
1586 if (!(*orig_field)) {
1587 *orig_field = (char **) malloc (sizeof (char *));
1588 (*orig_field)[0] = NULL;
1595 cmdline_parser_clitkRegionGrowing_internal (int argc, char * const *argv, struct args_info_clitkRegionGrowing *args_info,
1596 struct cmdline_parser_clitkRegionGrowing_params *params, const char *additional_error)
1598 int c; /* Character of the parsed option. */
1599 union generic_value multiple_default_value;
1601 struct generic_list * seed_list = NULL;
1602 struct generic_list * seedRadius_list = NULL;
1603 struct generic_list * radius_list = NULL;
1605 struct args_info_clitkRegionGrowing local_args_info;
1610 int check_ambiguity;
1612 package_name = argv[0];
1614 override = params->override;
1615 initialize = params->initialize;
1616 check_required = params->check_required;
1617 check_ambiguity = params->check_ambiguity;
1620 cmdline_parser_clitkRegionGrowing_init (args_info);
1622 cmdline_parser_clitkRegionGrowing_init (&local_args_info);
1626 opterr = params->print_errors;
1631 int option_index = 0;
1633 static struct option long_options[] = {
1634 { "help", 0, NULL, 'h' },
1635 { "version", 0, NULL, 'V' },
1636 { "config", 1, NULL, 0 },
1637 { "verbose", 0, NULL, 'v' },
1638 { "input", 1, NULL, 'i' },
1639 { "output", 1, NULL, 'o' },
1640 { "type", 1, NULL, 't' },
1641 { "lower", 1, NULL, 'l' },
1642 { "upper", 1, NULL, 'u' },
1643 { "maxUpper", 1, NULL, 0 },
1644 { "minLower", 1, NULL, 0 },
1645 { "step", 1, NULL, 0 },
1646 { "minStep", 1, NULL, 0 },
1647 { "adaptLower", 0, NULL, 0 },
1648 { "adaptUpper", 0, NULL, 0 },
1649 { "multiplier", 1, NULL, 'm' },
1650 { "seed", 1, NULL, 's' },
1651 { "seedRadius", 1, NULL, 0 },
1652 { "pad", 1, NULL, 'p' },
1653 { "radius", 1, NULL, 'r' },
1654 { "maxSD", 1, NULL, 0 },
1655 { "full", 0, NULL, 0 },
1656 { "iter", 1, NULL, 0 },
1657 { NULL, 0, NULL, 0 }
1660 custom_optarg = optarg;
1661 custom_optind = optind;
1662 custom_opterr = opterr;
1663 custom_optopt = optopt;
1665 c = custom_getopt_long (argc, argv, "hVvi:o:t:l:u:m:s:p:r:", long_options, &option_index);
1667 optarg = custom_optarg;
1668 optind = custom_optind;
1669 opterr = custom_opterr;
1670 optopt = custom_optopt;
1672 if (c == -1) break; /* Exit from `while (1)' loop. */
1676 case 'h': /* Print help and exit. */
1677 cmdline_parser_clitkRegionGrowing_print_help ();
1678 cmdline_parser_clitkRegionGrowing_free (&local_args_info);
1679 exit (EXIT_SUCCESS);
1681 case 'V': /* Print version and exit. */
1682 cmdline_parser_clitkRegionGrowing_print_version ();
1683 cmdline_parser_clitkRegionGrowing_free (&local_args_info);
1684 exit (EXIT_SUCCESS);
1686 case 'v': /* Verbose. */
1689 if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
1690 &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
1691 check_ambiguity, override, 1, 0, "verbose", 'v',
1696 case 'i': /* Input image filename. */
1699 if (update_arg( (void *)&(args_info->input_arg),
1700 &(args_info->input_orig), &(args_info->input_given),
1701 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1702 check_ambiguity, override, 0, 0,
1708 case 'o': /* Output image filename. */
1711 if (update_arg( (void *)&(args_info->output_arg),
1712 &(args_info->output_orig), &(args_info->output_given),
1713 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1714 check_ambiguity, override, 0, 0,
1720 case 't': /* Region growing filter type: 0=threshold , 1=neighborhood-threshold , 2=confidence , 3= locally-adaptive-threshold, 4= explosion-controlled-threshold. */
1723 if (update_arg( (void *)&(args_info->type_arg),
1724 &(args_info->type_orig), &(args_info->type_given),
1725 &(local_args_info.type_given), optarg, 0, "0", ARG_INT,
1726 check_ambiguity, override, 0, 0,
1732 case 'l': /* 1,2,3,4: Lower threshold value. */
1735 if (update_arg( (void *)&(args_info->lower_arg),
1736 &(args_info->lower_orig), &(args_info->lower_given),
1737 &(local_args_info.lower_given), optarg, 0, "310", ARG_DOUBLE,
1738 check_ambiguity, override, 0, 0,
1744 case 'u': /* 1,2,3,4: Upper threshold value. */
1747 if (update_arg( (void *)&(args_info->upper_arg),
1748 &(args_info->upper_orig), &(args_info->upper_given),
1749 &(local_args_info.upper_given), optarg, 0, "4000", ARG_DOUBLE,
1750 check_ambiguity, override, 0, 0,
1756 case 'm': /* 2-4: (2-3) accept if within mean+-mutiplier*SD, (4) explosion if size increases multiplier times. */
1759 if (update_arg( (void *)&(args_info->multiplier_arg),
1760 &(args_info->multiplier_orig), &(args_info->multiplier_given),
1761 &(local_args_info.multiplier_given), optarg, 0, "2.0", ARG_DOUBLE,
1762 check_ambiguity, override, 0, 0,
1768 case 's': /* Seed index postion (in voxels). */
1770 if (update_multiple_arg_temp(&seed_list,
1771 &(local_args_info.seed_given), optarg, 0, "0", ARG_INT,
1777 case 'p': /* The replace padding value. */
1780 if (update_arg( (void *)&(args_info->pad_arg),
1781 &(args_info->pad_orig), &(args_info->pad_given),
1782 &(local_args_info.pad_given), optarg, 0, "1.0", ARG_DOUBLE,
1783 check_ambiguity, override, 0, 0,
1789 case 'r': /* 1-3: The radius of the neighborhood. */
1791 if (update_multiple_arg_temp(&radius_list,
1792 &(local_args_info.radius_given), optarg, 0, "1", ARG_INT,
1799 case 0: /* Long option with no short option */
1801 if (strcmp (long_options[option_index].name, "config") == 0)
1805 if (update_arg( (void *)&(args_info->config_arg),
1806 &(args_info->config_orig), &(args_info->config_given),
1807 &(local_args_info.config_given), optarg, 0, 0, ARG_STRING,
1808 check_ambiguity, override, 0, 0,
1814 /* 4: Maximum upper threshold value. */
1815 else if (strcmp (long_options[option_index].name, "maxUpper") == 0)
1819 if (update_arg( (void *)&(args_info->maxUpper_arg),
1820 &(args_info->maxUpper_orig), &(args_info->maxUpper_given),
1821 &(local_args_info.maxUpper_given), optarg, 0, "2000", ARG_DOUBLE,
1822 check_ambiguity, override, 0, 0,
1828 /* 4: Minimum lower threshold value. */
1829 else if (strcmp (long_options[option_index].name, "minLower") == 0)
1833 if (update_arg( (void *)&(args_info->minLower_arg),
1834 &(args_info->minLower_orig), &(args_info->minLower_given),
1835 &(local_args_info.minLower_given), optarg, 0, "-1000", ARG_DOUBLE,
1836 check_ambiguity, override, 0, 0,
1842 /* 4: Threshold step size. */
1843 else if (strcmp (long_options[option_index].name, "step") == 0)
1847 if (update_arg( (void *)&(args_info->step_arg),
1848 &(args_info->step_orig), &(args_info->step_given),
1849 &(local_args_info.step_given), optarg, 0, "64.0", ARG_DOUBLE,
1850 check_ambiguity, override, 0, 0,
1856 /* 4: Minimum threshold step size. */
1857 else if (strcmp (long_options[option_index].name, "minStep") == 0)
1861 if (update_arg( (void *)&(args_info->minStep_arg),
1862 &(args_info->minStep_orig), &(args_info->minStep_given),
1863 &(local_args_info.minStep_given), optarg, 0, "1", ARG_DOUBLE,
1864 check_ambiguity, override, 0, 0,
1870 /* 3,4: (locally) adapt lower thresholding. */
1871 else if (strcmp (long_options[option_index].name, "adaptLower") == 0)
1875 if (update_arg((void *)&(args_info->adaptLower_flag), 0, &(args_info->adaptLower_given),
1876 &(local_args_info.adaptLower_given), optarg, 0, 0, ARG_FLAG,
1877 check_ambiguity, override, 1, 0, "adaptLower", '-',
1882 /* 3,4: (locally) adapt upper thresholding. */
1883 else if (strcmp (long_options[option_index].name, "adaptUpper") == 0)
1887 if (update_arg((void *)&(args_info->adaptUpper_flag), 0, &(args_info->adaptUpper_given),
1888 &(local_args_info.adaptUpper_given), optarg, 0, 0, ARG_FLAG,
1889 check_ambiguity, override, 1, 0, "adaptUpper", '-',
1894 /* Radius used for seed dilatation(in voxel). */
1895 else if (strcmp (long_options[option_index].name, "seedRadius") == 0)
1898 if (update_multiple_arg_temp(&seedRadius_list,
1899 &(local_args_info.seedRadius_given), optarg, 0, "0", ARG_INT,
1905 /* 3: Limit to SD. */
1906 else if (strcmp (long_options[option_index].name, "maxSD") == 0)
1910 if (update_arg( (void *)&(args_info->maxSD_arg),
1911 &(args_info->maxSD_orig), &(args_info->maxSD_given),
1912 &(local_args_info.maxSD_given), optarg, 0, 0, ARG_DOUBLE,
1913 check_ambiguity, override, 0, 0,
1919 /* 4: use full connectivity (not implemented yet). */
1920 else if (strcmp (long_options[option_index].name, "full") == 0)
1924 if (update_arg((void *)&(args_info->full_flag), 0, &(args_info->full_given),
1925 &(local_args_info.full_given), optarg, 0, 0, ARG_FLAG,
1926 check_ambiguity, override, 1, 0, "full", '-',
1931 /* 2: Iterations. */
1932 else if (strcmp (long_options[option_index].name, "iter") == 0)
1936 if (update_arg( (void *)&(args_info->iter_arg),
1937 &(args_info->iter_orig), &(args_info->iter_given),
1938 &(local_args_info.iter_given), optarg, 0, "5", ARG_INT,
1939 check_ambiguity, override, 0, 0,
1947 case '?': /* Invalid option. */
1948 /* `getopt_long' already printed an error message. */
1951 default: /* bug: option not considered. */
1952 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, c, (additional_error ? additional_error : ""));
1958 update_multiple_arg((void *)&(args_info->seed_arg),
1959 &(args_info->seed_orig), args_info->seed_given,
1960 local_args_info.seed_given, 0 ,
1961 ARG_INT, seed_list);
1962 update_multiple_arg((void *)&(args_info->seedRadius_arg),
1963 &(args_info->seedRadius_orig), args_info->seedRadius_given,
1964 local_args_info.seedRadius_given, 0 ,
1965 ARG_INT, seedRadius_list);
1966 multiple_default_value.int_arg = 1;
1967 update_multiple_arg((void *)&(args_info->radius_arg),
1968 &(args_info->radius_orig), args_info->radius_given,
1969 local_args_info.radius_given, &multiple_default_value ,
1970 ARG_INT, radius_list);
1972 args_info->seed_given += local_args_info.seed_given;
1973 local_args_info.seed_given = 0;
1974 args_info->seedRadius_given += local_args_info.seedRadius_given;
1975 local_args_info.seedRadius_given = 0;
1976 args_info->radius_given += local_args_info.radius_given;
1977 local_args_info.radius_given = 0;
1981 error += cmdline_parser_clitkRegionGrowing_required2 (args_info, argv[0], additional_error);
1984 cmdline_parser_clitkRegionGrowing_release (&local_args_info);
1987 return (EXIT_FAILURE);
1992 int found_prog_name = 0;
1993 /* whether program name, i.e., argv[0], is in the remaining args
1994 (this may happen with some implementations of getopt,
1995 but surely not with the one included by gengetopt) */
1998 args_info->inputs_num = argc - optind - found_prog_name;
2000 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
2001 while (optind < argc)
2002 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
2008 free_list (seed_list, 0 );
2009 free_list (seedRadius_list, 0 );
2010 free_list (radius_list, 0 );
2012 cmdline_parser_clitkRegionGrowing_release (&local_args_info);
2013 return (EXIT_FAILURE);
2016 #ifndef CONFIG_FILE_LINE_SIZE
2017 #define CONFIG_FILE_LINE_SIZE 2048
2019 #define ADDITIONAL_ERROR " in configuration file "
2021 #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
2022 /* 3 is for "--" and "=" */
2025 _cmdline_parser_clitkRegionGrowing_configfile (char * const filename, int *my_argc)
2028 char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
2029 char linebuf[CONFIG_FILE_LINE_SIZE];
2031 int result = 0, equal;
2034 size_t len, next_token;
2037 if ((file = fopen(filename, "r")) == NULL)
2039 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
2040 CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename);
2041 return EXIT_FAILURE;
2044 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
2048 len = strlen(linebuf);
2049 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
2051 fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
2052 CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename, line_num);
2053 result = EXIT_FAILURE;
2057 /* find first non-whitespace character in the line */
2058 next_token = strspn (linebuf, " \t\r\n");
2059 str_index = linebuf + next_token;
2061 if ( str_index[0] == '\0' || str_index[0] == '#')
2062 continue; /* empty line or comment line is skipped */
2066 /* truncate fopt at the end of the first non-valid character */
2067 next_token = strcspn (fopt, " \t\r\n=");
2069 if (fopt[next_token] == '\0') /* the line is over */
2076 /* remember if equal sign is present */
2077 equal = (fopt[next_token] == '=');
2078 fopt[next_token++] = '\0';
2080 /* advance pointers to the next token after the end of fopt */
2081 next_token += strspn (fopt + next_token, " \t\r\n");
2083 /* check for the presence of equal sign, and if so, skip it */
2085 if ((equal = (fopt[next_token] == '=')))
2088 next_token += strspn (fopt + next_token, " \t\r\n");
2090 str_index += next_token;
2094 if ( farg[0] == '\"' || farg[0] == '\'' )
2095 { /* quoted argument */
2096 str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
2101 "%s:%s:%d: unterminated string in configuration file\n",
2102 CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename, line_num);
2103 result = EXIT_FAILURE;
2108 { /* read up the remaining part up to a delimiter */
2109 next_token = strcspn (farg, " \t\r\n#\'\"");
2110 str_index += next_token;
2113 /* truncate farg at the delimiter and store it for further check */
2114 delimiter = *str_index, *str_index++ = '\0';
2116 /* everything but comment is illegal at the end of line */
2117 if (delimiter != '\0' && delimiter != '#')
2119 str_index += strspn(str_index, " \t\r\n");
2120 if (*str_index != '\0' && *str_index != '#')
2124 "%s:%s:%d: malformed string in configuration file\n",
2125 CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename, line_num);
2126 result = EXIT_FAILURE;
2132 if (!strcmp(fopt,"include")) {
2133 if (farg && *farg) {
2134 result = _cmdline_parser_clitkRegionGrowing_configfile(farg, my_argc);
2136 fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n",
2137 CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename, line_num);
2142 strcat (my_argv, len > 1 ? "--" : "-");
2143 strcat (my_argv, fopt);
2144 if (len > 1 && ((farg && *farg) || equal))
2145 strcat (my_argv, "=");
2147 strcat (my_argv, farg);
2150 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
2151 cmd_line_list_tmp->next = cmd_line_list;
2152 cmd_line_list = cmd_line_list_tmp;
2153 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
2162 cmdline_parser_clitkRegionGrowing_configfile (char * const filename,
2163 struct args_info_clitkRegionGrowing *args_info,
2164 int override, int initialize, int check_required)
2166 struct cmdline_parser_clitkRegionGrowing_params params;
2168 params.override = override;
2169 params.initialize = initialize;
2170 params.check_required = check_required;
2171 params.check_ambiguity = 0;
2172 params.print_errors = 1;
2174 return cmdline_parser_clitkRegionGrowing_config_file (filename, args_info, ¶ms);
2178 cmdline_parser_clitkRegionGrowing_config_file (char * const filename,
2179 struct args_info_clitkRegionGrowing *args_info,
2180 struct cmdline_parser_clitkRegionGrowing_params *params)
2185 char *additional_error;
2187 /* store the program name */
2188 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
2189 cmd_line_list_tmp->next = cmd_line_list;
2190 cmd_line_list = cmd_line_list_tmp;
2191 cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE);
2193 result = _cmdline_parser_clitkRegionGrowing_configfile(filename, &my_argc);
2195 if (result != EXIT_FAILURE) {
2196 my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
2197 cmd_line_list_tmp = cmd_line_list;
2199 for (i = my_argc - 1; i >= 0; --i) {
2200 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
2201 cmd_line_list_tmp = cmd_line_list_tmp->next;
2204 my_argv_arg[my_argc] = 0;
2206 additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
2207 strcpy (additional_error, ADDITIONAL_ERROR);
2208 strcat (additional_error, filename);
2210 cmdline_parser_clitkRegionGrowing_internal (my_argc, my_argv_arg, args_info,
2214 free (additional_error);
2219 if (result == EXIT_FAILURE)
2221 cmdline_parser_clitkRegionGrowing_free (args_info);
2222 exit (EXIT_FAILURE);