#! /bin/sh
# sh/psroff.bsd
# Copyright 1985,1987 Adobe Systems Incorporated. All rights reserved.
# GOVERNMENT END USERS: See notice of rights in Notice file in TranScript
# library directory -- probably /usr/lib/ps/Notice
# RCSID: $Header: /afs/dev.mit.edu/source/repository/third/transcript/sh/psroff.bsd,v 1.2 1997/06/24 17:46:55 ghudson Exp $
#
# run ditroff in an environment to print on a PostScript printer
#
# psroff - ditroff | psdit [| lpr]
#
PATH=/bin:/usr/bin:$PATH       # Make sure we get system programs.
export PATH

# The program installed as "troff" on Athena (and most vendor OSs) is
# actually ditroff.  If you want real troff, go buy yourelf a PDP-11.
ditroff=troff
psdit=psdit
nospool= dopt= fil= spool= dit= dioutput=
printer=-P${PRINTER-PostScript}
family=Times
fontdir=/mit/psutils/arch/i386_linux24/share/ps/ditroff.font
while test $# != 0
do	case "$1" in
	-d)	dioutput=1 ;;
	-t)	nospool=1 ;;
	-Tpsc)	;;
	-T*)	echo only -Tpsc is valid 1>&2 ; exit 2 ;;
	-F)	if test "$#" -lt 2 ; then
			echo '-F takes following font family name' 1>&2
			exit 1 
		fi
		family=$2 ; shift ;;
	-F*)	echo 'use -F familyname' 1>&2 ;
		exit 1 ;;
	-D)	if test "$#" -lt 2 ; then
			echo '-D takes following font directory' 1>&2
			exit 1 
		fi
		fontdir=$2 ; shift ;;
	-D*)	echo 'use -D fontdirectory' 1>&2 ;
		exit 1 ;;
	-#*|-h|-m|-z)	spool="$spool $1" ;;
	-P)	printer="-P$2" ; shift ;;
	-P*)	printer=$1 ;;
	-C)	spool="$spool $1 $2" ; shift ;;
	-J)	spool="$spool $1 $2" ; jobname=$2 ; shift ;;
	-)	fil="$fil $1" ;;
	-*)	dopt="$dopt $1" ;;
	*)	fil="$fil $1" ; jobname=${jobname-$1} ;;
	esac
	shift
done
if test "$jobname" = "" ; then
	spool="-J Ditroff $spool"
fi
spool="lpr $printer $spool"
if test "$fil" = "" ; then
	fil="-"
fi
dit="$ditroff -Tpsc -t -F$fontdir/$family $dopt $fil "
psdit="$psdit -F$fontdir/$family"

if test "$dioutput" = "1" ; then
	$dit
elif test "$nospool" = "1" ; then
	$dit | $psdit
else
	$dit | $psdit | $spool
fi
