#! /bin/csh -f
# Last modified on Thu Feb  7 13:45:13 PST 1991 by stolfi
#==================================================
# Runs TeX with stolfi's macros
# Usage: stolfi-tex [-nofilter] [-fontsize size] [-family fam] file
#  where "size" is main font size in points (10, 11 or 12 )
#  and "fam" selects AMR fonts (am) or CMR fonts (cm)
#  Default is -fontsize 11 -family cm
#==================================================

unset nofilter
set flags = ""
set fontsize = "11"
set family = "cm"
while ( $#argv > 1 )
  if ( "$1" == "-nofilter" ) then
    set nofilter
    shift
  else if ( "$1" == "-fontsize" ) then
    if ( ("$2" != "10") && ("$2" != "11") && ("$2" != "12") ) then
      echo "$0"': invalid point size="'$2'"\!'
      exit(1)
    endif
    set fontsize = $2
    shift; shift
  else if ( "$1" == "-family" ) then
    if ( ("$2" != "am") && ("$2" != "cm") ) then
      echo "$0"': invalid family="'$2'"\!'
      exit(1)
    endif
    set family = $2
    shift; shift
  else
    echo "Usage: $0 [-family fam] [-fontsize size] file"
    exit(1)
  endif
end

if ( $#argv == 0 ) then
  echo "Usage: $0 [-nofilter] [-family fam] [-fontsize size] file"
  exit(1)
endif

if ( ( ! ( $?TEXINPUTS ) ) || ( "x$TEXINPUTS" == "x" ) ) then
  setenv TEXINPUTS ".:/udir/stolfi/tex:/usr/local/lib/tex/"
endif
echo "TEXINPUTS = "$TEXINPUTS

foreach f ( $* )
  set f = "$f:r"
  if ( ! ( -r $f.tex ) ) then
    echo "${0}: cannot find $f.tex"
    exit(1)
  endif
  if ( $?nofilter ) then
    virtex \&/udir/stolfi/tex/${family}${fontsize}fmt $f  \
      | /udir/stolfi/bin/tex-error-filter $f \
    && /udir/stolfi/bin/tex-updatetags $family $fontsize $f
  else
    virtex \&/udir/stolfi/tex/${family}${fontsize}fmt $f \
    && /udir/stolfi/bin/tex-updatetags $family $fontsize $f
  endif
end

# END



