Krolyxon
Commit f71ea09

Branches

Refs →

nsxivoptions.c

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