Krolyxon
Commit b1ce42e

Branches

Refs →

nsxivoptions.c

101 lines · 2.4 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 "sxiv.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 [-dfhpqsvZ] [-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.fullscreen = 0;
49 _options.geometry = NULL;
50
51 _options.quiet = 0;
52
53 while ((opt = getopt(argc, argv, "dfg:hpqsvZz:")) != -1) {
54 switch (opt) {
55 case '?':
56 print_usage();
57 exit(1);
58 case 'd':
59 _options.scalemode = SCALE_DOWN;
60 break;
61 case 'f':
62 _options.fullscreen = 1;
63 break;
64 case 'g':
65 _options.geometry = optarg;
66 break;
67 case 'h':
68 print_usage();
69 exit(0);
70 case 'p':
71 _options.aa = 0;
72 break;
73 case 'q':
74 _options.quiet = 1;
75 break;
76 case 's':
77 _options.scalemode = SCALE_FIT;
78 break;
79 case 'v':
80 print_version();
81 exit(0);
82 case 'Z':
83 _options.scalemode = SCALE_ZOOM;
84 _options.zoom = 1.0;
85 break;
86 case 'z':
87 _options.scalemode = SCALE_ZOOM;
88 if (!sscanf(optarg, "%f", &z) || z < 0) {
89 fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
90 optarg);
91 exit(1);
92 } else {
93 _options.zoom = z / 100.0;
94 }
95 break;
96 }
97 }
98
99 _options.filenames = (const char**) argv + optind;
100 _options.filecnt = argc - optind;
101}