App-cloc
view release on metacpan or search on metacpan
# Keys of the stripped_X arrays are canonical file names;
# should overlap mostly. Keys in stripped_L but not in
# stripped_R are files that have been deleted. Keys in
# stripped_R but not in stripped_L have been added.
my %stripped_L = ();
@stripped_L{ @files_L_minus_dir } = @files_L;
my %stripped_R = ();
@stripped_R{ @files_R_minus_dir } = @files_R;
my %common = ();
foreach my $f (keys %stripped_L) {
$common{$f} = 1 if defined $stripped_R{$f};
}
my %deleted = ();
foreach my $f (keys %stripped_L) {
$deleted{$stripped_L{$f}} = $f unless defined $stripped_R{$f};
}
my %added = ();
foreach my $f (keys %stripped_R) {
$added{$stripped_R{$f}} = $f unless defined $stripped_L{$f};
}
#use Data::Dumper::Simple;
#print Dumper("align_by_pairs", %stripped_L, %stripped_R);
#print Dumper("align_by_pairs", %common, %added, %deleted);
foreach my $f (keys %common) {
push @{$ra_compare_list}, [ $stripped_L{$f},
$stripped_R{$f} ];
}
@{$ra_added } = keys %added ;
@{$ra_removed } = keys %deleted;
print "<- align_by_pairs()\n" if $opt_v > 2;
return;
#print Dumper("align_by_pairs", @files_L_minus_dir, @files_R_minus_dir);
#die;
} # 1}}}
sub html_header { # {{{1
my ($title , ) = @_;
print "-> html_header\n" if $opt_v > 2;
return
'<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="cloc http://github.com/AlDanial/cloc">
' .
"
<!-- Created by $script v$VERSION -->
<title>$title</title>
" .
'
<style TYPE="text/css">
<!--
body {
color: black;
background-color: white;
font-family: monospace
}
.whitespace {
background-color: gray;
}
.comment {
color: gray;
font-style: italic;
}
.clinenum {
color: red;
}
.linenum {
color: green;
}
-->
</style>
</head>
<body>
<pre><tt>
';
print "<- html_header\n" if $opt_v > 2;
} # 1}}}
sub html_end { # {{{1
return
'</tt></pre>
</body>
</html>
';
} # 1}}}
sub die_unknown_lang { # {{{1
my ($lang, $option_name) = @_;
die "Unknown language '$lang' used with $option_name option. " .
"The command\n $script --show-lang\n" .
"will print all recognized languages. Language names are " .
"case sensitive.\n" ;
} # 1}}}
sub unicode_file { # {{{1
my $file = shift @_;
print "-> unicode_file($file)\n" if $opt_v > 2;
return 0 if (-s $file > 2_000_000);
# don't bother trying to test binary files bigger than 2 MB
my $IN = new IO::File $file, "r";
if (!defined $IN) {
warn "Unable to read $file; ignoring.\n";
return 0;
}
my @lines = <$IN>;
$IN->close;
if (unicode_to_ascii( join('', @lines) )) {
print "<- unicode_file()\n" if $opt_v > 2;
return 1;
} else {
print "<- unicode_file()\n" if $opt_v > 2;
return 0;
}
} # 1}}}
if (!defined $IN) {
warn "Unable to read $file; ignoring.\n";
return ();
}
my @entry = ();
while (<$IN>) {
next if /^\s*$/ or /^\s*#/; # skip empty or commented lines
s/\cM$//; # DOS to Unix
chomp;
push @entry, $_;
}
$IN->close;
print "<- read_list_file\n" if $opt_v > 2;
return @entry;
}
# 1}}}
sub external_utility_exists { # {{{1
my $exe = shift @_;
my $success = 0;
if ($ON_WINDOWS) {
$success = 1 unless system $exe . ' > nul';
} else {
$success = 1 unless system $exe . ' >/dev/null 2>&1';
if (!$success) {
$success = 1 unless system "which" . " $exe" . ' >/dev/null 2>&1';
}
}
return $success;
} # 1}}}
sub write_xsl_file { # {{{1
my $OUT = new IO::File $CLOC_XSL, "w";
if (!defined $OUT) {
warn "Unable to write $CLOC_XSL $!\n";
return;
}
my $XSL = # <style> </style> {{{2
'<?xml version="1.0" encoding="US-ASCII"?>
<!-- XLS file by Paul Schwann, January 2009.
Fixes for by-file and by-file-by-lang by d_uragan, November 2010.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CLOC Results</title>
</head>
<style type="text/css">
table {
table-layout: auto;
border-collapse: collapse;
empty-cells: show;
}
td, th {
padding: 4px;
}
th {
background-color: #CCCCCC;
}
td {
text-align: center;
}
table, td, tr, th {
border: thin solid #999999;
}
</style>
<body>
<h3><xsl:value-of select="results/header"/></h3>
';
# 2}}}
if ($opt_by_file) {
$XSL .= # <table> </table>{{{2
' <table>
<thead>
<tr>
<th>File</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
<th>Language</th>
';
$XSL .=
' <th>3<sup>rd</sup> Generation Equivalent</th>
<th>Scale</th>
' if $opt_3;
$XSL .=
' </tr>
</thead>
<tbody>
<xsl:for-each select="results/files/file">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
<td><xsl:value-of select="@language"/></td>
';
$XSL .=
' <td><xsl:value-of select="@factor"/></td>
<td><xsl:value-of select="@scaled"/></td>
' if $opt_3;
$XSL .=
' </tr>
</xsl:for-each>
<tr>
<th>Total</th>
<th><xsl:value-of select="results/files/total/@blank"/></th>
<th><xsl:value-of select="results/files/total/@comment"/></th>
<th><xsl:value-of select="results/files/total/@code"/></th>
<th><xsl:value-of select="results/files/total/@language"/></th>
';
$XSL .=
' <th><xsl:value-of select="results/files/total/@factor"/></th>
<th><xsl:value-of select="results/files/total/@scaled"/></th>
' if $opt_3;
$XSL .=
' </tr>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
';
$XSL .=
' <td><xsl:value-of select="@factor"/></td>
<td><xsl:value-of select="@scaled"/></td>
' if $opt_3;
$XSL .=
' </tr>
</xsl:for-each>
<tr>
<th>Total</th>
<th><xsl:value-of select="results/languages/total/@sum_files"/></th>
<th><xsl:value-of select="results/languages/total/@blank"/></th>
<th><xsl:value-of select="results/languages/total/@comment"/></th>
<th><xsl:value-of select="results/languages/total/@code"/></th>
';
$XSL .=
' <th><xsl:value-of select="results/languages/total/@factor"/></th>
<th><xsl:value-of select="results/languages/total/@scaled"/></th>
' if $opt_3;
$XSL .=
' </tr>
</tbody>
</table>
';
# 2}}}
}
$XSL.= <<'EO_XSL'; # {{{2
</body>
</html>
</xsl:template>
</xsl:stylesheet>
EO_XSL
# 2}}}
my $XSL_DIFF = <<'EO_DIFF_XSL'; # {{{2
<?xml version="1.0" encoding="US-ASCII"?>
<!-- XLS file by Blazej Kroll, November 2010 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CLOC Results</title>
</head>
<style type="text/css">
table {
table-layout: auto;
border-collapse: collapse;
empty-cells: show;
margin: 1em;
}
td, th {
padding: 4px;
}
th {
background-color: #CCCCCC;
}
td {
text-align: center;
}
table, td, tr, th {
border: thin solid #999999;
}
</style>
<body>
<h3><xsl:value-of select="results/header"/></h3>
EO_DIFF_XSL
# 2}}}
if ($opt_by_file) {
$XSL_DIFF.= <<'EO_DIFF_XSL'; # {{{2
<table>
<thead>
<tr><th colspan="4">Same</th>
</tr>
<tr>
<th>File</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="diff_results/same/file">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
<table>
<thead>
<tr><th colspan="4">Modified</th>
</tr>
<tr>
<th>File</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="diff_results/modified/file">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
( run in 2.181 seconds using v1.01-cache-2.11-cpan-f56aa216473 )