2 File autogenerated by gengetopt version 2.22
3 generated with the following command:
4 /usr/local/bin/gengetopt --output-dir=/home/tbaudier/vv/vv_static/vv/vv_bin/tools --arg-struct-name=args_info_clitkMedianImageFilter --func-name=cmdline_parser_clitkMedianImageFilter --file-name=clitkMedianImageFilter_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 "clitkMedianImageFilter_ggo.h"
23 const char *args_info_clitkMedianImageFilter_purpose = "";
25 const char *args_info_clitkMedianImageFilter_usage = "Usage: clitkMedianImageFilter [OPTIONS]... [FILES]...";
27 const char *args_info_clitkMedianImageFilter_description = "";
29 const char *args_info_clitkMedianImageFilter_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 " -i, --input=STRING Input image filename",
35 " -o, --output=STRING Output image filename",
36 " -r, --radius=INT Radius in each Direction (default=`1')",
44 } cmdline_parser_clitkMedianImageFilter_arg_type;
47 void clear_given (struct args_info_clitkMedianImageFilter *args_info);
49 void clear_args (struct args_info_clitkMedianImageFilter *args_info);
52 cmdline_parser_clitkMedianImageFilter_internal (int argc, char * const *argv, struct args_info_clitkMedianImageFilter *args_info,
53 struct cmdline_parser_clitkMedianImageFilter_params *params, const char *additional_error);
56 cmdline_parser_clitkMedianImageFilter_required2 (struct args_info_clitkMedianImageFilter *args_info, const char *prog_name, const char *additional_error);
60 struct line_list * next;
63 static struct line_list *cmd_line_list = 0;
64 static struct line_list *cmd_line_list_tmp = 0;
69 /* free the list of a previous call */
72 while (cmd_line_list) {
73 cmd_line_list_tmp = cmd_line_list;
74 cmd_line_list = cmd_line_list->next;
75 free (cmd_line_list_tmp->string_arg);
76 free (cmd_line_list_tmp);
83 gengetopt_strdup (const char *s);
86 void clear_given (struct args_info_clitkMedianImageFilter *args_info)
88 args_info->help_given = 0 ;
89 args_info->version_given = 0 ;
90 args_info->config_given = 0 ;
91 args_info->verbose_given = 0 ;
92 args_info->input_given = 0 ;
93 args_info->output_given = 0 ;
94 args_info->radius_given = 0 ;
98 void clear_args (struct args_info_clitkMedianImageFilter *args_info)
100 args_info->config_arg = NULL;
101 args_info->config_orig = NULL;
102 args_info->verbose_flag = 0;
103 args_info->input_arg = NULL;
104 args_info->input_orig = NULL;
105 args_info->output_arg = NULL;
106 args_info->output_orig = NULL;
107 args_info->radius_arg = NULL;
108 args_info->radius_orig = NULL;
113 void init_args_info(struct args_info_clitkMedianImageFilter *args_info)
117 args_info->help_help = args_info_clitkMedianImageFilter_help[0] ;
118 args_info->version_help = args_info_clitkMedianImageFilter_help[1] ;
119 args_info->config_help = args_info_clitkMedianImageFilter_help[2] ;
120 args_info->verbose_help = args_info_clitkMedianImageFilter_help[3] ;
121 args_info->input_help = args_info_clitkMedianImageFilter_help[4] ;
122 args_info->output_help = args_info_clitkMedianImageFilter_help[5] ;
123 args_info->radius_help = args_info_clitkMedianImageFilter_help[6] ;
124 args_info->radius_min = -1;
125 args_info->radius_max = -1;
130 cmdline_parser_clitkMedianImageFilter_print_version (void)
132 printf ("%s %s\n", CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_VERSION);
135 static void print_help_common(void) {
136 cmdline_parser_clitkMedianImageFilter_print_version ();
138 if (strlen(args_info_clitkMedianImageFilter_purpose) > 0)
139 printf("\n%s\n", args_info_clitkMedianImageFilter_purpose);
141 if (strlen(args_info_clitkMedianImageFilter_usage) > 0)
142 printf("\n%s\n", args_info_clitkMedianImageFilter_usage);
146 if (strlen(args_info_clitkMedianImageFilter_description) > 0)
147 printf("%s\n", args_info_clitkMedianImageFilter_description);
151 cmdline_parser_clitkMedianImageFilter_print_help (void)
155 while (args_info_clitkMedianImageFilter_help[i])
156 printf("%s\n", args_info_clitkMedianImageFilter_help[i++]);
160 cmdline_parser_clitkMedianImageFilter_init (struct args_info_clitkMedianImageFilter *args_info)
162 clear_given (args_info);
163 clear_args (args_info);
164 init_args_info (args_info);
166 args_info->inputs = NULL;
167 args_info->inputs_num = 0;
171 cmdline_parser_clitkMedianImageFilter_params_init(struct cmdline_parser_clitkMedianImageFilter_params *params)
175 params->override = 0;
176 params->initialize = 1;
177 params->check_required = 1;
178 params->check_ambiguity = 0;
179 params->print_errors = 1;
183 struct cmdline_parser_clitkMedianImageFilter_params *
184 cmdline_parser_clitkMedianImageFilter_params_create(void)
186 struct cmdline_parser_clitkMedianImageFilter_params *params =
187 (struct cmdline_parser_clitkMedianImageFilter_params *)malloc(sizeof(struct cmdline_parser_clitkMedianImageFilter_params));
188 cmdline_parser_clitkMedianImageFilter_params_init(params);
193 free_string_field (char **s)
202 /** @brief generic value variable */
203 union generic_value {
208 /** @brief holds temporary values for multiple options */
211 union generic_value arg;
213 struct generic_list *next;
217 * @brief add a node at the head of the list
219 static void add_node(struct generic_list **list) {
220 struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list));
221 new_node->next = *list;
223 new_node->arg.string_arg = NULL;
224 new_node->orig = NULL;
228 free_multiple_field(unsigned int len, void **arg, char ***orig)
232 for (i = 0; i < len; ++i)
234 free_string_field(&((*orig)[i]));
246 cmdline_parser_clitkMedianImageFilter_release (struct args_info_clitkMedianImageFilter *args_info)
249 free_string_field (&(args_info->config_arg));
250 free_string_field (&(args_info->config_orig));
251 free_string_field (&(args_info->input_arg));
252 free_string_field (&(args_info->input_orig));
253 free_string_field (&(args_info->output_arg));
254 free_string_field (&(args_info->output_orig));
255 free_multiple_field (args_info->radius_given, (void **)&(args_info->radius_arg), &(args_info->radius_orig));
258 for (i = 0; i < args_info->inputs_num; ++i)
259 free (args_info->inputs [i]);
261 if (args_info->inputs_num)
262 free (args_info->inputs);
264 clear_given (args_info);
269 write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
272 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
274 fprintf(outfile, "%s\n", opt);
279 write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[])
283 for (i = 0; i < len; ++i)
284 write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
288 cmdline_parser_clitkMedianImageFilter_dump(FILE *outfile, struct args_info_clitkMedianImageFilter *args_info)
294 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE);
298 if (args_info->help_given)
299 write_into_file(outfile, "help", 0, 0 );
300 if (args_info->version_given)
301 write_into_file(outfile, "version", 0, 0 );
302 if (args_info->config_given)
303 write_into_file(outfile, "config", args_info->config_orig, 0);
304 if (args_info->verbose_given)
305 write_into_file(outfile, "verbose", 0, 0 );
306 if (args_info->input_given)
307 write_into_file(outfile, "input", args_info->input_orig, 0);
308 if (args_info->output_given)
309 write_into_file(outfile, "output", args_info->output_orig, 0);
310 write_multiple_into_file(outfile, args_info->radius_given, "radius", args_info->radius_orig, 0);
318 cmdline_parser_clitkMedianImageFilter_file_save(const char *filename, struct args_info_clitkMedianImageFilter *args_info)
323 outfile = fopen(filename, "w");
327 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename);
331 i = cmdline_parser_clitkMedianImageFilter_dump(outfile, args_info);
338 cmdline_parser_clitkMedianImageFilter_free (struct args_info_clitkMedianImageFilter *args_info)
340 cmdline_parser_clitkMedianImageFilter_release (args_info);
343 /** @brief replacement of strdup, which is not standard */
345 gengetopt_strdup (const char *s)
351 result = (char*)malloc(strlen(s) + 1);
352 if (result == (char*)0)
359 get_multiple_arg_token(const char *arg)
362 size_t len, num_of_escape, i, j;
367 tok = strchr (arg, ',');
370 /* make sure it is not escaped */
373 if (*(tok-1) == '\\')
375 /* find the next one */
376 tok = strchr (tok+1, ',');
384 len = (size_t)(tok - arg + 1);
386 len = strlen (arg) + 1;
388 len -= num_of_escape;
390 ret = (char *) malloc (len);
394 while (arg[i] && (j < len-1))
396 if (arg[i] == '\\' &&
410 get_multiple_arg_token_next(const char *arg)
417 tok = strchr (arg, ',');
419 /* make sure it is not escaped */
422 if (*(tok-1) == '\\')
424 /* find the next one */
425 tok = strchr (tok+1, ',');
431 if (! tok || strlen(tok) == 1)
438 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc);
441 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc)
445 if (option_given && ! (min < 0 && max < 0))
447 if (min >= 0 && max >= 0)
451 /* specific occurrences */
452 if (option_given != min)
454 fprintf (stderr, "%s: %s option occurrences must be %d\n",
455 prog_name, option_desc, min);
459 else if (option_given < min
460 || option_given > max)
462 /* range occurrences */
463 fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n",
464 prog_name, option_desc, min, max);
471 if (option_given < min)
473 fprintf (stderr, "%s: %s option occurrences must be at least %d\n",
474 prog_name, option_desc, min);
481 if (option_given > max)
483 fprintf (stderr, "%s: %s option occurrences must be at most %d\n",
484 prog_name, option_desc, max);
493 cmdline_parser_clitkMedianImageFilter (int argc, char * const *argv, struct args_info_clitkMedianImageFilter *args_info)
495 return cmdline_parser_clitkMedianImageFilter2 (argc, argv, args_info, 0, 1, 1);
499 cmdline_parser_clitkMedianImageFilter_ext (int argc, char * const *argv, struct args_info_clitkMedianImageFilter *args_info,
500 struct cmdline_parser_clitkMedianImageFilter_params *params)
503 result = cmdline_parser_clitkMedianImageFilter_internal (argc, argv, args_info, params, NULL);
505 if (result == EXIT_FAILURE)
507 cmdline_parser_clitkMedianImageFilter_free (args_info);
515 cmdline_parser_clitkMedianImageFilter2 (int argc, char * const *argv, struct args_info_clitkMedianImageFilter *args_info, int override, int initialize, int check_required)
518 struct cmdline_parser_clitkMedianImageFilter_params params;
520 params.override = override;
521 params.initialize = initialize;
522 params.check_required = check_required;
523 params.check_ambiguity = 0;
524 params.print_errors = 1;
526 result = cmdline_parser_clitkMedianImageFilter_internal (argc, argv, args_info, ¶ms, NULL);
528 if (result == EXIT_FAILURE)
530 cmdline_parser_clitkMedianImageFilter_free (args_info);
538 cmdline_parser_clitkMedianImageFilter_required (struct args_info_clitkMedianImageFilter *args_info, const char *prog_name)
540 int result = EXIT_SUCCESS;
542 if (cmdline_parser_clitkMedianImageFilter_required2(args_info, prog_name, NULL) > 0)
543 result = EXIT_FAILURE;
545 if (result == EXIT_FAILURE)
547 cmdline_parser_clitkMedianImageFilter_free (args_info);
555 cmdline_parser_clitkMedianImageFilter_required2 (struct args_info_clitkMedianImageFilter *args_info, const char *prog_name, const char *additional_error)
559 /* checks for required options */
560 if (! args_info->input_given)
562 fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
566 if (! args_info->output_given)
568 fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
572 if (check_multiple_option_occurrences(prog_name, args_info->radius_given, args_info->radius_min, args_info->radius_max, "'--radius' ('-r')"))
576 /* checks for dependences among options */
582 * Extracted from the glibc source tree, version 2.3.6
584 * Licensed under the GPL as per the whole glibc source tree.
586 * This file was modified so that getopt_long can be called
587 * many times without risking previous memory to be spoiled.
589 * Modified by Andre Noll and Lorenzo Bettini for use in
590 * GNU gengetopt generated files.
595 * we must include anything we need since this file is not thought to be
596 * inserted in a file already using getopt.h
604 /* has_arg can't be an enum because some compilers complain about
605 type mismatches in all the code that assumes it is an int. */
611 /* For communication from `getopt' to the caller.
612 When `getopt' finds an option that takes an argument,
613 the argument value is returned here.
614 Also, when `ordering' is RETURN_IN_ORDER,
615 each non-option ARGV-element is returned here. */
619 /* Index in ARGV of the next element to be scanned.
620 This is used for communication to and from the caller
621 and for communication between successive calls to `getopt'.
623 On entry to `getopt', zero means this is the first call; initialize.
625 When `getopt' returns -1, this is the index of the first of the
626 non-option elements that the caller should itself scan.
628 Otherwise, `optind' communicates from one call to the next
629 how much of ARGV has been scanned so far. */
633 /* Callers store zero here to inhibit the error message `getopt' prints
634 for unrecognized options. */
638 /* Set to an option character which was unrecognized. */
642 /* This version of `getopt' appears to the caller like standard Unix `getopt'
643 but it behaves differently for the user, since it allows the user
644 to intersperse the options with the other arguments.
646 As `getopt' works, it permutes the elements of ARGV so that,
647 when it is done, all the options precede everything else. Thus
648 all application programs are extended to handle flexible argument order.
651 If the field `flag' is not NULL, it points to a variable that is set
652 to the value given in the field `val' when the option is found, but
653 left unchanged if the option is not found.
655 To have a long-named option do something other than set an `int' to
656 a compiled-in constant, such as set a value from `custom_optarg', set the
657 option's `flag' field to zero and its `val' field to a nonzero
658 value (the equivalent single-letter option character, if there is
659 one). For long options that have a zero `flag' field, `getopt'
660 returns the contents of the `val' field. */
662 /* Names for the values of the `has_arg' field of `struct option'. */
664 #define no_argument 0
667 #ifndef required_argument
668 #define required_argument 1
671 #ifndef optional_argument
672 #define optional_argument 2
675 struct custom_getopt_data {
677 * These have exactly the same meaning as the corresponding global variables,
678 * except that they are used for the reentrant versions of getopt.
685 /* True if the internal members have been initialized. */
689 * The next char to be scanned in the option-element in which the last option
690 * character we returned was found. This allows us to pick up the scan where
691 * we left off. If this is zero, or a null string, it means resume the scan by
692 * advancing to the next ARGV-element.
697 * Describe the part of ARGV that contains non-options that have been skipped.
698 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
699 * the index after the last of them.
706 * the variables optarg, optind, opterr and optopt are renamed with
707 * the custom_ prefix so that they don't interfere with getopt ones.
709 * Moreover they're static so they are visible only from within the
710 * file where this very file will be included.
714 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
715 * option that takes an argument, the argument value is returned here.
717 static char *custom_optarg;
720 * Index in ARGV of the next element to be scanned. This is used for
721 * communication to and from the caller and for communication between
722 * successive calls to `custom_getopt'.
724 * On entry to `custom_getopt', 1 means this is the first call; initialize.
726 * When `custom_getopt' returns -1, this is the index of the first of the non-option
727 * elements that the caller should itself scan.
729 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
730 * has been scanned so far.
732 * 1003.2 says this must be 1 before any call.
734 static int custom_optind = 1;
737 * Callers store zero here to inhibit the error message for unrecognized
740 static int custom_opterr = 1;
743 * Set to an option character which was unrecognized. This must be initialized
744 * on some systems to avoid linking in the system's own getopt implementation.
746 static int custom_optopt = '?';
749 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
750 * [first_nonopt,last_nonopt) which contains all the non-options that have been
751 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
752 * all the options processed since those non-options were skipped.
753 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
754 * indices of the non-options in ARGV after they are moved.
756 static void exchange(char **argv, struct custom_getopt_data *d)
758 int bottom = d->first_nonopt;
759 int middle = d->last_nonopt;
760 int top = d->custom_optind;
764 * Exchange the shorter segment with the far end of the longer segment.
765 * That puts the shorter segment into the right place. It leaves the
766 * longer segment in the right place overall, but it consists of two
767 * parts that need to be swapped next.
769 while (top > middle && middle > bottom) {
770 if (top - middle > middle - bottom) {
771 /* Bottom segment is the short one. */
772 int len = middle - bottom;
775 /* Swap it with the top part of the top segment. */
776 for (i = 0; i < len; i++) {
777 tem = argv[bottom + i];
779 argv[top - (middle - bottom) + i];
780 argv[top - (middle - bottom) + i] = tem;
782 /* Exclude the moved bottom segment from further swapping. */
785 /* Top segment is the short one. */
786 int len = top - middle;
789 /* Swap it with the bottom part of the bottom segment. */
790 for (i = 0; i < len; i++) {
791 tem = argv[bottom + i];
792 argv[bottom + i] = argv[middle + i];
793 argv[middle + i] = tem;
795 /* Exclude the moved top segment from further swapping. */
799 /* Update records for the slots the non-options now occupy. */
800 d->first_nonopt += (d->custom_optind - d->last_nonopt);
801 d->last_nonopt = d->custom_optind;
804 /* Initialize the internal data when the first call is made. */
805 static void custom_getopt_initialize(struct custom_getopt_data *d)
808 * Start processing options with ARGV-element 1 (since ARGV-element 0
809 * is the program name); the sequence of previously skipped non-option
810 * ARGV-elements is empty.
812 d->first_nonopt = d->last_nonopt = d->custom_optind;
817 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
819 /* return: zero: continue, nonzero: return given value to user */
820 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
821 struct custom_getopt_data *d)
824 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
825 * moved back by the user (who may also have changed the arguments).
827 if (d->last_nonopt > d->custom_optind)
828 d->last_nonopt = d->custom_optind;
829 if (d->first_nonopt > d->custom_optind)
830 d->first_nonopt = d->custom_optind;
832 * If we have just processed some options following some
833 * non-options, exchange them so that the options come first.
835 if (d->first_nonopt != d->last_nonopt &&
836 d->last_nonopt != d->custom_optind)
837 exchange((char **) argv, d);
838 else if (d->last_nonopt != d->custom_optind)
839 d->first_nonopt = d->custom_optind;
841 * Skip any additional non-options and extend the range of
842 * non-options previously skipped.
844 while (d->custom_optind < argc && NONOPTION_P)
846 d->last_nonopt = d->custom_optind;
848 * The special ARGV-element `--' means premature end of options. Skip
849 * it like a null option, then exchange with previous non-options as if
850 * it were an option, then skip everything else like a non-option.
852 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
854 if (d->first_nonopt != d->last_nonopt
855 && d->last_nonopt != d->custom_optind)
856 exchange((char **) argv, d);
857 else if (d->first_nonopt == d->last_nonopt)
858 d->first_nonopt = d->custom_optind;
859 d->last_nonopt = argc;
860 d->custom_optind = argc;
863 * If we have done all the ARGV-elements, stop the scan and back over
864 * any non-options that we skipped and permuted.
866 if (d->custom_optind == argc) {
868 * Set the next-arg-index to point at the non-options that we
869 * previously skipped, so the caller will digest them.
871 if (d->first_nonopt != d->last_nonopt)
872 d->custom_optind = d->first_nonopt;
876 * If we have come to a non-option and did not permute it, either stop
877 * the scan or describe it to the caller and pass it by.
880 d->custom_optarg = argv[d->custom_optind++];
884 * We have found another option-ARGV-element. Skip the initial
887 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
892 * Check whether the ARGV-element is a long option.
894 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
895 * that an abbreviation of the long option, just like "--fu", and not "-f" with
898 * This distinction seems to be the most useful approach.
901 static int check_long_opt(int argc, char *const *argv, const char *optstring,
902 const struct option *longopts, int *longind,
903 int print_errors, struct custom_getopt_data *d)
906 const struct option *p;
907 const struct option *pfound = NULL;
913 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
916 /* Test all long options for either exact match or abbreviated matches */
917 for (p = longopts, option_index = 0; p->name; p++, option_index++)
918 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
919 if ((unsigned int) (nameend - d->nextchar)
920 == (unsigned int) strlen(p->name)) {
921 /* Exact match found. */
923 indfound = option_index;
926 } else if (pfound == NULL) {
927 /* First nonexact match found. */
929 indfound = option_index;
930 } else if (pfound->has_arg != p->has_arg
931 || pfound->flag != p->flag
932 || pfound->val != p->val)
933 /* Second or later nonexact match found. */
936 if (ambig && !exact) {
939 "%s: option `%s' is ambiguous\n",
940 argv[0], argv[d->custom_optind]);
942 d->nextchar += strlen(d->nextchar);
944 d->custom_optopt = 0;
948 option_index = indfound;
951 if (pfound->has_arg != no_argument)
952 d->custom_optarg = nameend + 1;
955 if (argv[d->custom_optind - 1][1] == '-') {
957 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
958 argv[0], pfound->name);
960 /* +option or -option */
961 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
962 argv[0], argv[d->custom_optind - 1][0], pfound->name);
966 d->nextchar += strlen(d->nextchar);
967 d->custom_optopt = pfound->val;
970 } else if (pfound->has_arg == required_argument) {
971 if (d->custom_optind < argc)
972 d->custom_optarg = argv[d->custom_optind++];
976 "%s: option `%s' requires an argument\n",
978 argv[d->custom_optind - 1]);
980 d->nextchar += strlen(d->nextchar);
981 d->custom_optopt = pfound->val;
982 return optstring[0] == ':' ? ':' : '?';
985 d->nextchar += strlen(d->nextchar);
987 *longind = option_index;
989 *(pfound->flag) = pfound->val;
995 * Can't find it as a long option. If this is not getopt_long_only, or
996 * the option starts with '--' or is not a valid short option, then
997 * it's an error. Otherwise interpret it as a short option.
1000 if (argv[d->custom_optind][1] == '-') {
1003 "%s: unrecognized option `--%s'\n",
1004 argv[0], d->nextchar);
1006 /* +option or -option */
1008 "%s: unrecognized option `%c%s'\n",
1009 argv[0], argv[d->custom_optind][0],
1013 d->nextchar = (char *) "";
1015 d->custom_optopt = 0;
1019 static int check_short_opt(int argc, char *const *argv, const char *optstring,
1020 int print_errors, struct custom_getopt_data *d)
1022 char c = *d->nextchar++;
1023 char *temp = strchr(optstring, c);
1025 /* Increment `custom_optind' when we start to process its last character. */
1026 if (*d->nextchar == '\0')
1028 if (!temp || c == ':') {
1030 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
1032 d->custom_optopt = c;
1035 if (temp[1] == ':') {
1036 if (temp[2] == ':') {
1037 /* This is an option that accepts an argument optionally. */
1038 if (*d->nextchar != '\0') {
1039 d->custom_optarg = d->nextchar;
1042 d->custom_optarg = NULL;
1045 /* This is an option that requires an argument. */
1046 if (*d->nextchar != '\0') {
1047 d->custom_optarg = d->nextchar;
1049 * If we end this ARGV-element by taking the
1050 * rest as an arg, we must advance to the next
1054 } else if (d->custom_optind == argc) {
1057 "%s: option requires an argument -- %c\n",
1060 d->custom_optopt = c;
1061 if (optstring[0] == ':')
1067 * We already incremented `custom_optind' once;
1068 * increment it again when taking next ARGV-elt
1071 d->custom_optarg = argv[d->custom_optind++];
1079 * Scan elements of ARGV for option characters given in OPTSTRING.
1081 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
1082 * then it is an option element. The characters of this element
1083 * (aside from the initial '-') are option characters. If `getopt'
1084 * is called repeatedly, it returns successively each of the option characters
1085 * from each of the option elements.
1087 * If `getopt' finds another option character, it returns that character,
1088 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
1089 * resume the scan with the following option character or ARGV-element.
1091 * If there are no more option characters, `getopt' returns -1.
1092 * Then `custom_optind' is the index in ARGV of the first ARGV-element
1093 * that is not an option. (The ARGV-elements have been permuted
1094 * so that those that are not options now come last.)
1096 * OPTSTRING is a string containing the legitimate option characters.
1097 * If an option character is seen that is not listed in OPTSTRING,
1098 * return '?' after printing an error message. If you set `custom_opterr' to
1099 * zero, the error message is suppressed but we still return '?'.
1101 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
1102 * so the following text in the same ARGV-element, or the text of the following
1103 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
1104 * wants an optional arg; if there is text in the current ARGV-element,
1105 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
1107 * If OPTSTRING starts with `-' or `+', it requests different methods of
1108 * handling the non-option ARGV-elements.
1109 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
1111 * Long-named options begin with `--' instead of `-'.
1112 * Their names may be abbreviated as long as the abbreviation is unique
1113 * or is an exact match for some defined option. If they have an
1114 * argument, it follows the option name in the same ARGV-element, separated
1115 * from the option name by a `=', or else the in next ARGV-element.
1116 * When `getopt' finds a long-named option, it returns 0 if that option's
1117 * `flag' field is nonzero, the value of the option's `val' field
1118 * if the `flag' field is zero.
1120 * The elements of ARGV aren't really const, because we permute them.
1121 * But we pretend they're const in the prototype to be compatible
1122 * with other systems.
1124 * LONGOPTS is a vector of `struct option' terminated by an
1125 * element containing a name which is zero.
1127 * LONGIND returns the index in LONGOPT of the long-named option found.
1128 * It is only valid when a long-named option has been found by the most
1131 * Return the option character from OPTS just read. Return -1 when there are
1132 * no more options. For unrecognized options, or options missing arguments,
1133 * `custom_optopt' is set to the option letter, and '?' is returned.
1135 * The OPTS string is a list of characters which are recognized option letters,
1136 * optionally followed by colons, specifying that that letter takes an
1137 * argument, to be placed in `custom_optarg'.
1139 * If a letter in OPTS is followed by two colons, its argument is optional.
1140 * This behavior is specific to the GNU `getopt'.
1142 * The argument `--' causes premature termination of argument scanning,
1143 * explicitly telling `getopt' that there are no more options. If OPTS begins
1144 * with `--', then non-option arguments are treated as arguments to the option
1145 * '\0'. This behavior is specific to the GNU `getopt'.
1148 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1149 const struct option *longopts, int *longind,
1150 struct custom_getopt_data *d)
1152 int ret, print_errors = d->custom_opterr;
1154 if (optstring[0] == ':')
1158 d->custom_optarg = NULL;
1161 * This is a big difference with GNU getopt, since optind == 0
1162 * means initialization while here 1 means first call.
1164 if (d->custom_optind == 0 || !d->initialized) {
1165 if (d->custom_optind == 0)
1166 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
1167 custom_getopt_initialize(d);
1169 if (d->nextchar == NULL || *d->nextchar == '\0') {
1170 ret = shuffle_argv(argc, argv, longopts, d);
1174 if (longopts && (argv[d->custom_optind][1] == '-' ))
1175 return check_long_opt(argc, argv, optstring, longopts,
1176 longind, print_errors, d);
1177 return check_short_opt(argc, argv, optstring, print_errors, d);
1180 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1181 const struct option *longopts, int *longind)
1184 /* Keep a global copy of all internal members of d */
1185 static struct custom_getopt_data d;
1187 d.custom_optind = custom_optind;
1188 d.custom_opterr = custom_opterr;
1189 result = getopt_internal_r(argc, argv, optstring, longopts,
1191 custom_optind = d.custom_optind;
1192 custom_optarg = d.custom_optarg;
1193 custom_optopt = d.custom_optopt;
1197 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1198 const struct option *long_options, int *opt_index)
1200 return custom_getopt_internal(argc, argv, options, long_options,
1205 static char *package_name = 0;
1208 * @brief updates an option
1209 * @param field the generic pointer to the field to update
1210 * @param orig_field the pointer to the orig field
1211 * @param field_given the pointer to the number of occurrence of this option
1212 * @param prev_given the pointer to the number of occurrence already seen
1213 * @param value the argument for this option (if null no arg was specified)
1214 * @param possible_values the possible values for this option (if specified)
1215 * @param default_value the default value (in case the option only accepts fixed values)
1216 * @param arg_type the type of this option
1217 * @param check_ambiguity @see cmdline_parser_clitkMedianImageFilter_params.check_ambiguity
1218 * @param override @see cmdline_parser_clitkMedianImageFilter_params.override
1219 * @param no_free whether to free a possible previous value
1220 * @param multiple_option whether this is a multiple option
1221 * @param long_opt the corresponding long option
1222 * @param short_opt the corresponding short option (or '-' if none)
1223 * @param additional_error possible further error specification
1226 int update_arg(void *field, char **orig_field,
1227 unsigned int *field_given, unsigned int *prev_given,
1228 char *value, char *possible_values[], const char *default_value,
1229 cmdline_parser_clitkMedianImageFilter_arg_type arg_type,
1230 int check_ambiguity, int override,
1231 int no_free, int multiple_option,
1232 const char *long_opt, char short_opt,
1233 const char *additional_error)
1235 char *stop_char = 0;
1236 const char *val = value;
1238 char **string_field;
1243 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1245 if (short_opt != '-')
1246 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1247 package_name, long_opt, short_opt,
1248 (additional_error ? additional_error : ""));
1250 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1251 package_name, long_opt,
1252 (additional_error ? additional_error : ""));
1253 return 1; /* failure */
1257 if (field_given && *field_given && ! override)
1263 if (possible_values)
1264 val = possible_values[found];
1268 *((int *)field) = !*((int *)field);
1271 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1275 string_field = (char **)field;
1276 if (!no_free && *string_field)
1277 free (*string_field); /* free previous string */
1278 *string_field = gengetopt_strdup (val);
1285 /* check numeric conversion */
1288 if (val && !(stop_char && *stop_char == '\0')) {
1289 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1290 return 1; /* failure */
1297 /* store the original value */
1303 if (value && orig_field) {
1305 *orig_field = value;
1308 free (*orig_field); /* free previous string */
1309 *orig_field = gengetopt_strdup (value);
1318 * @brief store information about a multiple option in a temporary list
1319 * @param list where to (temporarily) store multiple options
1322 int update_multiple_arg_temp(struct generic_list **list,
1323 unsigned int *prev_given, const char *val,
1324 char *possible_values[], const char *default_value,
1325 cmdline_parser_clitkMedianImageFilter_arg_type arg_type,
1326 const char *long_opt, char short_opt,
1327 const char *additional_error)
1329 char *multi_token, *multi_next; /* store single arguments */
1331 if (arg_type == ARG_NO) {
1336 multi_token = get_multiple_arg_token(val);
1337 multi_next = get_multiple_arg_token_next (val);
1342 if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0,
1343 prev_given, multi_token, possible_values, default_value,
1344 arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
1345 if (multi_token) free(multi_token);
1346 return 1; /* failure */
1351 multi_token = get_multiple_arg_token(multi_next);
1352 multi_next = get_multiple_arg_token_next (multi_next);
1362 * @brief free the passed list (including possible string argument)
1365 void free_list(struct generic_list *list, short string_arg)
1368 struct generic_list *tmp;
1372 if (string_arg && list->arg.string_arg)
1373 free (list->arg.string_arg);
1383 * @brief updates a multiple option starting from the passed list
1386 void update_multiple_arg(void *field, char ***orig_field,
1387 unsigned int field_given, unsigned int prev_given, union generic_value *default_value,
1388 cmdline_parser_clitkMedianImageFilter_arg_type arg_type,
1389 struct generic_list *list)
1392 struct generic_list *tmp;
1394 if (prev_given && list) {
1395 *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *));
1399 *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break;
1401 *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break;
1406 for (i = (prev_given - 1); i >= 0; --i)
1412 (*((int **)field))[i + field_given] = tmp->arg.int_arg; break;
1414 (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break;
1418 (*orig_field) [i + field_given] = list->orig;
1422 } else { /* set the default value */
1423 if (default_value && ! field_given) {
1426 if (! *((int **)field)) {
1427 *((int **)field) = (int *)malloc (sizeof (int));
1428 (*((int **)field))[0] = default_value->int_arg;
1432 if (! *((char ***)field)) {
1433 *((char ***)field) = (char **)malloc (sizeof (char *));
1434 (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg);
1439 if (!(*orig_field)) {
1440 *orig_field = (char **) malloc (sizeof (char *));
1441 (*orig_field)[0] = NULL;
1448 cmdline_parser_clitkMedianImageFilter_internal (int argc, char * const *argv, struct args_info_clitkMedianImageFilter *args_info,
1449 struct cmdline_parser_clitkMedianImageFilter_params *params, const char *additional_error)
1451 int c; /* Character of the parsed option. */
1452 union generic_value multiple_default_value;
1454 struct generic_list * radius_list = NULL;
1456 struct args_info_clitkMedianImageFilter local_args_info;
1461 int check_ambiguity;
1463 package_name = argv[0];
1465 override = params->override;
1466 initialize = params->initialize;
1467 check_required = params->check_required;
1468 check_ambiguity = params->check_ambiguity;
1471 cmdline_parser_clitkMedianImageFilter_init (args_info);
1473 cmdline_parser_clitkMedianImageFilter_init (&local_args_info);
1477 opterr = params->print_errors;
1482 int option_index = 0;
1484 static struct option long_options[] = {
1485 { "help", 0, NULL, 'h' },
1486 { "version", 0, NULL, 'V' },
1487 { "config", 1, NULL, 0 },
1488 { "verbose", 0, NULL, 'v' },
1489 { "input", 1, NULL, 'i' },
1490 { "output", 1, NULL, 'o' },
1491 { "radius", 1, NULL, 'r' },
1492 { NULL, 0, NULL, 0 }
1495 custom_optarg = optarg;
1496 custom_optind = optind;
1497 custom_opterr = opterr;
1498 custom_optopt = optopt;
1500 c = custom_getopt_long (argc, argv, "hVvi:o:r:", long_options, &option_index);
1502 optarg = custom_optarg;
1503 optind = custom_optind;
1504 opterr = custom_opterr;
1505 optopt = custom_optopt;
1507 if (c == -1) break; /* Exit from `while (1)' loop. */
1511 case 'h': /* Print help and exit. */
1512 cmdline_parser_clitkMedianImageFilter_print_help ();
1513 cmdline_parser_clitkMedianImageFilter_free (&local_args_info);
1514 exit (EXIT_SUCCESS);
1516 case 'V': /* Print version and exit. */
1517 cmdline_parser_clitkMedianImageFilter_print_version ();
1518 cmdline_parser_clitkMedianImageFilter_free (&local_args_info);
1519 exit (EXIT_SUCCESS);
1521 case 'v': /* Verbose. */
1524 if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
1525 &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
1526 check_ambiguity, override, 1, 0, "verbose", 'v',
1531 case 'i': /* Input image filename. */
1534 if (update_arg( (void *)&(args_info->input_arg),
1535 &(args_info->input_orig), &(args_info->input_given),
1536 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1537 check_ambiguity, override, 0, 0,
1543 case 'o': /* Output image filename. */
1546 if (update_arg( (void *)&(args_info->output_arg),
1547 &(args_info->output_orig), &(args_info->output_given),
1548 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1549 check_ambiguity, override, 0, 0,
1555 case 'r': /* Radius in each Direction. */
1557 if (update_multiple_arg_temp(&radius_list,
1558 &(local_args_info.radius_given), optarg, 0, "1", ARG_INT,
1565 case 0: /* Long option with no short option */
1567 if (strcmp (long_options[option_index].name, "config") == 0)
1571 if (update_arg( (void *)&(args_info->config_arg),
1572 &(args_info->config_orig), &(args_info->config_given),
1573 &(local_args_info.config_given), optarg, 0, 0, ARG_STRING,
1574 check_ambiguity, override, 0, 0,
1582 case '?': /* Invalid option. */
1583 /* `getopt_long' already printed an error message. */
1586 default: /* bug: option not considered. */
1587 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, c, (additional_error ? additional_error : ""));
1593 multiple_default_value.int_arg = 1;
1594 update_multiple_arg((void *)&(args_info->radius_arg),
1595 &(args_info->radius_orig), args_info->radius_given,
1596 local_args_info.radius_given, &multiple_default_value ,
1597 ARG_INT, radius_list);
1599 args_info->radius_given += local_args_info.radius_given;
1600 local_args_info.radius_given = 0;
1604 error += cmdline_parser_clitkMedianImageFilter_required2 (args_info, argv[0], additional_error);
1607 cmdline_parser_clitkMedianImageFilter_release (&local_args_info);
1610 return (EXIT_FAILURE);
1615 int found_prog_name = 0;
1616 /* whether program name, i.e., argv[0], is in the remaining args
1617 (this may happen with some implementations of getopt,
1618 but surely not with the one included by gengetopt) */
1621 args_info->inputs_num = argc - optind - found_prog_name;
1623 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1624 while (optind < argc)
1625 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1631 free_list (radius_list, 0 );
1633 cmdline_parser_clitkMedianImageFilter_release (&local_args_info);
1634 return (EXIT_FAILURE);
1637 #ifndef CONFIG_FILE_LINE_SIZE
1638 #define CONFIG_FILE_LINE_SIZE 2048
1640 #define ADDITIONAL_ERROR " in configuration file "
1642 #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1643 /* 3 is for "--" and "=" */
1646 _cmdline_parser_clitkMedianImageFilter_configfile (char * const filename, int *my_argc)
1649 char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
1650 char linebuf[CONFIG_FILE_LINE_SIZE];
1652 int result = 0, equal;
1655 size_t len, next_token;
1658 if ((file = fopen(filename, "r")) == NULL)
1660 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
1661 CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename);
1662 return EXIT_FAILURE;
1665 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
1669 len = strlen(linebuf);
1670 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
1672 fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
1673 CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename, line_num);
1674 result = EXIT_FAILURE;
1678 /* find first non-whitespace character in the line */
1679 next_token = strspn (linebuf, " \t\r\n");
1680 str_index = linebuf + next_token;
1682 if ( str_index[0] == '\0' || str_index[0] == '#')
1683 continue; /* empty line or comment line is skipped */
1687 /* truncate fopt at the end of the first non-valid character */
1688 next_token = strcspn (fopt, " \t\r\n=");
1690 if (fopt[next_token] == '\0') /* the line is over */
1697 /* remember if equal sign is present */
1698 equal = (fopt[next_token] == '=');
1699 fopt[next_token++] = '\0';
1701 /* advance pointers to the next token after the end of fopt */
1702 next_token += strspn (fopt + next_token, " \t\r\n");
1704 /* check for the presence of equal sign, and if so, skip it */
1706 if ((equal = (fopt[next_token] == '=')))
1709 next_token += strspn (fopt + next_token, " \t\r\n");
1711 str_index += next_token;
1715 if ( farg[0] == '\"' || farg[0] == '\'' )
1716 { /* quoted argument */
1717 str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
1722 "%s:%s:%d: unterminated string in configuration file\n",
1723 CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename, line_num);
1724 result = EXIT_FAILURE;
1729 { /* read up the remaining part up to a delimiter */
1730 next_token = strcspn (farg, " \t\r\n#\'\"");
1731 str_index += next_token;
1734 /* truncate farg at the delimiter and store it for further check */
1735 delimiter = *str_index, *str_index++ = '\0';
1737 /* everything but comment is illegal at the end of line */
1738 if (delimiter != '\0' && delimiter != '#')
1740 str_index += strspn(str_index, " \t\r\n");
1741 if (*str_index != '\0' && *str_index != '#')
1745 "%s:%s:%d: malformed string in configuration file\n",
1746 CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename, line_num);
1747 result = EXIT_FAILURE;
1753 if (!strcmp(fopt,"include")) {
1754 if (farg && *farg) {
1755 result = _cmdline_parser_clitkMedianImageFilter_configfile(farg, my_argc);
1757 fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n",
1758 CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename, line_num);
1763 strcat (my_argv, len > 1 ? "--" : "-");
1764 strcat (my_argv, fopt);
1765 if (len > 1 && ((farg && *farg) || equal))
1766 strcat (my_argv, "=");
1768 strcat (my_argv, farg);
1771 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1772 cmd_line_list_tmp->next = cmd_line_list;
1773 cmd_line_list = cmd_line_list_tmp;
1774 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
1783 cmdline_parser_clitkMedianImageFilter_configfile (char * const filename,
1784 struct args_info_clitkMedianImageFilter *args_info,
1785 int override, int initialize, int check_required)
1787 struct cmdline_parser_clitkMedianImageFilter_params params;
1789 params.override = override;
1790 params.initialize = initialize;
1791 params.check_required = check_required;
1792 params.check_ambiguity = 0;
1793 params.print_errors = 1;
1795 return cmdline_parser_clitkMedianImageFilter_config_file (filename, args_info, ¶ms);
1799 cmdline_parser_clitkMedianImageFilter_config_file (char * const filename,
1800 struct args_info_clitkMedianImageFilter *args_info,
1801 struct cmdline_parser_clitkMedianImageFilter_params *params)
1806 char *additional_error;
1808 /* store the program name */
1809 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1810 cmd_line_list_tmp->next = cmd_line_list;
1811 cmd_line_list = cmd_line_list_tmp;
1812 cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE);
1814 result = _cmdline_parser_clitkMedianImageFilter_configfile(filename, &my_argc);
1816 if (result != EXIT_FAILURE) {
1817 my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
1818 cmd_line_list_tmp = cmd_line_list;
1820 for (i = my_argc - 1; i >= 0; --i) {
1821 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
1822 cmd_line_list_tmp = cmd_line_list_tmp->next;
1825 my_argv_arg[my_argc] = 0;
1827 additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
1828 strcpy (additional_error, ADDITIONAL_ERROR);
1829 strcat (additional_error, filename);
1831 cmdline_parser_clitkMedianImageFilter_internal (my_argc, my_argv_arg, args_info,
1835 free (additional_error);
1840 if (result == EXIT_FAILURE)
1842 cmdline_parser_clitkMedianImageFilter_free (args_info);
1843 exit (EXIT_FAILURE);