home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- #
- # Build a whatis database.
- #
- $bs = sprintf("%c", 8);
-
- die "Usage: mkwhatis\n" unless ($#ARGV == -1);
-
- open(FILE, ">whatis") || die "Can't open whatis file\n";
- for ($i=1; $i<10; $i++)
- {
- if (-d "cat$i")
- {
- $section = $i;
- # Go through all man pages in the section.
- while (<cat$i.*.*>)
- {
- # Unzip it.
- open(PIPE, "gzip -dc <$_ |") || die "Can't run gzip\n";
-
- # Search for the NAME entry (Horrible way of handling
- # underlining).
- while (($_=<PIPE>) && (!/^\s*N.*A.*M.*E/)) {}
-
- # Now grab up until SYNOPSIS (lose underlines again).
- $syn = "";
- while ($_=<PIPE>)
- {
- chop;
- s/.$bs//g;
- s/^\s+//;
- if ((/^([^\s]*)/) &&
- (($1 eq "SYNOPSIS") || ($1 eq "DESCRIPTION")))
- {
- last;
- }
- $syn = $syn.$_." ";
- }
- close(PIPE);
-
- $_ = $syn;
- s/\s+/ /g;
- s/\s+$//;
-
- ($start, $rest) = split('-', $_, 2);
- $rest =~ s/- //;
- print "$start($section) -$rest\n";
- print FILE "$start($section) -$rest\n";
- }
- }
- }
- close(FILE);
- #system("sort whatis > whatistmp");
- #system("uniq whatistmp > whatis");
- #unlink("whatistmp");
-