Give makewhatis an absolute path to make upgrading etc from single-user
[dragonfly.git] / share / man / man0 / xrs.pl
1 #!/usr/bin/perl
2 # Copyright (c) 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
3 # All rights reserved.
4 #
5 # xrs - detect unsorted cross references in section SEE ALSO
6 #
7 # Cross references in the SEE ALSO section should
8 # be sorted by section number, and then placed in alphabetical
9 # order and comma separated.  For example:
10 #
11 # ls(1),  ps(1),  group(5),  passwd(5).
12 #
13 # The last entry may be finished with a dot `.'
14 #
15 # or a source example:.
16 # .Sh SEE ALSO
17 # .Xr foo 1 ,
18 # .Xr bla 2 ,
19 # .Xr foobar 8
20 # .Sh HISTORY
21 #
22 # usage: xrs manpages ...
23 #
24 # $FreeBSD: src/share/man/man0/xrs.pl,v 1.5 1999/08/28 00:19:39 peter Exp $
25 # $DragonFly: src/share/man/man0/Attic/xrs.pl,v 1.2 2003/06/17 04:36:58 dillon Exp $
26
27 sub mysort {
28
29     local(@c) = split($",$a);
30     local(@d) = split($",$b);
31
32     local($ret) = ($c[2] <=> $d[2]);
33                 
34     return $ret if $ret;
35     return $c[1] cmp $d[1];
36 }
37
38 sub usage { die "usage: xrs manpages ...\n"; }
39
40 sub compare {
41     local(*a, *b) = @_;
42
43     return 1 if ($#a != $#b);
44
45     for($i = 0; $i <= $#a; $i++) {
46         return 1 if
47             $a[$i] ne $b[$i];
48     }
49
50     for ($i = 0; $i < $#a; $i++) {
51         return 1 if $a[$i] !~ /\s,\s*$/;
52     }
53
54     return 1 if $a[$#a] =~ /\s,\s*$/;
55     return 1 if $a[$#a] =~ /^.Xr\s+\S+\s+\S+\s+[^.\s]/;
56     return 0;
57 }
58
59 &usage if $#ARGV >= 0 && $ARGV[0] =~ /^-\?|h/;
60
61 while(<>) {
62     if (/^\.Sh\s/ && /"?SEE\s+ALSO"?/) {
63         $file = $ARGV;
64         @a = ();
65         while(<>) {
66             last if $file ne $ARGV;
67
68             next if /^\.\\"\s/; # " ignore comments
69             # next if m%^/[^/]+/%; # ignore absolute path names
70             if (!/^\.(Xr|Fn)\s/) {
71                 if (!/^\.(Sh|Rs|\\"|Pp|br)\s*/ && !/^\s*$/) {
72                     warn "Oops: $ARGV $_";
73                 }
74                 last;
75             }
76             tr/A-Z/a-z/;
77             push(@a, $_);
78         }
79         @b = sort mysort @a;
80         if (&compare(*a,*b)) {
81             print "$file\n";
82         }
83     }
84     last if eof();
85 }