gliv-1.1.3
[gliv.git] / cmdline.c
blobcf95425f6ae2cfacaf1814e1890c7a0db2520868
1 /*
2 File autogenerated by gengetopt version 2.3
3 generated with the following command:
4 gengetopt --input=gliv.ggo --unamed-opts
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>
15 /* If we use autoconf. */
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19 /* Check for configure's getopt check result. */
20 #ifndef HAVE_GETOPT_LONG
21 #include "getopt.h"
22 #else
23 #include <getopt.h>
24 #endif
26 #include "cmdline.h"
29 void
30 cmdline_parser_print_version (void)
32 printf ("%s %s\n", PACKAGE, VERSION);
35 void
36 cmdline_parser_print_help (void)
38 cmdline_parser_print_version ();
39 printf("\n"
40 "Usage: %s [OPTIONS]... FILES...\n\
41 -h --help Print help and exit\n\
42 -V --version Print version and exit\n\
43 -f --full-screen Start in full screen mode (default=off)\n\
44 -s --shuffle Show images in random order (default=off)\n\
45 -R --recursive Process directories recursively (default=off)\n\
46 -i --info Show infos about displayed image (default=on)\n\
47 -m --maximize Maximize image to fit window (default=off)\n\
48 -dINT --delay=INT Delay before hiding the cursor\n\
49 -b --menu Display the menu bar (default=on)\n\
50 ", PACKAGE);
54 static char *
55 gengetopt_strdup (char * s)
57 char * n, * pn, * ps = s;
58 while (*ps) ps++;
59 n = (char *) malloc (1 + ps - s);
60 if (n != NULL)
62 for (ps=s,pn=n; *ps; ps++,pn++)
63 *pn = *ps;
64 *pn = 0;
66 return n;
70 int
71 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
73 int c; /* Character of the parsed option. */
74 int missing_required_options = 0;
76 args_info->help_given = 0 ;
77 args_info->version_given = 0 ;
78 args_info->full_screen_given = 0 ;
79 args_info->shuffle_given = 0 ;
80 args_info->recursive_given = 0 ;
81 args_info->info_given = 0 ;
82 args_info->maximize_given = 0 ;
83 args_info->delay_given = 0 ;
84 args_info->menu_given = 0 ;
85 #define clear_args() { \
86 args_info->full_screen_flag = 0;\
87 args_info->shuffle_flag = 0;\
88 args_info->recursive_flag = 0;\
89 args_info->info_flag = 1;\
90 args_info->maximize_flag = 0;\
91 args_info->menu_flag = 1;\
94 clear_args();
96 args_info->inputs = NULL;
97 args_info->inputs_num = 0;
99 while (1)
101 int option_index = 0;
102 static struct option long_options[] = {
103 { "help", 0, NULL, 'h' },
104 { "version", 0, NULL, 'V' },
105 { "full-screen", 0, NULL, 'f' },
106 { "shuffle", 0, NULL, 's' },
107 { "recursive", 0, NULL, 'R' },
108 { "info", 0, NULL, 'i' },
109 { "maximize", 0, NULL, 'm' },
110 { "delay", 1, NULL, 'd' },
111 { "menu", 0, NULL, 'b' },
112 { NULL, 0, NULL, 0 }
115 c = getopt_long (argc, argv, "hVfsRimd:b", long_options, &option_index);
117 if (c == -1) break; /* Exit from `while (1)' loop. */
119 switch (c)
121 case 'h': /* Print help and exit. */
122 clear_args ();
123 cmdline_parser_print_help ();
124 exit (0);
126 case 'V': /* Print version and exit. */
127 clear_args ();
128 cmdline_parser_print_version ();
129 exit (0);
131 case 'f': /* Start in full screen mode. */
132 args_info->full_screen_flag = !(args_info->full_screen_flag);
133 break;
135 case 's': /* Show images in random order. */
136 args_info->shuffle_flag = !(args_info->shuffle_flag);
137 break;
139 case 'R': /* Process directories recursively. */
140 args_info->recursive_flag = !(args_info->recursive_flag);
141 break;
143 case 'i': /* Show infos about displayed image. */
144 args_info->info_flag = !(args_info->info_flag);
145 break;
147 case 'm': /* Maximize image to fit window. */
148 args_info->maximize_flag = !(args_info->maximize_flag);
149 break;
151 case 'd': /* Delay before hiding the cursor. */
152 if (args_info->delay_given)
154 fprintf (stderr, "%s: `--delay' (`-d') option given more than once\n", PACKAGE);
155 clear_args ();
156 cmdline_parser_print_help ();
157 exit (1);
159 args_info->delay_given = 1;
160 args_info->delay_arg = atoi (optarg);
161 break;
163 case 'b': /* Display the menu bar. */
164 args_info->menu_flag = !(args_info->menu_flag);
165 break;
167 case 0: /* Long option with no short option */
169 case '?': /* Invalid option. */
170 /* `getopt_long' already printed an error message. */
171 exit (1);
173 default: /* bug: option not considered. */
174 fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
175 abort ();
176 } /* switch */
177 } /* while */
179 if ( missing_required_options )
180 exit (1);
182 if (optind < argc)
184 int i = 0 ;
186 args_info->inputs_num = argc - optind ;
187 args_info->inputs =
188 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
189 while (optind < argc)
190 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
193 return 0;