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

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

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

fig2dev -L ps "$BASE.ps" "$IN" 1>&2
/usr/lib/sdc/bin/pstogif "$BASE.ps" "$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"
)

echo "<IMG SRC=\"$OUT\">"