#!/bin/sh # # ghostscript filter # written by Hidenori Ishikawa # # $Id: lpfilter,v 1.6 2002/06/11 19:39:35 hideishi Exp $ # PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin # config settings file *REQUIRED* CONFIG=`dirname $0`/lp.cfg # path to GhostScript GS=/usr/local/bin/gs # defaults SPOOL=/var/spool/output/lpd/lp GSDEVICE=lips4 RESOLUTION=600x600 COLOR=-dBitsPerPixel=1 PAPERSIZE=a4 EXTRA_GS_OPTIONS= PS_SEND_EOF=NO GSPREPROCESS= GSPOSTPROCESS= # functions exit_post_magic() { echo "SPOOL empty or invalid to process." # clean out spool file rm -f ${SPOOLFILE} exit 1 } # load settings from configfile . ${CONFIG} # first check about file magics TEMPNAME=`basename $0` SPOOLFILE=`mktemp -q ${SPOOL}/${TEMPNAME}.XXXXXX` || exit cat - > ${SPOOLFILE} MAGIC=`file ${SPOOLFILE} | tr 'A-Z' 'a-z'` MAGIC=${MAGIC#*: } # decompression routines case ${MAGIC} in *packed*|*gzip*) DECOMPRESS="| gzip -dc" MAGIC=`cat ${SPOOLFILE} ${DECOMPRESS} | file - | tr 'A-Z' 'a-z'` MAGIC=${MAGIC#*: } ;; *bzip2*) DECOMPRESS="| bzip2 -dc" MAGIC=`cat ${SPOOLFILE} ${DECOMPRESS} | file - | tr 'A-Z' 'a-z'` MAGIC=${MAGIC#*: } ;; *) DECOMPRESS= ;; esac # extra filters case ${MAGIC} in *empty*) exit_post_magic ;; "pc bitmap data"*) FILTER="| bmptopnm | pnmtops" ;; "gif image data"*) FILTER="| giftopnm | pnmtops" ;; "jpeg image data"*) FILTER="| djpeg | pnmtops" ;; "tiff image data"*) FILTER="| tifftopnm | pnmtops" ;; "sun raster image data"*) FILTER="| rasttopnm | pnmtops" ;; pgm*|pbm*|ppm*) FILTER="| pnmtops" ;; png*) FILTER="| pngtopnm | pnmtops" ;; postscript*) FILTER= ;; "troff or preprocessor"*) FILTER="| grog -Tps -msafer -" ;; "iso-8859 text"*) FILTER="| a2ps-j -nh -ns -nt -p" ;; *ascii*|*text*|*english*|*script*) FILTER="| a2ps -q -1 -B --footer='%s./%s#' --borders=no" ;; *data*|*escape*|*pcl*) FILTER= ;; *) exit_post_magic ;; esac # ghostscript settings if [ x"${GSDEVICE}" = "xPOSTSCRIPT" ]; then GSCMD= else GSCMD="| ${GS} -q -dNOPAUSE -dSAFER -dBATCH \ -r${RESOLUTION} \ -sDEVICE=${GSDEVICE} \ -sPAPERSIZE=${PAPERSIZE} \ -sOutputFile=- \ ${COLOR} \ ${EXTRA_GS_OPTIONS} \ - quit.ps" fi # finally, do everything eval "${GSPREPROCESS}" eval "cat ${SPOOLFILE} ${DECOMPRESS} ${FILTER} ${GSCMD}" 2> /dev/null eval "${GSPOSTPROCESS}" # see if we need to send a form feed to eject the page from printer if [ x"${PS_SEND_EOF}" = "xYES" ]; then printf '\004' fi # clean out spool file rm -f ${SPOOLFILE} exit 0