#!/bin/ksh # # $Id: sman,v 1.1 2008/11/30 03:59:19 vogelke Exp $ # # NAME: # sman # # SYNOPSIS: # sman [-ev] pattern # # DESCRIPTION: # Look through manpage Estraier DB for "pattern". # # OPTIONS: # -e exact phrase search: don't insert AND between words # -v print the version and exit # # AUTHOR: # Karl Vogel # Sumaria Systems, Inc. PATH=/usr/local/bin:/opt/sfw/bin:/bin:/sbin:/usr/sbin:/usr/bin export PATH lrevno='$RCSfile: sman,v $ $Revision: 1.1 $' lrevdate='$Date: 2008/11/30 03:59:19 $' . /usr/local/lib/ksh/die.ksh . /usr/local/lib/ksh/usage.ksh . /usr/local/lib/ksh/version.ksh # Format a man entry nicely. nr () { file=$1 tbl $file | groff -Tascii -mandoc 2> /dev/null | cat -s | less } # # Command-line options. # exact='no' while getopts ":ev" opt; do case $opt in e) exact='yes' ;; v) version; exit 0 ;; \?) usage "-$OPTARG: invalid option"; exit 1 ;; esac done shift $(($OPTIND - 1)) # # Sanity checks. We move to the man directory to use grabchars # in combination with a set of letters. # top='/search/estraier' test -d "$top/man/srch" || die "no srch directory found" cd $top/man # # If exact search specified, search for that phrase. # If not, create search pattern: "word1 AND word2 AND word3 ..." # case "$@" in "") usage "no pattern to search for" ;; *) ;; esac case "$exact" in yes) pattern="$@" ;; no) pattern=`echo $@ | sed -e 's/ / AND /g'` ;; esac # # Run the search, 15 hits maximum. # tmp="sman.$$.$RANDOM" echo "Searching for: $pattern " estcmd search -sf -vu -max 15 srch "$pattern" | grep 'file://' | sed -e 's!^.*file:///doc/html/htdocs/man!!' \ -e 's!%3A%3A!::!g' -e 's/.htm$//' | paste -d' ' letters - > $tmp # # Keep the results, iterate through them until 'q' is pressed. # while : do clear cat $tmp ch=`grabchars -da -cabcdefghijklmnoq -q'Choice: '` set X `grep "^$ch" $tmp` case "$#" in 4) nr $4 ;; *) break ;; esac done rm $tmp exit 0