summaryrefslogtreecommitdiff
path: root/scripts/stats.pl
blob: 38cc67cc3994fdf1b8b0023eaf70594ca83b7d51 (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
93
94
95
96
97
#!/usr/bin/perl

# The yChat Project (2003 - 2004)
#
# This script generates source code and project statistics 

use strict;

use scripts::modules::file;

my %stats;

&recursive(".");

$stats{"Lines total"} = $stats{"Lines of source"} 
                   + $stats{"Lines of scripts"}   
                   + $stats{"Lines of text"}   
                   + $stats{"Lines of HTML"};

my $bool = 0;
foreach ( sort keys %stats )
{
 if ($bool == 0)
 { 
  print "$_ = " . $stats{$_} . "\n";
  $bool = 1;
 }
 else
 {
  print "$_ = " . $stats{$_} . "\n";
  $bool = 0;
 }
}

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|\.sh|configure.*|Makefile.*)$/ )
 {
  $stats{"Number of script files"}++;
  $stats{"Lines of scripts"} += countlines($shift);
 }
 elsif ( $shift =~ /(\.txt|README|INSTALL|COPYING|NEWS|SNAPSHOT|ChangeLog)$/ )
 {
  $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; 
}