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

#	Someone said -e for groff means allow equations to work, but it does not seem so
if [ "$perpage" -eq 1 ]; then
#    If you use equations, you want to use:
#	groff -e -t -Tps -rO$orientation $1
#    If you do not use equations, you want to use:
	groff -Tps -rO$orientation $1
else
#    If you use equations, you want to use:
#	groff -e -t -Tps -rO$orientation $1 | /usr/andrew/etc/multips $multiopt
#    If you do not use equations, you want to use:
	groff -Tps -rO$orientation $1 | /usr/andrew/etc/multips $multiopt
fi
#rm -f $1
exit

