2 File autogenerated by gengetopt version 2.22
3 generated with the following command:
4 /usr/local/bin/gengetopt --output-dir=/home/tbaudier/vv/vv_static/vv/vv_bin/tools --arg-struct-name=args_info_clitkResampleImage --func-name=cmdline_parser_clitkResampleImage --file-name=clitkResampleImage_ggo --unamed-opts --conf-parser --include-getopt
6 The developers of gengetopt consider the fixed text that goes in all
7 gengetopt output files to be in the public domain:
8 we make no copyright claims on it.
11 /* If we use autoconf. */
21 #include "clitkResampleImage_ggo.h"
23 const char *args_info_clitkResampleImage_purpose = "Resample an image. You can specify the interpolation, you can apply a Gaussian \nfilter before (automated if downsample).";
25 const char *args_info_clitkResampleImage_usage = "Usage: clitkResampleImage [OPTIONS]... [FILES]...";
27 const char *args_info_clitkResampleImage_description = "";
29 const char *args_info_clitkResampleImage_help[] = {
30 " -h, --help Print help and exit",
31 " -V, --version Print version and exit",
33 " --config=STRING Config file",
34 " -v, --verbose Verbose (default=off)",
35 " --imagetypes Verbose: allowed image types (default=off)",
36 " --thread=INT Nb of thread to use (default=max)",
37 "\nInput & Output options:",
38 " -i, --input=STRING Input image filename",
39 " -o, --output=STRING Output image filename",
40 " -l, --like=STRING Resample like this image",
41 " --size=INT Number of pixels of each coordonate (default=`0')",
42 " --spacing=FLOAT Spacing in mm between pixels (default=`-1.0')",
43 " -d, --default=FLOAT Default pixel value (default=`0.0')",
44 " -t, --time Last Dimension Is Time -> do not resample it (auto on \n for 4D) (default=off)",
46 " --interp=STRING Interpolation type: {nn, linear, bspline, blut} \n (default=`nn')",
47 " -b, --order=INT BSpline ordre (range 0-5) (default=`3')",
48 " -s, --sampling=INT BLUT sampling value (default=`30')",
49 "\nGaussian filtering:",
50 " -g, --gauss=FLOAT Apply Gaussian before (sigma in mm) (default=`0.0')",
51 " -a, --autogauss Apply Gaussian with auto sigma when downsample \n (default=off)",
60 } cmdline_parser_clitkResampleImage_arg_type;
63 void clear_given (struct args_info_clitkResampleImage *args_info);
65 void clear_args (struct args_info_clitkResampleImage *args_info);
68 cmdline_parser_clitkResampleImage_internal (int argc, char * const *argv, struct args_info_clitkResampleImage *args_info,
69 struct cmdline_parser_clitkResampleImage_params *params, const char *additional_error);
72 cmdline_parser_clitkResampleImage_required2 (struct args_info_clitkResampleImage *args_info, const char *prog_name, const char *additional_error);
76 struct line_list * next;
79 static struct line_list *cmd_line_list = 0;
80 static struct line_list *cmd_line_list_tmp = 0;
85 /* free the list of a previous call */
88 while (cmd_line_list) {
89 cmd_line_list_tmp = cmd_line_list;
90 cmd_line_list = cmd_line_list->next;
91 free (cmd_line_list_tmp->string_arg);
92 free (cmd_line_list_tmp);
99 gengetopt_strdup (const char *s);
102 void clear_given (struct args_info_clitkResampleImage *args_info)
104 args_info->help_given = 0 ;
105 args_info->version_given = 0 ;
106 args_info->config_given = 0 ;
107 args_info->verbose_given = 0 ;
108 args_info->imagetypes_given = 0 ;
109 args_info->thread_given = 0 ;
110 args_info->input_given = 0 ;
111 args_info->output_given = 0 ;
112 args_info->like_given = 0 ;
113 args_info->size_given = 0 ;
114 args_info->spacing_given = 0 ;
115 args_info->default_given = 0 ;
116 args_info->time_given = 0 ;
117 args_info->interp_given = 0 ;
118 args_info->order_given = 0 ;
119 args_info->sampling_given = 0 ;
120 args_info->gauss_given = 0 ;
121 args_info->autogauss_given = 0 ;
125 void clear_args (struct args_info_clitkResampleImage *args_info)
127 args_info->config_arg = NULL;
128 args_info->config_orig = NULL;
129 args_info->verbose_flag = 0;
130 args_info->imagetypes_flag = 0;
131 args_info->thread_orig = NULL;
132 args_info->input_arg = NULL;
133 args_info->input_orig = NULL;
134 args_info->output_arg = NULL;
135 args_info->output_orig = NULL;
136 args_info->like_arg = NULL;
137 args_info->like_orig = NULL;
138 args_info->size_arg = NULL;
139 args_info->size_orig = NULL;
140 args_info->spacing_arg = NULL;
141 args_info->spacing_orig = NULL;
142 args_info->default_arg = 0.0;
143 args_info->default_orig = NULL;
144 args_info->time_flag = 0;
145 args_info->interp_arg = gengetopt_strdup ("nn");
146 args_info->interp_orig = NULL;
147 args_info->order_arg = 3;
148 args_info->order_orig = NULL;
149 args_info->sampling_arg = 30;
150 args_info->sampling_orig = NULL;
151 args_info->gauss_arg = NULL;
152 args_info->gauss_orig = NULL;
153 args_info->autogauss_flag = 0;
158 void init_args_info(struct args_info_clitkResampleImage *args_info)
162 args_info->help_help = args_info_clitkResampleImage_help[0] ;
163 args_info->version_help = args_info_clitkResampleImage_help[1] ;
164 args_info->config_help = args_info_clitkResampleImage_help[3] ;
165 args_info->verbose_help = args_info_clitkResampleImage_help[4] ;
166 args_info->imagetypes_help = args_info_clitkResampleImage_help[5] ;
167 args_info->thread_help = args_info_clitkResampleImage_help[6] ;
168 args_info->input_help = args_info_clitkResampleImage_help[8] ;
169 args_info->output_help = args_info_clitkResampleImage_help[9] ;
170 args_info->like_help = args_info_clitkResampleImage_help[10] ;
171 args_info->size_help = args_info_clitkResampleImage_help[11] ;
172 args_info->size_min = -1;
173 args_info->size_max = -1;
174 args_info->spacing_help = args_info_clitkResampleImage_help[12] ;
175 args_info->spacing_min = -1;
176 args_info->spacing_max = -1;
177 args_info->default_help = args_info_clitkResampleImage_help[13] ;
178 args_info->time_help = args_info_clitkResampleImage_help[14] ;
179 args_info->interp_help = args_info_clitkResampleImage_help[16] ;
180 args_info->order_help = args_info_clitkResampleImage_help[17] ;
181 args_info->sampling_help = args_info_clitkResampleImage_help[18] ;
182 args_info->gauss_help = args_info_clitkResampleImage_help[20] ;
183 args_info->gauss_min = -1;
184 args_info->gauss_max = -1;
185 args_info->autogauss_help = args_info_clitkResampleImage_help[21] ;
190 cmdline_parser_clitkResampleImage_print_version (void)
192 printf ("%s %s\n", CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, CMDLINE_PARSER_CLITKRESAMPLEIMAGE_VERSION);
195 static void print_help_common(void) {
196 cmdline_parser_clitkResampleImage_print_version ();
198 if (strlen(args_info_clitkResampleImage_purpose) > 0)
199 printf("\n%s\n", args_info_clitkResampleImage_purpose);
201 if (strlen(args_info_clitkResampleImage_usage) > 0)
202 printf("\n%s\n", args_info_clitkResampleImage_usage);
206 if (strlen(args_info_clitkResampleImage_description) > 0)
207 printf("%s\n", args_info_clitkResampleImage_description);
211 cmdline_parser_clitkResampleImage_print_help (void)
215 while (args_info_clitkResampleImage_help[i])
216 printf("%s\n", args_info_clitkResampleImage_help[i++]);
220 cmdline_parser_clitkResampleImage_init (struct args_info_clitkResampleImage *args_info)
222 clear_given (args_info);
223 clear_args (args_info);
224 init_args_info (args_info);
226 args_info->inputs = NULL;
227 args_info->inputs_num = 0;
231 cmdline_parser_clitkResampleImage_params_init(struct cmdline_parser_clitkResampleImage_params *params)
235 params->override = 0;
236 params->initialize = 1;
237 params->check_required = 1;
238 params->check_ambiguity = 0;
239 params->print_errors = 1;
243 struct cmdline_parser_clitkResampleImage_params *
244 cmdline_parser_clitkResampleImage_params_create(void)
246 struct cmdline_parser_clitkResampleImage_params *params =
247 (struct cmdline_parser_clitkResampleImage_params *)malloc(sizeof(struct cmdline_parser_clitkResampleImage_params));
248 cmdline_parser_clitkResampleImage_params_init(params);
253 free_string_field (char **s)
262 /** @brief generic value variable */
263 union generic_value {
269 /** @brief holds temporary values for multiple options */
272 union generic_value arg;
274 struct generic_list *next;
278 * @brief add a node at the head of the list
280 static void add_node(struct generic_list **list) {
281 struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list));
282 new_node->next = *list;
284 new_node->arg.string_arg = NULL;
285 new_node->orig = NULL;
289 free_multiple_field(unsigned int len, void **arg, char ***orig)
293 for (i = 0; i < len; ++i)
295 free_string_field(&((*orig)[i]));
307 cmdline_parser_clitkResampleImage_release (struct args_info_clitkResampleImage *args_info)
310 free_string_field (&(args_info->config_arg));
311 free_string_field (&(args_info->config_orig));
312 free_string_field (&(args_info->thread_orig));
313 free_string_field (&(args_info->input_arg));
314 free_string_field (&(args_info->input_orig));
315 free_string_field (&(args_info->output_arg));
316 free_string_field (&(args_info->output_orig));
317 free_string_field (&(args_info->like_arg));
318 free_string_field (&(args_info->like_orig));
319 free_multiple_field (args_info->size_given, (void **)&(args_info->size_arg), &(args_info->size_orig));
320 free_multiple_field (args_info->spacing_given, (void **)&(args_info->spacing_arg), &(args_info->spacing_orig));
321 free_string_field (&(args_info->default_orig));
322 free_string_field (&(args_info->interp_arg));
323 free_string_field (&(args_info->interp_orig));
324 free_string_field (&(args_info->order_orig));
325 free_string_field (&(args_info->sampling_orig));
326 free_multiple_field (args_info->gauss_given, (void **)&(args_info->gauss_arg), &(args_info->gauss_orig));
329 for (i = 0; i < args_info->inputs_num; ++i)
330 free (args_info->inputs [i]);
332 if (args_info->inputs_num)
333 free (args_info->inputs);
335 clear_given (args_info);
340 write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
343 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
345 fprintf(outfile, "%s\n", opt);
350 write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[])
354 for (i = 0; i < len; ++i)
355 write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
359 cmdline_parser_clitkResampleImage_dump(FILE *outfile, struct args_info_clitkResampleImage *args_info)
365 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE);
369 if (args_info->help_given)
370 write_into_file(outfile, "help", 0, 0 );
371 if (args_info->version_given)
372 write_into_file(outfile, "version", 0, 0 );
373 if (args_info->config_given)
374 write_into_file(outfile, "config", args_info->config_orig, 0);
375 if (args_info->verbose_given)
376 write_into_file(outfile, "verbose", 0, 0 );
377 if (args_info->imagetypes_given)
378 write_into_file(outfile, "imagetypes", 0, 0 );
379 if (args_info->thread_given)
380 write_into_file(outfile, "thread", args_info->thread_orig, 0);
381 if (args_info->input_given)
382 write_into_file(outfile, "input", args_info->input_orig, 0);
383 if (args_info->output_given)
384 write_into_file(outfile, "output", args_info->output_orig, 0);
385 if (args_info->like_given)
386 write_into_file(outfile, "like", args_info->like_orig, 0);
387 write_multiple_into_file(outfile, args_info->size_given, "size", args_info->size_orig, 0);
388 write_multiple_into_file(outfile, args_info->spacing_given, "spacing", args_info->spacing_orig, 0);
389 if (args_info->default_given)
390 write_into_file(outfile, "default", args_info->default_orig, 0);
391 if (args_info->time_given)
392 write_into_file(outfile, "time", 0, 0 );
393 if (args_info->interp_given)
394 write_into_file(outfile, "interp", args_info->interp_orig, 0);
395 if (args_info->order_given)
396 write_into_file(outfile, "order", args_info->order_orig, 0);
397 if (args_info->sampling_given)
398 write_into_file(outfile, "sampling", args_info->sampling_orig, 0);
399 write_multiple_into_file(outfile, args_info->gauss_given, "gauss", args_info->gauss_orig, 0);
400 if (args_info->autogauss_given)
401 write_into_file(outfile, "autogauss", 0, 0 );
409 cmdline_parser_clitkResampleImage_file_save(const char *filename, struct args_info_clitkResampleImage *args_info)
414 outfile = fopen(filename, "w");
418 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename);
422 i = cmdline_parser_clitkResampleImage_dump(outfile, args_info);
429 cmdline_parser_clitkResampleImage_free (struct args_info_clitkResampleImage *args_info)
431 cmdline_parser_clitkResampleImage_release (args_info);
434 /** @brief replacement of strdup, which is not standard */
436 gengetopt_strdup (const char *s)
442 result = (char*)malloc(strlen(s) + 1);
443 if (result == (char*)0)
450 get_multiple_arg_token(const char *arg)
453 size_t len, num_of_escape, i, j;
458 tok = strchr (arg, ',');
461 /* make sure it is not escaped */
464 if (*(tok-1) == '\\')
466 /* find the next one */
467 tok = strchr (tok+1, ',');
475 len = (size_t)(tok - arg + 1);
477 len = strlen (arg) + 1;
479 len -= num_of_escape;
481 ret = (char *) malloc (len);
485 while (arg[i] && (j < len-1))
487 if (arg[i] == '\\' &&
501 get_multiple_arg_token_next(const char *arg)
508 tok = strchr (arg, ',');
510 /* make sure it is not escaped */
513 if (*(tok-1) == '\\')
515 /* find the next one */
516 tok = strchr (tok+1, ',');
522 if (! tok || strlen(tok) == 1)
529 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc);
532 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc)
536 if (option_given && ! (min < 0 && max < 0))
538 if (min >= 0 && max >= 0)
542 /* specific occurrences */
543 if (option_given != min)
545 fprintf (stderr, "%s: %s option occurrences must be %d\n",
546 prog_name, option_desc, min);
550 else if (option_given < min
551 || option_given > max)
553 /* range occurrences */
554 fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n",
555 prog_name, option_desc, min, max);
562 if (option_given < min)
564 fprintf (stderr, "%s: %s option occurrences must be at least %d\n",
565 prog_name, option_desc, min);
572 if (option_given > max)
574 fprintf (stderr, "%s: %s option occurrences must be at most %d\n",
575 prog_name, option_desc, max);
584 cmdline_parser_clitkResampleImage (int argc, char * const *argv, struct args_info_clitkResampleImage *args_info)
586 return cmdline_parser_clitkResampleImage2 (argc, argv, args_info, 0, 1, 1);
590 cmdline_parser_clitkResampleImage_ext (int argc, char * const *argv, struct args_info_clitkResampleImage *args_info,
591 struct cmdline_parser_clitkResampleImage_params *params)
594 result = cmdline_parser_clitkResampleImage_internal (argc, argv, args_info, params, NULL);
596 if (result == EXIT_FAILURE)
598 cmdline_parser_clitkResampleImage_free (args_info);
606 cmdline_parser_clitkResampleImage2 (int argc, char * const *argv, struct args_info_clitkResampleImage *args_info, int override, int initialize, int check_required)
609 struct cmdline_parser_clitkResampleImage_params params;
611 params.override = override;
612 params.initialize = initialize;
613 params.check_required = check_required;
614 params.check_ambiguity = 0;
615 params.print_errors = 1;
617 result = cmdline_parser_clitkResampleImage_internal (argc, argv, args_info, ¶ms, NULL);
619 if (result == EXIT_FAILURE)
621 cmdline_parser_clitkResampleImage_free (args_info);
629 cmdline_parser_clitkResampleImage_required (struct args_info_clitkResampleImage *args_info, const char *prog_name)
631 int result = EXIT_SUCCESS;
633 if (cmdline_parser_clitkResampleImage_required2(args_info, prog_name, NULL) > 0)
634 result = EXIT_FAILURE;
636 if (result == EXIT_FAILURE)
638 cmdline_parser_clitkResampleImage_free (args_info);
646 cmdline_parser_clitkResampleImage_required2 (struct args_info_clitkResampleImage *args_info, const char *prog_name, const char *additional_error)
650 /* checks for required options */
651 if (! args_info->input_given)
653 fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
657 if (! args_info->output_given)
659 fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
663 if (check_multiple_option_occurrences(prog_name, args_info->size_given, args_info->size_min, args_info->size_max, "'--size'"))
666 if (check_multiple_option_occurrences(prog_name, args_info->spacing_given, args_info->spacing_min, args_info->spacing_max, "'--spacing'"))
669 if (check_multiple_option_occurrences(prog_name, args_info->gauss_given, args_info->gauss_min, args_info->gauss_max, "'--gauss' ('-g')"))
673 /* checks for dependences among options */
679 * Extracted from the glibc source tree, version 2.3.6
681 * Licensed under the GPL as per the whole glibc source tree.
683 * This file was modified so that getopt_long can be called
684 * many times without risking previous memory to be spoiled.
686 * Modified by Andre Noll and Lorenzo Bettini for use in
687 * GNU gengetopt generated files.
692 * we must include anything we need since this file is not thought to be
693 * inserted in a file already using getopt.h
701 /* has_arg can't be an enum because some compilers complain about
702 type mismatches in all the code that assumes it is an int. */
708 /* For communication from `getopt' to the caller.
709 When `getopt' finds an option that takes an argument,
710 the argument value is returned here.
711 Also, when `ordering' is RETURN_IN_ORDER,
712 each non-option ARGV-element is returned here. */
716 /* Index in ARGV of the next element to be scanned.
717 This is used for communication to and from the caller
718 and for communication between successive calls to `getopt'.
720 On entry to `getopt', zero means this is the first call; initialize.
722 When `getopt' returns -1, this is the index of the first of the
723 non-option elements that the caller should itself scan.
725 Otherwise, `optind' communicates from one call to the next
726 how much of ARGV has been scanned so far. */
730 /* Callers store zero here to inhibit the error message `getopt' prints
731 for unrecognized options. */
735 /* Set to an option character which was unrecognized. */
739 /* This version of `getopt' appears to the caller like standard Unix `getopt'
740 but it behaves differently for the user, since it allows the user
741 to intersperse the options with the other arguments.
743 As `getopt' works, it permutes the elements of ARGV so that,
744 when it is done, all the options precede everything else. Thus
745 all application programs are extended to handle flexible argument order.
748 If the field `flag' is not NULL, it points to a variable that is set
749 to the value given in the field `val' when the option is found, but
750 left unchanged if the option is not found.
752 To have a long-named option do something other than set an `int' to
753 a compiled-in constant, such as set a value from `custom_optarg', set the
754 option's `flag' field to zero and its `val' field to a nonzero
755 value (the equivalent single-letter option character, if there is
756 one). For long options that have a zero `flag' field, `getopt'
757 returns the contents of the `val' field. */
759 /* Names for the values of the `has_arg' field of `struct option'. */
761 #define no_argument 0
764 #ifndef required_argument
765 #define required_argument 1
768 #ifndef optional_argument
769 #define optional_argument 2
772 struct custom_getopt_data {
774 * These have exactly the same meaning as the corresponding global variables,
775 * except that they are used for the reentrant versions of getopt.
782 /* True if the internal members have been initialized. */
786 * The next char to be scanned in the option-element in which the last option
787 * character we returned was found. This allows us to pick up the scan where
788 * we left off. If this is zero, or a null string, it means resume the scan by
789 * advancing to the next ARGV-element.
794 * Describe the part of ARGV that contains non-options that have been skipped.
795 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
796 * the index after the last of them.
803 * the variables optarg, optind, opterr and optopt are renamed with
804 * the custom_ prefix so that they don't interfere with getopt ones.
806 * Moreover they're static so they are visible only from within the
807 * file where this very file will be included.
811 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
812 * option that takes an argument, the argument value is returned here.
814 static char *custom_optarg;
817 * Index in ARGV of the next element to be scanned. This is used for
818 * communication to and from the caller and for communication between
819 * successive calls to `custom_getopt'.
821 * On entry to `custom_getopt', 1 means this is the first call; initialize.
823 * When `custom_getopt' returns -1, this is the index of the first of the non-option
824 * elements that the caller should itself scan.
826 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
827 * has been scanned so far.
829 * 1003.2 says this must be 1 before any call.
831 static int custom_optind = 1;
834 * Callers store zero here to inhibit the error message for unrecognized
837 static int custom_opterr = 1;
840 * Set to an option character which was unrecognized. This must be initialized
841 * on some systems to avoid linking in the system's own getopt implementation.
843 static int custom_optopt = '?';
846 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
847 * [first_nonopt,last_nonopt) which contains all the non-options that have been
848 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
849 * all the options processed since those non-options were skipped.
850 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
851 * indices of the non-options in ARGV after they are moved.
853 static void exchange(char **argv, struct custom_getopt_data *d)
855 int bottom = d->first_nonopt;
856 int middle = d->last_nonopt;
857 int top = d->custom_optind;
861 * Exchange the shorter segment with the far end of the longer segment.
862 * That puts the shorter segment into the right place. It leaves the
863 * longer segment in the right place overall, but it consists of two
864 * parts that need to be swapped next.
866 while (top > middle && middle > bottom) {
867 if (top - middle > middle - bottom) {
868 /* Bottom segment is the short one. */
869 int len = middle - bottom;
872 /* Swap it with the top part of the top segment. */
873 for (i = 0; i < len; i++) {
874 tem = argv[bottom + i];
876 argv[top - (middle - bottom) + i];
877 argv[top - (middle - bottom) + i] = tem;
879 /* Exclude the moved bottom segment from further swapping. */
882 /* Top segment is the short one. */
883 int len = top - middle;
886 /* Swap it with the bottom part of the bottom segment. */
887 for (i = 0; i < len; i++) {
888 tem = argv[bottom + i];
889 argv[bottom + i] = argv[middle + i];
890 argv[middle + i] = tem;
892 /* Exclude the moved top segment from further swapping. */
896 /* Update records for the slots the non-options now occupy. */
897 d->first_nonopt += (d->custom_optind - d->last_nonopt);
898 d->last_nonopt = d->custom_optind;
901 /* Initialize the internal data when the first call is made. */
902 static void custom_getopt_initialize(struct custom_getopt_data *d)
905 * Start processing options with ARGV-element 1 (since ARGV-element 0
906 * is the program name); the sequence of previously skipped non-option
907 * ARGV-elements is empty.
909 d->first_nonopt = d->last_nonopt = d->custom_optind;
914 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
916 /* return: zero: continue, nonzero: return given value to user */
917 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
918 struct custom_getopt_data *d)
921 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
922 * moved back by the user (who may also have changed the arguments).
924 if (d->last_nonopt > d->custom_optind)
925 d->last_nonopt = d->custom_optind;
926 if (d->first_nonopt > d->custom_optind)
927 d->first_nonopt = d->custom_optind;
929 * If we have just processed some options following some
930 * non-options, exchange them so that the options come first.
932 if (d->first_nonopt != d->last_nonopt &&
933 d->last_nonopt != d->custom_optind)
934 exchange((char **) argv, d);
935 else if (d->last_nonopt != d->custom_optind)
936 d->first_nonopt = d->custom_optind;
938 * Skip any additional non-options and extend the range of
939 * non-options previously skipped.
941 while (d->custom_optind < argc && NONOPTION_P)
943 d->last_nonopt = d->custom_optind;
945 * The special ARGV-element `--' means premature end of options. Skip
946 * it like a null option, then exchange with previous non-options as if
947 * it were an option, then skip everything else like a non-option.
949 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
951 if (d->first_nonopt != d->last_nonopt
952 && d->last_nonopt != d->custom_optind)
953 exchange((char **) argv, d);
954 else if (d->first_nonopt == d->last_nonopt)
955 d->first_nonopt = d->custom_optind;
956 d->last_nonopt = argc;
957 d->custom_optind = argc;
960 * If we have done all the ARGV-elements, stop the scan and back over
961 * any non-options that we skipped and permuted.
963 if (d->custom_optind == argc) {
965 * Set the next-arg-index to point at the non-options that we
966 * previously skipped, so the caller will digest them.
968 if (d->first_nonopt != d->last_nonopt)
969 d->custom_optind = d->first_nonopt;
973 * If we have come to a non-option and did not permute it, either stop
974 * the scan or describe it to the caller and pass it by.
977 d->custom_optarg = argv[d->custom_optind++];
981 * We have found another option-ARGV-element. Skip the initial
984 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
989 * Check whether the ARGV-element is a long option.
991 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
992 * that an abbreviation of the long option, just like "--fu", and not "-f" with
995 * This distinction seems to be the most useful approach.
998 static int check_long_opt(int argc, char *const *argv, const char *optstring,
999 const struct option *longopts, int *longind,
1000 int print_errors, struct custom_getopt_data *d)
1003 const struct option *p;
1004 const struct option *pfound = NULL;
1010 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
1013 /* Test all long options for either exact match or abbreviated matches */
1014 for (p = longopts, option_index = 0; p->name; p++, option_index++)
1015 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
1016 if ((unsigned int) (nameend - d->nextchar)
1017 == (unsigned int) strlen(p->name)) {
1018 /* Exact match found. */
1020 indfound = option_index;
1023 } else if (pfound == NULL) {
1024 /* First nonexact match found. */
1026 indfound = option_index;
1027 } else if (pfound->has_arg != p->has_arg
1028 || pfound->flag != p->flag
1029 || pfound->val != p->val)
1030 /* Second or later nonexact match found. */
1033 if (ambig && !exact) {
1036 "%s: option `%s' is ambiguous\n",
1037 argv[0], argv[d->custom_optind]);
1039 d->nextchar += strlen(d->nextchar);
1041 d->custom_optopt = 0;
1045 option_index = indfound;
1048 if (pfound->has_arg != no_argument)
1049 d->custom_optarg = nameend + 1;
1052 if (argv[d->custom_optind - 1][1] == '-') {
1054 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
1055 argv[0], pfound->name);
1057 /* +option or -option */
1058 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
1059 argv[0], argv[d->custom_optind - 1][0], pfound->name);
1063 d->nextchar += strlen(d->nextchar);
1064 d->custom_optopt = pfound->val;
1067 } else if (pfound->has_arg == required_argument) {
1068 if (d->custom_optind < argc)
1069 d->custom_optarg = argv[d->custom_optind++];
1073 "%s: option `%s' requires an argument\n",
1075 argv[d->custom_optind - 1]);
1077 d->nextchar += strlen(d->nextchar);
1078 d->custom_optopt = pfound->val;
1079 return optstring[0] == ':' ? ':' : '?';
1082 d->nextchar += strlen(d->nextchar);
1083 if (longind != NULL)
1084 *longind = option_index;
1086 *(pfound->flag) = pfound->val;
1092 * Can't find it as a long option. If this is not getopt_long_only, or
1093 * the option starts with '--' or is not a valid short option, then
1094 * it's an error. Otherwise interpret it as a short option.
1097 if (argv[d->custom_optind][1] == '-') {
1100 "%s: unrecognized option `--%s'\n",
1101 argv[0], d->nextchar);
1103 /* +option or -option */
1105 "%s: unrecognized option `%c%s'\n",
1106 argv[0], argv[d->custom_optind][0],
1110 d->nextchar = (char *) "";
1112 d->custom_optopt = 0;
1116 static int check_short_opt(int argc, char *const *argv, const char *optstring,
1117 int print_errors, struct custom_getopt_data *d)
1119 char c = *d->nextchar++;
1120 char *temp = strchr(optstring, c);
1122 /* Increment `custom_optind' when we start to process its last character. */
1123 if (*d->nextchar == '\0')
1125 if (!temp || c == ':') {
1127 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
1129 d->custom_optopt = c;
1132 if (temp[1] == ':') {
1133 if (temp[2] == ':') {
1134 /* This is an option that accepts an argument optionally. */
1135 if (*d->nextchar != '\0') {
1136 d->custom_optarg = d->nextchar;
1139 d->custom_optarg = NULL;
1142 /* This is an option that requires an argument. */
1143 if (*d->nextchar != '\0') {
1144 d->custom_optarg = d->nextchar;
1146 * If we end this ARGV-element by taking the
1147 * rest as an arg, we must advance to the next
1151 } else if (d->custom_optind == argc) {
1154 "%s: option requires an argument -- %c\n",
1157 d->custom_optopt = c;
1158 if (optstring[0] == ':')
1164 * We already incremented `custom_optind' once;
1165 * increment it again when taking next ARGV-elt
1168 d->custom_optarg = argv[d->custom_optind++];
1176 * Scan elements of ARGV for option characters given in OPTSTRING.
1178 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
1179 * then it is an option element. The characters of this element
1180 * (aside from the initial '-') are option characters. If `getopt'
1181 * is called repeatedly, it returns successively each of the option characters
1182 * from each of the option elements.
1184 * If `getopt' finds another option character, it returns that character,
1185 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
1186 * resume the scan with the following option character or ARGV-element.
1188 * If there are no more option characters, `getopt' returns -1.
1189 * Then `custom_optind' is the index in ARGV of the first ARGV-element
1190 * that is not an option. (The ARGV-elements have been permuted
1191 * so that those that are not options now come last.)
1193 * OPTSTRING is a string containing the legitimate option characters.
1194 * If an option character is seen that is not listed in OPTSTRING,
1195 * return '?' after printing an error message. If you set `custom_opterr' to
1196 * zero, the error message is suppressed but we still return '?'.
1198 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
1199 * so the following text in the same ARGV-element, or the text of the following
1200 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
1201 * wants an optional arg; if there is text in the current ARGV-element,
1202 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
1204 * If OPTSTRING starts with `-' or `+', it requests different methods of
1205 * handling the non-option ARGV-elements.
1206 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
1208 * Long-named options begin with `--' instead of `-'.
1209 * Their names may be abbreviated as long as the abbreviation is unique
1210 * or is an exact match for some defined option. If they have an
1211 * argument, it follows the option name in the same ARGV-element, separated
1212 * from the option name by a `=', or else the in next ARGV-element.
1213 * When `getopt' finds a long-named option, it returns 0 if that option's
1214 * `flag' field is nonzero, the value of the option's `val' field
1215 * if the `flag' field is zero.
1217 * The elements of ARGV aren't really const, because we permute them.
1218 * But we pretend they're const in the prototype to be compatible
1219 * with other systems.
1221 * LONGOPTS is a vector of `struct option' terminated by an
1222 * element containing a name which is zero.
1224 * LONGIND returns the index in LONGOPT of the long-named option found.
1225 * It is only valid when a long-named option has been found by the most
1228 * Return the option character from OPTS just read. Return -1 when there are
1229 * no more options. For unrecognized options, or options missing arguments,
1230 * `custom_optopt' is set to the option letter, and '?' is returned.
1232 * The OPTS string is a list of characters which are recognized option letters,
1233 * optionally followed by colons, specifying that that letter takes an
1234 * argument, to be placed in `custom_optarg'.
1236 * If a letter in OPTS is followed by two colons, its argument is optional.
1237 * This behavior is specific to the GNU `getopt'.
1239 * The argument `--' causes premature termination of argument scanning,
1240 * explicitly telling `getopt' that there are no more options. If OPTS begins
1241 * with `--', then non-option arguments are treated as arguments to the option
1242 * '\0'. This behavior is specific to the GNU `getopt'.
1245 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1246 const struct option *longopts, int *longind,
1247 struct custom_getopt_data *d)
1249 int ret, print_errors = d->custom_opterr;
1251 if (optstring[0] == ':')
1255 d->custom_optarg = NULL;
1258 * This is a big difference with GNU getopt, since optind == 0
1259 * means initialization while here 1 means first call.
1261 if (d->custom_optind == 0 || !d->initialized) {
1262 if (d->custom_optind == 0)
1263 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
1264 custom_getopt_initialize(d);
1266 if (d->nextchar == NULL || *d->nextchar == '\0') {
1267 ret = shuffle_argv(argc, argv, longopts, d);
1271 if (longopts && (argv[d->custom_optind][1] == '-' ))
1272 return check_long_opt(argc, argv, optstring, longopts,
1273 longind, print_errors, d);
1274 return check_short_opt(argc, argv, optstring, print_errors, d);
1277 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1278 const struct option *longopts, int *longind)
1281 /* Keep a global copy of all internal members of d */
1282 static struct custom_getopt_data d;
1284 d.custom_optind = custom_optind;
1285 d.custom_opterr = custom_opterr;
1286 result = getopt_internal_r(argc, argv, optstring, longopts,
1288 custom_optind = d.custom_optind;
1289 custom_optarg = d.custom_optarg;
1290 custom_optopt = d.custom_optopt;
1294 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1295 const struct option *long_options, int *opt_index)
1297 return custom_getopt_internal(argc, argv, options, long_options,
1302 static char *package_name = 0;
1305 * @brief updates an option
1306 * @param field the generic pointer to the field to update
1307 * @param orig_field the pointer to the orig field
1308 * @param field_given the pointer to the number of occurrence of this option
1309 * @param prev_given the pointer to the number of occurrence already seen
1310 * @param value the argument for this option (if null no arg was specified)
1311 * @param possible_values the possible values for this option (if specified)
1312 * @param default_value the default value (in case the option only accepts fixed values)
1313 * @param arg_type the type of this option
1314 * @param check_ambiguity @see cmdline_parser_clitkResampleImage_params.check_ambiguity
1315 * @param override @see cmdline_parser_clitkResampleImage_params.override
1316 * @param no_free whether to free a possible previous value
1317 * @param multiple_option whether this is a multiple option
1318 * @param long_opt the corresponding long option
1319 * @param short_opt the corresponding short option (or '-' if none)
1320 * @param additional_error possible further error specification
1323 int update_arg(void *field, char **orig_field,
1324 unsigned int *field_given, unsigned int *prev_given,
1325 char *value, char *possible_values[], const char *default_value,
1326 cmdline_parser_clitkResampleImage_arg_type arg_type,
1327 int check_ambiguity, int override,
1328 int no_free, int multiple_option,
1329 const char *long_opt, char short_opt,
1330 const char *additional_error)
1332 char *stop_char = 0;
1333 const char *val = value;
1335 char **string_field;
1340 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1342 if (short_opt != '-')
1343 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1344 package_name, long_opt, short_opt,
1345 (additional_error ? additional_error : ""));
1347 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1348 package_name, long_opt,
1349 (additional_error ? additional_error : ""));
1350 return 1; /* failure */
1354 if (field_given && *field_given && ! override)
1360 if (possible_values)
1361 val = possible_values[found];
1365 *((int *)field) = !*((int *)field);
1368 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1371 if (val) *((float *)field) = (float)strtod (val, &stop_char);
1375 string_field = (char **)field;
1376 if (!no_free && *string_field)
1377 free (*string_field); /* free previous string */
1378 *string_field = gengetopt_strdup (val);
1385 /* check numeric conversion */
1389 if (val && !(stop_char && *stop_char == '\0')) {
1390 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1391 return 1; /* failure */
1398 /* store the original value */
1404 if (value && orig_field) {
1406 *orig_field = value;
1409 free (*orig_field); /* free previous string */
1410 *orig_field = gengetopt_strdup (value);
1419 * @brief store information about a multiple option in a temporary list
1420 * @param list where to (temporarily) store multiple options
1423 int update_multiple_arg_temp(struct generic_list **list,
1424 unsigned int *prev_given, const char *val,
1425 char *possible_values[], const char *default_value,
1426 cmdline_parser_clitkResampleImage_arg_type arg_type,
1427 const char *long_opt, char short_opt,
1428 const char *additional_error)
1430 char *multi_token, *multi_next; /* store single arguments */
1432 if (arg_type == ARG_NO) {
1437 multi_token = get_multiple_arg_token(val);
1438 multi_next = get_multiple_arg_token_next (val);
1443 if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0,
1444 prev_given, multi_token, possible_values, default_value,
1445 arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
1446 if (multi_token) free(multi_token);
1447 return 1; /* failure */
1452 multi_token = get_multiple_arg_token(multi_next);
1453 multi_next = get_multiple_arg_token_next (multi_next);
1463 * @brief free the passed list (including possible string argument)
1466 void free_list(struct generic_list *list, short string_arg)
1469 struct generic_list *tmp;
1473 if (string_arg && list->arg.string_arg)
1474 free (list->arg.string_arg);
1484 * @brief updates a multiple option starting from the passed list
1487 void update_multiple_arg(void *field, char ***orig_field,
1488 unsigned int field_given, unsigned int prev_given, union generic_value *default_value,
1489 cmdline_parser_clitkResampleImage_arg_type arg_type,
1490 struct generic_list *list)
1493 struct generic_list *tmp;
1495 if (prev_given && list) {
1496 *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *));
1500 *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break;
1502 *((float **)field) = (float *)realloc (*((float **)field), (field_given + prev_given) * sizeof (float)); break;
1504 *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break;
1509 for (i = (prev_given - 1); i >= 0; --i)
1515 (*((int **)field))[i + field_given] = tmp->arg.int_arg; break;
1517 (*((float **)field))[i + field_given] = tmp->arg.float_arg; break;
1519 (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break;
1523 (*orig_field) [i + field_given] = list->orig;
1527 } else { /* set the default value */
1528 if (default_value && ! field_given) {
1531 if (! *((int **)field)) {
1532 *((int **)field) = (int *)malloc (sizeof (int));
1533 (*((int **)field))[0] = default_value->int_arg;
1537 if (! *((float **)field)) {
1538 *((float **)field) = (float *)malloc (sizeof (float));
1539 (*((float **)field))[0] = default_value->float_arg;
1543 if (! *((char ***)field)) {
1544 *((char ***)field) = (char **)malloc (sizeof (char *));
1545 (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg);
1550 if (!(*orig_field)) {
1551 *orig_field = (char **) malloc (sizeof (char *));
1552 (*orig_field)[0] = NULL;
1559 cmdline_parser_clitkResampleImage_internal (int argc, char * const *argv, struct args_info_clitkResampleImage *args_info,
1560 struct cmdline_parser_clitkResampleImage_params *params, const char *additional_error)
1562 int c; /* Character of the parsed option. */
1563 union generic_value multiple_default_value;
1565 struct generic_list * size_list = NULL;
1566 struct generic_list * spacing_list = NULL;
1567 struct generic_list * gauss_list = NULL;
1569 struct args_info_clitkResampleImage local_args_info;
1574 int check_ambiguity;
1576 package_name = argv[0];
1578 override = params->override;
1579 initialize = params->initialize;
1580 check_required = params->check_required;
1581 check_ambiguity = params->check_ambiguity;
1584 cmdline_parser_clitkResampleImage_init (args_info);
1586 cmdline_parser_clitkResampleImage_init (&local_args_info);
1590 opterr = params->print_errors;
1595 int option_index = 0;
1597 static struct option long_options[] = {
1598 { "help", 0, NULL, 'h' },
1599 { "version", 0, NULL, 'V' },
1600 { "config", 1, NULL, 0 },
1601 { "verbose", 0, NULL, 'v' },
1602 { "imagetypes", 0, NULL, 0 },
1603 { "thread", 1, NULL, 0 },
1604 { "input", 1, NULL, 'i' },
1605 { "output", 1, NULL, 'o' },
1606 { "like", 1, NULL, 'l' },
1607 { "size", 1, NULL, 0 },
1608 { "spacing", 1, NULL, 0 },
1609 { "default", 1, NULL, 'd' },
1610 { "time", 0, NULL, 't' },
1611 { "interp", 1, NULL, 0 },
1612 { "order", 1, NULL, 'b' },
1613 { "sampling", 1, NULL, 's' },
1614 { "gauss", 1, NULL, 'g' },
1615 { "autogauss", 0, NULL, 'a' },
1616 { NULL, 0, NULL, 0 }
1619 custom_optarg = optarg;
1620 custom_optind = optind;
1621 custom_opterr = opterr;
1622 custom_optopt = optopt;
1624 c = custom_getopt_long (argc, argv, "hVvi:o:l:d:tb:s:g:a", long_options, &option_index);
1626 optarg = custom_optarg;
1627 optind = custom_optind;
1628 opterr = custom_opterr;
1629 optopt = custom_optopt;
1631 if (c == -1) break; /* Exit from `while (1)' loop. */
1635 case 'h': /* Print help and exit. */
1636 cmdline_parser_clitkResampleImage_print_help ();
1637 cmdline_parser_clitkResampleImage_free (&local_args_info);
1638 exit (EXIT_SUCCESS);
1640 case 'V': /* Print version and exit. */
1641 cmdline_parser_clitkResampleImage_print_version ();
1642 cmdline_parser_clitkResampleImage_free (&local_args_info);
1643 exit (EXIT_SUCCESS);
1645 case 'v': /* Verbose. */
1648 if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
1649 &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
1650 check_ambiguity, override, 1, 0, "verbose", 'v',
1655 case 'i': /* Input image filename. */
1658 if (update_arg( (void *)&(args_info->input_arg),
1659 &(args_info->input_orig), &(args_info->input_given),
1660 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1661 check_ambiguity, override, 0, 0,
1667 case 'o': /* Output image filename. */
1670 if (update_arg( (void *)&(args_info->output_arg),
1671 &(args_info->output_orig), &(args_info->output_given),
1672 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1673 check_ambiguity, override, 0, 0,
1679 case 'l': /* Resample like this image. */
1682 if (update_arg( (void *)&(args_info->like_arg),
1683 &(args_info->like_orig), &(args_info->like_given),
1684 &(local_args_info.like_given), optarg, 0, 0, ARG_STRING,
1685 check_ambiguity, override, 0, 0,
1691 case 'd': /* Default pixel value. */
1694 if (update_arg( (void *)&(args_info->default_arg),
1695 &(args_info->default_orig), &(args_info->default_given),
1696 &(local_args_info.default_given), optarg, 0, "0.0", ARG_FLOAT,
1697 check_ambiguity, override, 0, 0,
1703 case 't': /* Last Dimension Is Time -> do not resample it (auto on for 4D). */
1706 if (update_arg((void *)&(args_info->time_flag), 0, &(args_info->time_given),
1707 &(local_args_info.time_given), optarg, 0, 0, ARG_FLAG,
1708 check_ambiguity, override, 1, 0, "time", 't',
1713 case 'b': /* BSpline ordre (range 0-5). */
1716 if (update_arg( (void *)&(args_info->order_arg),
1717 &(args_info->order_orig), &(args_info->order_given),
1718 &(local_args_info.order_given), optarg, 0, "3", ARG_INT,
1719 check_ambiguity, override, 0, 0,
1725 case 's': /* BLUT sampling value. */
1728 if (update_arg( (void *)&(args_info->sampling_arg),
1729 &(args_info->sampling_orig), &(args_info->sampling_given),
1730 &(local_args_info.sampling_given), optarg, 0, "30", ARG_INT,
1731 check_ambiguity, override, 0, 0,
1737 case 'g': /* Apply Gaussian before (sigma in mm). */
1739 if (update_multiple_arg_temp(&gauss_list,
1740 &(local_args_info.gauss_given), optarg, 0, "0.0", ARG_FLOAT,
1746 case 'a': /* Apply Gaussian with auto sigma when downsample. */
1749 if (update_arg((void *)&(args_info->autogauss_flag), 0, &(args_info->autogauss_given),
1750 &(local_args_info.autogauss_given), optarg, 0, 0, ARG_FLAG,
1751 check_ambiguity, override, 1, 0, "autogauss", 'a',
1757 case 0: /* Long option with no short option */
1759 if (strcmp (long_options[option_index].name, "config") == 0)
1763 if (update_arg( (void *)&(args_info->config_arg),
1764 &(args_info->config_orig), &(args_info->config_given),
1765 &(local_args_info.config_given), optarg, 0, 0, ARG_STRING,
1766 check_ambiguity, override, 0, 0,
1772 /* Verbose: allowed image types. */
1773 else if (strcmp (long_options[option_index].name, "imagetypes") == 0)
1777 if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given),
1778 &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG,
1779 check_ambiguity, override, 1, 0, "imagetypes", '-',
1784 /* Nb of thread to use (default=max). */
1785 else if (strcmp (long_options[option_index].name, "thread") == 0)
1789 if (update_arg( (void *)&(args_info->thread_arg),
1790 &(args_info->thread_orig), &(args_info->thread_given),
1791 &(local_args_info.thread_given), optarg, 0, 0, ARG_INT,
1792 check_ambiguity, override, 0, 0,
1798 /* Number of pixels of each coordonate. */
1799 else if (strcmp (long_options[option_index].name, "size") == 0)
1802 if (update_multiple_arg_temp(&size_list,
1803 &(local_args_info.size_given), optarg, 0, "0", ARG_INT,
1809 /* Spacing in mm between pixels. */
1810 else if (strcmp (long_options[option_index].name, "spacing") == 0)
1813 if (update_multiple_arg_temp(&spacing_list,
1814 &(local_args_info.spacing_given), optarg, 0, "-1.0", ARG_FLOAT,
1820 /* Interpolation type: {nn, linear, bspline, blut}. */
1821 else if (strcmp (long_options[option_index].name, "interp") == 0)
1825 if (update_arg( (void *)&(args_info->interp_arg),
1826 &(args_info->interp_orig), &(args_info->interp_given),
1827 &(local_args_info.interp_given), optarg, 0, "nn", ARG_STRING,
1828 check_ambiguity, override, 0, 0,
1836 case '?': /* Invalid option. */
1837 /* `getopt_long' already printed an error message. */
1840 default: /* bug: option not considered. */
1841 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, c, (additional_error ? additional_error : ""));
1847 update_multiple_arg((void *)&(args_info->size_arg),
1848 &(args_info->size_orig), args_info->size_given,
1849 local_args_info.size_given, 0 ,
1850 ARG_INT, size_list);
1851 multiple_default_value.float_arg = -1.0;
1852 update_multiple_arg((void *)&(args_info->spacing_arg),
1853 &(args_info->spacing_orig), args_info->spacing_given,
1854 local_args_info.spacing_given, &multiple_default_value ,
1855 ARG_FLOAT, spacing_list);
1856 multiple_default_value.float_arg = 0.0;
1857 update_multiple_arg((void *)&(args_info->gauss_arg),
1858 &(args_info->gauss_orig), args_info->gauss_given,
1859 local_args_info.gauss_given, &multiple_default_value ,
1860 ARG_FLOAT, gauss_list);
1862 args_info->size_given += local_args_info.size_given;
1863 local_args_info.size_given = 0;
1864 args_info->spacing_given += local_args_info.spacing_given;
1865 local_args_info.spacing_given = 0;
1866 args_info->gauss_given += local_args_info.gauss_given;
1867 local_args_info.gauss_given = 0;
1871 error += cmdline_parser_clitkResampleImage_required2 (args_info, argv[0], additional_error);
1874 cmdline_parser_clitkResampleImage_release (&local_args_info);
1877 return (EXIT_FAILURE);
1882 int found_prog_name = 0;
1883 /* whether program name, i.e., argv[0], is in the remaining args
1884 (this may happen with some implementations of getopt,
1885 but surely not with the one included by gengetopt) */
1888 args_info->inputs_num = argc - optind - found_prog_name;
1890 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1891 while (optind < argc)
1892 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1898 free_list (size_list, 0 );
1899 free_list (spacing_list, 0 );
1900 free_list (gauss_list, 0 );
1902 cmdline_parser_clitkResampleImage_release (&local_args_info);
1903 return (EXIT_FAILURE);
1906 #ifndef CONFIG_FILE_LINE_SIZE
1907 #define CONFIG_FILE_LINE_SIZE 2048
1909 #define ADDITIONAL_ERROR " in configuration file "
1911 #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1912 /* 3 is for "--" and "=" */
1915 _cmdline_parser_clitkResampleImage_configfile (char * const filename, int *my_argc)
1918 char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
1919 char linebuf[CONFIG_FILE_LINE_SIZE];
1921 int result = 0, equal;
1924 size_t len, next_token;
1927 if ((file = fopen(filename, "r")) == NULL)
1929 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
1930 CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename);
1931 return EXIT_FAILURE;
1934 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
1938 len = strlen(linebuf);
1939 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
1941 fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
1942 CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename, line_num);
1943 result = EXIT_FAILURE;
1947 /* find first non-whitespace character in the line */
1948 next_token = strspn (linebuf, " \t\r\n");
1949 str_index = linebuf + next_token;
1951 if ( str_index[0] == '\0' || str_index[0] == '#')
1952 continue; /* empty line or comment line is skipped */
1956 /* truncate fopt at the end of the first non-valid character */
1957 next_token = strcspn (fopt, " \t\r\n=");
1959 if (fopt[next_token] == '\0') /* the line is over */
1966 /* remember if equal sign is present */
1967 equal = (fopt[next_token] == '=');
1968 fopt[next_token++] = '\0';
1970 /* advance pointers to the next token after the end of fopt */
1971 next_token += strspn (fopt + next_token, " \t\r\n");
1973 /* check for the presence of equal sign, and if so, skip it */
1975 if ((equal = (fopt[next_token] == '=')))
1978 next_token += strspn (fopt + next_token, " \t\r\n");
1980 str_index += next_token;
1984 if ( farg[0] == '\"' || farg[0] == '\'' )
1985 { /* quoted argument */
1986 str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
1991 "%s:%s:%d: unterminated string in configuration file\n",
1992 CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename, line_num);
1993 result = EXIT_FAILURE;
1998 { /* read up the remaining part up to a delimiter */
1999 next_token = strcspn (farg, " \t\r\n#\'\"");
2000 str_index += next_token;
2003 /* truncate farg at the delimiter and store it for further check */
2004 delimiter = *str_index, *str_index++ = '\0';
2006 /* everything but comment is illegal at the end of line */
2007 if (delimiter != '\0' && delimiter != '#')
2009 str_index += strspn(str_index, " \t\r\n");
2010 if (*str_index != '\0' && *str_index != '#')
2014 "%s:%s:%d: malformed string in configuration file\n",
2015 CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename, line_num);
2016 result = EXIT_FAILURE;
2022 if (!strcmp(fopt,"include")) {
2023 if (farg && *farg) {
2024 result = _cmdline_parser_clitkResampleImage_configfile(farg, my_argc);
2026 fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n",
2027 CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE, filename, line_num);
2032 strcat (my_argv, len > 1 ? "--" : "-");
2033 strcat (my_argv, fopt);
2034 if (len > 1 && ((farg && *farg) || equal))
2035 strcat (my_argv, "=");
2037 strcat (my_argv, farg);
2040 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
2041 cmd_line_list_tmp->next = cmd_line_list;
2042 cmd_line_list = cmd_line_list_tmp;
2043 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
2052 cmdline_parser_clitkResampleImage_configfile (char * const filename,
2053 struct args_info_clitkResampleImage *args_info,
2054 int override, int initialize, int check_required)
2056 struct cmdline_parser_clitkResampleImage_params params;
2058 params.override = override;
2059 params.initialize = initialize;
2060 params.check_required = check_required;
2061 params.check_ambiguity = 0;
2062 params.print_errors = 1;
2064 return cmdline_parser_clitkResampleImage_config_file (filename, args_info, ¶ms);
2068 cmdline_parser_clitkResampleImage_config_file (char * const filename,
2069 struct args_info_clitkResampleImage *args_info,
2070 struct cmdline_parser_clitkResampleImage_params *params)
2075 char *additional_error;
2077 /* store the program name */
2078 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
2079 cmd_line_list_tmp->next = cmd_line_list;
2080 cmd_line_list = cmd_line_list_tmp;
2081 cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKRESAMPLEIMAGE_PACKAGE);
2083 result = _cmdline_parser_clitkResampleImage_configfile(filename, &my_argc);
2085 if (result != EXIT_FAILURE) {
2086 my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
2087 cmd_line_list_tmp = cmd_line_list;
2089 for (i = my_argc - 1; i >= 0; --i) {
2090 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
2091 cmd_line_list_tmp = cmd_line_list_tmp->next;
2094 my_argv_arg[my_argc] = 0;
2096 additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
2097 strcpy (additional_error, ADDITIONAL_ERROR);
2098 strcat (additional_error, filename);
2100 cmdline_parser_clitkResampleImage_internal (my_argc, my_argv_arg, args_info,
2104 free (additional_error);
2109 if (result == EXIT_FAILURE)
2111 cmdline_parser_clitkResampleImage_free (args_info);
2112 exit (EXIT_FAILURE);