#! /bin/sh
#
#  @(#)mailp 2.12 91/09/14
#
#  mailp, newsp, filep, digestp, filofaxp, timemanp and timesysp
#  shell script de lancement de mp
#  (mail/news/file/digest/filofax/time-manager/time-system pretty printer)
#
#  Original: Bruno Pillard - October 1988.
#  Modified: Rich Burridge - June 1989.
#  Revisited:  Larry W. Virden - August, September 1990.
#  Revisited:  Bruno Pillard - September 1990.

BIN=$OPENWINHOME/bin

#  NOTE: Banner printing is disabled below, by the inclusion of the -h
#        switch to the lpr command. Most of the information that typically
#        appears on the banner sheet, is output in the mp banners. If you
#        wish to enable banner printing, then you should remove the -h switch.

BANNER=
FILES=
FLAGS=
STDIN=

case $0 in
        *mailp)    PROG="mp"     ;;
        *newsp)    PROG="mp -a"  ;;
        *digestp)  PROG="mp -d"  ;;
        *filep)    PROG="mp -o" STDIN=-sstdin ;;
        *filofaxp) PROG="mp -f"  ;;
        *timemanp) PROG="mp -tm" ;;
        *timesysp) PROG="mp -ts" ;;
        *)      echo Unknown pretty printer: $0
                exit;;
esac

while [ $# -gt 0 ]
do
        case    "$1" in
        -s*)
                if [ "$1" = "-s" ] ; then
                        FLAGS="$FLAGS -s \"$2\""
                        shift
                else
                        FLAGS="$FLAGS \"$1\""
                fi
                STDIN=
                ;;
        -h)
                BANNER=-h
                ;;
        -F | -l)
                FLAGS="$FLAGS $1"
                ;;
        * )     FILES="$FILES \"$1\""
                ;;
        esac
        shift
done

if [ -d /usr/spool/lp ] ; then
	PRINT_CMD="lp -d${LPDEST:-postscript} -t"
else
	PRINT_CMD="lpr -P${PRINTER:-ps} -J"
fi

if [ -z "$FILES" ] ; then
        eval ${BIN}/${PROG} ${STDIN} ${FLAGS} | \
	eval ${PRINT_CMD}stdin ${BANNER}
else
        for FILE in $FILES ; do
                eval ${BIN}/${PROG} ${FLAGS} ${FILE} | \
		eval ${PRINT_CMD}${FILE} ${BANNER}
        done
fi

exit 0
