Krolyxon
Commit 03bfe10

Branches

Refs →

nsxiv03bfe10

Explicitly enable printing of warnings

Author
Bert
Date
2011-01-30 16:39 +0100
Parent
e2d9463
Commit
03bfe1015e7e67104c2872bdcf085b1315b24a4c

+31 −20

8 files changed

  1. M README.md +1 −0
  2. M image.c +0 −1
  3. M main.c +0 −1
  4. M options.c +7 −2
  5. M options.h +2 −0
  6. M sxiv.1 +4 −1
  7. M sxiv.h +17 −14
  8. M window.c +0 −1
M README.md View
@@ -35,6 +35,7 @@ sxiv supports the following command-line options:
3535 -p pixelize, i.e. turn off image anti-aliasing
3636 -s scale all images to fit into window
3737 -v print version information and exit
38+ -W enable printing of warnings
3839 -w WIDTHxHEIGHT
3940 set window width to WIDTH and height to HEIGHT
4041 (if HEIGHT is omitted, height is also set to WIDTH)
M image.c View
@@ -23,7 +23,6 @@
2323
2424 #include "sxiv.h"
2525 #include "image.h"
26−#include "options.h"
2726
2827 int zl_cnt;
2928 float zoom_min;
M main.c View
@@ -26,7 +26,6 @@
2626
2727 #include "sxiv.h"
2828 #include "image.h"
29−#include "options.h"
3029 #include "window.h"
3130
3231 void on_keypress(XEvent*);
M options.c View
@@ -29,7 +29,7 @@ options_t _options;
2929 const options_t *options = (const options_t*) &_options;
3030
3131 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");
3333 }
3434
3535 void print_version() {
@@ -50,7 +50,9 @@ void parse_options(int argc, char **argv) {
5050 _options.winh = h = 0;
5151 _options.fullscreen = 0;
5252
53− while ((opt = getopt(argc, argv, "dfhpsvw:Zz:")) != -1) {
53+ _options.warn = 0;
54+
55+ while ((opt = getopt(argc, argv, "dfhpsvWw:Zz:")) != -1) {
5456 switch (opt) {
5557 case '?':
5658 print_usage();
@@ -73,6 +75,9 @@ void parse_options(int argc, char **argv) {
7375 case 'v':
7476 print_version();
7577 exit(0);
78+ case 'W':
79+ _options.warn = 1;
80+ break;
7681 case 'w':
7782 if (!sscanf(optarg, "%hux%hu", &w, &h)) {
7883 fprintf(stderr, "sxiv: invalid argument for option -w: %s\n",
M options.h View
@@ -32,6 +32,8 @@ typedef struct options_s {
3232 int winw;
3333 int winh;
3434 unsigned char fullscreen;
35+
36+ unsigned char warn;
3537 } options_t;
3638
3739 extern const options_t *options;
M sxiv.1 View
@@ -3,7 +3,7 @@
33 sxiv \- Simple (or small or suckless) X Image Viewer
44 .SH SYNOPSIS
55 .B sxiv
6−.RB [ \-dfhpsvZ ]
6+.RB [ \-dfhpsvWZ ]
77 .RB [ \-w
88 .IB WIDTH x HEIGHT
99 ]
@@ -36,6 +36,9 @@ Scale all images to fit into window.
3636 .B \-v
3737 Print version information to standard output and exit.
3838 .TP
39+.B \-W
40+Enable printing of warnings to standard error stream.
41+.TP
3942 .BI "\-w " WIDTH x HEIGHT
4043 Set window width to
4144 .I WIDTH
M sxiv.h View
@@ -20,26 +20,29 @@
2020 #define SXIV_H
2121
2222 #include "config.h"
23+#include "options.h"
2324
2425 #define ABS(a) ((a) < 0 ? (-(a)) : (a))
2526 #define MIN(a,b) ((a) < (b) ? (a) : (b))
2627 #define MAX(a,b) ((a) > (b) ? (a) : (b))
2728
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)
3437
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)
4346
4447 void cleanup();
4548
M window.c View
@@ -24,7 +24,6 @@
2424 #include <X11/cursorfont.h>
2525
2626 #include "sxiv.h"
27−#include "options.h"
2827 #include "window.h"
2928
3029 static Cursor arrow;