home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / linux / 22343 < prev    next >
Encoding:
Text File  |  1993-01-01  |  4.0 KB  |  157 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!uunet.ca!xenitec!mongrel!shrdlu!gdm
  3. From: gdm@shrdlu.kwnet.on.ca (Giles D Malet)
  4. Subject: Re: Makewhatis dies!
  5. References: <1hor0pINN20q@savoy.cc.williams.edu>
  6. Organization: 3.141592653589793238462643383279502884197169399
  7. Date: Wed, 30 Dec 1992 01:08:43 GMT
  8. Message-ID: <C01sIJ.ns2@shrdlu.kwnet.on.ca>
  9. Lines: 146
  10.  
  11. In article <1hor0pINN20q@savoy.cc.williams.edu> 93jay@williams.edu (Jonathan Young) writes:
  12. >
  13. >it chugged for a few minutes then reported several broken pipes... now
  14. >my whatis database appears to be gone.
  15.  
  16. Below is a rather hacked version of makewhatis - it will build the
  17. whatis file from anything it can find, be it compressed, uncompressed,
  18. an unformatted page or a preformatted one.
  19.  
  20. No warranties expressed or implied, & all that, but give it a go.
  21. It handles 99% of my man pages, and the ones it doesn't cause me either
  22. to fix the man page, of add yet another line to this script...
  23.  
  24. BTW - My man command also handles compressed unformatted pages - if yours
  25.     does not, remove the lines near the top of this script that compress
  26.     them.
  27.  
  28. -----------------cut----------------------
  29. #!/bin/sh
  30. #
  31. # makewhatis -- update the whatis database in the man directories.
  32. #
  33. # Copyright (c) 1991, John W. Eaton.
  34. #
  35. # You may distribute under the terms of the GNU General Public
  36. # License as specified in the README file that comes with the man 1.0
  37. # distribution.  
  38. #
  39. # John W. Eaton
  40. # jwe@che.utexas.edu
  41. # Department of Chemical Engineering
  42. # The University of Texas at Austin
  43. # Austin, Texas  78712
  44. #
  45. # Seriously hacked by gdm@shrdlu.kwnet.on.ca to handle compressed pages,
  46. # as well as many different input formats.
  47.  
  48. PATH=/bin:/usr/bin:/usr/local/bin
  49.  
  50. if [ $# = 0 ]
  51. then
  52.     echo "usage: makewhatis directory [...]"
  53.     exit 1
  54. fi
  55.  
  56. for dir in $*    # compress all files except .../man/.. files of form `.so something'
  57. do
  58.     find $dir/cat? -type f -name '*\.[^Z]' -exec compress {} \;
  59.     for file in `find $dir/man? -type f -name '*\.[^Z]'`
  60.     do
  61.         firstword=`awk 'NR == 1 {print $1}' < $file`
  62.         if [ X$firstword != X.so ]
  63.         then
  64.             compress $file
  65.         fi
  66.     done
  67.     find $dir -type f -exec chmod 444 {} \;
  68.     find $dir -type f -exec chown bin.bin {} \;
  69. done
  70.  
  71. for dir in $*
  72. do
  73.     for subdir in `find $dir/* -type d`
  74.     do
  75.         cd $subdir
  76.         for file in `find * -type f`
  77.         do (
  78.             if expr $file : '\(.*\.Z$\)' >/dev/null    # compressed ?
  79.             then
  80.                 catter="zcat"
  81.             else
  82.                 catter="cat"
  83.             fi
  84.  
  85.             if [ `echo $subdir | sed "s;^$dir/(...).*;\1;"` = "cat" ]
  86.             then
  87.                 sect=`echo $file | sed 's/^[^\.]*\.(.).*/\1/'`
  88.                 echo ".TH foo $sect"
  89.                 $catter $file |
  90.                 sed -ne '
  91.                     s/_//g
  92.                     s/.//g
  93.                     /^$/d
  94.                     s/^[     ]*NAME/.SH NAME/
  95.                     s/^[     ]*SYNOPSIS/.SH SYNOPSIS/
  96.                     /^\.SH NAME/,/^\.SH/p'
  97.             else    # man #
  98.                 $catter $file |
  99.                 sed -ne '
  100.                     s/^\.Dt/\.TH/
  101.                     s/^\.Sh/\.SH/
  102.                     /^\.Nm/d
  103.                     /^\.Tn/d
  104.                     s/^\.Nd//
  105.                     s/\\[   ]*\-/-/
  106.                     s/^.PP.*$//
  107.                     s/\\(em//
  108.                     s/\\fI//
  109.                     s/\\fB//
  110.                     s/\\fR//
  111.                     s/^\\\*//
  112.                     /^$/d
  113.                     /^\.br.*$/d
  114.                     /^\.TH.*$/p
  115.                     /^\.SH[         ]*NAME/,/^\.SH/p'
  116.             fi
  117.            ) | # tee /tmp/chk.out | # for testing
  118.             awk 'BEGIN {insh = 0} {
  119.                 if ($1 == ".TH") {
  120.                     namesect = sprintf("%s (%s)", name, $3)
  121.                 } else if ($1 == ".SH" && insh == 0) {
  122.                     insh = 1
  123.                 } else if ($1 != ".SH" && insh == 1) {
  124.                     start = 1
  125.                     if (NF > 1) {
  126.                         if ($1 == name) {
  127.                             start = 2
  128.                             if ($2 == "-"  &&  NF > 2) start = 3
  129.                         }
  130.                     }
  131.                     printf("%-20.20s", namesect)
  132.                     printf(" - ")
  133.                     for (j = start; j <= NF ; j++) {
  134.                         if ($j != "-")
  135.                             printf("%s ", $j)
  136.                         else
  137.                             printf(": ")
  138.                     }
  139.                     printf("\n")
  140.                 }
  141.             }' name=`expr $file : '\(.*\)\.[0-9]'`
  142.         done
  143.     done | sort > $dir/whatis.new
  144.     mv -f $dir/whatis $dir/whatis.old
  145.     mv -f $dir/whatis.new $dir/whatis
  146. done
  147.  
  148. exit 0
  149. -----------------cut----------------------
  150.  
  151. Tell me how it fares !
  152. gdm
  153.  
  154. -- 
  155. Giles D Malet                                             gdm@shrdlu.kwnet.on.ca
  156. Waterloo, Ont, Canada       +1 519 725 5726       gdmalet@descartes.uwaterloo.ca
  157.