#!/bin/sh

BASE="/usr/local/src/ext/neatroff_make"
#BASE="/home/kaa/src/neatroff_make"
GS_FONTPATH="$BASE/fonts" export GS_FONTPATH
ROFF="$BASE/neatroff/roff"
POST="$BASE/neatpost/post"
PPDF="$BASE/neatpost/pdf"
EQN="$BASE/neateqn/eqn"
REFR="$BASE/neatrefer/refer"
PIC="$BASE/troff/pic/pic"
TBL="$BASE/troff/tbl/tbl"
SOIN="$BASE/soin/soin"
GRAP="$BASE/troff/all/grap/grap"
#DGRAP="$BASE/grap-1.46/grap.defines"

ROFFOPTS="-F$BASE -M$BASE/tmac"
ROFFMACS="-mpost"
POSTOPTS="-F$BASE -w80"
# width in 0.1 mm. 0.1mm = 1/254 in
POSTOPTS="$POSTOPTS -pletter"
REFROPTS="-m -e -o ct -p ref.bib"

# Plan 9 sed and .EPS do not mix.
# The unix sed is in /usr/bin.

# PDF
#$ROFF $ROFFOPTS $ROFFMACS $1 | tee ${1%%[.]*}.int | $PPDF $POSTOPTS > ${1%%[.]*}.pdf

in="${1:-banner_letter.tr}"
out="${in%.*}"
# PS
< $in 9 grap | $PIC | $ROFF $ROFFOPTS $ROFFMACS | tee "$out".int | $POST $POSTOPTS | tee "$out".ps | ps2pdf -dPDFSETTINGS=/prepress - "$out".pdf

hup()
{
	if ! [ $1 ]
	then
		return
	else
		kill -HUP $1
	fi
}

mupid=$(ps ax | grep "mupdf.*${in%%tr}pdf" | \
	grep -v grep)
hup $mupid
