Home / src
Name Modified Size InfoDownloads / Week
Parent folder
diagcc.l 2015-11-07 632 Bytes
diagcc.y 2015-11-07 2.3 kB
lex.yy.c 2015-11-07 45.9 kB
makefile 2015-11-07 175 Bytes
sample.c 2015-11-07 311 Bytes
util.c 2015-11-07 802 Bytes
util.h 2015-11-07 165 Bytes
y.tab.c 2015-11-07 45.9 kB
y.tab.h 2015-11-07 2.4 kB
Totals: 9 Items   98.7 kB 0

Diagcc

Diagcc is a tool that colors gcc's diagnostic message.

Example

Make

$ make

Redirect gcc's stderr to stdout then pipe to ./diagcc (only stdout can be piped)

$ gcc 2>&1 sample.c | ./diagcc

You will get something like this

example

Quote from GCC 4.9 Release Series Changes, New Features, and Fixes

Support for colorizing diagnostics emitted by GCC has been added. The -fdiagnostics-color=auto will enable it when outputting to terminals, -fdiagnostics-color=always unconditionally. The GCC_COLORS environment variable can be used to customize the colors or disable coloring. If GCC_COLORS variable is present in the environment, the default is -fdiagnostics-color=auto, otherwise -fdiagnostics-color=never.

Diagcc uses the same color scheme as fdiagnostics-color.

Implementation

Diagcc is implemented with flex and bison.

The language of the diagnostic message can be defined using by following BNF:

text            : error_block               {;}
                | text error_block          {;}
                ;

error_block     : file_name error_type messages    {color($1, $2, $3);}
                ;

error_type      : error_t                   {;}  /* $$ defaults to $1 */
                | warning_t                 {;}
                | note_t                    {;}
                ;

messages        : message                   {$$ = strdup($1);}
                | messages message          {$$ = my_concate($1, $2);}
                ;

Install

sh install.sh

Then restart the shell, chdir to src/ and test

gcc sample.c

Extension

Similar techque can also be used to color g++/lex/yacc's diagnostic message.

New keywords maybe added in the lexer.

Source: README.md, updated 2015-11-07