#! /bin/sh

# The intention of this script is to rearrange command-line
# arguments, to simulate dvips-like behaviour.
# 

opt=""
lpr_opt=""
file=""

while [ ! -z "$1" ] ; do
        case $1 in
        -P*)    lpr_opt="$1"
                ;;
	-p)	shift
		opt="$opt -f$1"
		;;
	-p*)	opt="$opt "`echo $1|sed 's/p/f/'`
		;;
	-l)	shift
		opt="$opt -t$1"
		;;
	-l*)	opt="$opt `echo $1|sed 's/l/t/'`"
		;;
	-o)	shift
		file=$1
		;;
	-o*)
		file=`echo $1| sed 's/^..//'`
		;;
        *)      opt="$opt $1"
		;;
        esac
        shift
done

case $file in
"")	dest="| lpr $lpr_opt"
	;;
*)	dest="> $file"
	;;
esac

eval "dvilj4 -x-4 -e- $opt $dest"
