summaryrefslogtreecommitdiff
path: root/scripts/stats.pl
blob: 425261f57d8db40b5626e853b051f7f3fb93765a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl

# The yChat Project (2003, 2004)
# The Xerl Project (2005, 2006)
#
# 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 CSS"} +
  $stats{"Lines of XML"};

unless ( defined $param ) {
    print "$_ = " . $stats{$_} . "\n" for sort keys %stats;

}
else {
    print $stats{$_} . ' ' for sort keys %stats;
}

print "\n";

sub recursive {
    my $shift = shift;
    return unless -d $shift;
    my @dir = dopen($shift);

    foreach (@dir) {
        next if /^\.$/o or /^\.{2}$/o;

        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)$/o ) {
        ++$stats{"Number of source files"};
        $stats{"Lines of source"} += countlines($shift);

    }
    elsif ( $shift =~ /\.css$/o ) {
        ++$stats{"Number of CSS files"};
        $stats{"Lines of CSS"} += countlines($shift);

    }
    elsif ( $shift =~ /\.(gif|png|jpg)$/o ) {
        ++$stats{"Number of gfx files"};

    }
    elsif ( $shift =~ /(\.xml)$/o ) {
        ++$stats{"Number of XML files"};
        $stats{"Lines of XML"} += countlines($shift);

    }
    elsif ( $shift =~ /(\.pl|\.pm|\.sh|configure.*|Makefile.*)$/o ) {
        ++$stats{"Number of script files"};
        $stats{"Lines of scripts"} += countlines($shift);

    }
    elsif ( $shift =~ /(\.txt|[A-Z]+)$/o ) {
        ++$stats{"Number of text files"};
        $stats{"Lines of text"} += countlines($shift);

    }
    elsif ( $shift =~ /\.so$/o ) {
        ++$stats{"Number of compiled module files"};
    }
}

sub countlines {
    return scalar fopen shift;
}