home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / languages / progs / bin / manpages / mkwhatis next >
Encoding:
Text File  |  1994-02-05  |  1.1 KB  |  56 lines

  1. #!/usr/local/bin/perl
  2. #
  3. # Build a whatis database.
  4. #
  5. $bs = sprintf("%c", 8);
  6.  
  7. die "Usage: mkwhatis\n" unless ($#ARGV == -1);
  8.  
  9. open(FILE, ">whatis") || die "Can't open whatis file\n";
  10. for ($i=1; $i<10; $i++)
  11. {
  12.     if (-d "cat$i")
  13.     {
  14.         $section = $i;
  15.         # Go through all man pages in the section.
  16.         while (<cat$i.*.*>)
  17.         {
  18.             # Unzip it.
  19.             open(PIPE, "gzip -dc <$_ |") || die "Can't run gzip\n";
  20.  
  21.             # Search for the NAME entry (Horrible way of handling
  22.             # underlining).
  23.             while (($_=<PIPE>) && (!/^\s*N.*A.*M.*E/)) {}
  24.  
  25.             # Now grab up until SYNOPSIS (lose underlines again).
  26.             $syn = "";
  27.             while ($_=<PIPE>)
  28.             { 
  29.                 chop;
  30.                 s/.$bs//g;
  31.                 s/^\s+//;
  32.                 if ((/^([^\s]*)/) &&
  33.                     (($1 eq "SYNOPSIS") || ($1 eq "DESCRIPTION")))
  34.                 {
  35.                     last;
  36.                 }
  37.                 $syn = $syn.$_." ";
  38.             }
  39.             close(PIPE);
  40.  
  41.             $_ = $syn;
  42.             s/\s+/ /g;
  43.             s/\s+$//;
  44.  
  45.             ($start, $rest) = split('-', $_, 2);
  46.             $rest =~ s/- //;
  47.             print "$start($section) -$rest\n";
  48.             print FILE "$start($section) -$rest\n";
  49.         }
  50.     }
  51. }
  52. close(FILE);
  53. #system("sort whatis > whatistmp");
  54. #system("uniq whatistmp > whatis");
  55. #unlink("whatistmp");
  56.