X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fcount_lines;fp=compiler%2Fcount_lines;h=43ca79e68a51ca00dc104606d6428a75a31ea05d;hp=0000000000000000000000000000000000000000;hb=0065d5ab628975892cea1ec7303f968c3338cbe1;hpb=28a464a75e14cece5db40f2765a29348273ff2d2 diff --git a/compiler/count_lines b/compiler/count_lines new file mode 100644 index 0000000..43ca79e --- /dev/null +++ b/compiler/count_lines @@ -0,0 +1,63 @@ +#! /usr/bin/perl +# +%DirCount = (); +%ModCount = (); +%DirComments = (); +%ModComments = (); + +foreach $f ( @ARGV ) { + + if ( $f =~ /\.lhs$/ ) { + open(INF, "../utils/unlit/unlit $f - |") || die "Couldn't unlit $f!\n"; + } else { + open(INF, "< $f") || die "Couldn't open $f!\n"; + } + $cnt = 0; + while () { + s/--.*//; + s/{-.*-}//; + next if /^\s*$/; + $cnt++; + } + close(INF); + + $f_wc = `wc $f`; die "wc failed: $f\n" if $? != 0; + if ( $f_wc =~ /\s*(\d+)\s*(\d+)\s*(\d+)/ ) { + $comments = $1 - $cnt; + } else { + die "Can't grok wc format: $f_wc"; + } + + if ( $f =~ /(.*)\/(.*)/ ) { + local($dir) = $1; + local($mod) = $2; + $DirCount{$dir} += $cnt; + $ModCount{$mod} += $cnt; + $DirComments{$dir} += $comments; + $ModComments{$mod} += $comments; + } else { + print STDERR "not counted in a directory: $f\n"; + $ModCount{$f} += $cnt; + $ModComments{$f} += $comments; + } +} + +# print the info +$tot = 0; +$totcmts = 0; +foreach $d (sort (keys %DirCount)) { + printf "%-20s %6d %6d\n", $d, $DirCount{$d}, $DirComments{$d}; + $tot += $DirCount{$d}; + $totcmts += $DirComments{$d}; +} +printf "\n%-20s %6d %6d\n\n\n", 'TOTAL:', $tot, $totcmts; + +$tot = 0; +$totcmts = 0; +printf "\n Code Comments\n"; +foreach $m (sort (keys %ModCount)) { + printf "%-20s %6d %6d\n", $m, $ModCount{$m}, $ModComments{$m}; + $tot += $ModCount{$m}; + $totcmts += $ModComments{$m}; +} +printf "\n%-20s %6d %6d\n", 'TOTAL:', $tot, $totcmts;