summaryrefslogtreecommitdiff
path: root/scripts/stats.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/stats.pl')
-rwxr-xr-xscripts/stats.pl95
1 files changed, 95 insertions, 0 deletions
diff --git a/scripts/stats.pl b/scripts/stats.pl
new file mode 100755
index 0000000..0eea04d
--- /dev/null
+++ b/scripts/stats.pl
@@ -0,0 +1,95 @@
+#!/usr/bin/perl
+
+# The yChat Project (2003 - 2005)
+#
+# This script generates source code and project statistics
+
+use strict;
+
+use scripts::modules::file;
+
+my %stats;
+my $param = shift;
+
+&recursive(".");
+
+$stats{"Lines total"} = $stats{"Lines of source"}
+ + $stats{"Lines of scripts"}
+ + $stats{"Lines of text"}
+ + $stats{"Lines of HTML"};
+
+unless (defined $param) {
+
+ print "$_ = " . $stats{$_} . "\n"
+ for ( sort keys %stats );
+
+} else {
+
+ print $stats{$_} . " "
+ for sort keys %stats;
+
+}
+
+print "\n";
+
+sub recursive
+{
+ my $shift = shift;
+ my @dir = &dopen($shift);
+
+ foreach (@dir)
+ {
+ next if /^\.$/ or /^\.{2}$/;
+
+ if ( -f "$shift/$_" )
+ {
+ $stats{"Number of files total"}++;
+ &filestats("$shift/$_");
+ }
+ elsif ( -d "$shift/$_" )
+ {
+ $stats{"Number of dirs total"}++;
+ &recursive("$shift/$_");
+ }
+ }
+}
+
+sub filestats
+{
+ my $shift = shift;
+ if ( $shift =~ /\.(cpp|h|tmpl)$/ )
+ {
+ $stats{"Number of source files"}++;
+ $stats{"Lines of source"} += countlines($shift);
+ }
+ elsif ( $shift =~ /\.(html|css)$/ )
+ {
+ $stats{"Number of HTML files"}++;
+ $stats{"Lines of HTML"} += countlines($shift);
+ }
+ elsif ( $shift =~ /\.(gif|png|jpg)$/ )
+ {
+ $stats{"Number of gfx files"}++;
+ }
+ elsif ( $shift =~ /(\.pl|\.pm|\.sh|configure.*|Makefile.*)$/ )
+ {
+ $stats{"Number of script files"}++;
+ $stats{"Lines of scripts"} += countlines($shift);
+ }
+ elsif ( $shift =~ /(\.txt|[A-Z]+)$/ )
+ {
+ $stats{"Number of text files"}++;
+ $stats{"Lines of text"} += countlines($shift);
+ }
+ elsif ( $shift =~ /\.so$/ )
+ {
+ $stats{"Number of compiled module files"}++;
+ }
+}
+
+sub countlines
+{
+ my $shift = shift;
+ my @file = fopen($shift);
+ return $#file;
+}