Merged older cs.po file with newest pot file.
[gliv/czech_localization.git] / src / cmdline.c
blobb830c420e4f952153ac5fc47649e982e5ad17e7a
1 /*
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.
9 */
11 /* If we use autoconf. */
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
20 #include "getopt.h"
22 #include "cmdline.h"
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",
49 typedef enum {ARG_NO
50 , ARG_STRING
51 } cmdline_parser_arg_type;
53 static
54 void clear_given (struct gengetopt_args_info *args_info);
55 static
56 void clear_args (struct gengetopt_args_info *args_info);
58 static int
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);
63 static char *
64 gengetopt_strdup (const char *s);
66 static
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 ;
86 static
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;
118 static
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] ;
141 void
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);
156 printf("\n");
158 if (strlen(gengetopt_args_info_description) > 0)
159 printf("%s\n\n", gengetopt_args_info_description);
162 void
163 cmdline_parser_print_help (void)
165 int i = 0;
166 print_help_common();
167 while (gengetopt_args_info_help[i])
168 printf("%s\n", gengetopt_args_info_help[i++]);
171 void
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;
182 void
183 cmdline_parser_params_init(struct cmdline_parser_params *params)
185 if (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);
201 return params;
204 static void
205 free_string_field (char **s)
207 if (*s)
209 free (*s);
210 *s = 0;
215 static void
216 cmdline_parser_release (struct gengetopt_args_info *args_info)
218 unsigned int i;
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);
257 static void
258 write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
260 if (arg) {
261 fprintf(outfile, "%s=\"%s\"\n", opt, arg);
262 } else {
263 fprintf(outfile, "%s\n", opt);
269 cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
271 int i = 0;
273 if (!outfile)
275 fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
276 return EXIT_FAILURE;
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);
311 i = EXIT_SUCCESS;
312 return i;
316 cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
318 FILE *outfile;
319 int i = 0;
321 outfile = fopen(filename, "w");
323 if (!outfile)
325 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
326 return EXIT_FAILURE;
329 i = cmdline_parser_dump(outfile, args_info);
330 fclose (outfile);
332 return i;
335 void
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 */
342 char *
343 gengetopt_strdup (const char *s)
345 char *result = NULL;
346 if (!s)
347 return result;
349 result = (char*)malloc(strlen(s) + 1);
350 if (result == (char*)0)
351 return (char*)0;
352 strcpy(result, s);
353 return result;
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)
366 int result;
367 result = cmdline_parser_internal (argc, argv, args_info, params, NULL);
369 return result;
373 cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
375 int result;
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, &params, NULL);
386 return result;
390 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
392 return EXIT_SUCCESS;
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
416 static
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)
426 char *stop_char = 0;
427 const char *val = value;
428 int found;
429 char **string_field;
431 stop_char = 0;
432 found = 0;
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 : ""));
440 else
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)
449 return 0;
450 if (prev_given)
451 (*prev_given)++;
452 if (field_given)
453 (*field_given)++;
454 if (possible_values)
455 val = possible_values[found];
457 switch(arg_type) {
458 case ARG_STRING:
459 if (val) {
460 string_field = (char **)field;
461 if (!no_free && *string_field)
462 free (*string_field); /* free previous string */
463 *string_field = gengetopt_strdup (val);
465 break;
466 default:
467 break;
471 /* store the original value */
472 switch(arg_type) {
473 case ARG_NO:
474 break;
475 default:
476 if (value && orig_field) {
477 if (no_free) {
478 *orig_field = value;
479 } else {
480 if (*orig_field)
481 free (*orig_field); /* free previous string */
482 *orig_field = gengetopt_strdup (value);
487 return 0; /* OK */
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. */
497 int error = 0;
498 struct gengetopt_args_info local_args_info;
500 int override;
501 int initialize;
502 int check_required;
503 int check_ambiguity;
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;
512 if (initialize)
513 cmdline_parser_init (args_info);
515 cmdline_parser_init (&local_args_info);
517 optarg = 0;
518 optind = 0;
519 opterr = params->print_errors;
520 optopt = '?';
522 while (1)
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' },
542 { NULL, 0, NULL, 0 }
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. */
549 switch (c)
551 case 'h': /* Print help and exit. */
552 cmdline_parser_print_help ();
553 cmdline_parser_free (&local_args_info);
554 exit (EXIT_SUCCESS);
556 case 'V': /* Print version and exit. */
557 cmdline_parser_print_version ();
558 cmdline_parser_free (&local_args_info);
559 exit (EXIT_SUCCESS);
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,
568 "add-all", 'a',
569 additional_error))
570 goto failure;
572 break;
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,
580 "recursive", 'R',
581 additional_error))
582 goto failure;
584 break;
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,
592 "sort", 'S',
593 additional_error))
594 goto failure;
596 break;
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,
604 "shuffle", 's',
605 additional_error))
606 goto failure;
608 break;
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,
616 "force-load", 'F',
617 additional_error))
618 goto failure;
620 break;
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,
628 "client", 'C',
629 additional_error))
630 goto failure;
632 break;
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,
640 "client-clear", 'c',
641 additional_error))
642 goto failure;
644 break;
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,
652 "build-menus", 'e',
653 additional_error))
654 goto failure;
656 break;
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,
664 "glivrc", 'g',
665 additional_error))
666 goto failure;
668 break;
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,
676 "slide-show", 'w',
677 additional_error))
678 goto failure;
680 break;
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,
688 "null", '0',
689 additional_error))
690 goto failure;
692 break;
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,
700 "collection", 'o',
701 additional_error))
702 goto failure;
704 break;
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,
712 "geometry", 'G',
713 additional_error))
714 goto failure;
716 break;
718 case 0: /* Long option with no short option */
719 case '?': /* Invalid option. */
720 /* `getopt_long' already printed an error message. */
721 goto failure;
723 default: /* bug: option not considered. */
724 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
725 abort ();
726 } /* switch */
727 } /* while */
732 cmdline_parser_release (&local_args_info);
734 if ( error )
735 return (EXIT_FAILURE);
737 if (optind < argc)
739 int i = 0 ;
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) */
745 i = optind;
746 while (i < argc)
747 if (argv[i++] == argv[0]) {
748 found_prog_name = 1;
749 break;
751 i = 0;
753 args_info->inputs_num = argc - optind - found_prog_name;
754 args_info->inputs =
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]) ;
761 return 0;
763 failure:
765 cmdline_parser_release (&local_args_info);
766 return (EXIT_FAILURE);