#! /bin/sh
#
#  Adobe Font Director Printer Script
#
#
#  Henry McGilton -- Trilithon Software.  September 1993.
#
#
#  This printer script executes the functions specified by
#  Adobe Font Director when downloading fonts to printers.
#  Change the printer stuff as required by your own flavour
#  of standard UNIX environment(s).
#
#
#  Uncomment the appropriate line or add new lines for different spoolers.
#
#  spooler=/usr/ucb/lpr -P$2
#
spooler="/bin/lp -d$2"
#
#
#
#  $1 is always the function that the script is to perform.
#  $2 is always the printer to which the final file is to be spooled.
#
#
#  Function = downloading to printer RAM.
#             $3 is the printer password
#             $4 is the name of the file containing
#                the font program to be downloaded
#             $5 is the temporary file into which
#                the downloadable font is constructed.
#

mypath=`dirname $0`

case $1 in
    DownLoadToRAM)
	sed -n -e '1p' $4 > $5
	echo serverdict begin $3 exitserver >> $5
	sed -n -e '2,$p' $4 >> $5
	chmod 644 $5
	$spooler -c $5
	rm $5
    ;;
#
#  Function = downloading to printer Disk.
#             $3 is the name of the font being downloaded to disk.
#             $4 is the name of the file containing
#                the font program to be downloaded
#             $5 is the temporary file into which
#                the downloadable font is constructed.
#
    DownLoadToDisk)    
	sed -e s/NAME_OF_FONT_TO_DOWNLOAD/$3/ $mypath/DownLoadToDisk.ps > $5
	cat $4 >> $5
	chmod 644 $5
	$spooler -c $5
	rm $5
    ;;
#
#  Function = Reporting the names of fonts which have been downloaded.
#             $3 is the name of the file containing a list of
#                fonts which have been downloaded.
#             $4 is the temporary file into which
#                the download report program is constructed.
#
    ReportDownLoad)    
	sed -n -e 1,/NAMES_OF_DOWNLOADED_FONTS/p $mypath/DownLoadReport.ps > $4
	cat $3 >> $4
	sed -n -e '/NAMES_OF_DOWNLOADED_FONTS/,$p' $mypath/DownLoadReport.ps >> $4
	echo $2 $3 $4
	rm -f $3
    ;;
#
#  Function = Printing a file to printer
#
    PrintSample)
	sed -e s/NAME_OF_FONT_TO_SAMPLE/$4/ $3 $mypath/SampleChars.ps | $spooler -c
	rm $3
    ;;
#
#  Function = Listing fonts from a printer.
#
    ListPrinterFonts)
	$spooler $mypath/ListPrinterFonts.ps
    ;;
#
#  Function = Removing fonts from printer RAM.
#             Not implemented.
#
    RemoveFromRAM)
	echo Remove fonts from printer RAM not yet implemented.
    ;;
#
#  Function = Removing fonts from printer Disk.
#             Not implemented.
#
    RemoveFromDisk)
	echo Remove fonts from printer Disk not yet implemented.
    ;;
#
#  Function = Restarting the printer.
#             Not implemented -- needs a printer password.
#
    RestartPrinter)
	echo Restart printer not yet implemented.
    ;;
    *)     echo "Booiiiiing"   ;;
esac
