diff options
Diffstat (limited to 'options.c')
-rw-r--r-- | options.c | 33 |
1 files changed, 13 insertions, 20 deletions
@@ -47,6 +47,9 @@ void parse_options(int argc, char **argv) char *end, *s; const char *scalemodes = "dfwh"; + progname = strrchr(argv[0], '/'); + progname = progname ? progname + 1 : argv[0]; + _options.from_stdin = false; _options.to_stdout = false; _options.recursive = false; @@ -86,10 +89,8 @@ void parse_options(int argc, char **argv) break; case 'G': n = strtol(optarg, &end, 0); - if (*end != '\0') { - fprintf(stderr, "sxiv: invalid argument for option -G: %s\n", optarg); - exit(EXIT_FAILURE); - } + if (*end != '\0') + error(EXIT_FAILURE, 0, "Invalid argument for option -G: %s", optarg); _options.gamma = n; break; case 'g': @@ -103,10 +104,8 @@ void parse_options(int argc, char **argv) break; case 'n': n = strtol(optarg, &end, 0); - if (*end != '\0' || n <= 0) { - fprintf(stderr, "sxiv: invalid argument for option -n: %s\n", optarg); - exit(EXIT_FAILURE); - } + if (*end != '\0' || n <= 0) + error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", optarg); _options.startnum = n - 1; break; case 'N': @@ -123,18 +122,14 @@ void parse_options(int argc, char **argv) break; case 'S': n = strtol(optarg, &end, 0); - if (*end != '\0' || n <= 0) { - fprintf(stderr, "sxiv: invalid argument for option -S: %s\n", optarg); - exit(EXIT_FAILURE); - } + if (*end != '\0' || n <= 0) + error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", optarg); _options.slideshow = n; break; case 's': 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); - } + if (s == NULL || *s == '\0' || strlen(optarg) != 1) + error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", optarg); _options.scalemode = s - scalemodes; break; case 't': @@ -149,10 +144,8 @@ void parse_options(int argc, char **argv) break; case 'z': n = strtol(optarg, &end, 0); - if (*end != '\0' || n <= 0) { - fprintf(stderr, "sxiv: invalid argument for option -z: %s\n", optarg); - exit(EXIT_FAILURE); - } + if (*end != '\0' || n <= 0) + error(EXIT_FAILURE, 0, "Invalid argument for option -z: %s", optarg); _options.scalemode = SCALE_ZOOM; _options.zoom = (float) n / 100.0; break; |