#!/bin/bash 
#
# $Id: runpmx,v 1.5 2005/11/28 23:12:15 rahtz Exp $
#
#et -x

export TEXINPUTS=inputs:

if test $? = 1
then 
 echo "WRONG number of args!"
 exit 1
fi

F=`basename $1 .pmx`

if test -r $F.eps
then
  echo $F.eps already made
else
  pmxab $F.pmx
  tex $F
  musixflx $F
  tex $F
  if test -r $F.slu # slur M package called
  then
    musixpss $F
    mpost $F
    tex $F
  fi
  dvips -j -E -Ppp $F.dvi -o $F.eps
#        ^ font subsetting

  ./cleaneps $F.eps

  if test ! -s $F.eps
  then
    rm $F.eps
    echo "*************************** eps file $F.eps has zero size"
    exit 1
  fi
  rm -f $F.[123456789] $F.mp $F.log $F.dvi $F.mx? $F.pml $F.tex $F.slu
  rm -f $F.pml
fi