Krolyxon
Commit a527025

Branches

Refs →

nsxivoptions.c

142 lines · 3.2 KB · C

1/* Copyright 2011 Bert Muennich
2 *
3 * This file is part of sxiv.
4 *
5 * sxiv is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License,
8 * or (at your option) any later version.
9 *
10 * sxiv is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
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(void)
35{
36 printf("usage: sxiv [-bcdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] "
37 "[-N name] [-z ZOOM] FILES...\n");
38}
39
40void print_version(void)
41{
42 printf("sxiv %s - Simple X Image Viewer\n", VERSION);
43}
44
45void parse_options(int argc, char **argv)
46{
47 int opt, t;
48
49 _options.recursive = false;
50 _options.startnum = 0;
51
52 _options.scalemode = SCALE_MODE;
53 _options.zoom = 1.0;
54 _options.aa = true;
55
56 _options.fixed_win = false;
57 _options.fullscreen = false;
58 _options.hide_bar = false;
59 _options.geometry = NULL;
60 _options.res_name = NULL;
61
62 _options.quiet = false;
63 _options.thumb_mode = false;
64 _options.clean_cache = false;
65
66 while ((opt = getopt(argc, argv, "bcdFfg:hn:N:pqrstvZz:")) != -1) {
67 switch (opt) {
68 case '?':
69 print_usage();
70 exit(EXIT_FAILURE);
71 case 'b':
72 _options.hide_bar = true;
73 break;
74 case 'c':
75 _options.clean_cache = true;
76 break;
77 case 'd':
78 _options.scalemode = SCALE_DOWN;
79 break;
80 case 'F':
81 _options.fixed_win = true;
82 break;
83 case 'f':
84 _options.fullscreen = true;
85 break;
86 case 'g':
87 _options.geometry = optarg;
88 break;
89 case 'h':
90 print_usage();
91 exit(EXIT_SUCCESS);
92 case 'n':
93 if (sscanf(optarg, "%d", &t) <= 0 || t < 1) {
94 fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
95 optarg);
96 exit(EXIT_FAILURE);
97 } else {
98 _options.startnum = t - 1;
99 }
100 break;
101 case 'N':
102 _options.res_name = optarg;
103 break;
104 case 'p':
105 _options.aa = false;
106 break;
107 case 'q':
108 _options.quiet = true;
109 break;
110 case 'r':
111 _options.recursive = true;
112 break;
113 case 's':
114 _options.scalemode = SCALE_FIT;
115 break;
116 case 't':
117 _options.thumb_mode = true;
118 break;
119 case 'v':
120 print_version();
121 exit(EXIT_SUCCESS);
122 case 'Z':
123 _options.scalemode = SCALE_ZOOM;
124 _options.zoom = 1.0;
125 break;
126 case 'z':
127 _options.scalemode = SCALE_ZOOM;
128 if (sscanf(optarg, "%d", &t) <= 0 || t <= 0) {
129 fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
130 optarg);
131 exit(EXIT_FAILURE);
132 }
133 _options.zoom = (float) t / 100.0;
134 break;
135 }
136 }
137
138 _options.filenames = argv + optind;
139 _options.filecnt = argc - optind;
140 _options.from_stdin = _options.filecnt == 1 &&
141 STREQ(_options.filenames[0], "-");
142}