[Patches] WarnLevel bold off unless output is to tty
Steve White
steve.white at aei.mpg.de
Sun Apr 16 12:19:05 CDT 2006
Hi,
I got tired of seeing all the terminal control characters in Cactus
output that was piped to files.
Patch attached.
Tested by watching Cactus output on a terminal, then piping ouput from the
same program to a file. E.g. in bash
make config-testsuite 2>&1 |tee > ts
--
Steve White : Programmer
Max-Planck-Institut für Gravitationsphysik Albert-Einstein-Institut
Am Mühlenberg 1, D-14476 Golm, Germany +49-331-567-7625
-------------- next part --------------
Index: WarnLevel.c
===================================================================
RCS file: /cactusdevcvs/Cactus/src/main/WarnLevel.c,v
retrieving revision 1.76
diff -u -r1.76 WarnLevel.c
--- WarnLevel.c 13 Dec 2005 16:31:40 -0000 1.76
+++ WarnLevel.c 16 Apr 2006 17:14:22 -0000
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#include <unistd.h>
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
@@ -46,6 +47,7 @@
********************************************************************/
/* Escape sequences to highlight warning messages.
*/
+
#ifndef WIN32
#define BOLD_ON "\033[1m"
#define BOLD_OFF "\033[0m"
@@ -54,6 +56,23 @@
#define BOLD_OFF ""
#endif
+static const char * bold_on (int desc)
+{
+ if (isatty (desc))
+ return BOLD_ON;
+ else
+ return "";
+}
+
+
+static const char * bold_off (int desc)
+{
+ if (isatty (desc))
+ return BOLD_OFF;
+ else
+ return "";
+}
+
/* maximum buffer length to hold the hostname */
#define MAXNAMELEN 255
@@ -534,7 +553,7 @@
if (highlight_warning_messages)
{
- fprintf (stderr, BOLD_ON);
+ fprintf (stderr, bold_on (STDERR_FILENO));
}
if (level <= error_level || cctk_full_warnings)
@@ -552,7 +571,7 @@
if (highlight_warning_messages)
{
- fprintf (stderr, BOLD_OFF);
+ fprintf (stderr, bold_off (STDERR_FILENO));
}
fprintf (stderr, " ");
@@ -567,7 +586,7 @@
if (highlight_warning_messages)
{
- fprintf (stdout, BOLD_ON);
+ fprintf (stdout, bold_on (STDOUT_FILENO));
}
if (level <= error_level || cctk_full_warnings)
@@ -585,7 +604,7 @@
if (highlight_warning_messages)
{
- fprintf (stdout, BOLD_OFF);
+ fprintf (stdout,bold_off (STDOUT_FILENO));
}
fprintf (stdout, " ");
@@ -670,7 +689,7 @@
highlight_warning_messages =
! highlight_warning_messages_ptr || *highlight_warning_messages_ptr;
- if (highlight_warning_messages)
+ if (highlight_warning_messages && isatty (STDERR_FILENO))
{
fprintf (stderr, BOLD_ON "PARAM %s (%s):" BOLD_OFF " %s\n",
cctk_strong_param_check ? "ERROR" : "WARNING", thorn, message);
@@ -747,7 +766,7 @@
highlight_warning_messages =
! highlight_warning_messages_ptr || *highlight_warning_messages_ptr;
- if (highlight_warning_messages)
+ if (highlight_warning_messages && isatty (STDERR_FILENO))
{
fprintf (stderr, BOLD_ON "PARAM %s (%s)" BOLD_OFF ": ",
cctk_strong_param_check ? "ERROR" : "WARNING", thorn);
More information about the Patches
mailing list