#! /bin/sh
# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.

# $Header: makewhatis.sh 1.4 90/10/23 $
rm -f /tmp/whatis$$
cd ${ROOT}/usr/catman
CAT=pcat
for i in *
do
if [ -d $i ]
then
	cd $i
	for j in *
	do
		if [ "$j" != "*" ];then
		if [ "`echo $j | egrep '\.z$'`" != "" ]
                then
                        CAT=pcat
                elif [ "`echo $j | egrep '\.Z$'`" != "" ]
                then
                        CAT=zcat
                else
                        CAT=cat
                fi
		${CAT} $j | sed -e "s/.//g" | nawk '
		{
		if ( $1 == "NAME" ) {
			getline
			while(NF > 0) {
				space = $0
				while(index(space," ") == 1)
					space = substr(space, 2, length(space) -1)
				temp = temp space
				getline;
			}
			n = split(temp, command, "-")
			out = command[1] section
			for (bob=2; bob <= n; bob++)
				out2 = out2 "-" command[bob]
			printf("%20-s %s\n", out, out2)
			exit
		} else if ( index($1, "(")) {
			section = substr($1, index($1, "("), length($1) - index($1, "(") +1)
		}
		next;
		}'
		fi
	done
	cd ..
fi
done >/tmp/whatis$$
sort /tmp/whatis$$ > /usr/catman/whatis
chmod 644 /usr/catman/whatis
rm -f /tmp/whatis$$
