nsxiv03bfe10
Explicitly enable printing of warnings
+31 −20
8 files changed
- M README.md +1 −0
- M image.c +0 −1
- M main.c +0 −1
- M options.c +7 −2
- M options.h +2 −0
- M sxiv.1 +4 −1
- M sxiv.h +17 −14
- M window.c +0 −1
| @@ -35,6 +35,7 @@ sxiv supports the following command-line options: | |||
| 35 | 35 | -p pixelize, i.e. turn off image anti-aliasing | |
| 36 | 36 | -s scale all images to fit into window | |
| 37 | 37 | -v print version information and exit | |
| 38 | + | -W enable printing of warnings | |
| 38 | 39 | -w WIDTHxHEIGHT | |
| 39 | 40 | set window width to WIDTH and height to HEIGHT | |
| 40 | 41 | (if HEIGHT is omitted, height is also set to WIDTH) | |
| @@ -23,7 +23,6 @@ | |||
| 23 | 23 | ||
| 24 | 24 | #include "sxiv.h" | |
| 25 | 25 | #include "image.h" | |
| 26 | − | #include "options.h" | |
| 27 | 26 | ||
| 28 | 27 | int zl_cnt; | |
| 29 | 28 | float zoom_min; | |
| @@ -26,7 +26,6 @@ | |||
| 26 | 26 | ||
| 27 | 27 | #include "sxiv.h" | |
| 28 | 28 | #include "image.h" | |
| 29 | − | #include "options.h" | |
| 30 | 29 | #include "window.h" | |
| 31 | 30 | ||
| 32 | 31 | void on_keypress(XEvent*); | |
| @@ -29,7 +29,7 @@ options_t _options; | |||
| 29 | 29 | const options_t *options = (const options_t*) &_options; | |
| 30 | 30 | ||
| 31 | 31 | void print_usage() { | |
| 32 | − | printf("usage: sxiv [-dfhpsvZ] [-w WIDTH[xHEIGHT]] [-z ZOOM] FILES...\n"); | |
| 32 | + | printf("usage: sxiv [-dfhpsvWZ] [-w WIDTH[xHEIGHT]] [-z ZOOM] FILES...\n"); | |
| 33 | 33 | } | |
| 34 | 34 | ||
| 35 | 35 | void print_version() { | |
| @@ -50,7 +50,9 @@ void parse_options(int argc, char **argv) { | |||
| 50 | 50 | _options.winh = h = 0; | |
| 51 | 51 | _options.fullscreen = 0; | |
| 52 | 52 | ||
| 53 | − | while ((opt = getopt(argc, argv, "dfhpsvw:Zz:")) != -1) { | |
| 53 | + | _options.warn = 0; | |
| 54 | + | ||
| 55 | + | while ((opt = getopt(argc, argv, "dfhpsvWw:Zz:")) != -1) { | |
| 54 | 56 | switch (opt) { | |
| 55 | 57 | case '?': | |
| 56 | 58 | print_usage(); | |
| @@ -73,6 +75,9 @@ void parse_options(int argc, char **argv) { | |||
| 73 | 75 | case 'v': | |
| 74 | 76 | print_version(); | |
| 75 | 77 | exit(0); | |
| 78 | + | case 'W': | |
| 79 | + | _options.warn = 1; | |
| 80 | + | break; | |
| 76 | 81 | case 'w': | |
| 77 | 82 | if (!sscanf(optarg, "%hux%hu", &w, &h)) { | |
| 78 | 83 | fprintf(stderr, "sxiv: invalid argument for option -w: %s\n", | |
| @@ -32,6 +32,8 @@ typedef struct options_s { | |||
| 32 | 32 | int winw; | |
| 33 | 33 | int winh; | |
| 34 | 34 | unsigned char fullscreen; | |
| 35 | + | ||
| 36 | + | unsigned char warn; | |
| 35 | 37 | } options_t; | |
| 36 | 38 | ||
| 37 | 39 | extern const options_t *options; | |
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | sxiv \- Simple (or small or suckless) X Image Viewer | |
| 4 | 4 | .SH SYNOPSIS | |
| 5 | 5 | .B sxiv | |
| 6 | − | .RB [ \-dfhpsvZ ] | |
| 6 | + | .RB [ \-dfhpsvWZ ] | |
| 7 | 7 | .RB [ \-w | |
| 8 | 8 | .IB WIDTH x HEIGHT | |
| 9 | 9 | ] | |
| @@ -36,6 +36,9 @@ Scale all images to fit into window. | |||
| 36 | 36 | .B \-v | |
| 37 | 37 | Print version information to standard output and exit. | |
| 38 | 38 | .TP | |
| 39 | + | .B \-W | |
| 40 | + | Enable printing of warnings to standard error stream. | |
| 41 | + | .TP | |
| 39 | 42 | .BI "\-w " WIDTH x HEIGHT | |
| 40 | 43 | Set window width to | |
| 41 | 44 | .I WIDTH | |
| @@ -20,26 +20,29 @@ | |||
| 20 | 20 | #define SXIV_H | |
| 21 | 21 | ||
| 22 | 22 | #include "config.h" | |
| 23 | + | #include "options.h" | |
| 23 | 24 | ||
| 24 | 25 | #define ABS(a) ((a) < 0 ? (-(a)) : (a)) | |
| 25 | 26 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) | |
| 26 | 27 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) | |
| 27 | 28 | ||
| 28 | − | #define WARN(...) \ | |
| 29 | − | do { \ | |
| 30 | − | fprintf(stderr, "sxiv: %s:%d: warning: ", __FILE__, __LINE__); \ | |
| 31 | − | fprintf(stderr, __VA_ARGS__); \ | |
| 32 | − | fprintf(stderr, "\n"); \ | |
| 33 | − | } while (0) | |
| 29 | + | #define WARN(...) \ | |
| 30 | + | do { \ | |
| 31 | + | if (options->warn) { \ | |
| 32 | + | fprintf(stderr, "sxiv: %s:%d: warning: ", __FILE__, __LINE__); \ | |
| 33 | + | fprintf(stderr, __VA_ARGS__); \ | |
| 34 | + | fprintf(stderr, "\n"); \ | |
| 35 | + | } \ | |
| 36 | + | } while (0) | |
| 34 | 37 | ||
| 35 | − | #define DIE(...) \ | |
| 36 | − | do { \ | |
| 37 | − | fprintf(stderr, "sxiv: %s:%d: error: ", __FILE__, __LINE__); \ | |
| 38 | − | fprintf(stderr, __VA_ARGS__); \ | |
| 39 | − | fprintf(stderr, "\n"); \ | |
| 40 | − | cleanup(); \ | |
| 41 | − | exit(1); \ | |
| 42 | − | } while (0) | |
| 38 | + | #define DIE(...) \ | |
| 39 | + | do { \ | |
| 40 | + | fprintf(stderr, "sxiv: %s:%d: error: ", __FILE__, __LINE__); \ | |
| 41 | + | fprintf(stderr, __VA_ARGS__); \ | |
| 42 | + | fprintf(stderr, "\n"); \ | |
| 43 | + | cleanup(); \ | |
| 44 | + | exit(1); \ | |
| 45 | + | } while (0) | |
| 43 | 46 | ||
| 44 | 47 | void cleanup(); | |
| 45 | 48 | ||
| @@ -24,7 +24,6 @@ | |||
| 24 | 24 | #include <X11/cursorfont.h> | |
| 25 | 25 | ||
| 26 | 26 | #include "sxiv.h" | |
| 27 | − | #include "options.h" | |
| 28 | 27 | #include "window.h" | |
| 29 | 28 | ||
| 30 | 29 | static Cursor arrow; | |