#!/bin/sh
#
# Create a PostScript file from a sgf file (using pstex mode)
#
# Author: Jan van der Steen (jansteen@cwi.nl)
# Date	: Mon Dec  6 16:48:43 MET 1993

#
# The full path to the sgf2misc style and PostScript prolog files
#
TOP=${HOME}/games/go/src/sgf2misc

#
# Notify TeX as well
#
TEXSYSLIB=/usr/local/TeX/lib/macros
TEXINPUTS=.:${TEXSYSLIB}:${TOP}; export TEXINPUTS

program="`basename $0`"

#
# Any arguments?
#
if [ $# -eq 0 ]
then
    echo "Usage: `basename $0` sgf_file"
    exit 0
fi

#
# Can we reach the gopro prolog?
#
if [ ! -f ${TOP}/gopro.eps ]
then
    echo "${program}: Can't find the gopro.eps prolog file"
    echo "Please adjust the \"TOP\" variable in the \"go_run\" script"
    exit 1
fi

#
# Can we open the sgf file?
#
if [ ! -f $1 ]
then
    echo "`basename $0`: Can't open \"$1\" (is it a readable file?)"
    exit 1
fi
OUTPUT="`basename $1 .sgf`.ps"

#
# Set up the cleanup procedure
#
trap "rm $$.tex $$.log $$.aux $$.dvi" 0 1 2 3 9

#
# Start working now...
#
sgf2misc -fig %50 -scale 160 -kibitz $1	\
    | sed "s#header=gopro.eps#header=${TOP}/gopro.eps#" > $$.tex
latex $$.tex
dvips $$.dvi > ${OUTPUT}

echo "I've left the PostScript file in: ${OUTPUT}"

exit 0
