#!/bin/bash
#
# This script prints a dvi file using dvips regardless of the actual
# configuration of dvips.
#
# Copyright 1996 Michael Meskes <meskes@informatik.rwth-aachen.de>
# Placed under GPL
#

DVICONF=/usr/lib/texmf/dvips
TMPFILE=/tmp/dviprint.$$

#
# Parse command line and remove -o and -P 
#
while [ $# -gt 0 ];
do
	case $1 in
	-P*)	printer=`echo $1 | cut -b3-`
		if [ -z ${printer} ]; then
			printer=$2
			shift 1
		fi;;
	-o*)	tofile="yes"
		options="${options} $1";;
	*)	options="${options} $1";;
	esac
	shift 1
done

#
# Add corrected -o resp. -P arguments
#
if [ ! "${tofile}" ]; then
	if [ "${printer}" ]; then
		if [ -f ${DVICONF}/config.${printer} ]; then
			options="${options} -P ${printer}"
		else
			options="${options} -o ${TMPFILE}"
			printcmd="lpr -P ${printer}"
		fi
	else
		options="${options} -o ${TMPFILE}"
		printcmd="lpr" 
	fi
fi

#
# Call dvips
#
dvips ${options}
if [ "${printcmd}" ]; then
	${printcmd} ${TMPFILE}
	/bin/rm -f ${TMPFILE}
fi

