#!/usr/bin/sh
#  $Source: /hpux/shared/supp//usr/src/cmd/lp/./model/HPGL2,v $
#  $Revision: 72.4 $

# HPGL2:  lp interface for HP7550A, HP7596A, HP7570A plotter.
#
#=====================================================================
# OPTIONS RECOGNIZED:
#
# Do not initialize
#	ni		do not initialize Plotter
#				(default initialize)
# Do not eject a page at the end of the plot
#	np		do not eject page
#				(default eject)
#=====================================================================

plotfilter=/usr/lbin/plotdvr 
log=/var/adm/lp/log

if [ -z "$LANG" ]
then
	LANG="C"
	export LANG
fi

# save the arguments to the model
plotter=`basename $0`
reqid=$1
user=$2
title=$3
copies=$4

# get device file names
devicefile="/etc/lp/member/$plotter"
devicename=`cat $devicefile | line`
interfacename="/etc/lp/interface/$plotter"

# Set up RS-232C interface if this is a tty port
if [ -t 1 ]
then
	stty 9600 opost onlcr -parenb cs8 ixon -istrip clocal tab3 <&1 2>/dev/null
fi

# Determine which options have been invoked
initialize=""
inputfile="def"
send_PG="true"

for i in $5
do
    case "$i" in
    -ni | ni)  # do not initialize
	initialize="-i";;

    -np | np) # do not eject a page
	send_PG="false";;

    esac
done

# Handle disable and cancel traps.
trap "trap 15;kill -15 0;exit 0" 15

# Assume that the rest of the arguments are files
shift; shift; shift; shift; shift
files="$*"

# plot the spooled file

i=1
while [ $i -le $copies ]
do
	for file in $files
	do
		case "$inputfile" in
			def)	$plotfilter -l$reqid -u$user -e\
				$initialize $file <$devicename 2>>$log;;
			*);;
		esac
		if $send_PG
		then
		    echo ";PG;\n"
		fi
	done
	i=`expr $i + 1`
done

# Insure all buffers are flushed to plotter
if [ -t 1 ]
then
	stty 9600 opost onlcr -parenb cs8 ixon -istrip clocal tab3 <&1 2>/dev/null
fi

exit 0

