#! /bin/sh 
#
# This file is part of the validate package.
# ------------------------------------------
#
# Checks a .tlg file against the .log file created by TeX from the test 
# file.
# A test file must have the extension .lvt
# Runs tex two times
#
# usage: checktlg <fmt name> <test file base>
# or
# usage: checktlg <test file base>
#
# In the later case a format called latfs will be used. 
# This is LaTeX with nfss running on my machine. If you don't this
# use the first form.


# check number of args and set format etc.
#
if [ $# = 1 ]
then
LATEX=latfs
BASE=`basename $1 .lvt`
else
LATEX="virtex &$1"
BASE=`basename $2 .lvt'`
fi

# check if .tlg file is there, if not try to get it from RCS source 
# library
#
if test ! -r $BASE.tlg 
then 
  co $BASE.tlg 
fi

# same for the lvt file
#
if test ! -r $BASE.lvt
then 
  co $BASE.lvt
fi

# remove all kind of rubbish
#
rm -f $BASE.log $BASE.au?  $BASE.tmp.tlg $BASE.tlg.diff $BASE.dvi
rm -f $BASE.glo $BASE.idx  $BASE.lof $BASE.toc $BASE.lot

# run TeX twice with chosen format
#
$LATEX $BASE.lvt </dev/null  > /dev/null
$LATEX $BASE.lvt </dev/null  > /dev/null

# remove stuff from the log which is of no interest and save the result
# in tmp file
#
sed -e "1,/START-TEST-LOG/d" \
    -e "/END-TEST-LOG/,//d"  \
    -e "/OMIT/,/TIMO/d"      \
    -e "s/$BASE//"           \
                              $BASE.log > $BASE.tmp.tlg

# comp both files
#
if (cmp -s $BASE.tlg $BASE.tmp.tlg)
then
  echo ' '
  echo Check passed for $BASE
  rm -f $BASE.log $BASE.au?  $BASE.tmp.tlg $BASE.tlg.diff $BASE.dvi
  rm -f $BASE.glo $BASE.idx  $BASE.lof $BASE.toc $BASE.lot
else
  echo ' '
  echo '***************************************************************'
  echo '*' Check not passed!  Preparing context diff in $BASE.tlg.diff 
  echo '***************************************************************'
  diff -c $BASE.tlg $BASE.tmp.tlg > $BASE.tlg.diff
  echo done with $BASE.tlg.diff
fi


#
