Krolyxon
Commit e2d4b9c

Branches

Refs →

nsxivoptions.c

144 lines · 3.3 KB · C

1/* sxiv: options.c
2 * Copyright (c) 2011 Bert Muennich <muennich at informatik.hu-berlin.de>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#define _POSIX_C_SOURCE 200112L
20
21#include <stdlib.h>
22#include <string.h>
23#include <stdio.h>
24#include <unistd.h>
25
26#include "options.h"
27#include "util.h"
28
29#define _IMAGE_CONFIG
30#include "config.h"
31
32options_t _options;
33const options_t *options = (const options_t*) &_options;
34
35void print_usage() {
36 printf("usage: sxiv [-cdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] "
37 "[-z ZOOM] FILES...\n");
38}
39
40void print_version() {
41 printf("sxiv %s - Simple X Image Viewer\n", VERSION);
42 printf("Additional features included (+) or not (-): %s, %s\n",
43#ifdef EXIF_SUPPORT
44 "+exif",
45#else
46 "-exif",
47#endif
48#ifdef GIF_SUPPORT
49 "+gif"
50#else
51 "-gif"
52#endif
53 );
54}
55
56void parse_options(int argc, char **argv) {
57 int opt, t;
58
59 _options.recursive = 0;
60 _options.startnum = 0;
61
62 _options.scalemode = SCALE_MODE;
63 _options.zoom = 1.0;
64 _options.aa = 1;
65
66 _options.fixed = 0;
67 _options.fullscreen = 0;
68 _options.geometry = NULL;
69
70 _options.quiet = 0;
71 _options.thumbnails = 0;
72 _options.clean_cache = 0;
73
74 while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) {
75 switch (opt) {
76 case '?':
77 print_usage();
78 exit(1);
79 case 'c':
80 _options.clean_cache = 1;
81 break;
82 case 'd':
83 _options.scalemode = SCALE_DOWN;
84 break;
85 case 'F':
86 _options.fixed = 1;
87 break;
88 case 'f':
89 _options.fullscreen = 1;
90 break;
91 case 'g':
92 _options.geometry = optarg;
93 break;
94 case 'h':
95 print_usage();
96 exit(0);
97 case 'n':
98 if (!sscanf(optarg, "%d", &t) || t < 1) {
99 fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
100 optarg);
101 exit(1);
102 } else {
103 _options.startnum = t - 1;
104 }
105 break;
106 case 'p':
107 _options.aa = 0;
108 break;
109 case 'q':
110 _options.quiet = 1;
111 break;
112 case 'r':
113 _options.recursive = 1;
114 break;
115 case 's':
116 _options.scalemode = SCALE_FIT;
117 break;
118 case 't':
119 _options.thumbnails = 1;
120 break;
121 case 'v':
122 print_version();
123 exit(0);
124 case 'Z':
125 _options.scalemode = SCALE_ZOOM;
126 _options.zoom = 1.0;
127 break;
128 case 'z':
129 _options.scalemode = SCALE_ZOOM;
130 if (!sscanf(optarg, "%d", &t) || t <= 0) {
131 fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
132 optarg);
133 exit(1);
134 }
135 _options.zoom = (float) t / 100.0;
136 break;
137 }
138 }
139
140 _options.filenames = argv + optind;
141 _options.filecnt = argc - optind;
142 _options.from_stdin = _options.filecnt == 1 &&
143 strcmp(_options.filenames[0], "-") == 0;
144}