#! /usr/bin/ksh
#
# ident "@(#)bblpcmd.sh	1.5 01/04/27 SMI"
#
# Copyright (c) 2001 by Sun Microsystems, Inc.
# All rights reserved.
#

. /opt/SUNWbb/printing/lib/print_globals
. ${printDir}/msgs/print_msgs

#
# First test to see if lpsched is running.
# If running, need to break up lp cmd as banner title requires
# to be quoted if there are blanks in the title. Also if no banner
# title, need to remove from cmd as causes problems. 
# If not running, exit. 
#
check_sched 
if (( $? != 0 )); then
    exit 1
fi

FILE=`echo $@ | awk '{ print $NF }'`

while getopts cd:n:t: opt; do
    case $opt in
        c) COPY="-c" ;;
        d) DEST="-d $OPTARG" ;;
        n) NUM="-n $OPTARG";;
        t) TITLE="-t \"$OPTARG\"";;
        \?) $BBLOGGER -c $BBCOMPONENT -e lpError \
	     -s Red "Error: $lp_msg"
           exit ;;
    esac
done

if [[ -n ${TITLE} ]]; then
        /usr/bin/lp ${COPY} ${NUM} "${TITLE}" ${DEST} ${FILE}
else
        /usr/bin/lp ${COPY} ${NUM} ${DEST} ${FILE}
fi

exit 0

