#!/bin/sh

# argument checking
if [ ${#} -ne "2" ]; then
	echo "Usage: ${0} <word document> <postscript output file>"
	exit 1
fi

which wvDVI >/dev/null 2>&1
if [ ${?} -ne "0" ]; then
	echo "Could not find required program 'wvDVI'"
	exit 1
fi

which dvips >/dev/null 2>&1
if [ ${?} -ne "0" ]; then
	echo "Could not find required program 'dvips'"
	exit 1
fi

# intermediate file
DVI_FILE="${2}.dvi"

wvDVI "${1}" "${DVI_FILE}" >/dev/null 2>&1
if [ ${?} -ne "0" ]; then
	echo "Could not convert into DVI"
	exit 1
fi


dvips -o "${2}" "${DVI_FILE}" >/dev/null 2>&1
if [ ${?} -ne "0" ]; then
	echo "Could not convert into Postscript"
	exit 1
fi

#clean up
rm -f "${DVI_FILE}"
