diff options
author | Bert <ber.t@gmx.com> | 2011-01-27 16:15:43 +0100 |
---|---|---|
committer | Bert <ber.t@gmx.com> | 2011-01-27 16:15:43 +0100 |
commit | 17e2a795bbcdbf9bc8eb07e2aaca0a494871b9e8 (patch) | |
tree | 7550f6d978ece256b2faa5d10bc300fa0d5eef97 /options.c | |
parent | e8a503bcbb5e29e8364095796d1417db4c138e64 (diff) | |
download | nsxiv-17e2a795bbcdbf9bc8eb07e2aaca0a494871b9e8.tar.zst |
Added -w cmdline option
Diffstat (limited to 'options.c')
-rw-r--r-- | options.c | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -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; } |