| 1 |
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' |
| 2 |
& eval 'exec perl -S $0 $argv:q' |
| 3 |
if 0; |
| 4 |
|
| 5 |
# -*- perl -*- |
| 6 |
|
| 7 |
use File::Basename; |
| 8 |
|
| 9 |
$cmd= basename($0); |
| 10 |
|
| 11 |
if ($#ARGV < 0) { |
| 12 |
die "Usage: $cmd module...\n"; |
| 13 |
} |
| 14 |
|
| 15 |
@match_order = (); |
| 16 |
%typeRE = (); |
| 17 |
|
| 18 |
&initfiletypes; |
| 19 |
|
| 20 |
foreach $module (@ARGV) { |
| 21 |
if ( ! -d $module ) { |
| 22 |
warn "$cmd: no such directory $module\n"; |
| 23 |
next; |
| 24 |
} |
| 25 |
|
| 26 |
open(DIRS, "find $module -type d|"); |
| 27 |
@dirs = grep {if(!/CVS/) {chop;}} <DIRS>; |
| 28 |
close(DIRS); |
| 29 |
|
| 30 |
open(FIND, "find $module -type f|"); |
| 31 |
@files = grep {if (!/build/ |
| 32 |
&& !/CVS/ |
| 33 |
&& !/rpc\+\+/ |
| 34 |
&& !/\.bpr$/ |
| 35 |
&& !/\.mdp$/ |
| 36 |
&& !/\.MDP$/ |
| 37 |
&& !/\.dsp$/ |
| 38 |
&& !/\.DSP$/ |
| 39 |
&& !/\.dsw$/ |
| 40 |
&& !/\.DSW$/ |
| 41 |
&& !/\.mak$/ |
| 42 |
&& !/\.MAK$/ |
| 43 |
&& !/\.o$/ |
| 44 |
&& !/\.sl$/ |
| 45 |
&& !/\.a$/) {chop;}} <FIND>; |
| 46 |
close(FIND); |
| 47 |
|
| 48 |
$totdirs = $#dirs; |
| 49 |
$totfiles = $#files; |
| 50 |
$totlines = 0; |
| 51 |
%lines = (); |
| 52 |
|
| 53 |
foreach $file (@files) { |
| 54 |
$n = 0; |
| 55 |
if (!open(IN, $file)) { |
| 56 |
warn "$cmd: cannot open '$file' for reading\n"; |
| 57 |
next; |
| 58 |
} |
| 59 |
while(<IN>) { |
| 60 |
$n++; |
| 61 |
} |
| 62 |
close(IN); |
| 63 |
$lines{$file} = $n; |
| 64 |
$totlines += $n; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
# Define two associative arrays to keep the results for each kind |
| 69 |
# of file. |
| 70 |
%linespertype = (); |
| 71 |
%filespertype = (); |
| 72 |
foreach $type (keys %typeRE) { |
| 73 |
$linespertype{$type} = 0; |
| 74 |
$filespertype{$type} = 0; |
| 75 |
} |
| 76 |
# The file is classified and added to the corresponding variable. |
| 77 |
FILE: while (($file, $l) = each %lines) { |
| 78 |
foreach $type (@match_order) { |
| 79 |
$re = $typeRE{$type}; |
| 80 |
if($file =~ m/$re/) { |
| 81 |
$linespertype{$type} += $l; |
| 82 |
$filespertype{$type}++; |
| 83 |
next FILE; |
| 84 |
} |
| 85 |
} |
| 86 |
print STDERR "Unmatched file: $file\n"; |
| 87 |
} |
| 88 |
|
| 89 |
format STDOUT_TOP= |
| 90 |
@||| |
| 91 |
$% |
| 92 |
|
| 93 |
Lines of code in module @<<<<<<<<<<<<<<<<<<<< |
| 94 |
$module |
| 95 |
|
| 96 |
Files: @>>>>>>>> |
| 97 |
$totfiles |
| 98 |
Directories: @>>>>>>>> |
| 99 |
$totdirs |
| 100 |
Lines: @>>>>>>>> |
| 101 |
$totlines |
| 102 |
|
| 103 |
File type lines files |
| 104 |
---------------------------- ------------------ ----------------- |
| 105 |
. |
| 106 |
format STDOUT= |
| 107 |
@<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>>>> @>>>>>>>>>>>>>>>> |
| 108 |
$type, $typelines, $typefiles |
| 109 |
. |
| 110 |
|
| 111 |
|
| 112 |
foreach $type (@match_order) { |
| 113 |
$typelines = $linespertype{$type}; |
| 114 |
$typefiles = $filespertype{$type}; |
| 115 |
if ($typefiles != 0) { |
| 116 |
write; |
| 117 |
} |
| 118 |
} |
| 119 |
# Forzamos un newpage para cada modulo. |
| 120 |
$- = 0; |
| 121 |
} |
| 122 |
|
| 123 |
sub updateRE { |
| 124 |
local $desc = shift; |
| 125 |
local $re = shift; |
| 126 |
|
| 127 |
if (exists $typeRE{$desc}) { |
| 128 |
local $mix = $typeRE{$desc} . '|(' . $re . ')'; |
| 129 |
$typeRE{$desc} = $mix; |
| 130 |
} else { |
| 131 |
$typeRE{$desc} = '(' . $re . ')'; |
| 132 |
push @match_order, $desc; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
sub initfiletypes { |
| 137 |
# Here we define the regular expressions for each kind of file. |
| 138 |
# This RE must be mutually exclusive, a file will not be counted |
| 139 |
# twice, but it could be unproperly classified. |
| 140 |
|
| 141 |
local %filenames = |
| 142 |
('GNUmakefile' => 'Makefile', |
| 143 |
'Makefile.*' => 'Makefile', |
| 144 |
'README' => 'README files', |
| 145 |
'COPYING' => 'Licenses', |
| 146 |
'LICENSE.*' => 'Licenses', |
| 147 |
'ChangeLog.*' => 'ChangeLog', |
| 148 |
'ChangeLog-.*' => 'ChangeLog', |
| 149 |
'.cvsignore' => 'Control CVS', |
| 150 |
'run_test.pl' => 'Test driver', |
| 151 |
'run_test' => 'Test driver', |
| 152 |
'run_tests' => 'Test driver', |
| 153 |
'run_test.sh' => 'Test driver'); |
| 154 |
local %fileexts = |
| 155 |
('cc' => 'C++ sources', |
| 156 |
'cpp' => 'C++ sources', |
| 157 |
'inl' => 'C++ sources', |
| 158 |
'i' => 'C++ sources', |
| 159 |
'h' => 'Headers', |
| 160 |
'hh' => 'Headers', |
| 161 |
'c' => 'C/C++ sources', |
| 162 |
'idl' => 'IDL sources', |
| 163 |
'IDL' => 'IDL sources', |
| 164 |
'pidl' => 'IDL sources', |
| 165 |
'y' => 'yacc source', |
| 166 |
'yy' => 'yacc source', |
| 167 |
'l' => 'lex source', |
| 168 |
'll' => 'lex source', |
| 169 |
'php' => 'php script', |
| 170 |
'pm' => 'perl script', |
| 171 |
'pl' => 'perl script', |
| 172 |
'perl' => 'perl script', |
| 173 |
'py' => 'python script', |
| 174 |
'GNU' => 'GNU make config', |
| 175 |
'tex' => '(La)TeX', |
| 176 |
'txt' => 'Text files', |
| 177 |
'1' => 'man pages', |
| 178 |
'3' => 'man pages', |
| 179 |
'html' => 'HTML', |
| 180 |
'bib' => 'BibTeX', |
| 181 |
'sty' => 'TeX styles', |
| 182 |
'bld' => 'VxWorks build file', |
| 183 |
'am' => 'Automake file', |
| 184 |
'icc' => 'VisualAge project files', |
| 185 |
'icp' => 'VisualAge project files', |
| 186 |
'vac' => 'VisualAge project files', |
| 187 |
'vcp' => 'Microsof eMbedded Visual Tools project files', |
| 188 |
'vcw' => 'Microsof eMbedded Visual Tools project files', |
| 189 |
'bpr' => 'Borland project files', |
| 190 |
'bor' => 'Borland project files', |
| 191 |
'dsp' => 'DevStudio project files', |
| 192 |
'DSP' => 'DevStudio project files', |
| 193 |
'mdp' => 'MSVC project files', |
| 194 |
'MDP' => 'MSVC project files', |
| 195 |
'dsw' => 'MSVC workspaces', |
| 196 |
'DSW' => 'MSVC workspaces', |
| 197 |
'mak' => 'MSVC MAK files', |
| 198 |
'MAK' => 'MSVC MAK files', |
| 199 |
'java' => 'JAVA source', |
| 200 |
'class' => 'JAVA class', |
| 201 |
'cccc' => 'codecount output', |
| 202 |
'gif' => 'GIF images', |
| 203 |
'conf' => 'Svc_Config files', |
| 204 |
'diff' => 'patches', |
| 205 |
'zip' => 'Compressed files', |
| 206 |
'gz' => 'Compressed files', |
| 207 |
'EXE' => 'Win32 executable', |
| 208 |
'shar' => 'Shar archive', |
| 209 |
'mib' => 'MIB definition files', |
| 210 |
'gperf' => 'GPERF input', |
| 211 |
'phil.*'=> 'Test driver' |
| 212 |
); |
| 213 |
local %paths = (); |
| 214 |
|
| 215 |
local ($desc, $reseed); |
| 216 |
while (($reseed, $desc) = each %filenames) { |
| 217 |
local $re = '/' . $reseed . '$'; |
| 218 |
updateRE($desc, $re); |
| 219 |
} |
| 220 |
while (($reseed, $desc) = each %fileexts) { |
| 221 |
local $re = '/[^/]*\.' . $reseed . '$'; |
| 222 |
updateRE($desc, $re); |
| 223 |
} |
| 224 |
while (($reseed, $desc) = each %paths) { |
| 225 |
local $re = $reseed; |
| 226 |
updateRE($desc, $re); |
| 227 |
} |
| 228 |
|
| 229 |
updateRE('Others', '.*'); |
| 230 |
|
| 231 |
# while (($desc, $reseed) = each %typeRE) { |
| 232 |
# print STDERR $desc, " ==> ", $reseed, "\n"; |
| 233 |
# } |
| 234 |
} |