summaryrefslogtreecommitdiffstats
path: root/options.c
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2015-10-28 23:03:37 +0100
committerBert Münnich <ber.t@posteo.de>2015-10-28 23:03:37 +0100
commitd3a70a285d03224fde9e6ef36eba9de21b773f39 (patch)
tree8b44b129eae5d9c067e2590c7293d06f3fba2753 /options.c
parent851e4288c102cc4177d54d87aded43d003e85885 (diff)
downloadnsxiv-d3a70a285d03224fde9e6ef36eba9de21b773f39.tar.zst
Revised error handling
- Functions warn() and die() replaced by GNU-like error(3) function - Register cleanup() with atexit(3) - Functions called by cleanup() are marked with CLEANUP and are not allowed to call exit(3)
Diffstat (limited to 'options.c')
-rw-r--r--options.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/options.c b/options.c
index 882ac49..f7aac23 100644
--- a/options.c
+++ b/options.c
@@ -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;