/* REXX */

/* emTeX/TDS fix # 008 installation script */
FIXNO = "008"
FIXVER = 0.56


/* loading the library */
ret = RxFuncAdd("SysLoadFuncs", "REXXUTIL", "SysLoadFuncs")
call SysLoadFuncs

/* Fixpak file name */
fixpak = "fix" || FIXNO || ".zip"

/* TeX drive */
texdrive = substr(value("EMTEXDIR", , "OS2ENVIRONMENT"),1,1)
if texdrive = "" then do
   say "The environment variable EMTEXDIR is undefined,"
   say "so I don't know what to fix."
   say "Are you sure that you have installed emTeX/TDS ?"
   exit
end

/* checking the version*/
version =  SysIni(texdrive||":\texmf\emtex\data\EMTEXTDS.INI", "EMTEXTDS", "VERSION")
if version <> FIXVER then do
   say "This fix can only be applied to emTeX/TDS, version " || FIXVER || "."
   exit
end

/* checking existence of fixpak file */
if  stream(fixpak, "C", "QUERY EXISTS") = "" then do
   say "I cannot find the file " || fixpak || " in the current directory!"
   exit
end

say "Fixing emTeX/TDS on drive" texdrive || ":"

/* directories */ 
call setlocal
tempdir = directory()
call directory(texdrive||":\texmf")

/* unzip fixpak */
ret=value("UNZIP", "-qqo", "OS2ENVIRONMENT")
"unzip " || tempdir || "\" || fixpak


/* =============================================================== */

/* delete junk files */
call SysFileDelete("fonts\source\public\cm\cmex9.mf")
call SysFileDelete("tex\latex\base\latexbug.msg")
call SysFileDelete("tex\latex\base\latex.log.new")
call SysFileDelete("doc\fonts\cm\bakoma-cm.fonts")
"erase fonts\type1\bakoma\cm\* /N"
"rmdir fonts\type1\bakoma\cm"
"rmdir fonts\type1\bakoma"

/* =============================================================== */

call endlocal

say
call makelatex
call makeplaintex
call makemf

say
say "Finis!"

/* finis */