#! /bin/sh

STYLESHEET=/usr/lib/sgml/stylesheets/dbtohtml.dsl

output=db2html.html
TMPFN=DBTOHTML.html

if [ $# -gt 2 ]
then
  echo "Usage: `basename $0` [filename.sgml]" >&2
  exit 1
fi

if [ $# -eq 1 ]
then
  if [ ! -r $1 ]
  then
    echo Cannot read \"$1\".  Exiting. >&2
    exit 1
  fi
  if echo $1 | egrep -i '\.sgml$|\.sgm$' >/dev/null 2>&1
  then
    output="`echo $1 | sed 's,\.sgml$,.html,;s,\.sgm$,.html,'`"
  fi
fi

# -V %no-split-output%  sends all the output to one file
# -V %no-make-index%    disables index creation
# -V %no-make-toc%      disables TOC creation
# -V %no-shade-screen%  disables grey background to SCREEN regions
# -V %show-comments%    includes contents of COMMENT regions


cat $* | jade -d $STYLESHEET -t sgml -V "%no-split-output%" > $TMPFN

if [ $# -eq 1 ]
then
  mv $TMPFN $output
else
  cat $TMPFN
fi

rm -f $TMPFN

exit 0
