fix haddock submodule pointer
[ghc-hetmet.git] / utils / count_lines / count_lines.lprl
1 #! /usr/bin/perl
2
3 \begin{code}
4
5 use FindBin;
6
7 %DirCount = ();
8 %ModCount = ();
9 %DirComments = ();
10 %ModComments = ();
11
12 my $binPath = $FindBin::Bin;
13
14 foreach $f ( @ARGV ) {
15
16     if ( $f =~ /\.lhs$/ ) {
17         open(INF, "$binPath/../../inplace/lib/unlit $f - |") || die "Couldn't unlit $f!\n";
18     } else {
19         open(INF, "< $f") || die "Couldn't open $f!\n";
20     }
21     $cnt = 0;
22     while (<INF>) {
23         s/--.*//;
24         s/{-.*-}//;
25         next if /^\s*$/;
26         $cnt++;
27     }
28     close(INF);
29
30     $f_wc = `wc $f`; die "wc failed: $f\n" if $? != 0;
31     if ( $f_wc =~ /\s*(\d+)\s*(\d+)\s*(\d+)/ ) {
32         $comments = $1 - $cnt;
33     } else {
34         die "Can't grok wc format: $f_wc";
35     }
36
37     if ( $f =~ /(.*)\/(.*)/ ) {
38         local($dir) = $1;
39         local($mod) = $2;
40         $DirCount{$dir} += $cnt;
41         $ModCount{$mod} += $cnt;
42         $DirComments{$dir} += $comments;
43         $ModComments{$mod} += $comments;
44     } else {
45         print STDERR "not counted in a directory: $f\n";
46         $ModCount{$f} += $cnt;
47         $ModComments{$f} += $comments;
48     }
49 }
50
51 # print the info
52 $tot = 0;
53 $totcmts = 0;
54 printf "\n                      Code  Comments\n";
55 foreach $d (sort (keys %DirCount)) {
56     printf "%-20s %6d %6d\n", $d, $DirCount{$d}, $DirComments{$d};
57     $tot     += $DirCount{$d};
58     $totcmts += $DirComments{$d};
59 }
60 printf "\n%-20s %6d %6d\n\n\n", 'TOTAL:', $tot, $totcmts;
61
62 $tot = 0;
63 $totcmts = 0;
64 printf "\n                      Code  Comments\n";
65 foreach $m (sort (keys %ModCount)) {
66     printf "%-20s %6d %6d\n", $m, $ModCount{$m}, $ModComments{$m};
67     $tot += $ModCount{$m};
68     $totcmts += $ModComments{$m};
69 }
70 printf "\n%-20s %6d %6d\n", 'TOTAL:', $tot, $totcmts;
71
72 \end{code}
73