Confessions of a Wall Street Programmer

practical ideas (and perhaps some uncommon knowledge) on software architecture, design, construction and testing

pvs2csv.pl

This script takes the output PVS-Studio (pvs-studio-analyzer analyze) and formats it in csv format.

Usage

pvs2csv.pl [-r relative_path] [file]

Parameters

Parameter Description
-r relative_path If specified, relative_path is stripped from the output. This makes it easier to compare results between different directories.
file Specifies the input file. If omitted, input is read from stdin.

Notes

Some people have experienced problems with the output from PVS-Studio, not realizing that the output is not intended to be used directly, but that it should first be post-processed using the included plog-converter utility. Note that the pvs2csv.pl script does not require the use of plog-converter, but processes the direct output from pvs-studio-analyzer analyze.

Leading ../ and ./ strings are also stripped from file paths.

See this post for more information.

Code Listing

(pvs2csv.pl) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
#
# Copyright 2016 by Bill Torpey. All Rights Reserved.
# This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 United States License.
# http://creativecommons.org/licenses/by-nc-nd/3.0/us/deed.en
#
use strict;

###############################################################
# trims quotes, leading & trailing spaces, etc. from a string
sub trim
{
   my @out = @_;
   for (@out) {
      s/^\s+//;
      s/\s+$//;
      s/"//g;
      s/\[//g;
      s/\]//g;
   }
   return wantarray ? @out : $out[0];
}

###############################################################
# get cmd line args
use Getopt::Long qw(:config pass_through);
# relative path to strip from full path
my $relative_path;
GetOptions('r=s' => \$relative_path);

# open named file, or use stdin
 local *INFILE;
 if (defined($ARGV[0])) {
     open(INFILE, "<:crlf", "$ARGV[0]") or die "Cant open $ARGV[0]\n";
 }
 else {
     *INFILE = *STDIN;
 }

# main loop
while (<INFILE>) {
   my $line = $_;
   my $i = index($line, "(");
   my $j = index($line, "):", $i);
   my $filename = substr($line, 0, $i);
   #$filename =~ s/^\.\.\///;                  # remove leading "../" from path 
   my $lineno = substr($line, $i+1, ($j-$i)-1);
   my $errStr = substr($line, $j+3);
   chomp($errStr);
   print "\"$filename:$lineno\",\"$errStr\"\n";
}

close(INFILE);

0;

Comments