#! /bin/sh

if test -z "$KDB2HTML_UNINSTALLED"; then
ksgmldir=/opt/kde/share/apps/ksgmltools
else
ksgmldir=$KDB2HTML_UNINSTALLED
fi

CATALOG=$ksgmldir/catalog
DB_STYLESHEET=$ksgmldir/stylesheets/kde.dsl

# This keeps all system and user variable settings untouched, but
# consults them when needed - IMHO the best solution
SP_C_SWITCHES=""

output=HTML
TMPDIR=DBTOHTML_OUTPUT_DIR$$

if [ ! $# = 1 ]
then
  echo "Usage: `basename $0` [filename.docbook]" >&2
  exit 1
fi

if [ ! -r $1 ]
then
  echo Cannot read \"$1\".  Exiting. >&2
  exit 1
fi

if test -z "$SP_C_SWITCHES"
then
  echo "Warning: No catalogues were found during installation!" >&2
fi

mkdir $TMPDIR
SAVE_PWD=`pwd`
(cd $TMPDIR;
  if test -f ../$1; then
    input_file=../$1
  else
    input_file=$1
  fi
  echo jade -c $CATALOG $SP_C_SWITCHES -t sgml -d ${DB_STYLESHEET}\#html $input_file 
  jade -c $CATALOG $SP_C_SWITCHES -t sgml -d ${DB_STYLESHEET}\#html $input_file
  cd $SAVE_PWD
)

if [ -d ${output}.junk ]; then
     /bin/rm -rf ${output}.junk
fi
if [ -d ${output} ]; then
    mv $output ${output}.junk
fi
mv ${TMPDIR} $output

exit 0

