#/bin/sh
#
#       Copyright (c) 1997, by Sun Microsystems Inc.
#       All Rights Reserved
#
#pragma ident   "@(#)interface.html     1.2     98/05/22 SM"
#
#       This is an example interface script to help you get an idea of how
# to integrate support for your printer under lp.  This is by no means the
# definitive source for information.  You should look at included interface
# scripts as examples and at the Solaris System Administrators Answerbook.
#
# This script is run as 'lp' on the print server if the job came in via the
# network.  It runs as the submitting user if the job is local.  You should
# also note that the data files are owned by the user running the script.
#
# Command Line Arguments:
#       $0      - .../{printer}
#       $1      - request-id
#       $2      - user
#       $3      - title
#       $4      - copies
#       $5      - options (lp -o)
#       $6+     - file list
# Environment Variables:
#       CHARSET         - the character set to use
#       FILTER          - fast filter to inline on the way to the printer
#       LC_COLLATE      - I18n
#       LC_CTYPE        - I18n
#       LC_MESSAGES     - I18n
#       LC_MONETARY     - I18n
#       LC_NUMERIC      - I18n
#       LC_TIME         - I18n
#       PATH            - default path (/usr/sbin:/usr/bin)
#       SPOOLER_KEY     - used by lp.tell for backchannel to lpsched
#       TERM            - printer type
#       TZ              - our timezone
# File Descriptors:
#       0       - don't recall
#       1       - printer device (use /dev/null for network attached printers)
#       2       - backchannel to lpsched
# Signals:
#
# Exit Codes:
#       0       - success
#       1 - 127 - failure, don't restart
#       128     - don't use
#       >128    - failure, wait or restart
#

if [ $# -lt 5 ] ; then
        echo "wrong number of arguments to interface program" 1>&2
        exit 1
fi


printer=`basename $0`
request_id=$1
user_name=$2
title=$3
copies=$4
option_list=$5

shift 5
files="$*"

stty=

parse () {
        echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
}

nobanner="no"
nofilebreak="no"
inlist=
for i in ${option_list}
do
        case "${inlist}${i}" in

        nobanner )
                nobanner="yes"
                ;;

        nofilebreak )
                nofilebreak="yes"
                ;;

# lp -o key
#       key )
#               key="whatever"
#               ;;

# lp -o key=value
#       key=* )
#               key=`parse ${i}`
#               ;;

# lp -o key='list ...'
#       stty=* )
#               inlist=`expr "${inlist}${i}" : "^\([^=]*=\)"`
#               case "${i}" in
#               ${inlist}\'*\' )
#                       item=`expr "${i}" : "^[^=]*='*\(.*\)'\$"`
#                       ;;
#               ${inlist}\' )
#                       continue
#                       ;;
#               ${inlist}\'* )
#                       item=`expr "${i}" : "^[^=]*='*\(.*\)\$"`
#                       ;;
#               ${inlist}* )
#                       item=`expr "${i}" : "^[^=]*=\(.*\)\$"`
#                       ;;
#               *\' )
#                       item=`expr "${i}" : "^\(.*\)'\$"`
#                       ;;
#               * )
#                       item="${i}"
#                       ;;
#               esac
#
#               #####
#               #
#               # We don't dare use "eval" because a clever user could
#               # put something in an option value that we'd end up
#               # exec'ing.
#               #####
#               case "${inlist}" in
#               key= )
#                       key="${key} ${item}"
#                       ;;
#               esac
#
#               case "${i}" in
#               ${inlist}\'*\' )
#                       inlist=
#                       ;;
#               ${inlist}\'* )
#                       ;;
#               *\' | ${inlist}* )
#                       inlist=
#                       ;;
#               esac
#               ;;
        * )
                echo "unrecognized \"-o ${i}\" option check the option, resubmit if necessary printing continues" 1>&2
                ;;
        esac
done

#
# should create a banner
#

#
# process the files
#

i=1
while [ $i -le $copies ]
do
        for file in $files
        do
                cat $file
        done
        i=`expr $i + 1`
done
exit 0
