#!/bin/sh
#
# install-help [ lib]
# ------------------- Install all the help files and index for library/_lib_
#
lib=$1
if [ x$lib = x ];then  lib=base ; fi
#
# Should work WHEREVER this is called from :
cd `dirname $0`/..
##
Hdir=help/$lib
LIBdir=src/library/$lib
MANdir=$LIBdir/man

if [ ! -d $LIBdir ]; then echo "There's no library `pwd`/$LIBdir !"; exit 1; fi
if [ ! -d $Hdir ]; then mkdir -p $Hdir; fi
cp /dev/null $Hdir/AnIndex

FILES="`ls -A $MANdir | sed '/CVS/d;/~$/d;/\.bak$/d;/\.orig$/d'`"

echo "==>>> Building   $Hdir/AnIndex  for library '$lib'"
(
for file in $FILES
do
	NAMES=`grep '^ALIAS(' $MANdir/$file| sed 's/ALIAS(\(.*\))$/\1/; s/[\*]/\\\&/g'`
	for name in $NAMES
	do
		echo "$name	$file"
		#	   ^^^^^ = TAB
	done
	(echo "$file:	$NAMES" | tr '\012' ','; echo '')| sed 's/,$//'	 >&2
done
if [ $lib != 'base' ]
##-- The following is NOT done anymore in 'base':
##-- 1) Each help file should have  ALIAS(..) for  ALL it's objects
##-- 2) The  help file name may differ from _ANY_ object (eg 'Special')
then 
	for file in $FILES
	do
		echo "$file	$file"
	done
fi
) | sort -d -f | uniq >> $Hdir/AnIndex

echo "   ==== Makeing Manual entries for library '$lib' ===="
for file in $FILES
do
	./etc/doc2ms $MANdir/$file | nroff -ms 2> /dev/null \
	| ./etc/help.pretty | sed 's/^/	/' >  $Hdir/$file
	# echo $file
done



if [ -f $LIBdir/TITLE ]
then
	cat $LIBdir/TITLE >> help/LibIndex
	cp $LIBdir/TITLE $Hdir/TITLE
fi

if [ -f $LIBdir/INDEX ]
then
	cp $LIBdir/INDEX $Hdir/INDEX
fi

