#!/usr/local/bin/bash
# 
# elaps: Simple script to convert an epix file to encapsulated Postscript
# 
# June 25, 2002, Andrew D. Hwang, ahwang@mathcs.holycross.edu
#

PROG=elaps

PID=$$
TEMP_EEPIC=$PROG-$PID.eepic
TEMP_LATEX=$PROG-$PID.tex
TEMP_DVI=$PROG-$PID.dvi
TEMP_PS=$PROG-$PID.ps
TEMP_EPSI=$PROG-$PID.epsi

fileroot=${1%%".c"} # Strip .c from filename

if [ $# != 1 ] 
  then  
    echo "Usage: elaps <filename>" 
    echo
    exit 1

  elif [ ! -f $1 ] && [ ! -f $fileroot.c   ]
    then
      echo "$PROG: File $fileroot.c not found, exiting" 
      echo
      exit 2
fi

# Create eepic file silently
epix $fileroot.c $TEMP_EEPIC 1> /dev/null

# Generate LaTeX file with "Here" document
cat <<EOF >> $TEMP_LATEX
\documentclass[12pt]{article}
\usepackage{latexsym,amsmath,epic,eepic,pstcol}
\pagestyle{empty}

\begin{document}
\begin{center}
\input{$TEMP_EEPIC}
\end{center}
\end{document}

EOF
#end of LaTeX file

# Create $TEMP_PS
latex $TEMP_LATEX 1> /dev/null

dvips -f $TEMP_DVI > $TEMP_PS

# Create eps
ps2epsi $TEMP_PS
mv -f $TEMP_EPSI $fileroot.eps

rm  $TEMP_EEPIC $TEMP_LATEX $TEMP_DVI $TEMP_PS \
    $PROG-$PID.aux $PROG-$PID.log

exit 0


