#! /bin/sh
# Author: Tom Gordon
# Date: 6 Dec 91

# Set to path of linuxdoc-sgml directory. This is all you should have to edit.
LINUXDOC=$HOME/linuxdoc-sgml

PATH=$LINUXDOC/bin:$PATH
export PATH

GROFF_TYPESETTER=ps
#GROFF_TMAC_PATH=/usr/local/gnu/groff-1.08/lib/groff/tmac
#export GROFF_TMAC_PATH

ASCII="groff -T ascii -t -mgs"
LATIN1="groff -T latin1 -t -mgs"
POSTSCRIPT="groff -et -mgs"
REFER="grefer -sA+E+D+ -ne -p"

TYPE="ascii"	 # default
DATABASE="NONE"      # refer database

# set terminal to lowest common denominator,
# appropriate for email


cleanup () {	# remove temporary files
	if [ -f $$.refer  ]
	then
		/bin/rm $$.refer
	fi
}

trap 'cleanup; exit 1' 1 2 3 9

usage () { 
echo "	qroff 	[-p]		         * PostScript instead of ASCII";
echo "          [-l]                     * Latin 1 instead of ASCII";
echo "		[-b <sgml bibliography>] * bibliography, without .sgml extension";
exit 1 
}

case "$1" in
	"help" | "HELP" | "Help" | "-help" ) usage
esac

set -- `getopt plb: $*`


if [ $? != 0 ]
then
	usage
fi

for i in $*
do
        case $i in
	      -p)	TYPE="PostScript"; shift;;
	      -l)       TYPE="latin1"; shift;;
	      -b)	DATABASE=$2; shift; shift;;
              --)       shift; break;;
        esac
done

roff () {
	if [ "$TYPE" = "PostScript" ]
	then
		$POSTSCRIPT
	elif [ "$TYPE" = "latin1" ]
        then	
		$LATIN1 
        else
		$ASCII | col -b
	fi
}

if [ "$DATABASE" = "NONE" ]
then
	preroff | roff
else
	if [ "$TYPE" = "PostScript" ]
	then
		biblio -T grops $DATABASE.sgml > $$.refer
	else
		biblio -T refer $DATABASE.sgml > $$.refer
	fi
	preroff | $REFER $$.refer | roff
fi

cleanup

