#!/bin/sh
# Script to convert an arbitrary PostScript image to a cropped GIF image
# suitable for incorporation into HTML documents as inlined images to be
# viewed with Xmosaic.
#
# This is a modified version of the pstoepsi script 
# by Doug Crabill dgc@cs.purdue.edu
#
# Note in the USAGE line below, the source PostScript file must end
# in a .ps extention.  This is a GhostScript requirement, not mine...
#
# This software is provided without any guarantee.
#
# Nikos Drakos, nikos@cbl.leeds.ac.uk
# Computer Based Learning Unit, University of Leeds.
#
# Tue Jun 8 13:11:53 BST 1993

USAGE="Usage: $0 <file>.ps <file>.gif"

### Edit these variables if you want to run the script outside the translator
### 
GS='gs'
PSTOPPM='pstoppm.ps'
PNMCROP='pnmcrop'
PPMTOGIF='ppmtogif'
######################################################################


if [ $# -ne 2 -o ! -f "$1" ] ; then
	echo $USAGE 1>&2
	exit 1
fi

trap 'rm -f ${BASE}.ppm; exit' 1 2 3 4 13 15

BASE=gs$$

ln $1 $BASE.ps

# If you like b/w substitude
# ($BASE) ppm1run
# for for "($BASE) ppm8run" in the following inline document.

$GS -q -dNODISPLAY $PSTOPPM << ND
100 100 ppmsetdensity
($BASE) ppm8run
ND

rm -f $BASE.ps

if test -f ${BASE}.ppm 
	then $PNMCROP ${BASE}.ppm | $PPMTOGIF - > $2
else for i in `ls ${BASE}.[1-9]*ppm`
	do $PNMCROP $i | $PPMTOGIF - > `echo $i |sed 's/\.\(.*\)ppm/\1\.xbm/'`;
	echo "Writing `echo $i |sed 's/\.\(.*\)ppm/\1\.xbm/'`"
     done
fi

rm -f ${BASE}.ppm
rm -f ${BASE}.[1-9]*ppm

exit 0
