home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / editor / man / makewhat.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1994-01-23  |  3KB  |  81 lines

  1. #!/bin/sh
  2. #
  3. # makewhatis -- update the whatis database in the man directories.
  4. #
  5. # Copyright (c) 1990, 1991, John W. Eaton.
  6. #
  7. # You may distribute under the terms of the GNU General Public
  8. # License as specified in the README file that comes with the man
  9. # distribution.  
  10. #
  11. # John W. Eaton
  12. # jwe@che.utexas.edu
  13. # Department of Chemical Engineering
  14. # The University of Texas at Austin
  15. # Austin, Texas  78712
  16.  
  17. #PATH=/bin:/usr/local/bin:/usr/ucb:/usr/bin
  18.  
  19. if [ $# = 0 ]
  20. then
  21.     echo "usage: makewhatis directory [...]"
  22.     exit 1
  23. fi
  24.  
  25. for dir in $*
  26. do
  27.     cd $dir
  28.     for subdir in man*
  29.     do
  30.         if [ -d $subdir ]
  31.         then
  32.         cd $subdir
  33.             for f in `find . -name '*' -print`
  34.             do
  35.                 sed -n '/^\.TH.*$/p
  36.                         /^\.SH[         ]*NAME/,/^\.SH/p' $f |\
  37.                 sed -e 's/\\[   ]*\-/-/
  38.                         s/^.PP.*$//
  39.                         s/\\(em//
  40.                         s/\\fI//
  41.                         s/\\fR//' |\
  42.                 gawk 'BEGIN {insh = 0} {
  43.                      if ($1 == ".TH")
  44.                        sect = $3
  45.                      else if ($1 == ".SH" && insh == 1) {
  46.                        if (i > 0 && name != NULL) {
  47.                          namesect = sprintf("%s (%s)", name, sect)
  48.                          printf("%-20.20s", namesect)
  49.                          printf(" - ")
  50.                          for (j = 0; j < i-1; j++)
  51.                            printf("%s ", desc[j])
  52.                          printf("%s\n", desc[i-1])
  53.                        }
  54.                      } else if ($1 == ".SH" && insh == 0) {
  55.                        insh = 1
  56.                        count = 0
  57.                        i = 0
  58.                      } else if (insh == 1) {
  59.                        count++
  60.                        if (count == 1 && NF > 2) {
  61.                          start = 2
  62.                          if ($2 == "-") start = 3
  63.                          if (NF > start + 1)
  64.                            for (j = start; j <= NF; j++)
  65.                              desc[i++] = $j
  66.                            name = $1
  67.                        } else {
  68.                          for (j = 1; j <= NF; j++)
  69.                            desc[i++] = $j
  70.                        }
  71.                      }
  72.                 }'
  73.             done
  74.             cd ..
  75.         fi
  76.     done | sort | cut -c -80 > $dir/whatis.db.tmp
  77.     mv $dir/whatis.db.tmp $dir/whatis
  78. done
  79.  
  80. exit
  81.