:
#
#	ps2fax,ps2laserjet,ps2epson,ps2ljet2p,ps2ljet3:
#
#	This script converts postscript to fax.
#	It requires that Ghostscript v2.4 or later be installed on your system.
#
#	You may also link this script to:
#		ps2laserjet
#		ps2ljet2p
#		ps2ljet3
#		ps2epson
#	These versions produce output ready for those types of printers
#

#
#	Various configurable variables
#

#	Places to find gs binary (a colon separated list of paths).
GS_BIN=/usr/local/bin

#	Places to find gs startup code and supporting files
GS_START=/usr/local/lib/ghostscript

#	Places to find gs fonts (a colon separated list of paths).
GS_FONTS=/usr/local/lib/ghostscript/fonts

#	Places to find Adobe fonts (a colon separated list of paths).
AD_FONTS=/usr/local/lib/ghostscript/fonts-adobe

#	Default fonts.  Set to either $GS_FONTS or $AD_FONTS
DEF_FONTS=$GS_FONTS

#	Pathname(s) of any printer preamble files you want to *always*
#	include before processing any files listed on the command line
PREAMBLE=

#	Options to make gs be silent
SILENT="-q -dNOPAUSE"

#	Any other options to pass to gs
GS_OPTS=

#
#	Determine what program we really are if linked to some other name
#
IAM=`basename "$0"`
case "$IAM" in
ps2laserjet|ps2pcl)
	Device=-sDEVICE=laserjet;
	DevName="LaserJet Series II printer"
	OutFile="-sOUTPUTFILE=|cat"
	;;
ps2ljet2p)
	Device=-sDEVICE=ljet2p;
	DevName="LaserJet Series IIP printer"
	OutFile="-sOUTPUTFILE=|cat"
	;;
ps2ljet3)
	Device=-sDEVICE=ljet3;
	DevName="LaserJet Series III printer"
	OutFile="-sOUTPUTFILE=|cat"
	;;
ps2epson)
	Device=-sDEVICE=epson;
	DevName="Epson printer"
	OutFile="-sOUTPUTFILE=|cat"
	;;
*)
	Device=-sDEVICE=dfaxhigh;
	DevName="DigiFAX fax"
	OutFile="-sOUTPUTFILE=ps2fax.fax"
	;;
esac

#
#	Usage message
#
usage() {
	cat <<EOF
Usage: $IAM [-l] [-ag] [ -o OUTFILE ] ps_files...

Converts Postscript file(s) to $DevName format using Ghostscript.
Requires that Ghostscript with the $Device devices be installed.
If no OUTFILE is specified, the output appears on standard output
for printers, or put into file "ps2fax.fax" for FAX.

The default font files are found in $DEF_FONTS.

Options:
-a		Force use of Adobe fonts.
		(in $AD_FONTS)
-g		Force use of GNU fonts.
		(in $GS_FONTS)
-l		Produce low resolution FAX output
-o OUTFILE	Names the file that contains the output
EOF
}

#
#	Process options
#
UseFonts=default
set -- `getopt ?aglo:r: $*`
if [ $? != 0 ]; then usage; exit 2; fi
for i in $*
do
	case $i in
	-l)		Device="-sDEVICE=dfaxlow"; shift;;
	-a)		UseFonts=adobe; shift;;
	-g)		UseFonts=gnu; shift;;
	-o)		OutFile="-sOUTPUTFILE=$2"; shift; shift;;
	-r)		GS_OPTS="$GS_OPTS -r$2"; shift; shift;;
	--)		shift; break;;
	-?)		usage; exit 0;;
	esac
done

#
#	Now, set up paths and variables
#
case $UseFonts in
adobe)	GS_LIB=$AD_FONTS:$GS_START;;
gnu)	GS_LIB=$GS_FONTS:$GS_START;;
*)	GS_LIB=$DEF_FONTS:$GS_START;;
esac

PATH=$GS_BIN:$PATH;
export PATH GS_LIB

#
#	Now do the real work by calling "gs"
#
files="$*"
if [ "Q$files" = Q ]
then
	exec gs $SILENT $Device $GS_OPTS $OutFile -
else
	exec gs $SILENT $Device $GS_OPTS $OutFile $PREAMBLE $files quit.ps
fi
