| 1 | #! /bin/sh |
| 2 | # -*-perl-*- |
| 3 | |
| 4 | exec perl -x $0 "$@"; |
| 5 | |
| 6 | #! perl |
| 7 | |
| 8 | # --- The idea --- |
| 9 | # |
| 10 | # Each manual page contains lines of the form |
| 11 | # |
| 12 | # .\" @function |
| 13 | # |
| 14 | # for each function and macro documented in it. This program sifts through |
| 15 | # all of the `toplevel' manual pages and creates little manpages which |
| 16 | # include the main text for each of the functions. |
| 17 | # |
| 18 | # The file `links' contains a generated list of little link manpages. This |
| 19 | # list is used for tidying (on a `make clean'), installing (for `make |
| 20 | # install') and for pruning out old links when they're not needed any more. |
| 21 | |
| 22 | %top = (); |
| 23 | %so = (); |
| 24 | if (open SO, "links") { while (<SO>) { chomp; $so{$_} = -1; } } |
| 25 | if (open TOP, "toplevel") { while (<TOP>) { chomp; $top{$_} = -1; } } |
| 26 | |
| 27 | foreach $f (@ARGV) { |
| 28 | ($ext = $f) =~ s/^[^.]*\.//; |
| 29 | next unless $ext =~ /^\d/; |
| 30 | $sec = $&; |
| 31 | open FILE, $f or die "open($f): $!"; |
| 32 | $top = 0; |
| 33 | while (<FILE>) { |
| 34 | chomp; |
| 35 | next unless /^\.\\\"\s+\@/; |
| 36 | $top = 1; |
| 37 | $link = $'; |
| 38 | $full = "$link.$ext"; |
| 39 | next if $full eq $f; |
| 40 | open OUT, ">$full" or die "open(>$full): $!"; |
| 41 | print OUT ".so man$sec/$f\n"; |
| 42 | close OUT; |
| 43 | $so{$full}++; |
| 44 | } |
| 45 | $top{$f}++ if $top; |
| 46 | close FILE; |
| 47 | } |
| 48 | |
| 49 | $write = 0; |
| 50 | foreach $i (keys(%so)) { |
| 51 | next if $so{$i} == 0; |
| 52 | unlink $i if $so{$i} < 0; |
| 53 | $write = 1; |
| 54 | } |
| 55 | if ($write) { |
| 56 | open LINKS, ">links" or die "open(>links): $!"; |
| 57 | foreach $i (sort(keys(%so))) { |
| 58 | print LINKS "$i\n" if $so{$i} >= 0; |
| 59 | } |
| 60 | close LINKS; |
| 61 | } |
| 62 | |
| 63 | $write = 0; |
| 64 | foreach $i (keys(%top)) { |
| 65 | $write = 1 unless $top{$i} == 0; |
| 66 | } |
| 67 | if ($write) { |
| 68 | open TOP, ">toplevel" or die "open(>toplevel): $!"; |
| 69 | foreach $i (sort(keys(%top))) { |
| 70 | print TOP "$i\n" if $top{$i} >= 0; |
| 71 | } |
| 72 | close TOP; |
| 73 | } |