Krolyxon
Commit 26c2179

Branches

Refs →

nsxivoptions.c

120 lines · 2.8 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
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#define _XOPEN_SOURCE
20
21#include <stdlib.h>
22#include <string.h>
23#include <stdio.h>
24#include <unistd.h>
25
26#include "config.h"
27#include "options.h"
28#include "util.h"
29
30options_t _options;
31const options_t *options = (const options_t*) &_options;
32
33void print_usage() {
34 printf("usage: sxiv [-dFfhpqrsTtvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
35}
36
37void print_version() {
38 printf("sxiv - simple x image viewer\n");
39 printf("Version %s, written by Bert Muennich\n", VERSION);
40}
41
42void parse_options(int argc, char **argv) {
43 float z;
44 int opt;
45
46 _options.scalemode = SCALE_MODE;
47 _options.zoom = 1.0;
48 _options.aa = 1;
49 _options.thumbnails = 0;
50
51 _options.fixed = 0;
52 _options.fullscreen = 0;
53 _options.geometry = NULL;
54
55 _options.quiet = 0;
56 _options.recursive = 0;
57
58 while ((opt = getopt(argc, argv, "dFfg:hpqrsTtvZz:")) != -1) {
59 switch (opt) {
60 case '?':
61 print_usage();
62 exit(1);
63 case 'd':
64 _options.scalemode = SCALE_DOWN;
65 break;
66 case 'F':
67 _options.fixed = 1;
68 break;
69 case 'f':
70 _options.fullscreen = 1;
71 break;
72 case 'g':
73 _options.geometry = optarg;
74 break;
75 case 'h':
76 print_usage();
77 exit(0);
78 case 'p':
79 _options.aa = 0;
80 break;
81 case 'q':
82 _options.quiet = 1;
83 break;
84 case 'r':
85 _options.recursive = 1;
86 break;
87 case 's':
88 _options.scalemode = SCALE_FIT;
89 break;
90 case 'T':
91 _options.thumbnails = 2;
92 break;
93 case 't':
94 _options.thumbnails = MAX(_options.thumbnails, 1);
95 break;
96 case 'v':
97 print_version();
98 exit(0);
99 case 'Z':
100 _options.scalemode = SCALE_ZOOM;
101 _options.zoom = 1.0;
102 break;
103 case 'z':
104 _options.scalemode = SCALE_ZOOM;
105 if (!sscanf(optarg, "%f", &z) || z < 0) {
106 fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
107 optarg);
108 exit(1);
109 } else {
110 _options.zoom = z / 100.0;
111 }
112 break;
113 }
114 }
115
116 _options.filenames = (const char**) argv + optind;
117 _options.filecnt = argc - optind;
118 _options.from_stdin = _options.filecnt == 1 &&
119 strcmp(_options.filenames[0], "-") == 0;
120}