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]
Message-Id: <1462794109-14652-4-git-send-email-treeze.taeung@gmail.com>
Date:	Mon,  9 May 2016 20:41:48 +0900
From:	Taeung Song <treeze.taeung@...il.com>
To:	Arnaldo Carvalho de Melo <acme@...nel.org>
Cc:	linux-kernel@...r.kernel.org, Jiri Olsa <jolsa@...nel.org>,
	Namhyung Kim <namhyung@...nel.org>,
	Ingo Molnar <mingo@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
	Taeung Song <treeze.taeung@...il.com>
Subject: [PATCH 3/4] perf config: Initialize ui_browser__colorsets with default config items

Set default config values for 'colors' section with 'colors_config_items[]'
instead of actual const char * type values.
(e.g. using colors_config_item[CONFIG_COLORS_TOP].value
instead of "red, default" string value for 'colors.top')

Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Jiri Olsa <jolsa@...nel.org>
Signed-off-by: Taeung Song <treeze.taeung@...il.com>
---
 tools/perf/ui/browser.c   | 46 ++++++++++++++++++++++++++++++++--------------
 tools/perf/ui/browser.h   |  1 +
 tools/perf/ui/tui/setup.c |  1 +
 tools/perf/util/cache.h   |  1 +
 tools/perf/util/config.h  | 12 ++++++++++++
 5 files changed, 47 insertions(+), 14 deletions(-)

diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index a477867..385d0de 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -509,44 +509,30 @@ static struct ui_browser_colorset {
 	{
 		.colorset = HE_COLORSET_TOP,
 		.name	  = "top",
-		.fg	  = "red",
-		.bg	  = "default",
 	},
 	{
 		.colorset = HE_COLORSET_MEDIUM,
 		.name	  = "medium",
-		.fg	  = "green",
-		.bg	  = "default",
 	},
 	{
 		.colorset = HE_COLORSET_NORMAL,
 		.name	  = "normal",
-		.fg	  = "default",
-		.bg	  = "default",
 	},
 	{
 		.colorset = HE_COLORSET_SELECTED,
 		.name	  = "selected",
-		.fg	  = "black",
-		.bg	  = "yellow",
 	},
 	{
 		.colorset = HE_COLORSET_JUMP_ARROWS,
 		.name	  = "jump_arrows",
-		.fg	  = "blue",
-		.bg	  = "default",
 	},
 	{
 		.colorset = HE_COLORSET_ADDR,
 		.name	  = "addr",
-		.fg	  = "magenta",
-		.bg	  = "default",
 	},
 	{
 		.colorset = HE_COLORSET_ROOT,
 		.name	  = "root",
-		.fg	  = "white",
-		.bg	  = "blue",
 	},
 	{
 		.name = NULL,
@@ -591,6 +577,7 @@ static int ui_browser__color_config(const char *var, const char *value,
 		if (strcmp(ui_browser__colorsets[i].name, name) != 0)
 			continue;
 
+		zfree((char **)&ui_browser__colorsets[i].fg);
 		ret = ui_browser__config_gcolors(&ui_browser__colorsets[i], value);
 		break;
 	}
@@ -745,10 +732,41 @@ void __ui_browser__line_arrow(struct ui_browser *browser, unsigned int column,
 		__ui_browser__line_arrow_down(browser, column, start, end);
 }
 
+static void ui_browser__free_color_configs(void)
+{
+	int i;
+
+	for (i = 0; ui_browser__colorsets[i].name != NULL; ++i)
+		zfree((char **)&ui_browser__colorsets[i].fg);
+}
+
+void ui_browser__free(void)
+{
+	ui_browser__free_color_configs();
+}
+
+static void ui_browser__init_colorsets(void)
+{
+	int i, j;
+
+	for (i = 0; ui_browser__colorsets[i].name != NULL; ++i) {
+		const char *name = ui_browser__colorsets[i].name;
+
+		for (j = 0; colors_config_items[j].name != NULL; j++) {
+			if (!strcmp(name, colors_config_items[j].name)) {
+				ui_browser__config_gcolors(&ui_browser__colorsets[i],
+							   colors_config_items[j].value.s);
+				break;
+			}
+		}
+	}
+}
+
 void ui_browser__init(void)
 {
 	int i = 0;
 
+	ui_browser__init_colorsets();
 	perf_config(ui_browser__color_config, NULL);
 
 	while (ui_browser__colorsets[i].name) {
diff --git a/tools/perf/ui/browser.h b/tools/perf/ui/browser.h
index be3b70e..7a83a1a 100644
--- a/tools/perf/ui/browser.h
+++ b/tools/perf/ui/browser.h
@@ -74,5 +74,6 @@ void ui_browser__list_head_seek(struct ui_browser *browser, off_t offset, int wh
 unsigned int ui_browser__list_head_refresh(struct ui_browser *browser);
 
 void ui_browser__init(void);
+void ui_browser__free(void);
 void annotate_browser__init(void);
 #endif /* _PERF_UI_BROWSER_H_ */
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index 7dfeba0..7999a57 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -171,4 +171,5 @@ void ui__exit(bool wait_for_ok)
 	SLang_reset_tty();
 
 	perf_error__unregister(&perf_tui_eops);
+	ui_browser__free();
 }
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 1f5a93c..8eab653 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -7,6 +7,7 @@
 #include <subcmd/pager.h>
 #include "../perf.h"
 #include "../ui/ui.h"
+#include "config.h"
 
 #include <linux/string.h>
 
diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h
index 84414af..e0c8392 100644
--- a/tools/perf/util/config.h
+++ b/tools/perf/util/config.h
@@ -44,6 +44,16 @@ struct perf_config_set {
 	struct list_head sections;
 };
 
+enum colors_config_items_idx {
+	CONFIG_COLORS_TOP,
+	CONFIG_COLORS_MEDIUM,
+	CONFIG_COLORS_NORMAL,
+	CONFIG_COLORS_SELECTED,
+	CONFIG_COLORS_JUMP_ARROWS,
+	CONFIG_COLORS_ADDR,
+	CONFIG_COLORS_ROOT,
+};
+
 #define CONF_VAR(_name, _field, _val, _type)			\
 	{ .name = _name, .value._field = _val, .type = _type }
 
@@ -64,6 +74,8 @@ struct perf_config_set {
 #define CONF_END()					\
 	{ .name = NULL }
 
+extern const struct default_config_item colors_config_items[];
+
 struct perf_config_set *perf_config_set__new(void);
 void perf_config_set__delete(struct perf_config_set *set);
 
-- 
2.5.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ