/**/

call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs


parse arg language texmf source options


if language = '049' then do

  msg.1 = 'msg:AMS-LaTeX'
  msg.2 = 'msg:AMS-LaTeX: Entpacke Dateien'
  msg.3 = 'msg:AMS-LaTeX: amslatex.ins'
  msg.4 = 'msg:AMS-LaTeX: amsclass.ins'
  msg.5 = 'msg:AMS-LaTeX: amsldoc.tex sortiere Index amsldoc.idx'
  msg.6 = 'msg:AMS-LaTeX: amsldoc.tex Lauf'
  msg.7 = 'von'

end
else do

  msg.1 = 'msg:AMS-LaTeX'
  msg.2 = 'msg:AMS-LaTeX: installing files'
  msg.3 = 'msg:AMS-LaTeX: amslatex.ins'
  msg.4 = 'msg:AMS-LaTeX: amsclass.ins'
  msg.5 = 'msg:AMS-LaTeX: amsldoc.tex sorting index amsldoc.idx'
  msg.6 = 'msg:AMS-LaTeX: amsldoc.tex run'
  msg.7 = 'of'

end

install = texmf||'\os2tex\install'


if ""=directory(texmf) then do
  say "err:Verzeichniswechsel nicht m”glich!"
  exit 1
end


if Pos("InstallFiles", options) > 0 then do


   say msg.1

   install||'\kdir '||texmf||'\tex\latex\amslatex'
   install||'\kdir '||texmf||'\doc\ams\amslatex'


   'md '||texmf||'\doc'
   'md '||texmf||'\doc\ams'
   'md '||texmf||'\doc\ams\amslatex'

   'md '||texmf||'\tex\latex\amslatex'


   say msg.2

   install||'\unzip '||source||'\amslatex.zip'



   tex = texmf||'\os2tex\bin\tex.exe'


   say msg.3

   tex||' -r -ff latex.fmt -pf '||texmf||'\os2tex\bin -pi '||texmf||'\tex; -po '||texmf||'\tex\latex\amslatex amslatex.ins'


   say msg.4

   tex||' -r -ff latex.fmt -pf '||texmf||'\os2tex\bin -pi '||texmf||'\tex; -po '||texmf||'\tex\latex\amslatex amsclass.ins'

   'copy '||texmf||'\tex\latex\amslatex\amsldoc.tex '||texmf||'\doc\ams\amslatex'
   'del '||texmf||'\tex\latex\amslatex\amsldoc.tex'

end



if SysOS2Ver() = '2.30' then
  top = 48
else
  top = 45



if Pos("CreateObjects", options) > 0 then do

   classname = 'WPFolder'
   objtitle  = 'AMS-LaTeX'
   location  = '<OS2TEX_DOC_FOLDER>'
   setup     = 'OBJECTID=<OS2TEX_AMSLATEX_FOLDER>;ICONVIEW=MINI,NONFLOWED;ALWAYSSORT=YES;ICONVIEWPOS=50,50,25,'||top
   duplicate = 'update'


   rc = SysCreateObject(classname,objtitle,location,setup,duplicate)

   if rc = 0 then do
      exit 1
   end

end


if Pos("InstallFiles", options) > 0 then do


   do i=1 to 3

      if i=3 then do
         say msg.5
         texmf||'\os2tex\bin\makeindex '||texmf||'\doc\ams\amslatex\amsldoc.idx'
      end

      say msg.6' 'i' 'msg.7' 3'
      tex||' -r -ff latex.fmt -pf '||texmf||'\os2tex\bin -pi '||texmf||'\tex;'||texmf||'\doc\ams -po '||texmf||'\doc\ams\amslatex -pt '||texmf||'\fonts\tfm amsldoc.tex'

   end

end


if Pos("CreateObjects", options) > 0 then do

   classname = 'WPProgram'

   if language = '049' then
      objtitle  = 'AMS-LaTeX Dokumentation'
   else
      objtitle  = 'AMS-LaTeX Documentation'

   location  = '<OS2TEX_AMSLATEX_FOLDER>'
   setup     = 'EXENAME='texmf'\os2tex\bin\dvi.exe;PROGTYPE=PM;STARTUPDIR='texmf'\os2tex\bin;OBJECTID=<OS2TEX_amsldoc.dvi>;PARAMETERS='texmf'\doc\ams\amslatex\amsldoc.dvi'
   duplicate = 'replace'

   rc = SysCreateObject(classname,objtitle,location,setup,duplicate)

   if rc = 0 then do
      exit 1
   end



   classname = 'WPProgram'

   if language = '049' then
      objtitle  = 'AMS-Zeichens„tze'
   else
      objtitle  = 'AMS-Fonts'

   location  = '<OS2TEX_AMSLATEX_FOLDER>'
   setup     = 'EXENAME='texmf'\os2tex\bin\dvi.exe;PROGTYPE=PM;STARTUPDIR='texmf'\os2tex\bin;OBJECTID=<OS2TEX_amsfndoc.dvi_2>;PARAMETERS='texmf'\doc\ams\amsfonts\amsfndoc.dvi'
   duplicate = 'replace'

   rc = SysCreateObject(classname,objtitle,location,setup,duplicate)

   if rc = 0 then do
      exit 1
   end


end



