#!/bin/bash
#
# /usr/lib/lpdfilter/filter/tiff2ps
#
# filter used by /usr/lib/lpdfilter/bin/if
#
# Copyright 2000 SuSE GmbH, Nuernberg Germany
#
# Author: Werner Fink <feedback@suse.de>
#

#
# Activate debugging if requested.
#
if test "$DEBUG" = "medium" -o "$DEBUG" = "high" ; then
    # bash should be verbose
    set -x
    # Redirect stderr to a file
    exec 2> $(mktemp /tmp/lpdfilter.${0##*/}-$$.XXXXXX) || exit 2
fi

#
# Get our environment
#
. /usr/lib/lpdfilter/global/signals
. /usr/lib/lpdfilter/global/functions
type -p readpc   &> /dev/null || export PATH=/usr/lib/lpdfilter/bin:${PATH}
type -p xpmtoppm &> /dev/null || export PATH=${PATH}:/usr/X11R6/bin

#
# Check for our filter program
#
type -p tifftopnm &> /dev/null || fault_filetype tifftopnm
if test "${color:=no}" = "no" ; then
    type -p ppmtopgm &> /dev/null || fault_filetype ppmtopgm
fi
type -p pnmtops  &> /dev/null || fault_filetype pnmtops

#
# media type translation for pnmtops
#
. /etc/lpdfilter/pnmtopsrc

#
# run the command on stdin
#
exec 0< <(exec -a tifftopnm tifftopnm)
if test "${color:=no}" = "no" ; then
    exec 0< <(exec -a ppmtopgm ppmtopgm)
fi
exec -a pnmtops pnmtops ${dpi:+-dpi $dpi} ${size:+$size}
