From 17e2a795bbcdbf9bc8eb07e2aaca0a494871b9e8 Mon Sep 17 00:00:00 2001 From: Bert Date: Thu, 27 Jan 2011 16:15:43 +0100 Subject: Added -w cmdline option --- options.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'options.c') 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; } -- cgit v1.2.3-54-g00ecf