#!/bin/sh

DOCDIR=doc/library
rm -rf $DOCDIR
mkdir $DOCDIR

if [ "$1" = "-v" ]; then
	VERBOSE=1
else
	VERBOSE=0
fi

FILES="times.l plus.l minus.l less.l lteq.l equal.l greater.l gteq.l abs.l append.l assoc.l assq.l booleanp.l caaaar.l caaar.l caar.l c-alphabeticp.l c-ciltp.l c-cilep.l c-cieqp.l c-cigtp.l c-cigep.l c-downcase.l c-lower-casep.l c-numericp.l c-upcase.l c-upper-casep.l c-whitespacep.l cltp.l clep.l ceqp.l cgtp.l cgep.l digits.l divide.l equalp.l evenp.l expt.l gcd.l id.l integer.l iterate.l lcm.l length.l list.l list-ref.l list-tail.l listp.l map.l max.l member.l memq.l min.l modulo.l ntimes.l nplus.l nminus.l nless.l nlteq.l ngreater.l ngteq.l natural.l naturalp.l ndivide.l negate.l negativep.l neqp.l newline.l nexpt.l non-negativep.l normalize.l not.l nquotient.l nremainder.l nullp.l numtostr.l oddp.l positivep.l pred.l quotient.l remainder.l reverse.l sqrt.l string.l strtonum.l s-append.l s-ciltp.l s-cilep.l s-cieqp.l s-cigtp.l s-cigep.l s-length.l s-ref.l sltp.l slep.l seqp.l sgtp.l sgep.l substring.l succ.l zerop.l"

make_html() {
    for dir in $*; do

	FLIST="n/a $FILES n/a"
	PREV=""
	THIS=""
	NEXT=""

	for name in $FLIST; do
		if [ "$name" != "n/a" ]; then
			name="lib/$name"
		fi
		PREV=$THIS
		THIS=$NEXT
		NEXT=$name
		if [ "$PREV" = "" ]; then continue; fi
		clname=`basename $THIS .l`
		if [ $VERBOSE = 1 ];then
			echo generating: $clname.html
		fi
		sed \
			-e '1,/---code---/s/^; //' \
    			-e '1,/---code---/s/^;	/	/' $THIS \
			| PF=$PREV TF=$THIS NF=$NEXT \
				awk -f util/mkhtml.awk \
			> $DOCDIR/$clname.html
	done
    done
}

make_html lib

cat <<__EOT1__ >$DOCDIR/index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Sketchy LISP - Scheme Function Library</TITLE>
<META name="description" content="Sketchy library index">
<META name="description" content="Scheme library index">
<META name="keywords" content="Scheme, LISP, library, source code ">
<LINK rel="stylesheet" type="text/css" href="../sketchy.css" title="sketchy">
</HEAD>
<BODY>

<H2>Sketchy Function Library</H2>

<TABLE class=list>
__EOT1__

for name in $FILES; do
	if [ $VERBOSE = 1 ];then
		echo indexing: `basename $name .l`
	fi
	sed -e 's/^; //' lib/$name \
		| NAME=lib/$name awk -f util/mkindx.awk >>$DOCDIR/index.html
done

cat <<__EOT3__ >>$DOCDIR/index.html
</TABLE>

</BODY>
</HTML>
__EOT3__
