From: Simon Rit Date: Fri, 24 Jun 2016 14:42:53 +0000 (+0200) Subject: Removed generated files from master branch X-Git-Tag: v1.4.0~16^2~1 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=885859f8d8534889ca95b731038ac414d36c9530;p=clitk.git Removed generated files from master branch --- diff --git a/common/clitkConfiguration.h b/common/clitkConfiguration.h deleted file mode 100644 index 705c623..0000000 --- a/common/clitkConfiguration.h +++ /dev/null @@ -1,29 +0,0 @@ -/*========================================================================= - Program: vv http://www.creatis.insa-lyon.fr/rio/vv - - Authors belong to: - - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://www.centreleonberard.fr - - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the copyright notices for more information. - - It is distributed under dual licence - - - BSD See included LICENSE.txt file - - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -===========================================================================**/ - -#ifndef clitk_configuration_h -#define clitk_configuration_h -//This file is interpreted by cmake, to define macros based on the cmake configuration options -// - - -// Global environment variables -#define OS_NAME "@CMAKE_SYSTEM@" -#define ARCHITECTURE "@CMAKE_SYSTEM_PROCESSOR@" - -#endif diff --git a/vv/tools_ggo/clitkBinarizeImage_ggo.c b/vv/tools_ggo/clitkBinarizeImage_ggo.c deleted file mode 100644 index 008da77..0000000 --- a/vv/tools_ggo/clitkBinarizeImage_ggo.c +++ /dev/null @@ -1,1686 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22 - generated with the following command: - /usr/local/bin/gengetopt --output-dir=/home/tbaudier/vv/vv_static/vv/vv_bin/tools --arg-struct-name=args_info_clitkBinarizeImage --func-name=cmdline_parser_clitkBinarizeImage --file-name=clitkBinarizeImage_ggo --unamed-opts --conf-parser --include-getopt - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - - -#include "clitkBinarizeImage_ggo.h" - -const char *args_info_clitkBinarizeImage_purpose = ""; - -const char *args_info_clitkBinarizeImage_usage = "Usage: clitkBinarizeImage [OPTIONS]... [FILES]..."; - -const char *args_info_clitkBinarizeImage_description = ""; - -const char *args_info_clitkBinarizeImage_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " --config=STRING Config file", - " -v, --verbose Verbose (default=off)", - " --imagetypes Display allowed image types (default=off)", - " -i, --input=STRING Input image filename", - " -o, --output=STRING Output image filename", - " -l, --lower=DOUBLE Lower intensity (default=min), fg is greater than this \n value", - " -u, --upper=DOUBLE Upper intensity (default=max), fg is lower than this \n value", - " --fg=DOUBLE Foreground (FG) or 'inside' value (default=`1')", - " --bg=DOUBLE Background (BG) or 'ouside' value (default=`0')", - " --mode=STRING Use FG and/or BG values (if FG, the BG is replaced by \n the input image values) (possible values=\"FG\", \n \"BG\", \"both\" default=`both')", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_DOUBLE -} cmdline_parser_clitkBinarizeImage_arg_type; - -static -void clear_given (struct args_info_clitkBinarizeImage *args_info); -static -void clear_args (struct args_info_clitkBinarizeImage *args_info); - -static int -cmdline_parser_clitkBinarizeImage_internal (int argc, char * const *argv, struct args_info_clitkBinarizeImage *args_info, - struct cmdline_parser_clitkBinarizeImage_params *params, const char *additional_error); - -static int -cmdline_parser_clitkBinarizeImage_required2 (struct args_info_clitkBinarizeImage *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -char *cmdline_parser_clitkBinarizeImage_mode_values[] = {"FG", "BG", "both", 0} ; /* Possible values for mode. */ - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct args_info_clitkBinarizeImage *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->config_given = 0 ; - args_info->verbose_given = 0 ; - args_info->imagetypes_given = 0 ; - args_info->input_given = 0 ; - args_info->output_given = 0 ; - args_info->lower_given = 0 ; - args_info->upper_given = 0 ; - args_info->fg_given = 0 ; - args_info->bg_given = 0 ; - args_info->mode_given = 0 ; -} - -static -void clear_args (struct args_info_clitkBinarizeImage *args_info) -{ - args_info->config_arg = NULL; - args_info->config_orig = NULL; - args_info->verbose_flag = 0; - args_info->imagetypes_flag = 0; - args_info->input_arg = NULL; - args_info->input_orig = NULL; - args_info->output_arg = NULL; - args_info->output_orig = NULL; - args_info->lower_orig = NULL; - args_info->upper_orig = NULL; - args_info->fg_arg = 1; - args_info->fg_orig = NULL; - args_info->bg_arg = 0; - args_info->bg_orig = NULL; - args_info->mode_arg = gengetopt_strdup ("both"); - args_info->mode_orig = NULL; - -} - -static -void init_args_info(struct args_info_clitkBinarizeImage *args_info) -{ - - - args_info->help_help = args_info_clitkBinarizeImage_help[0] ; - args_info->version_help = args_info_clitkBinarizeImage_help[1] ; - args_info->config_help = args_info_clitkBinarizeImage_help[2] ; - args_info->verbose_help = args_info_clitkBinarizeImage_help[3] ; - args_info->imagetypes_help = args_info_clitkBinarizeImage_help[4] ; - args_info->input_help = args_info_clitkBinarizeImage_help[5] ; - args_info->output_help = args_info_clitkBinarizeImage_help[6] ; - args_info->lower_help = args_info_clitkBinarizeImage_help[7] ; - args_info->upper_help = args_info_clitkBinarizeImage_help[8] ; - args_info->fg_help = args_info_clitkBinarizeImage_help[9] ; - args_info->bg_help = args_info_clitkBinarizeImage_help[10] ; - args_info->mode_help = args_info_clitkBinarizeImage_help[11] ; - -} - -void -cmdline_parser_clitkBinarizeImage_print_version (void) -{ - printf ("%s %s\n", CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE, CMDLINE_PARSER_CLITKBINARIZEIMAGE_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_clitkBinarizeImage_print_version (); - - if (strlen(args_info_clitkBinarizeImage_purpose) > 0) - printf("\n%s\n", args_info_clitkBinarizeImage_purpose); - - if (strlen(args_info_clitkBinarizeImage_usage) > 0) - printf("\n%s\n", args_info_clitkBinarizeImage_usage); - - printf("\n"); - - if (strlen(args_info_clitkBinarizeImage_description) > 0) - printf("%s\n", args_info_clitkBinarizeImage_description); -} - -void -cmdline_parser_clitkBinarizeImage_print_help (void) -{ - int i = 0; - print_help_common(); - while (args_info_clitkBinarizeImage_help[i]) - printf("%s\n", args_info_clitkBinarizeImage_help[i++]); -} - -void -cmdline_parser_clitkBinarizeImage_init (struct args_info_clitkBinarizeImage *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = NULL; - args_info->inputs_num = 0; -} - -void -cmdline_parser_clitkBinarizeImage_params_init(struct cmdline_parser_clitkBinarizeImage_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_clitkBinarizeImage_params * -cmdline_parser_clitkBinarizeImage_params_create(void) -{ - struct cmdline_parser_clitkBinarizeImage_params *params = - (struct cmdline_parser_clitkBinarizeImage_params *)malloc(sizeof(struct cmdline_parser_clitkBinarizeImage_params)); - cmdline_parser_clitkBinarizeImage_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - - -static void -cmdline_parser_clitkBinarizeImage_release (struct args_info_clitkBinarizeImage *args_info) -{ - unsigned int i; - free_string_field (&(args_info->config_arg)); - free_string_field (&(args_info->config_orig)); - free_string_field (&(args_info->input_arg)); - free_string_field (&(args_info->input_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - free_string_field (&(args_info->lower_orig)); - free_string_field (&(args_info->upper_orig)); - free_string_field (&(args_info->fg_orig)); - free_string_field (&(args_info->bg_orig)); - free_string_field (&(args_info->mode_arg)); - free_string_field (&(args_info->mode_orig)); - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - -/** - * @param val the value to check - * @param values the possible values - * @return the index of the matched value: - * -1 if no value matched, - * -2 if more than one value has matched - */ -static int -check_possible_values(const char *val, char *values[]) -{ - int i, found, last; - size_t len; - - if (!val) /* otherwise strlen() crashes below */ - return -1; /* -1 means no argument for the option */ - - found = last = 0; - - for (i = 0, len = strlen(val); values[i]; ++i) - { - if (strncmp(val, values[i], len) == 0) - { - ++found; - last = i; - if (strlen(values[i]) == len) - return i; /* exact macth no need to check more */ - } - } - - if (found == 1) /* one match: OK */ - return last; - - return (found ? -2 : -1); /* return many values or none matched */ -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) -{ - int found = -1; - if (arg) { - if (values) { - found = check_possible_values(arg, values); - } - if (found >= 0) - fprintf(outfile, "%s=\"%s\" # %s\n", opt, arg, values[found]); - else - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -cmdline_parser_clitkBinarizeImage_dump(FILE *outfile, struct args_info_clitkBinarizeImage *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->config_given) - write_into_file(outfile, "config", args_info->config_orig, 0); - if (args_info->verbose_given) - write_into_file(outfile, "verbose", 0, 0 ); - if (args_info->imagetypes_given) - write_into_file(outfile, "imagetypes", 0, 0 ); - if (args_info->input_given) - write_into_file(outfile, "input", args_info->input_orig, 0); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - if (args_info->lower_given) - write_into_file(outfile, "lower", args_info->lower_orig, 0); - if (args_info->upper_given) - write_into_file(outfile, "upper", args_info->upper_orig, 0); - if (args_info->fg_given) - write_into_file(outfile, "fg", args_info->fg_orig, 0); - if (args_info->bg_given) - write_into_file(outfile, "bg", args_info->bg_orig, 0); - if (args_info->mode_given) - write_into_file(outfile, "mode", args_info->mode_orig, cmdline_parser_clitkBinarizeImage_mode_values); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_clitkBinarizeImage_file_save(const char *filename, struct args_info_clitkBinarizeImage *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_clitkBinarizeImage_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_clitkBinarizeImage_free (struct args_info_clitkBinarizeImage *args_info) -{ - cmdline_parser_clitkBinarizeImage_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = NULL; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -cmdline_parser_clitkBinarizeImage (int argc, char * const *argv, struct args_info_clitkBinarizeImage *args_info) -{ - return cmdline_parser_clitkBinarizeImage2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_clitkBinarizeImage_ext (int argc, char * const *argv, struct args_info_clitkBinarizeImage *args_info, - struct cmdline_parser_clitkBinarizeImage_params *params) -{ - int result; - result = cmdline_parser_clitkBinarizeImage_internal (argc, argv, args_info, params, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkBinarizeImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkBinarizeImage2 (int argc, char * const *argv, struct args_info_clitkBinarizeImage *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_clitkBinarizeImage_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_clitkBinarizeImage_internal (argc, argv, args_info, ¶ms, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkBinarizeImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkBinarizeImage_required (struct args_info_clitkBinarizeImage *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_clitkBinarizeImage_required2(args_info, prog_name, NULL) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkBinarizeImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkBinarizeImage_required2 (struct args_info_clitkBinarizeImage *args_info, const char *prog_name, const char *additional_error) -{ - int error = 0; - - /* checks for required options */ - if (! args_info->input_given) - { - fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->output_given) - { - fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - - /* checks for dependences among options */ - - return error; -} - -/* - * Extracted from the glibc source tree, version 2.3.6 - * - * Licensed under the GPL as per the whole glibc source tree. - * - * This file was modified so that getopt_long can be called - * many times without risking previous memory to be spoiled. - * - * Modified by Andre Noll and Lorenzo Bettini for use in - * GNU gengetopt generated files. - * - */ - -/* - * we must include anything we need since this file is not thought to be - * inserted in a file already using getopt.h - * - * Lorenzo - */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -static char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -static int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -static int opterr; - -/* Set to an option character which was unrecognized. */ - -static int optopt; - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. -*/ -/* - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `custom_optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -/* Names for the values of the `has_arg' field of `struct option'. */ -#ifndef no_argument -#define no_argument 0 -#endif - -#ifndef required_argument -#define required_argument 1 -#endif - -#ifndef optional_argument -#define optional_argument 2 -#endif - -struct custom_getopt_data { - /* - * These have exactly the same meaning as the corresponding global variables, - * except that they are used for the reentrant versions of getopt. - */ - int custom_optind; - int custom_opterr; - int custom_optopt; - char *custom_optarg; - - /* True if the internal members have been initialized. */ - int initialized; - - /* - * The next char to be scanned in the option-element in which the last option - * character we returned was found. This allows us to pick up the scan where - * we left off. If this is zero, or a null string, it means resume the scan by - * advancing to the next ARGV-element. - */ - char *nextchar; - - /* - * Describe the part of ARGV that contains non-options that have been skipped. - * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is - * the index after the last of them. - */ - int first_nonopt; - int last_nonopt; -}; - -/* - * the variables optarg, optind, opterr and optopt are renamed with - * the custom_ prefix so that they don't interfere with getopt ones. - * - * Moreover they're static so they are visible only from within the - * file where this very file will be included. - */ - -/* - * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an - * option that takes an argument, the argument value is returned here. - */ -static char *custom_optarg; - -/* - * Index in ARGV of the next element to be scanned. This is used for - * communication to and from the caller and for communication between - * successive calls to `custom_getopt'. - * - * On entry to `custom_getopt', 1 means this is the first call; initialize. - * - * When `custom_getopt' returns -1, this is the index of the first of the non-option - * elements that the caller should itself scan. - * - * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV - * has been scanned so far. - * - * 1003.2 says this must be 1 before any call. - */ -static int custom_optind = 1; - -/* - * Callers store zero here to inhibit the error message for unrecognized - * options. - */ -static int custom_opterr = 1; - -/* - * Set to an option character which was unrecognized. This must be initialized - * on some systems to avoid linking in the system's own getopt implementation. - */ -static int custom_optopt = '?'; - -/* - * Exchange two adjacent subsequences of ARGV. One subsequence is elements - * [first_nonopt,last_nonopt) which contains all the non-options that have been - * skipped so far. The other is elements [last_nonopt,custom_optind), which contains - * all the options processed since those non-options were skipped. - * `first_nonopt' and `last_nonopt' are relocated so that they describe the new - * indices of the non-options in ARGV after they are moved. - */ -static void exchange(char **argv, struct custom_getopt_data *d) -{ - int bottom = d->first_nonopt; - int middle = d->last_nonopt; - int top = d->custom_optind; - char *tem; - - /* - * Exchange the shorter segment with the far end of the longer segment. - * That puts the shorter segment into the right place. It leaves the - * longer segment in the right place overall, but it consists of two - * parts that need to be swapped next. - */ - while (top > middle && middle > bottom) { - if (top - middle > middle - bottom) { - /* Bottom segment is the short one. */ - int len = middle - bottom; - int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = - argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } else { - /* Top segment is the short one. */ - int len = top - middle; - int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - /* Update records for the slots the non-options now occupy. */ - d->first_nonopt += (d->custom_optind - d->last_nonopt); - d->last_nonopt = d->custom_optind; -} - -/* Initialize the internal data when the first call is made. */ -static void custom_getopt_initialize(struct custom_getopt_data *d) -{ - /* - * Start processing options with ARGV-element 1 (since ARGV-element 0 - * is the program name); the sequence of previously skipped non-option - * ARGV-elements is empty. - */ - d->first_nonopt = d->last_nonopt = d->custom_optind; - d->nextchar = NULL; - d->initialized = 1; -} - -#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0') - -/* return: zero: continue, nonzero: return given value to user */ -static int shuffle_argv(int argc, char *const *argv,const struct option *longopts, - struct custom_getopt_data *d) -{ - /* - * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been - * moved back by the user (who may also have changed the arguments). - */ - if (d->last_nonopt > d->custom_optind) - d->last_nonopt = d->custom_optind; - if (d->first_nonopt > d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * If we have just processed some options following some - * non-options, exchange them so that the options come first. - */ - if (d->first_nonopt != d->last_nonopt && - d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->last_nonopt != d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * Skip any additional non-options and extend the range of - * non-options previously skipped. - */ - while (d->custom_optind < argc && NONOPTION_P) - d->custom_optind++; - d->last_nonopt = d->custom_optind; - /* - * The special ARGV-element `--' means premature end of options. Skip - * it like a null option, then exchange with previous non-options as if - * it were an option, then skip everything else like a non-option. - */ - if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) { - d->custom_optind++; - if (d->first_nonopt != d->last_nonopt - && d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->first_nonopt == d->last_nonopt) - d->first_nonopt = d->custom_optind; - d->last_nonopt = argc; - d->custom_optind = argc; - } - /* - * If we have done all the ARGV-elements, stop the scan and back over - * any non-options that we skipped and permuted. - */ - if (d->custom_optind == argc) { - /* - * Set the next-arg-index to point at the non-options that we - * previously skipped, so the caller will digest them. - */ - if (d->first_nonopt != d->last_nonopt) - d->custom_optind = d->first_nonopt; - return -1; - } - /* - * If we have come to a non-option and did not permute it, either stop - * the scan or describe it to the caller and pass it by. - */ - if (NONOPTION_P) { - d->custom_optarg = argv[d->custom_optind++]; - return 1; - } - /* - * We have found another option-ARGV-element. Skip the initial - * punctuation. - */ - d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-')); - return 0; -} - -/* - * Check whether the ARGV-element is a long option. - * - * If there's a long option "fubar" and the ARGV-element is "-fu", consider - * that an abbreviation of the long option, just like "--fu", and not "-f" with - * arg "u". - * - * This distinction seems to be the most useful approach. - * - */ -static int check_long_opt(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - int print_errors, struct custom_getopt_data *d) -{ - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match or abbreviated matches */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) { - if ((unsigned int) (nameend - d->nextchar) - == (unsigned int) strlen(p->name)) { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } else if (pfound == NULL) { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } else if (pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' is ambiguous\n", - argv[0], argv[d->custom_optind]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optind++; - d->custom_optopt = 0; - return '?'; - } - if (pfound) { - option_index = indfound; - d->custom_optind++; - if (*nameend) { - if (pfound->has_arg != no_argument) - d->custom_optarg = nameend + 1; - else { - if (print_errors) { - if (argv[d->custom_optind - 1][1] == '-') { - /* --option */ - fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[d->custom_optind - 1][0], pfound->name); - } - - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return '?'; - } - } else if (pfound->has_arg == required_argument) { - if (d->custom_optind < argc) - d->custom_optarg = argv[d->custom_optind++]; - else { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' requires an argument\n", - argv[0], - argv[d->custom_optind - 1]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->nextchar += strlen(d->nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* - * Can't find it as a long option. If this is not getopt_long_only, or - * the option starts with '--' or is not a valid short option, then - * it's an error. Otherwise interpret it as a short option. - */ - if (print_errors) { - if (argv[d->custom_optind][1] == '-') { - /* --option */ - fprintf(stderr, - "%s: unrecognized option `--%s'\n", - argv[0], d->nextchar); - } else { - /* +option or -option */ - fprintf(stderr, - "%s: unrecognized option `%c%s'\n", - argv[0], argv[d->custom_optind][0], - d->nextchar); - } - } - d->nextchar = (char *) ""; - d->custom_optind++; - d->custom_optopt = 0; - return '?'; -} - -static int check_short_opt(int argc, char *const *argv, const char *optstring, - int print_errors, struct custom_getopt_data *d) -{ - char c = *d->nextchar++; - char *temp = strchr(optstring, c); - - /* Increment `custom_optind' when we start to process its last character. */ - if (*d->nextchar == '\0') - ++d->custom_optind; - if (!temp || c == ':') { - if (print_errors) - fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); - - d->custom_optopt = c; - return '?'; - } - if (temp[1] == ':') { - if (temp[2] == ':') { - /* This is an option that accepts an argument optionally. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - d->custom_optind++; - } else - d->custom_optarg = NULL; - d->nextchar = NULL; - } else { - /* This is an option that requires an argument. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - /* - * If we end this ARGV-element by taking the - * rest as an arg, we must advance to the next - * element now. - */ - d->custom_optind++; - } else if (d->custom_optind == argc) { - if (print_errors) { - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], c); - } - d->custom_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } else - /* - * We already incremented `custom_optind' once; - * increment it again when taking next ARGV-elt - * as argument. - */ - d->custom_optarg = argv[d->custom_optind++]; - d->nextchar = NULL; - } - } - return c; -} - -/* - * Scan elements of ARGV for option characters given in OPTSTRING. - * - * If an element of ARGV starts with '-', and is not exactly "-" or "--", - * then it is an option element. The characters of this element - * (aside from the initial '-') are option characters. If `getopt' - * is called repeatedly, it returns successively each of the option characters - * from each of the option elements. - * - * If `getopt' finds another option character, it returns that character, - * updating `custom_optind' and `nextchar' so that the next call to `getopt' can - * resume the scan with the following option character or ARGV-element. - * - * If there are no more option characters, `getopt' returns -1. - * Then `custom_optind' is the index in ARGV of the first ARGV-element - * that is not an option. (The ARGV-elements have been permuted - * so that those that are not options now come last.) - * - * OPTSTRING is a string containing the legitimate option characters. - * If an option character is seen that is not listed in OPTSTRING, - * return '?' after printing an error message. If you set `custom_opterr' to - * zero, the error message is suppressed but we still return '?'. - * - * If a char in OPTSTRING is followed by a colon, that means it wants an arg, - * so the following text in the same ARGV-element, or the text of the following - * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that - * wants an optional arg; if there is text in the current ARGV-element, - * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero. - * - * If OPTSTRING starts with `-' or `+', it requests different methods of - * handling the non-option ARGV-elements. - * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - * - * Long-named options begin with `--' instead of `-'. - * Their names may be abbreviated as long as the abbreviation is unique - * or is an exact match for some defined option. If they have an - * argument, it follows the option name in the same ARGV-element, separated - * from the option name by a `=', or else the in next ARGV-element. - * When `getopt' finds a long-named option, it returns 0 if that option's - * `flag' field is nonzero, the value of the option's `val' field - * if the `flag' field is zero. - * - * The elements of ARGV aren't really const, because we permute them. - * But we pretend they're const in the prototype to be compatible - * with other systems. - * - * LONGOPTS is a vector of `struct option' terminated by an - * element containing a name which is zero. - * - * LONGIND returns the index in LONGOPT of the long-named option found. - * It is only valid when a long-named option has been found by the most - * recent call. - * - * Return the option character from OPTS just read. Return -1 when there are - * no more options. For unrecognized options, or options missing arguments, - * `custom_optopt' is set to the option letter, and '?' is returned. - * - * The OPTS string is a list of characters which are recognized option letters, - * optionally followed by colons, specifying that that letter takes an - * argument, to be placed in `custom_optarg'. - * - * If a letter in OPTS is followed by two colons, its argument is optional. - * This behavior is specific to the GNU `getopt'. - * - * The argument `--' causes premature termination of argument scanning, - * explicitly telling `getopt' that there are no more options. If OPTS begins - * with `--', then non-option arguments are treated as arguments to the option - * '\0'. This behavior is specific to the GNU `getopt'. - */ - -static int getopt_internal_r(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - struct custom_getopt_data *d) -{ - int ret, print_errors = d->custom_opterr; - - if (optstring[0] == ':') - print_errors = 0; - if (argc < 1) - return -1; - d->custom_optarg = NULL; - - /* - * This is a big difference with GNU getopt, since optind == 0 - * means initialization while here 1 means first call. - */ - if (d->custom_optind == 0 || !d->initialized) { - if (d->custom_optind == 0) - d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */ - custom_getopt_initialize(d); - } - if (d->nextchar == NULL || *d->nextchar == '\0') { - ret = shuffle_argv(argc, argv, longopts, d); - if (ret) - return ret; - } - if (longopts && (argv[d->custom_optind][1] == '-' )) - return check_long_opt(argc, argv, optstring, longopts, - longind, print_errors, d); - return check_short_opt(argc, argv, optstring, print_errors, d); -} - -static int custom_getopt_internal(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind) -{ - int result; - /* Keep a global copy of all internal members of d */ - static struct custom_getopt_data d; - - d.custom_optind = custom_optind; - d.custom_opterr = custom_opterr; - result = getopt_internal_r(argc, argv, optstring, longopts, - longind, &d); - custom_optind = d.custom_optind; - custom_optarg = d.custom_optarg; - custom_optopt = d.custom_optopt; - return result; -} - -static int custom_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return custom_getopt_internal(argc, argv, options, long_options, - opt_index); -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_clitkBinarizeImage_params.check_ambiguity - * @param override @see cmdline_parser_clitkBinarizeImage_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, - cmdline_parser_clitkBinarizeImage_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0) - { - if (short_opt != '-') - fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n", - package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n", - package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_DOUBLE: - if (val) *((double *)field) = strtod (val, &stop_char); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_DOUBLE: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -int -cmdline_parser_clitkBinarizeImage_internal (int argc, char * const *argv, struct args_info_clitkBinarizeImage *args_info, - struct cmdline_parser_clitkBinarizeImage_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error = 0; - struct args_info_clitkBinarizeImage local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_clitkBinarizeImage_init (args_info); - - cmdline_parser_clitkBinarizeImage_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "config", 1, NULL, 0 }, - { "verbose", 0, NULL, 'v' }, - { "imagetypes", 0, NULL, 0 }, - { "input", 1, NULL, 'i' }, - { "output", 1, NULL, 'o' }, - { "lower", 1, NULL, 'l' }, - { "upper", 1, NULL, 'u' }, - { "fg", 1, NULL, 0 }, - { "bg", 1, NULL, 0 }, - { "mode", 1, NULL, 0 }, - { NULL, 0, NULL, 0 } - }; - - custom_optarg = optarg; - custom_optind = optind; - custom_opterr = opterr; - custom_optopt = optopt; - - c = custom_getopt_long (argc, argv, "hVvi:o:l:u:", long_options, &option_index); - - optarg = custom_optarg; - optind = custom_optind; - opterr = custom_opterr; - optopt = custom_optopt; - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_clitkBinarizeImage_print_help (); - cmdline_parser_clitkBinarizeImage_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_clitkBinarizeImage_print_version (); - cmdline_parser_clitkBinarizeImage_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'v': /* Verbose. */ - - - if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) - goto failure; - - break; - case 'i': /* Input image filename. */ - - - if (update_arg( (void *)&(args_info->input_arg), - &(args_info->input_orig), &(args_info->input_given), - &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "input", 'i', - additional_error)) - goto failure; - - break; - case 'o': /* Output image filename. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - case 'l': /* Lower intensity (default=min), fg is greater than this value. */ - - - if (update_arg( (void *)&(args_info->lower_arg), - &(args_info->lower_orig), &(args_info->lower_given), - &(local_args_info.lower_given), optarg, 0, 0, ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "lower", 'l', - additional_error)) - goto failure; - - break; - case 'u': /* Upper intensity (default=max), fg is lower than this value. */ - - - if (update_arg( (void *)&(args_info->upper_arg), - &(args_info->upper_orig), &(args_info->upper_given), - &(local_args_info.upper_given), optarg, 0, 0, ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "upper", 'u', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Config file. */ - if (strcmp (long_options[option_index].name, "config") == 0) - { - - - if (update_arg( (void *)&(args_info->config_arg), - &(args_info->config_orig), &(args_info->config_given), - &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "config", '-', - additional_error)) - goto failure; - - } - /* Display allowed image types. */ - else if (strcmp (long_options[option_index].name, "imagetypes") == 0) - { - - - if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given), - &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "imagetypes", '-', - additional_error)) - goto failure; - - } - /* Foreground (FG) or 'inside' value. */ - else if (strcmp (long_options[option_index].name, "fg") == 0) - { - - - if (update_arg( (void *)&(args_info->fg_arg), - &(args_info->fg_orig), &(args_info->fg_given), - &(local_args_info.fg_given), optarg, 0, "1", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "fg", '-', - additional_error)) - goto failure; - - } - /* Background (BG) or 'ouside' value. */ - else if (strcmp (long_options[option_index].name, "bg") == 0) - { - - - if (update_arg( (void *)&(args_info->bg_arg), - &(args_info->bg_orig), &(args_info->bg_given), - &(local_args_info.bg_given), optarg, 0, "0", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "bg", '-', - additional_error)) - goto failure; - - } - /* Use FG and/or BG values (if FG, the BG is replaced by the input image values). */ - else if (strcmp (long_options[option_index].name, "mode") == 0) - { - - - if (update_arg( (void *)&(args_info->mode_arg), - &(args_info->mode_orig), &(args_info->mode_given), - &(local_args_info.mode_given), optarg, cmdline_parser_clitkBinarizeImage_mode_values, "both", ARG_STRING, - check_ambiguity, override, 0, 0, - "mode", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - if (check_required) - { - error += cmdline_parser_clitkBinarizeImage_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_clitkBinarizeImage_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; - } - - return 0; - -failure: - - cmdline_parser_clitkBinarizeImage_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_cmdline_parser_clitkBinarizeImage_configfile (char * const filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == NULL) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = NULL; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _cmdline_parser_clitkBinarizeImage_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -cmdline_parser_clitkBinarizeImage_configfile (char * const filename, - struct args_info_clitkBinarizeImage *args_info, - int override, int initialize, int check_required) -{ - struct cmdline_parser_clitkBinarizeImage_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return cmdline_parser_clitkBinarizeImage_config_file (filename, args_info, ¶ms); -} - -int -cmdline_parser_clitkBinarizeImage_config_file (char * const filename, - struct args_info_clitkBinarizeImage *args_info, - struct cmdline_parser_clitkBinarizeImage_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE); - - result = _cmdline_parser_clitkBinarizeImage_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - cmdline_parser_clitkBinarizeImage_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkBinarizeImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/vv/tools_ggo/clitkBinarizeImage_ggo.h b/vv/tools_ggo/clitkBinarizeImage_ggo.h deleted file mode 100644 index 2311073..0000000 --- a/vv/tools_ggo/clitkBinarizeImage_ggo.h +++ /dev/null @@ -1,233 +0,0 @@ -/** @file clitkBinarizeImage_ggo.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef CLITKBINARIZEIMAGE_GGO_H -#define CLITKBINARIZEIMAGE_GGO_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE -/** @brief the program name */ -#define CMDLINE_PARSER_CLITKBINARIZEIMAGE_PACKAGE "clitkBinarizeImage" -#endif - -#ifndef CMDLINE_PARSER_CLITKBINARIZEIMAGE_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_CLITKBINARIZEIMAGE_VERSION "1.0" -#endif - -/** @brief Where the command line options are stored */ -struct args_info_clitkBinarizeImage -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * config_arg; /**< @brief Config file. */ - char * config_orig; /**< @brief Config file original value given at command line. */ - const char *config_help; /**< @brief Config file help description. */ - int verbose_flag; /**< @brief Verbose (default=off). */ - const char *verbose_help; /**< @brief Verbose help description. */ - int imagetypes_flag; /**< @brief Display allowed image types (default=off). */ - const char *imagetypes_help; /**< @brief Display allowed image types help description. */ - char * input_arg; /**< @brief Input image filename. */ - char * input_orig; /**< @brief Input image filename original value given at command line. */ - const char *input_help; /**< @brief Input image filename help description. */ - char * output_arg; /**< @brief Output image filename. */ - char * output_orig; /**< @brief Output image filename original value given at command line. */ - const char *output_help; /**< @brief Output image filename help description. */ - double lower_arg; /**< @brief Lower intensity (default=min), fg is greater than this value. */ - char * lower_orig; /**< @brief Lower intensity (default=min), fg is greater than this value original value given at command line. */ - const char *lower_help; /**< @brief Lower intensity (default=min), fg is greater than this value help description. */ - double upper_arg; /**< @brief Upper intensity (default=max), fg is lower than this value. */ - char * upper_orig; /**< @brief Upper intensity (default=max), fg is lower than this value original value given at command line. */ - const char *upper_help; /**< @brief Upper intensity (default=max), fg is lower than this value help description. */ - double fg_arg; /**< @brief Foreground (FG) or 'inside' value (default='1'). */ - char * fg_orig; /**< @brief Foreground (FG) or 'inside' value original value given at command line. */ - const char *fg_help; /**< @brief Foreground (FG) or 'inside' value help description. */ - double bg_arg; /**< @brief Background (BG) or 'ouside' value (default='0'). */ - char * bg_orig; /**< @brief Background (BG) or 'ouside' value original value given at command line. */ - const char *bg_help; /**< @brief Background (BG) or 'ouside' value help description. */ - char * mode_arg; /**< @brief Use FG and/or BG values (if FG, the BG is replaced by the input image values) (default='both'). */ - char * mode_orig; /**< @brief Use FG and/or BG values (if FG, the BG is replaced by the input image values) original value given at command line. */ - const char *mode_help; /**< @brief Use FG and/or BG values (if FG, the BG is replaced by the input image values) help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int config_given ; /**< @brief Whether config was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int imagetypes_given ; /**< @brief Whether imagetypes was given. */ - unsigned int input_given ; /**< @brief Whether input was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int lower_given ; /**< @brief Whether lower was given. */ - unsigned int upper_given ; /**< @brief Whether upper was given. */ - unsigned int fg_given ; /**< @brief Whether fg was given. */ - unsigned int bg_given ; /**< @brief Whether bg was given. */ - unsigned int mode_given ; /**< @brief Whether mode was given. */ - - char **inputs ; /**< @brief unamed options (options without names) */ - unsigned inputs_num ; /**< @brief unamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_clitkBinarizeImage_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure args_info_clitkBinarizeImage (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure args_info_clitkBinarizeImage (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *args_info_clitkBinarizeImage_purpose; -/** @brief the usage string of the program */ -extern const char *args_info_clitkBinarizeImage_usage; -/** @brief all the lines making the help output */ -extern const char *args_info_clitkBinarizeImage_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkBinarizeImage (int argc, char * const *argv, - struct args_info_clitkBinarizeImage *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkBinarizeImage_ext() instead - */ -int cmdline_parser_clitkBinarizeImage2 (int argc, char * const *argv, - struct args_info_clitkBinarizeImage *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkBinarizeImage_ext (int argc, char * const *argv, - struct args_info_clitkBinarizeImage *args_info, - struct cmdline_parser_clitkBinarizeImage_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkBinarizeImage_dump(FILE *outfile, - struct args_info_clitkBinarizeImage *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkBinarizeImage_file_save(const char *filename, - struct args_info_clitkBinarizeImage *args_info); - -/** - * Print the help - */ -void cmdline_parser_clitkBinarizeImage_print_help(void); -/** - * Print the version - */ -void cmdline_parser_clitkBinarizeImage_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_clitkBinarizeImage_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_clitkBinarizeImage_params_init(struct cmdline_parser_clitkBinarizeImage_params *params); - -/** - * Allocates dynamically a cmdline_parser_clitkBinarizeImage_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_clitkBinarizeImage_params structure - */ -struct cmdline_parser_clitkBinarizeImage_params *cmdline_parser_clitkBinarizeImage_params_create(void); - -/** - * Initializes the passed args_info_clitkBinarizeImage structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_clitkBinarizeImage_init (struct args_info_clitkBinarizeImage *args_info); -/** - * Deallocates the string fields of the args_info_clitkBinarizeImage structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_clitkBinarizeImage_free (struct args_info_clitkBinarizeImage *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkBinarizeImage_config_file() instead - */ -int cmdline_parser_clitkBinarizeImage_configfile (char * const filename, - struct args_info_clitkBinarizeImage *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkBinarizeImage_config_file (char * const filename, - struct args_info_clitkBinarizeImage *args_info, - struct cmdline_parser_clitkBinarizeImage_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_clitkBinarizeImage_required (struct args_info_clitkBinarizeImage *args_info, - const char *prog_name); - -extern char *cmdline_parser_clitkBinarizeImage_mode_values[] ; /**< @brief Possible values for mode. */ - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CLITKBINARIZEIMAGE_GGO_H */ diff --git a/vv/tools_ggo/clitkConnectedComponentLabeling_ggo.c b/vv/tools_ggo/clitkConnectedComponentLabeling_ggo.c deleted file mode 100644 index 2ad535d..0000000 --- a/vv/tools_ggo/clitkConnectedComponentLabeling_ggo.c +++ /dev/null @@ -1,1606 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22 - generated with the following command: - /usr/local/bin/gengetopt --output-dir=/home/tbaudier/vv/vv_static/vv/vv_bin/segmentation --arg-struct-name=args_info_clitkConnectedComponentLabeling --func-name=cmdline_parser_clitkConnectedComponentLabeling --file-name=clitkConnectedComponentLabeling_ggo --unamed-opts --conf-parser --include-getopt - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - - -#include "clitkConnectedComponentLabeling_ggo.h" - -const char *args_info_clitkConnectedComponentLabeling_purpose = "Basic segmentation : connected component labeling "; - -const char *args_info_clitkConnectedComponentLabeling_usage = "Usage: clitkConnectedComponentLabeling [OPTIONS]... [FILES]..."; - -const char *args_info_clitkConnectedComponentLabeling_description = ""; - -const char *args_info_clitkConnectedComponentLabeling_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " --config=STRING Config file", - " -v, --verbose Verbose (default=off)", - " --imagetypes Display allowed image types (default=off)", - " --verboseOption Display options values (default=off)", - "\nI/O:", - " -i, --input=STRING Input image filename", - " --inputBG=INT Input Background (default=`0')", - " -o, --output=STRING Output filename", - "\nLabelize:", - " --minSize=INT Minimum component size in voxels (default=`100')", - " --full Full connecticity (default=off)", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_INT -} cmdline_parser_clitkConnectedComponentLabeling_arg_type; - -static -void clear_given (struct args_info_clitkConnectedComponentLabeling *args_info); -static -void clear_args (struct args_info_clitkConnectedComponentLabeling *args_info); - -static int -cmdline_parser_clitkConnectedComponentLabeling_internal (int argc, char * const *argv, struct args_info_clitkConnectedComponentLabeling *args_info, - struct cmdline_parser_clitkConnectedComponentLabeling_params *params, const char *additional_error); - -static int -cmdline_parser_clitkConnectedComponentLabeling_required2 (struct args_info_clitkConnectedComponentLabeling *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct args_info_clitkConnectedComponentLabeling *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->config_given = 0 ; - args_info->verbose_given = 0 ; - args_info->imagetypes_given = 0 ; - args_info->verboseOption_given = 0 ; - args_info->input_given = 0 ; - args_info->inputBG_given = 0 ; - args_info->output_given = 0 ; - args_info->minSize_given = 0 ; - args_info->full_given = 0 ; -} - -static -void clear_args (struct args_info_clitkConnectedComponentLabeling *args_info) -{ - args_info->config_arg = NULL; - args_info->config_orig = NULL; - args_info->verbose_flag = 0; - args_info->imagetypes_flag = 0; - args_info->verboseOption_flag = 0; - args_info->input_arg = NULL; - args_info->input_orig = NULL; - args_info->inputBG_arg = 0; - args_info->inputBG_orig = NULL; - args_info->output_arg = NULL; - args_info->output_orig = NULL; - args_info->minSize_arg = 100; - args_info->minSize_orig = NULL; - args_info->full_flag = 0; - -} - -static -void init_args_info(struct args_info_clitkConnectedComponentLabeling *args_info) -{ - - - args_info->help_help = args_info_clitkConnectedComponentLabeling_help[0] ; - args_info->version_help = args_info_clitkConnectedComponentLabeling_help[1] ; - args_info->config_help = args_info_clitkConnectedComponentLabeling_help[2] ; - args_info->verbose_help = args_info_clitkConnectedComponentLabeling_help[3] ; - args_info->imagetypes_help = args_info_clitkConnectedComponentLabeling_help[4] ; - args_info->verboseOption_help = args_info_clitkConnectedComponentLabeling_help[5] ; - args_info->input_help = args_info_clitkConnectedComponentLabeling_help[7] ; - args_info->inputBG_help = args_info_clitkConnectedComponentLabeling_help[8] ; - args_info->output_help = args_info_clitkConnectedComponentLabeling_help[9] ; - args_info->minSize_help = args_info_clitkConnectedComponentLabeling_help[11] ; - args_info->full_help = args_info_clitkConnectedComponentLabeling_help[12] ; - -} - -void -cmdline_parser_clitkConnectedComponentLabeling_print_version (void) -{ - printf ("%s %s\n", CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_clitkConnectedComponentLabeling_print_version (); - - if (strlen(args_info_clitkConnectedComponentLabeling_purpose) > 0) - printf("\n%s\n", args_info_clitkConnectedComponentLabeling_purpose); - - if (strlen(args_info_clitkConnectedComponentLabeling_usage) > 0) - printf("\n%s\n", args_info_clitkConnectedComponentLabeling_usage); - - printf("\n"); - - if (strlen(args_info_clitkConnectedComponentLabeling_description) > 0) - printf("%s\n", args_info_clitkConnectedComponentLabeling_description); -} - -void -cmdline_parser_clitkConnectedComponentLabeling_print_help (void) -{ - int i = 0; - print_help_common(); - while (args_info_clitkConnectedComponentLabeling_help[i]) - printf("%s\n", args_info_clitkConnectedComponentLabeling_help[i++]); -} - -void -cmdline_parser_clitkConnectedComponentLabeling_init (struct args_info_clitkConnectedComponentLabeling *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = NULL; - args_info->inputs_num = 0; -} - -void -cmdline_parser_clitkConnectedComponentLabeling_params_init(struct cmdline_parser_clitkConnectedComponentLabeling_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_clitkConnectedComponentLabeling_params * -cmdline_parser_clitkConnectedComponentLabeling_params_create(void) -{ - struct cmdline_parser_clitkConnectedComponentLabeling_params *params = - (struct cmdline_parser_clitkConnectedComponentLabeling_params *)malloc(sizeof(struct cmdline_parser_clitkConnectedComponentLabeling_params)); - cmdline_parser_clitkConnectedComponentLabeling_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - - -static void -cmdline_parser_clitkConnectedComponentLabeling_release (struct args_info_clitkConnectedComponentLabeling *args_info) -{ - unsigned int i; - free_string_field (&(args_info->config_arg)); - free_string_field (&(args_info->config_orig)); - free_string_field (&(args_info->input_arg)); - free_string_field (&(args_info->input_orig)); - free_string_field (&(args_info->inputBG_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - free_string_field (&(args_info->minSize_orig)); - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) -{ - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -cmdline_parser_clitkConnectedComponentLabeling_dump(FILE *outfile, struct args_info_clitkConnectedComponentLabeling *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->config_given) - write_into_file(outfile, "config", args_info->config_orig, 0); - if (args_info->verbose_given) - write_into_file(outfile, "verbose", 0, 0 ); - if (args_info->imagetypes_given) - write_into_file(outfile, "imagetypes", 0, 0 ); - if (args_info->verboseOption_given) - write_into_file(outfile, "verboseOption", 0, 0 ); - if (args_info->input_given) - write_into_file(outfile, "input", args_info->input_orig, 0); - if (args_info->inputBG_given) - write_into_file(outfile, "inputBG", args_info->inputBG_orig, 0); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - if (args_info->minSize_given) - write_into_file(outfile, "minSize", args_info->minSize_orig, 0); - if (args_info->full_given) - write_into_file(outfile, "full", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_clitkConnectedComponentLabeling_file_save(const char *filename, struct args_info_clitkConnectedComponentLabeling *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_clitkConnectedComponentLabeling_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_clitkConnectedComponentLabeling_free (struct args_info_clitkConnectedComponentLabeling *args_info) -{ - cmdline_parser_clitkConnectedComponentLabeling_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = NULL; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -cmdline_parser_clitkConnectedComponentLabeling (int argc, char * const *argv, struct args_info_clitkConnectedComponentLabeling *args_info) -{ - return cmdline_parser_clitkConnectedComponentLabeling2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_clitkConnectedComponentLabeling_ext (int argc, char * const *argv, struct args_info_clitkConnectedComponentLabeling *args_info, - struct cmdline_parser_clitkConnectedComponentLabeling_params *params) -{ - int result; - result = cmdline_parser_clitkConnectedComponentLabeling_internal (argc, argv, args_info, params, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkConnectedComponentLabeling_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkConnectedComponentLabeling2 (int argc, char * const *argv, struct args_info_clitkConnectedComponentLabeling *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_clitkConnectedComponentLabeling_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_clitkConnectedComponentLabeling_internal (argc, argv, args_info, ¶ms, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkConnectedComponentLabeling_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkConnectedComponentLabeling_required (struct args_info_clitkConnectedComponentLabeling *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_clitkConnectedComponentLabeling_required2(args_info, prog_name, NULL) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkConnectedComponentLabeling_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkConnectedComponentLabeling_required2 (struct args_info_clitkConnectedComponentLabeling *args_info, const char *prog_name, const char *additional_error) -{ - int error = 0; - - /* checks for required options */ - if (! args_info->input_given) - { - fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->output_given) - { - fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - - /* checks for dependences among options */ - - return error; -} - -/* - * Extracted from the glibc source tree, version 2.3.6 - * - * Licensed under the GPL as per the whole glibc source tree. - * - * This file was modified so that getopt_long can be called - * many times without risking previous memory to be spoiled. - * - * Modified by Andre Noll and Lorenzo Bettini for use in - * GNU gengetopt generated files. - * - */ - -/* - * we must include anything we need since this file is not thought to be - * inserted in a file already using getopt.h - * - * Lorenzo - */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -static char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -static int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -static int opterr; - -/* Set to an option character which was unrecognized. */ - -static int optopt; - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. -*/ -/* - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `custom_optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -/* Names for the values of the `has_arg' field of `struct option'. */ -#ifndef no_argument -#define no_argument 0 -#endif - -#ifndef required_argument -#define required_argument 1 -#endif - -#ifndef optional_argument -#define optional_argument 2 -#endif - -struct custom_getopt_data { - /* - * These have exactly the same meaning as the corresponding global variables, - * except that they are used for the reentrant versions of getopt. - */ - int custom_optind; - int custom_opterr; - int custom_optopt; - char *custom_optarg; - - /* True if the internal members have been initialized. */ - int initialized; - - /* - * The next char to be scanned in the option-element in which the last option - * character we returned was found. This allows us to pick up the scan where - * we left off. If this is zero, or a null string, it means resume the scan by - * advancing to the next ARGV-element. - */ - char *nextchar; - - /* - * Describe the part of ARGV that contains non-options that have been skipped. - * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is - * the index after the last of them. - */ - int first_nonopt; - int last_nonopt; -}; - -/* - * the variables optarg, optind, opterr and optopt are renamed with - * the custom_ prefix so that they don't interfere with getopt ones. - * - * Moreover they're static so they are visible only from within the - * file where this very file will be included. - */ - -/* - * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an - * option that takes an argument, the argument value is returned here. - */ -static char *custom_optarg; - -/* - * Index in ARGV of the next element to be scanned. This is used for - * communication to and from the caller and for communication between - * successive calls to `custom_getopt'. - * - * On entry to `custom_getopt', 1 means this is the first call; initialize. - * - * When `custom_getopt' returns -1, this is the index of the first of the non-option - * elements that the caller should itself scan. - * - * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV - * has been scanned so far. - * - * 1003.2 says this must be 1 before any call. - */ -static int custom_optind = 1; - -/* - * Callers store zero here to inhibit the error message for unrecognized - * options. - */ -static int custom_opterr = 1; - -/* - * Set to an option character which was unrecognized. This must be initialized - * on some systems to avoid linking in the system's own getopt implementation. - */ -static int custom_optopt = '?'; - -/* - * Exchange two adjacent subsequences of ARGV. One subsequence is elements - * [first_nonopt,last_nonopt) which contains all the non-options that have been - * skipped so far. The other is elements [last_nonopt,custom_optind), which contains - * all the options processed since those non-options were skipped. - * `first_nonopt' and `last_nonopt' are relocated so that they describe the new - * indices of the non-options in ARGV after they are moved. - */ -static void exchange(char **argv, struct custom_getopt_data *d) -{ - int bottom = d->first_nonopt; - int middle = d->last_nonopt; - int top = d->custom_optind; - char *tem; - - /* - * Exchange the shorter segment with the far end of the longer segment. - * That puts the shorter segment into the right place. It leaves the - * longer segment in the right place overall, but it consists of two - * parts that need to be swapped next. - */ - while (top > middle && middle > bottom) { - if (top - middle > middle - bottom) { - /* Bottom segment is the short one. */ - int len = middle - bottom; - int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = - argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } else { - /* Top segment is the short one. */ - int len = top - middle; - int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - /* Update records for the slots the non-options now occupy. */ - d->first_nonopt += (d->custom_optind - d->last_nonopt); - d->last_nonopt = d->custom_optind; -} - -/* Initialize the internal data when the first call is made. */ -static void custom_getopt_initialize(struct custom_getopt_data *d) -{ - /* - * Start processing options with ARGV-element 1 (since ARGV-element 0 - * is the program name); the sequence of previously skipped non-option - * ARGV-elements is empty. - */ - d->first_nonopt = d->last_nonopt = d->custom_optind; - d->nextchar = NULL; - d->initialized = 1; -} - -#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0') - -/* return: zero: continue, nonzero: return given value to user */ -static int shuffle_argv(int argc, char *const *argv,const struct option *longopts, - struct custom_getopt_data *d) -{ - /* - * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been - * moved back by the user (who may also have changed the arguments). - */ - if (d->last_nonopt > d->custom_optind) - d->last_nonopt = d->custom_optind; - if (d->first_nonopt > d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * If we have just processed some options following some - * non-options, exchange them so that the options come first. - */ - if (d->first_nonopt != d->last_nonopt && - d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->last_nonopt != d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * Skip any additional non-options and extend the range of - * non-options previously skipped. - */ - while (d->custom_optind < argc && NONOPTION_P) - d->custom_optind++; - d->last_nonopt = d->custom_optind; - /* - * The special ARGV-element `--' means premature end of options. Skip - * it like a null option, then exchange with previous non-options as if - * it were an option, then skip everything else like a non-option. - */ - if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) { - d->custom_optind++; - if (d->first_nonopt != d->last_nonopt - && d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->first_nonopt == d->last_nonopt) - d->first_nonopt = d->custom_optind; - d->last_nonopt = argc; - d->custom_optind = argc; - } - /* - * If we have done all the ARGV-elements, stop the scan and back over - * any non-options that we skipped and permuted. - */ - if (d->custom_optind == argc) { - /* - * Set the next-arg-index to point at the non-options that we - * previously skipped, so the caller will digest them. - */ - if (d->first_nonopt != d->last_nonopt) - d->custom_optind = d->first_nonopt; - return -1; - } - /* - * If we have come to a non-option and did not permute it, either stop - * the scan or describe it to the caller and pass it by. - */ - if (NONOPTION_P) { - d->custom_optarg = argv[d->custom_optind++]; - return 1; - } - /* - * We have found another option-ARGV-element. Skip the initial - * punctuation. - */ - d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-')); - return 0; -} - -/* - * Check whether the ARGV-element is a long option. - * - * If there's a long option "fubar" and the ARGV-element is "-fu", consider - * that an abbreviation of the long option, just like "--fu", and not "-f" with - * arg "u". - * - * This distinction seems to be the most useful approach. - * - */ -static int check_long_opt(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - int print_errors, struct custom_getopt_data *d) -{ - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match or abbreviated matches */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) { - if ((unsigned int) (nameend - d->nextchar) - == (unsigned int) strlen(p->name)) { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } else if (pfound == NULL) { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } else if (pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' is ambiguous\n", - argv[0], argv[d->custom_optind]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optind++; - d->custom_optopt = 0; - return '?'; - } - if (pfound) { - option_index = indfound; - d->custom_optind++; - if (*nameend) { - if (pfound->has_arg != no_argument) - d->custom_optarg = nameend + 1; - else { - if (print_errors) { - if (argv[d->custom_optind - 1][1] == '-') { - /* --option */ - fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[d->custom_optind - 1][0], pfound->name); - } - - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return '?'; - } - } else if (pfound->has_arg == required_argument) { - if (d->custom_optind < argc) - d->custom_optarg = argv[d->custom_optind++]; - else { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' requires an argument\n", - argv[0], - argv[d->custom_optind - 1]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->nextchar += strlen(d->nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* - * Can't find it as a long option. If this is not getopt_long_only, or - * the option starts with '--' or is not a valid short option, then - * it's an error. Otherwise interpret it as a short option. - */ - if (print_errors) { - if (argv[d->custom_optind][1] == '-') { - /* --option */ - fprintf(stderr, - "%s: unrecognized option `--%s'\n", - argv[0], d->nextchar); - } else { - /* +option or -option */ - fprintf(stderr, - "%s: unrecognized option `%c%s'\n", - argv[0], argv[d->custom_optind][0], - d->nextchar); - } - } - d->nextchar = (char *) ""; - d->custom_optind++; - d->custom_optopt = 0; - return '?'; -} - -static int check_short_opt(int argc, char *const *argv, const char *optstring, - int print_errors, struct custom_getopt_data *d) -{ - char c = *d->nextchar++; - char *temp = strchr(optstring, c); - - /* Increment `custom_optind' when we start to process its last character. */ - if (*d->nextchar == '\0') - ++d->custom_optind; - if (!temp || c == ':') { - if (print_errors) - fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); - - d->custom_optopt = c; - return '?'; - } - if (temp[1] == ':') { - if (temp[2] == ':') { - /* This is an option that accepts an argument optionally. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - d->custom_optind++; - } else - d->custom_optarg = NULL; - d->nextchar = NULL; - } else { - /* This is an option that requires an argument. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - /* - * If we end this ARGV-element by taking the - * rest as an arg, we must advance to the next - * element now. - */ - d->custom_optind++; - } else if (d->custom_optind == argc) { - if (print_errors) { - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], c); - } - d->custom_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } else - /* - * We already incremented `custom_optind' once; - * increment it again when taking next ARGV-elt - * as argument. - */ - d->custom_optarg = argv[d->custom_optind++]; - d->nextchar = NULL; - } - } - return c; -} - -/* - * Scan elements of ARGV for option characters given in OPTSTRING. - * - * If an element of ARGV starts with '-', and is not exactly "-" or "--", - * then it is an option element. The characters of this element - * (aside from the initial '-') are option characters. If `getopt' - * is called repeatedly, it returns successively each of the option characters - * from each of the option elements. - * - * If `getopt' finds another option character, it returns that character, - * updating `custom_optind' and `nextchar' so that the next call to `getopt' can - * resume the scan with the following option character or ARGV-element. - * - * If there are no more option characters, `getopt' returns -1. - * Then `custom_optind' is the index in ARGV of the first ARGV-element - * that is not an option. (The ARGV-elements have been permuted - * so that those that are not options now come last.) - * - * OPTSTRING is a string containing the legitimate option characters. - * If an option character is seen that is not listed in OPTSTRING, - * return '?' after printing an error message. If you set `custom_opterr' to - * zero, the error message is suppressed but we still return '?'. - * - * If a char in OPTSTRING is followed by a colon, that means it wants an arg, - * so the following text in the same ARGV-element, or the text of the following - * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that - * wants an optional arg; if there is text in the current ARGV-element, - * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero. - * - * If OPTSTRING starts with `-' or `+', it requests different methods of - * handling the non-option ARGV-elements. - * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - * - * Long-named options begin with `--' instead of `-'. - * Their names may be abbreviated as long as the abbreviation is unique - * or is an exact match for some defined option. If they have an - * argument, it follows the option name in the same ARGV-element, separated - * from the option name by a `=', or else the in next ARGV-element. - * When `getopt' finds a long-named option, it returns 0 if that option's - * `flag' field is nonzero, the value of the option's `val' field - * if the `flag' field is zero. - * - * The elements of ARGV aren't really const, because we permute them. - * But we pretend they're const in the prototype to be compatible - * with other systems. - * - * LONGOPTS is a vector of `struct option' terminated by an - * element containing a name which is zero. - * - * LONGIND returns the index in LONGOPT of the long-named option found. - * It is only valid when a long-named option has been found by the most - * recent call. - * - * Return the option character from OPTS just read. Return -1 when there are - * no more options. For unrecognized options, or options missing arguments, - * `custom_optopt' is set to the option letter, and '?' is returned. - * - * The OPTS string is a list of characters which are recognized option letters, - * optionally followed by colons, specifying that that letter takes an - * argument, to be placed in `custom_optarg'. - * - * If a letter in OPTS is followed by two colons, its argument is optional. - * This behavior is specific to the GNU `getopt'. - * - * The argument `--' causes premature termination of argument scanning, - * explicitly telling `getopt' that there are no more options. If OPTS begins - * with `--', then non-option arguments are treated as arguments to the option - * '\0'. This behavior is specific to the GNU `getopt'. - */ - -static int getopt_internal_r(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - struct custom_getopt_data *d) -{ - int ret, print_errors = d->custom_opterr; - - if (optstring[0] == ':') - print_errors = 0; - if (argc < 1) - return -1; - d->custom_optarg = NULL; - - /* - * This is a big difference with GNU getopt, since optind == 0 - * means initialization while here 1 means first call. - */ - if (d->custom_optind == 0 || !d->initialized) { - if (d->custom_optind == 0) - d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */ - custom_getopt_initialize(d); - } - if (d->nextchar == NULL || *d->nextchar == '\0') { - ret = shuffle_argv(argc, argv, longopts, d); - if (ret) - return ret; - } - if (longopts && (argv[d->custom_optind][1] == '-' )) - return check_long_opt(argc, argv, optstring, longopts, - longind, print_errors, d); - return check_short_opt(argc, argv, optstring, print_errors, d); -} - -static int custom_getopt_internal(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind) -{ - int result; - /* Keep a global copy of all internal members of d */ - static struct custom_getopt_data d; - - d.custom_optind = custom_optind; - d.custom_opterr = custom_opterr; - result = getopt_internal_r(argc, argv, optstring, longopts, - longind, &d); - custom_optind = d.custom_optind; - custom_optarg = d.custom_optarg; - custom_optopt = d.custom_optopt; - return result; -} - -static int custom_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return custom_getopt_internal(argc, argv, options, long_options, - opt_index); -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_clitkConnectedComponentLabeling_params.check_ambiguity - * @param override @see cmdline_parser_clitkConnectedComponentLabeling_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, - cmdline_parser_clitkConnectedComponentLabeling_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_INT: - if (val) *((int *)field) = strtol (val, &stop_char, 0); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_INT: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -int -cmdline_parser_clitkConnectedComponentLabeling_internal (int argc, char * const *argv, struct args_info_clitkConnectedComponentLabeling *args_info, - struct cmdline_parser_clitkConnectedComponentLabeling_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error = 0; - struct args_info_clitkConnectedComponentLabeling local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_clitkConnectedComponentLabeling_init (args_info); - - cmdline_parser_clitkConnectedComponentLabeling_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "config", 1, NULL, 0 }, - { "verbose", 0, NULL, 'v' }, - { "imagetypes", 0, NULL, 0 }, - { "verboseOption", 0, NULL, 0 }, - { "input", 1, NULL, 'i' }, - { "inputBG", 1, NULL, 0 }, - { "output", 1, NULL, 'o' }, - { "minSize", 1, NULL, 0 }, - { "full", 0, NULL, 0 }, - { NULL, 0, NULL, 0 } - }; - - custom_optarg = optarg; - custom_optind = optind; - custom_opterr = opterr; - custom_optopt = optopt; - - c = custom_getopt_long (argc, argv, "hVvi:o:", long_options, &option_index); - - optarg = custom_optarg; - optind = custom_optind; - opterr = custom_opterr; - optopt = custom_optopt; - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_clitkConnectedComponentLabeling_print_help (); - cmdline_parser_clitkConnectedComponentLabeling_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_clitkConnectedComponentLabeling_print_version (); - cmdline_parser_clitkConnectedComponentLabeling_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'v': /* Verbose. */ - - - if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) - goto failure; - - break; - case 'i': /* Input image filename. */ - - - if (update_arg( (void *)&(args_info->input_arg), - &(args_info->input_orig), &(args_info->input_given), - &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "input", 'i', - additional_error)) - goto failure; - - break; - case 'o': /* Output filename. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Config file. */ - if (strcmp (long_options[option_index].name, "config") == 0) - { - - - if (update_arg( (void *)&(args_info->config_arg), - &(args_info->config_orig), &(args_info->config_given), - &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "config", '-', - additional_error)) - goto failure; - - } - /* Display allowed image types. */ - else if (strcmp (long_options[option_index].name, "imagetypes") == 0) - { - - - if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given), - &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "imagetypes", '-', - additional_error)) - goto failure; - - } - /* Display options values. */ - else if (strcmp (long_options[option_index].name, "verboseOption") == 0) - { - - - if (update_arg((void *)&(args_info->verboseOption_flag), 0, &(args_info->verboseOption_given), - &(local_args_info.verboseOption_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verboseOption", '-', - additional_error)) - goto failure; - - } - /* Input Background. */ - else if (strcmp (long_options[option_index].name, "inputBG") == 0) - { - - - if (update_arg( (void *)&(args_info->inputBG_arg), - &(args_info->inputBG_orig), &(args_info->inputBG_given), - &(local_args_info.inputBG_given), optarg, 0, "0", ARG_INT, - check_ambiguity, override, 0, 0, - "inputBG", '-', - additional_error)) - goto failure; - - } - /* Minimum component size in voxels. */ - else if (strcmp (long_options[option_index].name, "minSize") == 0) - { - - - if (update_arg( (void *)&(args_info->minSize_arg), - &(args_info->minSize_orig), &(args_info->minSize_given), - &(local_args_info.minSize_given), optarg, 0, "100", ARG_INT, - check_ambiguity, override, 0, 0, - "minSize", '-', - additional_error)) - goto failure; - - } - /* Full connecticity. */ - else if (strcmp (long_options[option_index].name, "full") == 0) - { - - - if (update_arg((void *)&(args_info->full_flag), 0, &(args_info->full_given), - &(local_args_info.full_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "full", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - if (check_required) - { - error += cmdline_parser_clitkConnectedComponentLabeling_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_clitkConnectedComponentLabeling_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; - } - - return 0; - -failure: - - cmdline_parser_clitkConnectedComponentLabeling_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_cmdline_parser_clitkConnectedComponentLabeling_configfile (char * const filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == NULL) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = NULL; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _cmdline_parser_clitkConnectedComponentLabeling_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -cmdline_parser_clitkConnectedComponentLabeling_configfile (char * const filename, - struct args_info_clitkConnectedComponentLabeling *args_info, - int override, int initialize, int check_required) -{ - struct cmdline_parser_clitkConnectedComponentLabeling_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return cmdline_parser_clitkConnectedComponentLabeling_config_file (filename, args_info, ¶ms); -} - -int -cmdline_parser_clitkConnectedComponentLabeling_config_file (char * const filename, - struct args_info_clitkConnectedComponentLabeling *args_info, - struct cmdline_parser_clitkConnectedComponentLabeling_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE); - - result = _cmdline_parser_clitkConnectedComponentLabeling_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - cmdline_parser_clitkConnectedComponentLabeling_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkConnectedComponentLabeling_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/vv/tools_ggo/clitkConnectedComponentLabeling_ggo.h b/vv/tools_ggo/clitkConnectedComponentLabeling_ggo.h deleted file mode 100644 index 686eedf..0000000 --- a/vv/tools_ggo/clitkConnectedComponentLabeling_ggo.h +++ /dev/null @@ -1,225 +0,0 @@ -/** @file clitkConnectedComponentLabeling_ggo.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef CLITKCONNECTEDCOMPONENTLABELING_GGO_H -#define CLITKCONNECTEDCOMPONENTLABELING_GGO_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE -/** @brief the program name */ -#define CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_PACKAGE "clitkConnectedComponentLabeling" -#endif - -#ifndef CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_CLITKCONNECTEDCOMPONENTLABELING_VERSION "1.0" -#endif - -/** @brief Where the command line options are stored */ -struct args_info_clitkConnectedComponentLabeling -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * config_arg; /**< @brief Config file. */ - char * config_orig; /**< @brief Config file original value given at command line. */ - const char *config_help; /**< @brief Config file help description. */ - int verbose_flag; /**< @brief Verbose (default=off). */ - const char *verbose_help; /**< @brief Verbose help description. */ - int imagetypes_flag; /**< @brief Display allowed image types (default=off). */ - const char *imagetypes_help; /**< @brief Display allowed image types help description. */ - int verboseOption_flag; /**< @brief Display options values (default=off). */ - const char *verboseOption_help; /**< @brief Display options values help description. */ - char * input_arg; /**< @brief Input image filename. */ - char * input_orig; /**< @brief Input image filename original value given at command line. */ - const char *input_help; /**< @brief Input image filename help description. */ - int inputBG_arg; /**< @brief Input Background (default='0'). */ - char * inputBG_orig; /**< @brief Input Background original value given at command line. */ - const char *inputBG_help; /**< @brief Input Background help description. */ - char * output_arg; /**< @brief Output filename. */ - char * output_orig; /**< @brief Output filename original value given at command line. */ - const char *output_help; /**< @brief Output filename help description. */ - int minSize_arg; /**< @brief Minimum component size in voxels (default='100'). */ - char * minSize_orig; /**< @brief Minimum component size in voxels original value given at command line. */ - const char *minSize_help; /**< @brief Minimum component size in voxels help description. */ - int full_flag; /**< @brief Full connecticity (default=off). */ - const char *full_help; /**< @brief Full connecticity help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int config_given ; /**< @brief Whether config was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int imagetypes_given ; /**< @brief Whether imagetypes was given. */ - unsigned int verboseOption_given ; /**< @brief Whether verboseOption was given. */ - unsigned int input_given ; /**< @brief Whether input was given. */ - unsigned int inputBG_given ; /**< @brief Whether inputBG was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int minSize_given ; /**< @brief Whether minSize was given. */ - unsigned int full_given ; /**< @brief Whether full was given. */ - - char **inputs ; /**< @brief unamed options (options without names) */ - unsigned inputs_num ; /**< @brief unamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_clitkConnectedComponentLabeling_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure args_info_clitkConnectedComponentLabeling (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure args_info_clitkConnectedComponentLabeling (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *args_info_clitkConnectedComponentLabeling_purpose; -/** @brief the usage string of the program */ -extern const char *args_info_clitkConnectedComponentLabeling_usage; -/** @brief all the lines making the help output */ -extern const char *args_info_clitkConnectedComponentLabeling_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkConnectedComponentLabeling (int argc, char * const *argv, - struct args_info_clitkConnectedComponentLabeling *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkConnectedComponentLabeling_ext() instead - */ -int cmdline_parser_clitkConnectedComponentLabeling2 (int argc, char * const *argv, - struct args_info_clitkConnectedComponentLabeling *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkConnectedComponentLabeling_ext (int argc, char * const *argv, - struct args_info_clitkConnectedComponentLabeling *args_info, - struct cmdline_parser_clitkConnectedComponentLabeling_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkConnectedComponentLabeling_dump(FILE *outfile, - struct args_info_clitkConnectedComponentLabeling *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkConnectedComponentLabeling_file_save(const char *filename, - struct args_info_clitkConnectedComponentLabeling *args_info); - -/** - * Print the help - */ -void cmdline_parser_clitkConnectedComponentLabeling_print_help(void); -/** - * Print the version - */ -void cmdline_parser_clitkConnectedComponentLabeling_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_clitkConnectedComponentLabeling_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_clitkConnectedComponentLabeling_params_init(struct cmdline_parser_clitkConnectedComponentLabeling_params *params); - -/** - * Allocates dynamically a cmdline_parser_clitkConnectedComponentLabeling_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_clitkConnectedComponentLabeling_params structure - */ -struct cmdline_parser_clitkConnectedComponentLabeling_params *cmdline_parser_clitkConnectedComponentLabeling_params_create(void); - -/** - * Initializes the passed args_info_clitkConnectedComponentLabeling structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_clitkConnectedComponentLabeling_init (struct args_info_clitkConnectedComponentLabeling *args_info); -/** - * Deallocates the string fields of the args_info_clitkConnectedComponentLabeling structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_clitkConnectedComponentLabeling_free (struct args_info_clitkConnectedComponentLabeling *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkConnectedComponentLabeling_config_file() instead - */ -int cmdline_parser_clitkConnectedComponentLabeling_configfile (char * const filename, - struct args_info_clitkConnectedComponentLabeling *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkConnectedComponentLabeling_config_file (char * const filename, - struct args_info_clitkConnectedComponentLabeling *args_info, - struct cmdline_parser_clitkConnectedComponentLabeling_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_clitkConnectedComponentLabeling_required (struct args_info_clitkConnectedComponentLabeling *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CLITKCONNECTEDCOMPONENTLABELING_GGO_H */ diff --git a/vv/tools_ggo/clitkCropImage_ggo.c b/vv/tools_ggo/clitkCropImage_ggo.c deleted file mode 100644 index d28cba2..0000000 --- a/vv/tools_ggo/clitkCropImage_ggo.c +++ /dev/null @@ -1,2071 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22 - generated with the following command: - /usr/local/bin/gengetopt --output-dir=/home/tbaudier/vv/vv_static/vv/vv_bin/tools --arg-struct-name=args_info_clitkCropImage --func-name=cmdline_parser_clitkCropImage --file-name=clitkCropImage_ggo --unamed-opts --conf-parser --include-getopt - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - - -#include "clitkCropImage_ggo.h" - -const char *args_info_clitkCropImage_purpose = "Crop an image according to a given extends or AutoCrop with a background value \nor like another image"; - -const char *args_info_clitkCropImage_usage = "Usage: clitkCropImage [OPTIONS]... [FILES]..."; - -const char *args_info_clitkCropImage_description = ""; - -const char *args_info_clitkCropImage_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " --config=STRING Config file", - " --imagetypes Display allowed image types (default=off)", - " -v, --verbose Verbose (default=off)", - " --verboseOption Display options values (default=off)", - " --verboseWarningOff Do not display warning (default=off)", - "\nI/O:", - " -i, --input=STRING Input image filename", - " -o, --output=STRING Output image filename", - "\nUsed determined crop:", - " -b, --boundingBox=INT Bounding box of the crop region (in 3D: \n =x1,x2,y1,y2,z1,z2)", - " -l, --lower=INT Size of the lower crop region (multiple values)", - " -u, --upper=INT Size of the upper crop region (multiple values)", - " --origin Set new origin to zero (default=off)", - "\nAutoCrop with BG value:", - " --BG=DOUBLE Background value in input. (default=`0')", - "\nCrop like another image:", - " --like=STRING Crop like this image (must have the same spacing", - " --BGLike=DOUBLE Background value in output (if like larger) \n (default=`0')", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_INT - , ARG_DOUBLE -} cmdline_parser_clitkCropImage_arg_type; - -static -void clear_given (struct args_info_clitkCropImage *args_info); -static -void clear_args (struct args_info_clitkCropImage *args_info); - -static int -cmdline_parser_clitkCropImage_internal (int argc, char * const *argv, struct args_info_clitkCropImage *args_info, - struct cmdline_parser_clitkCropImage_params *params, const char *additional_error); - -static int -cmdline_parser_clitkCropImage_required2 (struct args_info_clitkCropImage *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct args_info_clitkCropImage *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->config_given = 0 ; - args_info->imagetypes_given = 0 ; - args_info->verbose_given = 0 ; - args_info->verboseOption_given = 0 ; - args_info->verboseWarningOff_given = 0 ; - args_info->input_given = 0 ; - args_info->output_given = 0 ; - args_info->boundingBox_given = 0 ; - args_info->lower_given = 0 ; - args_info->upper_given = 0 ; - args_info->origin_given = 0 ; - args_info->BG_given = 0 ; - args_info->like_given = 0 ; - args_info->BGLike_given = 0 ; -} - -static -void clear_args (struct args_info_clitkCropImage *args_info) -{ - args_info->config_arg = NULL; - args_info->config_orig = NULL; - args_info->imagetypes_flag = 0; - args_info->verbose_flag = 0; - args_info->verboseOption_flag = 0; - args_info->verboseWarningOff_flag = 0; - args_info->input_arg = NULL; - args_info->input_orig = NULL; - args_info->output_arg = NULL; - args_info->output_orig = NULL; - args_info->boundingBox_arg = NULL; - args_info->boundingBox_orig = NULL; - args_info->lower_arg = NULL; - args_info->lower_orig = NULL; - args_info->upper_arg = NULL; - args_info->upper_orig = NULL; - args_info->origin_flag = 0; - args_info->BG_arg = 0; - args_info->BG_orig = NULL; - args_info->like_arg = NULL; - args_info->like_orig = NULL; - args_info->BGLike_arg = 0; - args_info->BGLike_orig = NULL; - -} - -static -void init_args_info(struct args_info_clitkCropImage *args_info) -{ - - - args_info->help_help = args_info_clitkCropImage_help[0] ; - args_info->version_help = args_info_clitkCropImage_help[1] ; - args_info->config_help = args_info_clitkCropImage_help[2] ; - args_info->imagetypes_help = args_info_clitkCropImage_help[3] ; - args_info->verbose_help = args_info_clitkCropImage_help[4] ; - args_info->verboseOption_help = args_info_clitkCropImage_help[5] ; - args_info->verboseWarningOff_help = args_info_clitkCropImage_help[6] ; - args_info->input_help = args_info_clitkCropImage_help[8] ; - args_info->output_help = args_info_clitkCropImage_help[9] ; - args_info->boundingBox_help = args_info_clitkCropImage_help[11] ; - args_info->boundingBox_min = -1; - args_info->boundingBox_max = -1; - args_info->lower_help = args_info_clitkCropImage_help[12] ; - args_info->lower_min = -1; - args_info->lower_max = -1; - args_info->upper_help = args_info_clitkCropImage_help[13] ; - args_info->upper_min = -1; - args_info->upper_max = -1; - args_info->origin_help = args_info_clitkCropImage_help[14] ; - args_info->BG_help = args_info_clitkCropImage_help[16] ; - args_info->like_help = args_info_clitkCropImage_help[18] ; - args_info->BGLike_help = args_info_clitkCropImage_help[19] ; - -} - -void -cmdline_parser_clitkCropImage_print_version (void) -{ - printf ("%s %s\n", CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, CMDLINE_PARSER_CLITKCROPIMAGE_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_clitkCropImage_print_version (); - - if (strlen(args_info_clitkCropImage_purpose) > 0) - printf("\n%s\n", args_info_clitkCropImage_purpose); - - if (strlen(args_info_clitkCropImage_usage) > 0) - printf("\n%s\n", args_info_clitkCropImage_usage); - - printf("\n"); - - if (strlen(args_info_clitkCropImage_description) > 0) - printf("%s\n", args_info_clitkCropImage_description); -} - -void -cmdline_parser_clitkCropImage_print_help (void) -{ - int i = 0; - print_help_common(); - while (args_info_clitkCropImage_help[i]) - printf("%s\n", args_info_clitkCropImage_help[i++]); -} - -void -cmdline_parser_clitkCropImage_init (struct args_info_clitkCropImage *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = NULL; - args_info->inputs_num = 0; -} - -void -cmdline_parser_clitkCropImage_params_init(struct cmdline_parser_clitkCropImage_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_clitkCropImage_params * -cmdline_parser_clitkCropImage_params_create(void) -{ - struct cmdline_parser_clitkCropImage_params *params = - (struct cmdline_parser_clitkCropImage_params *)malloc(sizeof(struct cmdline_parser_clitkCropImage_params)); - cmdline_parser_clitkCropImage_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - -/** @brief generic value variable */ -union generic_value { - int int_arg; - double double_arg; - char *string_arg; -}; - -/** @brief holds temporary values for multiple options */ -struct generic_list -{ - union generic_value arg; - char *orig; - struct generic_list *next; -}; - -/** - * @brief add a node at the head of the list - */ -static void add_node(struct generic_list **list) { - struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); - new_node->next = *list; - *list = new_node; - new_node->arg.string_arg = NULL; - new_node->orig = NULL; -} - -static void -free_multiple_field(unsigned int len, void **arg, char ***orig) -{ - unsigned int i; - if (*arg) { - for (i = 0; i < len; ++i) - { - free_string_field(&((*orig)[i])); - } - - free (*arg); - *arg = 0; - free (*orig); - *orig = 0; - } -} - - -static void -cmdline_parser_clitkCropImage_release (struct args_info_clitkCropImage *args_info) -{ - unsigned int i; - free_string_field (&(args_info->config_arg)); - free_string_field (&(args_info->config_orig)); - free_string_field (&(args_info->input_arg)); - free_string_field (&(args_info->input_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - free_multiple_field (args_info->boundingBox_given, (void **)&(args_info->boundingBox_arg), &(args_info->boundingBox_orig)); - free_multiple_field (args_info->lower_given, (void **)&(args_info->lower_arg), &(args_info->lower_orig)); - free_multiple_field (args_info->upper_given, (void **)&(args_info->upper_arg), &(args_info->upper_orig)); - free_string_field (&(args_info->BG_orig)); - free_string_field (&(args_info->like_arg)); - free_string_field (&(args_info->like_orig)); - free_string_field (&(args_info->BGLike_orig)); - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) -{ - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - -static void -write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[]) -{ - int i; - - for (i = 0; i < len; ++i) - write_into_file(outfile, opt, (arg ? arg[i] : 0), values); -} - -int -cmdline_parser_clitkCropImage_dump(FILE *outfile, struct args_info_clitkCropImage *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->config_given) - write_into_file(outfile, "config", args_info->config_orig, 0); - if (args_info->imagetypes_given) - write_into_file(outfile, "imagetypes", 0, 0 ); - if (args_info->verbose_given) - write_into_file(outfile, "verbose", 0, 0 ); - if (args_info->verboseOption_given) - write_into_file(outfile, "verboseOption", 0, 0 ); - if (args_info->verboseWarningOff_given) - write_into_file(outfile, "verboseWarningOff", 0, 0 ); - if (args_info->input_given) - write_into_file(outfile, "input", args_info->input_orig, 0); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - write_multiple_into_file(outfile, args_info->boundingBox_given, "boundingBox", args_info->boundingBox_orig, 0); - write_multiple_into_file(outfile, args_info->lower_given, "lower", args_info->lower_orig, 0); - write_multiple_into_file(outfile, args_info->upper_given, "upper", args_info->upper_orig, 0); - if (args_info->origin_given) - write_into_file(outfile, "origin", 0, 0 ); - if (args_info->BG_given) - write_into_file(outfile, "BG", args_info->BG_orig, 0); - if (args_info->like_given) - write_into_file(outfile, "like", args_info->like_orig, 0); - if (args_info->BGLike_given) - write_into_file(outfile, "BGLike", args_info->BGLike_orig, 0); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_clitkCropImage_file_save(const char *filename, struct args_info_clitkCropImage *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_clitkCropImage_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_clitkCropImage_free (struct args_info_clitkCropImage *args_info) -{ - cmdline_parser_clitkCropImage_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = NULL; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -static char * -get_multiple_arg_token(const char *arg) -{ - char *tok, *ret; - size_t len, num_of_escape, i, j; - - if (!arg) - return NULL; - - tok = strchr (arg, ','); - num_of_escape = 0; - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - ++num_of_escape; - } - else - break; - } - - if (tok) - len = (size_t)(tok - arg + 1); - else - len = strlen (arg) + 1; - - len -= num_of_escape; - - ret = (char *) malloc (len); - - i = 0; - j = 0; - while (arg[i] && (j < len-1)) - { - if (arg[i] == '\\' && - arg[ i + 1 ] && - arg[ i + 1 ] == ',') - ++i; - - ret[j++] = arg[i++]; - } - - ret[len-1] = '\0'; - - return ret; -} - -static char * -get_multiple_arg_token_next(const char *arg) -{ - char *tok; - - if (!arg) - return NULL; - - tok = strchr (arg, ','); - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - } - else - break; - } - - if (! tok || strlen(tok) == 1) - return 0; - - return tok+1; -} - -static int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc); - -int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc) -{ - int error = 0; - - if (option_given && ! (min < 0 && max < 0)) - { - if (min >= 0 && max >= 0) - { - if (min == max) - { - /* specific occurrences */ - if (option_given != min) - { - fprintf (stderr, "%s: %s option occurrences must be %d\n", - prog_name, option_desc, min); - error = 1; - } - } - else if (option_given < min - || option_given > max) - { - /* range occurrences */ - fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n", - prog_name, option_desc, min, max); - error = 1; - } - } - else if (min >= 0) - { - /* at least check */ - if (option_given < min) - { - fprintf (stderr, "%s: %s option occurrences must be at least %d\n", - prog_name, option_desc, min); - error = 1; - } - } - else if (max >= 0) - { - /* at most check */ - if (option_given > max) - { - fprintf (stderr, "%s: %s option occurrences must be at most %d\n", - prog_name, option_desc, max); - error = 1; - } - } - } - - return error; -} -int -cmdline_parser_clitkCropImage (int argc, char * const *argv, struct args_info_clitkCropImage *args_info) -{ - return cmdline_parser_clitkCropImage2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_clitkCropImage_ext (int argc, char * const *argv, struct args_info_clitkCropImage *args_info, - struct cmdline_parser_clitkCropImage_params *params) -{ - int result; - result = cmdline_parser_clitkCropImage_internal (argc, argv, args_info, params, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkCropImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkCropImage2 (int argc, char * const *argv, struct args_info_clitkCropImage *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_clitkCropImage_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_clitkCropImage_internal (argc, argv, args_info, ¶ms, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkCropImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkCropImage_required (struct args_info_clitkCropImage *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_clitkCropImage_required2(args_info, prog_name, NULL) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkCropImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkCropImage_required2 (struct args_info_clitkCropImage *args_info, const char *prog_name, const char *additional_error) -{ - int error = 0; - - /* checks for required options */ - if (! args_info->input_given) - { - fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->output_given) - { - fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (check_multiple_option_occurrences(prog_name, args_info->boundingBox_given, args_info->boundingBox_min, args_info->boundingBox_max, "'--boundingBox' ('-b')")) - error = 1; - - if (check_multiple_option_occurrences(prog_name, args_info->lower_given, args_info->lower_min, args_info->lower_max, "'--lower' ('-l')")) - error = 1; - - if (check_multiple_option_occurrences(prog_name, args_info->upper_given, args_info->upper_min, args_info->upper_max, "'--upper' ('-u')")) - error = 1; - - - /* checks for dependences among options */ - - return error; -} - -/* - * Extracted from the glibc source tree, version 2.3.6 - * - * Licensed under the GPL as per the whole glibc source tree. - * - * This file was modified so that getopt_long can be called - * many times without risking previous memory to be spoiled. - * - * Modified by Andre Noll and Lorenzo Bettini for use in - * GNU gengetopt generated files. - * - */ - -/* - * we must include anything we need since this file is not thought to be - * inserted in a file already using getopt.h - * - * Lorenzo - */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -static char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -static int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -static int opterr; - -/* Set to an option character which was unrecognized. */ - -static int optopt; - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. -*/ -/* - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `custom_optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -/* Names for the values of the `has_arg' field of `struct option'. */ -#ifndef no_argument -#define no_argument 0 -#endif - -#ifndef required_argument -#define required_argument 1 -#endif - -#ifndef optional_argument -#define optional_argument 2 -#endif - -struct custom_getopt_data { - /* - * These have exactly the same meaning as the corresponding global variables, - * except that they are used for the reentrant versions of getopt. - */ - int custom_optind; - int custom_opterr; - int custom_optopt; - char *custom_optarg; - - /* True if the internal members have been initialized. */ - int initialized; - - /* - * The next char to be scanned in the option-element in which the last option - * character we returned was found. This allows us to pick up the scan where - * we left off. If this is zero, or a null string, it means resume the scan by - * advancing to the next ARGV-element. - */ - char *nextchar; - - /* - * Describe the part of ARGV that contains non-options that have been skipped. - * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is - * the index after the last of them. - */ - int first_nonopt; - int last_nonopt; -}; - -/* - * the variables optarg, optind, opterr and optopt are renamed with - * the custom_ prefix so that they don't interfere with getopt ones. - * - * Moreover they're static so they are visible only from within the - * file where this very file will be included. - */ - -/* - * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an - * option that takes an argument, the argument value is returned here. - */ -static char *custom_optarg; - -/* - * Index in ARGV of the next element to be scanned. This is used for - * communication to and from the caller and for communication between - * successive calls to `custom_getopt'. - * - * On entry to `custom_getopt', 1 means this is the first call; initialize. - * - * When `custom_getopt' returns -1, this is the index of the first of the non-option - * elements that the caller should itself scan. - * - * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV - * has been scanned so far. - * - * 1003.2 says this must be 1 before any call. - */ -static int custom_optind = 1; - -/* - * Callers store zero here to inhibit the error message for unrecognized - * options. - */ -static int custom_opterr = 1; - -/* - * Set to an option character which was unrecognized. This must be initialized - * on some systems to avoid linking in the system's own getopt implementation. - */ -static int custom_optopt = '?'; - -/* - * Exchange two adjacent subsequences of ARGV. One subsequence is elements - * [first_nonopt,last_nonopt) which contains all the non-options that have been - * skipped so far. The other is elements [last_nonopt,custom_optind), which contains - * all the options processed since those non-options were skipped. - * `first_nonopt' and `last_nonopt' are relocated so that they describe the new - * indices of the non-options in ARGV after they are moved. - */ -static void exchange(char **argv, struct custom_getopt_data *d) -{ - int bottom = d->first_nonopt; - int middle = d->last_nonopt; - int top = d->custom_optind; - char *tem; - - /* - * Exchange the shorter segment with the far end of the longer segment. - * That puts the shorter segment into the right place. It leaves the - * longer segment in the right place overall, but it consists of two - * parts that need to be swapped next. - */ - while (top > middle && middle > bottom) { - if (top - middle > middle - bottom) { - /* Bottom segment is the short one. */ - int len = middle - bottom; - int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = - argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } else { - /* Top segment is the short one. */ - int len = top - middle; - int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - /* Update records for the slots the non-options now occupy. */ - d->first_nonopt += (d->custom_optind - d->last_nonopt); - d->last_nonopt = d->custom_optind; -} - -/* Initialize the internal data when the first call is made. */ -static void custom_getopt_initialize(struct custom_getopt_data *d) -{ - /* - * Start processing options with ARGV-element 1 (since ARGV-element 0 - * is the program name); the sequence of previously skipped non-option - * ARGV-elements is empty. - */ - d->first_nonopt = d->last_nonopt = d->custom_optind; - d->nextchar = NULL; - d->initialized = 1; -} - -#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0') - -/* return: zero: continue, nonzero: return given value to user */ -static int shuffle_argv(int argc, char *const *argv,const struct option *longopts, - struct custom_getopt_data *d) -{ - /* - * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been - * moved back by the user (who may also have changed the arguments). - */ - if (d->last_nonopt > d->custom_optind) - d->last_nonopt = d->custom_optind; - if (d->first_nonopt > d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * If we have just processed some options following some - * non-options, exchange them so that the options come first. - */ - if (d->first_nonopt != d->last_nonopt && - d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->last_nonopt != d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * Skip any additional non-options and extend the range of - * non-options previously skipped. - */ - while (d->custom_optind < argc && NONOPTION_P) - d->custom_optind++; - d->last_nonopt = d->custom_optind; - /* - * The special ARGV-element `--' means premature end of options. Skip - * it like a null option, then exchange with previous non-options as if - * it were an option, then skip everything else like a non-option. - */ - if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) { - d->custom_optind++; - if (d->first_nonopt != d->last_nonopt - && d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->first_nonopt == d->last_nonopt) - d->first_nonopt = d->custom_optind; - d->last_nonopt = argc; - d->custom_optind = argc; - } - /* - * If we have done all the ARGV-elements, stop the scan and back over - * any non-options that we skipped and permuted. - */ - if (d->custom_optind == argc) { - /* - * Set the next-arg-index to point at the non-options that we - * previously skipped, so the caller will digest them. - */ - if (d->first_nonopt != d->last_nonopt) - d->custom_optind = d->first_nonopt; - return -1; - } - /* - * If we have come to a non-option and did not permute it, either stop - * the scan or describe it to the caller and pass it by. - */ - if (NONOPTION_P) { - d->custom_optarg = argv[d->custom_optind++]; - return 1; - } - /* - * We have found another option-ARGV-element. Skip the initial - * punctuation. - */ - d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-')); - return 0; -} - -/* - * Check whether the ARGV-element is a long option. - * - * If there's a long option "fubar" and the ARGV-element is "-fu", consider - * that an abbreviation of the long option, just like "--fu", and not "-f" with - * arg "u". - * - * This distinction seems to be the most useful approach. - * - */ -static int check_long_opt(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - int print_errors, struct custom_getopt_data *d) -{ - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match or abbreviated matches */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) { - if ((unsigned int) (nameend - d->nextchar) - == (unsigned int) strlen(p->name)) { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } else if (pfound == NULL) { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } else if (pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' is ambiguous\n", - argv[0], argv[d->custom_optind]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optind++; - d->custom_optopt = 0; - return '?'; - } - if (pfound) { - option_index = indfound; - d->custom_optind++; - if (*nameend) { - if (pfound->has_arg != no_argument) - d->custom_optarg = nameend + 1; - else { - if (print_errors) { - if (argv[d->custom_optind - 1][1] == '-') { - /* --option */ - fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[d->custom_optind - 1][0], pfound->name); - } - - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return '?'; - } - } else if (pfound->has_arg == required_argument) { - if (d->custom_optind < argc) - d->custom_optarg = argv[d->custom_optind++]; - else { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' requires an argument\n", - argv[0], - argv[d->custom_optind - 1]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->nextchar += strlen(d->nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* - * Can't find it as a long option. If this is not getopt_long_only, or - * the option starts with '--' or is not a valid short option, then - * it's an error. Otherwise interpret it as a short option. - */ - if (print_errors) { - if (argv[d->custom_optind][1] == '-') { - /* --option */ - fprintf(stderr, - "%s: unrecognized option `--%s'\n", - argv[0], d->nextchar); - } else { - /* +option or -option */ - fprintf(stderr, - "%s: unrecognized option `%c%s'\n", - argv[0], argv[d->custom_optind][0], - d->nextchar); - } - } - d->nextchar = (char *) ""; - d->custom_optind++; - d->custom_optopt = 0; - return '?'; -} - -static int check_short_opt(int argc, char *const *argv, const char *optstring, - int print_errors, struct custom_getopt_data *d) -{ - char c = *d->nextchar++; - char *temp = strchr(optstring, c); - - /* Increment `custom_optind' when we start to process its last character. */ - if (*d->nextchar == '\0') - ++d->custom_optind; - if (!temp || c == ':') { - if (print_errors) - fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); - - d->custom_optopt = c; - return '?'; - } - if (temp[1] == ':') { - if (temp[2] == ':') { - /* This is an option that accepts an argument optionally. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - d->custom_optind++; - } else - d->custom_optarg = NULL; - d->nextchar = NULL; - } else { - /* This is an option that requires an argument. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - /* - * If we end this ARGV-element by taking the - * rest as an arg, we must advance to the next - * element now. - */ - d->custom_optind++; - } else if (d->custom_optind == argc) { - if (print_errors) { - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], c); - } - d->custom_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } else - /* - * We already incremented `custom_optind' once; - * increment it again when taking next ARGV-elt - * as argument. - */ - d->custom_optarg = argv[d->custom_optind++]; - d->nextchar = NULL; - } - } - return c; -} - -/* - * Scan elements of ARGV for option characters given in OPTSTRING. - * - * If an element of ARGV starts with '-', and is not exactly "-" or "--", - * then it is an option element. The characters of this element - * (aside from the initial '-') are option characters. If `getopt' - * is called repeatedly, it returns successively each of the option characters - * from each of the option elements. - * - * If `getopt' finds another option character, it returns that character, - * updating `custom_optind' and `nextchar' so that the next call to `getopt' can - * resume the scan with the following option character or ARGV-element. - * - * If there are no more option characters, `getopt' returns -1. - * Then `custom_optind' is the index in ARGV of the first ARGV-element - * that is not an option. (The ARGV-elements have been permuted - * so that those that are not options now come last.) - * - * OPTSTRING is a string containing the legitimate option characters. - * If an option character is seen that is not listed in OPTSTRING, - * return '?' after printing an error message. If you set `custom_opterr' to - * zero, the error message is suppressed but we still return '?'. - * - * If a char in OPTSTRING is followed by a colon, that means it wants an arg, - * so the following text in the same ARGV-element, or the text of the following - * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that - * wants an optional arg; if there is text in the current ARGV-element, - * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero. - * - * If OPTSTRING starts with `-' or `+', it requests different methods of - * handling the non-option ARGV-elements. - * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - * - * Long-named options begin with `--' instead of `-'. - * Their names may be abbreviated as long as the abbreviation is unique - * or is an exact match for some defined option. If they have an - * argument, it follows the option name in the same ARGV-element, separated - * from the option name by a `=', or else the in next ARGV-element. - * When `getopt' finds a long-named option, it returns 0 if that option's - * `flag' field is nonzero, the value of the option's `val' field - * if the `flag' field is zero. - * - * The elements of ARGV aren't really const, because we permute them. - * But we pretend they're const in the prototype to be compatible - * with other systems. - * - * LONGOPTS is a vector of `struct option' terminated by an - * element containing a name which is zero. - * - * LONGIND returns the index in LONGOPT of the long-named option found. - * It is only valid when a long-named option has been found by the most - * recent call. - * - * Return the option character from OPTS just read. Return -1 when there are - * no more options. For unrecognized options, or options missing arguments, - * `custom_optopt' is set to the option letter, and '?' is returned. - * - * The OPTS string is a list of characters which are recognized option letters, - * optionally followed by colons, specifying that that letter takes an - * argument, to be placed in `custom_optarg'. - * - * If a letter in OPTS is followed by two colons, its argument is optional. - * This behavior is specific to the GNU `getopt'. - * - * The argument `--' causes premature termination of argument scanning, - * explicitly telling `getopt' that there are no more options. If OPTS begins - * with `--', then non-option arguments are treated as arguments to the option - * '\0'. This behavior is specific to the GNU `getopt'. - */ - -static int getopt_internal_r(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - struct custom_getopt_data *d) -{ - int ret, print_errors = d->custom_opterr; - - if (optstring[0] == ':') - print_errors = 0; - if (argc < 1) - return -1; - d->custom_optarg = NULL; - - /* - * This is a big difference with GNU getopt, since optind == 0 - * means initialization while here 1 means first call. - */ - if (d->custom_optind == 0 || !d->initialized) { - if (d->custom_optind == 0) - d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */ - custom_getopt_initialize(d); - } - if (d->nextchar == NULL || *d->nextchar == '\0') { - ret = shuffle_argv(argc, argv, longopts, d); - if (ret) - return ret; - } - if (longopts && (argv[d->custom_optind][1] == '-' )) - return check_long_opt(argc, argv, optstring, longopts, - longind, print_errors, d); - return check_short_opt(argc, argv, optstring, print_errors, d); -} - -static int custom_getopt_internal(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind) -{ - int result; - /* Keep a global copy of all internal members of d */ - static struct custom_getopt_data d; - - d.custom_optind = custom_optind; - d.custom_opterr = custom_opterr; - result = getopt_internal_r(argc, argv, optstring, longopts, - longind, &d); - custom_optind = d.custom_optind; - custom_optarg = d.custom_optarg; - custom_optopt = d.custom_optopt; - return result; -} - -static int custom_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return custom_getopt_internal(argc, argv, options, long_options, - opt_index); -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_clitkCropImage_params.check_ambiguity - * @param override @see cmdline_parser_clitkCropImage_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, - cmdline_parser_clitkCropImage_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_INT: - if (val) *((int *)field) = strtol (val, &stop_char, 0); - break; - case ARG_DOUBLE: - if (val) *((double *)field) = strtod (val, &stop_char); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_INT: - case ARG_DOUBLE: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - -/** - * @brief store information about a multiple option in a temporary list - * @param list where to (temporarily) store multiple options - */ -static -int update_multiple_arg_temp(struct generic_list **list, - unsigned int *prev_given, const char *val, - char *possible_values[], const char *default_value, - cmdline_parser_clitkCropImage_arg_type arg_type, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *multi_token, *multi_next; /* store single arguments */ - - if (arg_type == ARG_NO) { - (*prev_given)++; - return 0; /* OK */ - } - - multi_token = get_multiple_arg_token(val); - multi_next = get_multiple_arg_token_next (val); - - while (1) - { - add_node (list); - if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, - prev_given, multi_token, possible_values, default_value, - arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { - if (multi_token) free(multi_token); - return 1; /* failure */ - } - - if (multi_next) - { - multi_token = get_multiple_arg_token(multi_next); - multi_next = get_multiple_arg_token_next (multi_next); - } - else - break; - } - - return 0; /* OK */ -} - -/** - * @brief free the passed list (including possible string argument) - */ -static -void free_list(struct generic_list *list, short string_arg) -{ - if (list) { - struct generic_list *tmp; - while (list) - { - tmp = list; - if (string_arg && list->arg.string_arg) - free (list->arg.string_arg); - if (list->orig) - free (list->orig); - list = list->next; - free (tmp); - } - } -} - -/** - * @brief updates a multiple option starting from the passed list - */ -static -void update_multiple_arg(void *field, char ***orig_field, - unsigned int field_given, unsigned int prev_given, union generic_value *default_value, - cmdline_parser_clitkCropImage_arg_type arg_type, - struct generic_list *list) -{ - int i; - struct generic_list *tmp; - - if (prev_given && list) { - *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *)); - - switch(arg_type) { - case ARG_INT: - *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break; - case ARG_DOUBLE: - *((double **)field) = (double *)realloc (*((double **)field), (field_given + prev_given) * sizeof (double)); break; - case ARG_STRING: - *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; - default: - break; - }; - - for (i = (prev_given - 1); i >= 0; --i) - { - tmp = list; - - switch(arg_type) { - case ARG_INT: - (*((int **)field))[i + field_given] = tmp->arg.int_arg; break; - case ARG_DOUBLE: - (*((double **)field))[i + field_given] = tmp->arg.double_arg; break; - case ARG_STRING: - (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; - default: - break; - } - (*orig_field) [i + field_given] = list->orig; - list = list->next; - free (tmp); - } - } else { /* set the default value */ - if (default_value && ! field_given) { - switch(arg_type) { - case ARG_INT: - if (! *((int **)field)) { - *((int **)field) = (int *)malloc (sizeof (int)); - (*((int **)field))[0] = default_value->int_arg; - } - break; - case ARG_DOUBLE: - if (! *((double **)field)) { - *((double **)field) = (double *)malloc (sizeof (double)); - (*((double **)field))[0] = default_value->double_arg; - } - break; - case ARG_STRING: - if (! *((char ***)field)) { - *((char ***)field) = (char **)malloc (sizeof (char *)); - (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg); - } - break; - default: break; - } - if (!(*orig_field)) { - *orig_field = (char **) malloc (sizeof (char *)); - (*orig_field)[0] = NULL; - } - } - } -} - -int -cmdline_parser_clitkCropImage_internal (int argc, char * const *argv, struct args_info_clitkCropImage *args_info, - struct cmdline_parser_clitkCropImage_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - struct generic_list * boundingBox_list = NULL; - struct generic_list * lower_list = NULL; - struct generic_list * upper_list = NULL; - int error = 0; - struct args_info_clitkCropImage local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_clitkCropImage_init (args_info); - - cmdline_parser_clitkCropImage_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "config", 1, NULL, 0 }, - { "imagetypes", 0, NULL, 0 }, - { "verbose", 0, NULL, 'v' }, - { "verboseOption", 0, NULL, 0 }, - { "verboseWarningOff", 0, NULL, 0 }, - { "input", 1, NULL, 'i' }, - { "output", 1, NULL, 'o' }, - { "boundingBox", 1, NULL, 'b' }, - { "lower", 1, NULL, 'l' }, - { "upper", 1, NULL, 'u' }, - { "origin", 0, NULL, 0 }, - { "BG", 1, NULL, 0 }, - { "like", 1, NULL, 0 }, - { "BGLike", 1, NULL, 0 }, - { NULL, 0, NULL, 0 } - }; - - custom_optarg = optarg; - custom_optind = optind; - custom_opterr = opterr; - custom_optopt = optopt; - - c = custom_getopt_long (argc, argv, "hVvi:o:b:l:u:", long_options, &option_index); - - optarg = custom_optarg; - optind = custom_optind; - opterr = custom_opterr; - optopt = custom_optopt; - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_clitkCropImage_print_help (); - cmdline_parser_clitkCropImage_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_clitkCropImage_print_version (); - cmdline_parser_clitkCropImage_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'v': /* Verbose. */ - - - if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) - goto failure; - - break; - case 'i': /* Input image filename. */ - - - if (update_arg( (void *)&(args_info->input_arg), - &(args_info->input_orig), &(args_info->input_given), - &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "input", 'i', - additional_error)) - goto failure; - - break; - case 'o': /* Output image filename. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - case 'b': /* Bounding box of the crop region (in 3D: =x1,x2,y1,y2,z1,z2). */ - - if (update_multiple_arg_temp(&boundingBox_list, - &(local_args_info.boundingBox_given), optarg, 0, 0, ARG_INT, - "boundingBox", 'b', - additional_error)) - goto failure; - - break; - case 'l': /* Size of the lower crop region (multiple values). */ - - if (update_multiple_arg_temp(&lower_list, - &(local_args_info.lower_given), optarg, 0, 0, ARG_INT, - "lower", 'l', - additional_error)) - goto failure; - - break; - case 'u': /* Size of the upper crop region (multiple values). */ - - if (update_multiple_arg_temp(&upper_list, - &(local_args_info.upper_given), optarg, 0, 0, ARG_INT, - "upper", 'u', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Config file. */ - if (strcmp (long_options[option_index].name, "config") == 0) - { - - - if (update_arg( (void *)&(args_info->config_arg), - &(args_info->config_orig), &(args_info->config_given), - &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "config", '-', - additional_error)) - goto failure; - - } - /* Display allowed image types. */ - else if (strcmp (long_options[option_index].name, "imagetypes") == 0) - { - - - if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given), - &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "imagetypes", '-', - additional_error)) - goto failure; - - } - /* Display options values. */ - else if (strcmp (long_options[option_index].name, "verboseOption") == 0) - { - - - if (update_arg((void *)&(args_info->verboseOption_flag), 0, &(args_info->verboseOption_given), - &(local_args_info.verboseOption_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verboseOption", '-', - additional_error)) - goto failure; - - } - /* Do not display warning. */ - else if (strcmp (long_options[option_index].name, "verboseWarningOff") == 0) - { - - - if (update_arg((void *)&(args_info->verboseWarningOff_flag), 0, &(args_info->verboseWarningOff_given), - &(local_args_info.verboseWarningOff_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verboseWarningOff", '-', - additional_error)) - goto failure; - - } - /* Set new origin to zero. */ - else if (strcmp (long_options[option_index].name, "origin") == 0) - { - - - if (update_arg((void *)&(args_info->origin_flag), 0, &(args_info->origin_given), - &(local_args_info.origin_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "origin", '-', - additional_error)) - goto failure; - - } - /* Background value in input.. */ - else if (strcmp (long_options[option_index].name, "BG") == 0) - { - - - if (update_arg( (void *)&(args_info->BG_arg), - &(args_info->BG_orig), &(args_info->BG_given), - &(local_args_info.BG_given), optarg, 0, "0", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "BG", '-', - additional_error)) - goto failure; - - } - /* Crop like this image (must have the same spacing. */ - else if (strcmp (long_options[option_index].name, "like") == 0) - { - - - if (update_arg( (void *)&(args_info->like_arg), - &(args_info->like_orig), &(args_info->like_given), - &(local_args_info.like_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "like", '-', - additional_error)) - goto failure; - - } - /* Background value in output (if like larger). */ - else if (strcmp (long_options[option_index].name, "BGLike") == 0) - { - - - if (update_arg( (void *)&(args_info->BGLike_arg), - &(args_info->BGLike_orig), &(args_info->BGLike_given), - &(local_args_info.BGLike_given), optarg, 0, "0", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "BGLike", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - update_multiple_arg((void *)&(args_info->boundingBox_arg), - &(args_info->boundingBox_orig), args_info->boundingBox_given, - local_args_info.boundingBox_given, 0 , - ARG_INT, boundingBox_list); - update_multiple_arg((void *)&(args_info->lower_arg), - &(args_info->lower_orig), args_info->lower_given, - local_args_info.lower_given, 0 , - ARG_INT, lower_list); - update_multiple_arg((void *)&(args_info->upper_arg), - &(args_info->upper_orig), args_info->upper_given, - local_args_info.upper_given, 0 , - ARG_INT, upper_list); - - args_info->boundingBox_given += local_args_info.boundingBox_given; - local_args_info.boundingBox_given = 0; - args_info->lower_given += local_args_info.lower_given; - local_args_info.lower_given = 0; - args_info->upper_given += local_args_info.upper_given; - local_args_info.upper_given = 0; - - if (check_required) - { - error += cmdline_parser_clitkCropImage_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_clitkCropImage_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; - } - - return 0; - -failure: - free_list (boundingBox_list, 0 ); - free_list (lower_list, 0 ); - free_list (upper_list, 0 ); - - cmdline_parser_clitkCropImage_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_cmdline_parser_clitkCropImage_configfile (char * const filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == NULL) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = NULL; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _cmdline_parser_clitkCropImage_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -cmdline_parser_clitkCropImage_configfile (char * const filename, - struct args_info_clitkCropImage *args_info, - int override, int initialize, int check_required) -{ - struct cmdline_parser_clitkCropImage_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return cmdline_parser_clitkCropImage_config_file (filename, args_info, ¶ms); -} - -int -cmdline_parser_clitkCropImage_config_file (char * const filename, - struct args_info_clitkCropImage *args_info, - struct cmdline_parser_clitkCropImage_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE); - - result = _cmdline_parser_clitkCropImage_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - cmdline_parser_clitkCropImage_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkCropImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/vv/tools_ggo/clitkCropImage_ggo.h b/vv/tools_ggo/clitkCropImage_ggo.h deleted file mode 100644 index 24274a0..0000000 --- a/vv/tools_ggo/clitkCropImage_ggo.h +++ /dev/null @@ -1,250 +0,0 @@ -/** @file clitkCropImage_ggo.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef CLITKCROPIMAGE_GGO_H -#define CLITKCROPIMAGE_GGO_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE -/** @brief the program name */ -#define CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE "clitkCropImage" -#endif - -#ifndef CMDLINE_PARSER_CLITKCROPIMAGE_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_CLITKCROPIMAGE_VERSION "1.0" -#endif - -/** @brief Where the command line options are stored */ -struct args_info_clitkCropImage -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * config_arg; /**< @brief Config file. */ - char * config_orig; /**< @brief Config file original value given at command line. */ - const char *config_help; /**< @brief Config file help description. */ - int imagetypes_flag; /**< @brief Display allowed image types (default=off). */ - const char *imagetypes_help; /**< @brief Display allowed image types help description. */ - int verbose_flag; /**< @brief Verbose (default=off). */ - const char *verbose_help; /**< @brief Verbose help description. */ - int verboseOption_flag; /**< @brief Display options values (default=off). */ - const char *verboseOption_help; /**< @brief Display options values help description. */ - int verboseWarningOff_flag; /**< @brief Do not display warning (default=off). */ - const char *verboseWarningOff_help; /**< @brief Do not display warning help description. */ - char * input_arg; /**< @brief Input image filename. */ - char * input_orig; /**< @brief Input image filename original value given at command line. */ - const char *input_help; /**< @brief Input image filename help description. */ - char * output_arg; /**< @brief Output image filename. */ - char * output_orig; /**< @brief Output image filename original value given at command line. */ - const char *output_help; /**< @brief Output image filename help description. */ - int* boundingBox_arg; /**< @brief Bounding box of the crop region (in 3D: =x1,x2,y1,y2,z1,z2). */ - char ** boundingBox_orig; /**< @brief Bounding box of the crop region (in 3D: =x1,x2,y1,y2,z1,z2) original value given at command line. */ - int boundingBox_min; /**< @brief Bounding box of the crop region (in 3D: =x1,x2,y1,y2,z1,z2)'s minimum occurreces */ - int boundingBox_max; /**< @brief Bounding box of the crop region (in 3D: =x1,x2,y1,y2,z1,z2)'s maximum occurreces */ - const char *boundingBox_help; /**< @brief Bounding box of the crop region (in 3D: =x1,x2,y1,y2,z1,z2) help description. */ - int* lower_arg; /**< @brief Size of the lower crop region (multiple values). */ - char ** lower_orig; /**< @brief Size of the lower crop region (multiple values) original value given at command line. */ - int lower_min; /**< @brief Size of the lower crop region (multiple values)'s minimum occurreces */ - int lower_max; /**< @brief Size of the lower crop region (multiple values)'s maximum occurreces */ - const char *lower_help; /**< @brief Size of the lower crop region (multiple values) help description. */ - int* upper_arg; /**< @brief Size of the upper crop region (multiple values). */ - char ** upper_orig; /**< @brief Size of the upper crop region (multiple values) original value given at command line. */ - int upper_min; /**< @brief Size of the upper crop region (multiple values)'s minimum occurreces */ - int upper_max; /**< @brief Size of the upper crop region (multiple values)'s maximum occurreces */ - const char *upper_help; /**< @brief Size of the upper crop region (multiple values) help description. */ - int origin_flag; /**< @brief Set new origin to zero (default=off). */ - const char *origin_help; /**< @brief Set new origin to zero help description. */ - double BG_arg; /**< @brief Background value in input. (default='0'). */ - char * BG_orig; /**< @brief Background value in input. original value given at command line. */ - const char *BG_help; /**< @brief Background value in input. help description. */ - char * like_arg; /**< @brief Crop like this image (must have the same spacing. */ - char * like_orig; /**< @brief Crop like this image (must have the same spacing original value given at command line. */ - const char *like_help; /**< @brief Crop like this image (must have the same spacing help description. */ - double BGLike_arg; /**< @brief Background value in output (if like larger) (default='0'). */ - char * BGLike_orig; /**< @brief Background value in output (if like larger) original value given at command line. */ - const char *BGLike_help; /**< @brief Background value in output (if like larger) help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int config_given ; /**< @brief Whether config was given. */ - unsigned int imagetypes_given ; /**< @brief Whether imagetypes was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int verboseOption_given ; /**< @brief Whether verboseOption was given. */ - unsigned int verboseWarningOff_given ; /**< @brief Whether verboseWarningOff was given. */ - unsigned int input_given ; /**< @brief Whether input was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int boundingBox_given ; /**< @brief Whether boundingBox was given. */ - unsigned int lower_given ; /**< @brief Whether lower was given. */ - unsigned int upper_given ; /**< @brief Whether upper was given. */ - unsigned int origin_given ; /**< @brief Whether origin was given. */ - unsigned int BG_given ; /**< @brief Whether BG was given. */ - unsigned int like_given ; /**< @brief Whether like was given. */ - unsigned int BGLike_given ; /**< @brief Whether BGLike was given. */ - - char **inputs ; /**< @brief unamed options (options without names) */ - unsigned inputs_num ; /**< @brief unamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_clitkCropImage_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure args_info_clitkCropImage (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure args_info_clitkCropImage (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *args_info_clitkCropImage_purpose; -/** @brief the usage string of the program */ -extern const char *args_info_clitkCropImage_usage; -/** @brief all the lines making the help output */ -extern const char *args_info_clitkCropImage_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkCropImage (int argc, char * const *argv, - struct args_info_clitkCropImage *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkCropImage_ext() instead - */ -int cmdline_parser_clitkCropImage2 (int argc, char * const *argv, - struct args_info_clitkCropImage *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkCropImage_ext (int argc, char * const *argv, - struct args_info_clitkCropImage *args_info, - struct cmdline_parser_clitkCropImage_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkCropImage_dump(FILE *outfile, - struct args_info_clitkCropImage *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkCropImage_file_save(const char *filename, - struct args_info_clitkCropImage *args_info); - -/** - * Print the help - */ -void cmdline_parser_clitkCropImage_print_help(void); -/** - * Print the version - */ -void cmdline_parser_clitkCropImage_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_clitkCropImage_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_clitkCropImage_params_init(struct cmdline_parser_clitkCropImage_params *params); - -/** - * Allocates dynamically a cmdline_parser_clitkCropImage_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_clitkCropImage_params structure - */ -struct cmdline_parser_clitkCropImage_params *cmdline_parser_clitkCropImage_params_create(void); - -/** - * Initializes the passed args_info_clitkCropImage structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_clitkCropImage_init (struct args_info_clitkCropImage *args_info); -/** - * Deallocates the string fields of the args_info_clitkCropImage structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_clitkCropImage_free (struct args_info_clitkCropImage *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkCropImage_config_file() instead - */ -int cmdline_parser_clitkCropImage_configfile (char * const filename, - struct args_info_clitkCropImage *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkCropImage_config_file (char * const filename, - struct args_info_clitkCropImage *args_info, - struct cmdline_parser_clitkCropImage_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_clitkCropImage_required (struct args_info_clitkCropImage *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CLITKCROPIMAGE_GGO_H */ diff --git a/vv/tools_ggo/clitkImageArithm_ggo.c b/vv/tools_ggo/clitkImageArithm_ggo.c deleted file mode 100644 index e0dd21c..0000000 --- a/vv/tools_ggo/clitkImageArithm_ggo.c +++ /dev/null @@ -1,1628 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22 - generated with the following command: - /usr/local/bin/gengetopt --output-dir=/home/tbaudier/vv/vv_static/vv/vv_bin/tools --arg-struct-name=args_info_clitkImageArithm --func-name=cmdline_parser_clitkImageArithm --file-name=clitkImageArithm_ggo --unamed-opts --conf-parser --include-getopt - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - - -#include "clitkImageArithm_ggo.h" - -const char *args_info_clitkImageArithm_purpose = "Perform an arithmetic operation (+-*/ ...) using two images or using an image \nand a scalar value."; - -const char *args_info_clitkImageArithm_usage = "Usage: clitkImageArithm [OPTIONS]... [FILES]..."; - -const char *args_info_clitkImageArithm_description = ""; - -const char *args_info_clitkImageArithm_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " --config=STRING Config file", - " -v, --verbose Verbose (default=off)", - " --imagetypes Display allowed image types (default=off)", - " -i, --input1=STRING Input first image filename", - " -j, --input2=STRING Input second image filename", - " -o, --output=STRING Output image filename", - " -s, --scalar=DOUBLE Scalar value", - " -t, --operation=INT Type of operation : \n With another image : 0=add*, 1=multiply, \n 2=divide,\n 3=max, 4=min, 5=absdiff, 6=squareddiff, \n 7=difference*, 8=relativ diff\n ; For 'scalar' : 0=add*, 1=multiply*, 2=inverse,\n 3=max, 4=min 5=absval 6=squareval\n 7=log 8=exp 9=sqrt 10=EPID 11=divide* \n 12=normalize (divide by max) 13=-ln(I/IO)**; \n * operations supported with vector fields as \n inputs. \n ** for fluence image, if pixel value == 0, \n consider value=0.5 (default=`0')", - " --pixelValue=DOUBLE Default value for NaN/Inf (default=`0.0')", - " -f, --setFloatOutput Set output to float pixel type (default=off)", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_INT - , ARG_DOUBLE -} cmdline_parser_clitkImageArithm_arg_type; - -static -void clear_given (struct args_info_clitkImageArithm *args_info); -static -void clear_args (struct args_info_clitkImageArithm *args_info); - -static int -cmdline_parser_clitkImageArithm_internal (int argc, char * const *argv, struct args_info_clitkImageArithm *args_info, - struct cmdline_parser_clitkImageArithm_params *params, const char *additional_error); - -static int -cmdline_parser_clitkImageArithm_required2 (struct args_info_clitkImageArithm *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct args_info_clitkImageArithm *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->config_given = 0 ; - args_info->verbose_given = 0 ; - args_info->imagetypes_given = 0 ; - args_info->input1_given = 0 ; - args_info->input2_given = 0 ; - args_info->output_given = 0 ; - args_info->scalar_given = 0 ; - args_info->operation_given = 0 ; - args_info->pixelValue_given = 0 ; - args_info->setFloatOutput_given = 0 ; -} - -static -void clear_args (struct args_info_clitkImageArithm *args_info) -{ - args_info->config_arg = NULL; - args_info->config_orig = NULL; - args_info->verbose_flag = 0; - args_info->imagetypes_flag = 0; - args_info->input1_arg = NULL; - args_info->input1_orig = NULL; - args_info->input2_arg = NULL; - args_info->input2_orig = NULL; - args_info->output_arg = NULL; - args_info->output_orig = NULL; - args_info->scalar_orig = NULL; - args_info->operation_arg = 0; - args_info->operation_orig = NULL; - args_info->pixelValue_arg = 0.0; - args_info->pixelValue_orig = NULL; - args_info->setFloatOutput_flag = 0; - -} - -static -void init_args_info(struct args_info_clitkImageArithm *args_info) -{ - - - args_info->help_help = args_info_clitkImageArithm_help[0] ; - args_info->version_help = args_info_clitkImageArithm_help[1] ; - args_info->config_help = args_info_clitkImageArithm_help[2] ; - args_info->verbose_help = args_info_clitkImageArithm_help[3] ; - args_info->imagetypes_help = args_info_clitkImageArithm_help[4] ; - args_info->input1_help = args_info_clitkImageArithm_help[5] ; - args_info->input2_help = args_info_clitkImageArithm_help[6] ; - args_info->output_help = args_info_clitkImageArithm_help[7] ; - args_info->scalar_help = args_info_clitkImageArithm_help[8] ; - args_info->operation_help = args_info_clitkImageArithm_help[9] ; - args_info->pixelValue_help = args_info_clitkImageArithm_help[10] ; - args_info->setFloatOutput_help = args_info_clitkImageArithm_help[11] ; - -} - -void -cmdline_parser_clitkImageArithm_print_version (void) -{ - printf ("%s %s\n", CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, CMDLINE_PARSER_CLITKIMAGEARITHM_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_clitkImageArithm_print_version (); - - if (strlen(args_info_clitkImageArithm_purpose) > 0) - printf("\n%s\n", args_info_clitkImageArithm_purpose); - - if (strlen(args_info_clitkImageArithm_usage) > 0) - printf("\n%s\n", args_info_clitkImageArithm_usage); - - printf("\n"); - - if (strlen(args_info_clitkImageArithm_description) > 0) - printf("%s\n", args_info_clitkImageArithm_description); -} - -void -cmdline_parser_clitkImageArithm_print_help (void) -{ - int i = 0; - print_help_common(); - while (args_info_clitkImageArithm_help[i]) - printf("%s\n", args_info_clitkImageArithm_help[i++]); -} - -void -cmdline_parser_clitkImageArithm_init (struct args_info_clitkImageArithm *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = NULL; - args_info->inputs_num = 0; -} - -void -cmdline_parser_clitkImageArithm_params_init(struct cmdline_parser_clitkImageArithm_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_clitkImageArithm_params * -cmdline_parser_clitkImageArithm_params_create(void) -{ - struct cmdline_parser_clitkImageArithm_params *params = - (struct cmdline_parser_clitkImageArithm_params *)malloc(sizeof(struct cmdline_parser_clitkImageArithm_params)); - cmdline_parser_clitkImageArithm_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - - -static void -cmdline_parser_clitkImageArithm_release (struct args_info_clitkImageArithm *args_info) -{ - unsigned int i; - free_string_field (&(args_info->config_arg)); - free_string_field (&(args_info->config_orig)); - free_string_field (&(args_info->input1_arg)); - free_string_field (&(args_info->input1_orig)); - free_string_field (&(args_info->input2_arg)); - free_string_field (&(args_info->input2_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - free_string_field (&(args_info->scalar_orig)); - free_string_field (&(args_info->operation_orig)); - free_string_field (&(args_info->pixelValue_orig)); - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) -{ - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -cmdline_parser_clitkImageArithm_dump(FILE *outfile, struct args_info_clitkImageArithm *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->config_given) - write_into_file(outfile, "config", args_info->config_orig, 0); - if (args_info->verbose_given) - write_into_file(outfile, "verbose", 0, 0 ); - if (args_info->imagetypes_given) - write_into_file(outfile, "imagetypes", 0, 0 ); - if (args_info->input1_given) - write_into_file(outfile, "input1", args_info->input1_orig, 0); - if (args_info->input2_given) - write_into_file(outfile, "input2", args_info->input2_orig, 0); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - if (args_info->scalar_given) - write_into_file(outfile, "scalar", args_info->scalar_orig, 0); - if (args_info->operation_given) - write_into_file(outfile, "operation", args_info->operation_orig, 0); - if (args_info->pixelValue_given) - write_into_file(outfile, "pixelValue", args_info->pixelValue_orig, 0); - if (args_info->setFloatOutput_given) - write_into_file(outfile, "setFloatOutput", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_clitkImageArithm_file_save(const char *filename, struct args_info_clitkImageArithm *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_clitkImageArithm_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_clitkImageArithm_free (struct args_info_clitkImageArithm *args_info) -{ - cmdline_parser_clitkImageArithm_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = NULL; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -cmdline_parser_clitkImageArithm (int argc, char * const *argv, struct args_info_clitkImageArithm *args_info) -{ - return cmdline_parser_clitkImageArithm2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_clitkImageArithm_ext (int argc, char * const *argv, struct args_info_clitkImageArithm *args_info, - struct cmdline_parser_clitkImageArithm_params *params) -{ - int result; - result = cmdline_parser_clitkImageArithm_internal (argc, argv, args_info, params, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkImageArithm_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkImageArithm2 (int argc, char * const *argv, struct args_info_clitkImageArithm *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_clitkImageArithm_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_clitkImageArithm_internal (argc, argv, args_info, ¶ms, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkImageArithm_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkImageArithm_required (struct args_info_clitkImageArithm *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_clitkImageArithm_required2(args_info, prog_name, NULL) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkImageArithm_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkImageArithm_required2 (struct args_info_clitkImageArithm *args_info, const char *prog_name, const char *additional_error) -{ - int error = 0; - - /* checks for required options */ - if (! args_info->input1_given) - { - fprintf (stderr, "%s: '--input1' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->output_given) - { - fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - - /* checks for dependences among options */ - - return error; -} - -/* - * Extracted from the glibc source tree, version 2.3.6 - * - * Licensed under the GPL as per the whole glibc source tree. - * - * This file was modified so that getopt_long can be called - * many times without risking previous memory to be spoiled. - * - * Modified by Andre Noll and Lorenzo Bettini for use in - * GNU gengetopt generated files. - * - */ - -/* - * we must include anything we need since this file is not thought to be - * inserted in a file already using getopt.h - * - * Lorenzo - */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -static char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -static int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -static int opterr; - -/* Set to an option character which was unrecognized. */ - -static int optopt; - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. -*/ -/* - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `custom_optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -/* Names for the values of the `has_arg' field of `struct option'. */ -#ifndef no_argument -#define no_argument 0 -#endif - -#ifndef required_argument -#define required_argument 1 -#endif - -#ifndef optional_argument -#define optional_argument 2 -#endif - -struct custom_getopt_data { - /* - * These have exactly the same meaning as the corresponding global variables, - * except that they are used for the reentrant versions of getopt. - */ - int custom_optind; - int custom_opterr; - int custom_optopt; - char *custom_optarg; - - /* True if the internal members have been initialized. */ - int initialized; - - /* - * The next char to be scanned in the option-element in which the last option - * character we returned was found. This allows us to pick up the scan where - * we left off. If this is zero, or a null string, it means resume the scan by - * advancing to the next ARGV-element. - */ - char *nextchar; - - /* - * Describe the part of ARGV that contains non-options that have been skipped. - * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is - * the index after the last of them. - */ - int first_nonopt; - int last_nonopt; -}; - -/* - * the variables optarg, optind, opterr and optopt are renamed with - * the custom_ prefix so that they don't interfere with getopt ones. - * - * Moreover they're static so they are visible only from within the - * file where this very file will be included. - */ - -/* - * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an - * option that takes an argument, the argument value is returned here. - */ -static char *custom_optarg; - -/* - * Index in ARGV of the next element to be scanned. This is used for - * communication to and from the caller and for communication between - * successive calls to `custom_getopt'. - * - * On entry to `custom_getopt', 1 means this is the first call; initialize. - * - * When `custom_getopt' returns -1, this is the index of the first of the non-option - * elements that the caller should itself scan. - * - * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV - * has been scanned so far. - * - * 1003.2 says this must be 1 before any call. - */ -static int custom_optind = 1; - -/* - * Callers store zero here to inhibit the error message for unrecognized - * options. - */ -static int custom_opterr = 1; - -/* - * Set to an option character which was unrecognized. This must be initialized - * on some systems to avoid linking in the system's own getopt implementation. - */ -static int custom_optopt = '?'; - -/* - * Exchange two adjacent subsequences of ARGV. One subsequence is elements - * [first_nonopt,last_nonopt) which contains all the non-options that have been - * skipped so far. The other is elements [last_nonopt,custom_optind), which contains - * all the options processed since those non-options were skipped. - * `first_nonopt' and `last_nonopt' are relocated so that they describe the new - * indices of the non-options in ARGV after they are moved. - */ -static void exchange(char **argv, struct custom_getopt_data *d) -{ - int bottom = d->first_nonopt; - int middle = d->last_nonopt; - int top = d->custom_optind; - char *tem; - - /* - * Exchange the shorter segment with the far end of the longer segment. - * That puts the shorter segment into the right place. It leaves the - * longer segment in the right place overall, but it consists of two - * parts that need to be swapped next. - */ - while (top > middle && middle > bottom) { - if (top - middle > middle - bottom) { - /* Bottom segment is the short one. */ - int len = middle - bottom; - int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = - argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } else { - /* Top segment is the short one. */ - int len = top - middle; - int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - /* Update records for the slots the non-options now occupy. */ - d->first_nonopt += (d->custom_optind - d->last_nonopt); - d->last_nonopt = d->custom_optind; -} - -/* Initialize the internal data when the first call is made. */ -static void custom_getopt_initialize(struct custom_getopt_data *d) -{ - /* - * Start processing options with ARGV-element 1 (since ARGV-element 0 - * is the program name); the sequence of previously skipped non-option - * ARGV-elements is empty. - */ - d->first_nonopt = d->last_nonopt = d->custom_optind; - d->nextchar = NULL; - d->initialized = 1; -} - -#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0') - -/* return: zero: continue, nonzero: return given value to user */ -static int shuffle_argv(int argc, char *const *argv,const struct option *longopts, - struct custom_getopt_data *d) -{ - /* - * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been - * moved back by the user (who may also have changed the arguments). - */ - if (d->last_nonopt > d->custom_optind) - d->last_nonopt = d->custom_optind; - if (d->first_nonopt > d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * If we have just processed some options following some - * non-options, exchange them so that the options come first. - */ - if (d->first_nonopt != d->last_nonopt && - d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->last_nonopt != d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * Skip any additional non-options and extend the range of - * non-options previously skipped. - */ - while (d->custom_optind < argc && NONOPTION_P) - d->custom_optind++; - d->last_nonopt = d->custom_optind; - /* - * The special ARGV-element `--' means premature end of options. Skip - * it like a null option, then exchange with previous non-options as if - * it were an option, then skip everything else like a non-option. - */ - if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) { - d->custom_optind++; - if (d->first_nonopt != d->last_nonopt - && d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->first_nonopt == d->last_nonopt) - d->first_nonopt = d->custom_optind; - d->last_nonopt = argc; - d->custom_optind = argc; - } - /* - * If we have done all the ARGV-elements, stop the scan and back over - * any non-options that we skipped and permuted. - */ - if (d->custom_optind == argc) { - /* - * Set the next-arg-index to point at the non-options that we - * previously skipped, so the caller will digest them. - */ - if (d->first_nonopt != d->last_nonopt) - d->custom_optind = d->first_nonopt; - return -1; - } - /* - * If we have come to a non-option and did not permute it, either stop - * the scan or describe it to the caller and pass it by. - */ - if (NONOPTION_P) { - d->custom_optarg = argv[d->custom_optind++]; - return 1; - } - /* - * We have found another option-ARGV-element. Skip the initial - * punctuation. - */ - d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-')); - return 0; -} - -/* - * Check whether the ARGV-element is a long option. - * - * If there's a long option "fubar" and the ARGV-element is "-fu", consider - * that an abbreviation of the long option, just like "--fu", and not "-f" with - * arg "u". - * - * This distinction seems to be the most useful approach. - * - */ -static int check_long_opt(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - int print_errors, struct custom_getopt_data *d) -{ - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match or abbreviated matches */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) { - if ((unsigned int) (nameend - d->nextchar) - == (unsigned int) strlen(p->name)) { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } else if (pfound == NULL) { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } else if (pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' is ambiguous\n", - argv[0], argv[d->custom_optind]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optind++; - d->custom_optopt = 0; - return '?'; - } - if (pfound) { - option_index = indfound; - d->custom_optind++; - if (*nameend) { - if (pfound->has_arg != no_argument) - d->custom_optarg = nameend + 1; - else { - if (print_errors) { - if (argv[d->custom_optind - 1][1] == '-') { - /* --option */ - fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[d->custom_optind - 1][0], pfound->name); - } - - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return '?'; - } - } else if (pfound->has_arg == required_argument) { - if (d->custom_optind < argc) - d->custom_optarg = argv[d->custom_optind++]; - else { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' requires an argument\n", - argv[0], - argv[d->custom_optind - 1]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->nextchar += strlen(d->nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* - * Can't find it as a long option. If this is not getopt_long_only, or - * the option starts with '--' or is not a valid short option, then - * it's an error. Otherwise interpret it as a short option. - */ - if (print_errors) { - if (argv[d->custom_optind][1] == '-') { - /* --option */ - fprintf(stderr, - "%s: unrecognized option `--%s'\n", - argv[0], d->nextchar); - } else { - /* +option or -option */ - fprintf(stderr, - "%s: unrecognized option `%c%s'\n", - argv[0], argv[d->custom_optind][0], - d->nextchar); - } - } - d->nextchar = (char *) ""; - d->custom_optind++; - d->custom_optopt = 0; - return '?'; -} - -static int check_short_opt(int argc, char *const *argv, const char *optstring, - int print_errors, struct custom_getopt_data *d) -{ - char c = *d->nextchar++; - char *temp = strchr(optstring, c); - - /* Increment `custom_optind' when we start to process its last character. */ - if (*d->nextchar == '\0') - ++d->custom_optind; - if (!temp || c == ':') { - if (print_errors) - fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); - - d->custom_optopt = c; - return '?'; - } - if (temp[1] == ':') { - if (temp[2] == ':') { - /* This is an option that accepts an argument optionally. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - d->custom_optind++; - } else - d->custom_optarg = NULL; - d->nextchar = NULL; - } else { - /* This is an option that requires an argument. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - /* - * If we end this ARGV-element by taking the - * rest as an arg, we must advance to the next - * element now. - */ - d->custom_optind++; - } else if (d->custom_optind == argc) { - if (print_errors) { - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], c); - } - d->custom_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } else - /* - * We already incremented `custom_optind' once; - * increment it again when taking next ARGV-elt - * as argument. - */ - d->custom_optarg = argv[d->custom_optind++]; - d->nextchar = NULL; - } - } - return c; -} - -/* - * Scan elements of ARGV for option characters given in OPTSTRING. - * - * If an element of ARGV starts with '-', and is not exactly "-" or "--", - * then it is an option element. The characters of this element - * (aside from the initial '-') are option characters. If `getopt' - * is called repeatedly, it returns successively each of the option characters - * from each of the option elements. - * - * If `getopt' finds another option character, it returns that character, - * updating `custom_optind' and `nextchar' so that the next call to `getopt' can - * resume the scan with the following option character or ARGV-element. - * - * If there are no more option characters, `getopt' returns -1. - * Then `custom_optind' is the index in ARGV of the first ARGV-element - * that is not an option. (The ARGV-elements have been permuted - * so that those that are not options now come last.) - * - * OPTSTRING is a string containing the legitimate option characters. - * If an option character is seen that is not listed in OPTSTRING, - * return '?' after printing an error message. If you set `custom_opterr' to - * zero, the error message is suppressed but we still return '?'. - * - * If a char in OPTSTRING is followed by a colon, that means it wants an arg, - * so the following text in the same ARGV-element, or the text of the following - * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that - * wants an optional arg; if there is text in the current ARGV-element, - * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero. - * - * If OPTSTRING starts with `-' or `+', it requests different methods of - * handling the non-option ARGV-elements. - * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - * - * Long-named options begin with `--' instead of `-'. - * Their names may be abbreviated as long as the abbreviation is unique - * or is an exact match for some defined option. If they have an - * argument, it follows the option name in the same ARGV-element, separated - * from the option name by a `=', or else the in next ARGV-element. - * When `getopt' finds a long-named option, it returns 0 if that option's - * `flag' field is nonzero, the value of the option's `val' field - * if the `flag' field is zero. - * - * The elements of ARGV aren't really const, because we permute them. - * But we pretend they're const in the prototype to be compatible - * with other systems. - * - * LONGOPTS is a vector of `struct option' terminated by an - * element containing a name which is zero. - * - * LONGIND returns the index in LONGOPT of the long-named option found. - * It is only valid when a long-named option has been found by the most - * recent call. - * - * Return the option character from OPTS just read. Return -1 when there are - * no more options. For unrecognized options, or options missing arguments, - * `custom_optopt' is set to the option letter, and '?' is returned. - * - * The OPTS string is a list of characters which are recognized option letters, - * optionally followed by colons, specifying that that letter takes an - * argument, to be placed in `custom_optarg'. - * - * If a letter in OPTS is followed by two colons, its argument is optional. - * This behavior is specific to the GNU `getopt'. - * - * The argument `--' causes premature termination of argument scanning, - * explicitly telling `getopt' that there are no more options. If OPTS begins - * with `--', then non-option arguments are treated as arguments to the option - * '\0'. This behavior is specific to the GNU `getopt'. - */ - -static int getopt_internal_r(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - struct custom_getopt_data *d) -{ - int ret, print_errors = d->custom_opterr; - - if (optstring[0] == ':') - print_errors = 0; - if (argc < 1) - return -1; - d->custom_optarg = NULL; - - /* - * This is a big difference with GNU getopt, since optind == 0 - * means initialization while here 1 means first call. - */ - if (d->custom_optind == 0 || !d->initialized) { - if (d->custom_optind == 0) - d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */ - custom_getopt_initialize(d); - } - if (d->nextchar == NULL || *d->nextchar == '\0') { - ret = shuffle_argv(argc, argv, longopts, d); - if (ret) - return ret; - } - if (longopts && (argv[d->custom_optind][1] == '-' )) - return check_long_opt(argc, argv, optstring, longopts, - longind, print_errors, d); - return check_short_opt(argc, argv, optstring, print_errors, d); -} - -static int custom_getopt_internal(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind) -{ - int result; - /* Keep a global copy of all internal members of d */ - static struct custom_getopt_data d; - - d.custom_optind = custom_optind; - d.custom_opterr = custom_opterr; - result = getopt_internal_r(argc, argv, optstring, longopts, - longind, &d); - custom_optind = d.custom_optind; - custom_optarg = d.custom_optarg; - custom_optopt = d.custom_optopt; - return result; -} - -static int custom_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return custom_getopt_internal(argc, argv, options, long_options, - opt_index); -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_clitkImageArithm_params.check_ambiguity - * @param override @see cmdline_parser_clitkImageArithm_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, - cmdline_parser_clitkImageArithm_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_INT: - if (val) *((int *)field) = strtol (val, &stop_char, 0); - break; - case ARG_DOUBLE: - if (val) *((double *)field) = strtod (val, &stop_char); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_INT: - case ARG_DOUBLE: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -int -cmdline_parser_clitkImageArithm_internal (int argc, char * const *argv, struct args_info_clitkImageArithm *args_info, - struct cmdline_parser_clitkImageArithm_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error = 0; - struct args_info_clitkImageArithm local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_clitkImageArithm_init (args_info); - - cmdline_parser_clitkImageArithm_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "config", 1, NULL, 0 }, - { "verbose", 0, NULL, 'v' }, - { "imagetypes", 0, NULL, 0 }, - { "input1", 1, NULL, 'i' }, - { "input2", 1, NULL, 'j' }, - { "output", 1, NULL, 'o' }, - { "scalar", 1, NULL, 's' }, - { "operation", 1, NULL, 't' }, - { "pixelValue", 1, NULL, 0 }, - { "setFloatOutput", 0, NULL, 'f' }, - { NULL, 0, NULL, 0 } - }; - - custom_optarg = optarg; - custom_optind = optind; - custom_opterr = opterr; - custom_optopt = optopt; - - c = custom_getopt_long (argc, argv, "hVvi:j:o:s:t:f", long_options, &option_index); - - optarg = custom_optarg; - optind = custom_optind; - opterr = custom_opterr; - optopt = custom_optopt; - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_clitkImageArithm_print_help (); - cmdline_parser_clitkImageArithm_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_clitkImageArithm_print_version (); - cmdline_parser_clitkImageArithm_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'v': /* Verbose. */ - - - if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) - goto failure; - - break; - case 'i': /* Input first image filename. */ - - - if (update_arg( (void *)&(args_info->input1_arg), - &(args_info->input1_orig), &(args_info->input1_given), - &(local_args_info.input1_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "input1", 'i', - additional_error)) - goto failure; - - break; - case 'j': /* Input second image filename. */ - - - if (update_arg( (void *)&(args_info->input2_arg), - &(args_info->input2_orig), &(args_info->input2_given), - &(local_args_info.input2_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "input2", 'j', - additional_error)) - goto failure; - - break; - case 'o': /* Output image filename. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - case 's': /* Scalar value. */ - - - if (update_arg( (void *)&(args_info->scalar_arg), - &(args_info->scalar_orig), &(args_info->scalar_given), - &(local_args_info.scalar_given), optarg, 0, 0, ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "scalar", 's', - additional_error)) - goto failure; - - break; - case 't': /* Type of operation : \n With another image : 0=add*, 1=multiply, 2=divide,\n 3=max, 4=min, 5=absdiff, 6=squareddiff, 7=difference*, 8=relativ diff\n; For 'scalar' : 0=add*, 1=multiply*, 2=inverse,\n 3=max, 4=min 5=absval 6=squareval\n 7=log 8=exp 9=sqrt 10=EPID 11=divide* 12=normalize (divide by max) 13=-ln(I/IO)**; \n* operations supported with vector fields as inputs. \n** for fluence image, if pixel value == 0, consider value=0.5. */ - - - if (update_arg( (void *)&(args_info->operation_arg), - &(args_info->operation_orig), &(args_info->operation_given), - &(local_args_info.operation_given), optarg, 0, "0", ARG_INT, - check_ambiguity, override, 0, 0, - "operation", 't', - additional_error)) - goto failure; - - break; - case 'f': /* Set output to float pixel type. */ - - - if (update_arg((void *)&(args_info->setFloatOutput_flag), 0, &(args_info->setFloatOutput_given), - &(local_args_info.setFloatOutput_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "setFloatOutput", 'f', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Config file. */ - if (strcmp (long_options[option_index].name, "config") == 0) - { - - - if (update_arg( (void *)&(args_info->config_arg), - &(args_info->config_orig), &(args_info->config_given), - &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "config", '-', - additional_error)) - goto failure; - - } - /* Display allowed image types. */ - else if (strcmp (long_options[option_index].name, "imagetypes") == 0) - { - - - if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given), - &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "imagetypes", '-', - additional_error)) - goto failure; - - } - /* Default value for NaN/Inf. */ - else if (strcmp (long_options[option_index].name, "pixelValue") == 0) - { - - - if (update_arg( (void *)&(args_info->pixelValue_arg), - &(args_info->pixelValue_orig), &(args_info->pixelValue_given), - &(local_args_info.pixelValue_given), optarg, 0, "0.0", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "pixelValue", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - if (check_required) - { - error += cmdline_parser_clitkImageArithm_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_clitkImageArithm_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; - } - - return 0; - -failure: - - cmdline_parser_clitkImageArithm_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_cmdline_parser_clitkImageArithm_configfile (char * const filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == NULL) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = NULL; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _cmdline_parser_clitkImageArithm_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -cmdline_parser_clitkImageArithm_configfile (char * const filename, - struct args_info_clitkImageArithm *args_info, - int override, int initialize, int check_required) -{ - struct cmdline_parser_clitkImageArithm_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return cmdline_parser_clitkImageArithm_config_file (filename, args_info, ¶ms); -} - -int -cmdline_parser_clitkImageArithm_config_file (char * const filename, - struct args_info_clitkImageArithm *args_info, - struct cmdline_parser_clitkImageArithm_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE); - - result = _cmdline_parser_clitkImageArithm_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - cmdline_parser_clitkImageArithm_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkImageArithm_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/vv/tools_ggo/clitkImageArithm_ggo.h b/vv/tools_ggo/clitkImageArithm_ggo.h deleted file mode 100644 index afea948..0000000 --- a/vv/tools_ggo/clitkImageArithm_ggo.h +++ /dev/null @@ -1,230 +0,0 @@ -/** @file clitkImageArithm_ggo.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef CLITKIMAGEARITHM_GGO_H -#define CLITKIMAGEARITHM_GGO_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE -/** @brief the program name */ -#define CMDLINE_PARSER_CLITKIMAGEARITHM_PACKAGE "clitkImageArithm" -#endif - -#ifndef CMDLINE_PARSER_CLITKIMAGEARITHM_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_CLITKIMAGEARITHM_VERSION "1.0" -#endif - -/** @brief Where the command line options are stored */ -struct args_info_clitkImageArithm -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * config_arg; /**< @brief Config file. */ - char * config_orig; /**< @brief Config file original value given at command line. */ - const char *config_help; /**< @brief Config file help description. */ - int verbose_flag; /**< @brief Verbose (default=off). */ - const char *verbose_help; /**< @brief Verbose help description. */ - int imagetypes_flag; /**< @brief Display allowed image types (default=off). */ - const char *imagetypes_help; /**< @brief Display allowed image types help description. */ - char * input1_arg; /**< @brief Input first image filename. */ - char * input1_orig; /**< @brief Input first image filename original value given at command line. */ - const char *input1_help; /**< @brief Input first image filename help description. */ - char * input2_arg; /**< @brief Input second image filename. */ - char * input2_orig; /**< @brief Input second image filename original value given at command line. */ - const char *input2_help; /**< @brief Input second image filename help description. */ - char * output_arg; /**< @brief Output image filename. */ - char * output_orig; /**< @brief Output image filename original value given at command line. */ - const char *output_help; /**< @brief Output image filename help description. */ - double scalar_arg; /**< @brief Scalar value. */ - char * scalar_orig; /**< @brief Scalar value original value given at command line. */ - const char *scalar_help; /**< @brief Scalar value help description. */ - int operation_arg; /**< @brief Type of operation : \n With another image : 0=add*, 1=multiply, 2=divide,\n 3=max, 4=min, 5=absdiff, 6=squareddiff, 7=difference*, 8=relativ diff\n; For 'scalar' : 0=add*, 1=multiply*, 2=inverse,\n 3=max, 4=min 5=absval 6=squareval\n 7=log 8=exp 9=sqrt 10=EPID 11=divide* 12=normalize (divide by max) 13=-ln(I/IO)**; \n* operations supported with vector fields as inputs. \n** for fluence image, if pixel value == 0, consider value=0.5 (default='0'). */ - char * operation_orig; /**< @brief Type of operation : \n With another image : 0=add*, 1=multiply, 2=divide,\n 3=max, 4=min, 5=absdiff, 6=squareddiff, 7=difference*, 8=relativ diff\n; For 'scalar' : 0=add*, 1=multiply*, 2=inverse,\n 3=max, 4=min 5=absval 6=squareval\n 7=log 8=exp 9=sqrt 10=EPID 11=divide* 12=normalize (divide by max) 13=-ln(I/IO)**; \n* operations supported with vector fields as inputs. \n** for fluence image, if pixel value == 0, consider value=0.5 original value given at command line. */ - const char *operation_help; /**< @brief Type of operation : \n With another image : 0=add*, 1=multiply, 2=divide,\n 3=max, 4=min, 5=absdiff, 6=squareddiff, 7=difference*, 8=relativ diff\n; For 'scalar' : 0=add*, 1=multiply*, 2=inverse,\n 3=max, 4=min 5=absval 6=squareval\n 7=log 8=exp 9=sqrt 10=EPID 11=divide* 12=normalize (divide by max) 13=-ln(I/IO)**; \n* operations supported with vector fields as inputs. \n** for fluence image, if pixel value == 0, consider value=0.5 help description. */ - double pixelValue_arg; /**< @brief Default value for NaN/Inf (default='0.0'). */ - char * pixelValue_orig; /**< @brief Default value for NaN/Inf original value given at command line. */ - const char *pixelValue_help; /**< @brief Default value for NaN/Inf help description. */ - int setFloatOutput_flag; /**< @brief Set output to float pixel type (default=off). */ - const char *setFloatOutput_help; /**< @brief Set output to float pixel type help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int config_given ; /**< @brief Whether config was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int imagetypes_given ; /**< @brief Whether imagetypes was given. */ - unsigned int input1_given ; /**< @brief Whether input1 was given. */ - unsigned int input2_given ; /**< @brief Whether input2 was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int scalar_given ; /**< @brief Whether scalar was given. */ - unsigned int operation_given ; /**< @brief Whether operation was given. */ - unsigned int pixelValue_given ; /**< @brief Whether pixelValue was given. */ - unsigned int setFloatOutput_given ; /**< @brief Whether setFloatOutput was given. */ - - char **inputs ; /**< @brief unamed options (options without names) */ - unsigned inputs_num ; /**< @brief unamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_clitkImageArithm_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure args_info_clitkImageArithm (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure args_info_clitkImageArithm (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *args_info_clitkImageArithm_purpose; -/** @brief the usage string of the program */ -extern const char *args_info_clitkImageArithm_usage; -/** @brief all the lines making the help output */ -extern const char *args_info_clitkImageArithm_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkImageArithm (int argc, char * const *argv, - struct args_info_clitkImageArithm *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkImageArithm_ext() instead - */ -int cmdline_parser_clitkImageArithm2 (int argc, char * const *argv, - struct args_info_clitkImageArithm *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkImageArithm_ext (int argc, char * const *argv, - struct args_info_clitkImageArithm *args_info, - struct cmdline_parser_clitkImageArithm_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkImageArithm_dump(FILE *outfile, - struct args_info_clitkImageArithm *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkImageArithm_file_save(const char *filename, - struct args_info_clitkImageArithm *args_info); - -/** - * Print the help - */ -void cmdline_parser_clitkImageArithm_print_help(void); -/** - * Print the version - */ -void cmdline_parser_clitkImageArithm_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_clitkImageArithm_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_clitkImageArithm_params_init(struct cmdline_parser_clitkImageArithm_params *params); - -/** - * Allocates dynamically a cmdline_parser_clitkImageArithm_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_clitkImageArithm_params structure - */ -struct cmdline_parser_clitkImageArithm_params *cmdline_parser_clitkImageArithm_params_create(void); - -/** - * Initializes the passed args_info_clitkImageArithm structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_clitkImageArithm_init (struct args_info_clitkImageArithm *args_info); -/** - * Deallocates the string fields of the args_info_clitkImageArithm structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_clitkImageArithm_free (struct args_info_clitkImageArithm *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkImageArithm_config_file() instead - */ -int cmdline_parser_clitkImageArithm_configfile (char * const filename, - struct args_info_clitkImageArithm *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkImageArithm_config_file (char * const filename, - struct args_info_clitkImageArithm *args_info, - struct cmdline_parser_clitkImageArithm_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_clitkImageArithm_required (struct args_info_clitkImageArithm *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CLITKIMAGEARITHM_GGO_H */ diff --git a/vv/tools_ggo/clitkMIP_ggo.c b/vv/tools_ggo/clitkMIP_ggo.c deleted file mode 100644 index 5380103..0000000 --- a/vv/tools_ggo/clitkMIP_ggo.c +++ /dev/null @@ -1,1546 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22 - generated with the following command: - /usr/local/bin/gengetopt --output-dir=/home/tbaudier/vv/vv_static/vv/vv_bin/tools --arg-struct-name=args_info_clitkMIP --func-name=cmdline_parser_clitkMIP --file-name=clitkMIP_ggo --unamed-opts --conf-parser --include-getopt - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - - -#include "clitkMIP_ggo.h" - -const char *args_info_clitkMIP_purpose = ""; - -const char *args_info_clitkMIP_usage = "Usage: clitkMIP [OPTIONS]... [FILES]..."; - -const char *args_info_clitkMIP_description = ""; - -const char *args_info_clitkMIP_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " --config=STRING Config file", - " -v, --verbose Verbose (default=off)", - " --imagetypes Display allowed image types (default=off)", - " -i, --input=STRING Input image filename", - " -o, --output=STRING Output image filename", - " -d, --dimension=INT Dimension along which to projetct", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_INT -} cmdline_parser_clitkMIP_arg_type; - -static -void clear_given (struct args_info_clitkMIP *args_info); -static -void clear_args (struct args_info_clitkMIP *args_info); - -static int -cmdline_parser_clitkMIP_internal (int argc, char * const *argv, struct args_info_clitkMIP *args_info, - struct cmdline_parser_clitkMIP_params *params, const char *additional_error); - -static int -cmdline_parser_clitkMIP_required2 (struct args_info_clitkMIP *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct args_info_clitkMIP *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->config_given = 0 ; - args_info->verbose_given = 0 ; - args_info->imagetypes_given = 0 ; - args_info->input_given = 0 ; - args_info->output_given = 0 ; - args_info->dimension_given = 0 ; -} - -static -void clear_args (struct args_info_clitkMIP *args_info) -{ - args_info->config_arg = NULL; - args_info->config_orig = NULL; - args_info->verbose_flag = 0; - args_info->imagetypes_flag = 0; - args_info->input_arg = NULL; - args_info->input_orig = NULL; - args_info->output_arg = NULL; - args_info->output_orig = NULL; - args_info->dimension_orig = NULL; - -} - -static -void init_args_info(struct args_info_clitkMIP *args_info) -{ - - - args_info->help_help = args_info_clitkMIP_help[0] ; - args_info->version_help = args_info_clitkMIP_help[1] ; - args_info->config_help = args_info_clitkMIP_help[2] ; - args_info->verbose_help = args_info_clitkMIP_help[3] ; - args_info->imagetypes_help = args_info_clitkMIP_help[4] ; - args_info->input_help = args_info_clitkMIP_help[5] ; - args_info->output_help = args_info_clitkMIP_help[6] ; - args_info->dimension_help = args_info_clitkMIP_help[7] ; - -} - -void -cmdline_parser_clitkMIP_print_version (void) -{ - printf ("%s %s\n", CMDLINE_PARSER_CLITKMIP_PACKAGE, CMDLINE_PARSER_CLITKMIP_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_clitkMIP_print_version (); - - if (strlen(args_info_clitkMIP_purpose) > 0) - printf("\n%s\n", args_info_clitkMIP_purpose); - - if (strlen(args_info_clitkMIP_usage) > 0) - printf("\n%s\n", args_info_clitkMIP_usage); - - printf("\n"); - - if (strlen(args_info_clitkMIP_description) > 0) - printf("%s\n", args_info_clitkMIP_description); -} - -void -cmdline_parser_clitkMIP_print_help (void) -{ - int i = 0; - print_help_common(); - while (args_info_clitkMIP_help[i]) - printf("%s\n", args_info_clitkMIP_help[i++]); -} - -void -cmdline_parser_clitkMIP_init (struct args_info_clitkMIP *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = NULL; - args_info->inputs_num = 0; -} - -void -cmdline_parser_clitkMIP_params_init(struct cmdline_parser_clitkMIP_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_clitkMIP_params * -cmdline_parser_clitkMIP_params_create(void) -{ - struct cmdline_parser_clitkMIP_params *params = - (struct cmdline_parser_clitkMIP_params *)malloc(sizeof(struct cmdline_parser_clitkMIP_params)); - cmdline_parser_clitkMIP_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - - -static void -cmdline_parser_clitkMIP_release (struct args_info_clitkMIP *args_info) -{ - unsigned int i; - free_string_field (&(args_info->config_arg)); - free_string_field (&(args_info->config_orig)); - free_string_field (&(args_info->input_arg)); - free_string_field (&(args_info->input_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - free_string_field (&(args_info->dimension_orig)); - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) -{ - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -cmdline_parser_clitkMIP_dump(FILE *outfile, struct args_info_clitkMIP *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKMIP_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->config_given) - write_into_file(outfile, "config", args_info->config_orig, 0); - if (args_info->verbose_given) - write_into_file(outfile, "verbose", 0, 0 ); - if (args_info->imagetypes_given) - write_into_file(outfile, "imagetypes", 0, 0 ); - if (args_info->input_given) - write_into_file(outfile, "input", args_info->input_orig, 0); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - if (args_info->dimension_given) - write_into_file(outfile, "dimension", args_info->dimension_orig, 0); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_clitkMIP_file_save(const char *filename, struct args_info_clitkMIP *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKMIP_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_clitkMIP_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_clitkMIP_free (struct args_info_clitkMIP *args_info) -{ - cmdline_parser_clitkMIP_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = NULL; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -cmdline_parser_clitkMIP (int argc, char * const *argv, struct args_info_clitkMIP *args_info) -{ - return cmdline_parser_clitkMIP2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_clitkMIP_ext (int argc, char * const *argv, struct args_info_clitkMIP *args_info, - struct cmdline_parser_clitkMIP_params *params) -{ - int result; - result = cmdline_parser_clitkMIP_internal (argc, argv, args_info, params, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkMIP_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkMIP2 (int argc, char * const *argv, struct args_info_clitkMIP *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_clitkMIP_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_clitkMIP_internal (argc, argv, args_info, ¶ms, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkMIP_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkMIP_required (struct args_info_clitkMIP *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_clitkMIP_required2(args_info, prog_name, NULL) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkMIP_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkMIP_required2 (struct args_info_clitkMIP *args_info, const char *prog_name, const char *additional_error) -{ - int error = 0; - - /* checks for required options */ - if (! args_info->input_given) - { - fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->output_given) - { - fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->dimension_given) - { - fprintf (stderr, "%s: '--dimension' ('-d') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - - /* checks for dependences among options */ - - return error; -} - -/* - * Extracted from the glibc source tree, version 2.3.6 - * - * Licensed under the GPL as per the whole glibc source tree. - * - * This file was modified so that getopt_long can be called - * many times without risking previous memory to be spoiled. - * - * Modified by Andre Noll and Lorenzo Bettini for use in - * GNU gengetopt generated files. - * - */ - -/* - * we must include anything we need since this file is not thought to be - * inserted in a file already using getopt.h - * - * Lorenzo - */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -static char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -static int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -static int opterr; - -/* Set to an option character which was unrecognized. */ - -static int optopt; - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. -*/ -/* - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `custom_optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -/* Names for the values of the `has_arg' field of `struct option'. */ -#ifndef no_argument -#define no_argument 0 -#endif - -#ifndef required_argument -#define required_argument 1 -#endif - -#ifndef optional_argument -#define optional_argument 2 -#endif - -struct custom_getopt_data { - /* - * These have exactly the same meaning as the corresponding global variables, - * except that they are used for the reentrant versions of getopt. - */ - int custom_optind; - int custom_opterr; - int custom_optopt; - char *custom_optarg; - - /* True if the internal members have been initialized. */ - int initialized; - - /* - * The next char to be scanned in the option-element in which the last option - * character we returned was found. This allows us to pick up the scan where - * we left off. If this is zero, or a null string, it means resume the scan by - * advancing to the next ARGV-element. - */ - char *nextchar; - - /* - * Describe the part of ARGV that contains non-options that have been skipped. - * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is - * the index after the last of them. - */ - int first_nonopt; - int last_nonopt; -}; - -/* - * the variables optarg, optind, opterr and optopt are renamed with - * the custom_ prefix so that they don't interfere with getopt ones. - * - * Moreover they're static so they are visible only from within the - * file where this very file will be included. - */ - -/* - * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an - * option that takes an argument, the argument value is returned here. - */ -static char *custom_optarg; - -/* - * Index in ARGV of the next element to be scanned. This is used for - * communication to and from the caller and for communication between - * successive calls to `custom_getopt'. - * - * On entry to `custom_getopt', 1 means this is the first call; initialize. - * - * When `custom_getopt' returns -1, this is the index of the first of the non-option - * elements that the caller should itself scan. - * - * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV - * has been scanned so far. - * - * 1003.2 says this must be 1 before any call. - */ -static int custom_optind = 1; - -/* - * Callers store zero here to inhibit the error message for unrecognized - * options. - */ -static int custom_opterr = 1; - -/* - * Set to an option character which was unrecognized. This must be initialized - * on some systems to avoid linking in the system's own getopt implementation. - */ -static int custom_optopt = '?'; - -/* - * Exchange two adjacent subsequences of ARGV. One subsequence is elements - * [first_nonopt,last_nonopt) which contains all the non-options that have been - * skipped so far. The other is elements [last_nonopt,custom_optind), which contains - * all the options processed since those non-options were skipped. - * `first_nonopt' and `last_nonopt' are relocated so that they describe the new - * indices of the non-options in ARGV after they are moved. - */ -static void exchange(char **argv, struct custom_getopt_data *d) -{ - int bottom = d->first_nonopt; - int middle = d->last_nonopt; - int top = d->custom_optind; - char *tem; - - /* - * Exchange the shorter segment with the far end of the longer segment. - * That puts the shorter segment into the right place. It leaves the - * longer segment in the right place overall, but it consists of two - * parts that need to be swapped next. - */ - while (top > middle && middle > bottom) { - if (top - middle > middle - bottom) { - /* Bottom segment is the short one. */ - int len = middle - bottom; - int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = - argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } else { - /* Top segment is the short one. */ - int len = top - middle; - int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - /* Update records for the slots the non-options now occupy. */ - d->first_nonopt += (d->custom_optind - d->last_nonopt); - d->last_nonopt = d->custom_optind; -} - -/* Initialize the internal data when the first call is made. */ -static void custom_getopt_initialize(struct custom_getopt_data *d) -{ - /* - * Start processing options with ARGV-element 1 (since ARGV-element 0 - * is the program name); the sequence of previously skipped non-option - * ARGV-elements is empty. - */ - d->first_nonopt = d->last_nonopt = d->custom_optind; - d->nextchar = NULL; - d->initialized = 1; -} - -#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0') - -/* return: zero: continue, nonzero: return given value to user */ -static int shuffle_argv(int argc, char *const *argv,const struct option *longopts, - struct custom_getopt_data *d) -{ - /* - * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been - * moved back by the user (who may also have changed the arguments). - */ - if (d->last_nonopt > d->custom_optind) - d->last_nonopt = d->custom_optind; - if (d->first_nonopt > d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * If we have just processed some options following some - * non-options, exchange them so that the options come first. - */ - if (d->first_nonopt != d->last_nonopt && - d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->last_nonopt != d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * Skip any additional non-options and extend the range of - * non-options previously skipped. - */ - while (d->custom_optind < argc && NONOPTION_P) - d->custom_optind++; - d->last_nonopt = d->custom_optind; - /* - * The special ARGV-element `--' means premature end of options. Skip - * it like a null option, then exchange with previous non-options as if - * it were an option, then skip everything else like a non-option. - */ - if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) { - d->custom_optind++; - if (d->first_nonopt != d->last_nonopt - && d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->first_nonopt == d->last_nonopt) - d->first_nonopt = d->custom_optind; - d->last_nonopt = argc; - d->custom_optind = argc; - } - /* - * If we have done all the ARGV-elements, stop the scan and back over - * any non-options that we skipped and permuted. - */ - if (d->custom_optind == argc) { - /* - * Set the next-arg-index to point at the non-options that we - * previously skipped, so the caller will digest them. - */ - if (d->first_nonopt != d->last_nonopt) - d->custom_optind = d->first_nonopt; - return -1; - } - /* - * If we have come to a non-option and did not permute it, either stop - * the scan or describe it to the caller and pass it by. - */ - if (NONOPTION_P) { - d->custom_optarg = argv[d->custom_optind++]; - return 1; - } - /* - * We have found another option-ARGV-element. Skip the initial - * punctuation. - */ - d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-')); - return 0; -} - -/* - * Check whether the ARGV-element is a long option. - * - * If there's a long option "fubar" and the ARGV-element is "-fu", consider - * that an abbreviation of the long option, just like "--fu", and not "-f" with - * arg "u". - * - * This distinction seems to be the most useful approach. - * - */ -static int check_long_opt(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - int print_errors, struct custom_getopt_data *d) -{ - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match or abbreviated matches */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) { - if ((unsigned int) (nameend - d->nextchar) - == (unsigned int) strlen(p->name)) { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } else if (pfound == NULL) { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } else if (pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' is ambiguous\n", - argv[0], argv[d->custom_optind]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optind++; - d->custom_optopt = 0; - return '?'; - } - if (pfound) { - option_index = indfound; - d->custom_optind++; - if (*nameend) { - if (pfound->has_arg != no_argument) - d->custom_optarg = nameend + 1; - else { - if (print_errors) { - if (argv[d->custom_optind - 1][1] == '-') { - /* --option */ - fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[d->custom_optind - 1][0], pfound->name); - } - - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return '?'; - } - } else if (pfound->has_arg == required_argument) { - if (d->custom_optind < argc) - d->custom_optarg = argv[d->custom_optind++]; - else { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' requires an argument\n", - argv[0], - argv[d->custom_optind - 1]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->nextchar += strlen(d->nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* - * Can't find it as a long option. If this is not getopt_long_only, or - * the option starts with '--' or is not a valid short option, then - * it's an error. Otherwise interpret it as a short option. - */ - if (print_errors) { - if (argv[d->custom_optind][1] == '-') { - /* --option */ - fprintf(stderr, - "%s: unrecognized option `--%s'\n", - argv[0], d->nextchar); - } else { - /* +option or -option */ - fprintf(stderr, - "%s: unrecognized option `%c%s'\n", - argv[0], argv[d->custom_optind][0], - d->nextchar); - } - } - d->nextchar = (char *) ""; - d->custom_optind++; - d->custom_optopt = 0; - return '?'; -} - -static int check_short_opt(int argc, char *const *argv, const char *optstring, - int print_errors, struct custom_getopt_data *d) -{ - char c = *d->nextchar++; - char *temp = strchr(optstring, c); - - /* Increment `custom_optind' when we start to process its last character. */ - if (*d->nextchar == '\0') - ++d->custom_optind; - if (!temp || c == ':') { - if (print_errors) - fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); - - d->custom_optopt = c; - return '?'; - } - if (temp[1] == ':') { - if (temp[2] == ':') { - /* This is an option that accepts an argument optionally. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - d->custom_optind++; - } else - d->custom_optarg = NULL; - d->nextchar = NULL; - } else { - /* This is an option that requires an argument. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - /* - * If we end this ARGV-element by taking the - * rest as an arg, we must advance to the next - * element now. - */ - d->custom_optind++; - } else if (d->custom_optind == argc) { - if (print_errors) { - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], c); - } - d->custom_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } else - /* - * We already incremented `custom_optind' once; - * increment it again when taking next ARGV-elt - * as argument. - */ - d->custom_optarg = argv[d->custom_optind++]; - d->nextchar = NULL; - } - } - return c; -} - -/* - * Scan elements of ARGV for option characters given in OPTSTRING. - * - * If an element of ARGV starts with '-', and is not exactly "-" or "--", - * then it is an option element. The characters of this element - * (aside from the initial '-') are option characters. If `getopt' - * is called repeatedly, it returns successively each of the option characters - * from each of the option elements. - * - * If `getopt' finds another option character, it returns that character, - * updating `custom_optind' and `nextchar' so that the next call to `getopt' can - * resume the scan with the following option character or ARGV-element. - * - * If there are no more option characters, `getopt' returns -1. - * Then `custom_optind' is the index in ARGV of the first ARGV-element - * that is not an option. (The ARGV-elements have been permuted - * so that those that are not options now come last.) - * - * OPTSTRING is a string containing the legitimate option characters. - * If an option character is seen that is not listed in OPTSTRING, - * return '?' after printing an error message. If you set `custom_opterr' to - * zero, the error message is suppressed but we still return '?'. - * - * If a char in OPTSTRING is followed by a colon, that means it wants an arg, - * so the following text in the same ARGV-element, or the text of the following - * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that - * wants an optional arg; if there is text in the current ARGV-element, - * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero. - * - * If OPTSTRING starts with `-' or `+', it requests different methods of - * handling the non-option ARGV-elements. - * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - * - * Long-named options begin with `--' instead of `-'. - * Their names may be abbreviated as long as the abbreviation is unique - * or is an exact match for some defined option. If they have an - * argument, it follows the option name in the same ARGV-element, separated - * from the option name by a `=', or else the in next ARGV-element. - * When `getopt' finds a long-named option, it returns 0 if that option's - * `flag' field is nonzero, the value of the option's `val' field - * if the `flag' field is zero. - * - * The elements of ARGV aren't really const, because we permute them. - * But we pretend they're const in the prototype to be compatible - * with other systems. - * - * LONGOPTS is a vector of `struct option' terminated by an - * element containing a name which is zero. - * - * LONGIND returns the index in LONGOPT of the long-named option found. - * It is only valid when a long-named option has been found by the most - * recent call. - * - * Return the option character from OPTS just read. Return -1 when there are - * no more options. For unrecognized options, or options missing arguments, - * `custom_optopt' is set to the option letter, and '?' is returned. - * - * The OPTS string is a list of characters which are recognized option letters, - * optionally followed by colons, specifying that that letter takes an - * argument, to be placed in `custom_optarg'. - * - * If a letter in OPTS is followed by two colons, its argument is optional. - * This behavior is specific to the GNU `getopt'. - * - * The argument `--' causes premature termination of argument scanning, - * explicitly telling `getopt' that there are no more options. If OPTS begins - * with `--', then non-option arguments are treated as arguments to the option - * '\0'. This behavior is specific to the GNU `getopt'. - */ - -static int getopt_internal_r(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - struct custom_getopt_data *d) -{ - int ret, print_errors = d->custom_opterr; - - if (optstring[0] == ':') - print_errors = 0; - if (argc < 1) - return -1; - d->custom_optarg = NULL; - - /* - * This is a big difference with GNU getopt, since optind == 0 - * means initialization while here 1 means first call. - */ - if (d->custom_optind == 0 || !d->initialized) { - if (d->custom_optind == 0) - d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */ - custom_getopt_initialize(d); - } - if (d->nextchar == NULL || *d->nextchar == '\0') { - ret = shuffle_argv(argc, argv, longopts, d); - if (ret) - return ret; - } - if (longopts && (argv[d->custom_optind][1] == '-' )) - return check_long_opt(argc, argv, optstring, longopts, - longind, print_errors, d); - return check_short_opt(argc, argv, optstring, print_errors, d); -} - -static int custom_getopt_internal(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind) -{ - int result; - /* Keep a global copy of all internal members of d */ - static struct custom_getopt_data d; - - d.custom_optind = custom_optind; - d.custom_opterr = custom_opterr; - result = getopt_internal_r(argc, argv, optstring, longopts, - longind, &d); - custom_optind = d.custom_optind; - custom_optarg = d.custom_optarg; - custom_optopt = d.custom_optopt; - return result; -} - -static int custom_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return custom_getopt_internal(argc, argv, options, long_options, - opt_index); -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_clitkMIP_params.check_ambiguity - * @param override @see cmdline_parser_clitkMIP_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, - cmdline_parser_clitkMIP_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_INT: - if (val) *((int *)field) = strtol (val, &stop_char, 0); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_INT: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -int -cmdline_parser_clitkMIP_internal (int argc, char * const *argv, struct args_info_clitkMIP *args_info, - struct cmdline_parser_clitkMIP_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error = 0; - struct args_info_clitkMIP local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_clitkMIP_init (args_info); - - cmdline_parser_clitkMIP_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "config", 1, NULL, 0 }, - { "verbose", 0, NULL, 'v' }, - { "imagetypes", 0, NULL, 0 }, - { "input", 1, NULL, 'i' }, - { "output", 1, NULL, 'o' }, - { "dimension", 1, NULL, 'd' }, - { NULL, 0, NULL, 0 } - }; - - custom_optarg = optarg; - custom_optind = optind; - custom_opterr = opterr; - custom_optopt = optopt; - - c = custom_getopt_long (argc, argv, "hVvi:o:d:", long_options, &option_index); - - optarg = custom_optarg; - optind = custom_optind; - opterr = custom_opterr; - optopt = custom_optopt; - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_clitkMIP_print_help (); - cmdline_parser_clitkMIP_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_clitkMIP_print_version (); - cmdline_parser_clitkMIP_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'v': /* Verbose. */ - - - if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) - goto failure; - - break; - case 'i': /* Input image filename. */ - - - if (update_arg( (void *)&(args_info->input_arg), - &(args_info->input_orig), &(args_info->input_given), - &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "input", 'i', - additional_error)) - goto failure; - - break; - case 'o': /* Output image filename. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - case 'd': /* Dimension along which to projetct. */ - - - if (update_arg( (void *)&(args_info->dimension_arg), - &(args_info->dimension_orig), &(args_info->dimension_given), - &(local_args_info.dimension_given), optarg, 0, 0, ARG_INT, - check_ambiguity, override, 0, 0, - "dimension", 'd', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Config file. */ - if (strcmp (long_options[option_index].name, "config") == 0) - { - - - if (update_arg( (void *)&(args_info->config_arg), - &(args_info->config_orig), &(args_info->config_given), - &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "config", '-', - additional_error)) - goto failure; - - } - /* Display allowed image types. */ - else if (strcmp (long_options[option_index].name, "imagetypes") == 0) - { - - - if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given), - &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "imagetypes", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKMIP_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - if (check_required) - { - error += cmdline_parser_clitkMIP_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_clitkMIP_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; - } - - return 0; - -failure: - - cmdline_parser_clitkMIP_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_cmdline_parser_clitkMIP_configfile (char * const filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == NULL) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - CMDLINE_PARSER_CLITKMIP_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - CMDLINE_PARSER_CLITKMIP_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = NULL; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - CMDLINE_PARSER_CLITKMIP_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - CMDLINE_PARSER_CLITKMIP_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _cmdline_parser_clitkMIP_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - CMDLINE_PARSER_CLITKMIP_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -cmdline_parser_clitkMIP_configfile (char * const filename, - struct args_info_clitkMIP *args_info, - int override, int initialize, int check_required) -{ - struct cmdline_parser_clitkMIP_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return cmdline_parser_clitkMIP_config_file (filename, args_info, ¶ms); -} - -int -cmdline_parser_clitkMIP_config_file (char * const filename, - struct args_info_clitkMIP *args_info, - struct cmdline_parser_clitkMIP_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKMIP_PACKAGE); - - result = _cmdline_parser_clitkMIP_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - cmdline_parser_clitkMIP_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkMIP_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/vv/tools_ggo/clitkMIP_ggo.h b/vv/tools_ggo/clitkMIP_ggo.h deleted file mode 100644 index 70933d9..0000000 --- a/vv/tools_ggo/clitkMIP_ggo.h +++ /dev/null @@ -1,215 +0,0 @@ -/** @file clitkMIP_ggo.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef CLITKMIP_GGO_H -#define CLITKMIP_GGO_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_CLITKMIP_PACKAGE -/** @brief the program name */ -#define CMDLINE_PARSER_CLITKMIP_PACKAGE "clitkMIP" -#endif - -#ifndef CMDLINE_PARSER_CLITKMIP_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_CLITKMIP_VERSION "1.0" -#endif - -/** @brief Where the command line options are stored */ -struct args_info_clitkMIP -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * config_arg; /**< @brief Config file. */ - char * config_orig; /**< @brief Config file original value given at command line. */ - const char *config_help; /**< @brief Config file help description. */ - int verbose_flag; /**< @brief Verbose (default=off). */ - const char *verbose_help; /**< @brief Verbose help description. */ - int imagetypes_flag; /**< @brief Display allowed image types (default=off). */ - const char *imagetypes_help; /**< @brief Display allowed image types help description. */ - char * input_arg; /**< @brief Input image filename. */ - char * input_orig; /**< @brief Input image filename original value given at command line. */ - const char *input_help; /**< @brief Input image filename help description. */ - char * output_arg; /**< @brief Output image filename. */ - char * output_orig; /**< @brief Output image filename original value given at command line. */ - const char *output_help; /**< @brief Output image filename help description. */ - int dimension_arg; /**< @brief Dimension along which to projetct. */ - char * dimension_orig; /**< @brief Dimension along which to projetct original value given at command line. */ - const char *dimension_help; /**< @brief Dimension along which to projetct help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int config_given ; /**< @brief Whether config was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int imagetypes_given ; /**< @brief Whether imagetypes was given. */ - unsigned int input_given ; /**< @brief Whether input was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int dimension_given ; /**< @brief Whether dimension was given. */ - - char **inputs ; /**< @brief unamed options (options without names) */ - unsigned inputs_num ; /**< @brief unamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_clitkMIP_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure args_info_clitkMIP (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure args_info_clitkMIP (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *args_info_clitkMIP_purpose; -/** @brief the usage string of the program */ -extern const char *args_info_clitkMIP_usage; -/** @brief all the lines making the help output */ -extern const char *args_info_clitkMIP_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkMIP (int argc, char * const *argv, - struct args_info_clitkMIP *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkMIP_ext() instead - */ -int cmdline_parser_clitkMIP2 (int argc, char * const *argv, - struct args_info_clitkMIP *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkMIP_ext (int argc, char * const *argv, - struct args_info_clitkMIP *args_info, - struct cmdline_parser_clitkMIP_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkMIP_dump(FILE *outfile, - struct args_info_clitkMIP *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkMIP_file_save(const char *filename, - struct args_info_clitkMIP *args_info); - -/** - * Print the help - */ -void cmdline_parser_clitkMIP_print_help(void); -/** - * Print the version - */ -void cmdline_parser_clitkMIP_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_clitkMIP_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_clitkMIP_params_init(struct cmdline_parser_clitkMIP_params *params); - -/** - * Allocates dynamically a cmdline_parser_clitkMIP_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_clitkMIP_params structure - */ -struct cmdline_parser_clitkMIP_params *cmdline_parser_clitkMIP_params_create(void); - -/** - * Initializes the passed args_info_clitkMIP structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_clitkMIP_init (struct args_info_clitkMIP *args_info); -/** - * Deallocates the string fields of the args_info_clitkMIP structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_clitkMIP_free (struct args_info_clitkMIP *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkMIP_config_file() instead - */ -int cmdline_parser_clitkMIP_configfile (char * const filename, - struct args_info_clitkMIP *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkMIP_config_file (char * const filename, - struct args_info_clitkMIP *args_info, - struct cmdline_parser_clitkMIP_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_clitkMIP_required (struct args_info_clitkMIP *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CLITKMIP_GGO_H */ diff --git a/vv/tools_ggo/clitkMedianImageFilter_ggo.c b/vv/tools_ggo/clitkMedianImageFilter_ggo.c deleted file mode 100644 index f3449a9..0000000 --- a/vv/tools_ggo/clitkMedianImageFilter_ggo.c +++ /dev/null @@ -1,1847 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22 - generated with the following command: - /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 - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - - -#include "clitkMedianImageFilter_ggo.h" - -const char *args_info_clitkMedianImageFilter_purpose = ""; - -const char *args_info_clitkMedianImageFilter_usage = "Usage: clitkMedianImageFilter [OPTIONS]... [FILES]..."; - -const char *args_info_clitkMedianImageFilter_description = ""; - -const char *args_info_clitkMedianImageFilter_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " --config=STRING Config file", - " -v, --verbose Verbose (default=off)", - " -i, --input=STRING Input image filename", - " -o, --output=STRING Output image filename", - " -r, --radius=INT Radius in each Direction (default=`1')", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_INT -} cmdline_parser_clitkMedianImageFilter_arg_type; - -static -void clear_given (struct args_info_clitkMedianImageFilter *args_info); -static -void clear_args (struct args_info_clitkMedianImageFilter *args_info); - -static int -cmdline_parser_clitkMedianImageFilter_internal (int argc, char * const *argv, struct args_info_clitkMedianImageFilter *args_info, - struct cmdline_parser_clitkMedianImageFilter_params *params, const char *additional_error); - -static int -cmdline_parser_clitkMedianImageFilter_required2 (struct args_info_clitkMedianImageFilter *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct args_info_clitkMedianImageFilter *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->config_given = 0 ; - args_info->verbose_given = 0 ; - args_info->input_given = 0 ; - args_info->output_given = 0 ; - args_info->radius_given = 0 ; -} - -static -void clear_args (struct args_info_clitkMedianImageFilter *args_info) -{ - args_info->config_arg = NULL; - args_info->config_orig = NULL; - args_info->verbose_flag = 0; - args_info->input_arg = NULL; - args_info->input_orig = NULL; - args_info->output_arg = NULL; - args_info->output_orig = NULL; - args_info->radius_arg = NULL; - args_info->radius_orig = NULL; - -} - -static -void init_args_info(struct args_info_clitkMedianImageFilter *args_info) -{ - - - args_info->help_help = args_info_clitkMedianImageFilter_help[0] ; - args_info->version_help = args_info_clitkMedianImageFilter_help[1] ; - args_info->config_help = args_info_clitkMedianImageFilter_help[2] ; - args_info->verbose_help = args_info_clitkMedianImageFilter_help[3] ; - args_info->input_help = args_info_clitkMedianImageFilter_help[4] ; - args_info->output_help = args_info_clitkMedianImageFilter_help[5] ; - args_info->radius_help = args_info_clitkMedianImageFilter_help[6] ; - args_info->radius_min = -1; - args_info->radius_max = -1; - -} - -void -cmdline_parser_clitkMedianImageFilter_print_version (void) -{ - printf ("%s %s\n", CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_clitkMedianImageFilter_print_version (); - - if (strlen(args_info_clitkMedianImageFilter_purpose) > 0) - printf("\n%s\n", args_info_clitkMedianImageFilter_purpose); - - if (strlen(args_info_clitkMedianImageFilter_usage) > 0) - printf("\n%s\n", args_info_clitkMedianImageFilter_usage); - - printf("\n"); - - if (strlen(args_info_clitkMedianImageFilter_description) > 0) - printf("%s\n", args_info_clitkMedianImageFilter_description); -} - -void -cmdline_parser_clitkMedianImageFilter_print_help (void) -{ - int i = 0; - print_help_common(); - while (args_info_clitkMedianImageFilter_help[i]) - printf("%s\n", args_info_clitkMedianImageFilter_help[i++]); -} - -void -cmdline_parser_clitkMedianImageFilter_init (struct args_info_clitkMedianImageFilter *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = NULL; - args_info->inputs_num = 0; -} - -void -cmdline_parser_clitkMedianImageFilter_params_init(struct cmdline_parser_clitkMedianImageFilter_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_clitkMedianImageFilter_params * -cmdline_parser_clitkMedianImageFilter_params_create(void) -{ - struct cmdline_parser_clitkMedianImageFilter_params *params = - (struct cmdline_parser_clitkMedianImageFilter_params *)malloc(sizeof(struct cmdline_parser_clitkMedianImageFilter_params)); - cmdline_parser_clitkMedianImageFilter_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - -/** @brief generic value variable */ -union generic_value { - int int_arg; - char *string_arg; -}; - -/** @brief holds temporary values for multiple options */ -struct generic_list -{ - union generic_value arg; - char *orig; - struct generic_list *next; -}; - -/** - * @brief add a node at the head of the list - */ -static void add_node(struct generic_list **list) { - struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); - new_node->next = *list; - *list = new_node; - new_node->arg.string_arg = NULL; - new_node->orig = NULL; -} - -static void -free_multiple_field(unsigned int len, void **arg, char ***orig) -{ - unsigned int i; - if (*arg) { - for (i = 0; i < len; ++i) - { - free_string_field(&((*orig)[i])); - } - - free (*arg); - *arg = 0; - free (*orig); - *orig = 0; - } -} - - -static void -cmdline_parser_clitkMedianImageFilter_release (struct args_info_clitkMedianImageFilter *args_info) -{ - unsigned int i; - free_string_field (&(args_info->config_arg)); - free_string_field (&(args_info->config_orig)); - free_string_field (&(args_info->input_arg)); - free_string_field (&(args_info->input_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - free_multiple_field (args_info->radius_given, (void **)&(args_info->radius_arg), &(args_info->radius_orig)); - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) -{ - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - -static void -write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[]) -{ - int i; - - for (i = 0; i < len; ++i) - write_into_file(outfile, opt, (arg ? arg[i] : 0), values); -} - -int -cmdline_parser_clitkMedianImageFilter_dump(FILE *outfile, struct args_info_clitkMedianImageFilter *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->config_given) - write_into_file(outfile, "config", args_info->config_orig, 0); - if (args_info->verbose_given) - write_into_file(outfile, "verbose", 0, 0 ); - if (args_info->input_given) - write_into_file(outfile, "input", args_info->input_orig, 0); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - write_multiple_into_file(outfile, args_info->radius_given, "radius", args_info->radius_orig, 0); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_clitkMedianImageFilter_file_save(const char *filename, struct args_info_clitkMedianImageFilter *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_clitkMedianImageFilter_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_clitkMedianImageFilter_free (struct args_info_clitkMedianImageFilter *args_info) -{ - cmdline_parser_clitkMedianImageFilter_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = NULL; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -static char * -get_multiple_arg_token(const char *arg) -{ - char *tok, *ret; - size_t len, num_of_escape, i, j; - - if (!arg) - return NULL; - - tok = strchr (arg, ','); - num_of_escape = 0; - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - ++num_of_escape; - } - else - break; - } - - if (tok) - len = (size_t)(tok - arg + 1); - else - len = strlen (arg) + 1; - - len -= num_of_escape; - - ret = (char *) malloc (len); - - i = 0; - j = 0; - while (arg[i] && (j < len-1)) - { - if (arg[i] == '\\' && - arg[ i + 1 ] && - arg[ i + 1 ] == ',') - ++i; - - ret[j++] = arg[i++]; - } - - ret[len-1] = '\0'; - - return ret; -} - -static char * -get_multiple_arg_token_next(const char *arg) -{ - char *tok; - - if (!arg) - return NULL; - - tok = strchr (arg, ','); - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - } - else - break; - } - - if (! tok || strlen(tok) == 1) - return 0; - - return tok+1; -} - -static int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc); - -int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc) -{ - int error = 0; - - if (option_given && ! (min < 0 && max < 0)) - { - if (min >= 0 && max >= 0) - { - if (min == max) - { - /* specific occurrences */ - if (option_given != min) - { - fprintf (stderr, "%s: %s option occurrences must be %d\n", - prog_name, option_desc, min); - error = 1; - } - } - else if (option_given < min - || option_given > max) - { - /* range occurrences */ - fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n", - prog_name, option_desc, min, max); - error = 1; - } - } - else if (min >= 0) - { - /* at least check */ - if (option_given < min) - { - fprintf (stderr, "%s: %s option occurrences must be at least %d\n", - prog_name, option_desc, min); - error = 1; - } - } - else if (max >= 0) - { - /* at most check */ - if (option_given > max) - { - fprintf (stderr, "%s: %s option occurrences must be at most %d\n", - prog_name, option_desc, max); - error = 1; - } - } - } - - return error; -} -int -cmdline_parser_clitkMedianImageFilter (int argc, char * const *argv, struct args_info_clitkMedianImageFilter *args_info) -{ - return cmdline_parser_clitkMedianImageFilter2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_clitkMedianImageFilter_ext (int argc, char * const *argv, struct args_info_clitkMedianImageFilter *args_info, - struct cmdline_parser_clitkMedianImageFilter_params *params) -{ - int result; - result = cmdline_parser_clitkMedianImageFilter_internal (argc, argv, args_info, params, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkMedianImageFilter_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkMedianImageFilter2 (int argc, char * const *argv, struct args_info_clitkMedianImageFilter *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_clitkMedianImageFilter_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_clitkMedianImageFilter_internal (argc, argv, args_info, ¶ms, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkMedianImageFilter_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkMedianImageFilter_required (struct args_info_clitkMedianImageFilter *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_clitkMedianImageFilter_required2(args_info, prog_name, NULL) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkMedianImageFilter_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkMedianImageFilter_required2 (struct args_info_clitkMedianImageFilter *args_info, const char *prog_name, const char *additional_error) -{ - int error = 0; - - /* checks for required options */ - if (! args_info->input_given) - { - fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->output_given) - { - fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (check_multiple_option_occurrences(prog_name, args_info->radius_given, args_info->radius_min, args_info->radius_max, "'--radius' ('-r')")) - error = 1; - - - /* checks for dependences among options */ - - return error; -} - -/* - * Extracted from the glibc source tree, version 2.3.6 - * - * Licensed under the GPL as per the whole glibc source tree. - * - * This file was modified so that getopt_long can be called - * many times without risking previous memory to be spoiled. - * - * Modified by Andre Noll and Lorenzo Bettini for use in - * GNU gengetopt generated files. - * - */ - -/* - * we must include anything we need since this file is not thought to be - * inserted in a file already using getopt.h - * - * Lorenzo - */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -static char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -static int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -static int opterr; - -/* Set to an option character which was unrecognized. */ - -static int optopt; - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. -*/ -/* - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `custom_optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -/* Names for the values of the `has_arg' field of `struct option'. */ -#ifndef no_argument -#define no_argument 0 -#endif - -#ifndef required_argument -#define required_argument 1 -#endif - -#ifndef optional_argument -#define optional_argument 2 -#endif - -struct custom_getopt_data { - /* - * These have exactly the same meaning as the corresponding global variables, - * except that they are used for the reentrant versions of getopt. - */ - int custom_optind; - int custom_opterr; - int custom_optopt; - char *custom_optarg; - - /* True if the internal members have been initialized. */ - int initialized; - - /* - * The next char to be scanned in the option-element in which the last option - * character we returned was found. This allows us to pick up the scan where - * we left off. If this is zero, or a null string, it means resume the scan by - * advancing to the next ARGV-element. - */ - char *nextchar; - - /* - * Describe the part of ARGV that contains non-options that have been skipped. - * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is - * the index after the last of them. - */ - int first_nonopt; - int last_nonopt; -}; - -/* - * the variables optarg, optind, opterr and optopt are renamed with - * the custom_ prefix so that they don't interfere with getopt ones. - * - * Moreover they're static so they are visible only from within the - * file where this very file will be included. - */ - -/* - * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an - * option that takes an argument, the argument value is returned here. - */ -static char *custom_optarg; - -/* - * Index in ARGV of the next element to be scanned. This is used for - * communication to and from the caller and for communication between - * successive calls to `custom_getopt'. - * - * On entry to `custom_getopt', 1 means this is the first call; initialize. - * - * When `custom_getopt' returns -1, this is the index of the first of the non-option - * elements that the caller should itself scan. - * - * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV - * has been scanned so far. - * - * 1003.2 says this must be 1 before any call. - */ -static int custom_optind = 1; - -/* - * Callers store zero here to inhibit the error message for unrecognized - * options. - */ -static int custom_opterr = 1; - -/* - * Set to an option character which was unrecognized. This must be initialized - * on some systems to avoid linking in the system's own getopt implementation. - */ -static int custom_optopt = '?'; - -/* - * Exchange two adjacent subsequences of ARGV. One subsequence is elements - * [first_nonopt,last_nonopt) which contains all the non-options that have been - * skipped so far. The other is elements [last_nonopt,custom_optind), which contains - * all the options processed since those non-options were skipped. - * `first_nonopt' and `last_nonopt' are relocated so that they describe the new - * indices of the non-options in ARGV after they are moved. - */ -static void exchange(char **argv, struct custom_getopt_data *d) -{ - int bottom = d->first_nonopt; - int middle = d->last_nonopt; - int top = d->custom_optind; - char *tem; - - /* - * Exchange the shorter segment with the far end of the longer segment. - * That puts the shorter segment into the right place. It leaves the - * longer segment in the right place overall, but it consists of two - * parts that need to be swapped next. - */ - while (top > middle && middle > bottom) { - if (top - middle > middle - bottom) { - /* Bottom segment is the short one. */ - int len = middle - bottom; - int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = - argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } else { - /* Top segment is the short one. */ - int len = top - middle; - int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - /* Update records for the slots the non-options now occupy. */ - d->first_nonopt += (d->custom_optind - d->last_nonopt); - d->last_nonopt = d->custom_optind; -} - -/* Initialize the internal data when the first call is made. */ -static void custom_getopt_initialize(struct custom_getopt_data *d) -{ - /* - * Start processing options with ARGV-element 1 (since ARGV-element 0 - * is the program name); the sequence of previously skipped non-option - * ARGV-elements is empty. - */ - d->first_nonopt = d->last_nonopt = d->custom_optind; - d->nextchar = NULL; - d->initialized = 1; -} - -#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0') - -/* return: zero: continue, nonzero: return given value to user */ -static int shuffle_argv(int argc, char *const *argv,const struct option *longopts, - struct custom_getopt_data *d) -{ - /* - * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been - * moved back by the user (who may also have changed the arguments). - */ - if (d->last_nonopt > d->custom_optind) - d->last_nonopt = d->custom_optind; - if (d->first_nonopt > d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * If we have just processed some options following some - * non-options, exchange them so that the options come first. - */ - if (d->first_nonopt != d->last_nonopt && - d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->last_nonopt != d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * Skip any additional non-options and extend the range of - * non-options previously skipped. - */ - while (d->custom_optind < argc && NONOPTION_P) - d->custom_optind++; - d->last_nonopt = d->custom_optind; - /* - * The special ARGV-element `--' means premature end of options. Skip - * it like a null option, then exchange with previous non-options as if - * it were an option, then skip everything else like a non-option. - */ - if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) { - d->custom_optind++; - if (d->first_nonopt != d->last_nonopt - && d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->first_nonopt == d->last_nonopt) - d->first_nonopt = d->custom_optind; - d->last_nonopt = argc; - d->custom_optind = argc; - } - /* - * If we have done all the ARGV-elements, stop the scan and back over - * any non-options that we skipped and permuted. - */ - if (d->custom_optind == argc) { - /* - * Set the next-arg-index to point at the non-options that we - * previously skipped, so the caller will digest them. - */ - if (d->first_nonopt != d->last_nonopt) - d->custom_optind = d->first_nonopt; - return -1; - } - /* - * If we have come to a non-option and did not permute it, either stop - * the scan or describe it to the caller and pass it by. - */ - if (NONOPTION_P) { - d->custom_optarg = argv[d->custom_optind++]; - return 1; - } - /* - * We have found another option-ARGV-element. Skip the initial - * punctuation. - */ - d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-')); - return 0; -} - -/* - * Check whether the ARGV-element is a long option. - * - * If there's a long option "fubar" and the ARGV-element is "-fu", consider - * that an abbreviation of the long option, just like "--fu", and not "-f" with - * arg "u". - * - * This distinction seems to be the most useful approach. - * - */ -static int check_long_opt(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - int print_errors, struct custom_getopt_data *d) -{ - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match or abbreviated matches */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) { - if ((unsigned int) (nameend - d->nextchar) - == (unsigned int) strlen(p->name)) { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } else if (pfound == NULL) { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } else if (pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' is ambiguous\n", - argv[0], argv[d->custom_optind]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optind++; - d->custom_optopt = 0; - return '?'; - } - if (pfound) { - option_index = indfound; - d->custom_optind++; - if (*nameend) { - if (pfound->has_arg != no_argument) - d->custom_optarg = nameend + 1; - else { - if (print_errors) { - if (argv[d->custom_optind - 1][1] == '-') { - /* --option */ - fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[d->custom_optind - 1][0], pfound->name); - } - - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return '?'; - } - } else if (pfound->has_arg == required_argument) { - if (d->custom_optind < argc) - d->custom_optarg = argv[d->custom_optind++]; - else { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' requires an argument\n", - argv[0], - argv[d->custom_optind - 1]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->nextchar += strlen(d->nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* - * Can't find it as a long option. If this is not getopt_long_only, or - * the option starts with '--' or is not a valid short option, then - * it's an error. Otherwise interpret it as a short option. - */ - if (print_errors) { - if (argv[d->custom_optind][1] == '-') { - /* --option */ - fprintf(stderr, - "%s: unrecognized option `--%s'\n", - argv[0], d->nextchar); - } else { - /* +option or -option */ - fprintf(stderr, - "%s: unrecognized option `%c%s'\n", - argv[0], argv[d->custom_optind][0], - d->nextchar); - } - } - d->nextchar = (char *) ""; - d->custom_optind++; - d->custom_optopt = 0; - return '?'; -} - -static int check_short_opt(int argc, char *const *argv, const char *optstring, - int print_errors, struct custom_getopt_data *d) -{ - char c = *d->nextchar++; - char *temp = strchr(optstring, c); - - /* Increment `custom_optind' when we start to process its last character. */ - if (*d->nextchar == '\0') - ++d->custom_optind; - if (!temp || c == ':') { - if (print_errors) - fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); - - d->custom_optopt = c; - return '?'; - } - if (temp[1] == ':') { - if (temp[2] == ':') { - /* This is an option that accepts an argument optionally. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - d->custom_optind++; - } else - d->custom_optarg = NULL; - d->nextchar = NULL; - } else { - /* This is an option that requires an argument. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - /* - * If we end this ARGV-element by taking the - * rest as an arg, we must advance to the next - * element now. - */ - d->custom_optind++; - } else if (d->custom_optind == argc) { - if (print_errors) { - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], c); - } - d->custom_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } else - /* - * We already incremented `custom_optind' once; - * increment it again when taking next ARGV-elt - * as argument. - */ - d->custom_optarg = argv[d->custom_optind++]; - d->nextchar = NULL; - } - } - return c; -} - -/* - * Scan elements of ARGV for option characters given in OPTSTRING. - * - * If an element of ARGV starts with '-', and is not exactly "-" or "--", - * then it is an option element. The characters of this element - * (aside from the initial '-') are option characters. If `getopt' - * is called repeatedly, it returns successively each of the option characters - * from each of the option elements. - * - * If `getopt' finds another option character, it returns that character, - * updating `custom_optind' and `nextchar' so that the next call to `getopt' can - * resume the scan with the following option character or ARGV-element. - * - * If there are no more option characters, `getopt' returns -1. - * Then `custom_optind' is the index in ARGV of the first ARGV-element - * that is not an option. (The ARGV-elements have been permuted - * so that those that are not options now come last.) - * - * OPTSTRING is a string containing the legitimate option characters. - * If an option character is seen that is not listed in OPTSTRING, - * return '?' after printing an error message. If you set `custom_opterr' to - * zero, the error message is suppressed but we still return '?'. - * - * If a char in OPTSTRING is followed by a colon, that means it wants an arg, - * so the following text in the same ARGV-element, or the text of the following - * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that - * wants an optional arg; if there is text in the current ARGV-element, - * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero. - * - * If OPTSTRING starts with `-' or `+', it requests different methods of - * handling the non-option ARGV-elements. - * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - * - * Long-named options begin with `--' instead of `-'. - * Their names may be abbreviated as long as the abbreviation is unique - * or is an exact match for some defined option. If they have an - * argument, it follows the option name in the same ARGV-element, separated - * from the option name by a `=', or else the in next ARGV-element. - * When `getopt' finds a long-named option, it returns 0 if that option's - * `flag' field is nonzero, the value of the option's `val' field - * if the `flag' field is zero. - * - * The elements of ARGV aren't really const, because we permute them. - * But we pretend they're const in the prototype to be compatible - * with other systems. - * - * LONGOPTS is a vector of `struct option' terminated by an - * element containing a name which is zero. - * - * LONGIND returns the index in LONGOPT of the long-named option found. - * It is only valid when a long-named option has been found by the most - * recent call. - * - * Return the option character from OPTS just read. Return -1 when there are - * no more options. For unrecognized options, or options missing arguments, - * `custom_optopt' is set to the option letter, and '?' is returned. - * - * The OPTS string is a list of characters which are recognized option letters, - * optionally followed by colons, specifying that that letter takes an - * argument, to be placed in `custom_optarg'. - * - * If a letter in OPTS is followed by two colons, its argument is optional. - * This behavior is specific to the GNU `getopt'. - * - * The argument `--' causes premature termination of argument scanning, - * explicitly telling `getopt' that there are no more options. If OPTS begins - * with `--', then non-option arguments are treated as arguments to the option - * '\0'. This behavior is specific to the GNU `getopt'. - */ - -static int getopt_internal_r(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - struct custom_getopt_data *d) -{ - int ret, print_errors = d->custom_opterr; - - if (optstring[0] == ':') - print_errors = 0; - if (argc < 1) - return -1; - d->custom_optarg = NULL; - - /* - * This is a big difference with GNU getopt, since optind == 0 - * means initialization while here 1 means first call. - */ - if (d->custom_optind == 0 || !d->initialized) { - if (d->custom_optind == 0) - d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */ - custom_getopt_initialize(d); - } - if (d->nextchar == NULL || *d->nextchar == '\0') { - ret = shuffle_argv(argc, argv, longopts, d); - if (ret) - return ret; - } - if (longopts && (argv[d->custom_optind][1] == '-' )) - return check_long_opt(argc, argv, optstring, longopts, - longind, print_errors, d); - return check_short_opt(argc, argv, optstring, print_errors, d); -} - -static int custom_getopt_internal(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind) -{ - int result; - /* Keep a global copy of all internal members of d */ - static struct custom_getopt_data d; - - d.custom_optind = custom_optind; - d.custom_opterr = custom_opterr; - result = getopt_internal_r(argc, argv, optstring, longopts, - longind, &d); - custom_optind = d.custom_optind; - custom_optarg = d.custom_optarg; - custom_optopt = d.custom_optopt; - return result; -} - -static int custom_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return custom_getopt_internal(argc, argv, options, long_options, - opt_index); -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_clitkMedianImageFilter_params.check_ambiguity - * @param override @see cmdline_parser_clitkMedianImageFilter_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, - cmdline_parser_clitkMedianImageFilter_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_INT: - if (val) *((int *)field) = strtol (val, &stop_char, 0); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_INT: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - -/** - * @brief store information about a multiple option in a temporary list - * @param list where to (temporarily) store multiple options - */ -static -int update_multiple_arg_temp(struct generic_list **list, - unsigned int *prev_given, const char *val, - char *possible_values[], const char *default_value, - cmdline_parser_clitkMedianImageFilter_arg_type arg_type, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *multi_token, *multi_next; /* store single arguments */ - - if (arg_type == ARG_NO) { - (*prev_given)++; - return 0; /* OK */ - } - - multi_token = get_multiple_arg_token(val); - multi_next = get_multiple_arg_token_next (val); - - while (1) - { - add_node (list); - if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, - prev_given, multi_token, possible_values, default_value, - arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { - if (multi_token) free(multi_token); - return 1; /* failure */ - } - - if (multi_next) - { - multi_token = get_multiple_arg_token(multi_next); - multi_next = get_multiple_arg_token_next (multi_next); - } - else - break; - } - - return 0; /* OK */ -} - -/** - * @brief free the passed list (including possible string argument) - */ -static -void free_list(struct generic_list *list, short string_arg) -{ - if (list) { - struct generic_list *tmp; - while (list) - { - tmp = list; - if (string_arg && list->arg.string_arg) - free (list->arg.string_arg); - if (list->orig) - free (list->orig); - list = list->next; - free (tmp); - } - } -} - -/** - * @brief updates a multiple option starting from the passed list - */ -static -void update_multiple_arg(void *field, char ***orig_field, - unsigned int field_given, unsigned int prev_given, union generic_value *default_value, - cmdline_parser_clitkMedianImageFilter_arg_type arg_type, - struct generic_list *list) -{ - int i; - struct generic_list *tmp; - - if (prev_given && list) { - *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *)); - - switch(arg_type) { - case ARG_INT: - *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break; - case ARG_STRING: - *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; - default: - break; - }; - - for (i = (prev_given - 1); i >= 0; --i) - { - tmp = list; - - switch(arg_type) { - case ARG_INT: - (*((int **)field))[i + field_given] = tmp->arg.int_arg; break; - case ARG_STRING: - (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; - default: - break; - } - (*orig_field) [i + field_given] = list->orig; - list = list->next; - free (tmp); - } - } else { /* set the default value */ - if (default_value && ! field_given) { - switch(arg_type) { - case ARG_INT: - if (! *((int **)field)) { - *((int **)field) = (int *)malloc (sizeof (int)); - (*((int **)field))[0] = default_value->int_arg; - } - break; - case ARG_STRING: - if (! *((char ***)field)) { - *((char ***)field) = (char **)malloc (sizeof (char *)); - (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg); - } - break; - default: break; - } - if (!(*orig_field)) { - *orig_field = (char **) malloc (sizeof (char *)); - (*orig_field)[0] = NULL; - } - } - } -} - -int -cmdline_parser_clitkMedianImageFilter_internal (int argc, char * const *argv, struct args_info_clitkMedianImageFilter *args_info, - struct cmdline_parser_clitkMedianImageFilter_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - union generic_value multiple_default_value; - - struct generic_list * radius_list = NULL; - int error = 0; - struct args_info_clitkMedianImageFilter local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_clitkMedianImageFilter_init (args_info); - - cmdline_parser_clitkMedianImageFilter_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "config", 1, NULL, 0 }, - { "verbose", 0, NULL, 'v' }, - { "input", 1, NULL, 'i' }, - { "output", 1, NULL, 'o' }, - { "radius", 1, NULL, 'r' }, - { NULL, 0, NULL, 0 } - }; - - custom_optarg = optarg; - custom_optind = optind; - custom_opterr = opterr; - custom_optopt = optopt; - - c = custom_getopt_long (argc, argv, "hVvi:o:r:", long_options, &option_index); - - optarg = custom_optarg; - optind = custom_optind; - opterr = custom_opterr; - optopt = custom_optopt; - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_clitkMedianImageFilter_print_help (); - cmdline_parser_clitkMedianImageFilter_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_clitkMedianImageFilter_print_version (); - cmdline_parser_clitkMedianImageFilter_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'v': /* Verbose. */ - - - if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) - goto failure; - - break; - case 'i': /* Input image filename. */ - - - if (update_arg( (void *)&(args_info->input_arg), - &(args_info->input_orig), &(args_info->input_given), - &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "input", 'i', - additional_error)) - goto failure; - - break; - case 'o': /* Output image filename. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - case 'r': /* Radius in each Direction. */ - - if (update_multiple_arg_temp(&radius_list, - &(local_args_info.radius_given), optarg, 0, "1", ARG_INT, - "radius", 'r', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Config file. */ - if (strcmp (long_options[option_index].name, "config") == 0) - { - - - if (update_arg( (void *)&(args_info->config_arg), - &(args_info->config_orig), &(args_info->config_given), - &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "config", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - multiple_default_value.int_arg = 1; - update_multiple_arg((void *)&(args_info->radius_arg), - &(args_info->radius_orig), args_info->radius_given, - local_args_info.radius_given, &multiple_default_value , - ARG_INT, radius_list); - - args_info->radius_given += local_args_info.radius_given; - local_args_info.radius_given = 0; - - if (check_required) - { - error += cmdline_parser_clitkMedianImageFilter_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_clitkMedianImageFilter_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; - } - - return 0; - -failure: - free_list (radius_list, 0 ); - - cmdline_parser_clitkMedianImageFilter_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_cmdline_parser_clitkMedianImageFilter_configfile (char * const filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == NULL) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = NULL; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _cmdline_parser_clitkMedianImageFilter_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -cmdline_parser_clitkMedianImageFilter_configfile (char * const filename, - struct args_info_clitkMedianImageFilter *args_info, - int override, int initialize, int check_required) -{ - struct cmdline_parser_clitkMedianImageFilter_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return cmdline_parser_clitkMedianImageFilter_config_file (filename, args_info, ¶ms); -} - -int -cmdline_parser_clitkMedianImageFilter_config_file (char * const filename, - struct args_info_clitkMedianImageFilter *args_info, - struct cmdline_parser_clitkMedianImageFilter_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE); - - result = _cmdline_parser_clitkMedianImageFilter_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - cmdline_parser_clitkMedianImageFilter_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkMedianImageFilter_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/vv/tools_ggo/clitkMedianImageFilter_ggo.h b/vv/tools_ggo/clitkMedianImageFilter_ggo.h deleted file mode 100644 index e4430f8..0000000 --- a/vv/tools_ggo/clitkMedianImageFilter_ggo.h +++ /dev/null @@ -1,214 +0,0 @@ -/** @file clitkMedianImageFilter_ggo.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef CLITKMEDIANIMAGEFILTER_GGO_H -#define CLITKMEDIANIMAGEFILTER_GGO_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE -/** @brief the program name */ -#define CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_PACKAGE "clitkMedianImageFilter" -#endif - -#ifndef CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_CLITKMEDIANIMAGEFILTER_VERSION "1.0" -#endif - -/** @brief Where the command line options are stored */ -struct args_info_clitkMedianImageFilter -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * config_arg; /**< @brief Config file. */ - char * config_orig; /**< @brief Config file original value given at command line. */ - const char *config_help; /**< @brief Config file help description. */ - int verbose_flag; /**< @brief Verbose (default=off). */ - const char *verbose_help; /**< @brief Verbose help description. */ - char * input_arg; /**< @brief Input image filename. */ - char * input_orig; /**< @brief Input image filename original value given at command line. */ - const char *input_help; /**< @brief Input image filename help description. */ - char * output_arg; /**< @brief Output image filename. */ - char * output_orig; /**< @brief Output image filename original value given at command line. */ - const char *output_help; /**< @brief Output image filename help description. */ - int* radius_arg; /**< @brief Radius in each Direction (default='1'). */ - char ** radius_orig; /**< @brief Radius in each Direction original value given at command line. */ - int radius_min; /**< @brief Radius in each Direction's minimum occurreces */ - int radius_max; /**< @brief Radius in each Direction's maximum occurreces */ - const char *radius_help; /**< @brief Radius in each Direction help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int config_given ; /**< @brief Whether config was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int input_given ; /**< @brief Whether input was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int radius_given ; /**< @brief Whether radius was given. */ - - char **inputs ; /**< @brief unamed options (options without names) */ - unsigned inputs_num ; /**< @brief unamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_clitkMedianImageFilter_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure args_info_clitkMedianImageFilter (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure args_info_clitkMedianImageFilter (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *args_info_clitkMedianImageFilter_purpose; -/** @brief the usage string of the program */ -extern const char *args_info_clitkMedianImageFilter_usage; -/** @brief all the lines making the help output */ -extern const char *args_info_clitkMedianImageFilter_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkMedianImageFilter (int argc, char * const *argv, - struct args_info_clitkMedianImageFilter *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkMedianImageFilter_ext() instead - */ -int cmdline_parser_clitkMedianImageFilter2 (int argc, char * const *argv, - struct args_info_clitkMedianImageFilter *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkMedianImageFilter_ext (int argc, char * const *argv, - struct args_info_clitkMedianImageFilter *args_info, - struct cmdline_parser_clitkMedianImageFilter_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkMedianImageFilter_dump(FILE *outfile, - struct args_info_clitkMedianImageFilter *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkMedianImageFilter_file_save(const char *filename, - struct args_info_clitkMedianImageFilter *args_info); - -/** - * Print the help - */ -void cmdline_parser_clitkMedianImageFilter_print_help(void); -/** - * Print the version - */ -void cmdline_parser_clitkMedianImageFilter_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_clitkMedianImageFilter_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_clitkMedianImageFilter_params_init(struct cmdline_parser_clitkMedianImageFilter_params *params); - -/** - * Allocates dynamically a cmdline_parser_clitkMedianImageFilter_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_clitkMedianImageFilter_params structure - */ -struct cmdline_parser_clitkMedianImageFilter_params *cmdline_parser_clitkMedianImageFilter_params_create(void); - -/** - * Initializes the passed args_info_clitkMedianImageFilter structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_clitkMedianImageFilter_init (struct args_info_clitkMedianImageFilter *args_info); -/** - * Deallocates the string fields of the args_info_clitkMedianImageFilter structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_clitkMedianImageFilter_free (struct args_info_clitkMedianImageFilter *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkMedianImageFilter_config_file() instead - */ -int cmdline_parser_clitkMedianImageFilter_configfile (char * const filename, - struct args_info_clitkMedianImageFilter *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkMedianImageFilter_config_file (char * const filename, - struct args_info_clitkMedianImageFilter *args_info, - struct cmdline_parser_clitkMedianImageFilter_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_clitkMedianImageFilter_required (struct args_info_clitkMedianImageFilter *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CLITKMEDIANIMAGEFILTER_GGO_H */ diff --git a/vv/tools_ggo/clitkProfileImage_ggo.c b/vv/tools_ggo/clitkProfileImage_ggo.c deleted file mode 100644 index 69414aa..0000000 --- a/vv/tools_ggo/clitkProfileImage_ggo.c +++ /dev/null @@ -1,1906 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22 - generated with the following command: - /usr/local/bin/gengetopt --output-dir=/home/tbaudier/vv/vv_static/vv/vv_bin/tools --arg-struct-name=args_info_clitkProfileImage --func-name=cmdline_parser_clitkProfileImage --file-name=clitkProfileImage_ggo --unamed-opts --conf-parser --include-getopt - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - - -#include "clitkProfileImage_ggo.h" - -const char *args_info_clitkProfileImage_purpose = "Save the profile between 2 points of the input image in the output text file"; - -const char *args_info_clitkProfileImage_usage = "Usage: clitkProfileImage [OPTIONS]... [FILES]..."; - -const char *args_info_clitkProfileImage_description = ""; - -const char *args_info_clitkProfileImage_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " --config=STRING Config file", - " -v, --verbose Verbose (default=off)", - " --imagetypes Display allowed image types (default=off)", - " -i, --input=STRING Input image filename", - " -o, --output=STRING Output texte filename", - " -f, --point1=DOUBLE First point (mm)", - " -s, --point2=DOUBLE Second point (mm)", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_DOUBLE -} cmdline_parser_clitkProfileImage_arg_type; - -static -void clear_given (struct args_info_clitkProfileImage *args_info); -static -void clear_args (struct args_info_clitkProfileImage *args_info); - -static int -cmdline_parser_clitkProfileImage_internal (int argc, char * const *argv, struct args_info_clitkProfileImage *args_info, - struct cmdline_parser_clitkProfileImage_params *params, const char *additional_error); - -static int -cmdline_parser_clitkProfileImage_required2 (struct args_info_clitkProfileImage *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct args_info_clitkProfileImage *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->config_given = 0 ; - args_info->verbose_given = 0 ; - args_info->imagetypes_given = 0 ; - args_info->input_given = 0 ; - args_info->output_given = 0 ; - args_info->point1_given = 0 ; - args_info->point2_given = 0 ; -} - -static -void clear_args (struct args_info_clitkProfileImage *args_info) -{ - args_info->config_arg = NULL; - args_info->config_orig = NULL; - args_info->verbose_flag = 0; - args_info->imagetypes_flag = 0; - args_info->input_arg = NULL; - args_info->input_orig = NULL; - args_info->output_arg = NULL; - args_info->output_orig = NULL; - args_info->point1_arg = NULL; - args_info->point1_orig = NULL; - args_info->point2_arg = NULL; - args_info->point2_orig = NULL; - -} - -static -void init_args_info(struct args_info_clitkProfileImage *args_info) -{ - - - args_info->help_help = args_info_clitkProfileImage_help[0] ; - args_info->version_help = args_info_clitkProfileImage_help[1] ; - args_info->config_help = args_info_clitkProfileImage_help[2] ; - args_info->verbose_help = args_info_clitkProfileImage_help[3] ; - args_info->imagetypes_help = args_info_clitkProfileImage_help[4] ; - args_info->input_help = args_info_clitkProfileImage_help[5] ; - args_info->output_help = args_info_clitkProfileImage_help[6] ; - args_info->point1_help = args_info_clitkProfileImage_help[7] ; - args_info->point1_min = -1; - args_info->point1_max = 4; - args_info->point2_help = args_info_clitkProfileImage_help[8] ; - args_info->point2_min = -1; - args_info->point2_max = 4; - -} - -void -cmdline_parser_clitkProfileImage_print_version (void) -{ - printf ("%s %s\n", CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE, CMDLINE_PARSER_CLITKPROFILEIMAGE_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_clitkProfileImage_print_version (); - - if (strlen(args_info_clitkProfileImage_purpose) > 0) - printf("\n%s\n", args_info_clitkProfileImage_purpose); - - if (strlen(args_info_clitkProfileImage_usage) > 0) - printf("\n%s\n", args_info_clitkProfileImage_usage); - - printf("\n"); - - if (strlen(args_info_clitkProfileImage_description) > 0) - printf("%s\n", args_info_clitkProfileImage_description); -} - -void -cmdline_parser_clitkProfileImage_print_help (void) -{ - int i = 0; - print_help_common(); - while (args_info_clitkProfileImage_help[i]) - printf("%s\n", args_info_clitkProfileImage_help[i++]); -} - -void -cmdline_parser_clitkProfileImage_init (struct args_info_clitkProfileImage *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = NULL; - args_info->inputs_num = 0; -} - -void -cmdline_parser_clitkProfileImage_params_init(struct cmdline_parser_clitkProfileImage_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_clitkProfileImage_params * -cmdline_parser_clitkProfileImage_params_create(void) -{ - struct cmdline_parser_clitkProfileImage_params *params = - (struct cmdline_parser_clitkProfileImage_params *)malloc(sizeof(struct cmdline_parser_clitkProfileImage_params)); - cmdline_parser_clitkProfileImage_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - -/** @brief generic value variable */ -union generic_value { - double double_arg; - char *string_arg; -}; - -/** @brief holds temporary values for multiple options */ -struct generic_list -{ - union generic_value arg; - char *orig; - struct generic_list *next; -}; - -/** - * @brief add a node at the head of the list - */ -static void add_node(struct generic_list **list) { - struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); - new_node->next = *list; - *list = new_node; - new_node->arg.string_arg = NULL; - new_node->orig = NULL; -} - -static void -free_multiple_field(unsigned int len, void **arg, char ***orig) -{ - unsigned int i; - if (*arg) { - for (i = 0; i < len; ++i) - { - free_string_field(&((*orig)[i])); - } - - free (*arg); - *arg = 0; - free (*orig); - *orig = 0; - } -} - - -static void -cmdline_parser_clitkProfileImage_release (struct args_info_clitkProfileImage *args_info) -{ - unsigned int i; - free_string_field (&(args_info->config_arg)); - free_string_field (&(args_info->config_orig)); - free_string_field (&(args_info->input_arg)); - free_string_field (&(args_info->input_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - free_multiple_field (args_info->point1_given, (void **)&(args_info->point1_arg), &(args_info->point1_orig)); - free_multiple_field (args_info->point2_given, (void **)&(args_info->point2_arg), &(args_info->point2_orig)); - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) -{ - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - -static void -write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[]) -{ - int i; - - for (i = 0; i < len; ++i) - write_into_file(outfile, opt, (arg ? arg[i] : 0), values); -} - -int -cmdline_parser_clitkProfileImage_dump(FILE *outfile, struct args_info_clitkProfileImage *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->config_given) - write_into_file(outfile, "config", args_info->config_orig, 0); - if (args_info->verbose_given) - write_into_file(outfile, "verbose", 0, 0 ); - if (args_info->imagetypes_given) - write_into_file(outfile, "imagetypes", 0, 0 ); - if (args_info->input_given) - write_into_file(outfile, "input", args_info->input_orig, 0); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - write_multiple_into_file(outfile, args_info->point1_given, "point1", args_info->point1_orig, 0); - write_multiple_into_file(outfile, args_info->point2_given, "point2", args_info->point2_orig, 0); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_clitkProfileImage_file_save(const char *filename, struct args_info_clitkProfileImage *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_clitkProfileImage_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_clitkProfileImage_free (struct args_info_clitkProfileImage *args_info) -{ - cmdline_parser_clitkProfileImage_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = NULL; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -static char * -get_multiple_arg_token(const char *arg) -{ - char *tok, *ret; - size_t len, num_of_escape, i, j; - - if (!arg) - return NULL; - - tok = strchr (arg, ','); - num_of_escape = 0; - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - ++num_of_escape; - } - else - break; - } - - if (tok) - len = (size_t)(tok - arg + 1); - else - len = strlen (arg) + 1; - - len -= num_of_escape; - - ret = (char *) malloc (len); - - i = 0; - j = 0; - while (arg[i] && (j < len-1)) - { - if (arg[i] == '\\' && - arg[ i + 1 ] && - arg[ i + 1 ] == ',') - ++i; - - ret[j++] = arg[i++]; - } - - ret[len-1] = '\0'; - - return ret; -} - -static char * -get_multiple_arg_token_next(const char *arg) -{ - char *tok; - - if (!arg) - return NULL; - - tok = strchr (arg, ','); - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - } - else - break; - } - - if (! tok || strlen(tok) == 1) - return 0; - - return tok+1; -} - -static int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc); - -int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc) -{ - int error = 0; - - if (option_given && ! (min < 0 && max < 0)) - { - if (min >= 0 && max >= 0) - { - if (min == max) - { - /* specific occurrences */ - if (option_given != min) - { - fprintf (stderr, "%s: %s option occurrences must be %d\n", - prog_name, option_desc, min); - error = 1; - } - } - else if (option_given < min - || option_given > max) - { - /* range occurrences */ - fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n", - prog_name, option_desc, min, max); - error = 1; - } - } - else if (min >= 0) - { - /* at least check */ - if (option_given < min) - { - fprintf (stderr, "%s: %s option occurrences must be at least %d\n", - prog_name, option_desc, min); - error = 1; - } - } - else if (max >= 0) - { - /* at most check */ - if (option_given > max) - { - fprintf (stderr, "%s: %s option occurrences must be at most %d\n", - prog_name, option_desc, max); - error = 1; - } - } - } - - return error; -} -int -cmdline_parser_clitkProfileImage (int argc, char * const *argv, struct args_info_clitkProfileImage *args_info) -{ - return cmdline_parser_clitkProfileImage2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_clitkProfileImage_ext (int argc, char * const *argv, struct args_info_clitkProfileImage *args_info, - struct cmdline_parser_clitkProfileImage_params *params) -{ - int result; - result = cmdline_parser_clitkProfileImage_internal (argc, argv, args_info, params, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkProfileImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkProfileImage2 (int argc, char * const *argv, struct args_info_clitkProfileImage *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_clitkProfileImage_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_clitkProfileImage_internal (argc, argv, args_info, ¶ms, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkProfileImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkProfileImage_required (struct args_info_clitkProfileImage *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_clitkProfileImage_required2(args_info, prog_name, NULL) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkProfileImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkProfileImage_required2 (struct args_info_clitkProfileImage *args_info, const char *prog_name, const char *additional_error) -{ - int error = 0; - - /* checks for required options */ - if (! args_info->input_given) - { - fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->output_given) - { - fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->point1_given) - { - fprintf (stderr, "%s: '--point1' ('-f') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (check_multiple_option_occurrences(prog_name, args_info->point1_given, args_info->point1_min, args_info->point1_max, "'--point1' ('-f')")) - error = 1; - - if (! args_info->point2_given) - { - fprintf (stderr, "%s: '--point2' ('-s') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (check_multiple_option_occurrences(prog_name, args_info->point2_given, args_info->point2_min, args_info->point2_max, "'--point2' ('-s')")) - error = 1; - - - /* checks for dependences among options */ - - return error; -} - -/* - * Extracted from the glibc source tree, version 2.3.6 - * - * Licensed under the GPL as per the whole glibc source tree. - * - * This file was modified so that getopt_long can be called - * many times without risking previous memory to be spoiled. - * - * Modified by Andre Noll and Lorenzo Bettini for use in - * GNU gengetopt generated files. - * - */ - -/* - * we must include anything we need since this file is not thought to be - * inserted in a file already using getopt.h - * - * Lorenzo - */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -static char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -static int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -static int opterr; - -/* Set to an option character which was unrecognized. */ - -static int optopt; - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. -*/ -/* - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `custom_optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -/* Names for the values of the `has_arg' field of `struct option'. */ -#ifndef no_argument -#define no_argument 0 -#endif - -#ifndef required_argument -#define required_argument 1 -#endif - -#ifndef optional_argument -#define optional_argument 2 -#endif - -struct custom_getopt_data { - /* - * These have exactly the same meaning as the corresponding global variables, - * except that they are used for the reentrant versions of getopt. - */ - int custom_optind; - int custom_opterr; - int custom_optopt; - char *custom_optarg; - - /* True if the internal members have been initialized. */ - int initialized; - - /* - * The next char to be scanned in the option-element in which the last option - * character we returned was found. This allows us to pick up the scan where - * we left off. If this is zero, or a null string, it means resume the scan by - * advancing to the next ARGV-element. - */ - char *nextchar; - - /* - * Describe the part of ARGV that contains non-options that have been skipped. - * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is - * the index after the last of them. - */ - int first_nonopt; - int last_nonopt; -}; - -/* - * the variables optarg, optind, opterr and optopt are renamed with - * the custom_ prefix so that they don't interfere with getopt ones. - * - * Moreover they're static so they are visible only from within the - * file where this very file will be included. - */ - -/* - * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an - * option that takes an argument, the argument value is returned here. - */ -static char *custom_optarg; - -/* - * Index in ARGV of the next element to be scanned. This is used for - * communication to and from the caller and for communication between - * successive calls to `custom_getopt'. - * - * On entry to `custom_getopt', 1 means this is the first call; initialize. - * - * When `custom_getopt' returns -1, this is the index of the first of the non-option - * elements that the caller should itself scan. - * - * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV - * has been scanned so far. - * - * 1003.2 says this must be 1 before any call. - */ -static int custom_optind = 1; - -/* - * Callers store zero here to inhibit the error message for unrecognized - * options. - */ -static int custom_opterr = 1; - -/* - * Set to an option character which was unrecognized. This must be initialized - * on some systems to avoid linking in the system's own getopt implementation. - */ -static int custom_optopt = '?'; - -/* - * Exchange two adjacent subsequences of ARGV. One subsequence is elements - * [first_nonopt,last_nonopt) which contains all the non-options that have been - * skipped so far. The other is elements [last_nonopt,custom_optind), which contains - * all the options processed since those non-options were skipped. - * `first_nonopt' and `last_nonopt' are relocated so that they describe the new - * indices of the non-options in ARGV after they are moved. - */ -static void exchange(char **argv, struct custom_getopt_data *d) -{ - int bottom = d->first_nonopt; - int middle = d->last_nonopt; - int top = d->custom_optind; - char *tem; - - /* - * Exchange the shorter segment with the far end of the longer segment. - * That puts the shorter segment into the right place. It leaves the - * longer segment in the right place overall, but it consists of two - * parts that need to be swapped next. - */ - while (top > middle && middle > bottom) { - if (top - middle > middle - bottom) { - /* Bottom segment is the short one. */ - int len = middle - bottom; - int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = - argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } else { - /* Top segment is the short one. */ - int len = top - middle; - int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - /* Update records for the slots the non-options now occupy. */ - d->first_nonopt += (d->custom_optind - d->last_nonopt); - d->last_nonopt = d->custom_optind; -} - -/* Initialize the internal data when the first call is made. */ -static void custom_getopt_initialize(struct custom_getopt_data *d) -{ - /* - * Start processing options with ARGV-element 1 (since ARGV-element 0 - * is the program name); the sequence of previously skipped non-option - * ARGV-elements is empty. - */ - d->first_nonopt = d->last_nonopt = d->custom_optind; - d->nextchar = NULL; - d->initialized = 1; -} - -#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0') - -/* return: zero: continue, nonzero: return given value to user */ -static int shuffle_argv(int argc, char *const *argv,const struct option *longopts, - struct custom_getopt_data *d) -{ - /* - * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been - * moved back by the user (who may also have changed the arguments). - */ - if (d->last_nonopt > d->custom_optind) - d->last_nonopt = d->custom_optind; - if (d->first_nonopt > d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * If we have just processed some options following some - * non-options, exchange them so that the options come first. - */ - if (d->first_nonopt != d->last_nonopt && - d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->last_nonopt != d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * Skip any additional non-options and extend the range of - * non-options previously skipped. - */ - while (d->custom_optind < argc && NONOPTION_P) - d->custom_optind++; - d->last_nonopt = d->custom_optind; - /* - * The special ARGV-element `--' means premature end of options. Skip - * it like a null option, then exchange with previous non-options as if - * it were an option, then skip everything else like a non-option. - */ - if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) { - d->custom_optind++; - if (d->first_nonopt != d->last_nonopt - && d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->first_nonopt == d->last_nonopt) - d->first_nonopt = d->custom_optind; - d->last_nonopt = argc; - d->custom_optind = argc; - } - /* - * If we have done all the ARGV-elements, stop the scan and back over - * any non-options that we skipped and permuted. - */ - if (d->custom_optind == argc) { - /* - * Set the next-arg-index to point at the non-options that we - * previously skipped, so the caller will digest them. - */ - if (d->first_nonopt != d->last_nonopt) - d->custom_optind = d->first_nonopt; - return -1; - } - /* - * If we have come to a non-option and did not permute it, either stop - * the scan or describe it to the caller and pass it by. - */ - if (NONOPTION_P) { - d->custom_optarg = argv[d->custom_optind++]; - return 1; - } - /* - * We have found another option-ARGV-element. Skip the initial - * punctuation. - */ - d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-')); - return 0; -} - -/* - * Check whether the ARGV-element is a long option. - * - * If there's a long option "fubar" and the ARGV-element is "-fu", consider - * that an abbreviation of the long option, just like "--fu", and not "-f" with - * arg "u". - * - * This distinction seems to be the most useful approach. - * - */ -static int check_long_opt(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - int print_errors, struct custom_getopt_data *d) -{ - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match or abbreviated matches */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) { - if ((unsigned int) (nameend - d->nextchar) - == (unsigned int) strlen(p->name)) { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } else if (pfound == NULL) { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } else if (pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' is ambiguous\n", - argv[0], argv[d->custom_optind]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optind++; - d->custom_optopt = 0; - return '?'; - } - if (pfound) { - option_index = indfound; - d->custom_optind++; - if (*nameend) { - if (pfound->has_arg != no_argument) - d->custom_optarg = nameend + 1; - else { - if (print_errors) { - if (argv[d->custom_optind - 1][1] == '-') { - /* --option */ - fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[d->custom_optind - 1][0], pfound->name); - } - - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return '?'; - } - } else if (pfound->has_arg == required_argument) { - if (d->custom_optind < argc) - d->custom_optarg = argv[d->custom_optind++]; - else { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' requires an argument\n", - argv[0], - argv[d->custom_optind - 1]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->nextchar += strlen(d->nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* - * Can't find it as a long option. If this is not getopt_long_only, or - * the option starts with '--' or is not a valid short option, then - * it's an error. Otherwise interpret it as a short option. - */ - if (print_errors) { - if (argv[d->custom_optind][1] == '-') { - /* --option */ - fprintf(stderr, - "%s: unrecognized option `--%s'\n", - argv[0], d->nextchar); - } else { - /* +option or -option */ - fprintf(stderr, - "%s: unrecognized option `%c%s'\n", - argv[0], argv[d->custom_optind][0], - d->nextchar); - } - } - d->nextchar = (char *) ""; - d->custom_optind++; - d->custom_optopt = 0; - return '?'; -} - -static int check_short_opt(int argc, char *const *argv, const char *optstring, - int print_errors, struct custom_getopt_data *d) -{ - char c = *d->nextchar++; - char *temp = strchr(optstring, c); - - /* Increment `custom_optind' when we start to process its last character. */ - if (*d->nextchar == '\0') - ++d->custom_optind; - if (!temp || c == ':') { - if (print_errors) - fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); - - d->custom_optopt = c; - return '?'; - } - if (temp[1] == ':') { - if (temp[2] == ':') { - /* This is an option that accepts an argument optionally. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - d->custom_optind++; - } else - d->custom_optarg = NULL; - d->nextchar = NULL; - } else { - /* This is an option that requires an argument. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - /* - * If we end this ARGV-element by taking the - * rest as an arg, we must advance to the next - * element now. - */ - d->custom_optind++; - } else if (d->custom_optind == argc) { - if (print_errors) { - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], c); - } - d->custom_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } else - /* - * We already incremented `custom_optind' once; - * increment it again when taking next ARGV-elt - * as argument. - */ - d->custom_optarg = argv[d->custom_optind++]; - d->nextchar = NULL; - } - } - return c; -} - -/* - * Scan elements of ARGV for option characters given in OPTSTRING. - * - * If an element of ARGV starts with '-', and is not exactly "-" or "--", - * then it is an option element. The characters of this element - * (aside from the initial '-') are option characters. If `getopt' - * is called repeatedly, it returns successively each of the option characters - * from each of the option elements. - * - * If `getopt' finds another option character, it returns that character, - * updating `custom_optind' and `nextchar' so that the next call to `getopt' can - * resume the scan with the following option character or ARGV-element. - * - * If there are no more option characters, `getopt' returns -1. - * Then `custom_optind' is the index in ARGV of the first ARGV-element - * that is not an option. (The ARGV-elements have been permuted - * so that those that are not options now come last.) - * - * OPTSTRING is a string containing the legitimate option characters. - * If an option character is seen that is not listed in OPTSTRING, - * return '?' after printing an error message. If you set `custom_opterr' to - * zero, the error message is suppressed but we still return '?'. - * - * If a char in OPTSTRING is followed by a colon, that means it wants an arg, - * so the following text in the same ARGV-element, or the text of the following - * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that - * wants an optional arg; if there is text in the current ARGV-element, - * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero. - * - * If OPTSTRING starts with `-' or `+', it requests different methods of - * handling the non-option ARGV-elements. - * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - * - * Long-named options begin with `--' instead of `-'. - * Their names may be abbreviated as long as the abbreviation is unique - * or is an exact match for some defined option. If they have an - * argument, it follows the option name in the same ARGV-element, separated - * from the option name by a `=', or else the in next ARGV-element. - * When `getopt' finds a long-named option, it returns 0 if that option's - * `flag' field is nonzero, the value of the option's `val' field - * if the `flag' field is zero. - * - * The elements of ARGV aren't really const, because we permute them. - * But we pretend they're const in the prototype to be compatible - * with other systems. - * - * LONGOPTS is a vector of `struct option' terminated by an - * element containing a name which is zero. - * - * LONGIND returns the index in LONGOPT of the long-named option found. - * It is only valid when a long-named option has been found by the most - * recent call. - * - * Return the option character from OPTS just read. Return -1 when there are - * no more options. For unrecognized options, or options missing arguments, - * `custom_optopt' is set to the option letter, and '?' is returned. - * - * The OPTS string is a list of characters which are recognized option letters, - * optionally followed by colons, specifying that that letter takes an - * argument, to be placed in `custom_optarg'. - * - * If a letter in OPTS is followed by two colons, its argument is optional. - * This behavior is specific to the GNU `getopt'. - * - * The argument `--' causes premature termination of argument scanning, - * explicitly telling `getopt' that there are no more options. If OPTS begins - * with `--', then non-option arguments are treated as arguments to the option - * '\0'. This behavior is specific to the GNU `getopt'. - */ - -static int getopt_internal_r(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - struct custom_getopt_data *d) -{ - int ret, print_errors = d->custom_opterr; - - if (optstring[0] == ':') - print_errors = 0; - if (argc < 1) - return -1; - d->custom_optarg = NULL; - - /* - * This is a big difference with GNU getopt, since optind == 0 - * means initialization while here 1 means first call. - */ - if (d->custom_optind == 0 || !d->initialized) { - if (d->custom_optind == 0) - d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */ - custom_getopt_initialize(d); - } - if (d->nextchar == NULL || *d->nextchar == '\0') { - ret = shuffle_argv(argc, argv, longopts, d); - if (ret) - return ret; - } - if (longopts && (argv[d->custom_optind][1] == '-' )) - return check_long_opt(argc, argv, optstring, longopts, - longind, print_errors, d); - return check_short_opt(argc, argv, optstring, print_errors, d); -} - -static int custom_getopt_internal(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind) -{ - int result; - /* Keep a global copy of all internal members of d */ - static struct custom_getopt_data d; - - d.custom_optind = custom_optind; - d.custom_opterr = custom_opterr; - result = getopt_internal_r(argc, argv, optstring, longopts, - longind, &d); - custom_optind = d.custom_optind; - custom_optarg = d.custom_optarg; - custom_optopt = d.custom_optopt; - return result; -} - -static int custom_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return custom_getopt_internal(argc, argv, options, long_options, - opt_index); -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_clitkProfileImage_params.check_ambiguity - * @param override @see cmdline_parser_clitkProfileImage_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, - cmdline_parser_clitkProfileImage_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_DOUBLE: - if (val) *((double *)field) = strtod (val, &stop_char); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_DOUBLE: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - -/** - * @brief store information about a multiple option in a temporary list - * @param list where to (temporarily) store multiple options - */ -static -int update_multiple_arg_temp(struct generic_list **list, - unsigned int *prev_given, const char *val, - char *possible_values[], const char *default_value, - cmdline_parser_clitkProfileImage_arg_type arg_type, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *multi_token, *multi_next; /* store single arguments */ - - if (arg_type == ARG_NO) { - (*prev_given)++; - return 0; /* OK */ - } - - multi_token = get_multiple_arg_token(val); - multi_next = get_multiple_arg_token_next (val); - - while (1) - { - add_node (list); - if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, - prev_given, multi_token, possible_values, default_value, - arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { - if (multi_token) free(multi_token); - return 1; /* failure */ - } - - if (multi_next) - { - multi_token = get_multiple_arg_token(multi_next); - multi_next = get_multiple_arg_token_next (multi_next); - } - else - break; - } - - return 0; /* OK */ -} - -/** - * @brief free the passed list (including possible string argument) - */ -static -void free_list(struct generic_list *list, short string_arg) -{ - if (list) { - struct generic_list *tmp; - while (list) - { - tmp = list; - if (string_arg && list->arg.string_arg) - free (list->arg.string_arg); - if (list->orig) - free (list->orig); - list = list->next; - free (tmp); - } - } -} - -/** - * @brief updates a multiple option starting from the passed list - */ -static -void update_multiple_arg(void *field, char ***orig_field, - unsigned int field_given, unsigned int prev_given, union generic_value *default_value, - cmdline_parser_clitkProfileImage_arg_type arg_type, - struct generic_list *list) -{ - int i; - struct generic_list *tmp; - - if (prev_given && list) { - *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *)); - - switch(arg_type) { - case ARG_DOUBLE: - *((double **)field) = (double *)realloc (*((double **)field), (field_given + prev_given) * sizeof (double)); break; - case ARG_STRING: - *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; - default: - break; - }; - - for (i = (prev_given - 1); i >= 0; --i) - { - tmp = list; - - switch(arg_type) { - case ARG_DOUBLE: - (*((double **)field))[i + field_given] = tmp->arg.double_arg; break; - case ARG_STRING: - (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; - default: - break; - } - (*orig_field) [i + field_given] = list->orig; - list = list->next; - free (tmp); - } - } else { /* set the default value */ - if (default_value && ! field_given) { - switch(arg_type) { - case ARG_DOUBLE: - if (! *((double **)field)) { - *((double **)field) = (double *)malloc (sizeof (double)); - (*((double **)field))[0] = default_value->double_arg; - } - break; - case ARG_STRING: - if (! *((char ***)field)) { - *((char ***)field) = (char **)malloc (sizeof (char *)); - (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg); - } - break; - default: break; - } - if (!(*orig_field)) { - *orig_field = (char **) malloc (sizeof (char *)); - (*orig_field)[0] = NULL; - } - } - } -} - -int -cmdline_parser_clitkProfileImage_internal (int argc, char * const *argv, struct args_info_clitkProfileImage *args_info, - struct cmdline_parser_clitkProfileImage_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - struct generic_list * point1_list = NULL; - struct generic_list * point2_list = NULL; - int error = 0; - struct args_info_clitkProfileImage local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_clitkProfileImage_init (args_info); - - cmdline_parser_clitkProfileImage_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "config", 1, NULL, 0 }, - { "verbose", 0, NULL, 'v' }, - { "imagetypes", 0, NULL, 0 }, - { "input", 1, NULL, 'i' }, - { "output", 1, NULL, 'o' }, - { "point1", 1, NULL, 'f' }, - { "point2", 1, NULL, 's' }, - { NULL, 0, NULL, 0 } - }; - - custom_optarg = optarg; - custom_optind = optind; - custom_opterr = opterr; - custom_optopt = optopt; - - c = custom_getopt_long (argc, argv, "hVvi:o:f:s:", long_options, &option_index); - - optarg = custom_optarg; - optind = custom_optind; - opterr = custom_opterr; - optopt = custom_optopt; - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_clitkProfileImage_print_help (); - cmdline_parser_clitkProfileImage_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_clitkProfileImage_print_version (); - cmdline_parser_clitkProfileImage_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'v': /* Verbose. */ - - - if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) - goto failure; - - break; - case 'i': /* Input image filename. */ - - - if (update_arg( (void *)&(args_info->input_arg), - &(args_info->input_orig), &(args_info->input_given), - &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "input", 'i', - additional_error)) - goto failure; - - break; - case 'o': /* Output texte filename. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - case 'f': /* First point (mm). */ - - if (update_multiple_arg_temp(&point1_list, - &(local_args_info.point1_given), optarg, 0, 0, ARG_DOUBLE, - "point1", 'f', - additional_error)) - goto failure; - - break; - case 's': /* Second point (mm). */ - - if (update_multiple_arg_temp(&point2_list, - &(local_args_info.point2_given), optarg, 0, 0, ARG_DOUBLE, - "point2", 's', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Config file. */ - if (strcmp (long_options[option_index].name, "config") == 0) - { - - - if (update_arg( (void *)&(args_info->config_arg), - &(args_info->config_orig), &(args_info->config_given), - &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "config", '-', - additional_error)) - goto failure; - - } - /* Display allowed image types. */ - else if (strcmp (long_options[option_index].name, "imagetypes") == 0) - { - - - if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given), - &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "imagetypes", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - update_multiple_arg((void *)&(args_info->point1_arg), - &(args_info->point1_orig), args_info->point1_given, - local_args_info.point1_given, 0 , - ARG_DOUBLE, point1_list); - update_multiple_arg((void *)&(args_info->point2_arg), - &(args_info->point2_orig), args_info->point2_given, - local_args_info.point2_given, 0 , - ARG_DOUBLE, point2_list); - - args_info->point1_given += local_args_info.point1_given; - local_args_info.point1_given = 0; - args_info->point2_given += local_args_info.point2_given; - local_args_info.point2_given = 0; - - if (check_required) - { - error += cmdline_parser_clitkProfileImage_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_clitkProfileImage_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; - } - - return 0; - -failure: - free_list (point1_list, 0 ); - free_list (point2_list, 0 ); - - cmdline_parser_clitkProfileImage_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_cmdline_parser_clitkProfileImage_configfile (char * const filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == NULL) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = NULL; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _cmdline_parser_clitkProfileImage_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -cmdline_parser_clitkProfileImage_configfile (char * const filename, - struct args_info_clitkProfileImage *args_info, - int override, int initialize, int check_required) -{ - struct cmdline_parser_clitkProfileImage_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return cmdline_parser_clitkProfileImage_config_file (filename, args_info, ¶ms); -} - -int -cmdline_parser_clitkProfileImage_config_file (char * const filename, - struct args_info_clitkProfileImage *args_info, - struct cmdline_parser_clitkProfileImage_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE); - - result = _cmdline_parser_clitkProfileImage_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - cmdline_parser_clitkProfileImage_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkProfileImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/vv/tools_ggo/clitkProfileImage_ggo.h b/vv/tools_ggo/clitkProfileImage_ggo.h deleted file mode 100644 index a48ef93..0000000 --- a/vv/tools_ggo/clitkProfileImage_ggo.h +++ /dev/null @@ -1,223 +0,0 @@ -/** @file clitkProfileImage_ggo.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef CLITKPROFILEIMAGE_GGO_H -#define CLITKPROFILEIMAGE_GGO_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE -/** @brief the program name */ -#define CMDLINE_PARSER_CLITKPROFILEIMAGE_PACKAGE "clitkProfileImage" -#endif - -#ifndef CMDLINE_PARSER_CLITKPROFILEIMAGE_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_CLITKPROFILEIMAGE_VERSION "1.0" -#endif - -/** @brief Where the command line options are stored */ -struct args_info_clitkProfileImage -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * config_arg; /**< @brief Config file. */ - char * config_orig; /**< @brief Config file original value given at command line. */ - const char *config_help; /**< @brief Config file help description. */ - int verbose_flag; /**< @brief Verbose (default=off). */ - const char *verbose_help; /**< @brief Verbose help description. */ - int imagetypes_flag; /**< @brief Display allowed image types (default=off). */ - const char *imagetypes_help; /**< @brief Display allowed image types help description. */ - char * input_arg; /**< @brief Input image filename. */ - char * input_orig; /**< @brief Input image filename original value given at command line. */ - const char *input_help; /**< @brief Input image filename help description. */ - char * output_arg; /**< @brief Output texte filename. */ - char * output_orig; /**< @brief Output texte filename original value given at command line. */ - const char *output_help; /**< @brief Output texte filename help description. */ - double* point1_arg; /**< @brief First point (mm). */ - char ** point1_orig; /**< @brief First point (mm) original value given at command line. */ - int point1_min; /**< @brief First point (mm)'s minimum occurreces */ - int point1_max; /**< @brief First point (mm)'s maximum occurreces */ - const char *point1_help; /**< @brief First point (mm) help description. */ - double* point2_arg; /**< @brief Second point (mm). */ - char ** point2_orig; /**< @brief Second point (mm) original value given at command line. */ - int point2_min; /**< @brief Second point (mm)'s minimum occurreces */ - int point2_max; /**< @brief Second point (mm)'s maximum occurreces */ - const char *point2_help; /**< @brief Second point (mm) help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int config_given ; /**< @brief Whether config was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int imagetypes_given ; /**< @brief Whether imagetypes was given. */ - unsigned int input_given ; /**< @brief Whether input was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int point1_given ; /**< @brief Whether point1 was given. */ - unsigned int point2_given ; /**< @brief Whether point2 was given. */ - - char **inputs ; /**< @brief unamed options (options without names) */ - unsigned inputs_num ; /**< @brief unamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_clitkProfileImage_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure args_info_clitkProfileImage (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure args_info_clitkProfileImage (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *args_info_clitkProfileImage_purpose; -/** @brief the usage string of the program */ -extern const char *args_info_clitkProfileImage_usage; -/** @brief all the lines making the help output */ -extern const char *args_info_clitkProfileImage_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkProfileImage (int argc, char * const *argv, - struct args_info_clitkProfileImage *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkProfileImage_ext() instead - */ -int cmdline_parser_clitkProfileImage2 (int argc, char * const *argv, - struct args_info_clitkProfileImage *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkProfileImage_ext (int argc, char * const *argv, - struct args_info_clitkProfileImage *args_info, - struct cmdline_parser_clitkProfileImage_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkProfileImage_dump(FILE *outfile, - struct args_info_clitkProfileImage *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkProfileImage_file_save(const char *filename, - struct args_info_clitkProfileImage *args_info); - -/** - * Print the help - */ -void cmdline_parser_clitkProfileImage_print_help(void); -/** - * Print the version - */ -void cmdline_parser_clitkProfileImage_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_clitkProfileImage_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_clitkProfileImage_params_init(struct cmdline_parser_clitkProfileImage_params *params); - -/** - * Allocates dynamically a cmdline_parser_clitkProfileImage_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_clitkProfileImage_params structure - */ -struct cmdline_parser_clitkProfileImage_params *cmdline_parser_clitkProfileImage_params_create(void); - -/** - * Initializes the passed args_info_clitkProfileImage structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_clitkProfileImage_init (struct args_info_clitkProfileImage *args_info); -/** - * Deallocates the string fields of the args_info_clitkProfileImage structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_clitkProfileImage_free (struct args_info_clitkProfileImage *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkProfileImage_config_file() instead - */ -int cmdline_parser_clitkProfileImage_configfile (char * const filename, - struct args_info_clitkProfileImage *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkProfileImage_config_file (char * const filename, - struct args_info_clitkProfileImage *args_info, - struct cmdline_parser_clitkProfileImage_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_clitkProfileImage_required (struct args_info_clitkProfileImage *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CLITKPROFILEIMAGE_GGO_H */ diff --git a/vv/tools_ggo/clitkRegionGrowing_ggo.c b/vv/tools_ggo/clitkRegionGrowing_ggo.c deleted file mode 100644 index 0790e24..0000000 --- a/vv/tools_ggo/clitkRegionGrowing_ggo.c +++ /dev/null @@ -1,2226 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22 - generated with the following command: - /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 - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - - -#include "clitkRegionGrowing_ggo.h" - -const char *args_info_clitkRegionGrowing_purpose = "Region growing from a seed point using various types of conditions to control \nthe growing"; - -const char *args_info_clitkRegionGrowing_usage = "Usage: clitkRegionGrowing [OPTIONS]... [FILES]..."; - -const char *args_info_clitkRegionGrowing_description = ""; - -const char *args_info_clitkRegionGrowing_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " --config=STRING Config file", - " -v, --verbose Verbose (default=off)", - "\nI/O:", - " -i, --input=STRING Input image filename", - " -o, --output=STRING Output image filename", - "\nParameters:", - " -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')", - " -l, --lower=DOUBLE 1,2,3,4: Lower threshold value (default=`310')", - " -u, --upper=DOUBLE 1,2,3,4: Upper threshold value (default=`4000')", - " --maxUpper=DOUBLE 4: Maximum upper threshold value (default=`2000')", - " --minLower=DOUBLE 4: Minimum lower threshold value (default=`-1000')", - " --step=DOUBLE 4: Threshold step size (default=`64.0')", - " --minStep=DOUBLE 4: Minimum threshold step size (default=`1')", - " --adaptLower 3,4: (locally) adapt lower thresholding \n (default=off)", - " --adaptUpper 3,4: (locally) adapt upper thresholding \n (default=off)", - " -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')", - " -s, --seed=INT Seed index postion (in voxels) (default=`0')", - " --seedRadius=INT Radius used for seed dilatation(in voxel) \n (default=`0')", - " -p, --pad=DOUBLE The replace padding value (default=`1.0')", - " -r, --radius=INT 1-3: The radius of the neighborhood (default=`1')", - " --maxSD=DOUBLE 3: Limit to SD", - " --full 4: use full connectivity (not implemented yet) \n (default=off)", - " --iter=INT 2: Iterations (default=`5')", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_INT - , ARG_DOUBLE -} cmdline_parser_clitkRegionGrowing_arg_type; - -static -void clear_given (struct args_info_clitkRegionGrowing *args_info); -static -void clear_args (struct args_info_clitkRegionGrowing *args_info); - -static int -cmdline_parser_clitkRegionGrowing_internal (int argc, char * const *argv, struct args_info_clitkRegionGrowing *args_info, - struct cmdline_parser_clitkRegionGrowing_params *params, const char *additional_error); - -static int -cmdline_parser_clitkRegionGrowing_required2 (struct args_info_clitkRegionGrowing *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct args_info_clitkRegionGrowing *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->config_given = 0 ; - args_info->verbose_given = 0 ; - args_info->input_given = 0 ; - args_info->output_given = 0 ; - args_info->type_given = 0 ; - args_info->lower_given = 0 ; - args_info->upper_given = 0 ; - args_info->maxUpper_given = 0 ; - args_info->minLower_given = 0 ; - args_info->step_given = 0 ; - args_info->minStep_given = 0 ; - args_info->adaptLower_given = 0 ; - args_info->adaptUpper_given = 0 ; - args_info->multiplier_given = 0 ; - args_info->seed_given = 0 ; - args_info->seedRadius_given = 0 ; - args_info->pad_given = 0 ; - args_info->radius_given = 0 ; - args_info->maxSD_given = 0 ; - args_info->full_given = 0 ; - args_info->iter_given = 0 ; -} - -static -void clear_args (struct args_info_clitkRegionGrowing *args_info) -{ - args_info->config_arg = NULL; - args_info->config_orig = NULL; - args_info->verbose_flag = 0; - args_info->input_arg = NULL; - args_info->input_orig = NULL; - args_info->output_arg = NULL; - args_info->output_orig = NULL; - args_info->type_arg = 0; - args_info->type_orig = NULL; - args_info->lower_arg = 310; - args_info->lower_orig = NULL; - args_info->upper_arg = 4000; - args_info->upper_orig = NULL; - args_info->maxUpper_arg = 2000; - args_info->maxUpper_orig = NULL; - args_info->minLower_arg = -1000; - args_info->minLower_orig = NULL; - args_info->step_arg = 64.0; - args_info->step_orig = NULL; - args_info->minStep_arg = 1; - args_info->minStep_orig = NULL; - args_info->adaptLower_flag = 0; - args_info->adaptUpper_flag = 0; - args_info->multiplier_arg = 2.0; - args_info->multiplier_orig = NULL; - args_info->seed_arg = NULL; - args_info->seed_orig = NULL; - args_info->seedRadius_arg = NULL; - args_info->seedRadius_orig = NULL; - args_info->pad_arg = 1.0; - args_info->pad_orig = NULL; - args_info->radius_arg = NULL; - args_info->radius_orig = NULL; - args_info->maxSD_orig = NULL; - args_info->full_flag = 0; - args_info->iter_arg = 5; - args_info->iter_orig = NULL; - -} - -static -void init_args_info(struct args_info_clitkRegionGrowing *args_info) -{ - - - args_info->help_help = args_info_clitkRegionGrowing_help[0] ; - args_info->version_help = args_info_clitkRegionGrowing_help[1] ; - args_info->config_help = args_info_clitkRegionGrowing_help[2] ; - args_info->verbose_help = args_info_clitkRegionGrowing_help[3] ; - args_info->input_help = args_info_clitkRegionGrowing_help[5] ; - args_info->output_help = args_info_clitkRegionGrowing_help[6] ; - args_info->type_help = args_info_clitkRegionGrowing_help[8] ; - args_info->lower_help = args_info_clitkRegionGrowing_help[9] ; - args_info->upper_help = args_info_clitkRegionGrowing_help[10] ; - args_info->maxUpper_help = args_info_clitkRegionGrowing_help[11] ; - args_info->minLower_help = args_info_clitkRegionGrowing_help[12] ; - args_info->step_help = args_info_clitkRegionGrowing_help[13] ; - args_info->minStep_help = args_info_clitkRegionGrowing_help[14] ; - args_info->adaptLower_help = args_info_clitkRegionGrowing_help[15] ; - args_info->adaptUpper_help = args_info_clitkRegionGrowing_help[16] ; - args_info->multiplier_help = args_info_clitkRegionGrowing_help[17] ; - args_info->seed_help = args_info_clitkRegionGrowing_help[18] ; - args_info->seed_min = -1; - args_info->seed_max = -1; - args_info->seedRadius_help = args_info_clitkRegionGrowing_help[19] ; - args_info->seedRadius_min = -1; - args_info->seedRadius_max = -1; - args_info->pad_help = args_info_clitkRegionGrowing_help[20] ; - args_info->radius_help = args_info_clitkRegionGrowing_help[21] ; - args_info->radius_min = -1; - args_info->radius_max = -1; - args_info->maxSD_help = args_info_clitkRegionGrowing_help[22] ; - args_info->full_help = args_info_clitkRegionGrowing_help[23] ; - args_info->iter_help = args_info_clitkRegionGrowing_help[24] ; - -} - -void -cmdline_parser_clitkRegionGrowing_print_version (void) -{ - printf ("%s %s\n", CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, CMDLINE_PARSER_CLITKREGIONGROWING_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_clitkRegionGrowing_print_version (); - - if (strlen(args_info_clitkRegionGrowing_purpose) > 0) - printf("\n%s\n", args_info_clitkRegionGrowing_purpose); - - if (strlen(args_info_clitkRegionGrowing_usage) > 0) - printf("\n%s\n", args_info_clitkRegionGrowing_usage); - - printf("\n"); - - if (strlen(args_info_clitkRegionGrowing_description) > 0) - printf("%s\n", args_info_clitkRegionGrowing_description); -} - -void -cmdline_parser_clitkRegionGrowing_print_help (void) -{ - int i = 0; - print_help_common(); - while (args_info_clitkRegionGrowing_help[i]) - printf("%s\n", args_info_clitkRegionGrowing_help[i++]); -} - -void -cmdline_parser_clitkRegionGrowing_init (struct args_info_clitkRegionGrowing *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = NULL; - args_info->inputs_num = 0; -} - -void -cmdline_parser_clitkRegionGrowing_params_init(struct cmdline_parser_clitkRegionGrowing_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_clitkRegionGrowing_params * -cmdline_parser_clitkRegionGrowing_params_create(void) -{ - struct cmdline_parser_clitkRegionGrowing_params *params = - (struct cmdline_parser_clitkRegionGrowing_params *)malloc(sizeof(struct cmdline_parser_clitkRegionGrowing_params)); - cmdline_parser_clitkRegionGrowing_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - -/** @brief generic value variable */ -union generic_value { - int int_arg; - double double_arg; - char *string_arg; -}; - -/** @brief holds temporary values for multiple options */ -struct generic_list -{ - union generic_value arg; - char *orig; - struct generic_list *next; -}; - -/** - * @brief add a node at the head of the list - */ -static void add_node(struct generic_list **list) { - struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); - new_node->next = *list; - *list = new_node; - new_node->arg.string_arg = NULL; - new_node->orig = NULL; -} - -static void -free_multiple_field(unsigned int len, void **arg, char ***orig) -{ - unsigned int i; - if (*arg) { - for (i = 0; i < len; ++i) - { - free_string_field(&((*orig)[i])); - } - - free (*arg); - *arg = 0; - free (*orig); - *orig = 0; - } -} - - -static void -cmdline_parser_clitkRegionGrowing_release (struct args_info_clitkRegionGrowing *args_info) -{ - unsigned int i; - free_string_field (&(args_info->config_arg)); - free_string_field (&(args_info->config_orig)); - free_string_field (&(args_info->input_arg)); - free_string_field (&(args_info->input_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - free_string_field (&(args_info->type_orig)); - free_string_field (&(args_info->lower_orig)); - free_string_field (&(args_info->upper_orig)); - free_string_field (&(args_info->maxUpper_orig)); - free_string_field (&(args_info->minLower_orig)); - free_string_field (&(args_info->step_orig)); - free_string_field (&(args_info->minStep_orig)); - free_string_field (&(args_info->multiplier_orig)); - free_multiple_field (args_info->seed_given, (void **)&(args_info->seed_arg), &(args_info->seed_orig)); - free_multiple_field (args_info->seedRadius_given, (void **)&(args_info->seedRadius_arg), &(args_info->seedRadius_orig)); - free_string_field (&(args_info->pad_orig)); - free_multiple_field (args_info->radius_given, (void **)&(args_info->radius_arg), &(args_info->radius_orig)); - free_string_field (&(args_info->maxSD_orig)); - free_string_field (&(args_info->iter_orig)); - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) -{ - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - -static void -write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[]) -{ - int i; - - for (i = 0; i < len; ++i) - write_into_file(outfile, opt, (arg ? arg[i] : 0), values); -} - -int -cmdline_parser_clitkRegionGrowing_dump(FILE *outfile, struct args_info_clitkRegionGrowing *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->config_given) - write_into_file(outfile, "config", args_info->config_orig, 0); - if (args_info->verbose_given) - write_into_file(outfile, "verbose", 0, 0 ); - if (args_info->input_given) - write_into_file(outfile, "input", args_info->input_orig, 0); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - if (args_info->type_given) - write_into_file(outfile, "type", args_info->type_orig, 0); - if (args_info->lower_given) - write_into_file(outfile, "lower", args_info->lower_orig, 0); - if (args_info->upper_given) - write_into_file(outfile, "upper", args_info->upper_orig, 0); - if (args_info->maxUpper_given) - write_into_file(outfile, "maxUpper", args_info->maxUpper_orig, 0); - if (args_info->minLower_given) - write_into_file(outfile, "minLower", args_info->minLower_orig, 0); - if (args_info->step_given) - write_into_file(outfile, "step", args_info->step_orig, 0); - if (args_info->minStep_given) - write_into_file(outfile, "minStep", args_info->minStep_orig, 0); - if (args_info->adaptLower_given) - write_into_file(outfile, "adaptLower", 0, 0 ); - if (args_info->adaptUpper_given) - write_into_file(outfile, "adaptUpper", 0, 0 ); - if (args_info->multiplier_given) - write_into_file(outfile, "multiplier", args_info->multiplier_orig, 0); - write_multiple_into_file(outfile, args_info->seed_given, "seed", args_info->seed_orig, 0); - write_multiple_into_file(outfile, args_info->seedRadius_given, "seedRadius", args_info->seedRadius_orig, 0); - if (args_info->pad_given) - write_into_file(outfile, "pad", args_info->pad_orig, 0); - write_multiple_into_file(outfile, args_info->radius_given, "radius", args_info->radius_orig, 0); - if (args_info->maxSD_given) - write_into_file(outfile, "maxSD", args_info->maxSD_orig, 0); - if (args_info->full_given) - write_into_file(outfile, "full", 0, 0 ); - if (args_info->iter_given) - write_into_file(outfile, "iter", args_info->iter_orig, 0); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_clitkRegionGrowing_file_save(const char *filename, struct args_info_clitkRegionGrowing *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_clitkRegionGrowing_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_clitkRegionGrowing_free (struct args_info_clitkRegionGrowing *args_info) -{ - cmdline_parser_clitkRegionGrowing_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = NULL; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -static char * -get_multiple_arg_token(const char *arg) -{ - char *tok, *ret; - size_t len, num_of_escape, i, j; - - if (!arg) - return NULL; - - tok = strchr (arg, ','); - num_of_escape = 0; - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - ++num_of_escape; - } - else - break; - } - - if (tok) - len = (size_t)(tok - arg + 1); - else - len = strlen (arg) + 1; - - len -= num_of_escape; - - ret = (char *) malloc (len); - - i = 0; - j = 0; - while (arg[i] && (j < len-1)) - { - if (arg[i] == '\\' && - arg[ i + 1 ] && - arg[ i + 1 ] == ',') - ++i; - - ret[j++] = arg[i++]; - } - - ret[len-1] = '\0'; - - return ret; -} - -static char * -get_multiple_arg_token_next(const char *arg) -{ - char *tok; - - if (!arg) - return NULL; - - tok = strchr (arg, ','); - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - } - else - break; - } - - if (! tok || strlen(tok) == 1) - return 0; - - return tok+1; -} - -static int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc); - -int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc) -{ - int error = 0; - - if (option_given && ! (min < 0 && max < 0)) - { - if (min >= 0 && max >= 0) - { - if (min == max) - { - /* specific occurrences */ - if (option_given != min) - { - fprintf (stderr, "%s: %s option occurrences must be %d\n", - prog_name, option_desc, min); - error = 1; - } - } - else if (option_given < min - || option_given > max) - { - /* range occurrences */ - fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n", - prog_name, option_desc, min, max); - error = 1; - } - } - else if (min >= 0) - { - /* at least check */ - if (option_given < min) - { - fprintf (stderr, "%s: %s option occurrences must be at least %d\n", - prog_name, option_desc, min); - error = 1; - } - } - else if (max >= 0) - { - /* at most check */ - if (option_given > max) - { - fprintf (stderr, "%s: %s option occurrences must be at most %d\n", - prog_name, option_desc, max); - error = 1; - } - } - } - - return error; -} -int -cmdline_parser_clitkRegionGrowing (int argc, char * const *argv, struct args_info_clitkRegionGrowing *args_info) -{ - return cmdline_parser_clitkRegionGrowing2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_clitkRegionGrowing_ext (int argc, char * const *argv, struct args_info_clitkRegionGrowing *args_info, - struct cmdline_parser_clitkRegionGrowing_params *params) -{ - int result; - result = cmdline_parser_clitkRegionGrowing_internal (argc, argv, args_info, params, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkRegionGrowing_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkRegionGrowing2 (int argc, char * const *argv, struct args_info_clitkRegionGrowing *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_clitkRegionGrowing_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_clitkRegionGrowing_internal (argc, argv, args_info, ¶ms, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkRegionGrowing_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkRegionGrowing_required (struct args_info_clitkRegionGrowing *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_clitkRegionGrowing_required2(args_info, prog_name, NULL) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkRegionGrowing_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkRegionGrowing_required2 (struct args_info_clitkRegionGrowing *args_info, const char *prog_name, const char *additional_error) -{ - int error = 0; - - /* checks for required options */ - if (! args_info->input_given) - { - fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->output_given) - { - fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (check_multiple_option_occurrences(prog_name, args_info->seed_given, args_info->seed_min, args_info->seed_max, "'--seed' ('-s')")) - error = 1; - - if (check_multiple_option_occurrences(prog_name, args_info->seedRadius_given, args_info->seedRadius_min, args_info->seedRadius_max, "'--seedRadius'")) - error = 1; - - if (check_multiple_option_occurrences(prog_name, args_info->radius_given, args_info->radius_min, args_info->radius_max, "'--radius' ('-r')")) - error = 1; - - - /* checks for dependences among options */ - - return error; -} - -/* - * Extracted from the glibc source tree, version 2.3.6 - * - * Licensed under the GPL as per the whole glibc source tree. - * - * This file was modified so that getopt_long can be called - * many times without risking previous memory to be spoiled. - * - * Modified by Andre Noll and Lorenzo Bettini for use in - * GNU gengetopt generated files. - * - */ - -/* - * we must include anything we need since this file is not thought to be - * inserted in a file already using getopt.h - * - * Lorenzo - */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -static char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -static int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -static int opterr; - -/* Set to an option character which was unrecognized. */ - -static int optopt; - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. -*/ -/* - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `custom_optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -/* Names for the values of the `has_arg' field of `struct option'. */ -#ifndef no_argument -#define no_argument 0 -#endif - -#ifndef required_argument -#define required_argument 1 -#endif - -#ifndef optional_argument -#define optional_argument 2 -#endif - -struct custom_getopt_data { - /* - * These have exactly the same meaning as the corresponding global variables, - * except that they are used for the reentrant versions of getopt. - */ - int custom_optind; - int custom_opterr; - int custom_optopt; - char *custom_optarg; - - /* True if the internal members have been initialized. */ - int initialized; - - /* - * The next char to be scanned in the option-element in which the last option - * character we returned was found. This allows us to pick up the scan where - * we left off. If this is zero, or a null string, it means resume the scan by - * advancing to the next ARGV-element. - */ - char *nextchar; - - /* - * Describe the part of ARGV that contains non-options that have been skipped. - * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is - * the index after the last of them. - */ - int first_nonopt; - int last_nonopt; -}; - -/* - * the variables optarg, optind, opterr and optopt are renamed with - * the custom_ prefix so that they don't interfere with getopt ones. - * - * Moreover they're static so they are visible only from within the - * file where this very file will be included. - */ - -/* - * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an - * option that takes an argument, the argument value is returned here. - */ -static char *custom_optarg; - -/* - * Index in ARGV of the next element to be scanned. This is used for - * communication to and from the caller and for communication between - * successive calls to `custom_getopt'. - * - * On entry to `custom_getopt', 1 means this is the first call; initialize. - * - * When `custom_getopt' returns -1, this is the index of the first of the non-option - * elements that the caller should itself scan. - * - * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV - * has been scanned so far. - * - * 1003.2 says this must be 1 before any call. - */ -static int custom_optind = 1; - -/* - * Callers store zero here to inhibit the error message for unrecognized - * options. - */ -static int custom_opterr = 1; - -/* - * Set to an option character which was unrecognized. This must be initialized - * on some systems to avoid linking in the system's own getopt implementation. - */ -static int custom_optopt = '?'; - -/* - * Exchange two adjacent subsequences of ARGV. One subsequence is elements - * [first_nonopt,last_nonopt) which contains all the non-options that have been - * skipped so far. The other is elements [last_nonopt,custom_optind), which contains - * all the options processed since those non-options were skipped. - * `first_nonopt' and `last_nonopt' are relocated so that they describe the new - * indices of the non-options in ARGV after they are moved. - */ -static void exchange(char **argv, struct custom_getopt_data *d) -{ - int bottom = d->first_nonopt; - int middle = d->last_nonopt; - int top = d->custom_optind; - char *tem; - - /* - * Exchange the shorter segment with the far end of the longer segment. - * That puts the shorter segment into the right place. It leaves the - * longer segment in the right place overall, but it consists of two - * parts that need to be swapped next. - */ - while (top > middle && middle > bottom) { - if (top - middle > middle - bottom) { - /* Bottom segment is the short one. */ - int len = middle - bottom; - int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = - argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } else { - /* Top segment is the short one. */ - int len = top - middle; - int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - /* Update records for the slots the non-options now occupy. */ - d->first_nonopt += (d->custom_optind - d->last_nonopt); - d->last_nonopt = d->custom_optind; -} - -/* Initialize the internal data when the first call is made. */ -static void custom_getopt_initialize(struct custom_getopt_data *d) -{ - /* - * Start processing options with ARGV-element 1 (since ARGV-element 0 - * is the program name); the sequence of previously skipped non-option - * ARGV-elements is empty. - */ - d->first_nonopt = d->last_nonopt = d->custom_optind; - d->nextchar = NULL; - d->initialized = 1; -} - -#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0') - -/* return: zero: continue, nonzero: return given value to user */ -static int shuffle_argv(int argc, char *const *argv,const struct option *longopts, - struct custom_getopt_data *d) -{ - /* - * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been - * moved back by the user (who may also have changed the arguments). - */ - if (d->last_nonopt > d->custom_optind) - d->last_nonopt = d->custom_optind; - if (d->first_nonopt > d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * If we have just processed some options following some - * non-options, exchange them so that the options come first. - */ - if (d->first_nonopt != d->last_nonopt && - d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->last_nonopt != d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * Skip any additional non-options and extend the range of - * non-options previously skipped. - */ - while (d->custom_optind < argc && NONOPTION_P) - d->custom_optind++; - d->last_nonopt = d->custom_optind; - /* - * The special ARGV-element `--' means premature end of options. Skip - * it like a null option, then exchange with previous non-options as if - * it were an option, then skip everything else like a non-option. - */ - if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) { - d->custom_optind++; - if (d->first_nonopt != d->last_nonopt - && d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->first_nonopt == d->last_nonopt) - d->first_nonopt = d->custom_optind; - d->last_nonopt = argc; - d->custom_optind = argc; - } - /* - * If we have done all the ARGV-elements, stop the scan and back over - * any non-options that we skipped and permuted. - */ - if (d->custom_optind == argc) { - /* - * Set the next-arg-index to point at the non-options that we - * previously skipped, so the caller will digest them. - */ - if (d->first_nonopt != d->last_nonopt) - d->custom_optind = d->first_nonopt; - return -1; - } - /* - * If we have come to a non-option and did not permute it, either stop - * the scan or describe it to the caller and pass it by. - */ - if (NONOPTION_P) { - d->custom_optarg = argv[d->custom_optind++]; - return 1; - } - /* - * We have found another option-ARGV-element. Skip the initial - * punctuation. - */ - d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-')); - return 0; -} - -/* - * Check whether the ARGV-element is a long option. - * - * If there's a long option "fubar" and the ARGV-element is "-fu", consider - * that an abbreviation of the long option, just like "--fu", and not "-f" with - * arg "u". - * - * This distinction seems to be the most useful approach. - * - */ -static int check_long_opt(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - int print_errors, struct custom_getopt_data *d) -{ - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match or abbreviated matches */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) { - if ((unsigned int) (nameend - d->nextchar) - == (unsigned int) strlen(p->name)) { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } else if (pfound == NULL) { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } else if (pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' is ambiguous\n", - argv[0], argv[d->custom_optind]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optind++; - d->custom_optopt = 0; - return '?'; - } - if (pfound) { - option_index = indfound; - d->custom_optind++; - if (*nameend) { - if (pfound->has_arg != no_argument) - d->custom_optarg = nameend + 1; - else { - if (print_errors) { - if (argv[d->custom_optind - 1][1] == '-') { - /* --option */ - fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[d->custom_optind - 1][0], pfound->name); - } - - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return '?'; - } - } else if (pfound->has_arg == required_argument) { - if (d->custom_optind < argc) - d->custom_optarg = argv[d->custom_optind++]; - else { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' requires an argument\n", - argv[0], - argv[d->custom_optind - 1]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->nextchar += strlen(d->nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* - * Can't find it as a long option. If this is not getopt_long_only, or - * the option starts with '--' or is not a valid short option, then - * it's an error. Otherwise interpret it as a short option. - */ - if (print_errors) { - if (argv[d->custom_optind][1] == '-') { - /* --option */ - fprintf(stderr, - "%s: unrecognized option `--%s'\n", - argv[0], d->nextchar); - } else { - /* +option or -option */ - fprintf(stderr, - "%s: unrecognized option `%c%s'\n", - argv[0], argv[d->custom_optind][0], - d->nextchar); - } - } - d->nextchar = (char *) ""; - d->custom_optind++; - d->custom_optopt = 0; - return '?'; -} - -static int check_short_opt(int argc, char *const *argv, const char *optstring, - int print_errors, struct custom_getopt_data *d) -{ - char c = *d->nextchar++; - char *temp = strchr(optstring, c); - - /* Increment `custom_optind' when we start to process its last character. */ - if (*d->nextchar == '\0') - ++d->custom_optind; - if (!temp || c == ':') { - if (print_errors) - fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); - - d->custom_optopt = c; - return '?'; - } - if (temp[1] == ':') { - if (temp[2] == ':') { - /* This is an option that accepts an argument optionally. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - d->custom_optind++; - } else - d->custom_optarg = NULL; - d->nextchar = NULL; - } else { - /* This is an option that requires an argument. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - /* - * If we end this ARGV-element by taking the - * rest as an arg, we must advance to the next - * element now. - */ - d->custom_optind++; - } else if (d->custom_optind == argc) { - if (print_errors) { - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], c); - } - d->custom_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } else - /* - * We already incremented `custom_optind' once; - * increment it again when taking next ARGV-elt - * as argument. - */ - d->custom_optarg = argv[d->custom_optind++]; - d->nextchar = NULL; - } - } - return c; -} - -/* - * Scan elements of ARGV for option characters given in OPTSTRING. - * - * If an element of ARGV starts with '-', and is not exactly "-" or "--", - * then it is an option element. The characters of this element - * (aside from the initial '-') are option characters. If `getopt' - * is called repeatedly, it returns successively each of the option characters - * from each of the option elements. - * - * If `getopt' finds another option character, it returns that character, - * updating `custom_optind' and `nextchar' so that the next call to `getopt' can - * resume the scan with the following option character or ARGV-element. - * - * If there are no more option characters, `getopt' returns -1. - * Then `custom_optind' is the index in ARGV of the first ARGV-element - * that is not an option. (The ARGV-elements have been permuted - * so that those that are not options now come last.) - * - * OPTSTRING is a string containing the legitimate option characters. - * If an option character is seen that is not listed in OPTSTRING, - * return '?' after printing an error message. If you set `custom_opterr' to - * zero, the error message is suppressed but we still return '?'. - * - * If a char in OPTSTRING is followed by a colon, that means it wants an arg, - * so the following text in the same ARGV-element, or the text of the following - * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that - * wants an optional arg; if there is text in the current ARGV-element, - * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero. - * - * If OPTSTRING starts with `-' or `+', it requests different methods of - * handling the non-option ARGV-elements. - * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - * - * Long-named options begin with `--' instead of `-'. - * Their names may be abbreviated as long as the abbreviation is unique - * or is an exact match for some defined option. If they have an - * argument, it follows the option name in the same ARGV-element, separated - * from the option name by a `=', or else the in next ARGV-element. - * When `getopt' finds a long-named option, it returns 0 if that option's - * `flag' field is nonzero, the value of the option's `val' field - * if the `flag' field is zero. - * - * The elements of ARGV aren't really const, because we permute them. - * But we pretend they're const in the prototype to be compatible - * with other systems. - * - * LONGOPTS is a vector of `struct option' terminated by an - * element containing a name which is zero. - * - * LONGIND returns the index in LONGOPT of the long-named option found. - * It is only valid when a long-named option has been found by the most - * recent call. - * - * Return the option character from OPTS just read. Return -1 when there are - * no more options. For unrecognized options, or options missing arguments, - * `custom_optopt' is set to the option letter, and '?' is returned. - * - * The OPTS string is a list of characters which are recognized option letters, - * optionally followed by colons, specifying that that letter takes an - * argument, to be placed in `custom_optarg'. - * - * If a letter in OPTS is followed by two colons, its argument is optional. - * This behavior is specific to the GNU `getopt'. - * - * The argument `--' causes premature termination of argument scanning, - * explicitly telling `getopt' that there are no more options. If OPTS begins - * with `--', then non-option arguments are treated as arguments to the option - * '\0'. This behavior is specific to the GNU `getopt'. - */ - -static int getopt_internal_r(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - struct custom_getopt_data *d) -{ - int ret, print_errors = d->custom_opterr; - - if (optstring[0] == ':') - print_errors = 0; - if (argc < 1) - return -1; - d->custom_optarg = NULL; - - /* - * This is a big difference with GNU getopt, since optind == 0 - * means initialization while here 1 means first call. - */ - if (d->custom_optind == 0 || !d->initialized) { - if (d->custom_optind == 0) - d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */ - custom_getopt_initialize(d); - } - if (d->nextchar == NULL || *d->nextchar == '\0') { - ret = shuffle_argv(argc, argv, longopts, d); - if (ret) - return ret; - } - if (longopts && (argv[d->custom_optind][1] == '-' )) - return check_long_opt(argc, argv, optstring, longopts, - longind, print_errors, d); - return check_short_opt(argc, argv, optstring, print_errors, d); -} - -static int custom_getopt_internal(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind) -{ - int result; - /* Keep a global copy of all internal members of d */ - static struct custom_getopt_data d; - - d.custom_optind = custom_optind; - d.custom_opterr = custom_opterr; - result = getopt_internal_r(argc, argv, optstring, longopts, - longind, &d); - custom_optind = d.custom_optind; - custom_optarg = d.custom_optarg; - custom_optopt = d.custom_optopt; - return result; -} - -static int custom_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return custom_getopt_internal(argc, argv, options, long_options, - opt_index); -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_clitkRegionGrowing_params.check_ambiguity - * @param override @see cmdline_parser_clitkRegionGrowing_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, - cmdline_parser_clitkRegionGrowing_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_INT: - if (val) *((int *)field) = strtol (val, &stop_char, 0); - break; - case ARG_DOUBLE: - if (val) *((double *)field) = strtod (val, &stop_char); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_INT: - case ARG_DOUBLE: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - -/** - * @brief store information about a multiple option in a temporary list - * @param list where to (temporarily) store multiple options - */ -static -int update_multiple_arg_temp(struct generic_list **list, - unsigned int *prev_given, const char *val, - char *possible_values[], const char *default_value, - cmdline_parser_clitkRegionGrowing_arg_type arg_type, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *multi_token, *multi_next; /* store single arguments */ - - if (arg_type == ARG_NO) { - (*prev_given)++; - return 0; /* OK */ - } - - multi_token = get_multiple_arg_token(val); - multi_next = get_multiple_arg_token_next (val); - - while (1) - { - add_node (list); - if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, - prev_given, multi_token, possible_values, default_value, - arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { - if (multi_token) free(multi_token); - return 1; /* failure */ - } - - if (multi_next) - { - multi_token = get_multiple_arg_token(multi_next); - multi_next = get_multiple_arg_token_next (multi_next); - } - else - break; - } - - return 0; /* OK */ -} - -/** - * @brief free the passed list (including possible string argument) - */ -static -void free_list(struct generic_list *list, short string_arg) -{ - if (list) { - struct generic_list *tmp; - while (list) - { - tmp = list; - if (string_arg && list->arg.string_arg) - free (list->arg.string_arg); - if (list->orig) - free (list->orig); - list = list->next; - free (tmp); - } - } -} - -/** - * @brief updates a multiple option starting from the passed list - */ -static -void update_multiple_arg(void *field, char ***orig_field, - unsigned int field_given, unsigned int prev_given, union generic_value *default_value, - cmdline_parser_clitkRegionGrowing_arg_type arg_type, - struct generic_list *list) -{ - int i; - struct generic_list *tmp; - - if (prev_given && list) { - *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *)); - - switch(arg_type) { - case ARG_INT: - *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break; - case ARG_DOUBLE: - *((double **)field) = (double *)realloc (*((double **)field), (field_given + prev_given) * sizeof (double)); break; - case ARG_STRING: - *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; - default: - break; - }; - - for (i = (prev_given - 1); i >= 0; --i) - { - tmp = list; - - switch(arg_type) { - case ARG_INT: - (*((int **)field))[i + field_given] = tmp->arg.int_arg; break; - case ARG_DOUBLE: - (*((double **)field))[i + field_given] = tmp->arg.double_arg; break; - case ARG_STRING: - (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; - default: - break; - } - (*orig_field) [i + field_given] = list->orig; - list = list->next; - free (tmp); - } - } else { /* set the default value */ - if (default_value && ! field_given) { - switch(arg_type) { - case ARG_INT: - if (! *((int **)field)) { - *((int **)field) = (int *)malloc (sizeof (int)); - (*((int **)field))[0] = default_value->int_arg; - } - break; - case ARG_DOUBLE: - if (! *((double **)field)) { - *((double **)field) = (double *)malloc (sizeof (double)); - (*((double **)field))[0] = default_value->double_arg; - } - break; - case ARG_STRING: - if (! *((char ***)field)) { - *((char ***)field) = (char **)malloc (sizeof (char *)); - (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg); - } - break; - default: break; - } - if (!(*orig_field)) { - *orig_field = (char **) malloc (sizeof (char *)); - (*orig_field)[0] = NULL; - } - } - } -} - -int -cmdline_parser_clitkRegionGrowing_internal (int argc, char * const *argv, struct args_info_clitkRegionGrowing *args_info, - struct cmdline_parser_clitkRegionGrowing_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - union generic_value multiple_default_value; - - struct generic_list * seed_list = NULL; - struct generic_list * seedRadius_list = NULL; - struct generic_list * radius_list = NULL; - int error = 0; - struct args_info_clitkRegionGrowing local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_clitkRegionGrowing_init (args_info); - - cmdline_parser_clitkRegionGrowing_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "config", 1, NULL, 0 }, - { "verbose", 0, NULL, 'v' }, - { "input", 1, NULL, 'i' }, - { "output", 1, NULL, 'o' }, - { "type", 1, NULL, 't' }, - { "lower", 1, NULL, 'l' }, - { "upper", 1, NULL, 'u' }, - { "maxUpper", 1, NULL, 0 }, - { "minLower", 1, NULL, 0 }, - { "step", 1, NULL, 0 }, - { "minStep", 1, NULL, 0 }, - { "adaptLower", 0, NULL, 0 }, - { "adaptUpper", 0, NULL, 0 }, - { "multiplier", 1, NULL, 'm' }, - { "seed", 1, NULL, 's' }, - { "seedRadius", 1, NULL, 0 }, - { "pad", 1, NULL, 'p' }, - { "radius", 1, NULL, 'r' }, - { "maxSD", 1, NULL, 0 }, - { "full", 0, NULL, 0 }, - { "iter", 1, NULL, 0 }, - { NULL, 0, NULL, 0 } - }; - - custom_optarg = optarg; - custom_optind = optind; - custom_opterr = opterr; - custom_optopt = optopt; - - c = custom_getopt_long (argc, argv, "hVvi:o:t:l:u:m:s:p:r:", long_options, &option_index); - - optarg = custom_optarg; - optind = custom_optind; - opterr = custom_opterr; - optopt = custom_optopt; - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_clitkRegionGrowing_print_help (); - cmdline_parser_clitkRegionGrowing_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_clitkRegionGrowing_print_version (); - cmdline_parser_clitkRegionGrowing_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'v': /* Verbose. */ - - - if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) - goto failure; - - break; - case 'i': /* Input image filename. */ - - - if (update_arg( (void *)&(args_info->input_arg), - &(args_info->input_orig), &(args_info->input_given), - &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "input", 'i', - additional_error)) - goto failure; - - break; - case 'o': /* Output image filename. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - case 't': /* Region growing filter type: 0=threshold , 1=neighborhood-threshold , 2=confidence , 3= locally-adaptive-threshold, 4= explosion-controlled-threshold. */ - - - if (update_arg( (void *)&(args_info->type_arg), - &(args_info->type_orig), &(args_info->type_given), - &(local_args_info.type_given), optarg, 0, "0", ARG_INT, - check_ambiguity, override, 0, 0, - "type", 't', - additional_error)) - goto failure; - - break; - case 'l': /* 1,2,3,4: Lower threshold value. */ - - - if (update_arg( (void *)&(args_info->lower_arg), - &(args_info->lower_orig), &(args_info->lower_given), - &(local_args_info.lower_given), optarg, 0, "310", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "lower", 'l', - additional_error)) - goto failure; - - break; - case 'u': /* 1,2,3,4: Upper threshold value. */ - - - if (update_arg( (void *)&(args_info->upper_arg), - &(args_info->upper_orig), &(args_info->upper_given), - &(local_args_info.upper_given), optarg, 0, "4000", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "upper", 'u', - additional_error)) - goto failure; - - break; - case 'm': /* 2-4: (2-3) accept if within mean+-mutiplier*SD, (4) explosion if size increases multiplier times. */ - - - if (update_arg( (void *)&(args_info->multiplier_arg), - &(args_info->multiplier_orig), &(args_info->multiplier_given), - &(local_args_info.multiplier_given), optarg, 0, "2.0", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "multiplier", 'm', - additional_error)) - goto failure; - - break; - case 's': /* Seed index postion (in voxels). */ - - if (update_multiple_arg_temp(&seed_list, - &(local_args_info.seed_given), optarg, 0, "0", ARG_INT, - "seed", 's', - additional_error)) - goto failure; - - break; - case 'p': /* The replace padding value. */ - - - if (update_arg( (void *)&(args_info->pad_arg), - &(args_info->pad_orig), &(args_info->pad_given), - &(local_args_info.pad_given), optarg, 0, "1.0", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "pad", 'p', - additional_error)) - goto failure; - - break; - case 'r': /* 1-3: The radius of the neighborhood. */ - - if (update_multiple_arg_temp(&radius_list, - &(local_args_info.radius_given), optarg, 0, "1", ARG_INT, - "radius", 'r', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Config file. */ - if (strcmp (long_options[option_index].name, "config") == 0) - { - - - if (update_arg( (void *)&(args_info->config_arg), - &(args_info->config_orig), &(args_info->config_given), - &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "config", '-', - additional_error)) - goto failure; - - } - /* 4: Maximum upper threshold value. */ - else if (strcmp (long_options[option_index].name, "maxUpper") == 0) - { - - - if (update_arg( (void *)&(args_info->maxUpper_arg), - &(args_info->maxUpper_orig), &(args_info->maxUpper_given), - &(local_args_info.maxUpper_given), optarg, 0, "2000", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "maxUpper", '-', - additional_error)) - goto failure; - - } - /* 4: Minimum lower threshold value. */ - else if (strcmp (long_options[option_index].name, "minLower") == 0) - { - - - if (update_arg( (void *)&(args_info->minLower_arg), - &(args_info->minLower_orig), &(args_info->minLower_given), - &(local_args_info.minLower_given), optarg, 0, "-1000", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "minLower", '-', - additional_error)) - goto failure; - - } - /* 4: Threshold step size. */ - else if (strcmp (long_options[option_index].name, "step") == 0) - { - - - if (update_arg( (void *)&(args_info->step_arg), - &(args_info->step_orig), &(args_info->step_given), - &(local_args_info.step_given), optarg, 0, "64.0", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "step", '-', - additional_error)) - goto failure; - - } - /* 4: Minimum threshold step size. */ - else if (strcmp (long_options[option_index].name, "minStep") == 0) - { - - - if (update_arg( (void *)&(args_info->minStep_arg), - &(args_info->minStep_orig), &(args_info->minStep_given), - &(local_args_info.minStep_given), optarg, 0, "1", ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "minStep", '-', - additional_error)) - goto failure; - - } - /* 3,4: (locally) adapt lower thresholding. */ - else if (strcmp (long_options[option_index].name, "adaptLower") == 0) - { - - - if (update_arg((void *)&(args_info->adaptLower_flag), 0, &(args_info->adaptLower_given), - &(local_args_info.adaptLower_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "adaptLower", '-', - additional_error)) - goto failure; - - } - /* 3,4: (locally) adapt upper thresholding. */ - else if (strcmp (long_options[option_index].name, "adaptUpper") == 0) - { - - - if (update_arg((void *)&(args_info->adaptUpper_flag), 0, &(args_info->adaptUpper_given), - &(local_args_info.adaptUpper_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "adaptUpper", '-', - additional_error)) - goto failure; - - } - /* Radius used for seed dilatation(in voxel). */ - else if (strcmp (long_options[option_index].name, "seedRadius") == 0) - { - - if (update_multiple_arg_temp(&seedRadius_list, - &(local_args_info.seedRadius_given), optarg, 0, "0", ARG_INT, - "seedRadius", '-', - additional_error)) - goto failure; - - } - /* 3: Limit to SD. */ - else if (strcmp (long_options[option_index].name, "maxSD") == 0) - { - - - if (update_arg( (void *)&(args_info->maxSD_arg), - &(args_info->maxSD_orig), &(args_info->maxSD_given), - &(local_args_info.maxSD_given), optarg, 0, 0, ARG_DOUBLE, - check_ambiguity, override, 0, 0, - "maxSD", '-', - additional_error)) - goto failure; - - } - /* 4: use full connectivity (not implemented yet). */ - else if (strcmp (long_options[option_index].name, "full") == 0) - { - - - if (update_arg((void *)&(args_info->full_flag), 0, &(args_info->full_given), - &(local_args_info.full_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "full", '-', - additional_error)) - goto failure; - - } - /* 2: Iterations. */ - else if (strcmp (long_options[option_index].name, "iter") == 0) - { - - - if (update_arg( (void *)&(args_info->iter_arg), - &(args_info->iter_orig), &(args_info->iter_given), - &(local_args_info.iter_given), optarg, 0, "5", ARG_INT, - check_ambiguity, override, 0, 0, - "iter", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - update_multiple_arg((void *)&(args_info->seed_arg), - &(args_info->seed_orig), args_info->seed_given, - local_args_info.seed_given, 0 , - ARG_INT, seed_list); - update_multiple_arg((void *)&(args_info->seedRadius_arg), - &(args_info->seedRadius_orig), args_info->seedRadius_given, - local_args_info.seedRadius_given, 0 , - ARG_INT, seedRadius_list); - multiple_default_value.int_arg = 1; - update_multiple_arg((void *)&(args_info->radius_arg), - &(args_info->radius_orig), args_info->radius_given, - local_args_info.radius_given, &multiple_default_value , - ARG_INT, radius_list); - - args_info->seed_given += local_args_info.seed_given; - local_args_info.seed_given = 0; - args_info->seedRadius_given += local_args_info.seedRadius_given; - local_args_info.seedRadius_given = 0; - args_info->radius_given += local_args_info.radius_given; - local_args_info.radius_given = 0; - - if (check_required) - { - error += cmdline_parser_clitkRegionGrowing_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_clitkRegionGrowing_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; - } - - return 0; - -failure: - free_list (seed_list, 0 ); - free_list (seedRadius_list, 0 ); - free_list (radius_list, 0 ); - - cmdline_parser_clitkRegionGrowing_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_cmdline_parser_clitkRegionGrowing_configfile (char * const filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == NULL) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = NULL; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _cmdline_parser_clitkRegionGrowing_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -cmdline_parser_clitkRegionGrowing_configfile (char * const filename, - struct args_info_clitkRegionGrowing *args_info, - int override, int initialize, int check_required) -{ - struct cmdline_parser_clitkRegionGrowing_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return cmdline_parser_clitkRegionGrowing_config_file (filename, args_info, ¶ms); -} - -int -cmdline_parser_clitkRegionGrowing_config_file (char * const filename, - struct args_info_clitkRegionGrowing *args_info, - struct cmdline_parser_clitkRegionGrowing_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE); - - result = _cmdline_parser_clitkRegionGrowing_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - cmdline_parser_clitkRegionGrowing_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkRegionGrowing_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/vv/tools_ggo/clitkRegionGrowing_ggo.h b/vv/tools_ggo/clitkRegionGrowing_ggo.h deleted file mode 100644 index 3b76de6..0000000 --- a/vv/tools_ggo/clitkRegionGrowing_ggo.h +++ /dev/null @@ -1,279 +0,0 @@ -/** @file clitkRegionGrowing_ggo.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef CLITKREGIONGROWING_GGO_H -#define CLITKREGIONGROWING_GGO_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE -/** @brief the program name */ -#define CMDLINE_PARSER_CLITKREGIONGROWING_PACKAGE "clitkRegionGrowing" -#endif - -#ifndef CMDLINE_PARSER_CLITKREGIONGROWING_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_CLITKREGIONGROWING_VERSION "1.0" -#endif - -/** @brief Where the command line options are stored */ -struct args_info_clitkRegionGrowing -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * config_arg; /**< @brief Config file. */ - char * config_orig; /**< @brief Config file original value given at command line. */ - const char *config_help; /**< @brief Config file help description. */ - int verbose_flag; /**< @brief Verbose (default=off). */ - const char *verbose_help; /**< @brief Verbose help description. */ - char * input_arg; /**< @brief Input image filename. */ - char * input_orig; /**< @brief Input image filename original value given at command line. */ - const char *input_help; /**< @brief Input image filename help description. */ - char * output_arg; /**< @brief Output image filename. */ - char * output_orig; /**< @brief Output image filename original value given at command line. */ - const char *output_help; /**< @brief Output image filename help description. */ - int type_arg; /**< @brief Region growing filter type: 0=threshold , 1=neighborhood-threshold , 2=confidence , 3= locally-adaptive-threshold, 4= explosion-controlled-threshold (default='0'). */ - char * type_orig; /**< @brief Region growing filter type: 0=threshold , 1=neighborhood-threshold , 2=confidence , 3= locally-adaptive-threshold, 4= explosion-controlled-threshold original value given at command line. */ - const char *type_help; /**< @brief Region growing filter type: 0=threshold , 1=neighborhood-threshold , 2=confidence , 3= locally-adaptive-threshold, 4= explosion-controlled-threshold help description. */ - double lower_arg; /**< @brief 1,2,3,4: Lower threshold value (default='310'). */ - char * lower_orig; /**< @brief 1,2,3,4: Lower threshold value original value given at command line. */ - const char *lower_help; /**< @brief 1,2,3,4: Lower threshold value help description. */ - double upper_arg; /**< @brief 1,2,3,4: Upper threshold value (default='4000'). */ - char * upper_orig; /**< @brief 1,2,3,4: Upper threshold value original value given at command line. */ - const char *upper_help; /**< @brief 1,2,3,4: Upper threshold value help description. */ - double maxUpper_arg; /**< @brief 4: Maximum upper threshold value (default='2000'). */ - char * maxUpper_orig; /**< @brief 4: Maximum upper threshold value original value given at command line. */ - const char *maxUpper_help; /**< @brief 4: Maximum upper threshold value help description. */ - double minLower_arg; /**< @brief 4: Minimum lower threshold value (default='-1000'). */ - char * minLower_orig; /**< @brief 4: Minimum lower threshold value original value given at command line. */ - const char *minLower_help; /**< @brief 4: Minimum lower threshold value help description. */ - double step_arg; /**< @brief 4: Threshold step size (default='64.0'). */ - char * step_orig; /**< @brief 4: Threshold step size original value given at command line. */ - const char *step_help; /**< @brief 4: Threshold step size help description. */ - double minStep_arg; /**< @brief 4: Minimum threshold step size (default='1'). */ - char * minStep_orig; /**< @brief 4: Minimum threshold step size original value given at command line. */ - const char *minStep_help; /**< @brief 4: Minimum threshold step size help description. */ - int adaptLower_flag; /**< @brief 3,4: (locally) adapt lower thresholding (default=off). */ - const char *adaptLower_help; /**< @brief 3,4: (locally) adapt lower thresholding help description. */ - int adaptUpper_flag; /**< @brief 3,4: (locally) adapt upper thresholding (default=off). */ - const char *adaptUpper_help; /**< @brief 3,4: (locally) adapt upper thresholding help description. */ - double multiplier_arg; /**< @brief 2-4: (2-3) accept if within mean+-mutiplier*SD, (4) explosion if size increases multiplier times (default='2.0'). */ - char * multiplier_orig; /**< @brief 2-4: (2-3) accept if within mean+-mutiplier*SD, (4) explosion if size increases multiplier times original value given at command line. */ - const char *multiplier_help; /**< @brief 2-4: (2-3) accept if within mean+-mutiplier*SD, (4) explosion if size increases multiplier times help description. */ - int* seed_arg; /**< @brief Seed index postion (in voxels) (default='0'). */ - char ** seed_orig; /**< @brief Seed index postion (in voxels) original value given at command line. */ - int seed_min; /**< @brief Seed index postion (in voxels)'s minimum occurreces */ - int seed_max; /**< @brief Seed index postion (in voxels)'s maximum occurreces */ - const char *seed_help; /**< @brief Seed index postion (in voxels) help description. */ - int* seedRadius_arg; /**< @brief Radius used for seed dilatation(in voxel) (default='0'). */ - char ** seedRadius_orig; /**< @brief Radius used for seed dilatation(in voxel) original value given at command line. */ - int seedRadius_min; /**< @brief Radius used for seed dilatation(in voxel)'s minimum occurreces */ - int seedRadius_max; /**< @brief Radius used for seed dilatation(in voxel)'s maximum occurreces */ - const char *seedRadius_help; /**< @brief Radius used for seed dilatation(in voxel) help description. */ - double pad_arg; /**< @brief The replace padding value (default='1.0'). */ - char * pad_orig; /**< @brief The replace padding value original value given at command line. */ - const char *pad_help; /**< @brief The replace padding value help description. */ - int* radius_arg; /**< @brief 1-3: The radius of the neighborhood (default='1'). */ - char ** radius_orig; /**< @brief 1-3: The radius of the neighborhood original value given at command line. */ - int radius_min; /**< @brief 1-3: The radius of the neighborhood's minimum occurreces */ - int radius_max; /**< @brief 1-3: The radius of the neighborhood's maximum occurreces */ - const char *radius_help; /**< @brief 1-3: The radius of the neighborhood help description. */ - double maxSD_arg; /**< @brief 3: Limit to SD. */ - char * maxSD_orig; /**< @brief 3: Limit to SD original value given at command line. */ - const char *maxSD_help; /**< @brief 3: Limit to SD help description. */ - int full_flag; /**< @brief 4: use full connectivity (not implemented yet) (default=off). */ - const char *full_help; /**< @brief 4: use full connectivity (not implemented yet) help description. */ - int iter_arg; /**< @brief 2: Iterations (default='5'). */ - char * iter_orig; /**< @brief 2: Iterations original value given at command line. */ - const char *iter_help; /**< @brief 2: Iterations help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int config_given ; /**< @brief Whether config was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int input_given ; /**< @brief Whether input was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int type_given ; /**< @brief Whether type was given. */ - unsigned int lower_given ; /**< @brief Whether lower was given. */ - unsigned int upper_given ; /**< @brief Whether upper was given. */ - unsigned int maxUpper_given ; /**< @brief Whether maxUpper was given. */ - unsigned int minLower_given ; /**< @brief Whether minLower was given. */ - unsigned int step_given ; /**< @brief Whether step was given. */ - unsigned int minStep_given ; /**< @brief Whether minStep was given. */ - unsigned int adaptLower_given ; /**< @brief Whether adaptLower was given. */ - unsigned int adaptUpper_given ; /**< @brief Whether adaptUpper was given. */ - unsigned int multiplier_given ; /**< @brief Whether multiplier was given. */ - unsigned int seed_given ; /**< @brief Whether seed was given. */ - unsigned int seedRadius_given ; /**< @brief Whether seedRadius was given. */ - unsigned int pad_given ; /**< @brief Whether pad was given. */ - unsigned int radius_given ; /**< @brief Whether radius was given. */ - unsigned int maxSD_given ; /**< @brief Whether maxSD was given. */ - unsigned int full_given ; /**< @brief Whether full was given. */ - unsigned int iter_given ; /**< @brief Whether iter was given. */ - - char **inputs ; /**< @brief unamed options (options without names) */ - unsigned inputs_num ; /**< @brief unamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_clitkRegionGrowing_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure args_info_clitkRegionGrowing (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure args_info_clitkRegionGrowing (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *args_info_clitkRegionGrowing_purpose; -/** @brief the usage string of the program */ -extern const char *args_info_clitkRegionGrowing_usage; -/** @brief all the lines making the help output */ -extern const char *args_info_clitkRegionGrowing_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkRegionGrowing (int argc, char * const *argv, - struct args_info_clitkRegionGrowing *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkRegionGrowing_ext() instead - */ -int cmdline_parser_clitkRegionGrowing2 (int argc, char * const *argv, - struct args_info_clitkRegionGrowing *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkRegionGrowing_ext (int argc, char * const *argv, - struct args_info_clitkRegionGrowing *args_info, - struct cmdline_parser_clitkRegionGrowing_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkRegionGrowing_dump(FILE *outfile, - struct args_info_clitkRegionGrowing *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkRegionGrowing_file_save(const char *filename, - struct args_info_clitkRegionGrowing *args_info); - -/** - * Print the help - */ -void cmdline_parser_clitkRegionGrowing_print_help(void); -/** - * Print the version - */ -void cmdline_parser_clitkRegionGrowing_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_clitkRegionGrowing_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_clitkRegionGrowing_params_init(struct cmdline_parser_clitkRegionGrowing_params *params); - -/** - * Allocates dynamically a cmdline_parser_clitkRegionGrowing_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_clitkRegionGrowing_params structure - */ -struct cmdline_parser_clitkRegionGrowing_params *cmdline_parser_clitkRegionGrowing_params_create(void); - -/** - * Initializes the passed args_info_clitkRegionGrowing structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_clitkRegionGrowing_init (struct args_info_clitkRegionGrowing *args_info); -/** - * Deallocates the string fields of the args_info_clitkRegionGrowing structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_clitkRegionGrowing_free (struct args_info_clitkRegionGrowing *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkRegionGrowing_config_file() instead - */ -int cmdline_parser_clitkRegionGrowing_configfile (char * const filename, - struct args_info_clitkRegionGrowing *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkRegionGrowing_config_file (char * const filename, - struct args_info_clitkRegionGrowing *args_info, - struct cmdline_parser_clitkRegionGrowing_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_clitkRegionGrowing_required (struct args_info_clitkRegionGrowing *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CLITKREGIONGROWING_GGO_H */ diff --git a/vv/tools_ggo/clitkResampleImage_ggo.c b/vv/tools_ggo/clitkResampleImage_ggo.c deleted file mode 100644 index 09389d1..0000000 --- a/vv/tools_ggo/clitkResampleImage_ggo.c +++ /dev/null @@ -1,2116 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22 - generated with the following command: - /usr/local/bin/gengetopt --output-dir=/home/tbaudier/vv/vv_static/vv/vv_bin/tools --arg-struct-name=args_info_clitkResampleImage --func-name=cmdline_parser_clitkResampleImage --file-name=clitkResampleImage_ggo --unamed-opts --conf-parser --include-getopt - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - - -#include "clitkResampleImage_ggo.h" - -const char *args_info_clitkResampleImage_purpose = "Resample an image. You can specify the interpolation, you can apply a Gaussian \nfilter before (automated if downsample)."; - -const char *args_info_clitkResampleImage_usage = "Usage: clitkResampleImage [OPTIONS]... [FILES]..."; - -const char *args_info_clitkResampleImage_description = ""; - -const char *args_info_clitkResampleImage_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - "\nCommon:", - " --config=STRING Config file", - " -v, --verbose Verbose (default=off)", - " --imagetypes Verbose: allowed image types (default=off)", - " --thread=INT Nb of thread to use (default=max)", - "\nInput & Output options:", - " -i, --input=STRING Input image filename", - " -o, --output=STRING Output image filename", - " -l, --like=STRING Resample like this image", - " --size=INT Number of pixels of each coordonate (default=`0')", - " --spacing=FLOAT Spacing in mm between pixels (default=`-1.0')", - " -d, --default=FLOAT Default pixel value (default=`0.0')", - " -t, --time Last Dimension Is Time -> do not resample it (auto on \n for 4D) (default=off)", - "\nInterpolation:", - " --interp=STRING Interpolation type: {nn, linear, bspline, blut} \n (default=`nn')", - " -b, --order=INT BSpline ordre (range 0-5) (default=`3')", - " -s, --sampling=INT BLUT sampling value (default=`30')", - "\nGaussian filtering:", - " -g, --gauss=FLOAT Apply Gaussian before (sigma in mm) (default=`0.0')", - " -a, --autogauss Apply Gaussian with auto sigma when downsample \n (default=off)", - 0 -}; - -typedef enum {ARG_NO - , ARG_FLAG - , ARG_STRING - , ARG_INT - , ARG_FLOAT -} cmdline_parser_clitkResampleImage_arg_type; - -static -void clear_given (struct args_info_clitkResampleImage *args_info); -static -void clear_args (struct args_info_clitkResampleImage *args_info); - -static int -cmdline_parser_clitkResampleImage_internal (int argc, char * const *argv, struct args_info_clitkResampleImage *args_info, - struct cmdline_parser_clitkResampleImage_params *params, const char *additional_error); - -static int -cmdline_parser_clitkResampleImage_required2 (struct args_info_clitkResampleImage *args_info, const char *prog_name, const char *additional_error); -struct line_list -{ - char * string_arg; - struct line_list * next; -}; - -static struct line_list *cmd_line_list = 0; -static struct line_list *cmd_line_list_tmp = 0; - -static void -free_cmd_list(void) -{ - /* free the list of a previous call */ - if (cmd_line_list) - { - while (cmd_line_list) { - cmd_line_list_tmp = cmd_line_list; - cmd_line_list = cmd_line_list->next; - free (cmd_line_list_tmp->string_arg); - free (cmd_line_list_tmp); - } - } -} - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct args_info_clitkResampleImage *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->config_given = 0 ; - args_info->verbose_given = 0 ; - args_info->imagetypes_given = 0 ; - args_info->thread_given = 0 ; - args_info->input_given = 0 ; - args_info->output_given = 0 ; - args_info->like_given = 0 ; - args_info->size_given = 0 ; - args_info->spacing_given = 0 ; - args_info->default_given = 0 ; - args_info->time_given = 0 ; - args_info->interp_given = 0 ; - args_info->order_given = 0 ; - args_info->sampling_given = 0 ; - args_info->gauss_given = 0 ; - args_info->autogauss_given = 0 ; -} - -static -void clear_args (struct args_info_clitkResampleImage *args_info) -{ - args_info->config_arg = NULL; - args_info->config_orig = NULL; - args_info->verbose_flag = 0; - args_info->imagetypes_flag = 0; - args_info->thread_orig = NULL; - args_info->input_arg = NULL; - args_info->input_orig = NULL; - args_info->output_arg = NULL; - args_info->output_orig = NULL; - args_info->like_arg = NULL; - args_info->like_orig = NULL; - args_info->size_arg = NULL; - args_info->size_orig = NULL; - args_info->spacing_arg = NULL; - args_info->spacing_orig = NULL; - args_info->default_arg = 0.0; - args_info->default_orig = NULL; - args_info->time_flag = 0; - args_info->interp_arg = gengetopt_strdup ("nn"); - args_info->interp_orig = NULL; - args_info->order_arg = 3; - args_info->order_orig = NULL; - args_info->sampling_arg = 30; - args_info->sampling_orig = NULL; - args_info->gauss_arg = NULL; - args_info->gauss_orig = NULL; - args_info->autogauss_flag = 0; - -} - -static -void init_args_info(struct args_info_clitkResampleImage *args_info) -{ - - - args_info->help_help = args_info_clitkResampleImage_help[0] ; - args_info->version_help = args_info_clitkResampleImage_help[1] ; - args_info->config_help = args_info_clitkResampleImage_help[3] ; - args_info->verbose_help = args_info_clitkResampleImage_help[4] ; - args_info->imagetypes_help = args_info_clitkResampleImage_help[5] ; - args_info->thread_help = args_info_clitkResampleImage_help[6] ; - args_info->input_help = args_info_clitkResampleImage_help[8] ; - args_info->output_help = args_info_clitkResampleImage_help[9] ; - args_info->like_help = args_info_clitkResampleImage_help[10] ; - args_info->size_help = args_info_clitkResampleImage_help[11] ; - args_info->size_min = -1; - args_info->size_max = -1; - args_info->spacing_help = args_info_clitkResampleImage_help[12] ; - args_info->spacing_min = -1; - args_info->spacing_max = -1; - args_info->default_help = args_info_clitkResampleImage_help[13] ; - args_info->time_help = args_info_clitkResampleImage_help[14] ; - args_info->interp_help = args_info_clitkResampleImage_help[16] ; - args_info->order_help = args_info_clitkResampleImage_help[17] ; - args_info->sampling_help = args_info_clitkResampleImage_help[18] ; - args_info->gauss_help = args_info_clitkResampleImage_help[20] ; - args_info->gauss_min = -1; - args_info->gauss_max = -1; - args_info->autogauss_help = args_info_clitkResampleImage_help[21] ; - -} - -void -cmdline_parser_clitkResampleImage_print_version (void) -{ - printf ("%s %s\n", CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, CMDLINE_PARSER_CLITKRESAMPLEIMAGE_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_clitkResampleImage_print_version (); - - if (strlen(args_info_clitkResampleImage_purpose) > 0) - printf("\n%s\n", args_info_clitkResampleImage_purpose); - - if (strlen(args_info_clitkResampleImage_usage) > 0) - printf("\n%s\n", args_info_clitkResampleImage_usage); - - printf("\n"); - - if (strlen(args_info_clitkResampleImage_description) > 0) - printf("%s\n", args_info_clitkResampleImage_description); -} - -void -cmdline_parser_clitkResampleImage_print_help (void) -{ - int i = 0; - print_help_common(); - while (args_info_clitkResampleImage_help[i]) - printf("%s\n", args_info_clitkResampleImage_help[i++]); -} - -void -cmdline_parser_clitkResampleImage_init (struct args_info_clitkResampleImage *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = NULL; - args_info->inputs_num = 0; -} - -void -cmdline_parser_clitkResampleImage_params_init(struct cmdline_parser_clitkResampleImage_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_clitkResampleImage_params * -cmdline_parser_clitkResampleImage_params_create(void) -{ - struct cmdline_parser_clitkResampleImage_params *params = - (struct cmdline_parser_clitkResampleImage_params *)malloc(sizeof(struct cmdline_parser_clitkResampleImage_params)); - cmdline_parser_clitkResampleImage_params_init(params); - return params; -} - -static void -free_string_field (char **s) -{ - if (*s) - { - free (*s); - *s = 0; - } -} - -/** @brief generic value variable */ -union generic_value { - int int_arg; - float float_arg; - char *string_arg; -}; - -/** @brief holds temporary values for multiple options */ -struct generic_list -{ - union generic_value arg; - char *orig; - struct generic_list *next; -}; - -/** - * @brief add a node at the head of the list - */ -static void add_node(struct generic_list **list) { - struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list)); - new_node->next = *list; - *list = new_node; - new_node->arg.string_arg = NULL; - new_node->orig = NULL; -} - -static void -free_multiple_field(unsigned int len, void **arg, char ***orig) -{ - unsigned int i; - if (*arg) { - for (i = 0; i < len; ++i) - { - free_string_field(&((*orig)[i])); - } - - free (*arg); - *arg = 0; - free (*orig); - *orig = 0; - } -} - - -static void -cmdline_parser_clitkResampleImage_release (struct args_info_clitkResampleImage *args_info) -{ - unsigned int i; - free_string_field (&(args_info->config_arg)); - free_string_field (&(args_info->config_orig)); - free_string_field (&(args_info->thread_orig)); - free_string_field (&(args_info->input_arg)); - free_string_field (&(args_info->input_orig)); - free_string_field (&(args_info->output_arg)); - free_string_field (&(args_info->output_orig)); - free_string_field (&(args_info->like_arg)); - free_string_field (&(args_info->like_orig)); - free_multiple_field (args_info->size_given, (void **)&(args_info->size_arg), &(args_info->size_orig)); - free_multiple_field (args_info->spacing_given, (void **)&(args_info->spacing_arg), &(args_info->spacing_orig)); - free_string_field (&(args_info->default_orig)); - free_string_field (&(args_info->interp_arg)); - free_string_field (&(args_info->interp_orig)); - free_string_field (&(args_info->order_orig)); - free_string_field (&(args_info->sampling_orig)); - free_multiple_field (args_info->gauss_given, (void **)&(args_info->gauss_arg), &(args_info->gauss_orig)); - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[]) -{ - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - -static void -write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[]) -{ - int i; - - for (i = 0; i < len; ++i) - write_into_file(outfile, opt, (arg ? arg[i] : 0), values); -} - -int -cmdline_parser_clitkResampleImage_dump(FILE *outfile, struct args_info_clitkResampleImage *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->config_given) - write_into_file(outfile, "config", args_info->config_orig, 0); - if (args_info->verbose_given) - write_into_file(outfile, "verbose", 0, 0 ); - if (args_info->imagetypes_given) - write_into_file(outfile, "imagetypes", 0, 0 ); - if (args_info->thread_given) - write_into_file(outfile, "thread", args_info->thread_orig, 0); - if (args_info->input_given) - write_into_file(outfile, "input", args_info->input_orig, 0); - if (args_info->output_given) - write_into_file(outfile, "output", args_info->output_orig, 0); - if (args_info->like_given) - write_into_file(outfile, "like", args_info->like_orig, 0); - write_multiple_into_file(outfile, args_info->size_given, "size", args_info->size_orig, 0); - write_multiple_into_file(outfile, args_info->spacing_given, "spacing", args_info->spacing_orig, 0); - if (args_info->default_given) - write_into_file(outfile, "default", args_info->default_orig, 0); - if (args_info->time_given) - write_into_file(outfile, "time", 0, 0 ); - if (args_info->interp_given) - write_into_file(outfile, "interp", args_info->interp_orig, 0); - if (args_info->order_given) - write_into_file(outfile, "order", args_info->order_orig, 0); - if (args_info->sampling_given) - write_into_file(outfile, "sampling", args_info->sampling_orig, 0); - write_multiple_into_file(outfile, args_info->gauss_given, "gauss", args_info->gauss_orig, 0); - if (args_info->autogauss_given) - write_into_file(outfile, "autogauss", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_clitkResampleImage_file_save(const char *filename, struct args_info_clitkResampleImage *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_clitkResampleImage_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_clitkResampleImage_free (struct args_info_clitkResampleImage *args_info) -{ - cmdline_parser_clitkResampleImage_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = NULL; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -static char * -get_multiple_arg_token(const char *arg) -{ - char *tok, *ret; - size_t len, num_of_escape, i, j; - - if (!arg) - return NULL; - - tok = strchr (arg, ','); - num_of_escape = 0; - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - ++num_of_escape; - } - else - break; - } - - if (tok) - len = (size_t)(tok - arg + 1); - else - len = strlen (arg) + 1; - - len -= num_of_escape; - - ret = (char *) malloc (len); - - i = 0; - j = 0; - while (arg[i] && (j < len-1)) - { - if (arg[i] == '\\' && - arg[ i + 1 ] && - arg[ i + 1 ] == ',') - ++i; - - ret[j++] = arg[i++]; - } - - ret[len-1] = '\0'; - - return ret; -} - -static char * -get_multiple_arg_token_next(const char *arg) -{ - char *tok; - - if (!arg) - return NULL; - - tok = strchr (arg, ','); - - /* make sure it is not escaped */ - while (tok) - { - if (*(tok-1) == '\\') - { - /* find the next one */ - tok = strchr (tok+1, ','); - } - else - break; - } - - if (! tok || strlen(tok) == 1) - return 0; - - return tok+1; -} - -static int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc); - -int -check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc) -{ - int error = 0; - - if (option_given && ! (min < 0 && max < 0)) - { - if (min >= 0 && max >= 0) - { - if (min == max) - { - /* specific occurrences */ - if (option_given != min) - { - fprintf (stderr, "%s: %s option occurrences must be %d\n", - prog_name, option_desc, min); - error = 1; - } - } - else if (option_given < min - || option_given > max) - { - /* range occurrences */ - fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n", - prog_name, option_desc, min, max); - error = 1; - } - } - else if (min >= 0) - { - /* at least check */ - if (option_given < min) - { - fprintf (stderr, "%s: %s option occurrences must be at least %d\n", - prog_name, option_desc, min); - error = 1; - } - } - else if (max >= 0) - { - /* at most check */ - if (option_given > max) - { - fprintf (stderr, "%s: %s option occurrences must be at most %d\n", - prog_name, option_desc, max); - error = 1; - } - } - } - - return error; -} -int -cmdline_parser_clitkResampleImage (int argc, char * const *argv, struct args_info_clitkResampleImage *args_info) -{ - return cmdline_parser_clitkResampleImage2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_clitkResampleImage_ext (int argc, char * const *argv, struct args_info_clitkResampleImage *args_info, - struct cmdline_parser_clitkResampleImage_params *params) -{ - int result; - result = cmdline_parser_clitkResampleImage_internal (argc, argv, args_info, params, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkResampleImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkResampleImage2 (int argc, char * const *argv, struct args_info_clitkResampleImage *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_clitkResampleImage_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_clitkResampleImage_internal (argc, argv, args_info, ¶ms, NULL); - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkResampleImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkResampleImage_required (struct args_info_clitkResampleImage *args_info, const char *prog_name) -{ - int result = EXIT_SUCCESS; - - if (cmdline_parser_clitkResampleImage_required2(args_info, prog_name, NULL) > 0) - result = EXIT_FAILURE; - - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkResampleImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_clitkResampleImage_required2 (struct args_info_clitkResampleImage *args_info, const char *prog_name, const char *additional_error) -{ - int error = 0; - - /* checks for required options */ - if (! args_info->input_given) - { - fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (! args_info->output_given) - { - fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : "")); - error = 1; - } - - if (check_multiple_option_occurrences(prog_name, args_info->size_given, args_info->size_min, args_info->size_max, "'--size'")) - error = 1; - - if (check_multiple_option_occurrences(prog_name, args_info->spacing_given, args_info->spacing_min, args_info->spacing_max, "'--spacing'")) - error = 1; - - if (check_multiple_option_occurrences(prog_name, args_info->gauss_given, args_info->gauss_min, args_info->gauss_max, "'--gauss' ('-g')")) - error = 1; - - - /* checks for dependences among options */ - - return error; -} - -/* - * Extracted from the glibc source tree, version 2.3.6 - * - * Licensed under the GPL as per the whole glibc source tree. - * - * This file was modified so that getopt_long can be called - * many times without risking previous memory to be spoiled. - * - * Modified by Andre Noll and Lorenzo Bettini for use in - * GNU gengetopt generated files. - * - */ - -/* - * we must include anything we need since this file is not thought to be - * inserted in a file already using getopt.h - * - * Lorenzo - */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -static char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -static int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -static int opterr; - -/* Set to an option character which was unrecognized. */ - -static int optopt; - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. -*/ -/* - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `custom_optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -/* Names for the values of the `has_arg' field of `struct option'. */ -#ifndef no_argument -#define no_argument 0 -#endif - -#ifndef required_argument -#define required_argument 1 -#endif - -#ifndef optional_argument -#define optional_argument 2 -#endif - -struct custom_getopt_data { - /* - * These have exactly the same meaning as the corresponding global variables, - * except that they are used for the reentrant versions of getopt. - */ - int custom_optind; - int custom_opterr; - int custom_optopt; - char *custom_optarg; - - /* True if the internal members have been initialized. */ - int initialized; - - /* - * The next char to be scanned in the option-element in which the last option - * character we returned was found. This allows us to pick up the scan where - * we left off. If this is zero, or a null string, it means resume the scan by - * advancing to the next ARGV-element. - */ - char *nextchar; - - /* - * Describe the part of ARGV that contains non-options that have been skipped. - * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is - * the index after the last of them. - */ - int first_nonopt; - int last_nonopt; -}; - -/* - * the variables optarg, optind, opterr and optopt are renamed with - * the custom_ prefix so that they don't interfere with getopt ones. - * - * Moreover they're static so they are visible only from within the - * file where this very file will be included. - */ - -/* - * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an - * option that takes an argument, the argument value is returned here. - */ -static char *custom_optarg; - -/* - * Index in ARGV of the next element to be scanned. This is used for - * communication to and from the caller and for communication between - * successive calls to `custom_getopt'. - * - * On entry to `custom_getopt', 1 means this is the first call; initialize. - * - * When `custom_getopt' returns -1, this is the index of the first of the non-option - * elements that the caller should itself scan. - * - * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV - * has been scanned so far. - * - * 1003.2 says this must be 1 before any call. - */ -static int custom_optind = 1; - -/* - * Callers store zero here to inhibit the error message for unrecognized - * options. - */ -static int custom_opterr = 1; - -/* - * Set to an option character which was unrecognized. This must be initialized - * on some systems to avoid linking in the system's own getopt implementation. - */ -static int custom_optopt = '?'; - -/* - * Exchange two adjacent subsequences of ARGV. One subsequence is elements - * [first_nonopt,last_nonopt) which contains all the non-options that have been - * skipped so far. The other is elements [last_nonopt,custom_optind), which contains - * all the options processed since those non-options were skipped. - * `first_nonopt' and `last_nonopt' are relocated so that they describe the new - * indices of the non-options in ARGV after they are moved. - */ -static void exchange(char **argv, struct custom_getopt_data *d) -{ - int bottom = d->first_nonopt; - int middle = d->last_nonopt; - int top = d->custom_optind; - char *tem; - - /* - * Exchange the shorter segment with the far end of the longer segment. - * That puts the shorter segment into the right place. It leaves the - * longer segment in the right place overall, but it consists of two - * parts that need to be swapped next. - */ - while (top > middle && middle > bottom) { - if (top - middle > middle - bottom) { - /* Bottom segment is the short one. */ - int len = middle - bottom; - int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = - argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } else { - /* Top segment is the short one. */ - int len = top - middle; - int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - /* Update records for the slots the non-options now occupy. */ - d->first_nonopt += (d->custom_optind - d->last_nonopt); - d->last_nonopt = d->custom_optind; -} - -/* Initialize the internal data when the first call is made. */ -static void custom_getopt_initialize(struct custom_getopt_data *d) -{ - /* - * Start processing options with ARGV-element 1 (since ARGV-element 0 - * is the program name); the sequence of previously skipped non-option - * ARGV-elements is empty. - */ - d->first_nonopt = d->last_nonopt = d->custom_optind; - d->nextchar = NULL; - d->initialized = 1; -} - -#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0') - -/* return: zero: continue, nonzero: return given value to user */ -static int shuffle_argv(int argc, char *const *argv,const struct option *longopts, - struct custom_getopt_data *d) -{ - /* - * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been - * moved back by the user (who may also have changed the arguments). - */ - if (d->last_nonopt > d->custom_optind) - d->last_nonopt = d->custom_optind; - if (d->first_nonopt > d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * If we have just processed some options following some - * non-options, exchange them so that the options come first. - */ - if (d->first_nonopt != d->last_nonopt && - d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->last_nonopt != d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * Skip any additional non-options and extend the range of - * non-options previously skipped. - */ - while (d->custom_optind < argc && NONOPTION_P) - d->custom_optind++; - d->last_nonopt = d->custom_optind; - /* - * The special ARGV-element `--' means premature end of options. Skip - * it like a null option, then exchange with previous non-options as if - * it were an option, then skip everything else like a non-option. - */ - if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) { - d->custom_optind++; - if (d->first_nonopt != d->last_nonopt - && d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->first_nonopt == d->last_nonopt) - d->first_nonopt = d->custom_optind; - d->last_nonopt = argc; - d->custom_optind = argc; - } - /* - * If we have done all the ARGV-elements, stop the scan and back over - * any non-options that we skipped and permuted. - */ - if (d->custom_optind == argc) { - /* - * Set the next-arg-index to point at the non-options that we - * previously skipped, so the caller will digest them. - */ - if (d->first_nonopt != d->last_nonopt) - d->custom_optind = d->first_nonopt; - return -1; - } - /* - * If we have come to a non-option and did not permute it, either stop - * the scan or describe it to the caller and pass it by. - */ - if (NONOPTION_P) { - d->custom_optarg = argv[d->custom_optind++]; - return 1; - } - /* - * We have found another option-ARGV-element. Skip the initial - * punctuation. - */ - d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-')); - return 0; -} - -/* - * Check whether the ARGV-element is a long option. - * - * If there's a long option "fubar" and the ARGV-element is "-fu", consider - * that an abbreviation of the long option, just like "--fu", and not "-f" with - * arg "u". - * - * This distinction seems to be the most useful approach. - * - */ -static int check_long_opt(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - int print_errors, struct custom_getopt_data *d) -{ - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match or abbreviated matches */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) { - if ((unsigned int) (nameend - d->nextchar) - == (unsigned int) strlen(p->name)) { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } else if (pfound == NULL) { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } else if (pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' is ambiguous\n", - argv[0], argv[d->custom_optind]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optind++; - d->custom_optopt = 0; - return '?'; - } - if (pfound) { - option_index = indfound; - d->custom_optind++; - if (*nameend) { - if (pfound->has_arg != no_argument) - d->custom_optarg = nameend + 1; - else { - if (print_errors) { - if (argv[d->custom_optind - 1][1] == '-') { - /* --option */ - fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[d->custom_optind - 1][0], pfound->name); - } - - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return '?'; - } - } else if (pfound->has_arg == required_argument) { - if (d->custom_optind < argc) - d->custom_optarg = argv[d->custom_optind++]; - else { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' requires an argument\n", - argv[0], - argv[d->custom_optind - 1]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->nextchar += strlen(d->nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* - * Can't find it as a long option. If this is not getopt_long_only, or - * the option starts with '--' or is not a valid short option, then - * it's an error. Otherwise interpret it as a short option. - */ - if (print_errors) { - if (argv[d->custom_optind][1] == '-') { - /* --option */ - fprintf(stderr, - "%s: unrecognized option `--%s'\n", - argv[0], d->nextchar); - } else { - /* +option or -option */ - fprintf(stderr, - "%s: unrecognized option `%c%s'\n", - argv[0], argv[d->custom_optind][0], - d->nextchar); - } - } - d->nextchar = (char *) ""; - d->custom_optind++; - d->custom_optopt = 0; - return '?'; -} - -static int check_short_opt(int argc, char *const *argv, const char *optstring, - int print_errors, struct custom_getopt_data *d) -{ - char c = *d->nextchar++; - char *temp = strchr(optstring, c); - - /* Increment `custom_optind' when we start to process its last character. */ - if (*d->nextchar == '\0') - ++d->custom_optind; - if (!temp || c == ':') { - if (print_errors) - fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); - - d->custom_optopt = c; - return '?'; - } - if (temp[1] == ':') { - if (temp[2] == ':') { - /* This is an option that accepts an argument optionally. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - d->custom_optind++; - } else - d->custom_optarg = NULL; - d->nextchar = NULL; - } else { - /* This is an option that requires an argument. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - /* - * If we end this ARGV-element by taking the - * rest as an arg, we must advance to the next - * element now. - */ - d->custom_optind++; - } else if (d->custom_optind == argc) { - if (print_errors) { - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], c); - } - d->custom_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } else - /* - * We already incremented `custom_optind' once; - * increment it again when taking next ARGV-elt - * as argument. - */ - d->custom_optarg = argv[d->custom_optind++]; - d->nextchar = NULL; - } - } - return c; -} - -/* - * Scan elements of ARGV for option characters given in OPTSTRING. - * - * If an element of ARGV starts with '-', and is not exactly "-" or "--", - * then it is an option element. The characters of this element - * (aside from the initial '-') are option characters. If `getopt' - * is called repeatedly, it returns successively each of the option characters - * from each of the option elements. - * - * If `getopt' finds another option character, it returns that character, - * updating `custom_optind' and `nextchar' so that the next call to `getopt' can - * resume the scan with the following option character or ARGV-element. - * - * If there are no more option characters, `getopt' returns -1. - * Then `custom_optind' is the index in ARGV of the first ARGV-element - * that is not an option. (The ARGV-elements have been permuted - * so that those that are not options now come last.) - * - * OPTSTRING is a string containing the legitimate option characters. - * If an option character is seen that is not listed in OPTSTRING, - * return '?' after printing an error message. If you set `custom_opterr' to - * zero, the error message is suppressed but we still return '?'. - * - * If a char in OPTSTRING is followed by a colon, that means it wants an arg, - * so the following text in the same ARGV-element, or the text of the following - * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that - * wants an optional arg; if there is text in the current ARGV-element, - * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero. - * - * If OPTSTRING starts with `-' or `+', it requests different methods of - * handling the non-option ARGV-elements. - * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - * - * Long-named options begin with `--' instead of `-'. - * Their names may be abbreviated as long as the abbreviation is unique - * or is an exact match for some defined option. If they have an - * argument, it follows the option name in the same ARGV-element, separated - * from the option name by a `=', or else the in next ARGV-element. - * When `getopt' finds a long-named option, it returns 0 if that option's - * `flag' field is nonzero, the value of the option's `val' field - * if the `flag' field is zero. - * - * The elements of ARGV aren't really const, because we permute them. - * But we pretend they're const in the prototype to be compatible - * with other systems. - * - * LONGOPTS is a vector of `struct option' terminated by an - * element containing a name which is zero. - * - * LONGIND returns the index in LONGOPT of the long-named option found. - * It is only valid when a long-named option has been found by the most - * recent call. - * - * Return the option character from OPTS just read. Return -1 when there are - * no more options. For unrecognized options, or options missing arguments, - * `custom_optopt' is set to the option letter, and '?' is returned. - * - * The OPTS string is a list of characters which are recognized option letters, - * optionally followed by colons, specifying that that letter takes an - * argument, to be placed in `custom_optarg'. - * - * If a letter in OPTS is followed by two colons, its argument is optional. - * This behavior is specific to the GNU `getopt'. - * - * The argument `--' causes premature termination of argument scanning, - * explicitly telling `getopt' that there are no more options. If OPTS begins - * with `--', then non-option arguments are treated as arguments to the option - * '\0'. This behavior is specific to the GNU `getopt'. - */ - -static int getopt_internal_r(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - struct custom_getopt_data *d) -{ - int ret, print_errors = d->custom_opterr; - - if (optstring[0] == ':') - print_errors = 0; - if (argc < 1) - return -1; - d->custom_optarg = NULL; - - /* - * This is a big difference with GNU getopt, since optind == 0 - * means initialization while here 1 means first call. - */ - if (d->custom_optind == 0 || !d->initialized) { - if (d->custom_optind == 0) - d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */ - custom_getopt_initialize(d); - } - if (d->nextchar == NULL || *d->nextchar == '\0') { - ret = shuffle_argv(argc, argv, longopts, d); - if (ret) - return ret; - } - if (longopts && (argv[d->custom_optind][1] == '-' )) - return check_long_opt(argc, argv, optstring, longopts, - longind, print_errors, d); - return check_short_opt(argc, argv, optstring, print_errors, d); -} - -static int custom_getopt_internal(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind) -{ - int result; - /* Keep a global copy of all internal members of d */ - static struct custom_getopt_data d; - - d.custom_optind = custom_optind; - d.custom_opterr = custom_opterr; - result = getopt_internal_r(argc, argv, optstring, longopts, - longind, &d); - custom_optind = d.custom_optind; - custom_optarg = d.custom_optarg; - custom_optopt = d.custom_optopt; - return result; -} - -static int custom_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return custom_getopt_internal(argc, argv, options, long_options, - opt_index); -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_clitkResampleImage_params.check_ambiguity - * @param override @see cmdline_parser_clitkResampleImage_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, char *possible_values[], const char *default_value, - cmdline_parser_clitkResampleImage_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *stop_char = 0; - const char *val = value; - int found; - char **string_field; - - stop_char = 0; - found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - if (possible_values) - val = possible_values[found]; - - switch(arg_type) { - case ARG_FLAG: - *((int *)field) = !*((int *)field); - break; - case ARG_INT: - if (val) *((int *)field) = strtol (val, &stop_char, 0); - break; - case ARG_FLOAT: - if (val) *((float *)field) = (float)strtod (val, &stop_char); - break; - case ARG_STRING: - if (val) { - string_field = (char **)field; - if (!no_free && *string_field) - free (*string_field); /* free previous string */ - *string_field = gengetopt_strdup (val); - } - break; - default: - break; - }; - - /* check numeric conversion */ - switch(arg_type) { - case ARG_INT: - case ARG_FLOAT: - if (val && !(stop_char && *stop_char == '\0')) { - fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); - return 1; /* failure */ - } - break; - default: - ; - }; - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - case ARG_FLAG: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - -/** - * @brief store information about a multiple option in a temporary list - * @param list where to (temporarily) store multiple options - */ -static -int update_multiple_arg_temp(struct generic_list **list, - unsigned int *prev_given, const char *val, - char *possible_values[], const char *default_value, - cmdline_parser_clitkResampleImage_arg_type arg_type, - const char *long_opt, char short_opt, - const char *additional_error) -{ - char *multi_token, *multi_next; /* store single arguments */ - - if (arg_type == ARG_NO) { - (*prev_given)++; - return 0; /* OK */ - } - - multi_token = get_multiple_arg_token(val); - multi_next = get_multiple_arg_token_next (val); - - while (1) - { - add_node (list); - if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0, - prev_given, multi_token, possible_values, default_value, - arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) { - if (multi_token) free(multi_token); - return 1; /* failure */ - } - - if (multi_next) - { - multi_token = get_multiple_arg_token(multi_next); - multi_next = get_multiple_arg_token_next (multi_next); - } - else - break; - } - - return 0; /* OK */ -} - -/** - * @brief free the passed list (including possible string argument) - */ -static -void free_list(struct generic_list *list, short string_arg) -{ - if (list) { - struct generic_list *tmp; - while (list) - { - tmp = list; - if (string_arg && list->arg.string_arg) - free (list->arg.string_arg); - if (list->orig) - free (list->orig); - list = list->next; - free (tmp); - } - } -} - -/** - * @brief updates a multiple option starting from the passed list - */ -static -void update_multiple_arg(void *field, char ***orig_field, - unsigned int field_given, unsigned int prev_given, union generic_value *default_value, - cmdline_parser_clitkResampleImage_arg_type arg_type, - struct generic_list *list) -{ - int i; - struct generic_list *tmp; - - if (prev_given && list) { - *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *)); - - switch(arg_type) { - case ARG_INT: - *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break; - case ARG_FLOAT: - *((float **)field) = (float *)realloc (*((float **)field), (field_given + prev_given) * sizeof (float)); break; - case ARG_STRING: - *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break; - default: - break; - }; - - for (i = (prev_given - 1); i >= 0; --i) - { - tmp = list; - - switch(arg_type) { - case ARG_INT: - (*((int **)field))[i + field_given] = tmp->arg.int_arg; break; - case ARG_FLOAT: - (*((float **)field))[i + field_given] = tmp->arg.float_arg; break; - case ARG_STRING: - (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break; - default: - break; - } - (*orig_field) [i + field_given] = list->orig; - list = list->next; - free (tmp); - } - } else { /* set the default value */ - if (default_value && ! field_given) { - switch(arg_type) { - case ARG_INT: - if (! *((int **)field)) { - *((int **)field) = (int *)malloc (sizeof (int)); - (*((int **)field))[0] = default_value->int_arg; - } - break; - case ARG_FLOAT: - if (! *((float **)field)) { - *((float **)field) = (float *)malloc (sizeof (float)); - (*((float **)field))[0] = default_value->float_arg; - } - break; - case ARG_STRING: - if (! *((char ***)field)) { - *((char ***)field) = (char **)malloc (sizeof (char *)); - (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg); - } - break; - default: break; - } - if (!(*orig_field)) { - *orig_field = (char **) malloc (sizeof (char *)); - (*orig_field)[0] = NULL; - } - } - } -} - -int -cmdline_parser_clitkResampleImage_internal (int argc, char * const *argv, struct args_info_clitkResampleImage *args_info, - struct cmdline_parser_clitkResampleImage_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - union generic_value multiple_default_value; - - struct generic_list * size_list = NULL; - struct generic_list * spacing_list = NULL; - struct generic_list * gauss_list = NULL; - int error = 0; - struct args_info_clitkResampleImage local_args_info; - - int override; - int initialize; - int check_required; - int check_ambiguity; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_clitkResampleImage_init (args_info); - - cmdline_parser_clitkResampleImage_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "config", 1, NULL, 0 }, - { "verbose", 0, NULL, 'v' }, - { "imagetypes", 0, NULL, 0 }, - { "thread", 1, NULL, 0 }, - { "input", 1, NULL, 'i' }, - { "output", 1, NULL, 'o' }, - { "like", 1, NULL, 'l' }, - { "size", 1, NULL, 0 }, - { "spacing", 1, NULL, 0 }, - { "default", 1, NULL, 'd' }, - { "time", 0, NULL, 't' }, - { "interp", 1, NULL, 0 }, - { "order", 1, NULL, 'b' }, - { "sampling", 1, NULL, 's' }, - { "gauss", 1, NULL, 'g' }, - { "autogauss", 0, NULL, 'a' }, - { NULL, 0, NULL, 0 } - }; - - custom_optarg = optarg; - custom_optind = optind; - custom_opterr = opterr; - custom_optopt = optopt; - - c = custom_getopt_long (argc, argv, "hVvi:o:l:d:tb:s:g:a", long_options, &option_index); - - optarg = custom_optarg; - optind = custom_optind; - opterr = custom_opterr; - optopt = custom_optopt; - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_clitkResampleImage_print_help (); - cmdline_parser_clitkResampleImage_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_clitkResampleImage_print_version (); - cmdline_parser_clitkResampleImage_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'v': /* Verbose. */ - - - if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given), - &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "verbose", 'v', - additional_error)) - goto failure; - - break; - case 'i': /* Input image filename. */ - - - if (update_arg( (void *)&(args_info->input_arg), - &(args_info->input_orig), &(args_info->input_given), - &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "input", 'i', - additional_error)) - goto failure; - - break; - case 'o': /* Output image filename. */ - - - if (update_arg( (void *)&(args_info->output_arg), - &(args_info->output_orig), &(args_info->output_given), - &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "output", 'o', - additional_error)) - goto failure; - - break; - case 'l': /* Resample like this image. */ - - - if (update_arg( (void *)&(args_info->like_arg), - &(args_info->like_orig), &(args_info->like_given), - &(local_args_info.like_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "like", 'l', - additional_error)) - goto failure; - - break; - case 'd': /* Default pixel value. */ - - - if (update_arg( (void *)&(args_info->default_arg), - &(args_info->default_orig), &(args_info->default_given), - &(local_args_info.default_given), optarg, 0, "0.0", ARG_FLOAT, - check_ambiguity, override, 0, 0, - "default", 'd', - additional_error)) - goto failure; - - break; - case 't': /* Last Dimension Is Time -> do not resample it (auto on for 4D). */ - - - if (update_arg((void *)&(args_info->time_flag), 0, &(args_info->time_given), - &(local_args_info.time_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "time", 't', - additional_error)) - goto failure; - - break; - case 'b': /* BSpline ordre (range 0-5). */ - - - if (update_arg( (void *)&(args_info->order_arg), - &(args_info->order_orig), &(args_info->order_given), - &(local_args_info.order_given), optarg, 0, "3", ARG_INT, - check_ambiguity, override, 0, 0, - "order", 'b', - additional_error)) - goto failure; - - break; - case 's': /* BLUT sampling value. */ - - - if (update_arg( (void *)&(args_info->sampling_arg), - &(args_info->sampling_orig), &(args_info->sampling_given), - &(local_args_info.sampling_given), optarg, 0, "30", ARG_INT, - check_ambiguity, override, 0, 0, - "sampling", 's', - additional_error)) - goto failure; - - break; - case 'g': /* Apply Gaussian before (sigma in mm). */ - - if (update_multiple_arg_temp(&gauss_list, - &(local_args_info.gauss_given), optarg, 0, "0.0", ARG_FLOAT, - "gauss", 'g', - additional_error)) - goto failure; - - break; - case 'a': /* Apply Gaussian with auto sigma when downsample. */ - - - if (update_arg((void *)&(args_info->autogauss_flag), 0, &(args_info->autogauss_given), - &(local_args_info.autogauss_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "autogauss", 'a', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - /* Config file. */ - if (strcmp (long_options[option_index].name, "config") == 0) - { - - - if (update_arg( (void *)&(args_info->config_arg), - &(args_info->config_orig), &(args_info->config_given), - &(local_args_info.config_given), optarg, 0, 0, ARG_STRING, - check_ambiguity, override, 0, 0, - "config", '-', - additional_error)) - goto failure; - - } - /* Verbose: allowed image types. */ - else if (strcmp (long_options[option_index].name, "imagetypes") == 0) - { - - - if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given), - &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG, - check_ambiguity, override, 1, 0, "imagetypes", '-', - additional_error)) - goto failure; - - } - /* Nb of thread to use (default=max). */ - else if (strcmp (long_options[option_index].name, "thread") == 0) - { - - - if (update_arg( (void *)&(args_info->thread_arg), - &(args_info->thread_orig), &(args_info->thread_given), - &(local_args_info.thread_given), optarg, 0, 0, ARG_INT, - check_ambiguity, override, 0, 0, - "thread", '-', - additional_error)) - goto failure; - - } - /* Number of pixels of each coordonate. */ - else if (strcmp (long_options[option_index].name, "size") == 0) - { - - if (update_multiple_arg_temp(&size_list, - &(local_args_info.size_given), optarg, 0, "0", ARG_INT, - "size", '-', - additional_error)) - goto failure; - - } - /* Spacing in mm between pixels. */ - else if (strcmp (long_options[option_index].name, "spacing") == 0) - { - - if (update_multiple_arg_temp(&spacing_list, - &(local_args_info.spacing_given), optarg, 0, "-1.0", ARG_FLOAT, - "spacing", '-', - additional_error)) - goto failure; - - } - /* Interpolation type: {nn, linear, bspline, blut}. */ - else if (strcmp (long_options[option_index].name, "interp") == 0) - { - - - if (update_arg( (void *)&(args_info->interp_arg), - &(args_info->interp_orig), &(args_info->interp_given), - &(local_args_info.interp_given), optarg, 0, "nn", ARG_STRING, - check_ambiguity, override, 0, 0, - "interp", '-', - additional_error)) - goto failure; - - } - - break; - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - update_multiple_arg((void *)&(args_info->size_arg), - &(args_info->size_orig), args_info->size_given, - local_args_info.size_given, 0 , - ARG_INT, size_list); - multiple_default_value.float_arg = -1.0; - update_multiple_arg((void *)&(args_info->spacing_arg), - &(args_info->spacing_orig), args_info->spacing_given, - local_args_info.spacing_given, &multiple_default_value , - ARG_FLOAT, spacing_list); - multiple_default_value.float_arg = 0.0; - update_multiple_arg((void *)&(args_info->gauss_arg), - &(args_info->gauss_orig), args_info->gauss_given, - local_args_info.gauss_given, &multiple_default_value , - ARG_FLOAT, gauss_list); - - args_info->size_given += local_args_info.size_given; - local_args_info.size_given = 0; - args_info->spacing_given += local_args_info.spacing_given; - local_args_info.spacing_given = 0; - args_info->gauss_given += local_args_info.gauss_given; - local_args_info.gauss_given = 0; - - if (check_required) - { - error += cmdline_parser_clitkResampleImage_required2 (args_info, argv[0], additional_error); - } - - cmdline_parser_clitkResampleImage_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; - } - - return 0; - -failure: - free_list (size_list, 0 ); - free_list (spacing_list, 0 ); - free_list (gauss_list, 0 ); - - cmdline_parser_clitkResampleImage_release (&local_args_info); - return (EXIT_FAILURE); -} - -#ifndef CONFIG_FILE_LINE_SIZE -#define CONFIG_FILE_LINE_SIZE 2048 -#endif -#define ADDITIONAL_ERROR " in configuration file " - -#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) -/* 3 is for "--" and "=" */ - -static int -_cmdline_parser_clitkResampleImage_configfile (char * const filename, int *my_argc) -{ - FILE* file; - char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1]; - char linebuf[CONFIG_FILE_LINE_SIZE]; - int line_num = 0; - int result = 0, equal; - char *fopt, *farg; - char *str_index; - size_t len, next_token; - char delimiter; - - if ((file = fopen(filename, "r")) == NULL) - { - fprintf (stderr, "%s: Error opening configuration file '%s'\n", - CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename); - return EXIT_FAILURE; - } - - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) - { - ++line_num; - my_argv[0] = '\0'; - len = strlen(linebuf); - if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1)) - { - fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n", - CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - - /* find first non-whitespace character in the line */ - next_token = strspn (linebuf, " \t\r\n"); - str_index = linebuf + next_token; - - if ( str_index[0] == '\0' || str_index[0] == '#') - continue; /* empty line or comment line is skipped */ - - fopt = str_index; - - /* truncate fopt at the end of the first non-valid character */ - next_token = strcspn (fopt, " \t\r\n="); - - if (fopt[next_token] == '\0') /* the line is over */ - { - farg = NULL; - equal = 0; - goto noarg; - } - - /* remember if equal sign is present */ - equal = (fopt[next_token] == '='); - fopt[next_token++] = '\0'; - - /* advance pointers to the next token after the end of fopt */ - next_token += strspn (fopt + next_token, " \t\r\n"); - - /* check for the presence of equal sign, and if so, skip it */ - if ( !equal ) - if ((equal = (fopt[next_token] == '='))) - { - next_token++; - next_token += strspn (fopt + next_token, " \t\r\n"); - } - str_index += next_token; - - /* find argument */ - farg = str_index; - if ( farg[0] == '\"' || farg[0] == '\'' ) - { /* quoted argument */ - str_index = strchr (++farg, str_index[0] ); /* skip opening quote */ - if (! str_index) - { - fprintf - (stderr, - "%s:%s:%d: unterminated string in configuration file\n", - CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - else - { /* read up the remaining part up to a delimiter */ - next_token = strcspn (farg, " \t\r\n#\'\""); - str_index += next_token; - } - - /* truncate farg at the delimiter and store it for further check */ - delimiter = *str_index, *str_index++ = '\0'; - - /* everything but comment is illegal at the end of line */ - if (delimiter != '\0' && delimiter != '#') - { - str_index += strspn(str_index, " \t\r\n"); - if (*str_index != '\0' && *str_index != '#') - { - fprintf - (stderr, - "%s:%s:%d: malformed string in configuration file\n", - CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename, line_num); - result = EXIT_FAILURE; - break; - } - } - - noarg: - if (!strcmp(fopt,"include")) { - if (farg && *farg) { - result = _cmdline_parser_clitkResampleImage_configfile(farg, my_argc); - } else { - fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n", - CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename, line_num); - } - continue; - } - len = strlen(fopt); - strcat (my_argv, len > 1 ? "--" : "-"); - strcat (my_argv, fopt); - if (len > 1 && ((farg && *farg) || equal)) - strcat (my_argv, "="); - if (farg && *farg) - strcat (my_argv, farg); - ++(*my_argc); - - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(my_argv); - } /* while */ - - if (file) - fclose(file); - return result; -} - -int -cmdline_parser_clitkResampleImage_configfile (char * const filename, - struct args_info_clitkResampleImage *args_info, - int override, int initialize, int check_required) -{ - struct cmdline_parser_clitkResampleImage_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - return cmdline_parser_clitkResampleImage_config_file (filename, args_info, ¶ms); -} - -int -cmdline_parser_clitkResampleImage_config_file (char * const filename, - struct args_info_clitkResampleImage *args_info, - struct cmdline_parser_clitkResampleImage_params *params) -{ - int i, result; - int my_argc = 1; - char **my_argv_arg; - char *additional_error; - - /* store the program name */ - cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE); - - result = _cmdline_parser_clitkResampleImage_configfile(filename, &my_argc); - - if (result != EXIT_FAILURE) { - my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - - my_argv_arg[my_argc] = 0; - - additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy (additional_error, ADDITIONAL_ERROR); - strcat (additional_error, filename); - result = - cmdline_parser_clitkResampleImage_internal (my_argc, my_argv_arg, args_info, - params, - additional_error); - - free (additional_error); - free (my_argv_arg); - } - - free_cmd_list(); - if (result == EXIT_FAILURE) - { - cmdline_parser_clitkResampleImage_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} diff --git a/vv/tools_ggo/clitkResampleImage_ggo.h b/vv/tools_ggo/clitkResampleImage_ggo.h deleted file mode 100644 index 9d59e20..0000000 --- a/vv/tools_ggo/clitkResampleImage_ggo.h +++ /dev/null @@ -1,259 +0,0 @@ -/** @file clitkResampleImage_ggo.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef CLITKRESAMPLEIMAGE_GGO_H -#define CLITKRESAMPLEIMAGE_GGO_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE -/** @brief the program name */ -#define CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE "clitkResampleImage" -#endif - -#ifndef CMDLINE_PARSER_CLITKRESAMPLEIMAGE_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_CLITKRESAMPLEIMAGE_VERSION "2.0" -#endif - -/** @brief Where the command line options are stored */ -struct args_info_clitkResampleImage -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - char * config_arg; /**< @brief Config file. */ - char * config_orig; /**< @brief Config file original value given at command line. */ - const char *config_help; /**< @brief Config file help description. */ - int verbose_flag; /**< @brief Verbose (default=off). */ - const char *verbose_help; /**< @brief Verbose help description. */ - int imagetypes_flag; /**< @brief Verbose: allowed image types (default=off). */ - const char *imagetypes_help; /**< @brief Verbose: allowed image types help description. */ - int thread_arg; /**< @brief Nb of thread to use (default=max). */ - char * thread_orig; /**< @brief Nb of thread to use (default=max) original value given at command line. */ - const char *thread_help; /**< @brief Nb of thread to use (default=max) help description. */ - char * input_arg; /**< @brief Input image filename. */ - char * input_orig; /**< @brief Input image filename original value given at command line. */ - const char *input_help; /**< @brief Input image filename help description. */ - char * output_arg; /**< @brief Output image filename. */ - char * output_orig; /**< @brief Output image filename original value given at command line. */ - const char *output_help; /**< @brief Output image filename help description. */ - char * like_arg; /**< @brief Resample like this image. */ - char * like_orig; /**< @brief Resample like this image original value given at command line. */ - const char *like_help; /**< @brief Resample like this image help description. */ - int* size_arg; /**< @brief Number of pixels of each coordonate (default='0'). */ - char ** size_orig; /**< @brief Number of pixels of each coordonate original value given at command line. */ - int size_min; /**< @brief Number of pixels of each coordonate's minimum occurreces */ - int size_max; /**< @brief Number of pixels of each coordonate's maximum occurreces */ - const char *size_help; /**< @brief Number of pixels of each coordonate help description. */ - float* spacing_arg; /**< @brief Spacing in mm between pixels (default='-1.0'). */ - char ** spacing_orig; /**< @brief Spacing in mm between pixels original value given at command line. */ - int spacing_min; /**< @brief Spacing in mm between pixels's minimum occurreces */ - int spacing_max; /**< @brief Spacing in mm between pixels's maximum occurreces */ - const char *spacing_help; /**< @brief Spacing in mm between pixels help description. */ - float default_arg; /**< @brief Default pixel value (default='0.0'). */ - char * default_orig; /**< @brief Default pixel value original value given at command line. */ - const char *default_help; /**< @brief Default pixel value help description. */ - int time_flag; /**< @brief Last Dimension Is Time -> do not resample it (auto on for 4D) (default=off). */ - const char *time_help; /**< @brief Last Dimension Is Time -> do not resample it (auto on for 4D) help description. */ - char * interp_arg; /**< @brief Interpolation type: {nn, linear, bspline, blut} (default='nn'). */ - char * interp_orig; /**< @brief Interpolation type: {nn, linear, bspline, blut} original value given at command line. */ - const char *interp_help; /**< @brief Interpolation type: {nn, linear, bspline, blut} help description. */ - int order_arg; /**< @brief BSpline ordre (range 0-5) (default='3'). */ - char * order_orig; /**< @brief BSpline ordre (range 0-5) original value given at command line. */ - const char *order_help; /**< @brief BSpline ordre (range 0-5) help description. */ - int sampling_arg; /**< @brief BLUT sampling value (default='30'). */ - char * sampling_orig; /**< @brief BLUT sampling value original value given at command line. */ - const char *sampling_help; /**< @brief BLUT sampling value help description. */ - float* gauss_arg; /**< @brief Apply Gaussian before (sigma in mm) (default='0.0'). */ - char ** gauss_orig; /**< @brief Apply Gaussian before (sigma in mm) original value given at command line. */ - int gauss_min; /**< @brief Apply Gaussian before (sigma in mm)'s minimum occurreces */ - int gauss_max; /**< @brief Apply Gaussian before (sigma in mm)'s maximum occurreces */ - const char *gauss_help; /**< @brief Apply Gaussian before (sigma in mm) help description. */ - int autogauss_flag; /**< @brief Apply Gaussian with auto sigma when downsample (default=off). */ - const char *autogauss_help; /**< @brief Apply Gaussian with auto sigma when downsample help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int config_given ; /**< @brief Whether config was given. */ - unsigned int verbose_given ; /**< @brief Whether verbose was given. */ - unsigned int imagetypes_given ; /**< @brief Whether imagetypes was given. */ - unsigned int thread_given ; /**< @brief Whether thread was given. */ - unsigned int input_given ; /**< @brief Whether input was given. */ - unsigned int output_given ; /**< @brief Whether output was given. */ - unsigned int like_given ; /**< @brief Whether like was given. */ - unsigned int size_given ; /**< @brief Whether size was given. */ - unsigned int spacing_given ; /**< @brief Whether spacing was given. */ - unsigned int default_given ; /**< @brief Whether default was given. */ - unsigned int time_given ; /**< @brief Whether time was given. */ - unsigned int interp_given ; /**< @brief Whether interp was given. */ - unsigned int order_given ; /**< @brief Whether order was given. */ - unsigned int sampling_given ; /**< @brief Whether sampling was given. */ - unsigned int gauss_given ; /**< @brief Whether gauss was given. */ - unsigned int autogauss_given ; /**< @brief Whether autogauss was given. */ - - char **inputs ; /**< @brief unamed options (options without names) */ - unsigned inputs_num ; /**< @brief unamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_clitkResampleImage_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure args_info_clitkResampleImage (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure args_info_clitkResampleImage (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *args_info_clitkResampleImage_purpose; -/** @brief the usage string of the program */ -extern const char *args_info_clitkResampleImage_usage; -/** @brief all the lines making the help output */ -extern const char *args_info_clitkResampleImage_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkResampleImage (int argc, char * const *argv, - struct args_info_clitkResampleImage *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkResampleImage_ext() instead - */ -int cmdline_parser_clitkResampleImage2 (int argc, char * const *argv, - struct args_info_clitkResampleImage *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkResampleImage_ext (int argc, char * const *argv, - struct args_info_clitkResampleImage *args_info, - struct cmdline_parser_clitkResampleImage_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkResampleImage_dump(FILE *outfile, - struct args_info_clitkResampleImage *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkResampleImage_file_save(const char *filename, - struct args_info_clitkResampleImage *args_info); - -/** - * Print the help - */ -void cmdline_parser_clitkResampleImage_print_help(void); -/** - * Print the version - */ -void cmdline_parser_clitkResampleImage_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_clitkResampleImage_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_clitkResampleImage_params_init(struct cmdline_parser_clitkResampleImage_params *params); - -/** - * Allocates dynamically a cmdline_parser_clitkResampleImage_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_clitkResampleImage_params structure - */ -struct cmdline_parser_clitkResampleImage_params *cmdline_parser_clitkResampleImage_params_create(void); - -/** - * Initializes the passed args_info_clitkResampleImage structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_clitkResampleImage_init (struct args_info_clitkResampleImage *args_info); -/** - * Deallocates the string fields of the args_info_clitkResampleImage structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_clitkResampleImage_free (struct args_info_clitkResampleImage *args_info); - -/** - * The config file parser (deprecated version) - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_clitkResampleImage_config_file() instead - */ -int cmdline_parser_clitkResampleImage_configfile (char * const filename, - struct args_info_clitkResampleImage *args_info, - int override, int initialize, int check_required); - -/** - * The config file parser - * @param filename the name of the config file - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_clitkResampleImage_config_file (char * const filename, - struct args_info_clitkResampleImage *args_info, - struct cmdline_parser_clitkResampleImage_params *params); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_clitkResampleImage_required (struct args_info_clitkResampleImage *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* CLITKRESAMPLEIMAGE_GGO_H */ diff --git a/vv/tools_ggo/vvToolsList.h b/vv/tools_ggo/vvToolsList.h deleted file mode 100644 index f8df574..0000000 --- a/vv/tools_ggo/vvToolsList.h +++ /dev/null @@ -1,44 +0,0 @@ -#include "vvToolMedianFilter.h" -extern const vvToolCreator *dummyvvToolMedianFilter; -const vvToolCreator *dummyvvToolMedianFilter2 = dummyvvToolMedianFilter; - -#include "vvToolRigidReg.h" -extern const vvToolCreator *dummyvvToolRigidReg; -const vvToolCreator *dummyvvToolRigidReg2 = dummyvvToolRigidReg; - -#include "vvToolCropImage.h" -extern const vvToolCreator *dummyvvToolCropImage; -const vvToolCreator *dummyvvToolCropImage2 = dummyvvToolCropImage; - -#include "vvToolBinarize.h" -extern const vvToolCreator *dummyvvToolBinarize; -const vvToolCreator *dummyvvToolBinarize2 = dummyvvToolBinarize; - -#include "vvToolImageArithm.h" -extern const vvToolCreator *dummyvvToolImageArithm; -const vvToolCreator *dummyvvToolImageArithm2 = dummyvvToolImageArithm; - -#include "vvToolResample.h" -extern const vvToolCreator *dummyvvToolResample; -const vvToolCreator *dummyvvToolResample2 = dummyvvToolResample; - -#include "vvToolMIP.h" -extern const vvToolCreator *dummyvvToolMIP; -const vvToolCreator *dummyvvToolMIP2 = dummyvvToolMIP; - -#include "vvToolConvert.h" -extern const vvToolCreator *dummyvvToolConvert; -const vvToolCreator *dummyvvToolConvert2 = dummyvvToolConvert; - -#include "vvToolROIManager.h" -extern const vvToolCreator *dummyvvToolROIManager; -const vvToolCreator *dummyvvToolROIManager2 = dummyvvToolROIManager; - -#include "vvToolSegmentation.h" -extern const vvToolCreator *dummyvvToolSegmentation; -const vvToolCreator *dummyvvToolSegmentation2 = dummyvvToolSegmentation; - -#include "vvToolProfile.h" -extern const vvToolCreator *dummyvvToolProfile; -const vvToolCreator *dummyvvToolProfile2 = dummyvvToolProfile; - diff --git a/vv/vv.pro b/vv/vv.pro deleted file mode 100644 index 0f6b263..0000000 --- a/vv/vv.pro +++ /dev/null @@ -1,483 +0,0 @@ -TEMPLATE = app -CONFIG += qt static -QT += core gui widgets network dbus -QTPLUGIN.platforms = qxcb - -INCLUDEPATH += ../common/ tools_ggo ../tools/ ../itk/ ../segmentation ../registrtion $$PWD /usr/local/include/ITK-4.9/ /usr/local/include/vtk-6.3/ /usr/local/lib/vtk-6.3/ /home/tbaudier/vv/vv_static/ITK/ITK_bin/lib/ /home/tbaudier/vv/vv_static/Qt/lib/ - -HEADERS = vvMainWindowBase.h \ - QTreePushButton.h \ - vvDocumentation.h \ - vvHelpDialog.h \ - vvQDicomSeriesSelector.h \ - vvSlicerManager.h \ - vvSlicer.h \ - vvStructureSetActor.h \ - vvROIActor.h \ - vvToolCreatorBase.h \ - vvToolMedianFilter.h \ - vvToolRigidReg.h \ - vvToolCropImage.h \ - vvToolBinarize.h \ - vvToolImageArithm.h \ - vvToolResample.h \ - vvToolMIP.h \ - vvToolConvert.h \ - vvToolROIManager.h \ - vvToolSegmentation.h \ - vvToolProfile.h \ - vvInfoPanel.h \ - vvMainWindow.h \ - vvLinkPanel.h \ - vvOverlayPanel.h \ - vvLandmarksPanel.h \ - vvProgressDialog.h \ - vvSegmentationDialog.h \ - vvSurfaceViewerDialog.h \ - vvDeformationDialog.h \ - vvStructSelector.h \ - vvIntensityValueSlider.h \ - vvLabelImageLoaderWidget.h \ - vvToolWidgetBase.h \ - vvToolSimpleInputSelectorWidget.h \ - vvToolInputSelectorWidget.h \ - vvRegisterForm.h \ - vvConfiguration.h \ - ../common/clitkCommon.h \ - ../common/clitkConfiguration.h \ - ../common/clitkListOfPair.h \ - ../common/clitkTimer.h\ - ../common/clitkImageCommon.h \ - ../common/clitkTransformUtilities.h \ - ../common/clitkIO.h \ - ../common/clitkGateAsciiImageIO.h \ - ../common/clitkGateAsciiImageIOFactory.h \ - ../common/clitkVoxImageIO.h \ - ../common/clitkVoxImageIOFactory.h \ - ../common/clitkVfImageIO.h \ - ../common/clitkVfImageIOFactory.h \ - ../common/clitkXdrImageIOFactory.h \ - ../common/rtkHisImageIO.h \ - ../common/rtkHisImageIOFactory.h \ - ../common/rtkHndImageIO.h \ - ../common/rtkHndImageIOFactory.h \ - ../common/rtkEdfImageIO.h \ - ../common/rtkEdfImageIOFactory.h \ - ../common/rtkXRadImageIO.h \ - ../common/rtkXRadImageIOFactory.h \ - ../common/rtkImagXImageIO.h \ - ../common/rtkImagXImageIOFactory.h \ - ../common/rtkImagXXMLFileReader.h \ - ../common/clitkEsrfHstImageIO.h \ - ../common/clitkEsrfHstImageIOFactory.h \ - ../common/clitkEsrfHstXMLFileReader.h \ - ../common/clitkDicomRTDoseIO.h \ - ../common/clitkDicomRTDoseIOFactory.h \ - ../common/clitkOrientation.h \ - ../common/clitkImageToImageGenericFilterBase.h \ - ../common/clitkExceptionObject.h \ - ../common/clitkFilterBase.h \ - ../common/clitkMemoryUsage.h \ - ../common/clitkMatrix.h \ - ../common/vvImage.h \ - ../common/vvImageReader.h \ - ../common/vvImageWriter.h \ - ../common/clitkDicomRTStruct2ImageFilter.h \ - ../common/clitkDicomRT_ROI.h \ - ../common/clitkDicomRT_StructureSet.h \ - ../tools/clitkProfileImageGenericFilter.h \ - ../tools/clitkMedianImageGenericFilter.h \ - ../tools/clitkCropImageGenericFilter.h \ - ../tools/clitkBinarizeImageGenericFilter.h \ - ../tools/clitkResampleImageGenericFilter.h \ - ../tools/clitkMIPGenericFilter.h \ - ../tools/clitkImageArithmGenericFilter.h \ - ../tools/clitkImageConvertGenericFilter.h \ - ../itk/clitkCropLikeImageFilter.h \ - ../segmentation/clitkRegionGrowingGenericFilter.h \ - ../segmentation/clitkConnectedComponentLabelingGenericFilter.h \ - tools_ggo/clitkMedianImageFilter_ggo.h \ - tools_ggo/clitkCropImage_ggo.h \ - tools_ggo/clitkBinarizeImage_ggo.h \ - tools_ggo/clitkResampleImage_ggo.h \ - tools_ggo/clitkMIP_ggo.h \ - tools_ggo/clitkImageArithm_ggo.h\ - tools_ggo/clitkRegionGrowing_ggo.h \ - tools_ggo/clitkProfileImage_ggo.h \ - tools_ggo/vvToolsList.h \ - tools_ggo/clitkConnectedComponentLabeling_ggo.h - -FORMS = qt_ui/vvHelpDialog.ui \ - qt_ui/vvDocumentation.ui \ - qt_ui/vvDicomSeriesSelector.ui \ - qt_ui/vvDummyWindow.ui \ - qt_ui/vvToolMedianFilter.ui \ - qt_ui/vvToolRigidReg.ui \ - qt_ui/vvToolCropImage.ui \ - qt_ui/vvToolBinarize.ui \ - qt_ui/vvToolImageArithm.ui \ - qt_ui/vvToolResample.ui \ - qt_ui/vvToolMIP.ui \ - qt_ui/vvToolConvert.ui \ - qt_ui/vvToolROIManager.ui \ - qt_ui/vvToolSegmentation.ui \ - qt_ui/vvToolProfile.ui \ - qt_ui/vvInfoPanel.ui \ - qt_ui/vvMainWindow.ui \ - qt_ui/vvLinkPanel.ui \ - qt_ui/vvOverlayPanel.ui \ - qt_ui/vvLandmarksPanel.ui \ - qt_ui/vvProgressDialog.ui \ - qt_ui/vvSegmentationDialog.ui \ - qt_ui/vvSurfaceViewerDialog.ui \ - qt_ui/vvDeformationDialog.ui \ - qt_ui/vvStructSelector.ui \ - qt_ui/vvIntensityValueSlider.ui \ - qt_ui/vvLabelImageLoaderWidget.ui \ - qt_ui/vvToolWidgetBase.ui \ - qt_ui/vvToolSimpleInputSelectorWidget.ui \ - qt_ui/vvToolInputSelectorWidget.ui \ - qt_ui/vvRegisterForm.ui - -SOURCES = vv.cxx \ - vvToolMedianFilter.cxx \ - vvToolRigidReg.cxx \ - vvToolCropImage.cxx \ - vvToolBinarize.cxx \ - vvToolImageArithm.cxx \ - vvToolResample.cxx \ - vvToolMIP.cxx \ - vvToolConvert.cxx \ - vvToolROIManager.cxx \ - vvToolSegmentation.cxx \ - vvToolProfile.cxx \ - vvInfoPanel.cxx \ - vvMainWindow.cxx \ - vvLinkPanel.cxx \ - vvOverlayPanel.cxx \ - vvLandmarksPanel.cxx \ - vvProgressDialog.cxx \ - vvSegmentationDialog.cxx \ - vvSurfaceViewerDialog.cxx \ - vvDeformationDialog.cxx \ - vvStructSelector.cxx \ - vvIntensityValueSlider.cxx \ - vvLabelImageLoaderWidget.cxx \ - vvToolWidgetBase.cxx \ - vvToolSimpleInputSelectorWidget.cxx \ - vvToolInputSelectorWidget.cxx \ - vvRegisterForm.cxx \ - vvQProgressDialogITKCommand.cxx \ - vvQDicomSeriesSelector.cxx \ - QTreePushButton.cxx \ - vvMainWindowBase.cxx \ - vvImageWarp.cxx \ - vvDeformableRegistration.cxx \ - vtkVOXImageWriter.cxx \ - vvInteractorStyleNavigator.cxx \ - vvSlicer.cxx \ - vvLandmarks.cxx \ - vvLandmarksGlyph.cxx \ - vvClipPolyData.cxx \ - vvGlyphSource.cxx \ - vvGlyph2D.cxx \ - vvSlicerManager.cxx \ - vvSlicerManagerCommand.cxx \ - vvUtils.cxx \ - vvMesh.cxx \ - vvMeshActor.cxx \ - vvMeshReader.cxx \ - vvMidPosition.cxx \ - vvImageContour.cxx \ - vvBinaryImageOverlayActor.cxx \ - vvStructureSetActor.cxx \ - vvSaveState.cxx \ - vvReadState.cxx \ - vvROIActor.cxx \ - vvBlendImageActor.cxx \ - vvToolManager.cxx \ - vvToolCreatorBase.cxx \ - vvToolBaseBase.cxx \ - ../common/clitkCommon.cxx \ - ../common/clitkListOfPair.cxx \ - ../common/clitkTimer.cxx \ - ../common/clitkImageCommon.cxx \ - ../common/clitkTransformUtilities.cxx \ - ../common/clitkIO.cxx \ - ../common/clitkGateAsciiImageIO.cxx \ - ../common/clitkGateAsciiImageIOFactory.cxx \ - ../common/clitkVoxImageIO.cxx \ - ../common/clitkVoxImageIOFactory.cxx \ - ../common/clitkVfImageIO.cxx \ - ../common/clitkVfImageIOFactory.cxx \ - ../common/clitkXdrImageIOReader.cxx \ - ../common/clitkXdrImageIOWriter.cxx \ - ../common/clitkXdrImageIOFactory.cxx \ - ../common/rtkHisImageIO.cxx \ - ../common/rtkHisImageIOFactory.cxx \ - ../common/rtkHndImageIO.cxx \ - ../common/rtkHndImageIOFactory.cxx \ - ../common/rtkEdfImageIO.cxx \ - ../common/rtkEdfImageIOFactory.cxx \ - ../common/rtkXRadImageIO.cxx \ - ../common/rtkXRadImageIOFactory.cxx \ - ../common/rtkImagXImageIO.cxx \ - ../common/rtkImagXImageIOFactory.cxx \ - ../common/rtkImagXXMLFileReader.cxx \ - ../common/clitkEsrfHstImageIO.cxx \ - ../common/clitkEsrfHstImageIOFactory.cxx \ - ../common/clitkEsrfHstXMLFileReader.cxx \ - ../common/clitkDicomRTDoseIO.cxx \ - ../common/clitkDicomRTDoseIOFactory.cxx \ - ../common/clitkOrientation.cxx \ - ../common/clitkImageToImageGenericFilterBase.cxx \ - ../common/clitkExceptionObject.cxx \ - ../common/clitkFilterBase.cxx \ - ../common/clitkMemoryUsage.cxx \ - ../common/clitkMatrix.cxx \ - ../common/vvImage.cxx \ - ../common/vvImageReader.cxx \ - ../common/vvImageWriter.cxx \ - ../common/clitkDicomRTStruct2ImageFilter.cxx \ - ../common/clitkDicomRT_ROI.cxx \ - ../common/clitkDicomRT_StructureSet.cxx \ - ../common/clitkDicomRT_Contour.cxx \ - ../tools/clitkProfileImageGenericFilter.cxx \ - ../tools/clitkMedianImageGenericFilter.cxx \ - ../tools/clitkCropImageGenericFilter.cxx \ - ../tools/clitkBinarizeImageGenericFilter.cxx \ - ../tools/clitkResampleImageGenericFilter.cxx \ - ../tools/clitkMIPGenericFilter.cxx \ - ../tools/clitkImageArithmGenericFilter.cxx \ - ../tools/clitkImageConvertGenericFilter.cxx \ - ../itk/clitkCropLikeImageFilter.txx \ - ../segmentation/clitkRegionGrowingGenericFilter.txx \ - ../segmentation/clitkConnectedComponentLabelingGenericFilter.txx \ - tools_ggo/clitkMedianImageFilter_ggo.c \ - tools_ggo/clitkCropImage_ggo.c \ - tools_ggo/clitkBinarizeImage_ggo.c\ - tools_ggo/clitkResampleImage_ggo.c \ - tools_ggo/clitkMIP_ggo.c \ - tools_ggo/clitkImageArithm_ggo.c \ - tools_ggo/clitkRegionGrowing_ggo.c \ - tools_ggo/clitkProfileImage_ggo.c \ - tools_ggo/clitkConnectedComponentLabeling_ggo.c - -RESOURCES = vvIcons.qrc - -# add missing libraries -LIBS += -static-libgcc \ - -static-libstdc++ \ - -lz \ - -lglib-2.0 \ - -L/home/tbaudier/vv/vv_static/ITK/ITK_bin/lib/ \ - -L/home/tbaudier/vv/vv_static/VTK/VTK_bin/lib/ \ - -lvtkInteractionImage-6.3 \ - -lvtkInteractionStyle-6.3 \ - -lvtkViewsContext2D-6.3 \ - -lvtkViewsCore-6.3 \ - -lvtkFiltersGeneral-6.3 \ - -lvtkViewsQt-6.3 \ - -lvtkRenderingContextOpenGL-6.3 \ - -lvtkRenderingAnnotation-6.3 \ - -lvtkRenderingFreeType-6.3 \ - -lvtkRenderingQt-6.3 \ - -lvtkGUISupportQtSQL-6.3 \ - -lvtkGUISupportQtOpenGL-6.3 \ - -lvtkChartsCore-6.3 \ - -lvtkRenderingOpenGL-6.3 \ - -lvtkRenderingCore-6.3 \ - -lvtksys-6.3 \ - -lvtkmetaio-6.3 \ - -lvtkIOLegacy-6.3 \ - -lvtkIOImage-6.3 \ - -lvtkexpat-6.3 \ - -lvtkGeovisCore-6.3 \ - -lvtkFiltersExtraction-6.3 \ - -lvtkFiltersSMP-6.3 \ - -lvtkFiltersProgrammable-6.3 \ - -lvtkFiltersTexture-6.3 \ - -lvtkFiltersHybrid-6.3 \ - -lvtkFiltersCore-6.3 \ - -lvtkImagingMath-6.3 \ - -lvtkCommonExecutionModel-6.3 \ - -lvtkImagingStatistics-6.3 \ - -lvtkRenderingGL2PS-6.3 \ - -lvtkRenderingContext2D-6.3 \ - -lvtkIOSQL-6.3 \ - -lvtkImagingStencil-6.3 \ - -lvtkImagingCore-6.3 \ - -lvtkverdict-6.3 \ - -lvtkInfovisLayout-6.3 \ - -lvtkCommonDataModel-6.3 \ - -lvtktiff-6.3 \ - -lvtkzlib-6.3 \ - -lvtkproj4-6.3 \ - -lvtkNetCDF_cxx-6.3 \ - -lvtkRenderingLOD-6.3 \ - -lvtkhdf5_hl-6.3 \ - -lvtkCommonTransforms-6.3 \ - -lvtkCommonCore-6.3 \ - -lvtkjpeg-6.3 \ - -lvtkFiltersStatistics-6.3 \ - -lvtklibxml2-6.3 \ - -lvtkIOXML-6.3 \ - -lvtkFiltersHyperTree-6.3 \ - -lvtkIOLSDyna-6.3 \ - -lvtkIOXMLParser-6.3 \ - -lvtkImagingMorphological-6.3 \ - -lvtkCommonComputationalGeometry-6.3 \ - -lvtkCommonSystem-6.3 \ - -lvtkCommonMisc-6.3 \ - -lvtkIOImport-6.3 \ - -lvtkInfovisCore-6.3 \ - -lvtkhdf5-6.3 \ - -lvtkexoIIc-6.3 \ - -lvtkIOParallelXML-6.3 \ - -lvtkIOMovie-6.3 \ - -lvtkImagingFourier-6.3 \ - -lvtkgl2ps-6.3 \ - -lvtkRenderingVolumeOpenGL-6.3 \ - -lvtkpng-6.3 \ - -lvtkalglib-6.3 \ - -lvtkFiltersParallel-6.3 \ - -lvtkCommonMath-6.3 \ - -lvtkFiltersImaging-6.3 \ - -lvtksqlite-6.3 \ - -lvtkParallelCore-6.3 \ - -lvtkIOExodus-6.3 \ - -lvtkRenderingLabel-6.3 \ - -lvtkIOExport-6.3 \ - -lvtkIOGeometry-6.3 \ - -lvtkjsoncpp-6.3 \ - -lvtkImagingHybrid-6.3 \ - -lvtkFiltersSources-6.3 \ - -lvtkRenderingImage-6.3 \ - -lvtkDomainsChemistry-6.3 \ - -lvtkIOMINC-6.3 \ - -lvtkoggtheora-6.3 \ - -lvtkIOCore-6.3 \ - -lvtkDICOMParser-6.3 \ - -lvtkCommonColor-6.3 \ - -lvtkRenderingLIC-6.3 \ - -lvtkImagingSources-6.3 \ - -lvtkViewsInfovis-6.3 \ - -lvtkNetCDF-6.3 \ - -lvtkFiltersGeometry-6.3 \ - -lvtkFiltersGeneric-6.3 \ - -lvtkRenderingVolume-6.3 \ - -lvtkIONetCDF-6.3 \ - -lvtksys-6.3 \ - -lvtkIOPLY-6.3 \ - -lvtkftgl-6.3 \ - -lvtkfreetype-6.3 \ - -lvtkImagingGeneral-6.3 \ - -lvtkFiltersParallelImaging-6.3 \ - -lvtkIOAMR-6.3 \ - -lvtkFiltersFlowPaths-6.3 \ - -lvtkImagingColor-6.3 \ - -lvtkFiltersAMR-6.3 \ - -lvtkInteractionWidgets-6.3 \ - -lvtkIOInfovis-6.3 \ - -lvtkFiltersVerdict-6.3 \ - -lvtkFiltersSelection-6.3 \ - -lvtkIOParallel-6.3 \ - -lvtkIOEnSight-6.3 \ - -lvtkFiltersModeling-6.3 \ - -lvtkIOVideo-6.3 \ - -lvtkGUISupportQt-6.3 \ - -litktestlib-4.9 \ - -lITKIOMeta-4.9 \ - -lITKIOGDCM-4.9 \ - -lITKCommon-4.9 \ - -lITKPolynomials-4.9 \ - -lITKOptimizers-4.9 \ - -lITKVNLInstantiation-4.9 \ - -lITKNrrdIO-4.9 \ - -litkhdf5_cpp-4.9 \ - -lITKIOCSV-4.9 \ - -lITKLabelMap-4.9 \ - -lITKIOGIPL-4.9 \ - -lITKIOPNG-4.9 \ - -lITKIOMRC-4.9 \ - -lITKBioCell-4.9 \ - -lITKIOTransformInsightLegacy-4.9 \ - -lITKIONIFTI-4.9 \ - -lITKVTK-4.9 \ - -lITKPath-4.9 \ - -lITKIONRRD-4.9 \ - -litkdouble-conversion-4.9 \ - -lITKKLMRegionGrowing-4.9 \ - -lITKIOTIFF-4.9 \ - -lITKMesh-4.9 \ - -lITKIOIPL-4.9 \ - -lITKOptimizersv4-4.9 \ - -lITKReview-4.9 \ - -lITKniftiio-4.9 \ - -lITKIOJPEG-4.9 \ - -lITKIOTransformBase-4.9 \ - -lITKgiftiio-4.9 \ - -lITKznz-4.9 \ - -lITKIOLSM-4.9 \ - -lITKSpatialObjects-4.9 \ - -lITKWatersheds-4.9 \ - -lITKStatistics-4.9 \ - -lITKIOBMP-4.9 \ - -lITKIOSpatialObjects-4.9 \ - -litkvnl_algo-4.9 \ - -lITKIOVTK-4.9 \ - -litkopenjpeg-4.9 \ - -lITKIOGE-4.9 \ - -lITKBiasCorrection-4.9 \ - -litkv3p_lsqr-4.9 \ - -lITKTransform-4.9 \ - -litkzlib-4.9 \ - -lITKIOStimulate-4.9 \ - -lITKIOMesh-4.9 \ - -litkv3p_netlib-4.9 \ - -lITKVideoIO-4.9 \ - -lITKIOTransformHDF5-4.9 \ - -lITKDICOMParser-4.9 \ - -lITKIOImageBase-4.9 \ - -litkjpeg-4.9 \ - -lITKIOXML-4.9 \ - -litkNetlibSlatec-4.9 \ - -lITKIOBioRad-4.9 \ - -lITKIOTransformMatlab-4.9 \ - -litkvcl-4.9 \ - -litktiff-4.9 \ - -litkpng-4.9 \ - -lITKFEM-4.9 \ - -lITKVideoCore-4.9 \ - -lITKMetaIO-4.9 \ - -litkhdf5-4.9 \ - -lITKQuadEdgeMesh-4.9 \ - -lITKIOHDF5-4.9 \ - -lITKVtkGlue-4.9 \ - -lITKIOSiemens-4.9 \ - -litkvnl-4.9 \ - -lITKEXPAT-4.9 \ - -litksys-4.9 \ - -litkgdcmMSFF-4.9 \ - -litkgdcmopenjpeg-4.9 \ - -litkgdcmjpeg16-4.9 \ - -litkgdcmDICT-4.9 \ - -litkgdcmjpeg12-4.9 \ - -litkgdcmsocketxx-4.9 \ - -litkgdcmuuid-4.9 \ - -litkgdcmcharls-4.9 \ - -litkgdcmDSED-4.9 \ - -litkgdcmjpeg8-4.9 \ - -litkgdcmMEXD-4.9 \ - -litkgdcmCommon-4.9 \ - -litkgdcmIOD-4.9 \ - -L/usr/X11R6/lib \ - -L/usr/lib64 \ - -L/home/tbaudier/vv/vv_static/Qt/lib/ \ - -lQt5Core \ - -lQt5Gui \ - -lQt5Widgets \ - -ldl \ - -lX11 \ - -lXt - diff --git a/vv/vvConfiguration.h b/vv/vvConfiguration.h deleted file mode 100644 index 36d3258..0000000 --- a/vv/vvConfiguration.h +++ /dev/null @@ -1,24 +0,0 @@ -/*========================================================================= - Program: vv http://www.creatis.insa-lyon.fr/rio/vv - - Authors belong to: - - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://www.centreleonberard.fr - - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the copyright notices for more information. - - It is distributed under dual licence - - - BSD See included LICENSE.txt file - - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -===========================================================================**/ - -#ifndef vv_configuration_h -#define vv_configuration_h - -#define VV_VERSION "v@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@" - -#endif