#!/bin/sh
# handle lout file for html, expects args %f %S
set -e			# die on any error
BASE=`basename $2 .lout`
IN=$2			# input file
OUT=$BASE.gif		# output file
TMP1=$BASE.tmplout
TMP2=$BASE.eps

[ -f "$IN" ] || exit 1	# ensure our file exists

# make sure our temp files do not already exist
if [ -f "$TMP1" ]; then
   echo "$0: $TMP1 is in the way" 1>&2
   exit 1
fi
if [ -f "$TMP2" ]; then
   echo "$0: $TMP2 is in the way" 1>&2
   exit 1
fi

cat >"$TMP1" <<EOF
@SysInclude{fig}
@SysInclude{eq}
@SysInclude{graph}
@SysInclude{doc}
@Doc //
@Text @Begin

EOF

cat "$IN" >>"$TMP1"

cat >>"$TMP1" <<EOF

@End @Text

EOF

lout -EPS "$TMP1" -o "$TMP2"
/usr/lib/sdc/bin/pstogif "$TMP2" "$OUT" 1>&2

# making transparent gifs is nice but not required
( giftrans -t "#ffffff" -o "$OUT.1" "$OUT" && \
    mv -f "$OUT.1" "$OUT" || \
    true
  rm -f "$OUT.1"
)

rm -f $TMP1.* $TMP1 $TMP2 lout.li
echo "<IMG SRC=\"$OUT\">"
