#!/bin/sh
export TEXMF=/usr/share/texmf
export TTF2PKINPUTS=.:$TEXMF//
export TTF2TFMINPUTS=.:$TEXMF//
export PATH=/usr/share/texmf/chitex:/bin:/usr/bin:.
#
# This script is a part of ChiTeX
# By Hung-Yih Chen    
#           Last updated  Sep. 9, 1998
#
# This script is used to compile chinese (Big5)
# LaTeX source file
#
# Usage: chilatex sourcefile
#
# where sourcefile is a LaTeX source filename
# Example:
#         chilatex math2   (or chilatex math2.tex)
# when you have math2.tex 
#


fileno=1
export fileno
inputno=0
export inputno
if test ! -d .tmp00; then
   mkdir .tmp00
fi


PWD=`pwd`  
/bin/rm -f *temp@ maintemp*@ maintmp*@ fileb@ *.@@@ *.temp$ *.temp$ trasl*@
/bin/rm -f addmac*@ filemap@ trancode@ *.tmp00

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


  bname=`basename $filename`                    
  filea=`echo $bname|cut -d. -f 1` 
  fileb=`echo $bname |cut -d. -f 2`

  export filea=$filea

echo $filename > texfile@

#echo $1 > stemp@
#chitranx

chitran $1

enddoc=`cut -d% -f 1 $filea.tmp00|grep "\\end{document}"`
enddocsp=`cut -d% -f 1 $filea.tmp00|grep "\\end {document}"`
if [ "$enddoc" = "" -a "$enddocsp" = "" ]; then
   echo "\\end{document}" >> $filea.tmp00
   echo -e " \a "
   echo " "
   echo " "
   echo "Warning! Warning! "
   echo "Missing command \\end{document} "
   echo "Now ChiTeX insert it to your document temporarily. "
   echo "    "
   echo -e "* Press any key to continue\c"
   read inkey
fi


/bin/rm -f *temp@ maintemp*@ maintmp*@ fileb@ *.@@@ 

virtex \&chitexl $filea.tmp00|cctran 2> /dev/null


#echo "****************************************               "
#echo "*****  ChiTeX version 6.0.8 - by                         "
#echo "*****     (Hung-Yih Chen)  yih@math.ncu.edu.tw)   "
#echo "*****  ߤjǼƾǨt (Dept. of Math., National Central Univ.)"
##echo "*****  (Dept. of Math., National Central Univ.)          "
#echo "****************************************               "

/bin/rm -f tmp@@ *.tmp@* *.temp$ *.tmp!* 
/bin/rm -f transl@*  addmac*@ *.tmp0*  *@
/bin/rm -rf .tmp00

date
exit

