File indexing completed on 2024-04-06 12:31:47
0001
0002 use File::Basename;
0003 use lib dirname($0);
0004 use Getopt::Long;
0005 use SCRAMGenUtils;
0006 $|=1;
0007
0008 my $INSTALL_PATH = dirname($0);
0009 my $curdir=`/bin/pwd`; chomp $curdir;
0010 my $precentage_prec=3;
0011 my $value_length=10;
0012 my $html=0;
0013 if(&GetOptions(
0014 "--log=s",\$log,
0015 "--tmpdir=s",\$dir,
0016 "--help",\$help,
0017 ) eq ""){print "ERROR: Wrong arguments.\n"; &usage_msg();}
0018
0019 if (defined $help){&usage_msg();}
0020 if ((!defined $log) || ($log eq "") || (!-f $log))
0021 {print "Log file missing.\n";&usage_msg();}
0022 if ((defined $dir) && ($dir!~/^\s*$/) || (-d $dir))
0023 {
0024 print "<html><head></head><body><pre>\n";
0025 $html=1;
0026 }
0027
0028 if(!open(LOGFILE, $log)){die "Can not open \"$log\" file for reading.";}
0029 my $file="";
0030 my $cache={};
0031 my %urls=();
0032 if($html){$urls{src}=1;}
0033 while(my $line=<LOGFILE>)
0034 {
0035 chomp $line;
0036 if ($line=~/^File:\s+([^\s]+?)\s*$/)
0037 {
0038 $file=$1;
0039 foreach my $key ("Total Lines", "Code Lines", "Commented Lines", "Empty Lines", "Include Statements", "Include Added", "Include Removed")
0040 {&addValue ($cache, $file, $key);}
0041 &addValue ($cache,$file,"Files",1);
0042 if($html && -f "${dir}/includechecker/src/${file}")
0043 {
0044 my $f=$file;
0045 while($f ne "."){$urls{"src/${f}"}=1;$f=dirname($f);}
0046 }
0047 }
0048 elsif ($line=~/^\s+Total\s+lines\s+:\s+(\d+)\s*$/)
0049 {&addValue ($cache, $file, "Total Lines", $1);}
0050 elsif ($line=~/^\s+Code\s+lines\s+:\s+(\d+)\s*$/)
0051 {&addValue ($cache, $file, "Code Lines", $1);}
0052 elsif ($line=~/^\s+Commented\s+lines\s+:\s+(\d+)\s*$/)
0053 {&addValue ($cache, $file, "Commented Lines", $1);}
0054 elsif ($line=~/^\s+Empty\s+lines\s+:\s+(\d+)\s*$/)
0055 {&addValue ($cache, $file, "Empty Lines", $1);}
0056 elsif ($line=~/^\s+Number\s+of\s+includes\s+:\s+(\d+)\s*$/)
0057 {&addValue ($cache, $file, "Include Statements", $1);}
0058 elsif ($line=~/^\s+Actual\s+include\s+added\s+:\s+(\d+)\s*$/)
0059 {&addValue ($cache, $file, "Include Added", $1);}
0060 elsif ($line=~/^\s+Actual\s+include\s+removed\s+:\s+(\d+)\s*$/)
0061 {&addValue ($cache, $file, "Include Removed", $1);}
0062 }
0063 close(LOGFILE);
0064 &process ($cache);
0065 if($html){print "</pre></body></html>\n";}
0066
0067 sub process ()
0068 {
0069 my $cache = shift;
0070 my $base=shift || "";
0071 my $totals = shift || {};
0072 if (!defined $cache){return;}
0073 foreach my $key (sort keys %$cache)
0074 {
0075 if($key eq "_DATA"){next;}
0076 my $ctype = "Total Lines";
0077 my $total = $cache->{$key}{_DATA}{$ctype};
0078 my $num = scalar(@{$totals->{$ctype}});
0079 my $empty = $cache->{$key}{_DATA}{"Empty Lines"};
0080 my $code = $cache->{$key}{_DATA}{"Code Lines"};
0081 my $comment = $cache->{$key}{_DATA}{"Commented Lines"};
0082 my $lines=($comment - ($total - $empty - $code))/2;
0083 if($lines != int($lines)){$code++;$lines=int($lines)+1;}
0084 $code = $code - $lines;
0085 $comment = $comment - $lines;
0086 $cache->{$key}{_DATA}{"Code Lines"} = $code;
0087 $cache->{$key}{_DATA}{"Commented Lines"} = $comment;
0088 my $url="";
0089 if($html)
0090 {
0091 if(exists $urls{"${base}${key}"}){$url="${base}${key}";}
0092
0093 }
0094 print "###########################################################################\n";
0095 if($url){print "For <A href=\"$url\">${base}${key}</a>\n";}
0096 else{print "For ${base}${key}\n";}
0097 foreach my $skey ("Total Lines", "Code Lines", "Commented Lines", "Empty Lines")
0098 {
0099 my $value=$cache->{$key}{_DATA}{$skey};
0100 my $precentage = "-";
0101 if ($total>0)
0102 {$precentage=&SCRAMGenUtils::setPrecision(($value * 100)/$total, $precentage_prec);}
0103 print &SCRAMGenUtils::leftAdjust($skey, 20).": ".&SCRAMGenUtils::leftAdjust($value, $value_length).&SCRAMGenUtils::rightAdjust("$precentage%",$precentage_prec+5)." ";
0104 for(my $i=$num-1; $i>=0; $i--)
0105 {
0106 my $t=$totals->{$ctype}[$i];
0107 if ($t>0)
0108 {$precentage=&SCRAMGenUtils::setPrecision(($value * 100)/$t, $precentage_prec);}
0109 print &SCRAMGenUtils::rightAdjust("$precentage%",$precentage_prec+5)." ";
0110 }
0111 print "\n";
0112 }
0113 $ctype = "Files";
0114 $total=$cache->{$key}{_DATA}{$ctype};
0115 $num = scalar(@{$totals->{$ctype}});
0116 foreach my $skey ("Files")
0117 {
0118 my $value=$cache->{$key}{_DATA}{$skey};
0119 if($value<=1){next;}
0120 my $precentage = "-";
0121 if ($total>0)
0122 {$precentage=&SCRAMGenUtils::setPrecision(($value * 100)/$total, $precentage_prec);}
0123 print &SCRAMGenUtils::leftAdjust($skey, 20).": ".&SCRAMGenUtils::leftAdjust($value, $value_length).&SCRAMGenUtils::rightAdjust("$precentage%",$precentage_prec+5)." ";
0124 for(my $i=$num-1; $i>=0; $i--)
0125 {
0126 my $t=$totals->{$ctype}[$i];
0127 if ($t>0)
0128 {$precentage=&SCRAMGenUtils::setPrecision(($value * 100)/$t, $precentage_prec);}
0129 print &SCRAMGenUtils::rightAdjust("$precentage%",$precentage_prec+5)." ";
0130 }
0131 print "\n";
0132 }
0133 $ctype = "Include Statements";
0134 $total=$cache->{$key}{_DATA}{$ctype};
0135 $num = scalar(@{$totals->{$ctype}});
0136 foreach my $skey ("Include Statements", "Include Added", "Include Removed")
0137 {
0138 my $value=$cache->{$key}{_DATA}{$skey};
0139 if($value==0){next;}
0140 my $precentage = "-";
0141 if ($total>0)
0142 {$precentage=&SCRAMGenUtils::setPrecision(($value * 100)/$total, $precentage_prec);}
0143 print &SCRAMGenUtils::leftAdjust($skey, 20).": ".&SCRAMGenUtils::leftAdjust($value, $value_length).&SCRAMGenUtils::rightAdjust("$precentage%",$precentage_prec+5)." ";
0144 for(my $i=$num-1; $i>=0; $i--)
0145 {
0146 my $t=$totals->{$ctype}[$i];
0147 if ($t>0)
0148 {$precentage=&SCRAMGenUtils::setPrecision(($value * 100)/$t, $precentage_prec);}
0149 print &SCRAMGenUtils::rightAdjust("$precentage%",$precentage_prec+5)." ";
0150 }
0151 print "\n";
0152 }
0153 }
0154 foreach my $key (sort keys %$cache)
0155 {
0156 if($key eq "_DATA"){next;}
0157 foreach my $ctype ("Total Lines", "Files", "Include Statements")
0158 {push @{$totals->{$ctype}}, $cache->{$key}{_DATA}{$ctype};}
0159 &process($cache->{$key}, "${base}${key}/",$totals);
0160 foreach my $ctype ("Total Lines", "Files", "Include Statements")
0161 {pop @{$totals->{$ctype}};}
0162 }
0163 }
0164
0165 sub addValue ()
0166 {
0167 my $cache=shift || return;
0168 my $file=shift || return;
0169 my $type=shift || return;
0170 my $value=shift || 0;
0171 my $str="src";
0172 $cache->{$str} ||= {};
0173 $cache=$cache->{$str};
0174 my $oldvalue=$cache->{_DATA}{$type} || 0;
0175 $cache->{_DATA}{$type}=$oldvalue+$value;
0176 foreach $str (split /\/+/, $file)
0177 {
0178 $cache->{$str} ||= {};
0179 $cache=$cache->{$str};
0180 $oldvalue=$cache->{_DATA}{$type} || 0;
0181 $cache->{_DATA}{$type}=$oldvalue+$value;
0182 }
0183 }
0184
0185 sub usage_msg()
0186 {
0187 print "Usage: \n$0 \\\n\t[--log <file>] [--help]\n\n";
0188 print " --log <file> Log file whcih contains the output of includechecker\n";
0189 print " --tmpdir <dir> Path of directory tmp directory where the newly generated files are available.\n";
0190 print " --help To see this help message.\n";
0191 exit 0;
0192 }