On 10 Oct 2017 2:34 am, "Liu Hao" <lh_mo...@126.com> wrote:
Since on *nix it is not when `colorize_start()` is called that the terminal color is changed (it is when those ANSI escape codes are delivered to the other peer which will translate them), and the string passed to `fputs()` is free to deliver multiple escape codes, it is not an option unless we output integral diagnostic messages using multiple fputs()` calls. For example, ``` test.c:3:9: warning: 'a' is used uninitialized in this function [-Wuninitialized] ``` The words 'warning' and '-Wuninitialized' should be magenta, so there are four ANSI escape codes (two to set the color and another two to restore the color), and this line of text must be output using five individual calls to the `fputs()` function (one for each segment with the consistent color), which is not the case (this whole line of text is delivered using a single call), so all five segments have to be all in magenta or no color at all. This is not a solution. Ops! You're obviously right. What was I thinking? I still believe that pretty-printer.c is not the right place for all this color-handling code (diagnostic-color.c or libiberty/ may be better places). Also, your code handles a lot more ANSI codes than those needed for color output. The code in grep seems much simpler. Could your fputs replacement split the string as you suggest above, then if the chunk is an ANSI code, use grep's conversion function to transform the codes, otherwise use fputs to print text. Cheers, Manuel.