Krolyxon
Commit abb5fee

Branches

Refs →

nsxivoptions.c

132 lines · 3.1 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
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA.
17 */
18
19#define _XOPEN_SOURCE
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] [-z ZOOM] FILES...\n");
36}
37
38void print_version() {
39 printf("sxiv %s - simple x image viewer\n", VERSION);
40}
41
42void parse_options(int argc, char **argv) {
43 float z;
44 int n, opt;
45
46 _options.startnum = 0;
47
48 _options.scalemode = SCALE_MODE;
49 _options.zoom = 1.0;
50 _options.aa = 1;
51 _options.thumbnails = 0;
52
53 _options.fixed = 0;
54 _options.fullscreen = 0;
55 _options.geometry = NULL;
56
57 _options.quiet = 0;
58 _options.clean_cache = 0;
59 _options.recursive = 0;
60
61 while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) {
62 switch (opt) {
63 case '?':
64 print_usage();
65 exit(1);
66 case 'c':
67 _options.clean_cache = 1;
68 break;
69 case 'd':
70 _options.scalemode = SCALE_DOWN;
71 break;
72 case 'F':
73 _options.fixed = 1;
74 break;
75 case 'f':
76 _options.fullscreen = 1;
77 break;
78 case 'g':
79 _options.geometry = optarg;
80 break;
81 case 'h':
82 print_usage();
83 exit(0);
84 case 'n':
85 if (!sscanf(optarg, "%d", &n) || n < 1) {
86 fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
87 optarg);
88 exit(1);
89 } else {
90 _options.startnum = n - 1;
91 }
92 break;
93 case 'p':
94 _options.aa = 0;
95 break;
96 case 'q':
97 _options.quiet = 1;
98 break;
99 case 'r':
100 _options.recursive = 1;
101 break;
102 case 's':
103 _options.scalemode = SCALE_FIT;
104 break;
105 case 't':
106 _options.thumbnails = 1;
107 break;
108 case 'v':
109 print_version();
110 exit(0);
111 case 'Z':
112 _options.scalemode = SCALE_ZOOM;
113 _options.zoom = 1.0;
114 break;
115 case 'z':
116 _options.scalemode = SCALE_ZOOM;
117 if (!sscanf(optarg, "%f", &z) || z < 0) {
118 fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
119 optarg);
120 exit(1);
121 } else {
122 _options.zoom = z / 100.0;
123 }
124 break;
125 }
126 }
127
128 _options.filenames = argv + optind;
129 _options.filecnt = argc - optind;
130 _options.from_stdin = _options.filecnt == 1 &&
131 strcmp(_options.filenames[0], "-") == 0;
132}