#!/bin/sh # # bj200if - Print Ghostscript-simulated PostScript on a Canon BJ-200 # Installed in /usr/local/libexec/lpd/bj200if # # Derived from the sample shown in section 11.4.1.3, # Simulating PostScript on Non-PostScript Printers, # in the Advanced Printer Setup page of the FreeBSD Handbook. # # Read first two characters of the file # IFS="" read -r first_line first_two_chars=`expr "$first_line" : '\(..\)'` if [ "$first_two_chars" = "%!" ]; then # # It is PostScript; use Ghostscript to scan-convert and print it. # # Note that PostScript files are actually interpreted programs, # and those programs are allowed to write to stdout, which will # mess up the printed output. So, we redirect stdout to stderr # and then make descriptor 3 go to stdout, and have Ghostscript # write its output there. Exercise for the clever reader: # capture the stderr output from Ghostscript and mail it back to # the user originating the print job. # exec 3>&1 1>&2 /usr/local/bin/gs -dSAFER -dNOPAUSE -q -sDEVICE=bj200 \ -sOutputFile=/dev/fd/3 - && exit 0 # /usr/local/bin/gs -dSAFER -dNOPAUSE -q -sDEVICE=bj200 -sOutputFile=- - \ && exit 0 else # # Plain text so just print it directly; print a form feed # at the end to eject the last page. # # # Treat LF as CR+LF: # printf "\03351" || exit 2 echo "$first_line" && cat && printf "\015" && exit 0 fi exit 2