| [3228] | 1 | #! /bin/bash
|
|---|
| 2 | #
|
|---|
| 3 | # original from:
|
|---|
| 4 | # fman: new man program
|
|---|
| 5 | # @(#) fman.ksh 1.5 94/04/16
|
|---|
| 6 | # 91/07/03 john h. dubois iii ([email protected])
|
|---|
| 7 | # 91/07/11 made it unpack man pages if neccessary
|
|---|
| 8 | # 91/07/16 fixed test for whether man file pattern was expanded
|
|---|
| 9 | # 92/01/21 made it read /etc/default/man to get section order,
|
|---|
| 10 | # and only display the first section found.
|
|---|
| 11 | # 92/02/06 changed name to fman
|
|---|
| 12 | # 92/02/07 fixed bug in notfound
|
|---|
| 13 | # 92/02/13 incorporated changes from DOS version
|
|---|
| 14 | # 92/03/11 changed to use MANPATH from environment if set,
|
|---|
| 15 | # and search all directories given in MANPATH
|
|---|
| 16 | # 92/03/15 exec pager or man w/o forking
|
|---|
| 17 | # 92/05/31 try using index if one exists
|
|---|
| 18 | # 92/10/01 Added "See also <other sections>"
|
|---|
| 19 | # 92/10/18 If PAGER is less, search for name of man page to make it easier
|
|---|
| 20 | # to find information in man pages for multiple items
|
|---|
| 21 | # 92/11/11 Make it work for compressed files not listed in index;
|
|---|
| 22 | # deal with man pages listed in index that don't exist.
|
|---|
| 23 | # 93/03/30 Fixed bug in MANPATH processing
|
|---|
| 24 | # 93/06/17 Include paths in "See also:" message if they would be needed
|
|---|
| 25 | # to get to a man page. Allow MANPATH spec on command line.
|
|---|
| 26 | # 93/07/09 Added -h and -e options.
|
|---|
| 27 | # 94/04/16 Added x option.
|
|---|
| 28 | #
|
|---|
| 29 | # conversion to bash v2 syntax done by Chet Ramey
|
|---|
| 30 |
|
|---|
| 31 | istrue()
|
|---|
| 32 | {
|
|---|
| 33 | test 0 -ne "$1"
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | isfalse()
|
|---|
| 37 | {
|
|---|
| 38 | test 0 -eq "$1"
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | # Finds all sections that man page $1 is in and puts them in the the
|
|---|
| 42 | # global array Sections[].
|
|---|
| 43 | # The filename of each page is put in FileNames[] with the same index.
|
|---|
| 44 | # Global vars used:
|
|---|
| 45 | # patharr[] MANPATH directories.
|
|---|
| 46 |
|
|---|
| 47 | FindSectionsInIndex ()
|
|---|
| 48 | {
|
|---|
| 49 | typeset index indexes section mpath page=$1
|
|---|
| 50 | typeset -i i=0 NIndex=0
|
|---|
| 51 |
|
|---|
| 52 | for mpath in "${patharr[@]}"; do
|
|---|
| 53 | if [ -r $mpath/index ]; then
|
|---|
| 54 | indexes="$indexes $mpath/index"
|
|---|
| 55 | let NIndex+=1
|
|---|
| 56 | fi
|
|---|
| 57 | done
|
|---|
| 58 | [ -z "$indexes" ] && return
|
|---|
| 59 | # Make grep give filename
|
|---|
| 60 | [ NIndex -lt 2 ] && indexes="$indexes /dev/null"
|
|---|
| 61 | # set positional parameters to
|
|---|
| 62 | # indexfile:searchname pagename section ...
|
|---|
| 63 | # e.g.
|
|---|
| 64 | # /usr/man/index:FP_OFF Routines DOS
|
|---|
| 65 | set -- `grep "^$page[ ]" $indexes`
|
|---|
| 66 | while [ $# -gt 2 ]; do
|
|---|
| 67 | FileNames[i]=${1%%index*}cat$3/$2.$3
|
|---|
| 68 | Sections[i]=$3
|
|---|
| 69 | shift 3
|
|---|
| 70 | let i+=1
|
|---|
| 71 | done
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | # Finds all sections that man page $1 is in by searching each man directory
|
|---|
| 75 | # in the order given in patharr[],
|
|---|
| 76 | # and puts them in the the global array Sections[].
|
|---|
| 77 | # The filename of each page is put in FileNames[] with the same index.
|
|---|
| 78 | # Global vars used:
|
|---|
| 79 | # patharr[] MANPATH directories.
|
|---|
| |
|---|