#!/bin/sh

chilatexname=`which chilatex`

if test "$chilatexname" != ""; then

gawk '
BEGIN{found="0"}
{
  if (found == "0")
  {
   filename=index($0,"filename=`find ")
   if (filename > 0)
    {subline=substr($0,filename+15,length($0)-filename-14)
     slash=index(subline,"/")
     endstr=index(subline,"/tex ")
     texmf=substr(subline,slash,endstr-1)
     print texmf > "texmf@"
     found="1"
    }
  }
}
END{}' $chilatexname

fi


texmf=`cat texmf@`

  help="1"

  while test "$help" = "1"
  do
  clear
  echo " "
  echo "       Choose one of the following:"
  echo " "
  echo "       1. Read README.* about installation of fonts(r)"
  echo "       2. Read README.use, *.ps about the usage of ChiTeX"
  echo "       3. Read README.* about others"
  echo "       4. Use old ttf2pk(Y xdvi,dvips ɦY~T, "
  echo "          LkQͤ pk ɮ, i^_ϥ ttf2pk,"
  echo "          PɧiD(email: yih@math.ncu.edu.tw)oT)"
  echo "       5. Use new ttf2pk"
  echo "       q. Quit"
  echo " "
  echo -n "       J '1', '2'  ,,, : "
  read inkey
  clear

  case "$inkey" in
       "1")
          subhelp="1"
          while test "$subhelp" = "1"
          do
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. vi README.install.advance "
          echo "       2. vi README.fonttable (rΫO²) "
          echo "       3. vi README.fonts (rΫOӸԪ) "
          echo "       q. quit "
          echo " "
          read subinkey
          case "$subinkey" in         
             "1")
                 less /usr/doc/chitex-6.0.8p3/README.install.advance
                 ;;
             "2")
                 less /usr/doc/chitex-6.0.8p3/README.fonttable 
                 ;;
             "3")
                 less /usr/doc/chitex-6.0.8p3/README.fonttable 
                 ;;
             "q")
                 subhelp="0"
                 ;;
               *)
                 subhelp="1";;
         esac
         done;;
       "2")
          subhelp="1"
          while test "$subhelp" = "1"
          do
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. vi README.use"
          echo "       2. ghostview intro.ps "
          echo "       3. ghostview newmac.ps "
          echo "       q. quit "
          echo " "
          read subinkey
          case "$subinkey" in         
             "1")
                 less /usr/doc/chitex-6.0.8p3/README.use
                 ;;
             "2")
                 gv /usr/doc/chitex-6.0.8p3/intro.ps
                 ;;
             "3")
                 gv /usr/doc/chitex-6.0.8p3/newmac.ps
                 ;;
             "q")
                 subhelp="0"
                 ;;
               *)
                 subhelp="1";;
          esac
          done;;
       "3")
          subhelp="1"
          while test "$subhelp" = "1"
          do
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. vi README"
          echo "       2. vi README.first"
          echo "       3. vi README.inst.quick"
          echo "       4. vi README.install.advance"
          echo "       5. vi README.chtable"
          echo "       6. vi README.print"
          echo "       7. vi README.fonts.suggetion "
          echo "       8. vi ChangeLog "
          echo "       q. quit "
          echo " "
          read subinkey
          case "$subinkey" in         
             "1")
                 less /usr/doc/chitex-6.0.8p3/README
                 ;;
             "2")
                 less /usr/doc/chitex-6.0.8p3/README.first
                 ;;
             "3")
                 less /usr/doc/chitex-6.0.8p3/README.inst.quick
                 ;;
             "4")
                 less /usr/doc/chitex-6.0.8p3/README.install.advance
                 ;;
             "5")
                 less /usr/doc/chitex-6.0.8p3/README.chtable
                 ;;
             "6")
                 less /usr/doc/chitex-6.0.8p3/README.print
                 ;;
             "7")
                 less /usr/doc/chitex-6.0.8p3/README.fonts.suggetion
                 ;;
             "8")
                 less /usr/doc/chitex-6.0.8p3/ChangeLog
                 ;;
             "q")
                 subhelp="0"
                 ;;
               *)
                 subhelp="1";;
          esac
          done;;
       "4")
           verify="1"
           while test "$verify" = "1"
           do
           clear
           echo " "; echo " "
           echo    "         ATwnª ttf2pk?"
           echo " "
           echo    -n "         TwJ 'y', _h J 'n' : "
           read inkey

           if test "$inkey" = "y" -o "$inkey" = "n"; then
              verify="0"
           fi
           done
           echo "yes" > tmp@
           if test "$inkey" = "y"; then
           ttf2pkf=`which ttf2pk`
           bindir=`
           gawk -v ttf2pkf=$ttf2pkf '
           BEGIN{}
           {ttf2pkloc=index(ttf2pkf,"/ttf2pk")
            bindir=substr(ttf2pkf,1,ttf2pkloc-1)
            print bindir
           }
           END{}' tmp@ `

           cp $bindir/ttf2pk.oldbak $bindir/ttf2pk
           cp $bindir/MakeTeXPK.oldbak $bindir/MakeTeXPK
           cp $bindir/MakeTeXTFM.oldbak $bindir/MakeTeXTFM
           cp $bindir/InstallFont.oldbak $bindir/InstallFont
           clear
           echo " "; echo " "
           echo    "        {bA ChiTeX wª ttf2pk "
           echo " "
           echo -n "        Press any key to continue"
           read inkey
           fi
           ;;
        "5")
           verify="1"
           while test "$verify" = "1"
           do
           clear
           echo " "
           echo    "         ATwnηs ttf2pk?"
           echo " "
           echo    -n "         TwJ 'y', _h J 'n' : " 
           read inkey
           if test "$inkey" = "y" -o "$inkey" = "n"; then
              verify="0"
           fi
           done
           if test "$inkey" = "y"; then
           echo "yes" > tmp@
           ttf2pkf=`which ttf2pk`
           bindir=`
           gawk -v ttf2pkf=$ttf2pkf '
           BEGIN{}
           {ttf2pkloc=index(ttf2pkf,"/ttf2pk")
            bindir=substr(ttf2pkf,1,ttf2pkloc-1)
            print bindir
           }
           END{}' tmp@ `

           cp $bindir/ttf2pk.new $bindir/ttf2pk
           cp $bindir/MakeTeXPK.new $bindir/MakeTeXPK
           cp $bindir/MakeTeXTFM.new $bindir/MakeTeXTFM
           cp $bindir/InstallFont.new $bindir/InstallFont
           clear
           echo " "; echo " "
           echo    "        {bA ChiTeX wηs ttf2pk "
           echo " "
           echo -n "        Press any key to continue"
           read inkey
           fi         
           ;;
        "q")
           help="0"
           ;;
        *)
           help="1";;
  esac
  done

/bin/rm -f *@

exit





  while test "$help" = "1"
  do
  clear
  echo " "
  echo "       Choose one of the following:"
  echo " "
  echo "       1. vi README.use "
  echo "       2. ghostview intro.ps "
  echo "       3. ghostview newmac.ps "
  echo "       4. vi README.fonttable (rΫO²) "
  echo "       5. vi README.fonts (rΫOӸԪ) "
  echo "       6. vi README "
  echo "       7. vi README.first"
  echo "       8. vi README.inst.quick"
  echo "       9. vi README.install.advance"
  echo "      10. vi README.chtable"
  echo "      11. vi README.print"
  echo "      12. vi README.fonts.suggetion "
  echo "      13. vi ChangeLog "
  echo "      14. Use old ttf2pk(Y xdvi,dvips ɦY~T, "
  echo "          LkQͤ pk ɮ, i^_ϥ ttf2pk,"
  echo "          PɧiD(email: yih@math.ncu.edu.tw)oT)"
  echo "      15. Use new ttf2pk"
  echo "       q. Quit"
  echo " "
  echo -n "       J '1', '2'  ,,, : "
  read inkey
  clear

  case "$inkey" in
       "1")
           less /usr/doc/chitex-6.0.8p3/README.use
           ;;
       "2")
           gv /usr/doc/chitex-6.0.8p3/intro.ps
           ;;
       "3")
           gv /usr/doc/chitex-6.0.8p3/newmac.ps
           ;;
       "4")
           less /usr/doc/chitex-6.0.8p3/README.fonttable
           ;;
       "5")
           less /usr/doc/chitex-6.0.8p3/README.fonts
           ;;
       "6")
           less /usr/doc/chitex-6.0.8p3/README
           ;;
       "7")
           less /usr/doc/chitex-6.0.8p3/README.first
           ;;
       "8")
           less /usr/doc/chitex-6.0.8p3/README.inst.quick
           ;;
       "9")
           less /usr/doc/chitex-6.0.8p3/README.install.advance
           ;;
       "10")
           less /usr/doc/chitex-6.0.8p3/README.chtable
           ;;
       "11")
           less /usr/doc/chitex-6.0.8p3/README.print
           ;;
       "12")
           less /usr/doc/chitex-6.0.8p3/README.fonts.suggetion
           ;;
       "13")
           less /usr/doc/chitex-6.0.8p3/ChangeLog
           ;;
       "14")
           verify="1"
           while test "$verify" = "1"
           do
           clear
           echo " "; echo " "
           echo    "         ATwnª ttf2pk?"
           echo " "
           echo    -n "         TwJ 'y', _h J 'n' : "
           read inkey

           if test "$inkey" = "y" -o "$inkey" = "n"; then
              verify="0"
           fi
           done
           echo "yes" > tmp@
           if test "$inkey" = "y"; then
           ttf2pkf=`which ttf2pk`
           bindir=`
           gawk -v ttf2pkf=$ttf2pkf '
           BEGIN{}
           {ttf2pkloc=index(ttf2pkf,"/ttf2pk")
            bindir=substr(ttf2pkf,1,ttf2pkloc-1)
            print bindir
           }
           END{}' tmp@ `

           cp $bindir/ttf2pk.oldbak $bindir/ttf2pk
           cp $bindir/MakeTeXPK.oldbak $bindir/MakeTeXPK
           cp $bindir/MakeTeXTFM.oldbak $bindir/MakeTeXTFM
           cp $bindir/InstallFont.oldbak $bindir/InstallFont
           clear
           echo " "; echo " "
           echo    "        {bA ChiTeX wª ttf2pk "
           echo " "
           echo -n "        Press any key to continue"
           read inkey
           fi
           ;;
        "15")
           verify="1"
           while test "$verify" = "1"
           do
           clear
           echo " "
           echo    "         ATwnηs ttf2pk?"
           echo " "
           echo    -n "         TwJ 'y', _h J 'n' : " 
           read inkey
           if test "$inkey" = "y" -o "$inkey" = "n"; then
              verify="0"
           fi
           done

