#! /bin/sh
#! *sh* 10/91
#! Fapropos
#! scan the Ferret Users Guide for the indicated string
#! report occurrances with line numbers
#! the command Fhelp can then be used to access the Usegs Guide
#! beginning at a selected line number

# no argument given: explain the ropes
if [ $# -eq 0 ]; then
     echo ' '
     echo '    *** Fapropos - Interactive help for FERRET ***'
     echo ' '
     echo '    Fapropos scans the FERRET Users Guide for a character string'
     echo ' '
     echo '        Correct usage is:  Fapropos  string'
     echo ' '
     echo '        Example: Fapropos regridding'
     echo ' '
     echo '    Fhelp can then be used to enter the Users Guide'
     echo '        Correct usage is:  Fhelp line_number'
     exit
fi

# too many arguments: explain the syntax
# actually not a problem except for whitespace conversion
if [ $# -gt 1 ]; then
     echo " "
     echo "    *** Syntax error in command entered ***"
     echo " "
     echo "    Usage:  Fapropos  string"
     echo " "
     echo "    Note: multi-word strings need to be enclosed in quotations"
     exit
fi

# scan the FERRET manual
# first check if something exists since the "not found" status seesm to get lost under bash
if grep -q "$1" "${FER_DIR}/doc/ferret_users_guide.txt" ; then
     grep -in "$1" "${FER_DIR}/doc/ferret_users_guide.txt" | awk -f "${FER_DIR}/bin/Fapropos.awk" | more -d
else
     echo " '$1' is not found in the FERRET manual"
fi

