Krolyxon
Commit 62fb69b

Branches

Refs →

nsxivoptions.c

116 lines · 2.7 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 [-dFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
35}
36
37void print_version() {
38 printf("sxiv version %s - simple x image viewer\n", VERSION);
39}
40
41void parse_options(int argc, char **argv) {
42 float z;
43 int opt;
44
45 _options.scalemode = SCALE_MODE;
46 _options.zoom = 1.0;
47 _options.aa = 1;
48 _options.thumbnails = 0;
49
50 _options.fixed = 0;
51 _options.fullscreen = 0;
52 _options.geometry = NULL;
53
54 _options.quiet = 0;
55 _options.recursive = 0;
56
57 while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) {
58 switch (opt) {
59 case '?':
60 print_usage();
61 exit(1);
62 case 'd':
63 _options.scalemode = SCALE_DOWN;
64 break;
65 case 'F':
66 _options.fixed = 1;
67 break;
68 case 'f':
69 _options.fullscreen = 1;
70 break;
71 case 'g':
72 _options.geometry = optarg;
73 break;
74 case 'h':
75 print_usage();
76 exit(0);
77 case 'p':
78 _options.aa = 0;
79 break;
80 case 'q':
81 _options.quiet = 1;
82 break;
83 case 'r':
84 _options.recursive = 1;
85 break;
86 case 's':
87 _options.scalemode = SCALE_FIT;
88 break;
89 case 't':
90 _options.thumbnails = 1;
91 break;
92 case 'v':
93 print_version();
94 exit(0);
95 case 'Z':
96 _options.scalemode = SCALE_ZOOM;
97 _options.zoom = 1.0;
98 break;
99 case 'z':
100 _options.scalemode = SCALE_ZOOM;
101 if (!sscanf(optarg, "%f", &z) || z < 0) {
102 fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
103 optarg);
104 exit(1);
105 } else {
106 _options.zoom = z / 100.0;
107 }
108 break;
109 }
110 }
111
112 _options.filenames = (const char**) argv + optind;
113 _options.filecnt = argc - optind;
114 _options.from_stdin = _options.filecnt == 1 &&
115 strcmp(_options.filenames[0], "-") == 0;
116}