| 1 | #!/usr/bin/perl |
| 2 | # -*- perl -*- |
| 3 | |
| 4 | # Copyright (C) 2001 |
| 5 | # Free Software Foundation |
| 6 | # |
| 7 | # This file is part of the libiberty library. |
| 8 | # Libiberty is free software; you can redistribute it and/or |
| 9 | # modify it under the terms of the GNU Library General Public |
| 10 | # License as published by the Free Software Foundation; either |
| 11 | # version 2 of the License, or (at your option) any later version. |
| 12 | # |
| 13 | # Libiberty is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | # Library General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU Library General Public |
| 19 | # License along with libiberty; see the file COPYING.LIB. If not, |
| 20 | # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 21 | # Boston, MA 02111-1307, USA. |
| 22 | # |
| 23 | # Originally written by DJ Delorie <dj@redhat.com> |
| 24 | |
| 25 | |
| 26 | # This is a trivial script which checks the lists of C and O files in |
| 27 | # the Makefile for consistency. |
| 28 | |
| 29 | $mode = shift; |
| 30 | $srcdir = "."; |
| 31 | |
| 32 | if ($mode eq "-s") { |
| 33 | $srcdir = shift; |
| 34 | $mode = shift; |
| 35 | } |
| 36 | |
| 37 | &missing() if $mode eq "missing"; |
| 38 | &undoc() if $mode eq "undoc"; |
| 39 | |
| 40 | exit 0; |
| 41 | |
| 42 | format STDOUT = |
| 43 | ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~ |
| 44 | $out |
| 45 | ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ |
| 46 | $out |
| 47 | . |
| 48 | |
| 49 | ###################################################################### |
| 50 | |
| 51 | sub missing { |
| 52 | |
| 53 | opendir(S, $srcdir); |
| 54 | while ($f = readdir S) { |
| 55 | $have{$f} = 1; |
| 56 | } |
| 57 | closedir(S); |
| 58 | opendir(S, "."); |
| 59 | while ($f = readdir S) { |
| 60 | $have{$f} = 1; |
| 61 | } |
| 62 | closedir(S); |
| 63 | |
| 64 | for $a (@ARGV) { |
| 65 | $listed{$a} = 1; |
| 66 | $have{$a} = 0; |
| 67 | } |
| 68 | |
| 69 | for $f (sort keys %have) { |
| 70 | next unless $have{$f}; |
| 71 | if ($f =~ /\.c$/) { |
| 72 | print "S $f\n"; |
| 73 | } |
| 74 | } |
| 75 | for $f (sort keys %listed) { |
| 76 | if ($f =~ /(.*)\.c$/) { |
| 77 | $base = $1; |
| 78 | if (! $listed{"$base.o"}) { |
| 79 | print "O $f\n"; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | ###################################################################### |
| 86 | |
| 87 | sub undoc { |
| 88 | |
| 89 | opendir(S, $srcdir); |
| 90 | while ($file = readdir S) { |
| 91 | if ($file =~ /\.texi$/) { |
| 92 | open(T, "$srcdir/$file"); |
| 93 | while (<T>) { |
| 94 | if (/^\@deftype[^\(]* ([^\s\(]+) *\(/) { |
| 95 | $documented{$1} = 1; |
| 96 | } |
| 97 | } |
| 98 | close(T); |
| 99 | } |
| 100 | if ($file =~ /\.c$/) { |
| 101 | open(C, "$srcdir/$file"); |
| 102 | while (<C>) { |
| 103 | if (/\@undocumented (\S+)/) { |
| 104 | $documented{$1} = 1; |
| 105 | } |
| 106 | if (/^static /) { |
| 107 | if (! /[\(;]/) { |
| 108 | s/[\r\n]+$/ /; |
| 109 | $_ .= <C>; |
| 110 | } |
| 111 | while ($_ =~ /\([^\)]*$/) { |
| 112 | s/[\r\n]+$/ /; |
| 113 | $_ .= <C>; |
| 114 | } |
| 115 | } |
| 116 | s/ VPARAMS([ \(])/$1/; |
| 117 | s/PREFIX\(([^\)]*)\)/byte_$1/; |
| 118 | if (/^static [^\(]* ([^\s\(]+) *\(.*\)$/) { |
| 119 | $documented{$1} = 1; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | closedir(D); |
| 125 | |
| 126 | # $out = join(' ', sort keys %documented); |
| 127 | # write; |
| 128 | # print "\n"; |
| 129 | |
| 130 | system "etags $srcdir/*.c $srcdir/../include/*.h"; |
| 131 | open(TAGS, "TAGS"); |
| 132 | while (<TAGS>) { |
| 133 | s/[\r\n]+$//; |
| 134 | if (/^\014$/) { |
| 135 | $filename = <TAGS>; |
| 136 | $filename =~ s/[\r\n]+$//; |
| 137 | $filename =~ s/,\d+$//; |
| 138 | $filename =~ s@.*[/\\]@@; |
| 139 | next; |
| 140 | } |
| 141 | if ($filename =~ /\.c$/ ) { |
| 142 | next unless /^[_a-zA-Z]/; |
| 143 | } else { |
| 144 | next unless /^\# *define/; |
| 145 | s/\# *define *//; |
| 146 | } |
| 147 | next if $filename =~ /mpw\.c/; |
| 148 | |
| 149 | s/ VPARAMS//; |
| 150 | s/ *\177.*//; |
| 151 | s/,$//; |
| 152 | s/DEFUN\(//; |
| 153 | s/\(//; |
| 154 | |
| 155 | next if /^static /; |
| 156 | next if /\s/; |
| 157 | next if /^_/; |
| 158 | next if $documented{$_}; |
| 159 | next if /_H_?$/; |
| 160 | |
| 161 | if ($seen_in{$_} ne $filename) { |
| 162 | $saw{$_} ++; |
| 163 | } |
| 164 | $seen_in{$_} = $filename; |
| 165 | } |
| 166 | |
| 167 | for $k (keys %saw) { |
| 168 | delete $saw{$k} if $saw{$k} > 1; |
| 169 | } |
| 170 | |
| 171 | for $k (sort keys %saw) { |
| 172 | $fromfile{$seen_in{$k}} .= " " if $fromfile{$seen_in{$k}}; |
| 173 | $fromfile{$seen_in{$k}} .= $k; |
| 174 | } |
| 175 | |
| 176 | for $f (sort keys %fromfile) { |
| 177 | $out = "$f: $fromfile{$f}"; |
| 178 | write; |
| 179 | } |
| 180 | } |