#! /bin/sh

STYLESHEET=qbrew.xsl
XSLTCOMPILE="xsltproc --nonet --catalogs"

SGML_CATALOG_FILES=./catalog
SGML_CATALOG_FILES=$SGML_CATALOG_FILES:/usr/local/share/sgml/catalog
SGML_CATALOG_FILES=$SGML_CATALOG_FILES:/usr/local/share/xml/catalog

export SGML_CATALOG_FILES
export SP_CHARSET_FIXED=yes
export SP_ENCODING=unicode

# create output directory
rm -rf html
mkdir html
cd html

# process xml
if [ -e ../qbrew.docbook ] ; then
  echo "Processing qbrew.docbook"
  $XSLTCOMPILE ../$STYLESHEET ../qbrew.docbook
  tidy -indent -quiet -modify *.html
  LNFILE=`find * -name ln-*.html -print | head -n 1`
  if test "no$LNFILE" != "no" ; then
    mv $LNFILE notice.html
    sed -i .bak -e s/"$LNFILE"/notice.html/ handbook.html
    rm handbook.html.bak
  fi
  # add prefixes to filenames (would be nice if stylesheet could do this)
  htmllist=`ls *.html`
  for htmlfile in $htmllist ; do
    filelist=`ls *.html`
    for temp in $filelist ; do
      sed -i .bak -e s/"$htmlfile"/qbrew-$htmlfile/ $temp
    done
    if [ -e $htmlfile ] ; then
      mv ${htmlfile} qbrew-${htmlfile}
    fi
  done
  rm -f *.bak
else
  echo "WARNING: qbrew.docbook not found"
fi

cd ..
