home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!uunet.ca!xenitec!mongrel!shrdlu!gdm
- From: gdm@shrdlu.kwnet.on.ca (Giles D Malet)
- Subject: Re: Makewhatis dies!
- References: <1hor0pINN20q@savoy.cc.williams.edu>
- Organization: 3.141592653589793238462643383279502884197169399
- Date: Wed, 30 Dec 1992 01:08:43 GMT
- Message-ID: <C01sIJ.ns2@shrdlu.kwnet.on.ca>
- Lines: 146
-
- In article <1hor0pINN20q@savoy.cc.williams.edu> 93jay@williams.edu (Jonathan Young) writes:
- >
- >it chugged for a few minutes then reported several broken pipes... now
- >my whatis database appears to be gone.
-
- Below is a rather hacked version of makewhatis - it will build the
- whatis file from anything it can find, be it compressed, uncompressed,
- an unformatted page or a preformatted one.
-
- No warranties expressed or implied, & all that, but give it a go.
- It handles 99% of my man pages, and the ones it doesn't cause me either
- to fix the man page, of add yet another line to this script...
-
- BTW - My man command also handles compressed unformatted pages - if yours
- does not, remove the lines near the top of this script that compress
- them.
-
- -----------------cut----------------------
- #!/bin/sh
- #
- # makewhatis -- update the whatis database in the man directories.
- #
- # Copyright (c) 1991, John W. Eaton.
- #
- # You may distribute under the terms of the GNU General Public
- # License as specified in the README file that comes with the man 1.0
- # distribution.
- #
- # John W. Eaton
- # jwe@che.utexas.edu
- # Department of Chemical Engineering
- # The University of Texas at Austin
- # Austin, Texas 78712
- #
- # Seriously hacked by gdm@shrdlu.kwnet.on.ca to handle compressed pages,
- # as well as many different input formats.
-
- PATH=/bin:/usr/bin:/usr/local/bin
-
- if [ $# = 0 ]
- then
- echo "usage: makewhatis directory [...]"
- exit 1
- fi
-
- for dir in $* # compress all files except .../man/.. files of form `.so something'
- do
- find $dir/cat? -type f -name '*\.[^Z]' -exec compress {} \;
- for file in `find $dir/man? -type f -name '*\.[^Z]'`
- do
- firstword=`awk 'NR == 1 {print $1}' < $file`
- if [ X$firstword != X.so ]
- then
- compress $file
- fi
- done
- find $dir -type f -exec chmod 444 {} \;
- find $dir -type f -exec chown bin.bin {} \;
- done
-
- for dir in $*
- do
- for subdir in `find $dir/* -type d`
- do
- cd $subdir
- for file in `find * -type f`
- do (
- if expr $file : '\(.*\.Z$\)' >/dev/null # compressed ?
- then
- catter="zcat"
- else
- catter="cat"
- fi
-
- if [ `echo $subdir | sed "s;^$dir/(...).*;\1;"` = "cat" ]
- then
- sect=`echo $file | sed 's/^[^\.]*\.(.).*/\1/'`
- echo ".TH foo $sect"
- $catter $file |
- sed -ne '
- s/_//g
- s/.//g
- /^$/d
- s/^[ ]*NAME/.SH NAME/
- s/^[ ]*SYNOPSIS/.SH SYNOPSIS/
- /^\.SH NAME/,/^\.SH/p'
- else # man #
- $catter $file |
- sed -ne '
- s/^\.Dt/\.TH/
- s/^\.Sh/\.SH/
- /^\.Nm/d
- /^\.Tn/d
- s/^\.Nd//
- s/\\[ ]*\-/-/
- s/^.PP.*$//
- s/\\(em//
- s/\\fI//
- s/\\fB//
- s/\\fR//
- s/^\\\*//
- /^$/d
- /^\.br.*$/d
- /^\.TH.*$/p
- /^\.SH[ ]*NAME/,/^\.SH/p'
- fi
- ) | # tee /tmp/chk.out | # for testing
- awk 'BEGIN {insh = 0} {
- if ($1 == ".TH") {
- namesect = sprintf("%s (%s)", name, $3)
- } else if ($1 == ".SH" && insh == 0) {
- insh = 1
- } else if ($1 != ".SH" && insh == 1) {
- start = 1
- if (NF > 1) {
- if ($1 == name) {
- start = 2
- if ($2 == "-" && NF > 2) start = 3
- }
- }
- printf("%-20.20s", namesect)
- printf(" - ")
- for (j = start; j <= NF ; j++) {
- if ($j != "-")
- printf("%s ", $j)
- else
- printf(": ")
- }
- printf("\n")
- }
- }' name=`expr $file : '\(.*\)\.[0-9]'`
- done
- done | sort > $dir/whatis.new
- mv -f $dir/whatis $dir/whatis.old
- mv -f $dir/whatis.new $dir/whatis
- done
-
- exit 0
- -----------------cut----------------------
-
- Tell me how it fares !
- gdm
-
- --
- Giles D Malet gdm@shrdlu.kwnet.on.ca
- Waterloo, Ont, Canada +1 519 725 5726 gdmalet@descartes.uwaterloo.ca
-