2 File autogenerated by gengetopt version 2.22.1
3 generated with the following command:
4 gengetopt --input=../tools/gliv.ggo --unamed-opts --no-handle-error
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. */
24 const char *gengetopt_args_info_purpose
= "Image Viewer using OpenGL";
26 const char *gengetopt_args_info_usage
= "Usage: " CMDLINE_PARSER_PACKAGE
" [OPTIONS]... [FILES]...";
28 const char *gengetopt_args_info_description
= "";
30 const char *gengetopt_args_info_help
[] = {
31 " -h, --help Print help and exit",
32 " -V, --version Print version and exit",
33 " -a, --add-all[=on|off] Add all files in the directory",
34 " -R, --recursive[=on|off] Recursive directory traversal",
35 " -S, --sort[=on|off] Show images in sorted order",
36 " -s, --shuffle[=on|off] Show images in random order",
37 " -F, --force-load[=on|off] Try to load every file",
38 " -C, --client[=on|off] Connect to a running gliv, appending to the list",
39 " -c, --client-clear[=on|off] Connect to a running gliv, replacing the list",
40 " -e, --build-menus[=on|off] No images menu at startup",
41 " -g, --glivrc[=FILE] Use this configuration file or none",
42 " -w, --slide-show[=on|off] Start the slide show immediately",
43 " -0, --null[=on|off] Read null-terminated filenames",
44 " -o, --collection[=FILE] Output a collection",
45 " -G, --geometry=GEOMETRY Initial window geometry",
51 } cmdline_parser_arg_type
;
54 void clear_given (struct gengetopt_args_info
*args_info
);
56 void clear_args (struct gengetopt_args_info
*args_info
);
59 cmdline_parser_internal (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
,
60 struct cmdline_parser_params
*params
, const char *additional_error
);
64 gengetopt_strdup (const char *s
);
67 void clear_given (struct gengetopt_args_info
*args_info
)
69 args_info
->help_given
= 0 ;
70 args_info
->version_given
= 0 ;
71 args_info
->add_all_given
= 0 ;
72 args_info
->recursive_given
= 0 ;
73 args_info
->sort_given
= 0 ;
74 args_info
->shuffle_given
= 0 ;
75 args_info
->force_load_given
= 0 ;
76 args_info
->client_given
= 0 ;
77 args_info
->client_clear_given
= 0 ;
78 args_info
->build_menus_given
= 0 ;
79 args_info
->glivrc_given
= 0 ;
80 args_info
->slide_show_given
= 0 ;
81 args_info
->null_given
= 0 ;
82 args_info
->collection_given
= 0 ;
83 args_info
->geometry_given
= 0 ;
87 void clear_args (struct gengetopt_args_info
*args_info
)
89 args_info
->add_all_arg
= NULL
;
90 args_info
->add_all_orig
= NULL
;
91 args_info
->recursive_arg
= NULL
;
92 args_info
->recursive_orig
= NULL
;
93 args_info
->sort_arg
= NULL
;
94 args_info
->sort_orig
= NULL
;
95 args_info
->shuffle_arg
= NULL
;
96 args_info
->shuffle_orig
= NULL
;
97 args_info
->force_load_arg
= NULL
;
98 args_info
->force_load_orig
= NULL
;
99 args_info
->client_arg
= NULL
;
100 args_info
->client_orig
= NULL
;
101 args_info
->client_clear_arg
= NULL
;
102 args_info
->client_clear_orig
= NULL
;
103 args_info
->build_menus_arg
= NULL
;
104 args_info
->build_menus_orig
= NULL
;
105 args_info
->glivrc_arg
= NULL
;
106 args_info
->glivrc_orig
= NULL
;
107 args_info
->slide_show_arg
= NULL
;
108 args_info
->slide_show_orig
= NULL
;
109 args_info
->null_arg
= NULL
;
110 args_info
->null_orig
= NULL
;
111 args_info
->collection_arg
= NULL
;
112 args_info
->collection_orig
= NULL
;
113 args_info
->geometry_arg
= NULL
;
114 args_info
->geometry_orig
= NULL
;
119 void init_args_info(struct gengetopt_args_info
*args_info
)
123 args_info
->help_help
= gengetopt_args_info_help
[0] ;
124 args_info
->version_help
= gengetopt_args_info_help
[1] ;
125 args_info
->add_all_help
= gengetopt_args_info_help
[2] ;
126 args_info
->recursive_help
= gengetopt_args_info_help
[3] ;
127 args_info
->sort_help
= gengetopt_args_info_help
[4] ;
128 args_info
->shuffle_help
= gengetopt_args_info_help
[5] ;
129 args_info
->force_load_help
= gengetopt_args_info_help
[6] ;
130 args_info
->client_help
= gengetopt_args_info_help
[7] ;
131 args_info
->client_clear_help
= gengetopt_args_info_help
[8] ;
132 args_info
->build_menus_help
= gengetopt_args_info_help
[9] ;
133 args_info
->glivrc_help
= gengetopt_args_info_help
[10] ;
134 args_info
->slide_show_help
= gengetopt_args_info_help
[11] ;
135 args_info
->null_help
= gengetopt_args_info_help
[12] ;
136 args_info
->collection_help
= gengetopt_args_info_help
[13] ;
137 args_info
->geometry_help
= gengetopt_args_info_help
[14] ;
142 cmdline_parser_print_version (void)
144 printf ("%s %s\n", CMDLINE_PARSER_PACKAGE
, CMDLINE_PARSER_VERSION
);
147 static void print_help_common(void) {
148 cmdline_parser_print_version ();
150 if (strlen(gengetopt_args_info_purpose
) > 0)
151 printf("\n%s\n", gengetopt_args_info_purpose
);
153 if (strlen(gengetopt_args_info_usage
) > 0)
154 printf("\n%s\n", gengetopt_args_info_usage
);
158 if (strlen(gengetopt_args_info_description
) > 0)
159 printf("%s\n\n", gengetopt_args_info_description
);
163 cmdline_parser_print_help (void)
167 while (gengetopt_args_info_help
[i
])
168 printf("%s\n", gengetopt_args_info_help
[i
++]);
172 cmdline_parser_init (struct gengetopt_args_info
*args_info
)
174 clear_given (args_info
);
175 clear_args (args_info
);
176 init_args_info (args_info
);
178 args_info
->inputs
= NULL
;
179 args_info
->inputs_num
= 0;
183 cmdline_parser_params_init(struct cmdline_parser_params
*params
)
187 params
->override
= 0;
188 params
->initialize
= 1;
189 params
->check_required
= 1;
190 params
->check_ambiguity
= 0;
191 params
->print_errors
= 1;
195 struct cmdline_parser_params
*
196 cmdline_parser_params_create(void)
198 struct cmdline_parser_params
*params
=
199 (struct cmdline_parser_params
*)malloc(sizeof(struct cmdline_parser_params
));
200 cmdline_parser_params_init(params
);
205 free_string_field (char **s
)
216 cmdline_parser_release (struct gengetopt_args_info
*args_info
)
219 free_string_field (&(args_info
->add_all_arg
));
220 free_string_field (&(args_info
->add_all_orig
));
221 free_string_field (&(args_info
->recursive_arg
));
222 free_string_field (&(args_info
->recursive_orig
));
223 free_string_field (&(args_info
->sort_arg
));
224 free_string_field (&(args_info
->sort_orig
));
225 free_string_field (&(args_info
->shuffle_arg
));
226 free_string_field (&(args_info
->shuffle_orig
));
227 free_string_field (&(args_info
->force_load_arg
));
228 free_string_field (&(args_info
->force_load_orig
));
229 free_string_field (&(args_info
->client_arg
));
230 free_string_field (&(args_info
->client_orig
));
231 free_string_field (&(args_info
->client_clear_arg
));
232 free_string_field (&(args_info
->client_clear_orig
));
233 free_string_field (&(args_info
->build_menus_arg
));
234 free_string_field (&(args_info
->build_menus_orig
));
235 free_string_field (&(args_info
->glivrc_arg
));
236 free_string_field (&(args_info
->glivrc_orig
));
237 free_string_field (&(args_info
->slide_show_arg
));
238 free_string_field (&(args_info
->slide_show_orig
));
239 free_string_field (&(args_info
->null_arg
));
240 free_string_field (&(args_info
->null_orig
));
241 free_string_field (&(args_info
->collection_arg
));
242 free_string_field (&(args_info
->collection_orig
));
243 free_string_field (&(args_info
->geometry_arg
));
244 free_string_field (&(args_info
->geometry_orig
));
247 for (i
= 0; i
< args_info
->inputs_num
; ++i
)
248 free (args_info
->inputs
[i
]);
250 if (args_info
->inputs_num
)
251 free (args_info
->inputs
);
253 clear_given (args_info
);
258 write_into_file(FILE *outfile
, const char *opt
, const char *arg
, char *values
[])
261 fprintf(outfile
, "%s=\"%s\"\n", opt
, arg
);
263 fprintf(outfile
, "%s\n", opt
);
269 cmdline_parser_dump(FILE *outfile
, struct gengetopt_args_info
*args_info
)
275 fprintf (stderr
, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE
);
279 if (args_info
->help_given
)
280 write_into_file(outfile
, "help", 0, 0 );
281 if (args_info
->version_given
)
282 write_into_file(outfile
, "version", 0, 0 );
283 if (args_info
->add_all_given
)
284 write_into_file(outfile
, "add-all", args_info
->add_all_orig
, 0);
285 if (args_info
->recursive_given
)
286 write_into_file(outfile
, "recursive", args_info
->recursive_orig
, 0);
287 if (args_info
->sort_given
)
288 write_into_file(outfile
, "sort", args_info
->sort_orig
, 0);
289 if (args_info
->shuffle_given
)
290 write_into_file(outfile
, "shuffle", args_info
->shuffle_orig
, 0);
291 if (args_info
->force_load_given
)
292 write_into_file(outfile
, "force-load", args_info
->force_load_orig
, 0);
293 if (args_info
->client_given
)
294 write_into_file(outfile
, "client", args_info
->client_orig
, 0);
295 if (args_info
->client_clear_given
)
296 write_into_file(outfile
, "client-clear", args_info
->client_clear_orig
, 0);
297 if (args_info
->build_menus_given
)
298 write_into_file(outfile
, "build-menus", args_info
->build_menus_orig
, 0);
299 if (args_info
->glivrc_given
)
300 write_into_file(outfile
, "glivrc", args_info
->glivrc_orig
, 0);
301 if (args_info
->slide_show_given
)
302 write_into_file(outfile
, "slide-show", args_info
->slide_show_orig
, 0);
303 if (args_info
->null_given
)
304 write_into_file(outfile
, "null", args_info
->null_orig
, 0);
305 if (args_info
->collection_given
)
306 write_into_file(outfile
, "collection", args_info
->collection_orig
, 0);
307 if (args_info
->geometry_given
)
308 write_into_file(outfile
, "geometry", args_info
->geometry_orig
, 0);
316 cmdline_parser_file_save(const char *filename
, struct gengetopt_args_info
*args_info
)
321 outfile
= fopen(filename
, "w");
325 fprintf (stderr
, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE
, filename
);
329 i
= cmdline_parser_dump(outfile
, args_info
);
336 cmdline_parser_free (struct gengetopt_args_info
*args_info
)
338 cmdline_parser_release (args_info
);
341 /** @brief replacement of strdup, which is not standard */
343 gengetopt_strdup (const char *s
)
349 result
= (char*)malloc(strlen(s
) + 1);
350 if (result
== (char*)0)
357 cmdline_parser (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
)
359 return cmdline_parser2 (argc
, argv
, args_info
, 0, 1, 1);
363 cmdline_parser_ext (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
,
364 struct cmdline_parser_params
*params
)
367 result
= cmdline_parser_internal (argc
, argv
, args_info
, params
, NULL
);
373 cmdline_parser2 (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
, int override
, int initialize
, int check_required
)
376 struct cmdline_parser_params params
;
378 params
.override
= override
;
379 params
.initialize
= initialize
;
380 params
.check_required
= check_required
;
381 params
.check_ambiguity
= 0;
382 params
.print_errors
= 1;
384 result
= cmdline_parser_internal (argc
, argv
, args_info
, ¶ms
, NULL
);
390 cmdline_parser_required (struct gengetopt_args_info
*args_info
, const char *prog_name
)
396 static char *package_name
= 0;
399 * @brief updates an option
400 * @param field the generic pointer to the field to update
401 * @param orig_field the pointer to the orig field
402 * @param field_given the pointer to the number of occurrence of this option
403 * @param prev_given the pointer to the number of occurrence already seen
404 * @param value the argument for this option (if null no arg was specified)
405 * @param possible_values the possible values for this option (if specified)
406 * @param default_value the default value (in case the option only accepts fixed values)
407 * @param arg_type the type of this option
408 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
409 * @param override @see cmdline_parser_params.override
410 * @param no_free whether to free a possible previous value
411 * @param multiple_option whether this is a multiple option
412 * @param long_opt the corresponding long option
413 * @param short_opt the corresponding short option (or '-' if none)
414 * @param additional_error possible further error specification
417 int update_arg(void *field
, char **orig_field
,
418 unsigned int *field_given
, unsigned int *prev_given
,
419 char *value
, char *possible_values
[], const char *default_value
,
420 cmdline_parser_arg_type arg_type
,
421 int check_ambiguity
, int override
,
422 int no_free
, int multiple_option
,
423 const char *long_opt
, char short_opt
,
424 const char *additional_error
)
427 const char *val
= value
;
434 if (!multiple_option
&& prev_given
&& (*prev_given
|| (check_ambiguity
&& *field_given
)))
436 if (short_opt
!= '-')
437 fprintf (stderr
, "%s: `--%s' (`-%c') option given more than once%s\n",
438 package_name
, long_opt
, short_opt
,
439 (additional_error
? additional_error
: ""));
441 fprintf (stderr
, "%s: `--%s' option given more than once%s\n",
442 package_name
, long_opt
,
443 (additional_error
? additional_error
: ""));
444 return 1; /* failure */
448 if (field_given
&& *field_given
&& ! override
)
455 val
= possible_values
[found
];
460 string_field
= (char **)field
;
461 if (!no_free
&& *string_field
)
462 free (*string_field
); /* free previous string */
463 *string_field
= gengetopt_strdup (val
);
471 /* store the original value */
476 if (value
&& orig_field
) {
481 free (*orig_field
); /* free previous string */
482 *orig_field
= gengetopt_strdup (value
);
492 cmdline_parser_internal (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
,
493 struct cmdline_parser_params
*params
, const char *additional_error
)
495 int c
; /* Character of the parsed option. */
498 struct gengetopt_args_info local_args_info
;
505 package_name
= argv
[0];
507 override
= params
->override
;
508 initialize
= params
->initialize
;
509 check_required
= params
->check_required
;
510 check_ambiguity
= params
->check_ambiguity
;
513 cmdline_parser_init (args_info
);
515 cmdline_parser_init (&local_args_info
);
519 opterr
= params
->print_errors
;
524 int option_index
= 0;
526 static struct option long_options
[] = {
527 { "help", 0, NULL
, 'h' },
528 { "version", 0, NULL
, 'V' },
529 { "add-all", 2, NULL
, 'a' },
530 { "recursive", 2, NULL
, 'R' },
531 { "sort", 2, NULL
, 'S' },
532 { "shuffle", 2, NULL
, 's' },
533 { "force-load", 2, NULL
, 'F' },
534 { "client", 2, NULL
, 'C' },
535 { "client-clear", 2, NULL
, 'c' },
536 { "build-menus", 2, NULL
, 'e' },
537 { "glivrc", 2, NULL
, 'g' },
538 { "slide-show", 2, NULL
, 'w' },
539 { "null", 2, NULL
, '0' },
540 { "collection", 2, NULL
, 'o' },
541 { "geometry", 1, NULL
, 'G' },
545 c
= getopt_long (argc
, argv
, "hVa::R::S::s::F::C::c::e::g::w::0::o::G:", long_options
, &option_index
);
547 if (c
== -1) break; /* Exit from `while (1)' loop. */
551 case 'h': /* Print help and exit. */
552 cmdline_parser_print_help ();
553 cmdline_parser_free (&local_args_info
);
556 case 'V': /* Print version and exit. */
557 cmdline_parser_print_version ();
558 cmdline_parser_free (&local_args_info
);
561 case 'a': /* Add all files in the directory. */
564 if (update_arg( (void *)&(args_info
->add_all_arg
),
565 &(args_info
->add_all_orig
), &(args_info
->add_all_given
),
566 &(local_args_info
.add_all_given
), optarg
, 0, 0, ARG_STRING
,
567 check_ambiguity
, override
, 0, 0,
573 case 'R': /* Recursive directory traversal. */
576 if (update_arg( (void *)&(args_info
->recursive_arg
),
577 &(args_info
->recursive_orig
), &(args_info
->recursive_given
),
578 &(local_args_info
.recursive_given
), optarg
, 0, 0, ARG_STRING
,
579 check_ambiguity
, override
, 0, 0,
585 case 'S': /* Show images in sorted order. */
588 if (update_arg( (void *)&(args_info
->sort_arg
),
589 &(args_info
->sort_orig
), &(args_info
->sort_given
),
590 &(local_args_info
.sort_given
), optarg
, 0, 0, ARG_STRING
,
591 check_ambiguity
, override
, 0, 0,
597 case 's': /* Show images in random order. */
600 if (update_arg( (void *)&(args_info
->shuffle_arg
),
601 &(args_info
->shuffle_orig
), &(args_info
->shuffle_given
),
602 &(local_args_info
.shuffle_given
), optarg
, 0, 0, ARG_STRING
,
603 check_ambiguity
, override
, 0, 0,
609 case 'F': /* Try to load every file. */
612 if (update_arg( (void *)&(args_info
->force_load_arg
),
613 &(args_info
->force_load_orig
), &(args_info
->force_load_given
),
614 &(local_args_info
.force_load_given
), optarg
, 0, 0, ARG_STRING
,
615 check_ambiguity
, override
, 0, 0,
621 case 'C': /* Connect to a running gliv, appending to the list. */
624 if (update_arg( (void *)&(args_info
->client_arg
),
625 &(args_info
->client_orig
), &(args_info
->client_given
),
626 &(local_args_info
.client_given
), optarg
, 0, 0, ARG_STRING
,
627 check_ambiguity
, override
, 0, 0,
633 case 'c': /* Connect to a running gliv, replacing the list. */
636 if (update_arg( (void *)&(args_info
->client_clear_arg
),
637 &(args_info
->client_clear_orig
), &(args_info
->client_clear_given
),
638 &(local_args_info
.client_clear_given
), optarg
, 0, 0, ARG_STRING
,
639 check_ambiguity
, override
, 0, 0,
645 case 'e': /* No images menu at startup. */
648 if (update_arg( (void *)&(args_info
->build_menus_arg
),
649 &(args_info
->build_menus_orig
), &(args_info
->build_menus_given
),
650 &(local_args_info
.build_menus_given
), optarg
, 0, 0, ARG_STRING
,
651 check_ambiguity
, override
, 0, 0,
657 case 'g': /* Use this configuration file or none. */
660 if (update_arg( (void *)&(args_info
->glivrc_arg
),
661 &(args_info
->glivrc_orig
), &(args_info
->glivrc_given
),
662 &(local_args_info
.glivrc_given
), optarg
, 0, 0, ARG_STRING
,
663 check_ambiguity
, override
, 0, 0,
669 case 'w': /* Start the slide show immediately. */
672 if (update_arg( (void *)&(args_info
->slide_show_arg
),
673 &(args_info
->slide_show_orig
), &(args_info
->slide_show_given
),
674 &(local_args_info
.slide_show_given
), optarg
, 0, 0, ARG_STRING
,
675 check_ambiguity
, override
, 0, 0,
681 case '0': /* Read null-terminated filenames. */
684 if (update_arg( (void *)&(args_info
->null_arg
),
685 &(args_info
->null_orig
), &(args_info
->null_given
),
686 &(local_args_info
.null_given
), optarg
, 0, 0, ARG_STRING
,
687 check_ambiguity
, override
, 0, 0,
693 case 'o': /* Output a collection. */
696 if (update_arg( (void *)&(args_info
->collection_arg
),
697 &(args_info
->collection_orig
), &(args_info
->collection_given
),
698 &(local_args_info
.collection_given
), optarg
, 0, 0, ARG_STRING
,
699 check_ambiguity
, override
, 0, 0,
705 case 'G': /* Initial window geometry. */
708 if (update_arg( (void *)&(args_info
->geometry_arg
),
709 &(args_info
->geometry_orig
), &(args_info
->geometry_given
),
710 &(local_args_info
.geometry_given
), optarg
, 0, 0, ARG_STRING
,
711 check_ambiguity
, override
, 0, 0,
718 case 0: /* Long option with no short option */
719 case '?': /* Invalid option. */
720 /* `getopt_long' already printed an error message. */
723 default: /* bug: option not considered. */
724 fprintf (stderr
, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE
, c
, (additional_error
? additional_error
: ""));
732 cmdline_parser_release (&local_args_info
);
735 return (EXIT_FAILURE
);
740 int found_prog_name
= 0;
741 /* whether program name, i.e., argv[0], is in the remaining args
742 (this may happen with some implementations of getopt,
743 but surely not with the one included by gengetopt) */
747 if (argv
[i
++] == argv
[0]) {
753 args_info
->inputs_num
= argc
- optind
- found_prog_name
;
755 (char **)(malloc ((args_info
->inputs_num
)*sizeof(char *))) ;
756 while (optind
< argc
)
757 if (argv
[optind
++] != argv
[0])
758 args_info
->inputs
[ i
++ ] = gengetopt_strdup (argv
[optind
-1]) ;
765 cmdline_parser_release (&local_args_info
);
766 return (EXIT_FAILURE
);