merge the formfield patch from ooo-build
[ooovba.git] / sal / qa / helper / gcov / gcov_resultinterpreter.pl
blob56ce13a594acf546da93060880c201eaf57ec5ad
1 #!/usr/bin/perl -w
2 #
3 # $Id: gcov_resultinterpreter.pl,v 1.3 2005-11-02 17:24:12 kz Exp $
6 # GCOV_RESULTINTERPRETER
7 #
8 # Helper, to interpret the result
10 # Q: Why perl?
11 # A: regexp ;-)
14 use strict;
15 use File::Basename;
16 use Getopt::Long;
18 our $version_info = 'gcov helper $Revision: 1.3 $ ';
20 our $help; # Help option flag
21 our $version; # Version option flag
22 # our $infile;
24 our $usedFunctions; # show all functions, which have a value > 0
25 our $nonusedFunctions; # show all functions, which have a value == 0
26 our $nPercent; # show all functions, which have a value > $nPercent
27 our $complete; # show all functions, which have a value == 100
28 our $incomplete; # show all functions, which have a value > 0 && < 100
30 # Prototypes
31 sub print_usage(*);
32 sub read_gcov_function_file($);
34 # Parse command line options
35 if (!GetOptions(
36 "usedfunctions" => \$usedFunctions,
37 "nonusedfunctions" => \$nonusedFunctions,
38 "percent=s" => \$nPercent,
39 "complete" => \$complete,
40 "incomplete" => \$incomplete,
41 "help" => \$help,
42 "version" => \$version
45 print_usage(*STDERR);
46 exit(1);
49 # Check for help option
50 if ($help)
52 print_usage(*STDOUT);
53 exit(0);
56 # Check for version option
57 if ($version)
59 print("$version_info\n");
60 exit(0);
63 # check if enough parameters
64 if ($#ARGV < 0)
66 print("No input filename specified\n");
67 print_usage(*STDERR);
68 exit(1);
71 if ($complete)
73 $nPercent = 100.00;
75 # ------------------------------------------------------------------------------
77 my %list = read_gcov_function_file($ARGV[0]);
79 my $key;
80 my $value;
82 while (($key, $value) = each %list)
84 # print "function: $key = $value\n";
85 if ($nonusedFunctions)
87 if ($value <= 0.00)
89 print "$key\n";
92 elsif ($usedFunctions)
94 if ($value != 0.00)
96 print "$key, $value\n";
99 elsif ($nPercent)
101 if ($value >= $nPercent)
103 print "$key, $value\n";
106 elsif ($incomplete)
108 if ($value > 0.00 && $value < 100.00)
110 print "$key, $value\n";
113 else
115 print "$key, $value\n";
119 # --------------------------------------------------------------------------------
120 # Read the gcov function (gcov -f) file
121 # and compare line by line with the export function list
122 # so we get a list of functions, which are only exported, and not all stuff.
124 sub read_gcov_function_file($)
126 local *INPUT_HANDLE;
127 my $file = $_[0];
128 my %list;
129 my $line = "";
131 open(INPUT_HANDLE, $file)
132 or die("ERROR: cannot open $file!\n");
134 while ($line = <INPUT_HANDLE>)
136 chomp($line);
137 # sample line (for reg exp:)
138 # 100.00 rtl_ustr_toDouble
139 if ($line =~ /^(.*) (\w+)$/ )
141 my $percent = $1;
142 my $value = $2;
144 $list{$value} = $percent;
147 close(INPUT_HANDLE);
148 return %list;
151 # ----------------------------------------------------------------------------
152 sub print_usage(*)
154 local *HANDLE = $_[0];
155 my $tool_name = basename($0);
157 print(HANDLE <<END_OF_USAGE);
159 Usage: $tool_name [OPTIONS] INPUTFILE
161 -u, --usedFunctions show all functions, which have a value > 0
162 -n, --nonusedFunctions show all functions, which have a value == 0
163 -p, --percent show all functions, which have a value > percent
164 -c, --complete show all functions, which have a value == 100
165 -i, --incomplete show all functions, which have a value > 0 && < 100
167 -h, --help Print this help, then exit
168 -v, --version Print version number, then exit
170 END_OF_USAGE