#!/bin/sh
#	Usage:	atkprint   troff-input-file
#
#	Format and print an ATK document.
#	The shell is sensitive to a number of environment variables:
#
#	LANDSCAPE = yes, the page is oriented in Landscape mode
#		LANDSCAPE seems to be broken. Leave code here, never call it
#	MULTIPAGE = 1, 2, 4, or 8   Number of pages to mash onto one page
#
orientation=0		# Default is portrait
if [ "x$LANDSCAPE" = "xyes" ]; then
	orientation=1	# Landscape
fi

# Check for combinations of MULTIPAGE.
perpage=${MULTIPAGE:-"1"}
if [ "x$Multitwo" = "xyes" ]; then
	perpage="2"	# Force 2 page mode
fi
if [ "x$Multifour" = "xyes" ]; then
	perpage="4"	# Force 4 page mode
fi
multiopt=""
case $perpage in
    2)  if [ $orientation -eq 0 ]; then
	    opts=""
	    multiopt="-l -r 1 -c 2 -o c"
	else
	    opts="-landscape"	# Ghostview: opts="-landscape"
	    multiopt="-p -r 1 -c 2"
	fi
	;;
    4)	if [ $orientation -eq 0 ]; then
	    opts=""
            multiopt="-p -r 2 -c 2 -o c"
	else
	    opts="-landscape"	# Ghostview: opts=-landscape
	    multiopt="-l -r 2 -c 2"
	fi
	;;
    8)  if [ $orientation -eq 0 ]; then
	    opts=""
            multiopt="-p -r 2 -c 4 -o c"
	else
	    opts="-landscape"	# Ghostview: opts=-landscape
            multiopt="-l -r 2 -c 4"
	fi
	;;
esac

#	-e means allow equations to work
if [ "$perpage" -eq 1 ]; then
	geqn $1 | gtbl | groff -e -Tps -rO$orientation
else
	geqn $1 | gtbl | groff -e -Tps -rO$orientation | /usr/andrew/etc/multips $multiopt
fi
#rm -f $1
exit

