#!/bin/sh

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

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

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

# intermediate file
PS_FILE="${2}.ps"

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

# Here we should add pstopdf -- MV

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

#clean up
rm -f "${PS_FILE}" "${PS_FILE}.log"

mv "${PS_FILE}.pdf" "${2}"
