1#!/usr/bin/perl -w 2 3 4sub processdir($$) { 5 my ($dirname,$path) = @_; 6 my $file = ""; 7 my $mypath = $dirname; 8 local *DIR; 9 if ($path ne "") {$mypath = "$path/$dirname"} 10 opendir(DIR, $mypath); 11 my %dirfiles = (); 12 my %dirdirs = (); 13 my @dirlines = (); 14 my $hasmake = 0; 15 my $ilines = 0; 16 17 my %mysource = (); 18 my %mybinary = (); 19 my %myfile = (); 20 my $f; 21 22 if(-s "$mypath/Makefile.am") { 23 $hasmake = 1; 24 print " File $file\n"; 25 $fileprint = ""; 26 @dirlines = &processfile("Makefile.am", $mypath); # &avoids prototype recursion warning 27 my $name = $prename = $postname = $x = ""; 28 foreach $x (@dirlines) { 29 $ilines++; 30 print "$ilines: $x"; 31 if($x =~ /^\s*([^_\s]+)_([^_\s]+)\s+[=]\s+(.*)/) { 32 $prename = $1; 33 $postname = $2; 34 @filenames = split(/\s+/, $3); 35 if($postname eq "PROGRAMS") { 36 foreach $f (@filenames) {$mybinary{$f}++} 37 } 38 elsif($postname eq "SOURCES") { 39 foreach $f (@filenames) {$mysource{$f}++} 40 } 41 elsif($postname eq "HEADERS") { 42 foreach $f (@filenames) {$mysource{$f}++} 43 } 44 elsif($postname eq "DATA") { 45 foreach $f (@filenames) {$myfile{$f}++} 46 } 47 elsif($prename eq "EXTRA" && $postname eq "DIST") { 48 foreach $f (@filenames) {$myfile{$f}++} 49 } 50 elsif($prename eq "AM" && $postname eq "CFLAGS") { 51 } 52 else { 53 print ".. ignored line: [$prename]_[$postname] $line\n"; 54 } 55 my $n = scalar @filenames; 56# print "$ilines: [$n] $x"; 57 } 58 elsif($x =~ /^\s*([^_\s]+)\s+[=]\s+(.*)/) { 59 $name = $1; 60 @filenames = split(/\s+/, $2); 61 if($name eq "SUBDIRS") { 62 foreach $f (@filenames) {$mydir{$f}++} 63 } 64 elsif($name =~ /SRC$/) { 65 foreach $f (@filenames) {$mysource{$f}++} 66 } 67 } 68 } 69 } 70 71 while ($file = readdir(DIR)) { 72 if(($file =~ /^[.]/) && (-d "$mypath/$file")) {next} # skip .* hidden files 73 if($file =~ /^CVS$/) {next} # skip CVS directory 74 if($file =~ /^Makefile([.]in)?$/) {next} # skip Makefile, Makefile.in 75 if($file =~ /[~]$/) {next} # skip *~ recover files 76 if($file =~ /^[.][\#]/) {next} # skip .# recover files 77 if($file =~ /^[\#].*[\#]/) {next} # skip #xxx# recover files 78 if($file =~ /[.]o$/) {next} # skip .o object files 79 if($file =~ /[.]l[oa]$/) {next} # skip .o object files 80 if($file eq "Makefile.am") {next} 81 if (-d "$mypath/$file") { 82 if(-e "$mypath/$file/Makefile.am") { 83 #print " Directory $file\n"; 84 $fileprint = ""; 85 &processdir($file,$mypath); #& avoids prototype warning 86 $dirdirs{$file} = "$mypath/$file"; 87 } 88 else { 89 print ".. $mypath/$file no Makefile.am\n"; 90 } 91 } 92 else { 93 $dirfiles{$file} = "$mypath/$file"; 94 } 95 } 96 closedir(DIR); 97 98 print " Directory: $mypath\n"; 99 $f = scalar keys %dirfiles; 100 101 if(!$hasmake) { 102 print "++ no Makefile.am found in $mypath\n"; 103 } 104 elsif(!scalar @dirlines) { 105 print "++ no '=' lines found in $mypath\n"; 106 } 107 108 else { 109 my $nsrc = scalar keys %mysource; 110 my $nbin = scalar keys %mybinary; 111 my $nfil = scalar keys %myfile; 112 print ".. $ilines lines $nsrc sources $nbin binaries $nfil other\n"; 113 my @unknown = (); 114 foreach $fname (keys (%dirfiles)) { 115 if($fname =~ /[.][ch]$/) { 116 if(!defined($mysource{$fname})) {push @unknown, $fname} 117 } 118 elsif($fname =~ /[.]/) { 119 if(!defined($myfile{$fname})) {push @unknown, $fname} 120 } 121 else { 122 if(!defined($myfile{$fname}) && 123 !defined($mybinary{$fname})) {push @unknown, $fname} 124 } 125 } 126 if(scalar @unknown) { 127 my $uname = ""; 128 my $nunk = scalar @unknown; 129 print "++ $nunk unknown files\n"; 130 foreach $uname (@unknown) { 131 print " $uname\n"; 132 } 133 } 134 } 135 my $dname; 136 foreach $dname (keys (%dirdirs)) { 137 if(!defined($mydir{$fname})) { 138 print "++ $dname not in SUBDIRS\n"} 139 } 140 print " Done directory: $mypath $f files\n\n"; 141} 142 143 144sub processfile($$) { 145 my ($filename,$path) = @_; 146 my $fullname = "$path/$filename"; 147 print " Process file $fullname\n"; 148 $fileprint .= " Process file $fullname\n"; 149 my @lines = (); 150# 151# read file 152# 153# concatenate all lines ending with '\' 154# 155# then process any of the special strings 156# 157# we only need lines starting word = list 158 159 $line = ""; 160 $wantline = 0; 161 open (IN, "$fullname") || die "Cannot open $fullname"; 162 while (<IN>) { 163 if(/^\s*$/) {next} 164 if(/^[\#]$/) {next} 165 if(/^\s*([^_\s])+_([^_\s]+)\s+[=]/) { 166 $wantline = 1; 167 } 168 if(/\s*SUBDIRS\s+[=]/) { 169 $wantline = 1; 170 } 171 if(/\s*[A-Z]+SRC\s+[=]/) { 172 $wantline = 1; 173 } 174 if(/^(.*)[\\]\s*$/) { # has a continuation 175 if($wantline) {$line .= $1} 176 } 177 elsif($wantline) { # complete line - process it 178 $line .= $_; 179 push @lines, $line; 180 $line = ""; 181 $wantline = 0; 182 } 183 } 184 return @lines; 185} 186 187 188 189processdir(".",""); 190 191if ((-e "embassy") && (-d "embassy")) { 192 local *EDIR; 193 opendir(EDIR, "embassy"); 194 while ($file = readdir(EDIR)) { 195 if(($file =~ /^[.]/) && (-d $file)) {next} # skip .* hidden files 196 if($file =~ /^CVS$/) {next} # skip CVS directory 197 processdir(".","embassy/$file"); 198 } 199 closedir(EDIR); 200} 201