Listing 4
#!/bin/sh

# Copyright (C) 1992 QMS, Inc
####################################
#### Modified to Do Print Quota ####
####################################
PRINTERNAME="eb120_colorps"
PNAME="decs-color"
COLORSPOOL="/var/spool/lp/logs"
QMSSPOOL=$COLORSPOOL/$PRINTERNAME
TotalPg=0
####################################
####  End of Modification       ####
####################################

#
# Make sure we clean up after ourselves if we receive an interrupt
#
trap 'rm $PROLOGUE ; echo "Spooler terminated communication" >> $LOG; exit 2' 2
trap 'rm $PROLOGUE ; echo "Filter received a signal! Quit!" >> $LOG; exit 2' 1 3  15

####################################
#### Modified to Do Print Quota ####
####################################
PATH=/bin:/usr/bin:/etc:/usr/etc:/usr/ucb:/etc/lp/interfaces
####################################
####  End of Modification       ####
####################################
export PATH


#
# Create temp file names
#

PROLOGUE=/tmp/$$qprologue

#
# Set default variables
#

HOST=`uname -n`
DATE=`date`

    # Sleep time (in seconds) to wait for emulation timeout (Parallel or
    # Serial Comm)
EM_TIMEOUT=5

#
# Get user, title, and copies from the command line
#

USER=$2
TITLE=$3
COPIES=$4
#####################
# Begin Quota Check #
#####################
#
# Convert Upper Case to Lower Case
#
user=`echo $USER|cut -d "!" -f2`
lowername=`echo $user|nawk '{ print tolower($1) }'`
user=$lowername
printer=$PRINTERNAME
#
# Include the Printer quota library
#
. PrnQt_lib.sh
#
# Check users again NIS+ table
#
Usermatch
#
if [ -f $UserPrnQtFile ]
then
  ChkPrnQt
else
  InitUserPrnQtFile
fi
#####################
# End Quota Check   #
#####################

# Shift off the now useless arguments to get to the filenames
#
shift 5

FILES=$*

#
# Configuration dependent variables
#

DOC_SUPPORTED=yes
COMM_OPTION=tcp/ip
HOSTNAME=$PNAME
PORT=35
QEF=/usr/bin/qef
BAUD=9600
LOG=$QMSSPOOL/log
STATFILE=$QMSSPOOL/$PRINTERNAME.status
SETUPFILE=$QMSSPOOL/$PRINTERNAME.setup
BJOBFILE=$QMSSPOOL/back.job
BLOGFILE=$QMSSPOOL/back.log
JOBFILE=$QMSSPOOL/job.status
LOGFILE=$QMSSPOOL/log.status
REQUEST_TIME=5
PARAMETERS=" -s $STATFILE -h $HOSTNAME  -b $BJOBFILE  -B $BLOGFILE  -j $JOBFILE  -l $LOGFILE  -u  -g $REQUEST_TIME" 
PREPROLOGUE=$QMSSPOOL/$PRINTERNAME.pro
FILQEF="cat -"
CATQEF=$PROLOGUE

# Copyright (C) 1992 QMS, Inc

#
# Check LOG for writability.  Exit if we can't write to it.
#

if [ ! -w $LOG ]
then
    echo "Can't open log file $LOG for writing." | mail root $USER
    rm -f $PROLOGUE
    exit 2
fi


#
# Begin the log entry
#

echo `date` >> $LOG
echo "qfilter: Initiating Send of File" >> $LOG

touch $PROLOGUE
if [ $DOC_SUPPORTED = yes ]
then
#
# Create the DCL prologue file
#

echo "%!" >> $PROLOGUE
echo "%%For: $USER" >> $PROLOGUE
echo "%%Date: $DATE" >> $PROLOGUE
fi

#
# Check for a setup file. Append it to the PROLOGUE file if it exists.
#

if test -r $SETUPFILE
then
    cat $SETUPFILE >> $PROLOGUE
fi

#
# Check for a preprologue file. Append it to the PROLOGUE file if it exists.
#

if test -r $PREPROLOGUE
then
    cat $PREPROLOGUE >> $PROLOGUE
fi

#
# Log the fact that we are about to begin file transfer
#
echo `date` >> $LOG
echo "qfilter: Beginning File Transfer" >> $LOG

#
# Send the data (via the correct protocol) to the printer
#

if [ $COMM_OPTION != tcp/ip ]
then

    #
    # Communication Protocol is Serial or Parallel
    #
    # First, initialize the printer port.
    #
    if [ $COMM_OPTION = parallel ]
    then
	stty -parenb ixon ixoff raw <&1 2>> $LOG
    else
	stty -parenb ixon ixoff raw -echo hupcl $BAUD <&1 2>> $LOG
    fi

    #
    # Send each file to the printer port, sleeping long enough for the
    # printer comm to time out, so that jobs aren't concatenated
    #

    for cfile in $FILES
    do
	( cat $CATQEF $cfile ) 2>> $LOG | $FILQEF
        if [ $COMM_OPTION = parallel ]
        then
            echo "0statusdict begin 1 200 setemulation end\c" 
        else
            echo "0statusdict begin 0 200 setemulation end\c" 
        fi
        sleep $EM_TIMEOUT
    done

else

    #
    # Communication Protocol is Ethernet
    # Send each file to printer via the QMS Ethernet Filter
    #

    for cfile in $FILES
    do

        ( cat $CATQEF $cfile ) 2>> $LOG | $FILQEF | ( $QEF $PARAMETERS ) 1>> $LOG 2>&1
        STATUS=$?

        #
        # Check for problems with the above transaction and tell the spooler
        # there was a problem if one was found.
        #

        if [ $STATUS != 0 ]
        then
	    rm $PROLOGUE
	    echo "qfilter: Filter $QEF Could Not Complete Data Transfer" >> $LOG
	    echo
	    exit 2
        fi
        #######################################
        ####       Read Page Printed       ####
        #######################################
        PAGES=`awk -F\; '/pagecount:/{print $2}' $JOBFILE|cut -d":" -f2` 
        TotalPg=`expr $TotalPg + $PAGES`
        #######################################
        ####  End of Reading Page Printed  ####
        #######################################
    done

fi
############################
#   Update Print Quota     #
############################
UpdatePrnQtFile $TotalPg 20
############################
#   Update Print Quota     #
############################
#
# Clean up the temp files, log that we've finished, and exit happily
#

echo `date` >> $LOG
echo "qfilter: File Transfer Complete" >> $LOG
echo >> $LOG
rm $PROLOGUE 2> /dev/null

exit 0

