# Based on original from Eric Bischoff <eric@caldera.de>

# Create an HTML document with index and figures in place.
# This is done by:

# 1. Converting from SGML to HTML
# 2. Generating an SGML index based on the HTML
# 3. Converting from SGML to HTML (taking into account the index this time)
# 4. Copying figures from original source tree into the output directory

# The end result is a directory tree ready for publishing/packaging/whatever...

# Point to the CSS and standard admon graphics.  Note that these paths use
# the "dsssl-stylesheets" symlink to point to the latest dsssl stuff...

FINAL_INDEX=generated-index.sgml
#ADMON_GRAPHICS=/usr/share/sgml/docbook/dsssl-stylesheets/images/*.gif
ADMON_GRAPHICS=../rh-sgml/stylesheet-images/*.gif
INDEXFILE=INDEX$$

# Convert to HTML, generating the HTML.index file that we'll use to
# create an SGML index...

echo Running $SGML_JADE...

$SGML_JADE -t sgml -V html-index $SGML_ARGUMENTS

# Generate the index, fixing up the problem of bogus empty closing tags (</>)...

echo Indexing...
perl /usr/bin/collateindex.pl -g -i generated-index -o ../$FINAL_INDEX HTML.index

# Not sure if these are still needed; when we first tried collateindex;
# it threw "</>" in the generated index in certain cases...

cat ../$FINAL_INDEX | sed 's,^[        ]*</>[  ]*$,,' > ../$INDEXFILE
mv -f ../$INDEXFILE ../$FINAL_INDEX

# Nuke the HTML.index file; we don't need it anymore...

rm -f HTML.index

echo Rerunning $SGML_JADE...

$SGML_JADE -t sgml $SGML_ARGUMENTS

echo -n "Copying admon graphics..."
mkdir ./stylesheet-images
cp ${ADMON_GRAPHICS} ./stylesheet-images/
echo "Done!"

if [ -d ../figs/ ]
    then
        echo -n "Moving figures..."
        (cd ../ ; tar chf - figs/) | (tar xf -)
        echo "Done!"
        echo -n "Cleaning CVS..."
        find ./figs/ -type d -name "CVS"|xargs rm -rf
        echo -n "EPS..."
        find ./figs/ -type f -name "*eps"|xargs rm -f
        echo -n " .xvpics..."
        find ./figs/ -type d -name ".xvpics"|xargs rm -rf
        echo -n "directories..."
        find ./figs/ -type d -empty|xargs rm -rf
        echo "Done!"
    fi
# 
exit 0
