summaryrefslogtreecommitdiffstats
path: root/options.c
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-01-27 16:15:43 +0100
committerBert <ber.t@gmx.com>2011-01-27 16:15:43 +0100
commit17e2a795bbcdbf9bc8eb07e2aaca0a494871b9e8 (patch)
tree7550f6d978ece256b2faa5d10bc300fa0d5eef97 /options.c
parente8a503bcbb5e29e8364095796d1417db4c138e64 (diff)
downloadnsxiv-17e2a795bbcdbf9bc8eb07e2aaca0a494871b9e8.tar.zst
Added -w cmdline option
Diffstat (limited to 'options.c')
-rw-r--r--options.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/options.c b/options.c
index 50f2012..b0beae9 100644
--- a/options.c
+++ b/options.c
@@ -29,7 +29,7 @@ options_t _options;
const options_t *options = (const options_t*) &_options;
void print_usage() {
- printf("usage: sxiv [-hv] FILES...\n");
+ printf("usage: sxiv [-hv] [-w WIDTH[xHEIGHT]] FILES...\n");
}
void print_version() {
@@ -38,9 +38,13 @@ void print_version() {
}
void parse_options(int argc, char **argv) {
+ unsigned short w, h;
int opt;
- while ((opt = getopt(argc, argv, "hv")) != -1) {
+ _options.winw = w = 0;
+ _options.winh = h = 0;
+
+ while ((opt = getopt(argc, argv, "hvw:")) != -1) {
switch (opt) {
case '?':
print_usage();
@@ -51,9 +55,26 @@ void parse_options(int argc, char **argv) {
case 'v':
print_version();
exit(0);
+ case 'w':
+ if (!sscanf(optarg, "%hux%hu", &w, &h)) {
+ fprintf(stderr, "sxiv: invalid argument for option -w: %s\n",
+ optarg);
+ exit(1);
+ } else {
+ _options.winw = (int) w;
+ _options.winh = (int) h;
+ }
+ break;
}
}
+ if (!_options.winw) {
+ _options.winw = WIN_WIDTH;
+ _options.winh = WIN_HEIGHT;
+ } else if (!_options.winh) {
+ _options.winh = _options.winw;
+ }
+
_options.filenames = (const char**) argv + optind;
_options.filecnt = argc - optind;
}