#!/bin/sh
#
# GFax front end to the 'lpr' command.  This makes it easy to execute
# the wish script with the proper environment.  Also there is no need to
# worry about what kind of 'fax' printer one sets up as this does it all.
#
##############################################################################
#
#
#  Copyright (c) 1999 George A. Farris 
#
#  NO WARRANTY:
#  
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
#  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
#  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-
#  INFRINGEMENT.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 
#  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
#  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECT-
#  ION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
##############################################################################

# get the last argument on the command line
LAST=`eval echo \\\$$#`

RNAME=G$$
OP=
FAX=
SPOOL_DIR=/tmp

BINDIR=/usr/bin
#BINDIR=/usr/local/bin

for i in $*
do
	case $i in
		-P)	OP=true;;
		-Pfax)	FAX=true;;
	esac

	if [ $OP ]
	then
		if [ "$i" = "fax" ]
		then
			FAX=true
		fi
	fi
done

if [ $FAX ]
then

	#if we use lpr in command line mode go here
	if [ -f "$LAST" ]
	then
		cp $LAST $SPOOL_DIR/D.$RNAME
		$BINDIR/gfax $SPOOL_DIR/D.$RNAME
		exit 0
	fi
	# otherwise it is piped in
	cat > $SPOOL_DIR/D.$RNAME
	$BINDIR/gfax $SPOOL_DIR/D.$RNAME
	exit 0
fi

# If it's not a fax pass everything straight through to lpr.dist
# which is the original lpr renamed when gfax is installed.
lpr.dist $@
