Krolyxon
Commit 8f4af65

Branches

Refs →

nsxivoptions.c

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