My boss ran lint on some code I had written. This version of lint is extremely picky (good) and resulted in 12,115 lines to check out (bad). Much of it was ignorable but it all had to be checked out. But the time and effort of just going to the indicated lines was looking at about 3 days minimum. 3 looong days.
There had to be a better way. So I looked around at the usual places and was surprised to find no help on how to get an arbitrary file into a DevStudio Output window. I'm sure there is a Microsoft article somewhere, but I couldn't find it. There were several articles on writing Add-Ins and Macros, including the requirements for formatting the filename and line number, but nothing more basic.
Example -- Lint output
OK, here is an example. Here are a few lines from that dreadful lint output:
memcpy(&tmpOID[1], &almOID[0], oidLength * sizeof(OIDC_T));
SCTE-Alarms.cpp 599 Info 737: Loss of sign in
promotion from int to unsigned
int
SCTE-Alarms.cpp 599 Warning 534: Ignoring return value of function
'memcpy(void *, const void *, unsigned int)' (compare with line 44,
file string.h)
string.h 44 Info 830: Location cited in prior message
-
int fullLen = tmpOID[0] + 1; // number of components in tmpOID[]
SCTE-Alarms.cpp 601 Info 713: Loss of precision (initialization) (unsigned
long to int)
Now before going further, note that the filename and line number sequences are not in a format that DevStudio will recognize. DevStudio wants a sequence like: filename(linenumber): stuff
So I used a little Perl script to munge the file: my @file = <>;
chomp @file;
my $line;
foreach $line (@file)
{
if($line =~ m/^(\S+)\s+(\d+)(.+)/)
{
print "$1($2):$3\n";
}
else
{
print $line, "\n";
}
}
Now the lines (which I saved in "munged.txt") look like: memcpy(&tmpOID[1], &almOID[0], oidLength * sizeof(OIDC_T));
SCTE-Alarms.cpp(599): Info 737: Loss of sign in
promotion from int to unsigned
int
SCTE-Alarms.cpp(599): Warning 534: Ignoring return value of function
'memcpy(void *, const void *, unsigned int)'
(compare with line 44, file
string.h)
string.h(44): Info 830: Location cited in prior message
_
int fullLen = tmpOID[0] + 1; // number of components in tmpOID[]
SCTE-Alarms.cpp(601): Info 713: Loss of precision
(initialization) (unsigned
long to int)
(Obviously, if I was going to be doing this a lot, I would have a dedicated command to do the lint and then the Perl.)
Now, to use the Dump file
tool in DevStudio:
OK, let's try another one. I used gcc on a file and got this error output: sys_conf.h:709: error: `ULONG' was not declared in this scope
sys_conf.h:709: error: syntax error before `)' token
The filename and linenumber are still not quite right, but this Perl script fixes that:
my @file = <>;
chomp @file;
my $line;
foreach $line (@file)
{
if($line =~ m/^([^:]+):(\d+):(.+)/)
{
print "$1($2):$3\n";
}
else
{
print $line, "\n";
}
}
yielding munged lines like: sys_conf.h(709): error: `ULONG' was not declared in this scope
sys_conf.h(709): error: syntax error before `)' token
Now run the Dump file
tool and get: