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_clitkCropImage --func-name=cmdline_parser_clitkCropImage --file-name=clitkCropImage_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 "clitkCropImage_ggo.h"
23 const char *args_info_clitkCropImage_purpose = "Crop an image according to a given extends or AutoCrop with a background value \nor like another image";
25 const char *args_info_clitkCropImage_usage = "Usage: clitkCropImage [OPTIONS]... [FILES]...";
27 const char *args_info_clitkCropImage_description = "";
29 const char *args_info_clitkCropImage_help[] = {
30 " -h, --help Print help and exit",
31 " -V, --version Print version and exit",
32 " --config=STRING Config file",
33 " --imagetypes Display allowed image types (default=off)",
34 " -v, --verbose Verbose (default=off)",
35 " --verboseOption Display options values (default=off)",
36 " --verboseWarningOff Do not display warning (default=off)",
38 " -i, --input=STRING Input image filename",
39 " -o, --output=STRING Output image filename",
40 "\nUsed determined crop:",
41 " -b, --boundingBox=INT Bounding box of the crop region (in 3D: \n =x1,x2,y1,y2,z1,z2)",
42 " -l, --lower=INT Size of the lower crop region (multiple values)",
43 " -u, --upper=INT Size of the upper crop region (multiple values)",
44 " --origin Set new origin to zero (default=off)",
45 "\nAutoCrop with BG value:",
46 " --BG=DOUBLE Background value in input. (default=`0')",
47 "\nCrop like another image:",
48 " --like=STRING Crop like this image (must have the same spacing",
49 " --BGLike=DOUBLE Background value in output (if like larger) \n (default=`0')",
58 } cmdline_parser_clitkCropImage_arg_type;
61 void clear_given (struct args_info_clitkCropImage *args_info);
63 void clear_args (struct args_info_clitkCropImage *args_info);
66 cmdline_parser_clitkCropImage_internal (int argc, char * const *argv, struct args_info_clitkCropImage *args_info,
67 struct cmdline_parser_clitkCropImage_params *params, const char *additional_error);
70 cmdline_parser_clitkCropImage_required2 (struct args_info_clitkCropImage *args_info, const char *prog_name, const char *additional_error);
74 struct line_list * next;
77 static struct line_list *cmd_line_list = 0;
78 static struct line_list *cmd_line_list_tmp = 0;
83 /* free the list of a previous call */
86 while (cmd_line_list) {
87 cmd_line_list_tmp = cmd_line_list;
88 cmd_line_list = cmd_line_list->next;
89 free (cmd_line_list_tmp->string_arg);
90 free (cmd_line_list_tmp);
97 gengetopt_strdup (const char *s);
100 void clear_given (struct args_info_clitkCropImage *args_info)
102 args_info->help_given = 0 ;
103 args_info->version_given = 0 ;
104 args_info->config_given = 0 ;
105 args_info->imagetypes_given = 0 ;
106 args_info->verbose_given = 0 ;
107 args_info->verboseOption_given = 0 ;
108 args_info->verboseWarningOff_given = 0 ;
109 args_info->input_given = 0 ;
110 args_info->output_given = 0 ;
111 args_info->boundingBox_given = 0 ;
112 args_info->lower_given = 0 ;
113 args_info->upper_given = 0 ;
114 args_info->origin_given = 0 ;
115 args_info->BG_given = 0 ;
116 args_info->like_given = 0 ;
117 args_info->BGLike_given = 0 ;
121 void clear_args (struct args_info_clitkCropImage *args_info)
123 args_info->config_arg = NULL;
124 args_info->config_orig = NULL;
125 args_info->imagetypes_flag = 0;
126 args_info->verbose_flag = 0;
127 args_info->verboseOption_flag = 0;
128 args_info->verboseWarningOff_flag = 0;
129 args_info->input_arg = NULL;
130 args_info->input_orig = NULL;
131 args_info->output_arg = NULL;
132 args_info->output_orig = NULL;
133 args_info->boundingBox_arg = NULL;
134 args_info->boundingBox_orig = NULL;
135 args_info->lower_arg = NULL;
136 args_info->lower_orig = NULL;
137 args_info->upper_arg = NULL;
138 args_info->upper_orig = NULL;
139 args_info->origin_flag = 0;
140 args_info->BG_arg = 0;
141 args_info->BG_orig = NULL;
142 args_info->like_arg = NULL;
143 args_info->like_orig = NULL;
144 args_info->BGLike_arg = 0;
145 args_info->BGLike_orig = NULL;
150 void init_args_info(struct args_info_clitkCropImage *args_info)
154 args_info->help_help = args_info_clitkCropImage_help[0] ;
155 args_info->version_help = args_info_clitkCropImage_help[1] ;
156 args_info->config_help = args_info_clitkCropImage_help[2] ;
157 args_info->imagetypes_help = args_info_clitkCropImage_help[3] ;
158 args_info->verbose_help = args_info_clitkCropImage_help[4] ;
159 args_info->verboseOption_help = args_info_clitkCropImage_help[5] ;
160 args_info->verboseWarningOff_help = args_info_clitkCropImage_help[6] ;
161 args_info->input_help = args_info_clitkCropImage_help[8] ;
162 args_info->output_help = args_info_clitkCropImage_help[9] ;
163 args_info->boundingBox_help = args_info_clitkCropImage_help[11] ;
164 args_info->boundingBox_min = -1;
165 args_info->boundingBox_max = -1;
166 args_info->lower_help = args_info_clitkCropImage_help[12] ;
167 args_info->lower_min = -1;
168 args_info->lower_max = -1;
169 args_info->upper_help = args_info_clitkCropImage_help[13] ;
170 args_info->upper_min = -1;
171 args_info->upper_max = -1;
172 args_info->origin_help = args_info_clitkCropImage_help[14] ;
173 args_info->BG_help = args_info_clitkCropImage_help[16] ;
174 args_info->like_help = args_info_clitkCropImage_help[18] ;
175 args_info->BGLike_help = args_info_clitkCropImage_help[19] ;
180 cmdline_parser_clitkCropImage_print_version (void)
182 printf ("%s %s\n", CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, CMDLINE_PARSER_CLITKCROPIMAGE_VERSION);
185 static void print_help_common(void) {
186 cmdline_parser_clitkCropImage_print_version ();
188 if (strlen(args_info_clitkCropImage_purpose) > 0)
189 printf("\n%s\n", args_info_clitkCropImage_purpose);
191 if (strlen(args_info_clitkCropImage_usage) > 0)
192 printf("\n%s\n", args_info_clitkCropImage_usage);
196 if (strlen(args_info_clitkCropImage_description) > 0)
197 printf("%s\n", args_info_clitkCropImage_description);
201 cmdline_parser_clitkCropImage_print_help (void)
205 while (args_info_clitkCropImage_help[i])
206 printf("%s\n", args_info_clitkCropImage_help[i++]);
210 cmdline_parser_clitkCropImage_init (struct args_info_clitkCropImage *args_info)
212 clear_given (args_info);
213 clear_args (args_info);
214 init_args_info (args_info);
216 args_info->inputs = NULL;
217 args_info->inputs_num = 0;
221 cmdline_parser_clitkCropImage_params_init(struct cmdline_parser_clitkCropImage_params *params)
225 params->override = 0;
226 params->initialize = 1;
227 params->check_required = 1;
228 params->check_ambiguity = 0;
229 params->print_errors = 1;
233 struct cmdline_parser_clitkCropImage_params *
234 cmdline_parser_clitkCropImage_params_create(void)
236 struct cmdline_parser_clitkCropImage_params *params =
237 (struct cmdline_parser_clitkCropImage_params *)malloc(sizeof(struct cmdline_parser_clitkCropImage_params));
238 cmdline_parser_clitkCropImage_params_init(params);
243 free_string_field (char **s)
252 /** @brief generic value variable */
253 union generic_value {
259 /** @brief holds temporary values for multiple options */
262 union generic_value arg;
264 struct generic_list *next;
268 * @brief add a node at the head of the list
270 static void add_node(struct generic_list **list) {
271 struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list));
272 new_node->next = *list;
274 new_node->arg.string_arg = NULL;
275 new_node->orig = NULL;
279 free_multiple_field(unsigned int len, void **arg, char ***orig)
283 for (i = 0; i < len; ++i)
285 free_string_field(&((*orig)[i]));
297 cmdline_parser_clitkCropImage_release (struct args_info_clitkCropImage *args_info)
300 free_string_field (&(args_info->config_arg));
301 free_string_field (&(args_info->config_orig));
302 free_string_field (&(args_info->input_arg));
303 free_string_field (&(args_info->input_orig));
304 free_string_field (&(args_info->output_arg));
305 free_string_field (&(args_info->output_orig));
306 free_multiple_field (args_info->boundingBox_given, (void **)&(args_info->boundingBox_arg), &(args_info->boundingBox_orig));
307 free_multiple_field (args_info->lower_given, (void **)&(args_info->lower_arg), &(args_info->lower_orig));
308 free_multiple_field (args_info->upper_given, (void **)&(args_info->upper_arg), &(args_info->upper_orig));
309 free_string_field (&(args_info->BG_orig));
310 free_string_field (&(args_info->like_arg));
311 free_string_field (&(args_info->like_orig));
312 free_string_field (&(args_info->BGLike_orig));
315 for (i = 0; i < args_info->inputs_num; ++i)
316 free (args_info->inputs [i]);
318 if (args_info->inputs_num)
319 free (args_info->inputs);
321 clear_given (args_info);
326 write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
329 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
331 fprintf(outfile, "%s\n", opt);
336 write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[])
340 for (i = 0; i < len; ++i)
341 write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
345 cmdline_parser_clitkCropImage_dump(FILE *outfile, struct args_info_clitkCropImage *args_info)
351 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE);
355 if (args_info->help_given)
356 write_into_file(outfile, "help", 0, 0 );
357 if (args_info->version_given)
358 write_into_file(outfile, "version", 0, 0 );
359 if (args_info->config_given)
360 write_into_file(outfile, "config", args_info->config_orig, 0);
361 if (args_info->imagetypes_given)
362 write_into_file(outfile, "imagetypes", 0, 0 );
363 if (args_info->verbose_given)
364 write_into_file(outfile, "verbose", 0, 0 );
365 if (args_info->verboseOption_given)
366 write_into_file(outfile, "verboseOption", 0, 0 );
367 if (args_info->verboseWarningOff_given)
368 write_into_file(outfile, "verboseWarningOff", 0, 0 );
369 if (args_info->input_given)
370 write_into_file(outfile, "input", args_info->input_orig, 0);
371 if (args_info->output_given)
372 write_into_file(outfile, "output", args_info->output_orig, 0);
373 write_multiple_into_file(outfile, args_info->boundingBox_given, "boundingBox", args_info->boundingBox_orig, 0);
374 write_multiple_into_file(outfile, args_info->lower_given, "lower", args_info->lower_orig, 0);
375 write_multiple_into_file(outfile, args_info->upper_given, "upper", args_info->upper_orig, 0);
376 if (args_info->origin_given)
377 write_into_file(outfile, "origin", 0, 0 );
378 if (args_info->BG_given)
379 write_into_file(outfile, "BG", args_info->BG_orig, 0);
380 if (args_info->like_given)
381 write_into_file(outfile, "like", args_info->like_orig, 0);
382 if (args_info->BGLike_given)
383 write_into_file(outfile, "BGLike", args_info->BGLike_orig, 0);
391 cmdline_parser_clitkCropImage_file_save(const char *filename, struct args_info_clitkCropImage *args_info)
396 outfile = fopen(filename, "w");
400 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename);
404 i = cmdline_parser_clitkCropImage_dump(outfile, args_info);
411 cmdline_parser_clitkCropImage_free (struct args_info_clitkCropImage *args_info)
413 cmdline_parser_clitkCropImage_release (args_info);
416 /** @brief replacement of strdup, which is not standard */
418 gengetopt_strdup (const char *s)
424 result = (char*)malloc(strlen(s) + 1);
425 if (result == (char*)0)
432 get_multiple_arg_token(const char *arg)
435 size_t len, num_of_escape, i, j;
440 tok = strchr (arg, ',');
443 /* make sure it is not escaped */
446 if (*(tok-1) == '\\')
448 /* find the next one */
449 tok = strchr (tok+1, ',');
457 len = (size_t)(tok - arg + 1);
459 len = strlen (arg) + 1;
461 len -= num_of_escape;
463 ret = (char *) malloc (len);
467 while (arg[i] && (j < len-1))
469 if (arg[i] == '\\' &&
483 get_multiple_arg_token_next(const char *arg)
490 tok = strchr (arg, ',');
492 /* make sure it is not escaped */
495 if (*(tok-1) == '\\')
497 /* find the next one */
498 tok = strchr (tok+1, ',');
504 if (! tok || strlen(tok) == 1)
511 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc);
514 check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc)
518 if (option_given && ! (min < 0 && max < 0))
520 if (min >= 0 && max >= 0)
524 /* specific occurrences */
525 if (option_given != min)
527 fprintf (stderr, "%s: %s option occurrences must be %d\n",
528 prog_name, option_desc, min);
532 else if (option_given < min
533 || option_given > max)
535 /* range occurrences */
536 fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n",
537 prog_name, option_desc, min, max);
544 if (option_given < min)
546 fprintf (stderr, "%s: %s option occurrences must be at least %d\n",
547 prog_name, option_desc, min);
554 if (option_given > max)
556 fprintf (stderr, "%s: %s option occurrences must be at most %d\n",
557 prog_name, option_desc, max);
566 cmdline_parser_clitkCropImage (int argc, char * const *argv, struct args_info_clitkCropImage *args_info)
568 return cmdline_parser_clitkCropImage2 (argc, argv, args_info, 0, 1, 1);
572 cmdline_parser_clitkCropImage_ext (int argc, char * const *argv, struct args_info_clitkCropImage *args_info,
573 struct cmdline_parser_clitkCropImage_params *params)
576 result = cmdline_parser_clitkCropImage_internal (argc, argv, args_info, params, NULL);
578 if (result == EXIT_FAILURE)
580 cmdline_parser_clitkCropImage_free (args_info);
588 cmdline_parser_clitkCropImage2 (int argc, char * const *argv, struct args_info_clitkCropImage *args_info, int override, int initialize, int check_required)
591 struct cmdline_parser_clitkCropImage_params params;
593 params.override = override;
594 params.initialize = initialize;
595 params.check_required = check_required;
596 params.check_ambiguity = 0;
597 params.print_errors = 1;
599 result = cmdline_parser_clitkCropImage_internal (argc, argv, args_info, ¶ms, NULL);
601 if (result == EXIT_FAILURE)
603 cmdline_parser_clitkCropImage_free (args_info);
611 cmdline_parser_clitkCropImage_required (struct args_info_clitkCropImage *args_info, const char *prog_name)
613 int result = EXIT_SUCCESS;
615 if (cmdline_parser_clitkCropImage_required2(args_info, prog_name, NULL) > 0)
616 result = EXIT_FAILURE;
618 if (result == EXIT_FAILURE)
620 cmdline_parser_clitkCropImage_free (args_info);
628 cmdline_parser_clitkCropImage_required2 (struct args_info_clitkCropImage *args_info, const char *prog_name, const char *additional_error)
632 /* checks for required options */
633 if (! args_info->input_given)
635 fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
639 if (! args_info->output_given)
641 fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
645 if (check_multiple_option_occurrences(prog_name, args_info->boundingBox_given, args_info->boundingBox_min, args_info->boundingBox_max, "'--boundingBox' ('-b')"))
648 if (check_multiple_option_occurrences(prog_name, args_info->lower_given, args_info->lower_min, args_info->lower_max, "'--lower' ('-l')"))
651 if (check_multiple_option_occurrences(prog_name, args_info->upper_given, args_info->upper_min, args_info->upper_max, "'--upper' ('-u')"))
655 /* checks for dependences among options */
661 * Extracted from the glibc source tree, version 2.3.6
663 * Licensed under the GPL as per the whole glibc source tree.
665 * This file was modified so that getopt_long can be called
666 * many times without risking previous memory to be spoiled.
668 * Modified by Andre Noll and Lorenzo Bettini for use in
669 * GNU gengetopt generated files.
674 * we must include anything we need since this file is not thought to be
675 * inserted in a file already using getopt.h
683 /* has_arg can't be an enum because some compilers complain about
684 type mismatches in all the code that assumes it is an int. */
690 /* For communication from `getopt' to the caller.
691 When `getopt' finds an option that takes an argument,
692 the argument value is returned here.
693 Also, when `ordering' is RETURN_IN_ORDER,
694 each non-option ARGV-element is returned here. */
698 /* Index in ARGV of the next element to be scanned.
699 This is used for communication to and from the caller
700 and for communication between successive calls to `getopt'.
702 On entry to `getopt', zero means this is the first call; initialize.
704 When `getopt' returns -1, this is the index of the first of the
705 non-option elements that the caller should itself scan.
707 Otherwise, `optind' communicates from one call to the next
708 how much of ARGV has been scanned so far. */
712 /* Callers store zero here to inhibit the error message `getopt' prints
713 for unrecognized options. */
717 /* Set to an option character which was unrecognized. */
721 /* This version of `getopt' appears to the caller like standard Unix `getopt'
722 but it behaves differently for the user, since it allows the user
723 to intersperse the options with the other arguments.
725 As `getopt' works, it permutes the elements of ARGV so that,
726 when it is done, all the options precede everything else. Thus
727 all application programs are extended to handle flexible argument order.
730 If the field `flag' is not NULL, it points to a variable that is set
731 to the value given in the field `val' when the option is found, but
732 left unchanged if the option is not found.
734 To have a long-named option do something other than set an `int' to
735 a compiled-in constant, such as set a value from `custom_optarg', set the
736 option's `flag' field to zero and its `val' field to a nonzero
737 value (the equivalent single-letter option character, if there is
738 one). For long options that have a zero `flag' field, `getopt'
739 returns the contents of the `val' field. */
741 /* Names for the values of the `has_arg' field of `struct option'. */
743 #define no_argument 0
746 #ifndef required_argument
747 #define required_argument 1
750 #ifndef optional_argument
751 #define optional_argument 2
754 struct custom_getopt_data {
756 * These have exactly the same meaning as the corresponding global variables,
757 * except that they are used for the reentrant versions of getopt.
764 /* True if the internal members have been initialized. */
768 * The next char to be scanned in the option-element in which the last option
769 * character we returned was found. This allows us to pick up the scan where
770 * we left off. If this is zero, or a null string, it means resume the scan by
771 * advancing to the next ARGV-element.
776 * Describe the part of ARGV that contains non-options that have been skipped.
777 * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is
778 * the index after the last of them.
785 * the variables optarg, optind, opterr and optopt are renamed with
786 * the custom_ prefix so that they don't interfere with getopt ones.
788 * Moreover they're static so they are visible only from within the
789 * file where this very file will be included.
793 * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an
794 * option that takes an argument, the argument value is returned here.
796 static char *custom_optarg;
799 * Index in ARGV of the next element to be scanned. This is used for
800 * communication to and from the caller and for communication between
801 * successive calls to `custom_getopt'.
803 * On entry to `custom_getopt', 1 means this is the first call; initialize.
805 * When `custom_getopt' returns -1, this is the index of the first of the non-option
806 * elements that the caller should itself scan.
808 * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV
809 * has been scanned so far.
811 * 1003.2 says this must be 1 before any call.
813 static int custom_optind = 1;
816 * Callers store zero here to inhibit the error message for unrecognized
819 static int custom_opterr = 1;
822 * Set to an option character which was unrecognized. This must be initialized
823 * on some systems to avoid linking in the system's own getopt implementation.
825 static int custom_optopt = '?';
828 * Exchange two adjacent subsequences of ARGV. One subsequence is elements
829 * [first_nonopt,last_nonopt) which contains all the non-options that have been
830 * skipped so far. The other is elements [last_nonopt,custom_optind), which contains
831 * all the options processed since those non-options were skipped.
832 * `first_nonopt' and `last_nonopt' are relocated so that they describe the new
833 * indices of the non-options in ARGV after they are moved.
835 static void exchange(char **argv, struct custom_getopt_data *d)
837 int bottom = d->first_nonopt;
838 int middle = d->last_nonopt;
839 int top = d->custom_optind;
843 * Exchange the shorter segment with the far end of the longer segment.
844 * That puts the shorter segment into the right place. It leaves the
845 * longer segment in the right place overall, but it consists of two
846 * parts that need to be swapped next.
848 while (top > middle && middle > bottom) {
849 if (top - middle > middle - bottom) {
850 /* Bottom segment is the short one. */
851 int len = middle - bottom;
854 /* Swap it with the top part of the top segment. */
855 for (i = 0; i < len; i++) {
856 tem = argv[bottom + i];
858 argv[top - (middle - bottom) + i];
859 argv[top - (middle - bottom) + i] = tem;
861 /* Exclude the moved bottom segment from further swapping. */
864 /* Top segment is the short one. */
865 int len = top - middle;
868 /* Swap it with the bottom part of the bottom segment. */
869 for (i = 0; i < len; i++) {
870 tem = argv[bottom + i];
871 argv[bottom + i] = argv[middle + i];
872 argv[middle + i] = tem;
874 /* Exclude the moved top segment from further swapping. */
878 /* Update records for the slots the non-options now occupy. */
879 d->first_nonopt += (d->custom_optind - d->last_nonopt);
880 d->last_nonopt = d->custom_optind;
883 /* Initialize the internal data when the first call is made. */
884 static void custom_getopt_initialize(struct custom_getopt_data *d)
887 * Start processing options with ARGV-element 1 (since ARGV-element 0
888 * is the program name); the sequence of previously skipped non-option
889 * ARGV-elements is empty.
891 d->first_nonopt = d->last_nonopt = d->custom_optind;
896 #define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0')
898 /* return: zero: continue, nonzero: return given value to user */
899 static int shuffle_argv(int argc, char *const *argv,const struct option *longopts,
900 struct custom_getopt_data *d)
903 * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been
904 * moved back by the user (who may also have changed the arguments).
906 if (d->last_nonopt > d->custom_optind)
907 d->last_nonopt = d->custom_optind;
908 if (d->first_nonopt > d->custom_optind)
909 d->first_nonopt = d->custom_optind;
911 * If we have just processed some options following some
912 * non-options, exchange them so that the options come first.
914 if (d->first_nonopt != d->last_nonopt &&
915 d->last_nonopt != d->custom_optind)
916 exchange((char **) argv, d);
917 else if (d->last_nonopt != d->custom_optind)
918 d->first_nonopt = d->custom_optind;
920 * Skip any additional non-options and extend the range of
921 * non-options previously skipped.
923 while (d->custom_optind < argc && NONOPTION_P)
925 d->last_nonopt = d->custom_optind;
927 * The special ARGV-element `--' means premature end of options. Skip
928 * it like a null option, then exchange with previous non-options as if
929 * it were an option, then skip everything else like a non-option.
931 if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) {
933 if (d->first_nonopt != d->last_nonopt
934 && d->last_nonopt != d->custom_optind)
935 exchange((char **) argv, d);
936 else if (d->first_nonopt == d->last_nonopt)
937 d->first_nonopt = d->custom_optind;
938 d->last_nonopt = argc;
939 d->custom_optind = argc;
942 * If we have done all the ARGV-elements, stop the scan and back over
943 * any non-options that we skipped and permuted.
945 if (d->custom_optind == argc) {
947 * Set the next-arg-index to point at the non-options that we
948 * previously skipped, so the caller will digest them.
950 if (d->first_nonopt != d->last_nonopt)
951 d->custom_optind = d->first_nonopt;
955 * If we have come to a non-option and did not permute it, either stop
956 * the scan or describe it to the caller and pass it by.
959 d->custom_optarg = argv[d->custom_optind++];
963 * We have found another option-ARGV-element. Skip the initial
966 d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-'));
971 * Check whether the ARGV-element is a long option.
973 * If there's a long option "fubar" and the ARGV-element is "-fu", consider
974 * that an abbreviation of the long option, just like "--fu", and not "-f" with
977 * This distinction seems to be the most useful approach.
980 static int check_long_opt(int argc, char *const *argv, const char *optstring,
981 const struct option *longopts, int *longind,
982 int print_errors, struct custom_getopt_data *d)
985 const struct option *p;
986 const struct option *pfound = NULL;
992 for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++)
995 /* Test all long options for either exact match or abbreviated matches */
996 for (p = longopts, option_index = 0; p->name; p++, option_index++)
997 if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) {
998 if ((unsigned int) (nameend - d->nextchar)
999 == (unsigned int) strlen(p->name)) {
1000 /* Exact match found. */
1002 indfound = option_index;
1005 } else if (pfound == NULL) {
1006 /* First nonexact match found. */
1008 indfound = option_index;
1009 } else if (pfound->has_arg != p->has_arg
1010 || pfound->flag != p->flag
1011 || pfound->val != p->val)
1012 /* Second or later nonexact match found. */
1015 if (ambig && !exact) {
1018 "%s: option `%s' is ambiguous\n",
1019 argv[0], argv[d->custom_optind]);
1021 d->nextchar += strlen(d->nextchar);
1023 d->custom_optopt = 0;
1027 option_index = indfound;
1030 if (pfound->has_arg != no_argument)
1031 d->custom_optarg = nameend + 1;
1034 if (argv[d->custom_optind - 1][1] == '-') {
1036 fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n",
1037 argv[0], pfound->name);
1039 /* +option or -option */
1040 fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n",
1041 argv[0], argv[d->custom_optind - 1][0], pfound->name);
1045 d->nextchar += strlen(d->nextchar);
1046 d->custom_optopt = pfound->val;
1049 } else if (pfound->has_arg == required_argument) {
1050 if (d->custom_optind < argc)
1051 d->custom_optarg = argv[d->custom_optind++];
1055 "%s: option `%s' requires an argument\n",
1057 argv[d->custom_optind - 1]);
1059 d->nextchar += strlen(d->nextchar);
1060 d->custom_optopt = pfound->val;
1061 return optstring[0] == ':' ? ':' : '?';
1064 d->nextchar += strlen(d->nextchar);
1065 if (longind != NULL)
1066 *longind = option_index;
1068 *(pfound->flag) = pfound->val;
1074 * Can't find it as a long option. If this is not getopt_long_only, or
1075 * the option starts with '--' or is not a valid short option, then
1076 * it's an error. Otherwise interpret it as a short option.
1079 if (argv[d->custom_optind][1] == '-') {
1082 "%s: unrecognized option `--%s'\n",
1083 argv[0], d->nextchar);
1085 /* +option or -option */
1087 "%s: unrecognized option `%c%s'\n",
1088 argv[0], argv[d->custom_optind][0],
1092 d->nextchar = (char *) "";
1094 d->custom_optopt = 0;
1098 static int check_short_opt(int argc, char *const *argv, const char *optstring,
1099 int print_errors, struct custom_getopt_data *d)
1101 char c = *d->nextchar++;
1102 char *temp = strchr(optstring, c);
1104 /* Increment `custom_optind' when we start to process its last character. */
1105 if (*d->nextchar == '\0')
1107 if (!temp || c == ':') {
1109 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
1111 d->custom_optopt = c;
1114 if (temp[1] == ':') {
1115 if (temp[2] == ':') {
1116 /* This is an option that accepts an argument optionally. */
1117 if (*d->nextchar != '\0') {
1118 d->custom_optarg = d->nextchar;
1121 d->custom_optarg = NULL;
1124 /* This is an option that requires an argument. */
1125 if (*d->nextchar != '\0') {
1126 d->custom_optarg = d->nextchar;
1128 * If we end this ARGV-element by taking the
1129 * rest as an arg, we must advance to the next
1133 } else if (d->custom_optind == argc) {
1136 "%s: option requires an argument -- %c\n",
1139 d->custom_optopt = c;
1140 if (optstring[0] == ':')
1146 * We already incremented `custom_optind' once;
1147 * increment it again when taking next ARGV-elt
1150 d->custom_optarg = argv[d->custom_optind++];
1158 * Scan elements of ARGV for option characters given in OPTSTRING.
1160 * If an element of ARGV starts with '-', and is not exactly "-" or "--",
1161 * then it is an option element. The characters of this element
1162 * (aside from the initial '-') are option characters. If `getopt'
1163 * is called repeatedly, it returns successively each of the option characters
1164 * from each of the option elements.
1166 * If `getopt' finds another option character, it returns that character,
1167 * updating `custom_optind' and `nextchar' so that the next call to `getopt' can
1168 * resume the scan with the following option character or ARGV-element.
1170 * If there are no more option characters, `getopt' returns -1.
1171 * Then `custom_optind' is the index in ARGV of the first ARGV-element
1172 * that is not an option. (The ARGV-elements have been permuted
1173 * so that those that are not options now come last.)
1175 * OPTSTRING is a string containing the legitimate option characters.
1176 * If an option character is seen that is not listed in OPTSTRING,
1177 * return '?' after printing an error message. If you set `custom_opterr' to
1178 * zero, the error message is suppressed but we still return '?'.
1180 * If a char in OPTSTRING is followed by a colon, that means it wants an arg,
1181 * so the following text in the same ARGV-element, or the text of the following
1182 * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that
1183 * wants an optional arg; if there is text in the current ARGV-element,
1184 * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero.
1186 * If OPTSTRING starts with `-' or `+', it requests different methods of
1187 * handling the non-option ARGV-elements.
1188 * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
1190 * Long-named options begin with `--' instead of `-'.
1191 * Their names may be abbreviated as long as the abbreviation is unique
1192 * or is an exact match for some defined option. If they have an
1193 * argument, it follows the option name in the same ARGV-element, separated
1194 * from the option name by a `=', or else the in next ARGV-element.
1195 * When `getopt' finds a long-named option, it returns 0 if that option's
1196 * `flag' field is nonzero, the value of the option's `val' field
1197 * if the `flag' field is zero.
1199 * The elements of ARGV aren't really const, because we permute them.
1200 * But we pretend they're const in the prototype to be compatible
1201 * with other systems.
1203 * LONGOPTS is a vector of `struct option' terminated by an
1204 * element containing a name which is zero.
1206 * LONGIND returns the index in LONGOPT of the long-named option found.
1207 * It is only valid when a long-named option has been found by the most
1210 * Return the option character from OPTS just read. Return -1 when there are
1211 * no more options. For unrecognized options, or options missing arguments,
1212 * `custom_optopt' is set to the option letter, and '?' is returned.
1214 * The OPTS string is a list of characters which are recognized option letters,
1215 * optionally followed by colons, specifying that that letter takes an
1216 * argument, to be placed in `custom_optarg'.
1218 * If a letter in OPTS is followed by two colons, its argument is optional.
1219 * This behavior is specific to the GNU `getopt'.
1221 * The argument `--' causes premature termination of argument scanning,
1222 * explicitly telling `getopt' that there are no more options. If OPTS begins
1223 * with `--', then non-option arguments are treated as arguments to the option
1224 * '\0'. This behavior is specific to the GNU `getopt'.
1227 static int getopt_internal_r(int argc, char *const *argv, const char *optstring,
1228 const struct option *longopts, int *longind,
1229 struct custom_getopt_data *d)
1231 int ret, print_errors = d->custom_opterr;
1233 if (optstring[0] == ':')
1237 d->custom_optarg = NULL;
1240 * This is a big difference with GNU getopt, since optind == 0
1241 * means initialization while here 1 means first call.
1243 if (d->custom_optind == 0 || !d->initialized) {
1244 if (d->custom_optind == 0)
1245 d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */
1246 custom_getopt_initialize(d);
1248 if (d->nextchar == NULL || *d->nextchar == '\0') {
1249 ret = shuffle_argv(argc, argv, longopts, d);
1253 if (longopts && (argv[d->custom_optind][1] == '-' ))
1254 return check_long_opt(argc, argv, optstring, longopts,
1255 longind, print_errors, d);
1256 return check_short_opt(argc, argv, optstring, print_errors, d);
1259 static int custom_getopt_internal(int argc, char *const *argv, const char *optstring,
1260 const struct option *longopts, int *longind)
1263 /* Keep a global copy of all internal members of d */
1264 static struct custom_getopt_data d;
1266 d.custom_optind = custom_optind;
1267 d.custom_opterr = custom_opterr;
1268 result = getopt_internal_r(argc, argv, optstring, longopts,
1270 custom_optind = d.custom_optind;
1271 custom_optarg = d.custom_optarg;
1272 custom_optopt = d.custom_optopt;
1276 static int custom_getopt_long (int argc, char *const *argv, const char *options,
1277 const struct option *long_options, int *opt_index)
1279 return custom_getopt_internal(argc, argv, options, long_options,
1284 static char *package_name = 0;
1287 * @brief updates an option
1288 * @param field the generic pointer to the field to update
1289 * @param orig_field the pointer to the orig field
1290 * @param field_given the pointer to the number of occurrence of this option
1291 * @param prev_given the pointer to the number of occurrence already seen
1292 * @param value the argument for this option (if null no arg was specified)
1293 * @param possible_values the possible values for this option (if specified)
1294 * @param default_value the default value (in case the option only accepts fixed values)
1295 * @param arg_type the type of this option
1296 * @param check_ambiguity @see cmdline_parser_clitkCropImage_params.check_ambiguity
1297 * @param override @see cmdline_parser_clitkCropImage_params.override
1298 * @param no_free whether to free a possible previous value
1299 * @param multiple_option whether this is a multiple option
1300 * @param long_opt the corresponding long option
1301 * @param short_opt the corresponding short option (or '-' if none)
1302 * @param additional_error possible further error specification
1305 int update_arg(void *field, char **orig_field,
1306 unsigned int *field_given, unsigned int *prev_given,
1307 char *value, char *possible_values[], const char *default_value,
1308 cmdline_parser_clitkCropImage_arg_type arg_type,
1309 int check_ambiguity, int override,
1310 int no_free, int multiple_option,
1311 const char *long_opt, char short_opt,
1312 const char *additional_error)
1314 char *stop_char = 0;
1315 const char *val = value;
1317 char **string_field;
1322 if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
1324 if (short_opt != '-')
1325 fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
1326 package_name, long_opt, short_opt,
1327 (additional_error ? additional_error : ""));
1329 fprintf (stderr, "%s: `--%s' option given more than once%s\n",
1330 package_name, long_opt,
1331 (additional_error ? additional_error : ""));
1332 return 1; /* failure */
1336 if (field_given && *field_given && ! override)
1342 if (possible_values)
1343 val = possible_values[found];
1347 *((int *)field) = !*((int *)field);
1350 if (val) *((int *)field) = strtol (val, &stop_char, 0);
1353 if (val) *((double *)field) = strtod (val, &stop_char);
1357 string_field = (char **)field;
1358 if (!no_free && *string_field)
1359 free (*string_field); /* free previous string */
1360 *string_field = gengetopt_strdup (val);
1367 /* check numeric conversion */
1371 if (val && !(stop_char && *stop_char == '\0')) {
1372 fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
1373 return 1; /* failure */
1380 /* store the original value */
1386 if (value && orig_field) {
1388 *orig_field = value;
1391 free (*orig_field); /* free previous string */
1392 *orig_field = gengetopt_strdup (value);
1401 * @brief store information about a multiple option in a temporary list
1402 * @param list where to (temporarily) store multiple options
1405 int update_multiple_arg_temp(struct generic_list **list,
1406 unsigned int *prev_given, const char *val,
1407 char *possible_values[], const char *default_value,
1408 cmdline_parser_clitkCropImage_arg_type arg_type,
1409 const char *long_opt, char short_opt,
1410 const char *additional_error)
1412 char *multi_token, *multi_next; /* store single arguments */
1414 if (arg_type == ARG_NO) {
1419 multi_token = get_multiple_arg_token(val);
1420 multi_next = get_multiple_arg_token_next (val);
1425 if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0,
1426 prev_given, multi_token, possible_values, default_value,
1427 arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
1428 if (multi_token) free(multi_token);
1429 return 1; /* failure */
1434 multi_token = get_multiple_arg_token(multi_next);
1435 multi_next = get_multiple_arg_token_next (multi_next);
1445 * @brief free the passed list (including possible string argument)
1448 void free_list(struct generic_list *list, short string_arg)
1451 struct generic_list *tmp;
1455 if (string_arg && list->arg.string_arg)
1456 free (list->arg.string_arg);
1466 * @brief updates a multiple option starting from the passed list
1469 void update_multiple_arg(void *field, char ***orig_field,
1470 unsigned int field_given, unsigned int prev_given, union generic_value *default_value,
1471 cmdline_parser_clitkCropImage_arg_type arg_type,
1472 struct generic_list *list)
1475 struct generic_list *tmp;
1477 if (prev_given && list) {
1478 *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *));
1482 *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break;
1484 *((double **)field) = (double *)realloc (*((double **)field), (field_given + prev_given) * sizeof (double)); break;
1486 *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break;
1491 for (i = (prev_given - 1); i >= 0; --i)
1497 (*((int **)field))[i + field_given] = tmp->arg.int_arg; break;
1499 (*((double **)field))[i + field_given] = tmp->arg.double_arg; break;
1501 (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break;
1505 (*orig_field) [i + field_given] = list->orig;
1509 } else { /* set the default value */
1510 if (default_value && ! field_given) {
1513 if (! *((int **)field)) {
1514 *((int **)field) = (int *)malloc (sizeof (int));
1515 (*((int **)field))[0] = default_value->int_arg;
1519 if (! *((double **)field)) {
1520 *((double **)field) = (double *)malloc (sizeof (double));
1521 (*((double **)field))[0] = default_value->double_arg;
1525 if (! *((char ***)field)) {
1526 *((char ***)field) = (char **)malloc (sizeof (char *));
1527 (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg);
1532 if (!(*orig_field)) {
1533 *orig_field = (char **) malloc (sizeof (char *));
1534 (*orig_field)[0] = NULL;
1541 cmdline_parser_clitkCropImage_internal (int argc, char * const *argv, struct args_info_clitkCropImage *args_info,
1542 struct cmdline_parser_clitkCropImage_params *params, const char *additional_error)
1544 int c; /* Character of the parsed option. */
1546 struct generic_list * boundingBox_list = NULL;
1547 struct generic_list * lower_list = NULL;
1548 struct generic_list * upper_list = NULL;
1550 struct args_info_clitkCropImage local_args_info;
1555 int check_ambiguity;
1557 package_name = argv[0];
1559 override = params->override;
1560 initialize = params->initialize;
1561 check_required = params->check_required;
1562 check_ambiguity = params->check_ambiguity;
1565 cmdline_parser_clitkCropImage_init (args_info);
1567 cmdline_parser_clitkCropImage_init (&local_args_info);
1571 opterr = params->print_errors;
1576 int option_index = 0;
1578 static struct option long_options[] = {
1579 { "help", 0, NULL, 'h' },
1580 { "version", 0, NULL, 'V' },
1581 { "config", 1, NULL, 0 },
1582 { "imagetypes", 0, NULL, 0 },
1583 { "verbose", 0, NULL, 'v' },
1584 { "verboseOption", 0, NULL, 0 },
1585 { "verboseWarningOff", 0, NULL, 0 },
1586 { "input", 1, NULL, 'i' },
1587 { "output", 1, NULL, 'o' },
1588 { "boundingBox", 1, NULL, 'b' },
1589 { "lower", 1, NULL, 'l' },
1590 { "upper", 1, NULL, 'u' },
1591 { "origin", 0, NULL, 0 },
1592 { "BG", 1, NULL, 0 },
1593 { "like", 1, NULL, 0 },
1594 { "BGLike", 1, NULL, 0 },
1595 { NULL, 0, NULL, 0 }
1598 custom_optarg = optarg;
1599 custom_optind = optind;
1600 custom_opterr = opterr;
1601 custom_optopt = optopt;
1603 c = custom_getopt_long (argc, argv, "hVvi:o:b:l:u:", long_options, &option_index);
1605 optarg = custom_optarg;
1606 optind = custom_optind;
1607 opterr = custom_opterr;
1608 optopt = custom_optopt;
1610 if (c == -1) break; /* Exit from `while (1)' loop. */
1614 case 'h': /* Print help and exit. */
1615 cmdline_parser_clitkCropImage_print_help ();
1616 cmdline_parser_clitkCropImage_free (&local_args_info);
1617 exit (EXIT_SUCCESS);
1619 case 'V': /* Print version and exit. */
1620 cmdline_parser_clitkCropImage_print_version ();
1621 cmdline_parser_clitkCropImage_free (&local_args_info);
1622 exit (EXIT_SUCCESS);
1624 case 'v': /* Verbose. */
1627 if (update_arg((void *)&(args_info->verbose_flag), 0, &(args_info->verbose_given),
1628 &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
1629 check_ambiguity, override, 1, 0, "verbose", 'v',
1634 case 'i': /* Input image filename. */
1637 if (update_arg( (void *)&(args_info->input_arg),
1638 &(args_info->input_orig), &(args_info->input_given),
1639 &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
1640 check_ambiguity, override, 0, 0,
1646 case 'o': /* Output image filename. */
1649 if (update_arg( (void *)&(args_info->output_arg),
1650 &(args_info->output_orig), &(args_info->output_given),
1651 &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
1652 check_ambiguity, override, 0, 0,
1658 case 'b': /* Bounding box of the crop region (in 3D: =x1,x2,y1,y2,z1,z2). */
1660 if (update_multiple_arg_temp(&boundingBox_list,
1661 &(local_args_info.boundingBox_given), optarg, 0, 0, ARG_INT,
1667 case 'l': /* Size of the lower crop region (multiple values). */
1669 if (update_multiple_arg_temp(&lower_list,
1670 &(local_args_info.lower_given), optarg, 0, 0, ARG_INT,
1676 case 'u': /* Size of the upper crop region (multiple values). */
1678 if (update_multiple_arg_temp(&upper_list,
1679 &(local_args_info.upper_given), optarg, 0, 0, ARG_INT,
1686 case 0: /* Long option with no short option */
1688 if (strcmp (long_options[option_index].name, "config") == 0)
1692 if (update_arg( (void *)&(args_info->config_arg),
1693 &(args_info->config_orig), &(args_info->config_given),
1694 &(local_args_info.config_given), optarg, 0, 0, ARG_STRING,
1695 check_ambiguity, override, 0, 0,
1701 /* Display allowed image types. */
1702 else if (strcmp (long_options[option_index].name, "imagetypes") == 0)
1706 if (update_arg((void *)&(args_info->imagetypes_flag), 0, &(args_info->imagetypes_given),
1707 &(local_args_info.imagetypes_given), optarg, 0, 0, ARG_FLAG,
1708 check_ambiguity, override, 1, 0, "imagetypes", '-',
1713 /* Display options values. */
1714 else if (strcmp (long_options[option_index].name, "verboseOption") == 0)
1718 if (update_arg((void *)&(args_info->verboseOption_flag), 0, &(args_info->verboseOption_given),
1719 &(local_args_info.verboseOption_given), optarg, 0, 0, ARG_FLAG,
1720 check_ambiguity, override, 1, 0, "verboseOption", '-',
1725 /* Do not display warning. */
1726 else if (strcmp (long_options[option_index].name, "verboseWarningOff") == 0)
1730 if (update_arg((void *)&(args_info->verboseWarningOff_flag), 0, &(args_info->verboseWarningOff_given),
1731 &(local_args_info.verboseWarningOff_given), optarg, 0, 0, ARG_FLAG,
1732 check_ambiguity, override, 1, 0, "verboseWarningOff", '-',
1737 /* Set new origin to zero. */
1738 else if (strcmp (long_options[option_index].name, "origin") == 0)
1742 if (update_arg((void *)&(args_info->origin_flag), 0, &(args_info->origin_given),
1743 &(local_args_info.origin_given), optarg, 0, 0, ARG_FLAG,
1744 check_ambiguity, override, 1, 0, "origin", '-',
1749 /* Background value in input.. */
1750 else if (strcmp (long_options[option_index].name, "BG") == 0)
1754 if (update_arg( (void *)&(args_info->BG_arg),
1755 &(args_info->BG_orig), &(args_info->BG_given),
1756 &(local_args_info.BG_given), optarg, 0, "0", ARG_DOUBLE,
1757 check_ambiguity, override, 0, 0,
1763 /* Crop like this image (must have the same spacing. */
1764 else if (strcmp (long_options[option_index].name, "like") == 0)
1768 if (update_arg( (void *)&(args_info->like_arg),
1769 &(args_info->like_orig), &(args_info->like_given),
1770 &(local_args_info.like_given), optarg, 0, 0, ARG_STRING,
1771 check_ambiguity, override, 0, 0,
1777 /* Background value in output (if like larger). */
1778 else if (strcmp (long_options[option_index].name, "BGLike") == 0)
1782 if (update_arg( (void *)&(args_info->BGLike_arg),
1783 &(args_info->BGLike_orig), &(args_info->BGLike_given),
1784 &(local_args_info.BGLike_given), optarg, 0, "0", ARG_DOUBLE,
1785 check_ambiguity, override, 0, 0,
1793 case '?': /* Invalid option. */
1794 /* `getopt_long' already printed an error message. */
1797 default: /* bug: option not considered. */
1798 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, c, (additional_error ? additional_error : ""));
1804 update_multiple_arg((void *)&(args_info->boundingBox_arg),
1805 &(args_info->boundingBox_orig), args_info->boundingBox_given,
1806 local_args_info.boundingBox_given, 0 ,
1807 ARG_INT, boundingBox_list);
1808 update_multiple_arg((void *)&(args_info->lower_arg),
1809 &(args_info->lower_orig), args_info->lower_given,
1810 local_args_info.lower_given, 0 ,
1811 ARG_INT, lower_list);
1812 update_multiple_arg((void *)&(args_info->upper_arg),
1813 &(args_info->upper_orig), args_info->upper_given,
1814 local_args_info.upper_given, 0 ,
1815 ARG_INT, upper_list);
1817 args_info->boundingBox_given += local_args_info.boundingBox_given;
1818 local_args_info.boundingBox_given = 0;
1819 args_info->lower_given += local_args_info.lower_given;
1820 local_args_info.lower_given = 0;
1821 args_info->upper_given += local_args_info.upper_given;
1822 local_args_info.upper_given = 0;
1826 error += cmdline_parser_clitkCropImage_required2 (args_info, argv[0], additional_error);
1829 cmdline_parser_clitkCropImage_release (&local_args_info);
1832 return (EXIT_FAILURE);
1837 int found_prog_name = 0;
1838 /* whether program name, i.e., argv[0], is in the remaining args
1839 (this may happen with some implementations of getopt,
1840 but surely not with the one included by gengetopt) */
1843 args_info->inputs_num = argc - optind - found_prog_name;
1845 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1846 while (optind < argc)
1847 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1853 free_list (boundingBox_list, 0 );
1854 free_list (lower_list, 0 );
1855 free_list (upper_list, 0 );
1857 cmdline_parser_clitkCropImage_release (&local_args_info);
1858 return (EXIT_FAILURE);
1861 #ifndef CONFIG_FILE_LINE_SIZE
1862 #define CONFIG_FILE_LINE_SIZE 2048
1864 #define ADDITIONAL_ERROR " in configuration file "
1866 #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1867 /* 3 is for "--" and "=" */
1870 _cmdline_parser_clitkCropImage_configfile (char * const filename, int *my_argc)
1873 char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
1874 char linebuf[CONFIG_FILE_LINE_SIZE];
1876 int result = 0, equal;
1879 size_t len, next_token;
1882 if ((file = fopen(filename, "r")) == NULL)
1884 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
1885 CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename);
1886 return EXIT_FAILURE;
1889 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
1893 len = strlen(linebuf);
1894 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
1896 fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
1897 CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename, line_num);
1898 result = EXIT_FAILURE;
1902 /* find first non-whitespace character in the line */
1903 next_token = strspn (linebuf, " \t\r\n");
1904 str_index = linebuf + next_token;
1906 if ( str_index[0] == '\0' || str_index[0] == '#')
1907 continue; /* empty line or comment line is skipped */
1911 /* truncate fopt at the end of the first non-valid character */
1912 next_token = strcspn (fopt, " \t\r\n=");
1914 if (fopt[next_token] == '\0') /* the line is over */
1921 /* remember if equal sign is present */
1922 equal = (fopt[next_token] == '=');
1923 fopt[next_token++] = '\0';
1925 /* advance pointers to the next token after the end of fopt */
1926 next_token += strspn (fopt + next_token, " \t\r\n");
1928 /* check for the presence of equal sign, and if so, skip it */
1930 if ((equal = (fopt[next_token] == '=')))
1933 next_token += strspn (fopt + next_token, " \t\r\n");
1935 str_index += next_token;
1939 if ( farg[0] == '\"' || farg[0] == '\'' )
1940 { /* quoted argument */
1941 str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
1946 "%s:%s:%d: unterminated string in configuration file\n",
1947 CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename, line_num);
1948 result = EXIT_FAILURE;
1953 { /* read up the remaining part up to a delimiter */
1954 next_token = strcspn (farg, " \t\r\n#\'\"");
1955 str_index += next_token;
1958 /* truncate farg at the delimiter and store it for further check */
1959 delimiter = *str_index, *str_index++ = '\0';
1961 /* everything but comment is illegal at the end of line */
1962 if (delimiter != '\0' && delimiter != '#')
1964 str_index += strspn(str_index, " \t\r\n");
1965 if (*str_index != '\0' && *str_index != '#')
1969 "%s:%s:%d: malformed string in configuration file\n",
1970 CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename, line_num);
1971 result = EXIT_FAILURE;
1977 if (!strcmp(fopt,"include")) {
1978 if (farg && *farg) {
1979 result = _cmdline_parser_clitkCropImage_configfile(farg, my_argc);
1981 fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n",
1982 CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE, filename, line_num);
1987 strcat (my_argv, len > 1 ? "--" : "-");
1988 strcat (my_argv, fopt);
1989 if (len > 1 && ((farg && *farg) || equal))
1990 strcat (my_argv, "=");
1992 strcat (my_argv, farg);
1995 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1996 cmd_line_list_tmp->next = cmd_line_list;
1997 cmd_line_list = cmd_line_list_tmp;
1998 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
2007 cmdline_parser_clitkCropImage_configfile (char * const filename,
2008 struct args_info_clitkCropImage *args_info,
2009 int override, int initialize, int check_required)
2011 struct cmdline_parser_clitkCropImage_params params;
2013 params.override = override;
2014 params.initialize = initialize;
2015 params.check_required = check_required;
2016 params.check_ambiguity = 0;
2017 params.print_errors = 1;
2019 return cmdline_parser_clitkCropImage_config_file (filename, args_info, ¶ms);
2023 cmdline_parser_clitkCropImage_config_file (char * const filename,
2024 struct args_info_clitkCropImage *args_info,
2025 struct cmdline_parser_clitkCropImage_params *params)
2030 char *additional_error;
2032 /* store the program name */
2033 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
2034 cmd_line_list_tmp->next = cmd_line_list;
2035 cmd_line_list = cmd_line_list_tmp;
2036 cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_CLITKCROPIMAGE_PACKAGE);
2038 result = _cmdline_parser_clitkCropImage_configfile(filename, &my_argc);
2040 if (result != EXIT_FAILURE) {
2041 my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
2042 cmd_line_list_tmp = cmd_line_list;
2044 for (i = my_argc - 1; i >= 0; --i) {
2045 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
2046 cmd_line_list_tmp = cmd_line_list_tmp->next;
2049 my_argv_arg[my_argc] = 0;
2051 additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
2052 strcpy (additional_error, ADDITIONAL_ERROR);
2053 strcat (additional_error, filename);
2055 cmdline_parser_clitkCropImage_internal (my_argc, my_argv_arg, args_info,
2059 free (additional_error);
2064 if (result == EXIT_FAILURE)
2066 cmdline_parser_clitkCropImage_free (args_info);
2067 exit (EXIT_FAILURE);