#!/bin/bash # # elaps: Convert an epix file to encapsulated Postscript, i.e. epix2eps # # June 25, 2002, Andrew D. Hwang, ahwang@mathcs.holycross.edu # Sept 02, 2002, Printer options to dvips added (Walter A. Kehowski) # Sept 15, 2002, Accept all epix options (ADH) # Sept 20, 2002, Accept eepic file as input (ADH) # PROG=$(basename $0) DVIPS_OPTS="-f" PID=$$ ELAPS_TEMP_EEPIC=$PROG-$PID.eepic ELAPS_TEMP_LATEX=$PROG-$PID.tex ELAPS_TEMP_DVI=$PROG-$PID.dvi ELAPS_TEMP_PS=$PROG-$PID.ps ELAPS_TEMP_EPSI=$PROG-$PID.epsi declare ELAPS_FILEROOT declare ELAPS_INFILE declare ELAPS_EXT # Input file extension ELAPS_OUT=/dev/null ELAPS_VERBOSE= function elaps_die { echo "$PROG: ERROR: $1" exit 1 } function elaps_parse_options { # Skip command line options while [ "$1" != "${1#"-"}" ]; do case "$1" in -V|-b|-i*|-o|-u|-x) if [ "$2" != "${2#"-"}" -o "$2" = "" ]; then elaps_die "Compiler option \"$1\" cannot be followed by \"$2\"" else shift 2; fi ;; -h|--help) elaps_help; ;; -v|--version) elaps_version; ;; -vv|--verbose) ELAPS_VERBOSE=1 ELAPS_OUT=/dev/stdout shift; ;; -P*) DVIPS_OPTS="$1 $DVIPS_OPTS"; shift; ;; *) shift; ;; esac done if [ $2 ]; then # More than one option left is a fatal error elaps_die "No arguments allowed after input file ($1)" elif [ "$1" = "" ]; then elaps_die "You must specify an input file!" # Otherwise, assume next parameter is the input file elif [ $1 = ${1%%".eepic"}.eepic ] then ELAPS_FILEROOT=${1%%".eepic"} ELAPS_EXT="eepic" elif [ $1 = ${1%%".c"}.c ] then ELAPS_FILEROOT=${1%%".c"} elif [ $1 = ${1%%".cc"}.cc ] then ELAPS_FILEROOT=${1%%".cc"} elif [ $1 = ${1%%".C"}.C ] then ELAPS_FILEROOT=${1%%".C"} elif [ $1 = ${1%%".cpp"}.cpp ] then ELAPS_FILEROOT=${1%%".cpp"} else # No recognized extension supplied ELAPS_FILEROOT=$1 if [ -f $ELAPS_FILEROOT.eepic ]; then ELAPS_EXT="eepic"; fi fi } function elaps_help { echo "Usage: $PROG [options] [.eepic|.c|.cc|.C|.cpp]" >&1 if [ "$ELAPS_VERBOSE" != "" ]; then cat <&1 Recognized options are: -vv, --verbose Show output messages. Mostly useful if this script hangs silently. -P dvips printer options, e.g. "-Pamz", may be given on the command line. They are also read from ~/.dvipsrc if this file exists. -h, --help Print help message; accepts --verbose option. -v, --version Print version information; use --verbose option for license. EOF else echo " \"$PROG --verbose -h\" for detailed help" fi exit 0 } # End of elaps_help function elaps_version { cat <&1 $PROG is part of ePiX, Version 0.8.7 Copyright (C) 2001, 2002 Andrew D. Hwang Department of Mathematics and Computer Science College of the Holy Cross Worcester, MA, 01610-2395, USA VERSION1 if [ "$ELAPS_VERBOSE" != "" ]; then cat <&1 ePiX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ePiX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ePiX; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA VERSION2 else echo " \"$PROG --verbose -v\" for license" fi exit 0 } # End of elaps_version ## script starts here ## if [ $# = 0 ]; then elaps_help; fi # exit elaps_parse_options $@ # Create eepic file if necessary if [ "$ELAPS_EXT" != "eepic" ]; then epix $@ $ELAPS_TEMP_EEPIC 1> $ELAPS_OUT || elaps_die "Can't create $ELAPS_FILEROOT.eepic" elif [ -f $ELAPS_FILEROOT.eepic ]; then ELAPS_TEMP_EEPIC=$ELAPS_FILEROOT.eepic else elaps_die "$ELAPS_FILEROOT.eepic not found" fi # Generate LaTeX file cat <> $ELAPS_TEMP_LATEX \documentclass[12pt]{article} \usepackage{latexsym,amsmath,epic,eepic,pstcol} \pagestyle{empty} \begin{document} \begin{center} \input{$ELAPS_TEMP_EEPIC} \end{center} \end{document} EOF #end of LaTeX file # Create $ELAPS_TEMP_PS; dvips prints some non-error messages to stderr... latex $ELAPS_TEMP_LATEX 1> $ELAPS_OUT dvips -Pcmz -Pamz -f -o $ELAPS_TEMP_PS $ELAPS_TEMP_DVI &> $ELAPS_OUT # Create eps file, ps2epsi $ELAPS_TEMP_PS 1> $ELAPS_OUT # fix title, sed "s/elaps-$PID/$ELAPS_FILEROOT/g" $ELAPS_TEMP_EPSI > $ELAPS_FILEROOT.eps # and clean up rm $ELAPS_TEMP_LATEX $ELAPS_TEMP_DVI $ELAPS_TEMP_PS $ELAPS_TEMP_EPSI \ $PROG-$PID.aux $PROG-$PID.log if [ "$ELAPS_EXT" != "eepic" ]; then rm $ELAPS_TEMP_EEPIC; fi exit 0