#!/bin/sh
# handle tgif file for html, expects args %f %S
set -e			# die on any error
BASE=`basename $2 .obj`
IN=$2			# input file
OUT=$BASE.gif		# output file, in this case, also temporary
TMP=$BASE.tmp		# temporary file

[ -f "$IN" ] || exit 1	# ensure our file exists
# make sure our temp file does not already exist
if [ -f "$TMP" ]; then
   echo "$0: $TMP is in the way" 1>&2
   exit 1
fi

tgif -print -eps -stdout "$IN" > "$TMP"
/usr/lib/sdc/bin/pstogif "$TMP" "$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 "$TMP"
echo "<IMG SRC=\"$OUT\">"
