1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
#!/usr/bin/perl -w
#
# scatman - find turds in mantrees
# tchrist@perl.com
use strict;
my ($Manpath, $Debug);
parse_opts();
MANTREE:
for my $tree (split /:/, $Manpath) {
debug("chdir($tree)");
chdir($tree) || die "cannot cd to main tree $tree: $!";
# XXX: doesn't handles openbsd recursive mandirs yet
MANDIR:
#for my $mandir ( grep { -d } <{man,cat}*> ) {
my @mandirs = grep { -d } <{cat,man}*>;
while (@mandirs) {
my $mandir = shift @mandirs;
my $was_catted = $mandir =~ /^cat/;
debug("chdir($tree/$mandir)");
chdir("$tree/$mandir") || die "cannot cd to subdir $tree/$mandir: $!";
my($dirext) = ($mandir =~ /^(?:cat|man)(.*)/);
my($ext, @pages);
local *MANDIR;
unless (opendir(MANDIR, ".")) {
die "$0: can't opendir . while in $tree/$mandir: $!\n";
}
MANPAGE:
while (my $file = readdir(MANDIR)) {
next MANPAGE if $file =~ /^\.\.?$/;
my $path = "$tree/$mandir/$file";
if (-l $file) {
my $target = readlink($file);
debug("readlink on $path -> $target");
unless (-f $target && -r $target) {
print "$path: bad symlink ($target)\n";
}
next MANPAGE;
}
if (-d $file) {
push @mandirs, "$mandir/$file";
next;
}
unless (-f $file) {
print "$path: not a plain file\n";
next MANPAGE;
}
unless ($file =~ /\./) {
print "$path: doesn't smell like a manpage to me\n";
next MANPAGE;
}
unless ($file =~ /\.${dirext}\S*(\.(gz|Z))?$/
# get a real man dang you!
|| ($was_catted && $file =~ /\.0/)
)
{
print "$path: strange extension for this directory\n";
}
my $openspec = ($file =~ /\.(gz|Z)$/)
? "gzip -dc < $file |"
: "< $file";
local *FH;
debug("open $openspec");
unless (open(FH, $openspec)) {
warn "can't open $openspec: $!\n";
next;
}
my($saw_TH, $saw_DOT, $over_struck);
local $_;
MANLINE:
while (<FH>) {
$saw_DOT += /^['.]/;
$saw_TH += m{
^ [.'] # ' unlikely but possible
\s* # optional white space
(?:
TH # -man version
| Dt # -mandoc version
)
\b
}x;
if (/^['.]\s*so\s+(\S+)/) {
my $link = $1;
my $sofile = $link =~ m#^/#
? $link
: "$tree/$link"; # not $mandir!
debug("$path: so's to $sofile");
unless (-f $sofile && -r $sofile) {
print "$path: bad solink: $link\n";
}
close FH;
next MANPAGE;
}
if (!defined $over_struck) {
$over_struck++ if /(.)[\b]\1/;
}
close FH,last if $saw_DOT && $saw_TH;
}
close FH;
if ($saw_DOT) {
unless ($saw_TH) {
print "$path: missing title macro\n";
}
}
else {
if ($over_struck) {
my $wish = "$tree/cat$dirext/$file";
print "$path: this catpage should be in $wish"
unless $path eq $wish;
} else {
print "$path: doesn't look like nroff, maybe ",
`file $path 2>&1` =~ /: (.*)/, "\n";
}
}
}
}
}
sub debug {
print "[ @_ ]\n" if $Debug;
}
sub usage {
print STDERR "@_\n" if @_;
die "Usage: $0 [ -h ] [ -d ] [ [ -M ] [ manpath ] ]\n";
}
sub run_help {
my $pager;
unless ($pager = $ENV{PAGER}) {
require Config;
# lint happiness. blech.
$pager = $Config::Config{'pager'} || $Config::Config{'pager'};
}
$pager = "/bin/cat" unless has_cmd($pager);
if (has_cmd("pod2man") && has_cmd("nroff") ) {
{ exec("pod2man $0 | nroff -man | $pager") } # lint happiness
warn "exec of pod2man | nroff | $pager failed: $!";
}
if (has_cmd("pod2text")) {
{ exec("pod2text $0 | $pager") } # lint happiness
warn "exec of pod2text | $pager failed: $!";
}
# sucks to be you!
if (eval q{ require Pod::Text; 1; }) {
open (STDOUT, "| $pager") || die "no pager $pager: $!";
# this forces a wait on child if needed
sub END { close(STDOUT) || die "cannot close STDOUT: $!" }
Pod::Text::pod2text($0);
exit 0;
}
# it REALLY REALLY REALLY sucks to be you!
open 0 or die "$0: cannot open myself: $!";
$/ = '';
while (<0>) {
last if /__(END|DATA)__/; # must be careful here
}
print <0>;
exit;
}
sub has_cmd {
my $cmd = shift;
for (split(/:/, $ENV{PATH})) {
my $path = "$_/$cmd";
return $path if -f $path && -x _;
}
return;
}
sub parse_opts {
ARG: while (@ARGV && $ARGV[0] =~ s/^-(?=.)//) {
OPT: for (shift @ARGV) { # getopts is for wimps
m/^$/ && do { next ARG; };
m/^-$/ && do { last ARG; };
s/^d// && do { $Debug++; redo OPT; };
s/^M(.*)// && do { $Manpath = $1 || shift @ARGV; next ARG; };
m/^(h|-help)?$/ # stupid fsf broken crappy excuse for real manpages
&& do { run_help(); exit; };
usage("unknown option: -$_");
}
}
if (@ARGV) {
usage("Manpath set, but arguments remaining") if $Manpath;
usage("Too many arguments") if @ARGV > 1;
$Manpath = $ARGV[0];
}
else {
$Manpath = '/usr/share/man';
}
}
__END__
=head1 NAME
scatman - find turds in mantrees
=head1 SYNOPSIS
B<scatman> S<[ B<-h> ]> S<[ B<-d> ]> S<[ [ B<-M> ] [ I<manpath> ] ]>
=head1 DESCRIPTION
The B<scatman> program locates things in man directories that
shouldn't be there. It looks for stray files, catpage installed
where manpage belong, non-troff files, troff files without proper
title macros, wrong symbolic links, wrong C<.so> links, manpages
installed with odd extensions, and unreadable files.
The B<-d> flag adds debugging.
The B<-M> I<manpath> flag is there for compatibility with
other manly programs.
The B<-h> flag prints this manpage and exit. You cannot lose
this manpage. No more whingeing!
=head1 SEE ALSO
man(1), man(7), mandoc(7), cfman(8), noman(8)
=head1 RESTRICTIONS
This program has only been tested on the Redhat operating system.
=head1 AUTHOR
Tom Christiansen <tchrist@perl.com>
=head1 HISTORY
Version 1: 24 October 1999
|