Krolyxon
Commit 8f99adb

Branches

Refs →

nsxivoptions.c

143 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#define _IMAGE_CONFIG
21
22#include <stdlib.h>
23#include <string.h>
24#include <stdio.h>
25#include <unistd.h>
26
27#include "options.h"
28#include "util.h"
29#include "config.h"
30
31options_t _options;
32const options_t *options = (const options_t*) &_options;
33
34void print_usage() {
35 printf("usage: sxiv [-cdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] "
36 "[-z ZOOM] FILES...\n");
37}
38
39void print_version() {
40 printf("sxiv %s - Simple X Image Viewer\n", VERSION);
41 printf("Additional features included (+) or not (-): %s, %s\n",
42#ifdef EXIF_SUPPORT
43 "+exif",
44#else
45 "-exif",
46#endif
47#ifdef GIF_SUPPORT
48 "+gif"
49#else
50 "-gif"
51#endif
52 );
53}
54
55void parse_options(int argc, char **argv) {
56 int opt, t;
57
58 _options.recursive = false;
59 _options.startnum = 0;
60
61 _options.scalemode = SCALE_MODE;
62 _options.zoom = 1.0;
63 _options.aa = true;
64
65 _options.fixed_win = false;
66 _options.fullscreen = false;
67 _options.geometry = NULL;
68
69 _options.quiet = false;
70 _options.thumb_mode = false;
71 _options.clean_cache = false;
72
73 while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) {
74 switch (opt) {
75 case '?':
76 print_usage();
77 exit(1);
78 case 'c':
79 _options.clean_cache = true;
80 break;
81 case 'd':
82 _options.scalemode = SCALE_DOWN;
83 break;
84 case 'F':
85 _options.fixed_win = true;
86 break;
87 case 'f':
88 _options.fullscreen = true;
89 break;
90 case 'g':
91 _options.geometry = optarg;
92 break;
93 case 'h':
94 print_usage();
95 exit(0);
96 case 'n':
97 if (!sscanf(optarg, "%d", &t) || t < 1) {
98 fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
99 optarg);
100 exit(1);
101 } else {
102 _options.startnum = t - 1;
103 }
104 break;
105 case 'p':
106 _options.aa = false;
107 break;
108 case 'q':
109 _options.quiet = true;
110 break;
111 case 'r':
112 _options.recursive = true;
113 break;
114 case 's':
115 _options.scalemode = SCALE_FIT;
116 break;
117 case 't':
118 _options.thumb_mode = true;
119 break;
120 case 'v':
121 print_version();
122 exit(0);
123 case 'Z':
124 _options.scalemode = SCALE_ZOOM;
125 _options.zoom = 1.0;
126 break;
127 case 'z':
128 _options.scalemode = SCALE_ZOOM;
129 if (!sscanf(optarg, "%d", &t) || t <= 0) {
130 fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
131 optarg);
132 exit(1);
133 }
134 _options.zoom = (float) t / 100.0;
135 break;
136 }
137 }
138
139 _options.filenames = argv + optind;
140 _options.filecnt = argc - optind;
141 _options.from_stdin = _options.filecnt == 1 &&
142 !strcmp(_options.filenames[0], "-");
143}