lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 17 Aug 2017 10:35:48 -0700
From:   Julien Fortin <julien@...ulusnetworks.com>
To:     netdev@...r.kernel.org
Cc:     roopa@...ulusnetworks.com, nikolay@...ulusnetworks.com,
        dsa@...ulusnetworks.com, Julien Fortin <julien@...ulusnetworks.com>
Subject: [PATCH iproute2 json v2 01/27] color: add new COLOR_NONE and disable_color function

From: Julien Fortin <julien@...ulusnetworks.com>

Signed-off-by: Julien Fortin <julien@...ulusnetworks.com>
---
 include/color.h |  2 ++
 lib/color.c     | 12 ++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/color.h b/include/color.h
index ba0b237e..1cd6f7d2 100644
--- a/include/color.h
+++ b/include/color.h
@@ -2,6 +2,7 @@
 #define __COLOR_H__ 1
 
 enum color_attr {
+	COLOR_NONE,
 	COLOR_IFNAME,
 	COLOR_MAC,
 	COLOR_INET,
@@ -12,6 +13,7 @@ enum color_attr {
 };
 
 void enable_color(void);
+void check_if_color_enabled(void);
 void set_color_palette(void);
 int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...);
 enum color_attr ifa_family_color(__u8 ifa_family);
diff --git a/lib/color.c b/lib/color.c
index 4e947500..79d5e289 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -89,6 +89,14 @@ void set_color_palette(void)
 		is_dark_bg = 1;
 }
 
+void check_if_color_enabled(void)
+{
+	if (color_is_enabled) {
+		fprintf(stderr, "Option \"-json\" conflicts with \"-color\".\n");
+		exit(1);
+	}
+}
+
 int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
 {
 	int ret = 0;
@@ -96,13 +104,13 @@ int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
 
 	va_start(args, fmt);
 
-	if (!color_is_enabled) {
+	if (!color_is_enabled || attr == COLOR_NONE) {
 		ret = vfprintf(fp, fmt, args);
 		goto end;
 	}
 
 	ret += fprintf(fp, "%s",
-		       color_codes[attr_colors[is_dark_bg ? attr + 7 : attr]]);
+		       color_codes[attr_colors[is_dark_bg ? attr + 8 : attr]]);
 	ret += vfprintf(fp, fmt, args);
 	ret += fprintf(fp, "%s", color_codes[C_CLEAR]);
 
-- 
2.14.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ