#!/bin/csh -f

#  Copyright (c) 1991, 1992, 1993 Xerox Corporation.  All Rights Reserved.  
#  
#  Unlimited use, reproduction, and distribution of this software is
#  permitted.  Any copy of this software must include both the above
#  copyright notice of Xerox Corporation and this paragraph.  Any
#  distribution of this software must comply with all applicable United
#  States export control laws.  This software is made available AS IS,
#  and XEROX CORPORATION DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
#  INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY
#  AND FITNESS FOR A PARTICULAR PURPOSE, AND NOTWITHSTANDING ANY OTHER
#  PROVISION CONTAINED HEREIN, ANY LIABILITY FOR DAMAGES RESULTING FROM
#  THE SOFTWARE OR ITS USE IS EXPRESSLY DISCLAIMED, WHETHER ARISING IN
#  CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, EVEN IF
#  XEROX CORPORATION IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#  
#  $Id: texinfo2ps.dist,v 1.3 1993/09/23 01:22:17 janssen Exp $

if ( $#argv < 1 ) then
	echo "Usage:  texinfo2ps INPUTFILE.texinfo >OUTPUTFILE.ps"
	exit 1
endif

set intermediateFile = $1
set errorFile = ${intermediateFile:r}.err
set dviFile = ${intermediateFile:r}.dvi
set psFile = ${intermediateFile:r}.ps

/import/tex/bin/tex ${intermediateFile} >&${errorFile} </dev/null
if ($status == 0) then
	rm ${errorFile}
else
	/bin/sh -c "( echo '/import/tex/bin/tex:' ; cat ${errorFile} ) >&2"
	rm ${errorFile}
	exit 1
endif
# now sort the indices
/import/gnu-2.0/sparc-sun-sunos4.1/gbin/texindex ${intermediateFile:r}.{cp,fn,pg,vr,tp,ky} >&${errorFile}
if ($status == 0) then
	rm ${errorFile}
else
	/bin/sh -c "( echo '/import/gnu-2.0/sparc-sun-sunos4.1/gbin/texindex:' ; cat ${errorFile} ) >&2"
	rm ${errorFile}
	exit 1
endif
# second pass to use the aux file built on the first pass
/import/tex/bin/tex ${intermediateFile} >&${errorFile} </dev/null
if ($status == 0) then
	rm ${errorFile}
else
	/bin/sh -c "( echo '/import/tex/bin/tex:' ; cat ${errorFile} ) >&2"
	rm ${errorFile}
	exit 1
endif
rm ${psFile:r}.aux ${psFile:r}.cp ${psFile:r}.fn ${psFile:r}.ky ${psFile:r}.log ${psFile:r}.pg ${psFile:r}.toc ${psFile:r}.tp ${psFile:r}.vr ${psFile:r}.cps ${psFile:r}.fns ${psFile:r}.kys ${psFile:r}.pgs
/import/dvips/bin/dvips ${dviFile} -o ${psFile} >&${errorFile}
if ($status == 0) then
	rm ${errorFile}
else
	/bin/sh -c "( echo '/import/dvips/bin/dvips:' ; cat ${errorFile} ) >&2"
	rm ${errorFile}
	exit 1
endif
cat ${psFile}
rm ${psFile} ${dviFile}
exit 0
