2 File autogenerated by gengetopt version 2.22.2
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. */
21 #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
28 const char *gengetopt_args_info_purpose
= "Image Viewer using OpenGL";
30 const char *gengetopt_args_info_usage
= "Usage: " CMDLINE_PARSER_PACKAGE
" [OPTIONS]... [FILES]...";
32 const char *gengetopt_args_info_description
= "";
34 const char *gengetopt_args_info_help
[] = {
35 " -h, --help Print help and exit",
36 " -V, --version Print version and exit",
37 " -a, --add-all[=on|off] Add all files in the directory",
38 " -R, --recursive[=on|off] Recursive directory traversal",
39 " -S, --sort[=on|off] Show images in sorted order",
40 " -s, --shuffle[=on|off] Show images in random order",
41 " -F, --force-load[=on|off] Try to load every file",
42 " -C, --client[=on|off] Connect to a running gliv, appending to the list",
43 " -c, --client-clear[=on|off] Connect to a running gliv, replacing the list",
44 " -e, --build-menus[=on|off] No images menu at startup",
45 " -g, --glivrc[=FILE] Use this configuration file or none",
46 " -w, --slide-show[=on|off] Start the slide show immediately",
47 " -0, --null[=on|off] Read null-terminated filenames",
48 " -o, --collection[=FILE] Output a collection",
49 " -G, --geometry=GEOMETRY Initial window geometry",
55 } cmdline_parser_arg_type
;
58 void clear_given (struct gengetopt_args_info
*args_info
);
60 void clear_args (struct gengetopt_args_info
*args_info
);
63 cmdline_parser_internal (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
,
64 struct cmdline_parser_params
*params
, const char *additional_error
);
68 gengetopt_strdup (const char *s
);
71 void clear_given (struct gengetopt_args_info
*args_info
)
73 args_info
->help_given
= 0 ;
74 args_info
->version_given
= 0 ;
75 args_info
->add_all_given
= 0 ;
76 args_info
->recursive_given
= 0 ;
77 args_info
->sort_given
= 0 ;
78 args_info
->shuffle_given
= 0 ;
79 args_info
->force_load_given
= 0 ;
80 args_info
->client_given
= 0 ;
81 args_info
->client_clear_given
= 0 ;
82 args_info
->build_menus_given
= 0 ;
83 args_info
->glivrc_given
= 0 ;
84 args_info
->slide_show_given
= 0 ;
85 args_info
->null_given
= 0 ;
86 args_info
->collection_given
= 0 ;
87 args_info
->geometry_given
= 0 ;
91 void clear_args (struct gengetopt_args_info
*args_info
)
93 FIX_UNUSED (args_info
);
94 args_info
->add_all_arg
= NULL
;
95 args_info
->add_all_orig
= NULL
;
96 args_info
->recursive_arg
= NULL
;
97 args_info
->recursive_orig
= NULL
;
98 args_info
->sort_arg
= NULL
;
99 args_info
->sort_orig
= NULL
;
100 args_info
->shuffle_arg
= NULL
;
101 args_info
->shuffle_orig
= NULL
;
102 args_info
->force_load_arg
= NULL
;
103 args_info
->force_load_orig
= NULL
;
104 args_info
->client_arg
= NULL
;
105 args_info
->client_orig
= NULL
;
106 args_info
->client_clear_arg
= NULL
;
107 args_info
->client_clear_orig
= NULL
;
108 args_info
->build_menus_arg
= NULL
;
109 args_info
->build_menus_orig
= NULL
;
110 args_info
->glivrc_arg
= NULL
;
111 args_info
->glivrc_orig
= NULL
;
112 args_info
->slide_show_arg
= NULL
;
113 args_info
->slide_show_orig
= NULL
;
114 args_info
->null_arg
= NULL
;
115 args_info
->null_orig
= NULL
;
116 args_info
->collection_arg
= NULL
;
117 args_info
->collection_orig
= NULL
;
118 args_info
->geometry_arg
= NULL
;
119 args_info
->geometry_orig
= NULL
;
124 void init_args_info(struct gengetopt_args_info
*args_info
)
128 args_info
->help_help
= gengetopt_args_info_help
[0] ;
129 args_info
->version_help
= gengetopt_args_info_help
[1] ;
130 args_info
->add_all_help
= gengetopt_args_info_help
[2] ;
131 args_info
->recursive_help
= gengetopt_args_info_help
[3] ;
132 args_info
->sort_help
= gengetopt_args_info_help
[4] ;
133 args_info
->shuffle_help
= gengetopt_args_info_help
[5] ;
134 args_info
->force_load_help
= gengetopt_args_info_help
[6] ;
135 args_info
->client_help
= gengetopt_args_info_help
[7] ;
136 args_info
->client_clear_help
= gengetopt_args_info_help
[8] ;
137 args_info
->build_menus_help
= gengetopt_args_info_help
[9] ;
138 args_info
->glivrc_help
= gengetopt_args_info_help
[10] ;
139 args_info
->slide_show_help
= gengetopt_args_info_help
[11] ;
140 args_info
->null_help
= gengetopt_args_info_help
[12] ;
141 args_info
->collection_help
= gengetopt_args_info_help
[13] ;
142 args_info
->geometry_help
= gengetopt_args_info_help
[14] ;
147 cmdline_parser_print_version (void)
150 (strlen(CMDLINE_PARSER_PACKAGE_NAME
) ? CMDLINE_PARSER_PACKAGE_NAME
: CMDLINE_PARSER_PACKAGE
),
151 CMDLINE_PARSER_VERSION
);
154 static void print_help_common(void) {
155 cmdline_parser_print_version ();
157 if (strlen(gengetopt_args_info_purpose
) > 0)
158 printf("\n%s\n", gengetopt_args_info_purpose
);
160 if (strlen(gengetopt_args_info_usage
) > 0)
161 printf("\n%s\n", gengetopt_args_info_usage
);
165 if (strlen(gengetopt_args_info_description
) > 0)
166 printf("%s\n\n", gengetopt_args_info_description
);
170 cmdline_parser_print_help (void)
174 while (gengetopt_args_info_help
[i
])
175 printf("%s\n", gengetopt_args_info_help
[i
++]);
179 cmdline_parser_init (struct gengetopt_args_info
*args_info
)
181 clear_given (args_info
);
182 clear_args (args_info
);
183 init_args_info (args_info
);
185 args_info
->inputs
= 0;
186 args_info
->inputs_num
= 0;
190 cmdline_parser_params_init(struct cmdline_parser_params
*params
)
194 params
->override
= 0;
195 params
->initialize
= 1;
196 params
->check_required
= 1;
197 params
->check_ambiguity
= 0;
198 params
->print_errors
= 1;
202 struct cmdline_parser_params
*
203 cmdline_parser_params_create(void)
205 struct cmdline_parser_params
*params
=
206 (struct cmdline_parser_params
*)malloc(sizeof(struct cmdline_parser_params
));
207 cmdline_parser_params_init(params
);
212 free_string_field (char **s
)
223 cmdline_parser_release (struct gengetopt_args_info
*args_info
)
226 free_string_field (&(args_info
->add_all_arg
));
227 free_string_field (&(args_info
->add_all_orig
));
228 free_string_field (&(args_info
->recursive_arg
));
229 free_string_field (&(args_info
->recursive_orig
));
230 free_string_field (&(args_info
->sort_arg
));
231 free_string_field (&(args_info
->sort_orig
));
232 free_string_field (&(args_info
->shuffle_arg
));
233 free_string_field (&(args_info
->shuffle_orig
));
234 free_string_field (&(args_info
->force_load_arg
));
235 free_string_field (&(args_info
->force_load_orig
));
236 free_string_field (&(args_info
->client_arg
));
237 free_string_field (&(args_info
->client_orig
));
238 free_string_field (&(args_info
->client_clear_arg
));
239 free_string_field (&(args_info
->client_clear_orig
));
240 free_string_field (&(args_info
->build_menus_arg
));
241 free_string_field (&(args_info
->build_menus_orig
));
242 free_string_field (&(args_info
->glivrc_arg
));
243 free_string_field (&(args_info
->glivrc_orig
));
244 free_string_field (&(args_info
->slide_show_arg
));
245 free_string_field (&(args_info
->slide_show_orig
));
246 free_string_field (&(args_info
->null_arg
));
247 free_string_field (&(args_info
->null_orig
));
248 free_string_field (&(args_info
->collection_arg
));
249 free_string_field (&(args_info
->collection_orig
));
250 free_string_field (&(args_info
->geometry_arg
));
251 free_string_field (&(args_info
->geometry_orig
));
254 for (i
= 0; i
< args_info
->inputs_num
; ++i
)
255 free (args_info
->inputs
[i
]);
257 if (args_info
->inputs_num
)
258 free (args_info
->inputs
);
260 clear_given (args_info
);
265 write_into_file(FILE *outfile
, const char *opt
, const char *arg
, const char *values
[])
269 fprintf(outfile
, "%s=\"%s\"\n", opt
, arg
);
271 fprintf(outfile
, "%s\n", opt
);
277 cmdline_parser_dump(FILE *outfile
, struct gengetopt_args_info
*args_info
)
283 fprintf (stderr
, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE
);
287 if (args_info
->help_given
)
288 write_into_file(outfile
, "help", 0, 0 );
289 if (args_info
->version_given
)
290 write_into_file(outfile
, "version", 0, 0 );
291 if (args_info
->add_all_given
)
292 write_into_file(outfile
, "add-all", args_info
->add_all_orig
, 0);
293 if (args_info
->recursive_given
)
294 write_into_file(outfile
, "recursive", args_info
->recursive_orig
, 0);
295 if (args_info
->sort_given
)
296 write_into_file(outfile
, "sort", args_info
->sort_orig
, 0);
297 if (args_info
->shuffle_given
)
298 write_into_file(outfile
, "shuffle", args_info
->shuffle_orig
, 0);
299 if (args_info
->force_load_given
)
300 write_into_file(outfile
, "force-load", args_info
->force_load_orig
, 0);
301 if (args_info
->client_given
)
302 write_into_file(outfile
, "client", args_info
->client_orig
, 0);
303 if (args_info
->client_clear_given
)
304 write_into_file(outfile
, "client-clear", args_info
->client_clear_orig
, 0);
305 if (args_info
->build_menus_given
)
306 write_into_file(outfile
, "build-menus", args_info
->build_menus_orig
, 0);
307 if (args_info
->glivrc_given
)
308 write_into_file(outfile
, "glivrc", args_info
->glivrc_orig
, 0);
309 if (args_info
->slide_show_given
)
310 write_into_file(outfile
, "slide-show", args_info
->slide_show_orig
, 0);
311 if (args_info
->null_given
)
312 write_into_file(outfile
, "null", args_info
->null_orig
, 0);
313 if (args_info
->collection_given
)
314 write_into_file(outfile
, "collection", args_info
->collection_orig
, 0);
315 if (args_info
->geometry_given
)
316 write_into_file(outfile
, "geometry", args_info
->geometry_orig
, 0);
324 cmdline_parser_file_save(const char *filename
, struct gengetopt_args_info
*args_info
)
329 outfile
= fopen(filename
, "w");
333 fprintf (stderr
, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE
, filename
);
337 i
= cmdline_parser_dump(outfile
, args_info
);
344 cmdline_parser_free (struct gengetopt_args_info
*args_info
)
346 cmdline_parser_release (args_info
);
349 /** @brief replacement of strdup, which is not standard */
351 gengetopt_strdup (const char *s
)
357 result
= (char*)malloc(strlen(s
) + 1);
358 if (result
== (char*)0)
365 cmdline_parser (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
)
367 return cmdline_parser2 (argc
, argv
, args_info
, 0, 1, 1);
371 cmdline_parser_ext (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
,
372 struct cmdline_parser_params
*params
)
375 result
= cmdline_parser_internal (argc
, argv
, args_info
, params
, 0);
381 cmdline_parser2 (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
, int override
, int initialize
, int check_required
)
384 struct cmdline_parser_params params
;
386 params
.override
= override
;
387 params
.initialize
= initialize
;
388 params
.check_required
= check_required
;
389 params
.check_ambiguity
= 0;
390 params
.print_errors
= 1;
392 result
= cmdline_parser_internal (argc
, argv
, args_info
, ¶ms
, 0);
398 cmdline_parser_required (struct gengetopt_args_info
*args_info
, const char *prog_name
)
400 FIX_UNUSED (args_info
);
401 FIX_UNUSED (prog_name
);
406 static char *package_name
= 0;
409 * @brief updates an option
410 * @param field the generic pointer to the field to update
411 * @param orig_field the pointer to the orig field
412 * @param field_given the pointer to the number of occurrence of this option
413 * @param prev_given the pointer to the number of occurrence already seen
414 * @param value the argument for this option (if null no arg was specified)
415 * @param possible_values the possible values for this option (if specified)
416 * @param default_value the default value (in case the option only accepts fixed values)
417 * @param arg_type the type of this option
418 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
419 * @param override @see cmdline_parser_params.override
420 * @param no_free whether to free a possible previous value
421 * @param multiple_option whether this is a multiple option
422 * @param long_opt the corresponding long option
423 * @param short_opt the corresponding short option (or '-' if none)
424 * @param additional_error possible further error specification
427 int update_arg(void *field
, char **orig_field
,
428 unsigned int *field_given
, unsigned int *prev_given
,
429 char *value
, const char *possible_values
[],
430 const char *default_value
,
431 cmdline_parser_arg_type arg_type
,
432 int check_ambiguity
, int override
,
433 int no_free
, int multiple_option
,
434 const char *long_opt
, char short_opt
,
435 const char *additional_error
)
439 const char *val
= value
;
446 if (!multiple_option
&& prev_given
&& (*prev_given
|| (check_ambiguity
&& *field_given
)))
448 if (short_opt
!= '-')
449 fprintf (stderr
, "%s: `--%s' (`-%c') option given more than once%s\n",
450 package_name
, long_opt
, short_opt
,
451 (additional_error
? additional_error
: ""));
453 fprintf (stderr
, "%s: `--%s' option given more than once%s\n",
454 package_name
, long_opt
,
455 (additional_error
? additional_error
: ""));
456 return 1; /* failure */
459 FIX_UNUSED (default_value
);
461 if (field_given
&& *field_given
&& ! override
)
468 val
= possible_values
[found
];
473 string_field
= (char **)field
;
474 if (!no_free
&& *string_field
)
475 free (*string_field
); /* free previous string */
476 *string_field
= gengetopt_strdup (val
);
484 /* store the original value */
489 if (value
&& orig_field
) {
494 free (*orig_field
); /* free previous string */
495 *orig_field
= gengetopt_strdup (value
);
505 cmdline_parser_internal (
506 int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
,
507 struct cmdline_parser_params
*params
, const char *additional_error
)
509 int c
; /* Character of the parsed option. */
512 struct gengetopt_args_info local_args_info
;
519 package_name
= argv
[0];
521 override
= params
->override
;
522 initialize
= params
->initialize
;
523 check_required
= params
->check_required
;
524 check_ambiguity
= params
->check_ambiguity
;
527 cmdline_parser_init (args_info
);
529 cmdline_parser_init (&local_args_info
);
533 opterr
= params
->print_errors
;
538 int option_index
= 0;
540 static struct option long_options
[] = {
541 { "help", 0, NULL
, 'h' },
542 { "version", 0, NULL
, 'V' },
543 { "add-all", 2, NULL
, 'a' },
544 { "recursive", 2, NULL
, 'R' },
545 { "sort", 2, NULL
, 'S' },
546 { "shuffle", 2, NULL
, 's' },
547 { "force-load", 2, NULL
, 'F' },
548 { "client", 2, NULL
, 'C' },
549 { "client-clear", 2, NULL
, 'c' },
550 { "build-menus", 2, NULL
, 'e' },
551 { "glivrc", 2, NULL
, 'g' },
552 { "slide-show", 2, NULL
, 'w' },
553 { "null", 2, NULL
, '0' },
554 { "collection", 2, NULL
, 'o' },
555 { "geometry", 1, NULL
, 'G' },
559 c
= getopt_long (argc
, argv
, "hVa::R::S::s::F::C::c::e::g::w::0::o::G:", long_options
, &option_index
);
561 if (c
== -1) break; /* Exit from `while (1)' loop. */
565 case 'h': /* Print help and exit. */
566 cmdline_parser_print_help ();
567 cmdline_parser_free (&local_args_info
);
570 case 'V': /* Print version and exit. */
571 cmdline_parser_print_version ();
572 cmdline_parser_free (&local_args_info
);
575 case 'a': /* Add all files in the directory. */
578 if (update_arg( (void *)&(args_info
->add_all_arg
),
579 &(args_info
->add_all_orig
), &(args_info
->add_all_given
),
580 &(local_args_info
.add_all_given
), optarg
, 0, 0, ARG_STRING
,
581 check_ambiguity
, override
, 0, 0,
587 case 'R': /* Recursive directory traversal. */
590 if (update_arg( (void *)&(args_info
->recursive_arg
),
591 &(args_info
->recursive_orig
), &(args_info
->recursive_given
),
592 &(local_args_info
.recursive_given
), optarg
, 0, 0, ARG_STRING
,
593 check_ambiguity
, override
, 0, 0,
599 case 'S': /* Show images in sorted order. */
602 if (update_arg( (void *)&(args_info
->sort_arg
),
603 &(args_info
->sort_orig
), &(args_info
->sort_given
),
604 &(local_args_info
.sort_given
), optarg
, 0, 0, ARG_STRING
,
605 check_ambiguity
, override
, 0, 0,
611 case 's': /* Show images in random order. */
614 if (update_arg( (void *)&(args_info
->shuffle_arg
),
615 &(args_info
->shuffle_orig
), &(args_info
->shuffle_given
),
616 &(local_args_info
.shuffle_given
), optarg
, 0, 0, ARG_STRING
,
617 check_ambiguity
, override
, 0, 0,
623 case 'F': /* Try to load every file. */
626 if (update_arg( (void *)&(args_info
->force_load_arg
),
627 &(args_info
->force_load_orig
), &(args_info
->force_load_given
),
628 &(local_args_info
.force_load_given
), optarg
, 0, 0, ARG_STRING
,
629 check_ambiguity
, override
, 0, 0,
635 case 'C': /* Connect to a running gliv, appending to the list. */
638 if (update_arg( (void *)&(args_info
->client_arg
),
639 &(args_info
->client_orig
), &(args_info
->client_given
),
640 &(local_args_info
.client_given
), optarg
, 0, 0, ARG_STRING
,
641 check_ambiguity
, override
, 0, 0,
647 case 'c': /* Connect to a running gliv, replacing the list. */
650 if (update_arg( (void *)&(args_info
->client_clear_arg
),
651 &(args_info
->client_clear_orig
), &(args_info
->client_clear_given
),
652 &(local_args_info
.client_clear_given
), optarg
, 0, 0, ARG_STRING
,
653 check_ambiguity
, override
, 0, 0,
659 case 'e': /* No images menu at startup. */
662 if (update_arg( (void *)&(args_info
->build_menus_arg
),
663 &(args_info
->build_menus_orig
), &(args_info
->build_menus_given
),
664 &(local_args_info
.build_menus_given
), optarg
, 0, 0, ARG_STRING
,
665 check_ambiguity
, override
, 0, 0,
671 case 'g': /* Use this configuration file or none. */
674 if (update_arg( (void *)&(args_info
->glivrc_arg
),
675 &(args_info
->glivrc_orig
), &(args_info
->glivrc_given
),
676 &(local_args_info
.glivrc_given
), optarg
, 0, 0, ARG_STRING
,
677 check_ambiguity
, override
, 0, 0,
683 case 'w': /* Start the slide show immediately. */
686 if (update_arg( (void *)&(args_info
->slide_show_arg
),
687 &(args_info
->slide_show_orig
), &(args_info
->slide_show_given
),
688 &(local_args_info
.slide_show_given
), optarg
, 0, 0, ARG_STRING
,
689 check_ambiguity
, override
, 0, 0,
695 case '0': /* Read null-terminated filenames. */
698 if (update_arg( (void *)&(args_info
->null_arg
),
699 &(args_info
->null_orig
), &(args_info
->null_given
),
700 &(local_args_info
.null_given
), optarg
, 0, 0, ARG_STRING
,
701 check_ambiguity
, override
, 0, 0,
707 case 'o': /* Output a collection. */
710 if (update_arg( (void *)&(args_info
->collection_arg
),
711 &(args_info
->collection_orig
), &(args_info
->collection_given
),
712 &(local_args_info
.collection_given
), optarg
, 0, 0, ARG_STRING
,
713 check_ambiguity
, override
, 0, 0,
719 case 'G': /* Initial window geometry. */
722 if (update_arg( (void *)&(args_info
->geometry_arg
),
723 &(args_info
->geometry_orig
), &(args_info
->geometry_given
),
724 &(local_args_info
.geometry_given
), optarg
, 0, 0, ARG_STRING
,
725 check_ambiguity
, override
, 0, 0,
732 case 0: /* Long option with no short option */
733 case '?': /* Invalid option. */
734 /* `getopt_long' already printed an error message. */
737 default: /* bug: option not considered. */
738 fprintf (stderr
, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE
, c
, (additional_error
? additional_error
: ""));
746 cmdline_parser_release (&local_args_info
);
749 return (EXIT_FAILURE
);
754 int found_prog_name
= 0;
755 /* whether program name, i.e., argv[0], is in the remaining args
756 (this may happen with some implementations of getopt,
757 but surely not with the one included by gengetopt) */
761 if (argv
[i
++] == argv
[0]) {
767 args_info
->inputs_num
= argc
- optind
- found_prog_name
;
769 (char **)(malloc ((args_info
->inputs_num
)*sizeof(char *))) ;
770 while (optind
< argc
)
771 if (argv
[optind
++] != argv
[0])
772 args_info
->inputs
[ i
++ ] = gengetopt_strdup (argv
[optind
-1]) ;
779 cmdline_parser_release (&local_args_info
);
780 return (EXIT_FAILURE
);