#!/bin/sh
#
# convert ps to the format required by the printer on this queue
#
# if the printer is a PostScript printer, just cat it through
# if the printer uses ghostscript, we'll run it now
# if the printer is neither, we die (with good message to someone)
#

#
# read in PostScript configuration settings
#
source ${SPOOLDIR}/postscript.cfg

#
# see if we should reverse order
#
# support will be added for this in the future
# psorder needed and is part of netatalk, which we dont currently ship
#

#
# if the driver is "POSTSCRIPT" it means the printer handles Postscript
# natively, no need to run gs.
# if the driver is "TEXT" then it means the printer cannot handle PS input
#
if [ "$GSDEVICE" = "POSTSCRIPT" ]; then
   cat -
elif [ "$GSDEVICE" = "TEXT" ]; then
   echo "Error - ps-to-printer.fpi - this printer cannot print postscript"
   echo "                            and ghostscript does not have support"
   exit 1
else
#  we're using ghostscript
   gs -q -sDEVICE=$GSDEVICE \
      -r$RESOLUTION \
      -sPAPERSIZE=$PAPERSIZE \
      -dNOPAUSE \
      -dSAFER \
      -sOutputFile=- \
      $COLOR \
      $EXTRA_GS_OPTIONS \
      -
fi

#
#
#   see if we need to send a form feed to eject the page from printer
#
    if [ "$PS_SEND_EOF" = "YES" ]; then
      printf "\014"
    fi

exit 0
