Don't close the window when the user refused to quit.
[gliv.git] / src / cmdline.c
blobb7b0d028b6e64ac2d370f0c150f8c0d9f050f95d
1 /*
2 File autogenerated by gengetopt version 2.10
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 */
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
16 /* If we use autoconf. */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
21 #include "getopt.h"
23 #include "cmdline.h"
25 void
26 cmdline_parser_print_version (void)
28 printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
31 void
32 cmdline_parser_print_help (void)
34 cmdline_parser_print_version ();
35 printf("\n"
36 "Purpose:\n"
37 " Image Viewer using OpenGL\n"
38 "\n"
39 "Usage: %s [OPTIONS]... [FILES]...\n", CMDLINE_PARSER_PACKAGE);
40 printf(" -h --help Print help and exit\n");
41 printf(" -V --version Print version and exit\n");
42 printf("\n");
43 printf(" Group: sort\n");
44 printf(" -s --shuffle Show images in random order\n");
45 printf(" -S --sort Show images in sorted order\n");
46 printf(" -R --recursive Process directories recursively (default=off)\n");
47 printf(" -f --full-screen Start in full screen mode (default=off)\n");
48 printf(" -l --scale-down Reduce the image to the window (default=off)\n");
49 printf(" -M --maximize Maximize the image to the window (default=off)\n");
50 printf(" -m --make-fit Make the image fit the window (default=off)\n");
51 printf(" -z --zoom-pointer Zoom centered on pointer (default=off)\n");
52 printf(" -t --dither Enable dithering (default=off)\n");
53 printf(" -F --force-load Try to load every file (default=off)\n");
54 printf(" -p --mipmap Build Mipmaps (default=off)\n");
55 printf(" -n --mnemonics Make mnemonics for images menus (default=off)\n");
56 printf(" -w --slide-show Start the slide show immediately (default=off)\n");
57 printf(" -L --loop Make the slide show loop at the end (default=off)\n");
58 printf(" -1 --one-image Keep only one image in memory (default=off)\n");
59 printf(" -0 --null Read null-terminated filenames (default=off)\n");
60 printf(" -e --build-menus Build images menu at startup (default=on)\n");
61 printf(" -b --menu Display the menu bar (default=on)\n");
62 printf(" -i --info Show infos about displayed image (default=on)\n");
63 printf(" -o --scrollbars Display scrollbars (default=on)\n");
64 printf(" -g --glivrc Load ~/.glivrc (default=on)\n");
65 printf(" -c --alpha-checks Alpha checks in the background (default=on)\n");
66 printf(" -T --thumbnails Show thumbnails in images menus (default=on)\n");
67 printf(" -W --resize-win Automatic window resizing (default=on)\n");
68 printf(" -dINT --delay=INT Delay before hiding the cursor\n");
69 printf(" -uINT --history=INT Length of history\n");
70 printf(" -aINT --duration=INT Delay between each image\n");
71 printf(" -PINT --fps=INT Maximum framerate\n");
75 static char *gengetopt_strdup (const char *s);
77 /* gengetopt_strdup() */
78 /* strdup.c replacement of strdup, which is not standard */
79 char *
80 gengetopt_strdup (const char *s)
82 char *result = (char*)malloc(strlen(s) + 1);
83 if (result == (char*)0)
84 return (char*)0;
85 strcpy(result, s);
86 return result;
89 int
90 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
92 int c; /* Character of the parsed option. */
93 int missing_required_options = 0;
94 int sort_group_counter = 0;
97 args_info->help_given = 0 ;
98 args_info->version_given = 0 ;
99 args_info->shuffle_given = 0 ;
100 args_info->sort_given = 0 ;
101 args_info->recursive_given = 0 ;
102 args_info->full_screen_given = 0 ;
103 args_info->scale_down_given = 0 ;
104 args_info->maximize_given = 0 ;
105 args_info->make_fit_given = 0 ;
106 args_info->zoom_pointer_given = 0 ;
107 args_info->dither_given = 0 ;
108 args_info->force_load_given = 0 ;
109 args_info->mipmap_given = 0 ;
110 args_info->mnemonics_given = 0 ;
111 args_info->slide_show_given = 0 ;
112 args_info->loop_given = 0 ;
113 args_info->one_image_given = 0 ;
114 args_info->null_given = 0 ;
115 args_info->build_menus_given = 0 ;
116 args_info->menu_given = 0 ;
117 args_info->info_given = 0 ;
118 args_info->scrollbars_given = 0 ;
119 args_info->glivrc_given = 0 ;
120 args_info->alpha_checks_given = 0 ;
121 args_info->thumbnails_given = 0 ;
122 args_info->resize_win_given = 0 ;
123 args_info->delay_given = 0 ;
124 args_info->history_given = 0 ;
125 args_info->duration_given = 0 ;
126 args_info->fps_given = 0 ;
127 #define clear_args() { \
128 args_info->recursive_flag = 0;\
129 args_info->full_screen_flag = 0;\
130 args_info->scale_down_flag = 0;\
131 args_info->maximize_flag = 0;\
132 args_info->make_fit_flag = 0;\
133 args_info->zoom_pointer_flag = 0;\
134 args_info->dither_flag = 0;\
135 args_info->force_load_flag = 0;\
136 args_info->mipmap_flag = 0;\
137 args_info->mnemonics_flag = 0;\
138 args_info->slide_show_flag = 0;\
139 args_info->loop_flag = 0;\
140 args_info->one_image_flag = 0;\
141 args_info->null_flag = 0;\
142 args_info->build_menus_flag = 1;\
143 args_info->menu_flag = 1;\
144 args_info->info_flag = 1;\
145 args_info->scrollbars_flag = 1;\
146 args_info->glivrc_flag = 1;\
147 args_info->alpha_checks_flag = 1;\
148 args_info->thumbnails_flag = 1;\
149 args_info->resize_win_flag = 1;\
152 clear_args();
154 args_info->inputs = NULL;
155 args_info->inputs_num = 0;
157 optarg = 0;
158 optind = 1;
159 opterr = 1;
160 optopt = '?';
162 while (1)
164 int option_index = 0;
165 char *stop_char;
167 static struct option long_options[] = {
168 { "help", 0, NULL, 'h' },
169 { "version", 0, NULL, 'V' },
170 { "shuffle", 0, NULL, 's' },
171 { "sort", 0, NULL, 'S' },
172 { "recursive", 0, NULL, 'R' },
173 { "full-screen", 0, NULL, 'f' },
174 { "scale-down", 0, NULL, 'l' },
175 { "maximize", 0, NULL, 'M' },
176 { "make-fit", 0, NULL, 'm' },
177 { "zoom-pointer", 0, NULL, 'z' },
178 { "dither", 0, NULL, 't' },
179 { "force-load", 0, NULL, 'F' },
180 { "mipmap", 0, NULL, 'p' },
181 { "mnemonics", 0, NULL, 'n' },
182 { "slide-show", 0, NULL, 'w' },
183 { "loop", 0, NULL, 'L' },
184 { "one-image", 0, NULL, '1' },
185 { "null", 0, NULL, '0' },
186 { "build-menus", 0, NULL, 'e' },
187 { "menu", 0, NULL, 'b' },
188 { "info", 0, NULL, 'i' },
189 { "scrollbars", 0, NULL, 'o' },
190 { "glivrc", 0, NULL, 'g' },
191 { "alpha-checks", 0, NULL, 'c' },
192 { "thumbnails", 0, NULL, 'T' },
193 { "resize-win", 0, NULL, 'W' },
194 { "delay", 1, NULL, 'd' },
195 { "history", 1, NULL, 'u' },
196 { "duration", 1, NULL, 'a' },
197 { "fps", 1, NULL, 'P' },
198 { NULL, 0, NULL, 0 }
201 stop_char = 0;
202 c = getopt_long (argc, argv, "hVsSRflMmztFpnwL10ebiogcTWd:u:a:P:", long_options, &option_index);
204 if (c == -1) break; /* Exit from `while (1)' loop. */
206 switch (c)
208 case 'h': /* Print help and exit. */
209 clear_args ();
210 cmdline_parser_print_help ();
211 exit (EXIT_SUCCESS);
213 case 'V': /* Print version and exit. */
214 clear_args ();
215 cmdline_parser_print_version ();
216 exit (EXIT_SUCCESS);
218 case 's': /* Show images in random order. */
219 if (args_info->shuffle_given)
221 fprintf (stderr, "%s: `--shuffle' (`-s') option given more than once\n", CMDLINE_PARSER_PACKAGE);
222 clear_args ();
223 return (EXIT_FAILURE);
225 args_info->shuffle_given = 1;
226 sort_group_counter += 1;
227 break;
229 case 'S': /* Show images in sorted order. */
230 if (args_info->sort_given)
232 fprintf (stderr, "%s: `--sort' (`-S') option given more than once\n", CMDLINE_PARSER_PACKAGE);
233 clear_args ();
234 return (EXIT_FAILURE);
236 args_info->sort_given = 1;
237 sort_group_counter += 1;
238 break;
240 case 'R': /* Process directories recursively. */
241 if (args_info->recursive_given)
243 fprintf (stderr, "%s: `--recursive' (`-R') option given more than once\n", CMDLINE_PARSER_PACKAGE);
244 clear_args ();
245 return (EXIT_FAILURE);
247 args_info->recursive_given = 1;
248 args_info->recursive_flag = !(args_info->recursive_flag);
249 break;
251 case 'f': /* Start in full screen mode. */
252 if (args_info->full_screen_given)
254 fprintf (stderr, "%s: `--full-screen' (`-f') option given more than once\n", CMDLINE_PARSER_PACKAGE);
255 clear_args ();
256 return (EXIT_FAILURE);
258 args_info->full_screen_given = 1;
259 args_info->full_screen_flag = !(args_info->full_screen_flag);
260 break;
262 case 'l': /* Reduce the image to the window. */
263 if (args_info->scale_down_given)
265 fprintf (stderr, "%s: `--scale-down' (`-l') option given more than once\n", CMDLINE_PARSER_PACKAGE);
266 clear_args ();
267 return (EXIT_FAILURE);
269 args_info->scale_down_given = 1;
270 args_info->scale_down_flag = !(args_info->scale_down_flag);
271 break;
273 case 'M': /* Maximize the image to the window. */
274 if (args_info->maximize_given)
276 fprintf (stderr, "%s: `--maximize' (`-M') option given more than once\n", CMDLINE_PARSER_PACKAGE);
277 clear_args ();
278 return (EXIT_FAILURE);
280 args_info->maximize_given = 1;
281 args_info->maximize_flag = !(args_info->maximize_flag);
282 break;
284 case 'm': /* Make the image fit the window. */
285 if (args_info->make_fit_given)
287 fprintf (stderr, "%s: `--make-fit' (`-m') option given more than once\n", CMDLINE_PARSER_PACKAGE);
288 clear_args ();
289 return (EXIT_FAILURE);
291 args_info->make_fit_given = 1;
292 args_info->make_fit_flag = !(args_info->make_fit_flag);
293 break;
295 case 'z': /* Zoom centered on pointer. */
296 if (args_info->zoom_pointer_given)
298 fprintf (stderr, "%s: `--zoom-pointer' (`-z') option given more than once\n", CMDLINE_PARSER_PACKAGE);
299 clear_args ();
300 return (EXIT_FAILURE);
302 args_info->zoom_pointer_given = 1;
303 args_info->zoom_pointer_flag = !(args_info->zoom_pointer_flag);
304 break;
306 case 't': /* Enable dithering. */
307 if (args_info->dither_given)
309 fprintf (stderr, "%s: `--dither' (`-t') option given more than once\n", CMDLINE_PARSER_PACKAGE);
310 clear_args ();
311 return (EXIT_FAILURE);
313 args_info->dither_given = 1;
314 args_info->dither_flag = !(args_info->dither_flag);
315 break;
317 case 'F': /* Try to load every file. */
318 if (args_info->force_load_given)
320 fprintf (stderr, "%s: `--force-load' (`-F') option given more than once\n", CMDLINE_PARSER_PACKAGE);
321 clear_args ();
322 return (EXIT_FAILURE);
324 args_info->force_load_given = 1;
325 args_info->force_load_flag = !(args_info->force_load_flag);
326 break;
328 case 'p': /* Build Mipmaps. */
329 if (args_info->mipmap_given)
331 fprintf (stderr, "%s: `--mipmap' (`-p') option given more than once\n", CMDLINE_PARSER_PACKAGE);
332 clear_args ();
333 return (EXIT_FAILURE);
335 args_info->mipmap_given = 1;
336 args_info->mipmap_flag = !(args_info->mipmap_flag);
337 break;
339 case 'n': /* Make mnemonics for images menus. */
340 if (args_info->mnemonics_given)
342 fprintf (stderr, "%s: `--mnemonics' (`-n') option given more than once\n", CMDLINE_PARSER_PACKAGE);
343 clear_args ();
344 return (EXIT_FAILURE);
346 args_info->mnemonics_given = 1;
347 args_info->mnemonics_flag = !(args_info->mnemonics_flag);
348 break;
350 case 'w': /* Start the slide show immediately. */
351 if (args_info->slide_show_given)
353 fprintf (stderr, "%s: `--slide-show' (`-w') option given more than once\n", CMDLINE_PARSER_PACKAGE);
354 clear_args ();
355 return (EXIT_FAILURE);
357 args_info->slide_show_given = 1;
358 args_info->slide_show_flag = !(args_info->slide_show_flag);
359 break;
361 case 'L': /* Make the slide show loop at the end. */
362 if (args_info->loop_given)
364 fprintf (stderr, "%s: `--loop' (`-L') option given more than once\n", CMDLINE_PARSER_PACKAGE);
365 clear_args ();
366 return (EXIT_FAILURE);
368 args_info->loop_given = 1;
369 args_info->loop_flag = !(args_info->loop_flag);
370 break;
372 case '1': /* Keep only one image in memory. */
373 if (args_info->one_image_given)
375 fprintf (stderr, "%s: `--one-image' (`-1') option given more than once\n", CMDLINE_PARSER_PACKAGE);
376 clear_args ();
377 return (EXIT_FAILURE);
379 args_info->one_image_given = 1;
380 args_info->one_image_flag = !(args_info->one_image_flag);
381 break;
383 case '0': /* Read null-terminated filenames. */
384 if (args_info->null_given)
386 fprintf (stderr, "%s: `--null' (`-0') option given more than once\n", CMDLINE_PARSER_PACKAGE);
387 clear_args ();
388 return (EXIT_FAILURE);
390 args_info->null_given = 1;
391 args_info->null_flag = !(args_info->null_flag);
392 break;
394 case 'e': /* Build images menu at startup. */
395 if (args_info->build_menus_given)
397 fprintf (stderr, "%s: `--build-menus' (`-e') option given more than once\n", CMDLINE_PARSER_PACKAGE);
398 clear_args ();
399 return (EXIT_FAILURE);
401 args_info->build_menus_given = 1;
402 args_info->build_menus_flag = !(args_info->build_menus_flag);
403 break;
405 case 'b': /* Display the menu bar. */
406 if (args_info->menu_given)
408 fprintf (stderr, "%s: `--menu' (`-b') option given more than once\n", CMDLINE_PARSER_PACKAGE);
409 clear_args ();
410 return (EXIT_FAILURE);
412 args_info->menu_given = 1;
413 args_info->menu_flag = !(args_info->menu_flag);
414 break;
416 case 'i': /* Show infos about displayed image. */
417 if (args_info->info_given)
419 fprintf (stderr, "%s: `--info' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE);
420 clear_args ();
421 return (EXIT_FAILURE);
423 args_info->info_given = 1;
424 args_info->info_flag = !(args_info->info_flag);
425 break;
427 case 'o': /* Display scrollbars. */
428 if (args_info->scrollbars_given)
430 fprintf (stderr, "%s: `--scrollbars' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
431 clear_args ();
432 return (EXIT_FAILURE);
434 args_info->scrollbars_given = 1;
435 args_info->scrollbars_flag = !(args_info->scrollbars_flag);
436 break;
438 case 'g': /* Load ~/.glivrc. */
439 if (args_info->glivrc_given)
441 fprintf (stderr, "%s: `--glivrc' (`-g') option given more than once\n", CMDLINE_PARSER_PACKAGE);
442 clear_args ();
443 return (EXIT_FAILURE);
445 args_info->glivrc_given = 1;
446 args_info->glivrc_flag = !(args_info->glivrc_flag);
447 break;
449 case 'c': /* Alpha checks in the background. */
450 if (args_info->alpha_checks_given)
452 fprintf (stderr, "%s: `--alpha-checks' (`-c') option given more than once\n", CMDLINE_PARSER_PACKAGE);
453 clear_args ();
454 return (EXIT_FAILURE);
456 args_info->alpha_checks_given = 1;
457 args_info->alpha_checks_flag = !(args_info->alpha_checks_flag);
458 break;
460 case 'T': /* Show thumbnails in images menus. */
461 if (args_info->thumbnails_given)
463 fprintf (stderr, "%s: `--thumbnails' (`-T') option given more than once\n", CMDLINE_PARSER_PACKAGE);
464 clear_args ();
465 return (EXIT_FAILURE);
467 args_info->thumbnails_given = 1;
468 args_info->thumbnails_flag = !(args_info->thumbnails_flag);
469 break;
471 case 'W': /* Automatic window resizing. */
472 if (args_info->resize_win_given)
474 fprintf (stderr, "%s: `--resize-win' (`-W') option given more than once\n", CMDLINE_PARSER_PACKAGE);
475 clear_args ();
476 return (EXIT_FAILURE);
478 args_info->resize_win_given = 1;
479 args_info->resize_win_flag = !(args_info->resize_win_flag);
480 break;
482 case 'd': /* Delay before hiding the cursor. */
483 if (args_info->delay_given)
485 fprintf (stderr, "%s: `--delay' (`-d') option given more than once\n", CMDLINE_PARSER_PACKAGE);
486 clear_args ();
487 return (EXIT_FAILURE);
489 args_info->delay_given = 1;
490 args_info->delay_arg = strtol (optarg,&stop_char,0);
491 break;
493 case 'u': /* Length of history. */
494 if (args_info->history_given)
496 fprintf (stderr, "%s: `--history' (`-u') option given more than once\n", CMDLINE_PARSER_PACKAGE);
497 clear_args ();
498 return (EXIT_FAILURE);
500 args_info->history_given = 1;
501 args_info->history_arg = strtol (optarg,&stop_char,0);
502 break;
504 case 'a': /* Delay between each image. */
505 if (args_info->duration_given)
507 fprintf (stderr, "%s: `--duration' (`-a') option given more than once\n", CMDLINE_PARSER_PACKAGE);
508 clear_args ();
509 return (EXIT_FAILURE);
511 args_info->duration_given = 1;
512 args_info->duration_arg = strtol (optarg,&stop_char,0);
513 break;
515 case 'P': /* Maximum framerate. */
516 if (args_info->fps_given)
518 fprintf (stderr, "%s: `--fps' (`-P') option given more than once\n", CMDLINE_PARSER_PACKAGE);
519 clear_args ();
520 return (EXIT_FAILURE);
522 args_info->fps_given = 1;
523 args_info->fps_arg = strtol (optarg,&stop_char,0);
524 break;
527 case 0: /* Long option with no short option */
529 case '?': /* Invalid option. */
530 /* `getopt_long' already printed an error message. */
531 return (EXIT_FAILURE);
533 default: /* bug: option not considered. */
534 fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
535 abort ();
536 } /* switch */
537 } /* while */
539 if ( sort_group_counter > 1)
541 fprintf (stderr, "%s: %d options of group sort were given. At most one is required\n", CMDLINE_PARSER_PACKAGE, sort_group_counter);
542 missing_required_options = 1;
546 if ( missing_required_options )
547 return (EXIT_FAILURE);
549 if (optind < argc)
551 int i = 0 ;
553 args_info->inputs_num = argc - optind ;
554 args_info->inputs =
555 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
556 while (optind < argc)
557 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
560 return 0;