#!/bin/sh -

# mkwhatis - make personal man/whatis or man/windex files
# Steve Kinzler, steve@kinzler.com, Feb 94/Jul 96
# https://kinzler.com/me/home.html#homedir

# NOTE: 2008-09-30: catman is not available on RHEL.  This script is no
#	longer fully supported/maintained.

case $# in
0)	;;
*)	echo "usage: $0" 1>&2; exit 1;;
esac

for man in `echo "$MANPATH_ME" | tr : ' '`
do
	test -f "$man/whatis" && touch "$man/whatis"
	catman -w -M "$man"

	set `ls -t $man` x
	case "$1" in
	whatis|windex)	whatis=$1;;
	*)		echo "$0: catman didn't make $man/{whatis,windex}" 1>&2
			continue;;
	esac

	bin=`echo "$man" | sed -n 's,man\([^/]*\)$,bin\1,p'`
	test -z "$bin" -o ! -d "$bin" && continue

	cat $bin/* 2> /dev/null |
	sed -n 's/^# \([^ 	][^ 	]*\) \(- .*\)/\1\2/p' |
	case "$whatis" in
	windex) awk -F '{ printf "%-16s%-16s%s\n", $1, $1 " (0)", $2 }';;
	*)	awk -F '{ printf "%-24s%s\n",          $1 " (0)", $2 }';;
	esac >> $man/$whatis

	sort -o $man/$whatis $man/$whatis
done
