#!/bin/sh
#
# fmprint -- wrap fmbatch to print documents
# Copyright (c) 1989-1993 Frame Technology Corp. All rights reserved.
#
# $Id: fmprint,v 1.3 1994/02/04 22:52:24 lss Exp $
# 

[ $# -gt 0 ] || {
	echo "Usage: `basename $0` [-p printopts] [fileorbook ...]" >&2
	exit 3
}

# Add check if on non-SVR4 machine then use hostname instead of uname -n
# in case hostname is longer than 9 letters
case `$FMHOME/bin/scripts/fmarch` in
sunxm.s5.sparc|moto.s5.m88k|sgi.irix.mips) TF=/tmp/Fz$$`uname -n`;;
*) TF=/tmp/Fz$$`hostname` ;;
esac

trap "rm $TF" 0
trap "exit 1" 1 2 3 4 15
>$TF

FLAGS="-noerrorquit" a= printopts=

# Commands.
QUIT=Quit OPEN=Open PRINT=Print

#
# First transform the argument list into a pile of fmbatch commands
# stored in the file $TF
#
while [ $# -gt 0 ]; do
	case $1 in
	-i*)
		FLAGS="$FLAGS $1"
		;;
	-p*)
		shift
		[ $# -gt 0 ] || {
			echo "Usage: `basename $0` [-p printopts] [fileorbook ...]" >&2
			exit 3
		}
		oprintopts="$printopts"
		printopts="\"$1\""
		[ -z "$oprintopts" ] || echo "$QUIT $oprintopts" >>$TF
		echo "$OPEN $printopts" >>$TF
		;;
	*)
		echo "$OPEN \"$1\"" >>$TF
		echo "$PRINT \"$1\" $printopts" >>$TF
		echo "$QUIT \"$1\"" >>$TF
		a=T		# a file needs printing
		;;
	esac
	shift
done

#
# If there are files to be printed, run fmbatch with our script.
#
[ $a ] && fmbatch $FLAGS <$TF
