home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / armlinux / alpha / PARTITIONS / USR_GZ / usr / lib / makewhatis < prev    next >
Encoding:
Text File  |  1995-06-08  |  6.0 KB  |  157 lines

  1. #!/bin/sh
  2. # makewhatis: create the whatis database
  3. # Created: Sun Jun 14 10:49:37 1992
  4. # Revised: Sat Jan  8 14:12:37 1994 by faith@cs.unc.edu
  5. # Copyright 1992, 1993, 1994 Rickard E. Faith (faith@cs.unc.edu)
  6. # May be freely distributed and modified as long as copyright is retained.
  7. #
  8. # Wed Dec 23 13:27:50 1992: Rik Faith (faith@cs.unc.edu) applied changes
  9. # based on Mitchum DSouza (mitchum.dsouza@mrc-apu.cam.ac.uk) cat patches.
  10. # Also, cleaned up code and make it work with NET-2 doc pages.
  11. #
  12. # makewhatis-1.4: aeb 940802, 941007
  13. # Fixed so that the -c option works correctly for the cat pages
  14. # on my machine. Fix for -u by Nan Zou (nan@ksu.ksu.edu).
  15. #
  16.  
  17. PATH=/usr/bin:/bin
  18.  
  19. for name in $*
  20. do
  21. case $name in
  22.     -c) pages=cat;
  23.         filter="col -bx";
  24.         continue;;
  25.     -u) update="-ctime 0";
  26.         continue;;
  27.     -w) manpath=`man --path | tr : '\040'`
  28.     continue;;
  29.     -*) echo "Usage: makewhatis [-c] [-u] [-w] [manpath]";
  30.         echo "       -c: build database from cat pages";
  31.         echo "       -u: update database with new pages";
  32.     echo "       -w: use manpath obtained from \`man --path\`";
  33.         echo "       [manpath]: man directories (default: /usr/man)";
  34.         exit;;
  35.      *) if [ -d $name ]
  36.         then
  37.             manpath="$manpath $name"
  38.         else
  39.             echo "No such directory $name"
  40.             exit
  41.         fi;;
  42. esac
  43. done
  44.  
  45. pages=${pages-man}
  46. export pages
  47. manpath=${manpath-/usr/man}
  48. filter=${filter-cat}
  49.  
  50. for mandir in $manpath
  51. do
  52.     cd $mandir
  53.     
  54.     for i in 1 2 3 4 5 6 7 8 9 n l
  55.     do
  56.         if [ -d ${pages}$i ]
  57.         then
  58.             cd ${pages}$i
  59.             section=$i
  60.             export section
  61.             for j in `find . -name '*' ${update} -print`
  62.             do
  63.         case $j in
  64.         *.Z|*.z|*.gz)
  65.                     Cat=zcat
  66.             ;;
  67.         *)
  68.                     Cat=cat
  69.             ;;
  70.         esac
  71.                 ${Cat} ${j} | ${filter} |\
  72.                 gawk 'BEGIN {after = 0; insh = 0;
  73.                             pages = ENVIRON["pages"];
  74.                             section = ENVIRON["section"]} {
  75.                     if (($1 ~ /^\.[Ss][Hh]/ && $2 ~ /[Nn][Aa][Mm][Ee]/) ||
  76.                         (pages == "cat" && $1 ~ /^NAME/)) {
  77.                         if (!insh)
  78.                             insh = 1
  79.                         else {
  80.                             printf "\n"
  81.                             exit
  82.                         }
  83.                     } else if (insh) {
  84.                         if ($1 ~ /^\.[Ss][HhYS]/ ||
  85.                 (pages == "cat" &&
  86.                 ($1 ~ /^S[yYeE]/ || $1 ~ /^DESCRIPTION/ ||
  87.                  $1 ~ /^COMMAND/ || $1 ~ /^OVERVIEW/ ||
  88.                  $1 ~ /^STRUCTURES/ || $1 ~ /^INTRODUCTION/))) {
  89.                 # end insh for Synopsis, Syntax, but also for
  90.                 # DESCRIPTION (e.g., XFree86.1x),
  91.                 # COMMAND (e.g., xspread.1)
  92.                 # OVERVIEW (e.g., TclCommandWriting.3)
  93.                 # STRUCTURES (e.g., XEvent.3x)
  94.                 # INTRODUCTION (e.g., TclX.n)
  95.                             printf "\n"
  96.                             exit
  97.                         } else { # Substitutions after Tom Christiansen perl script
  98.                             gsub(/    /, " ")             # Translate tabs to spaces
  99.                             gsub(/  /, " ")             # Collapse spaces
  100.                             gsub(/  /, " ")             # Collapse spaces
  101.                             gsub(/  /, " ")             # Collapse spaces
  102.                             sub(/^[ ]/, "")             # Kill initial spaces
  103.                             sub(/-$/,"")                # Handle Hyphenations
  104.                             sub(/^.[IB] /, "")          # Kill bold and italics
  105.                             gsub(/\\f[PRIB0123]/, "")   # Kill font changes
  106.                             gsub(/\\s[-+0-9]*/, "")     # Kill size changes
  107.                             gsub(/\\&/, "")             # Kill \&
  108.                             gsub(/\\\((ru|ul)/, "_")    # Translate
  109.                             gsub(/\\\((mi|hy|em)/, "-") # Translate
  110.                             gsub(/\\\*\(../, "")        # Kill troff strings
  111.                             sub(/^\.\\\".*/, "")          # Kill comments
  112.                             gsub(/\\/, "")              # Kill all backslashes
  113.                             if ($0 !~ / - / && $0 !~ / -$/ && $0 !~ /^- /) {
  114.                                 if (after) {
  115.                                     if ($1 !~ /^\.../ && $1 != "")
  116.                                         printf " %s", $0
  117.                                     else {
  118.                                         printf "\n"
  119.                                         after = 0
  120.                                     }
  121.                                 } else {
  122.                                     if ($1 !~ /^\.../ && $1 != "")
  123.                                         printf "%s ", $0
  124.                                     else
  125.                                         printf "\n"
  126.                                 }
  127.                             } else {
  128.                                 after = 1
  129.                                 if ($0 ~ / - /) {
  130.                                     printf "%-20s", sprintf( "%s (%s)",
  131.                                         substr( $0, 0, match( $0, / - / )-1 ),
  132.                                             section )
  133.                                     printf "%s", substr( $0, match( $0, / - / ) )
  134.                                 } else if ($0 ~ / -$/) {
  135.                                     printf "%-20s", sprintf( "%s (%s) -",
  136.                                         substr( $0, 0, match( $0, / -$/ )-1 ),
  137.                                             section )
  138.                                 } else {
  139.                                     printf "(%s) %s", section, $0
  140.                                 }
  141.                             }
  142.                         }
  143.                     }
  144.                 }'
  145.                 done
  146.             cd ..
  147.         fi
  148.     done > /tmp/whatis$$
  149.     if [ -n "$update" -a -f ${mandir}/whatis ]
  150.     then
  151.     cat ${mandir}/whatis >> /tmp/whatis$$
  152.     fi
  153.     sed '/^$/d' < /tmp/whatis$$ | sort | uniq > ${mandir}/whatis
  154.     chmod 644 ${mandir}/whatis
  155.     rm /tmp/whatis$$
  156. done
  157.