From 7c03e4c57a07c0772eb87c16ad46927e7230d9de Mon Sep 17 00:00:00 2001 From: Holger Freyther Date: Sat, 27 Dec 2008 12:46:48 +0000 Subject: Assign colors to the different categories Let there be colors. I have no idea if this will be appreciated. It can be disabled by an option. --- src/debug.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/debug.c') diff --git a/src/debug.c b/src/debug.c index 2b91814ad..8a558c202 100644 --- a/src/debug.c +++ b/src/debug.c @@ -43,14 +43,16 @@ struct debug_info { #define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0])) static const struct debug_info debug_info[] = { - DEBUG_CATEGORY(DRLL, "DRLL", "", "") - DEBUG_CATEGORY(DCC, "DCC", "", "") - DEBUG_CATEGORY(DNM, "DMM", "", "") - DEBUG_CATEGORY(DRR, "DRR", "", "") - DEBUG_CATEGORY(DRSL, "DRSSL","", "") - DEBUG_CATEGORY(DNM, "DNM", "", "") + DEBUG_CATEGORY(DRLL, "DRLL", "\033[1;31m", "") + DEBUG_CATEGORY(DCC, "DCC", "\033[1;32m", "") + DEBUG_CATEGORY(DNM, "DMM", "\033[1;33m", "") + DEBUG_CATEGORY(DRR, "DRR", "\033[1;34m", "") + DEBUG_CATEGORY(DRSL, "DRSSL","\033[1;35m", "") + DEBUG_CATEGORY(DNM, "DNM", "\033[1;36m", "") }; +static int use_color = 1; + /* * Parse the category mask. * category1:category2:category3 @@ -75,6 +77,18 @@ void parse_category_mask(const char *_mask) debug_mask = new_mask; } +const char* color(int subsys) +{ + int i = 0; + + for (i = 0; use_color && i < ARRAY_SIZE(debug_info); ++i) { + if (debug_info[i].number == subsys) + return debug_info[i].color; + } + + return ""; +} + void debugp(unsigned int subsys, char *file, int line, const char *format, ...) { char *timestr; @@ -90,8 +104,9 @@ void debugp(unsigned int subsys, char *file, int line, const char *format, ...) tm = time(NULL); timestr = ctime(&tm); timestr[strlen(timestr)-1] = '\0'; - fprintf(outfd, "%s <%4.4x> %s:%d ", timestr, subsys, file, line); + fprintf(outfd, "%s%s <%4.4x> %s:%d ", color(subsys), timestr, subsys, file, line); vfprintf(outfd, format, ap); + fprintf(outfd, "\033[0;m"); va_end(ap); -- cgit v1.2.3