#!/bin/sh
# Usage: make-queue -w WIDTH -h HEIGHT [-e] [-o] [-2] [-4] [-lq]
#        must specify page width and height in chars
#	 optionally one of -e -o for even/odd sides
#	 optionally one of -2 -4 for 2-up 4-up
#        optionally -lq for letter quality, otherwise defaults to draft

BJFDIR=/usr/local/sbin/bjf
PRINTCAP=/etc/printcap
BJF=$BJFDIR/bjf

width=
height=
head="-"
tail="-"
flags=
antiflags="-draft"

while [ $# -gt 0 ]
do
    case "$1" in
    -w)	 width="$2"; flags="$flags -width $2"; shift;;
    -h)	 height="$2"; flags="$flags -height $2"; shift;;
    -2)	 tail="$tail"2; flags="$flags -two-up";;
    -4)	 tail="$tail"4; flags="$flags -four-up";;
    -e)	 tail="$tail"e; flags="$flags -even";;
    -o)	 tail="$tail"o; flags="$flags -odd";;
    -lq) head=lq"$head"; antiflags= ;;
    esac
    shift
done

if [ "$width" = "PS" ]
then
    cpi="-cpi ps"
elif [ $width -le 75 ]
then
    cpi="-cpi 10"
elif [ $width -le 80 ]
then
    cpi="-cpi 12"
else
    cpi="-landscape"
fi

case "$head" in
    -)     head=
esac

case "$tail" in
    -)      tail= ;;
    *[24]*) cpi= ;;
esac

queuename="$head$width"x"$height$tail"
filtername=$BJFDIR/bjf-$queuename

echo "#!/bin/sh" > $filtername
echo exec $BJF $flags $antiflags $cpi >> $filtername
echo "$queuename":if="$filtername":tc=bj >> $PRINTCAP

exit 0
