Browse Source

Add q() macro that checks quiet flag.

Georgi Chorbadzhiyski 9 years ago
parent
commit
e16243a5d8
2 changed files with 12 additions and 8 deletions
  1. 6
    8
      cmd.c
  2. 6
    0
      data.h

+ 6
- 8
cmd.c View File

@@ -68,14 +68,12 @@ bool parse_command(struct videohub_data *data, char *cmd) {
68 68
 	}
69 69
 
70 70
 	if (!v) {
71
-		if (!quiet) {
72
-			fprintf(stderr, "WARNING: Videohub sent unknown command!\n");
73
-			fprintf(stderr, "         Please report this command to author's email: georgi@unixsol.org\n");
74
-			fprintf(stderr, "         You may use -q or --quiet to suppress the message.\n");
75
-			fprintf(stderr, "---------8<-----------8<----------- cut here ---------8<------------8<---------\n");
76
-			fprintf(stderr, "%s\n", cmd);
77
-			fprintf(stderr, "---------8<-----------8<----------- cut here ---------8<------------8<---------\n");
78
-		}
71
+		q("WARNING: Videohub sent unknown command!\n");
72
+		q("         Please report this command to author's email: georgi@unixsol.org\n");
73
+		q("         You may use -q or --quiet to suppress the message.\n");
74
+		q("---------8<-----------8<----------- cut here ---------8<------------8<---------\n");
75
+		q("%s\n", cmd);
76
+		q("---------8<-----------8<----------- cut here ---------8<------------8<---------\n");
79 77
 		return false;
80 78
 	}
81 79
 

+ 6
- 0
data.h View File

@@ -68,6 +68,12 @@ extern int quiet;
68 68
 			printf("debug: " fmt, ## arguments); \
69 69
 	} while(0)
70 70
 
71
+#define q(fmt, arguments...) \
72
+	do { \
73
+		if (!quiet) \
74
+			fprintf(stderr, fmt, ## arguments); \
75
+	} while(0)
76
+
71 77
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
72 78
 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
73 79
 #define UNUSED(x) UNUSED_ ## x __attribute__((unused))

Loading…
Cancel
Save