#!/bin/ksh

#############################################################################

## APPX_PRINT

##

## This script will submit the Appx report specified on the

## the command line to print spooler.

##

## The format of the command line is expected to be:

##

##appx_print [-config=<config_file_name>] [options*] printfiles*

##

## Where the "-config=<config_file_name>", if present, specifies

## a configuration file to be used when submitting the given

## printfiles to the spooler.

##

## A configuration file is expected to be a flat ascii file which

## should contain a list of spooler options, one per line, in

## the format:

##

##-<option>=<value>

##

## The options may also be specified on the command line. Options are

## processed in order of appearance, whether they come from a configuration

## file or from the command line. The value of an option will be the last

## one processed.

##

## Where "-<option>" is one of the following:

##

##-mode=

##-disposition=

##-copies=

##-notify=

##-banner=

##-format=

##-priority=

##-date=

##-user=

##-printer_name=

##-printer_id=

##-printer_ctl=

##-printer_queue=

##-form_name=

##-form_id=

##-form_ctl=

##

#############################################################################

#############################################################################

## NAME: PROCESS_CONFIG( config_file_name )

##

## DESCRIPTION: This function will read spooler options from the named

## configuration file.

##

## PARAMETERS: $1 = Pathname of configuration file to be parsed

##

PROCESS_CONFIG ()

{

##

## Open the configuration file as file descriptor #3

##

exec 3< $1

##

## Now read through the configuration file, putting each line in $CFG_REC

##

while read CFG_REC &3

do

##

##Treat lines beginning with a "#" as comments

##

if [ "$CFG_REC" = "\#*" ]

then

continue

fi

##

##Process this line as if it were a command line argument

##

PROCESS_OPTION $CFG_REC

done

##

## Close the configuration file

##

exec 3&-

##

## Delete the configuration file

##

rm $1

}

#############################################################################

## NAME: PROCESS_OPTION( option )

##

## DESCRIPTION: This function will parse the given spooler option

##

## PARAMETERS: $1 = Spooler option to be processed

##

PROCESS_OPTION ()

# echo "PROCESS_OPTION: $1" > $LOGFILE # turn on to capture each Option

{

case "$1" in

-mode*)

# This option contains the print mode for

# this print job. The value will be one of the

#following:

#<blank>

#HOLD - queue but don't print files

#SPOOL - queue for printing ASAP

# KEEP - do not queue files for printing

#ONLINE - bypass spooler and print directly

# to device (future)

#

PRINT_MODE=`echo $* | cut -f 2 -d =`

;;

-disposition*)

# This option specifies what to do with the print

# files after they have been printed. The following

#values should be expected:

#<blank>

#SCRATCH- delete the file after printing

#SAVE- retain the file after printing

#REQUEUE - requeue the file after printing

#

PRINT_FILE_DISPOSITION=`echo $* | cut -f 2 -d =`

;;

-copies*)

#This option specifies how many copies the

#user would like to print. It contains the

# value of the "PRINT COPIES" PDF.

#

PRINT_COPIES=`echo $* | cut -f 2 -d =`

;;

-notify*)

# This option is an interpretation of the

# "PRINT NOTIFY USER" PDF. It will contain

#either "Yes", "No", or blank.

#

PRINT_NOTIFY_USER=`echo $* | cut -f 2 -d =`

;;

-banner*)

#This option contains an interpretation of the

#"PRINT BANNER" PDF. It will contain either "Yes",

#"No", or blank.

#

PRINT_BANNER=`echo $* | cut -f 2 -d =`

;;

-format*)

#This option contains the value of the "PRINT

# FORMAT" PDF. This option is reserved for future

#use.

#

PRINT_FORMAT=`echo $* | cut -f 2 -d =`

;;

-priority*)

#This option contains the value of the "PRINT

# PRIORITY" PDF.

#

PRINT_PRIORITY=`echo $* | cut -f 2 -d =`

;;

-date*)

#This option contains an interpetation of the

#"PRINT SPOOL DATE" PDF. It will be in the form

#CCYYMMDDhhmmssth. This date specifies when the

#user would like the report released to the printer.

#

PRINT_SPOOL_DATE=`echo $* | cut -f 2 -d =`

;;

-user*)

#This option contains the Unix user name

# of the submitter.

#

UNIX_USER=`echo $* | cut -f 2 -d =`

;;

-printer_name*)

#This option contains the value of the "PRINT

#PRINTER ID" PDF, which is the Appx identifier

#for the destination printer.

#

PRINTER_NAME=`echo $* | cut -f 2 -d =`

;;

-printer_id*)

#This option contains the OS name for the destination

#printer. This value comes from the Appx System

#Administration PRINTER file record whose key is

#determined by the "PRINT PRINTER ID" PDF.

#

PRINTER_ID=`echo $* | cut -f 2 -d =`

;;

-printer_ctl*)

#This option contains user-defined options for the

#destination printer. This value comes from the Appx

#System Administration PRINTER file record whose key

#is determined by the "PRINT PRINTER ID" PDF.

#

PRTR_CTL=`echo $* | cut -f 2 -d =`

;;

-printer_queue*)

#This option specifies the name of the queue to which

#the given reports should be spooled. This value comes

#from the Appx System Administration PRINTER file

#record whose key is determined by the "PRINT PRINTER

#ID" PDF.

#

QUEUE_NAME=`echo $* | cut -f 2 -d =`

;;

-form_name*)

#This option contains the value of the "FORM ID" PDF,

# which is the Appx identifier for the desired form.

#

FORM_NAME=`echo $* | cut -f 2 -d =`

;;

-form_id*)

#This option contains the OS name for the destination

#form. This value comes from the Appx System

#Administration FORM file record whose key is

#determined by the "FORM ID" PDF.

#

FORM_ID=`echo $* | cut -f 2 -d =`

;;

-form_ctl*)

#This option contains user-defined options for the

#destination form. This value comes from the Appx

#System Administration FORM file record whose key

#is determined by the "FORM ID" PDF.

#

FORM_CTL=`echo $* | cut -f 2 -d =`

;;

esac

}

##############################################################################

## MAIN

##

## Process the command line arguments, watching for a configuration file.

##

## Stop as soon as we see the first argument which does not begin with a

## hyphen. The remainder of the command line is considered to be a list

## of filenames which we pass straight to the spooler.

##

UMASK=`umask`; umask 00 # store original umask, set to '00'
LOGFILE=/tmp/appx_print.last # create Log file

# LOGFILE=/dev/null # create NO Log file

echo "======" > $LOGFILE # initialize LOGFILE

#echo "======" > $LOGFILE # or append to LOGFILE

umask $UMASK # restore original umask

# set > $LOGFILE # dump current user's environment into LOGFILE
echo > $LOGFILE

echo "...... Parameters passed to 'appx_print' ...... " > $LOGFILE

echo $* > $LOGFILE # record '$*' parameters into LOGFILE

echo > $LOGFILE

PRINTER_NAME= FORM_NAME= PRINT_COPIES= PRINT_NOTIFY_USER= UNIX_USER=

PRINT_PRIORITY= PRINT_MODE= PRINT_FILE_DISPOSITION= PRINT_BANNER=

while [ $# -gt 0 ]

do

case $1 in

##

## Process configuration files

##

-config*)

PROCESS_CONFIG `echo $1 | cut -f 2 -d =`

shift

;;

##

## Process options

##

-*)

PROCESS_OPTION "$1"

shift

;;

##

## This argument is neither an option nor a config file, stop

##

*)

break

;;

esac

done

##

# Do not spool file if print mode is KEEP

if [ "$PRINT_MODE" = "KEEP" ]

then

exit

fi

#

if [ -n "$PRINTER_NAME" ]

then

PRINTER_NAME=-d$PRINTER_NAME

fi

if [ -n "$FORM_NAME" ]

then

FORM_NAME=-f$FORM_NAME

fi

PRINT_COPIES=-n$PRINT_COPIES

# UniQue only wants the 1st position of PRIORITY for CLASS

if [ -n "$PRINT_PRIORITY" ]

then

CLASS=`echo $PRINT_PRIORITY | cut -c 1`

CLASS=-C$CLASS

else

CLASS=

fi

# UniQue notify option

if [ "$PRINT_NOTIFY_USER" = "Yes" ]

then

PRINT_NOTIFY_USER="-m -A$UNIX_USER"

else

PRINT_NOTIFY_USER=

fi

if [ "$PRINT_MODE" = "SPOOL" ]

then

if [ "$PRINT_FILE_DISPOSITION" = "REQUEUE" ]

then

ULP_MODE=-Mre

elif [ "$PRINT_FILE_DISPOSITION" = "SCRATCH" ]

then

ULP_MODE=-Mdel,leave

elif [ "$PRINT_FILE_DISPOSITION" = "SAVE" ]

then

ULP_MODE=-Mleave

else

ULP_MODE=-Mleave

fi

elif [ "$PRINT_MODE" = "HOLD" ]

then

if [ "$PRINT_FILE_DISPOSITION" = "REQUEUE" ]

then

ULP_MODE=-Mhold,re

elif [ "$PRINT_FILE_DISPOSITION" = "SCRATCH" ]

then

ULP_MODE=-Mhold,del,leave

elif [ "$PRINT_FILE_DISPOSITION" = "SAVE" ]

then

ULP_MODE=-Mhold,leave

else

ULP_MODE=-Mhold,leave

fi

else

ULP_MODE=-Mleave

fi

# Banner?

if [ "$PRINT_BANNER" = "Yes" ]

then

ULP_MODE=$ULP_MODE,banner

fi

##

while [ $# -gt 0 ]

do

echo > $LOGFILE; echo "## Final Invocation of 'ulp':"> $LOGFILE

if [ -s $1 ]

then

echo "/usr/spool/uprint/ulp $PRINTER_NAME $FORM_NAME $CLASS $PRINT_NOTIFY_USER $PRINT_COPIES $ULP_MODE -q $1" > $LOGFILE

/usr/spool/uprint/ulp $PRINTER_NAME $FORM_NAME $CLASS $PRINT_NOTIFY_USER $PRINT_COPIES $ULP_MODE -q $1 > $LOGFILE 2&1

elif [ "$PRINT_FILE_DISPOSITION" = "SCRATCH" ]

then

rm $1

fi

echo > $LOGFILE # blank line at end of LOGFILE entry
shift

done

#############################################################################

## Modification History

##

## DATE BY Description

## ------

## 2/11/00 PAT Added /tmp/appx_print.last LOGFILE audit trail.

## 10/03/94 SPF Modified to support UniQue print spooler instead of lp

## 11/13/93 KAD Initial Creation

## 07/26/93 BHW Modified to run under Bourne shell (instead of Korn

## Shell) for portability. No loss of functionality, but

## some of the readability was sacrificed. Many external

## utilities had to be used to compensate for the shell

## "downgrade."

## 07/26/93 BHW Runs correctly under BASH (Bourne Again Shell). There

## are problems with some shells (HP-UX 8.0 /bin/sh) that

## make this version unusable on those platforms.

##

#############################################################################