> Date: Thu, 20 Oct 2011 20:19:33 +0200 > From: Sebastian Pipping <sebast...@pipping.org> > > I have some new code ready for you to tear apart, err review :-)
Here's mine: + /* Determine target file (i.e. stdout or stderr) and color to pick */ + switch (type) + { + case OT_DIR_ENTER: target = stdout; color = color_dir_enter; break; + case OT_DIR_LEAVE: target = stdout; color = color_dir_leave; break; + case OT_MISC_MESSAGE: target = stdout; color = color_misc_message; break; + case OT_MISC_ERROR: target = stderr; color = color_misc_error; break; + case OT_MISC_FATAL: target = stderr; color = color_misc_fatal; break; + case OT_EXECUTION: target = stdout; color = color_execution; break; + default: target = stdout; color = ""; colorize = 0; break; + } This should probably be a data structure, indexed by the OT_* values. + /* Output color start */ + if (colorize) + /* TODO make "\33[K" part optional as done in grep */ + fprintf (target, "\33[%sm\33[K", color); + + /* Output prefix */ + if (flags & OF_PREPEND_PREFIX) + { + const char * catchy = (type == OT_MISC_FATAL) ? "*** " : ""; + if (flocp && flocp->filenm) + fprintf (target, "%s:%lu: %s", flocp->filenm, flocp->lineno, catchy); + else if (makelevel == 0) + fprintf (target, "%s: %s", program, catchy); + else + fprintf (target, "%s[%u]: %s", program, makelevel, catchy); + } + + /* Output actual message */ + /* TODO make more portabe, see misc.c */ + vfprintf (target, format, args); + + if (type == OT_MISC_FATAL) + fputs (_(". Stop."), target); + + /* Output finishing newline and color stop */ + if (colorize) + /* TODO make "\33[K" part optional as done in grep */ + fprintf (target, "%s\33[m\33[K", append_newline ? "\n" : ""); + else if (append_newline) + fputc ('\n', target); + + /* Flush */ + if (flags & OF_FLUSH) + fflush(target); This will only work with a Posix console or a terminal emulator window. To make it more portable, one more level of abstraction is in order. E.g., provide the following APIs: output_color_start (target, color); output_prefix (target, type, flocp, makelevel); output_message (target, type, format, args); output_color_stop (target, color); output_newline_and_flush (target, append_newline_p, flash_p); Then your current code could be the implementation of these APIs for Posix platforms. Thanks. _______________________________________________ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make