#!/bin/sh
#
# fmprint -- wrap fmbatch to print documents
# Copyright 1989, Frame Technology Corporation.
#

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

TF=/tmp/Fz$$`hostname`
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
