i\'m currently refactoring a C-project, throwing about 1000 warnings at me. is there a way to highlight and filter these warnings. (eg make all index warnings red, unused bl
You could pipe the output of your compile through grep:
make 2> error.txt; grep -e error error.txt
Gcc 4.9 seems to have added this feature via the -fdiagnostics-color flag: http://gcc.gnu.org/onlinedocs/gcc/Language-Independent-Options.html#index-fdiagnostics-color-246
I've been using pretty make, which formats and colorizes gcc output nicely. The indented format for command options is very clear. I did end up hacking it to swap the deprecated popen2 to subprocess.
This answer is more about the general approach to reworking old C code.
Large volumes of warnings usually are repetitions of the same small group of warnings because of some errors in header files that are included all over the place by other source code files.
If you're refactoring an old C project, quite often most warning come down to various things such as old K'n'R function dec's, previously allowed casts now being highlighted with a warning, using deprecated functions, etc.
Assuming you're using (g)make to build the project, I'd run the compile using the following command:
gmake 2>&1 | tee results
Then you can have a look at the results file and see what are the most popular warnings you're getting. Start with eliminating all existing warnings before getting on to any refactoring of the code base.
Running the make from within vim gives you lots of possibilities to couple the error and warning messages with the source files.
The warn_summary script is pretty nice
You can get a count of all your warnings, the type and also just print out the warnings without all the other output from gcc.
gcc <...> | tee buildoutput
warn_summary -s 0 -wpass buildoutput
warn_summary -s 0 buildoutput
This is really basic, but I've been using grep...
make 2>&1 | grep --color -iP "\^|warning:|error:|"
just to quickly draw the eye to the error line and offending section pointed to by ^
.
I've found other methods over-use colour and you end up with the same problem. I guess you could also inject colour escape sequences with sed
.