home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 January / CHIPCD1_98.iso / software / pelne / monkey / mlinux06.a01 / BIN / APROPOS < prev    next >
Text File  |  1997-04-13  |  2KB  |  103 lines

  1. #!/bin/sh
  2. #
  3. # apropos -- search the whatis database for keywords.
  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. # apropos-1.4d aeb 950220
  18. #
  19.  
  20. OLDPATH=$PATH
  21. PATH=/usr/local/bin:/bin:/usr/ucb:/usr/bin
  22.  
  23. libdir=/usr/lib
  24.  
  25. if [ $# = 0 ]
  26. then
  27.     echo "usage: `basename $0` keyword ..."
  28.     exit 1
  29. fi
  30.  
  31. manpath=`(PATH=$OLDPATH; /usr/bin/man --path) | tr : '\040'`
  32.  
  33. if [ "$manpath" = "" ]
  34. then
  35.     echo "apropos: manpath is null"
  36.     exit 1
  37. fi
  38.  
  39. if [ "$PAGER" = "" ]
  40. then
  41.     PAGER="/usr/bin/less -is"
  42. fi
  43.  
  44. # avoid using a pager if only output is "nothing appropriate"
  45. nothing=
  46. found=0
  47. while [ $found = 0 -a -n "$1" ]
  48. do
  49.     for d in $manpath /usr/lib
  50.     do
  51.         if [ -f $d/whatis ]
  52.         then
  53.             if grep -iq "$1" $d/whatis > /dev/null
  54.             then
  55.                 found=1
  56.             fi
  57.         fi
  58.     done
  59.     if [ $found = 0 ]
  60.     then
  61.     nothing="$nothing $1"
  62.     shift
  63.     fi
  64. done
  65.  
  66. if [ $found = 0 ]
  67. then
  68.     for i in $nothing
  69.     do
  70.     echo "$i: nothing appropriate"
  71.     done
  72.     exit
  73. fi
  74.  
  75. while [ $1 ]
  76. do
  77.     for i in $nothing
  78.     do
  79.     echo "$i: nothing appropriate"
  80.     done
  81.     nothing=
  82.     found=0
  83.     for d in $manpath /usr/lib
  84.     do
  85.         if [ -f $d/whatis ]
  86.         then
  87.             if grep -i "$1" $d/whatis
  88.             then
  89.                 found=1
  90.             fi
  91.         fi
  92.     done
  93.  
  94.     if [ $found = 0 ]
  95.     then
  96.         echo "$1: nothing appropriate"
  97.     fi
  98.  
  99.     shift
  100. done | $PAGER
  101.  
  102. exit
  103.