#! /bin/sh
# $Id: FMlpr,v 1.3 1993/05/25 01:17:13 dxc Exp $
# Copyright (c) 1989-1993 Frame Technology Corp. All rights reserved.
#
# FMlpr
#
# This script is called by FrameMaker when a file is printed.
#
# The default is to just lpr it with the -r flag, and the -s flag only 
# if the file didn't fit on /tmp (otherwise /tmp fills up too easily)
#
# DEC Ultrix 4.0 users, see comments at the bottom of this script
#

# Load arguments into named variables
. $3/FMlpr.init

case "$PRINTER" in
    *:*)
	# If the printer name matches the pattern 'xxxx:*' then the user
	# is intending the document to be processed by a filter.
	# This can be a fax modem, postscript hacking code, etc.

	# Convert the first part to lowercase, and call the script
	# FMlpr.xxxx with the same arguments as we had, but strip off
	# the xxxx:

	# Example:
	#	FMlpr FAX:415-555-1212:secret faxfile initdir homedir ...
	# calls
	#	FMlpr.fax 415-555-1212:secret faxfile initdir homedir ...

	# Get scriptname to call
	SCRIPTNAME=`echo "$PRINTER" | sed -e 's/:.*//'`

	# Strip off the xxxx: part of the printername
	# (can't use expr since no string args on UnixV)
	PRINTER=`echo "$PRINTER" | sed -e "s/${SCRIPTNAME}://"`
	
	# Now that we've stripped it off, convert it to lowercase
	SCRIPTNAME=`echo $SCRIPTNAME | tr '[A-Z]' '[a-z]'`	

	FMLPR_LOCATION=FMlpr.$SCRIPTNAME
	. $FMINITDIR/FMlpr.finder	

	# If the script exists, execute it.  If it doesn't, strip it
	# off and try again.
	if [ $FMLPR_LOCATION != '' ]; then
	    # Now call the filter, with the new printername
	    # CAUTION: $PRINTER could be null in which case the arguments
	    # will be numbered differently
	    echo "$MYNAME: Calling $FMLPR_LOCATION to process print file $FILE"
	    exec $FMLPR_LOCATION "$PRINTER" "$FILE" $FMINITDIR $HOMEDIR $LOCATIONFLAG $FMBINDIR
	else
	    echo "$MYNAME: Couldn't find FMlpr.$SCRIPTNAME, so ignoring $SCRIPTNAME: option in Printer Name" >&2
	    FMLPR_LOCATION=FMlpr
	    . $FMINITDIR/FMlpr.finder	
	    exec $FMLPR_LOCATION "$PRINTER" "$FILE" $FMINITDIR $HOMEDIR $LOCATIONFLAG $FMBINDIR
	fi
    ;;		


    *)
        # Send the FrameMaker postscript print file to a printer.
	# Some vendors have unique requirements.
	case "$FMARCH" in

	    apollo*)
		# Note: On the Apollo you have three choices of spooling
		# commands.  They are chosen by printer name.  You should
		# modify the names below to correspond to the printer
		# names at your site.
		case "$PRINTER" in
		    # These Apollo printers use UNIX style spooling commands.
		    # Edit this list for your site's printers.
		    lp|lw|ps|postscript|PostScript)
			if [ -f /usr/ucb/lpr ]; then
			    # BSD spooler.
			    if [ "$LOCATIONFLAG" -eq 1 ]; then
				lpr -r -s -P"$PRINTER" "$FILE"
			    else
				lpr -r -P"$PRINTER" "$FILE"
			    fi
			else
			    # SYSV spooler.
			    if [ "$LOCATIONFLAG" -eq 1 ]; then
				lp -d"$PRINTER" "$FILE"
				rm -f "$FILE"
			    else
				lp -c -d"$PRINTER" "$FILE"
				rm -f "$FILE"
			    fi
			fi
		    ;;

		    # These printers use the Aegis prf command for spooling.
		    *)
			if [ $LOCATIONFLAG -eq 1 ]; then
			    prf "$FILE" -pr "$PRINTER" -nc -check
			else
			    prf "$FILE" -pr "$PRINTER" -check
			fi
		    ;;
		esac; # case "$PRINTER" in
	    ;; # apollo

	    hp*)
		lp -c -d"$PRINTER" "$FILE"
		rm -f "$FILE"
	    ;;

	    sunxm.s5.sparc)
		lp -c -d"$PRINTER" "$FILE"
		rm -f "$FILE"
	    ;;

	    m88k*)
		# Motorola suggests using the -of flag so the PostScript
		# file will print on all printers.  Note that there is
		# no "-r" flag; use -c instead to make a copy of the file.
		if [ $LOCATIONFLAG -eq 1 ]; then
		    # Not enough disk space in /tmp so don't make a copy.
		    # No way to determine when file has been printed, so
		    # print files accumulate in $HOME (you can't just
		    # delete the file since lpr returns immediately)
		    lp -of -d"$PRINTER" "$FILE"
		else
		    # Normal case: make a copy of the file so can remove
		    # the original.
		    lp -c -of -d"$PRINTER" "$FILE"
		    rm -f "$FILE"
		fi
	    ;;

	    *)
		########################################################
		# This is the normal(?) case (all other architectures) #
		########################################################
		#
		# For DEC Ultrix version 4.0, you may need to add the
		# "-Dpostscript" option to both of the lpr commands below.

		if [ $LOCATIONFLAG -eq 1 ]; then
		    lpr -r -s -P"$PRINTER" "$FILE"
		else
		    lpr -r -P"$PRINTER" "$FILE"
		fi
	    ;;

	esac  # case $FMARCH in
    ;;
esac
