From 997c8518c5884fecf03fb3d677dbc6d80d11c9df Mon Sep 17 00:00:00 2001 From: Bert Münnich Date: Tue, 4 Feb 2014 23:05:29 +0100 Subject: Set scale mode at startup via argument to -s option --- options.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'options.c') diff --git a/options.c b/options.c index c074677..bf993e3 100644 --- a/options.c +++ b/options.c @@ -33,8 +33,8 @@ const options_t *options = (const options_t*) &_options; void print_usage(void) { - printf("usage: sxiv [-bcFfhioqrstvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] " - "[-N NAME] [-S DELAY] [-z ZOOM] FILES...\n"); + printf("usage: sxiv [-bcFfhioqrtvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] " + "[-N NAME] [-S DELAY] [-s MODE] [-z ZOOM] FILES...\n"); } void print_version(void) @@ -45,7 +45,8 @@ void print_version(void) void parse_options(int argc, char **argv) { int n, opt; - char *end; + char *end, *s; + const char *scalemodes = "dfwh"; _options.from_stdin = false; _options.to_stdout = false; @@ -67,7 +68,7 @@ void parse_options(int argc, char **argv) _options.thumb_mode = false; _options.clean_cache = false; - while ((opt = getopt(argc, argv, "bcFfG:g:hin:N:oqrS:stvZz:")) != -1) { + while ((opt = getopt(argc, argv, "bcFfG:g:hin:N:oqrS:s:tvZz:")) != -1) { switch (opt) { case '?': print_usage(); @@ -130,7 +131,12 @@ void parse_options(int argc, char **argv) _options.slideshow = n; break; case 's': - _options.scalemode = SCALE_FIT; + s = strchr(scalemodes, optarg[0]); + if (s == NULL || *s == '\0' || strlen(optarg) != 1) { + fprintf(stderr, "sxiv: invalid argument for option -s: %s\n", optarg); + exit(EXIT_FAILURE); + } + _options.scalemode = s - scalemodes; break; case 't': _options.thumb_mode = true; -- cgit v1.2.3-70-g09d2