#!/bin/csh -f

# Usage: latc fileroot [key]

# Fileroot is the given file name or the part preceding ".tex.e" or
# ".tex" where applicable.  So you get the same behavior from "latc
# foo" or "latc foo.tex.e" or "latc foo.tex".

# The optional crypt key is prompted for if omitted on the command line..

umask 66

set inputbase = `echo $1 | sed 's+\.e$++' | sed 's+\.tex$++'`

shift
set key = "$*"
if ("$key" == "") then
  echo "Enter key:"
  set key = "$<"
endif

set tempbase = \#temp.$$

crypt "$key" <$inputbase.tex.e >$tempbase.tex

if (-e $inputbase.aux) cp $inputbase.aux $tempbase.aux
latex $tempbase.tex
rm -f $tempbase.tex
mv $tempbase.log $inputbase.log
if (-e $tempbase.aux) mv $tempbase.aux $inputbase.aux
crypt "$key" <$tempbase.dvi >$inputbase.dvi

echo "View? (y/n) [n]"
set answer = $<
if ("$answer" == "y") xd $tempbase.dvi

echo "Print? (y/n) [n]"
set answer = $<
if ("$answer" == "y") lprd $tempbase.dvi

rm -f $tempbase.dvi
