#!/bin/bash
#
# /usr/lib/lpdfilter/filter/ps2ps
#
# filter used by /usr/lib/lpdfilter/bin/if
#
# Copyright 2001 SuSE GmbH, Nuernberg Germany
#
# Author: Werner Fink <feedback@suse.de>
#
# Comment: this script is required to make printing of of other
#          encodings as ISO 8859-1 possible (Euro symbol, latin 2)
#

#
# 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

case "$encoding" in
    *8859-1|*latin1)
	# no additional filter required
	exec -a cat cat ;;
    *)
	#
	# Check for our filter program
	#
	type -p ogonkify &> /dev/null || fault_filetype ogonkify

	#
	# Check for encoding
	#
	case "$encoding" in
	    *8859-2|*latin2)		lat="-e L2" ;;
	    *8859-3|*latin3)		lat="-e L3" ;;
	    *8859-4|*latin4)		lat="-e L4" ;;
	    *8859-9|*latin5)		lat="-e L5" ;;
	    *8859-10|*latin6)		lat="-e L6" ;;
	    *8859-13|*latin7)		lat="-e L7" ;;
	    *8859-15|*latin9|*euro)	lat="-e L9 -E"
	esac

	#
	# Check for creator
	#
	case "$creator" in
	    *netscape*|*mozilla*)	lat="$lat -AT -N"  ;;
	    *mosaic*)			lat="$lat -AT -M"  ;;
	    *wind/u*xprinter*)		lat="$lat -AT -SO" ;;
	    *applixware*)		lat="$lat -AT -AX" ;;
	    *fig2dev*)			lat="$lat -AT -F"
	esac

	#
	# run the command on stdin
	#
	exec -a ogonkify ogonkify ${lat:+$lat}
esac
