From 03bfe1015e7e67104c2872bdcf085b1315b24a4c Mon Sep 17 00:00:00 2001 From: Bert Date: Sun, 30 Jan 2011 16:39:16 +0100 Subject: [PATCH] Explicitly enable printing of warnings --- README.md | 1 + image.c | 1 - main.c | 1 - options.c | 9 +++++++-- options.h | 2 ++ sxiv.1 | 5 ++++- sxiv.h | 31 +++++++++++++++++-------------- window.c | 1 - 8 files changed, 31 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 96eadf7..8942414 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ sxiv supports the following command-line options: -p pixelize, i.e. turn off image anti-aliasing -s scale all images to fit into window -v print version information and exit + -W enable printing of warnings -w WIDTHxHEIGHT set window width to WIDTH and height to HEIGHT (if HEIGHT is omitted, height is also set to WIDTH) diff --git a/image.c b/image.c index 4673c63..8a99737 100644 --- a/image.c +++ b/image.c @@ -23,7 +23,6 @@ #include "sxiv.h" #include "image.h" -#include "options.h" int zl_cnt; float zoom_min; diff --git a/main.c b/main.c index df4ef9e..ef32324 100644 --- a/main.c +++ b/main.c @@ -26,7 +26,6 @@ #include "sxiv.h" #include "image.h" -#include "options.h" #include "window.h" void on_keypress(XEvent*); diff --git a/options.c b/options.c index b0f3186..1bcfbe1 100644 --- a/options.c +++ b/options.c @@ -29,7 +29,7 @@ options_t _options; const options_t *options = (const options_t*) &_options; void print_usage() { - printf("usage: sxiv [-dfhpsvZ] [-w WIDTH[xHEIGHT]] [-z ZOOM] FILES...\n"); + printf("usage: sxiv [-dfhpsvWZ] [-w WIDTH[xHEIGHT]] [-z ZOOM] FILES...\n"); } void print_version() { @@ -50,7 +50,9 @@ void parse_options(int argc, char **argv) { _options.winh = h = 0; _options.fullscreen = 0; - while ((opt = getopt(argc, argv, "dfhpsvw:Zz:")) != -1) { + _options.warn = 0; + + while ((opt = getopt(argc, argv, "dfhpsvWw:Zz:")) != -1) { switch (opt) { case '?': print_usage(); @@ -73,6 +75,9 @@ void parse_options(int argc, char **argv) { case 'v': print_version(); exit(0); + case 'W': + _options.warn = 1; + break; case 'w': if (!sscanf(optarg, "%hux%hu", &w, &h)) { fprintf(stderr, "sxiv: invalid argument for option -w: %s\n", diff --git a/options.h b/options.h index 707dd90..072c700 100644 --- a/options.h +++ b/options.h @@ -32,6 +32,8 @@ typedef struct options_s { int winw; int winh; unsigned char fullscreen; + + unsigned char warn; } options_t; extern const options_t *options; diff --git a/sxiv.1 b/sxiv.1 index a17e3e0..b0bf1a6 100644 --- a/sxiv.1 +++ b/sxiv.1 @@ -3,7 +3,7 @@ sxiv \- Simple (or small or suckless) X Image Viewer .SH SYNOPSIS .B sxiv -.RB [ \-dfhpsvZ ] +.RB [ \-dfhpsvWZ ] .RB [ \-w .IB WIDTH x HEIGHT ] @@ -36,6 +36,9 @@ Scale all images to fit into window. .B \-v Print version information to standard output and exit. .TP +.B \-W +Enable printing of warnings to standard error stream. +.TP .BI "\-w " WIDTH x HEIGHT Set window width to .I WIDTH diff --git a/sxiv.h b/sxiv.h index 837ae73..15db96e 100644 --- a/sxiv.h +++ b/sxiv.h @@ -20,26 +20,29 @@ #define SXIV_H #include "config.h" +#include "options.h" #define ABS(a) ((a) < 0 ? (-(a)) : (a)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b)) -#define WARN(...) \ - do { \ - fprintf(stderr, "sxiv: %s:%d: warning: ", __FILE__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, "\n"); \ - } while (0) +#define WARN(...) \ + do { \ + if (options->warn) { \ + fprintf(stderr, "sxiv: %s:%d: warning: ", __FILE__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ + } \ + } while (0) -#define DIE(...) \ - do { \ - fprintf(stderr, "sxiv: %s:%d: error: ", __FILE__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, "\n"); \ - cleanup(); \ - exit(1); \ - } while (0) +#define DIE(...) \ + do { \ + fprintf(stderr, "sxiv: %s:%d: error: ", __FILE__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ + cleanup(); \ + exit(1); \ + } while (0) void cleanup(); diff --git a/window.c b/window.c index d5f5f4f..82d8396 100644 --- a/window.c +++ b/window.c @@ -24,7 +24,6 @@ #include #include "sxiv.h" -#include "options.h" #include "window.h" static Cursor arrow;