#!/bin/sh
# 4.2BSD line printer spooler interface for PostScript/TranScript printer
# this is the printcap/lpd-invoked top level filter program for ALL file types
# Copyright (c) 1985,1987 Adobe Systems Incorporated. All Rights Reserved. 
# GOVERNMENT END USERS: See Notice file in TranScript library directory
# -- probably /usr/lib/ps/Notice
# RCSID: $Header: /afs/athena.mit.edu/user/d/a/darrin/Private/src/transcript-v2.1/RCS/psif,v 1.2 92/09/24 10:25:35 darrin Exp Locker: darrin $

PATH=/bin:/usr/bin:/usr/ucb
export PATH

prog=`basename $prog`

# set up initial undefined variable values
width= length= indent= login= host= afile= 
prog=$0
cwd=`pwd`
pname=`basename $cwd`

# define the default printer-specific and TranScript
# configuration options, these may be overridden by
# real printer-specific options in the .options file

PSLIBDIR=/usr/athena/lib/ps
REVERSE=
VERBOSELOG=1
BANNERFIRST=1
BANNERLAST=0
BANNERPRO=$PSLIBDIR/banner.pro
DUPLEXPRO=/var/hp/duplex.pro
LPS40BANNERPRO=$PSLIBDIR/lps40banner.pro
LAPS=/usr/lib/dnet/lps40/laps
PSTEXT=$PSLIBDIR/pstext
PSBANNER=$PSLIBDIR/psbanner
PSCOMM=/var/hp/hpcomm

export PSLIBDIR VERBOSELOG BANNERFIRST BANNERLAST BANNERPRO LPSBANNERPRO REVERSE PSTEXT LAPS DUPLEXPRO

# load the values from the .options file if present
test -r ./.options && . ./.options

# parse the command line arguments, most get ignored
# the -hhost vs. -h host is due to one report of someone doing it wrong.
# you could add or filter out non-standard options here (-p and -f)

while test $# != 0
do	case "$1" in
	-a*)	account=`expr $1 : '-.\(.*\)'` ;;
	-m*)	mediacost=`expr $1 : '-.\(.*\)'` ;;
	-c)	;;
	-w*)	width=$1 ;;
	-l*)	length=$1 ;;
	-i*)	indent=$1 ;;
	-x*)	width=$1 ;;
	-y*)	length=$1 ;;
	-n)	user=$2 ; shift ;;
	-n*)	user=`expr $1 : '-.\(.*\)'` ;;
	-h)	host=$2 ; shift ;;
	-h*)	host=`expr $1 : '-.\(.*\)'` ;;
	-P)	pname=$2 ; shift ;;
	-P*)	pname=`expr $1 : '-.\(.*\)'` ;;
	-*)	;; 
	*)	afile=$1 ;;
	esac
	shift
done

PATH=$PSLIBDIR:$PATH
export PATH

# now exec the format-specific filter, based on $prog
# if - communications filter [default]
# of - banner filter [execed directly]
# nf - ditroff, tf - troff (CAT), gf - plot
# vf - raster, df - TeX DVI, cf - cifplot, rf - fortran

prog=`basename $prog`

args="-p $prog -n $user -h $host ${account+-a ${account}} ${mediacost+-m ${mediacost}}"

case $prog in
	psiflps40) comm="lps40comm -P $pname $args $afile" ;;
	*) comm="$PSCOMM -P $pname $args $afile"
esac

case $prog in
	psif| psiflps40) exec $comm ;;
	psof) exec $PSBANNER $pname ; exit 0 ;;
	psoflps40) exec lps40psbanner $pname ; exit 0 ;;
	psnf) psdit | $comm ;;
	pstf) pscat | $comm ;;
	psgf) psplot | $comm ;;
	psvf|pscf|psdf|psrf) echo "$prog: filter not available." 1>&2  ;
			psbad $prog $pname $user $host | $comm ;;
esac

