All pastes #339662 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-02-04 06:46 UTC
rendered paste body
[inaki@mecha]~/Desktop/wgcc/pgdc>make info
perl lines.pl
2188 lines in 14 files.
        322 lines in 1 h files.
        1476 lines in 10 cpp files.
        257 lines in 1 pal files.
        52 lines in 1 pl files.
        81 lines in 1 Makefile files.

55kb in 14 files.
        11kb in 1 h files.
        37kb in 10 cpp files.
        2kb in 1 pal files.
        1kb in 1 pl files.
        2kb in 1 Makefile files.


#!/usr/bin/perl

opendir(DIR, ".") or die "$!\n";
while($z=readdir(DIR)) {
	if (-f $z) {
	open(F, $z);
	@tmp = split(/\./,$z);
	$ext = $tmp[$#tmp];
	$files{$ext}++;
	@bar = <F>;
	close(F);
	$file{$ext} += $#bar + 1;
	$total+= $#bar+1;
	$tfile++;
	$br = join('',@bar);
	$bytes{$ext} += length($br);
	$tbytes += length($br);
        # change these to whatever the extension of your code is
	next if ($key ne "cpp" && $key ne "h" && $key ne "c");
	$fipa++
	}
}
print $total." lines in ".$tfile." files.\n";
while (($key, $value) = each %file) {
	print "\t".$value." lines in ".$files{$key}." $key files.\n";
	$tcbytes += $bytes{$key};
}
print "\n".byteconv($tcbytes)." in $tfile files.\n";

while (($key, $value) = each %file) {
	print "\t".byteconv($bytes{$key})." in ".$files{$key}." $key files.\n";
}

# a rough-and-ready human-readable byte converter
sub byteconv {
	my $bytes = shift;
	if ($bytes < 1024) {
		$dretr = $bytes."b";
	}
	if ($bytes > 1023 && $bytes < (1024**2)) {
		my $tmp = int($bytes/1024);
		$dretr = $tmp."kb";
	}
	if ($bytes > ((1024**2)-1) && $bytes < (1024**3)) {
		my $tmp = int($bytes/(1024**2));
		$dretr = $tmp."mb";
	}
	if ($bytes > ((1024**3)-1) && $bytes < (1024**4)) {
		my $tmp = int($bytes/(1024**3));
		$dretr = $tmp."gb";
	}
	return $dretr;
}