rendered paste bodyuse strict;
use warnings;
use Cwd;
use File::Find;
my ($asm_line_count, $c_line_count);
find(\&search, cwd);
print "C lines: $c_line_count (".(($c_line_count / ($c_line_count + $asm_line_count)) * 100)."%)\n";
print "ASM lines: $asm_line_count (".(($asm_line_count / ($c_line_count + $asm_line_count)) * 100)."%)\n";
print "Total: ".($asm_line_count + $c_line_count)."\n";
sub search($$) {
my $file = $File::Find::name || return;
return unless -r $file;
if($file =~ /(asm|inc|c|h)$/) {
count($file, $1);
}
}
sub count($$) {
my ($file, $type) = @_;
open(F, $file) or print("unable to open $file\n") && return;
my @f;
if($type eq "c" || $type eq "h") {
my $comment = 0;
# this is the ugliest thing ever.. searching for lines between
# comment markers "/*" and "*/". trying to find a better/cleaner way
# was causing my skull to pulsate
while(<F>) {
if($comment) {
if(/\*\//) {
$comment = 0;
} else {
next;
}
} elsif(/^\/\*/) {
$comment = 1;
}
$c_line_count++ unless (($comment) || (/^\/\//) || (/^\s*$/));
}
}
elsif($type eq "asm" || $type eq "inc") {
while(<F>) {
$asm_line_count++ unless ((/^;/) || (/^\s*$/));
}
}
close(F);