chiark / gitweb /
Perl script to make `.so' links for all appropriate mLib functions.
authormdw <mdw>
Tue, 6 Jul 1999 19:14:42 +0000 (19:14 +0000)
committermdw <mdw>
Tue, 6 Jul 1999 19:14:42 +0000 (19:14 +0000)
man/mksofiles [new file with mode: 0755]

diff --git a/man/mksofiles b/man/mksofiles
new file mode 100755 (executable)
index 0000000..f5b28e8
--- /dev/null
@@ -0,0 +1,73 @@
+#! /bin/sh
+# -*-perl-*-
+
+exec perl -x $0 "$@";
+  
+#! perl
+
+# --- The idea ---
+#
+# Each manual page contains lines of the form
+#
+#   .\" @function
+#
+# for each function and macro documented in it.  This program sifts through
+# all of the `toplevel' manual pages and creates little manpages which
+# include the main text for each of the functions.
+#
+# The file `links' contains a generated list of little link manpages.  This
+# list is used for tidying (on a `make clean'), installing (for `make
+# install') and for pruning out old links when they're not needed any more.
+
+%top = ();
+%so = ();
+if (open SO, "links") { while (<SO>) { chomp; $so{$_} = -1; } }
+if (open TOP, "toplevel") { while (<TOP>) { chomp; $top{$_} = -1; } }
+
+foreach $f (@ARGV) {
+  ($ext = $f) =~ s/^[^.]*\.//;
+  next unless $ext =~ /^\d/;
+  $sec = $&;
+  open FILE, $f or die "open($f): $!";
+  $top = 0;
+  while (<FILE>) {
+    chomp;
+    next unless /^\.\\\"\s+\@/;
+    $top = 1;
+    $link = $';
+    $full = "$link.$ext";
+    next if $full eq $f;
+    open OUT, ">$full" or die "open(>$full): $!";
+    print OUT ".so man$sec/$f\n";
+    close OUT;
+    $so{$full}++;
+  }
+  $top{$f}++ if $top;
+  close FILE;
+}
+
+$write = 0;
+foreach $i (keys(%so)) {
+  next if $so{$i} == 0;
+  unlink $i if $so{$i} < 0;
+  $write = 1;
+}
+if ($write) {
+  open LINKS, ">links" or die "open(>links): $!";
+  foreach $i (sort(keys(%so))) {
+    print LINKS "$i\n" if $so{$i} >= 0;
+  }
+  close LINKS;
+}
+
+$write = 0;
+foreach $i (keys(%top)) {
+  $write = 1 unless $top{$i} == 0;
+}
+if ($write) {
+  open TOP, ">toplevel" or die "open(>toplevel): $!";
+  foreach $i (sort(keys(%top))) {
+    print TOP "$i\n" if $top{$i} >= 0;
+  }
+  close TOP;
+}