#!/bin/sh
#
#
#
# Shell script to bundle the psfx80 Epson FX80 printer filter to 
# the network printer program lp(1) so that Epson FX80 output can be
# printed directly via lp(1) with one command.
#
# This utility is called via the lp printer emulation when the
# specified SunPC lpt port is assigned to 'Printer' Epson_FX80
#
# usage: Epson_FX80 <lp(1) flags>
#
#     Copyright (c) 1991, Sun Microsystems, Inc.  All Rights Reserved
#     Sun considers its source code as an unpublished, proprietary
#     trade secret, and it is available only under strict license
#     provisions.  This copyright notice is placed here only to protect
#     Sun in the event the source is deemed a published work.  Dissassembly,
#     decompilation, or other means of reducing the object code to human
#     readable form is prohibited by the license agreement under which
#     this code is provided to the user or company in possession of this
#     copy.
 
#     RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
#     Government is subject to restrictions as set forth in subparagraph
#     (c)(1)(ii) of the Rights in Technical Data and Computer Software
#     clause at DFARS 52.227-7013 and in similar clauses in the FAR and
#     NASA FAR Supplement.

# This script DOES rely on external environment variables. 
# It assumes that:
# SUNPCHOME has been set and that the following utility program can be found
#         in $SUNPCHOME/bin:
#		psfx80 - dos Epson Fx80 filter
#		/usr/bin/lp(1) - SunOS network printer program lp(1)
#
# In addition it assumes:
#	all flags are for lp and are correct in their useage.
#
# okay lets parse off the argurments, 
# and make sure we have everything we need
#

ARGS=$*

#
# check to make sure we have everything that we need

if test -x $SUNPCHOME/bin/psfx80
then
	:
else
	echo "Epson_FX80:  error: $SUNPCHOME/bin/psfx80: does not exist or is not executable"
	echo "             SUNPCHOME may be set incorrectly or"
	echo "             SUNPCHOME it may be installed incorrectly"
	exit 1
fi

if test -x /usr/bin/lp
then
	:
else
	echo "Epson_FX80:  error: /usr/bin/lp: does not exist or is not executable"
	exit 1
fi

if test -x /usr/bin/lpstat
then
	:
else
	echo "Epson_FX80:  error: /usr/bin/lpstat: does not exist or is not executable"
	exit 1
fi

#check for -P <printer>
while [ $# -gt 0 ]; do
	#echo $0 $*
	if [ $1 = "-d" ] 
	then
		lpstat $1 $2 1> /dev/null 2>&1
		if [ $? -ne 0 ] 
		then
			echo "Epson_FX80: unknown printer $1 $2"
			exit 1
		fi
	fi
	shift
done

$SUNPCHOME/bin/psfx80 | /usr/bin/lp $ARGS


