#!/bin/sh
#
# ps-to-pcl version 0.01
# Convert a PostScript file to a PCL file.

dirname=`dirname $0`
progname=`basename $0`
device=setmonohpljdevice
eps=0
xsize=2550
ysize=3300
dpi=300
copy=1
gps=$dirname/gps

while [ $# -gt 2 ]
do case "$1" in
    -eps)
	eps=1
	;;
    -size)
	shift; xsize=$1; ysize=$1
	;;
    -xsize)
	shift; xsize=$1;
	;;
    -ysize)
	shift; ysize=$1;
	;;
    -dpi)
	shift; dpi=$1;
	;;
    -copy)
	shift; copy=$1;
	;;
    esac
    shift
done

if [ $# != 2 ] ; then
	cat << __END__

$progname: you must specify an input file and an output file.
usage: $progname [-rgb|-g] [-xsize s] [-ysize s] [-size s] [-dpi s]
    [-copy n] [-eps] file outfile
  -rgb: Convert \`file' to an RGB raster.
  -g:   Convert \`file' to an 8-bit gray raster.
  -xsize s: Set the x-size of the raster to \`s'.
  -ysize s: Set the y-size of the raster to \`s'.
  -size s: Set the x-size and y-size of the raster to \`s'.
  -dpi s: Set the resolution of the raster to \`s' dpi.
  -copy n: Set the number of copies to \`n'.
  -eps: Treat this file as an EPS file.  If \`file' has the extension \`.eps',
        this is the default.
__END__
	exit 1
fi

infile=$1
outfile=$2

if [ ! -r $infile ] ; then
	echo "$progname: \`$infile' does not exist."
	exit 1
fi

if [ $eps -ne 0 -o `expr $infile : '.*\.eps$'` -ne 0 ] ; then
	run="($dirname/eps-to-ps -b $infile) (r) pipe cvx exec"
else
	run="($infile) run"
fi

exec $gps -no-init -no-memstats -batch -e "
    { 
	userdict /#copies $copy put
	($outfile) $xsize $ysize $dpi $device
	($dirname/..//fonts) setfontpath
	setfoliofontdevice
	($dirname/fnmconvers.ps) run
	% (Imaging ) print ($infile) print ( . . . ) print
	$run
	% (done\n) print
    } stopped {
	handleerror
    } if
"
if test $status ! -eq 0
then    exit 23

