#!/bin/sh
#
# lp interface for plotters that need to hold the line open
#
# $Revision: 1.5 $
# $Date: 1993/12/08 02:56:32 $
#
# Configurable paramters:
#
# BAUDRATE	Sets the baud rate for tty printers
#
# Info for administration tools:
# NAME=Generic Serial Plotter, DEVICE=SERIAL
NAME=
TYPE=Dumb

# Change the following to set up defaults
BAUDRATE=9600

#
# Grab command line arguments
printer=`basename $0`
seqid=$1
name=$2
title="$3"
copies=$4
options="$5"
shift; shift; shift; shift; shift
files="$*"

#
# Initialize port parameters
#
# Hold port open
ok=0
devpath=`cat /var/spool/lp/member/$printer`
device=`basename $devpath`
filename=/tmp/.lp.$printer.$device
if [ -f $filename ];
then
	pid=`cat $filename 2> /dev/null`
	if ps -p $pid > /dev/null;
	then
		ok=1
	fi
fi
if [ $ok = 0 ]
then
	sleep 15768000 <&1 2> /dev/null &
	echo $! > $filename
fi

# Set up tty
stty sane $BAUDRATE <&1

(
i=1
while [ $i -le $copies ]
do
	for file in $files
	do
		cat "$file" 2>&1
	done
	i=`expr $i + 1`
done
) | cat $options

exit 0
