1996-12-30 15:58:53 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Copyright (c) 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
|
1997-09-29 14:41:35 +02:00
|
|
|
# All rights reserved.
|
1996-12-30 15:58:53 +01:00
|
|
|
#
|
|
|
|
# xrs - detect unsorted cross references in section SEE ALSO
|
|
|
|
#
|
|
|
|
# Cross references in the SEE ALSO section should
|
|
|
|
# be sorted by section number, and then placed in alphabetical
|
|
|
|
# order and comma separated. For example:
|
|
|
|
#
|
|
|
|
# ls(1), ps(1), group(5), passwd(5).
|
|
|
|
#
|
|
|
|
# The last entry may be finished with a dot `.'
|
|
|
|
#
|
|
|
|
# or a source example:.
|
|
|
|
# .Sh SEE ALSO
|
|
|
|
# .Xr foo 1 ,
|
|
|
|
# .Xr bla 2 ,
|
|
|
|
# .Xr foobar 8
|
|
|
|
# .Sh HISTORY
|
|
|
|
#
|
|
|
|
# usage: xrs manpages ...
|
|
|
|
#
|
1997-02-22 14:26:29 +01:00
|
|
|
# $Id$
|
1996-12-30 15:58:53 +01:00
|
|
|
|
|
|
|
sub mysort {
|
|
|
|
|
|
|
|
local(@c) = split($",$a);
|
|
|
|
local(@d) = split($",$b);
|
|
|
|
|
|
|
|
local($ret) = ($c[2] <=> $d[2]);
|
|
|
|
|
|
|
|
return $ret if $ret;
|
|
|
|
return $c[1] cmp $d[1];
|
|
|
|
}
|
|
|
|
|
1997-09-29 14:41:35 +02:00
|
|
|
sub usage { die "usage: xrs manpages ...\n"; }
|
|
|
|
|
1996-12-30 15:58:53 +01:00
|
|
|
sub compare {
|
|
|
|
local(*a, *b) = @_;
|
|
|
|
|
|
|
|
return 1 if ($#a != $#b);
|
|
|
|
|
|
|
|
for($i = 0; $i <= $#a; $i++) {
|
|
|
|
return 1 if
|
|
|
|
$a[$i] ne $b[$i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($i = 0; $i < $#a; $i++) {
|
|
|
|
return 1 if $a[$i] !~ /\s,\s*$/;
|
|
|
|
}
|
1997-09-29 14:41:35 +02:00
|
|
|
|
1996-12-30 15:58:53 +01:00
|
|
|
return 1 if $a[$#a] =~ /\s,\s*$/;
|
1997-09-29 14:41:35 +02:00
|
|
|
return 1 if $a[$#a] =~ /^.Xr\s+\S+\s+\S+\s+[^.\s]/;
|
1996-12-30 15:58:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-09-29 14:41:35 +02:00
|
|
|
&usage if $#ARGV >= 0 && $ARGV[0] =~ /^-\?|h/;
|
1996-12-30 15:58:53 +01:00
|
|
|
|
|
|
|
while(<>) {
|
1997-09-29 14:41:35 +02:00
|
|
|
if (/^\.Sh\s/ && /"?SEE\s+ALSO"?/) {
|
1996-12-30 15:58:53 +01:00
|
|
|
$file = $ARGV;
|
|
|
|
@a = ();
|
|
|
|
while(<>) {
|
1997-09-29 14:41:35 +02:00
|
|
|
last if $file ne $ARGV;
|
|
|
|
|
|
|
|
next if /^\.\\"\s/; # " ignore comments
|
|
|
|
# next if m%^/[^/]+/%; # ignore absolute path names
|
1996-12-30 15:58:53 +01:00
|
|
|
if (!/^\.(Xr|Fn)\s/) {
|
|
|
|
if (!/^\.(Sh|Rs|\\"|Pp|br)\s*/ && !/^\s*$/) {
|
|
|
|
warn "Oops: $ARGV $_";
|
|
|
|
}
|
|
|
|
last;
|
|
|
|
}
|
1997-09-29 14:41:35 +02:00
|
|
|
tr/A-Z/a-z/;
|
1996-12-30 15:58:53 +01:00
|
|
|
push(@a, $_);
|
|
|
|
}
|
|
|
|
@b = sort mysort @a;
|
|
|
|
if (&compare(*a,*b)) {
|
|
|
|
print "$file\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last if eof();
|
|
|
|
}
|