#------------------------------------------------------------------------------
# first pass for permuted index of the Oberon library
# afb 7/90
#------------------------------------------------------------------------------

	name=`basename $0`
	usage="Usage: $name manual..."

	tmpfile1=/tmp/ptx1.$$
	tmpfile2=/tmp/ptx2.$$
	tmpfile3=/tmp/ptx3.$$
	trap "rm -f $tmpfile1 $tmpfile2 $tmpfile3; exit 1" 1 2 3 15
	trap "rm -f $tmpfile1 $tmpfile2 $tmpfile3" 0
	out_index=index
	out_toc=toc

if [ $# -eq 0 ]
then	echo >&2 "$usage"; exit 1
fi
manpages="$*"

grep -l "^\.SH" $manpages | sed 's/\.\([0-8]\)/(\1/
	s/$/)/' > $tmpfile1
sed -n '/^\.SH *NAME/{
	n
	p
	}' $manpages > $tmpfile2
pr -t -m '-s ' $tmpfile1 $tmpfile2 | sed 's/	/ /g
	s/\\s[+-]1//g
	s/\\s0//g' | sed '/^ *$/d
	s/ *\\- /: /
	s/ *- /: /' > $tmpfile3
ed $tmpfile3 >/dev/null 2>/dev/null <<!!
/^intro/m0
w
q
!!
sed 's/\([^ ]*\)[^:]*:/\1/
	s/^/.xx "/
	s/([0-9a-zA-Z]*) /" "/
	s/man[135]\///
	s/$/"/' $tmpfile3 >$out_toc
while read manual modulname rest
do	names=`makenames "$manual"`
	modulname=`echo "$modulname" | sed 's/://'`
	manual=`basename $manual`
	case $names
	in "")	echo "$manual" "$modulname:" "$rest"
	;; *)	names=`echo $names | sed 's/ /, /g'`
		echo "$manual" "$modulname, $names:" "$rest"
	esac
done <$tmpfile3 >$out_index
