#!/bin/bash

# Walk through a library of Eiffel classes and build an interconnecting
# set of HTML pages
function do_short() {
        $SmallEiffel/bin/short -html_deb ${THIS} |
            sed -e 's/="_CLASSREF">\([A-Z][A-Z_0-9]*\)</="\1.html">\1</g' |
	    eval sed    -e \'s/_THISCLASS/${THIS}/g\' \
		-e \'s/_DATE/${TODAY}/g\' \
		-e \'s/_PREVCLASS/${PREV}/g\' \
		-e \'s/_NEXTCLASS/${NEXT}/g\' >>$outf

	echo '<LI><A HREF="'${THIS}'.html">'${THIS}'</A>' >>${INDEX} ;
}

TODAY=`date +%d\ %B\ %Y`
TOP=$1
PARENT=/usr/doc/smalleiffel/html
if [ -z "$TOP" ]
then
    TOP=.
fi

INDEX=${TOP}/index.html

cat >${INDEX} << EOI
<HTML>
<HEAD>
<TITLE>Eiffel Library Index</TITLE>
</HEAD>
<BODY>
<A HREF="${PARENT}/index.html"><IMG SRC="${PARENT}/up.jpeg" ALT="Up" ALIGN=bottom WIDTH="40" HEIGHT="40"></A> Top
<BR><BR>
<HR>
<H1>Eiffel Library Index</H1>
<H2>Classes inherited by every class</H2>
Every class inherits ANY by default, unless an inheritance clause is
included in it. Any class specified by an inheritance clause will itself
inherit from ANY, and so ANY and its ancestors are effectively inherited
by every class, apart from features which are specifically undefined or
redefined. 
<p>
ANY inherits from PLATFORM, and PLATFORM in turn inherits from GENERAL.
GENERAL is the only class which has no parent. 
<p>
Therefore all the features of all these classes are available to every class
in your application. 
<H2>List of classes</H2>
These are the library classes available:                                        
<p>                                                                             
<ul COMPACT> 
EOI

if [ -z "$SmallEiffel" ]
then
    SmallEiffel=/usr/lib/smalleiffel
fi

export SmallEiffel

TMPFIL=/tmp/$$
rm -f $TMPFIL

LIST=`cat $SmallEiffel/sys/loadpath.UNIX`
(
for f in `ls $LIST | grep '\.e$'`
do
    CLASS=`basename $f .e | tr '[a-z]' '[A-Z]'`
    echo $CLASS
done
) | sort -u >$TMPFIL

FIRST=`head -1 $TMPFIL`
LAST=`tail -1 $TMPFIL`

THIS=""
NEXT=""
for CLASS in `cat $TMPFIL`
do
    if [ -z "$THIS" ]
    then
	THIS=$CLASS
        outf=${TOP}/${CLASS}.html
	PREV=$LAST
    else
	NEXT=${CLASS}
	do_short
	PREV=$THIS
	THIS=$CLASS
	outf=${TOP}/${CLASS}.html
    fi
done

NEXT=${FIRST}
do_short

cat >>${INDEX} << EOI
</ul>
<h2>Class ANY</h2>
ANY does not possess any new features of its own. It inherits all the
features of <A HREF="PLATFORM.html">PLATFORM</A> and of
<A HREF="GENERAL.html">GENERAL</A>.
<p>
If you wanted to make some new features that were available to all your
classes, you could insert them in ANY (either by writing your own class or,
less advisedly, by editing /usr/lib/smalleiffel/lib_std/any.e) and thus
cause them to be inherited by every other class (including other base
library classes).
<BR>
<BR>
<HR>
<BR>
<A HREF="${PARENT}/index.html"><IMG SRC="${PARENT}/up.jpeg" ALT="Up" ALIGN=bottom WIDTH="40" H
EIGHT="40"></A> Top
<BR><BR><HR><BR>
<I>Generated by selib2html on $TODAY</I>
</BODY>
</HTML>
EOI

rm -f $TMPFIL
