#!/bin/sh
#
#	This is a wrapper for the pcl2tiff program which sets
#	the 'usual' environment in which to perform PCL to FAX
#	conversion.  Feel free to customize this.
#

#
#	Determine what program we really are if linked to some other name
#
IAM=`basename "$0"`
case "$IAM" in
faxjet2*)	IAM=faxjet2; engine=pcl2tiff;;
pclview*)	IAM=pclview; engine=hpview;;
xpclview*)	IAM=pclview; engine=xhpview;;
*)		IAM=faxjet; engine=pcl2tiff;;
esac

usage() {
	case "$IAM" in
	pclview)echo "Usage: $IAM [pcl2tiff_options] pcl_file";;
	xpclview)echo "Usage: $IAM [pcl2tiff_options] pcl_file";;
	*)	echo "Usage: $IAM [pcl2tiff_options] < pcl_file -o fax_file";;
	esac
	echo
	$engine -?
}

#
#	Default output format
#		Put -c, -t, -f, and -Z options here
#
case "$IAM" in
faxjet2)	res="-r200"; defcomp="-c digifax";;
faxjet)		res=""; defcomp="-c digifax -t 0";;
pclview)	res=""; defcomp="";;
xpclview)	res=""; defcomp="";;
esac

#
#	Default font configuration:
#		Roman-8 and PC-8 symbol sets are preloaded
#		Default symbol set is set to PC-8
#
case "$IAM" in
faxjet2)	F=/usr/lib/faxjet/200;;		#Place to find HP PCL fonts
faxjet)		F=/usr/lib/faxjet/300;;		#Place to find HP PCL fonts
pclview)	F=/usr/lib/faxjet/300;;		#Place to find HP PCL fonts
xpclview)	F=/usr/lib/faxjet/300;;		#Place to find HP PCL fonts
esac

roman8="-I$F/co120rfn.r8p -I$F/co120bfn.r8p -I$F/lp085rfn.r8p"
pc8="-I$F/co120rfn.pcp -I$F/co120bfn.pcp -I$F/lp085rfn.pcp"
legal="-I$F/co120rfn.lgp -I$F/co120bfn.lgp -I$F/lp085rfn.lgp"
latin1="-I$F/co120rfn.l1p -I$F/co120bfn.l1p -I$F/lp085rfn.l1p"

roman8set="-Y8U"
pc8set="-Y10U"
legalset="-Y1U"
latin1set="-Y0N"

deffont="$pc8set $roman8 $pc8"

#
#	Miscellaneous options
#
misc=
misc="$misc -T2"	#NL ->CR/NL (for Unix text files)

set -- `getopt ?lZ:O:P:B:D:L:R:I:S:N:F:Y:T:o:c:f:t: $*`
if [ $? != 0 ]; then usage; exit 2; fi

for i in $*
do
	case $i in
	-l)		misc="$misc $i"; shift;;
	-c)		defcomp=; misc="$misc $i$2"; shift; shift;;
	-I)		deffont=; misc="$misc $i$2"; shift; shift;;
	-[A-Za-z])	misc="$misc $i$2"; shift; shift;;
	--)		shift; break;;
	-?)		usage; exit 0;;
	esac
done
file="$*"

if [ "Q$file" = Q ]; then
	exec $engine $res $defcomp $deffont $misc
elif [ "$IAM" = pclview -o "$IAM" = xpclview ]; then
	exec $engine $res $defcomp $deffont $misc $file
else
	exec $engine $res $defcomp $deffont $misc <$file
fi
