#!/bin/sh
#
#  This is a part of ChiTeX.
#  This script is created by 
#    Hung-Yih Chen ()  (yih@math.ncu.edu.tw)
#               (Dept. of Mathematics, National Central Univ.)
#           Last updated  Jan. 20, 2000
# 
#                All rights preserved   
#

gawkloc=`which gawk|grep ":"`
if test "$gawkloc" = ""; then
   gawkloc=`which gawk|grep "no gawk"`
fi
if test "$gawkloc" != ""; then
   gawkbin="awk"
else
   gawkbin="gawk"
fi

searchtexmf="y"
if test "$searchtexmf" = "y"; then
echo "yes" > tmp@
texmfcnffile=`kpsexpand -w cnf texmf.cnf`
TEXMFCNF=`
$gawkbin  '
{texmfcnfloc=index(texmfcnffile,"/texmf.cnf")
 print substr(texmfcnffile,1,texmfcnfloc-1)
}' texmfcnffile=$texmfcnffile tmp@ `

echo $TEXMFCNF > tmp@
TEXMF=`
$gawkbin '
{
  inline=$0
  gsub(/web2c/,"",inline)
  inline=substr(inline,1,length(inline)-1)
  print inline
}' tmp@ `
export TEXMF
fi

export fileno
filenoo=`expr $fileno + 1`
/bin/rm -f *temp@ maintemp*@ maintmp*@ fileb@ *.@@@ 

if test ! -s $1.tex
then
 if test ! -s $1; then 
   filename=`find $TEXMF/tex -follow -name $1 -print`
   if test "$filename" = ""; then
      filename=`find $TEXMF/tex/ -follow -name $1.tex -print`
      if test "$filename" = ""; then
         exit
      fi
   fi
 else
   filename=$1
 fi
else 
 filename=$1.tex
fi

/bin/cp $filename maintemp@


if test ! -s maintmpb@; then

chitranu1 -v infile=$filename -v fileno=$fileno maintemp@

filenoold="$fileno"

fileno="$filenoo"



if test -s transl@.$filenoold; then
   chmod +x ./transl@.$filenoold
   ./transl@.$filenoold
fi

if test -s  replfileu@; then
   chmod +x  replfileu@
   ./replfileu@
fi



rm  -f *.ident@

fi

#rm -f tmp@

exit 
