@echo off
if "%2"=="" goto usage
if "%1"=="" goto usage

:i0
cls
echo.
echo.
echo RESULT
echo UNPACK emTeX FILES AND OTHER PACKAGES
echo.
echo Continue installation ?
echo Press Ctrl+Break to abort or any key to continue . . .
pause>nul
:: First go files from installation diskette
echo.
echo Unpack CyrTUG support files
call %eminst%\instb.bat %1 %2 cyrt -d -o @%eminst%\cyrtug.ls -x@%eminst%\excludlh.lsc %emtexdir%\
if %PC%==error goto erend
:i1
if exist %emtexdir%\BIN\te.exe goto i2
echo.
echo Unpack TeX Editor
call %eminst%\instb.bat %1 %2 tedt -d -o %1:\
if %PC%==error goto erend
:i2
if %AM%==N goto i3
echo.
echo Unpack AmSTeX files
call %eminst%\instb.bat %1 %2 amst -d -o %1:\
if %PC%==error goto erend
:i3
if %BA%==N goto i3n
echo.
echo Unpack Babel files
call %eminst%\instb.bat %1 %2 babl -d -o @%eminst%\babel.lsc %1:\
if %PC%==error goto erend
:i3n
if %NF%==N goto i4
echo.
echo Unpack NFSS1 files
call %eminst%\instb.bat %1 %2 nfss -d -o %1:\
if %PC%==error goto erend
:i4
for %%c in (%TeX%,%LA%,%LAe%,%NF%) do if %%c==A goto i40
for %%c in (%TeX%,%LA%,%LAe%,%NF%) do if %%c==C goto i40
goto i5
:i40
if %MF%==0 goto i43
if not exist %emtexdir%\MFINPUT\LH\*.* goto i41
echo You have already installed LH fonts of another version.
echo If you have old LH fonts (older than 3.2) you must skip
echo LHfonts installation or quit installation and then delete all files
echo of this package, e.g. to avoid conflicts with 1.2 delete installed
echo version using command:
echo   emremove -a lhfonts12 %1:\
echo and repeat installation with CyrTUG-EmTeX set.
%eminst%\ask.exe Install LHfonts (Yes No or Quit) ? (Y/N/Q),nNyYqQ
echo.
if errorlevel 5 goto end
if errorlevel 3 goto i5
:i41
echo.
echo Unpack LH fonts
call %eminst%\instb.bat %1 %2 lhfn -d -o @%eminst%\lhfont32.lsc -x@%eminst%\excludlh.lsc %emtexdir%\
if %PC%==error goto erend
:i5
for %%c in (0,Ctex,Ctex186,Ctex386) do if NOT %PC%==%%c goto i51
for %%c in (0,Cmf,Cmf186,Cmf386) do if NOT %MF%==%%c goto i51
for %%c in (%TeX%,%LA%,%LAe%,%AM%,%NF%) do if NOT %%c==N goto id
goto d0
:i51
cls
echo.
for %%c in (0,Ctex,Ctex186,Ctex386) do if %PC%==%%c goto i7
echo.
echo Unpack TeX compilers
call %eminst%\instb.bat %1 %2 frst -d -o @%eminst%\first.ls %1:\
if %PC%==error goto erend
call %eminst%\instb.bat %1 %2 texp -d -o @%eminst%\tex.ls %1:\
if %PC%==error goto erend
:i6
if "%MC%"=="0" goto i7
echo.
echo Unpack DVIDRV
call %eminst%\instb.bat %1 %2 done -d -o @%eminst%\dvi1.ls %1:\
if %PC%==error goto erend
call %eminst%\instb.bat %1 %2 dtwo -d -o @%eminst%\dvi2.ls %1:\
if %PC%==error goto erend
:i7
for %%c in (0,Cmf,Cmf186,Cmf386) do if %MF%==%%c goto i8
echo.
echo Unpack METAFONT and MFJob
call %eminst%\instb.bat %1 %2 mfpr -d -o @%eminst%\mf.ls %1:\
if %PC%==error goto erend
call %eminst%\instb.bat %1 %2 mfjp -d -o @%eminst%\mfjob.ls %1:\
if %PC%==error goto erend
:i8
for %%c in (0,Ctex,Ctex186,Ctex386) do if %PC%==%%c goto ia
goto ia1
:ia
for %%c in (0,Cmf,Cmf186,Cmf386) do if %MF%==%%c goto id
:ia1
cls
echo.
echo.
echo Unpack fonts
call %eminst%\instb.bat %1 %2 fontcm -d -o @%eminst%\fontcm.ls %1:\
if %PC%==error goto erend
call %eminst%\instb.bat %1 %2 fontemsy -d -o @%eminst%\fontemsy.ls %1:\
if %PC%==error goto erend
call %eminst%\instb.bat %1 %2 fontltx -d -o @%eminst%\fontltx.ls %1:\
if %PC%==error goto erend
call %eminst%\instb.bat %1 %2 fontams -d -o @%eminst%\fontams.ls %1:\
if %PC%==error goto erend
if %LAe%==Y call %eminst%\instb.bat %1 %2 fontams -d -o emtex/dist/amsfonts/latex/*.*  %1:\
if %PC%==error goto erend
echo.
echo Do you need EC fonts ? (If you don't know what it is you don't.)
%eminst%\ask.exe Enter letter (Y/N),yYnN
echo.
if errorlevel 3 goto ib
echo Unpack European Computer Modern fonts
if exist %eminst%\fontec.lsc goto ia2
call %eminst%\instb.bat %1 %2 fontec -d -o %1:\
goto ib
:ia2
call %eminst%\instb.bat %1 %2 fontec -d -o @%eminst%\fontec.lsc %1:\
:ib
if %PC%==tex386 goto ic
if %MF%==mf386 goto ic
goto id
:ic
echo.
echo Unpack EMX/RSX package
if NOT exist %1:\EMX\BIN\emx*.* goto ic0
if NOT exist %1:\EMTEX\BIN\rsx*.* goto ic0
goto ic1
:ic0
call %eminst%\instb.bat %1 %2 emrs -d -o @%eminst%\emxrsx.ls %1:\
if %PC%==error goto erend
goto id
:ic1
echo 
%eminst%\ask.exe !!! EMXRSX package already installed. Overwrite ? (Y/N),nNyY
if errorlevel 3 goto ic0
:id
cls
echo.
if %LA%==N goto ie
for %%c in (T,CT) do if %LA%==%%c goto id1
echo.
echo Unpack LaTeX 2.09 files
call %eminst%\instb.bat %1 %2 ltxo -d -o -xemtex/texinput/latex209/doc/*.doc %1:\
if %PC%==error goto erend
for %%c in (AT,MT,CT,T) do if %LA%==%%c goto id1
goto ie
:id1
echo.
echo Unpack array styles for LaTeX 2.09
call %eminst%\instb.bat %1 %2 mitt -d -o %1:\
if %PC%==error goto erend
:ie
if %LAe%==N goto d0
for %%c in (T,CT) do if %LAe%==%%c goto ie1
echo.
echo Unpack LaTeX 2e files
call %eminst%\instb.bat %1 %2 ltxi -d -o %1:\
if %PC%==error goto erend
for %%c in (AT,MT,CT,T) do if %LAe%==%%c goto ie1
goto d0
:ie1
echo.
echo Unpack tools package styles for LaTeX 2e
call %eminst%\instb.bat %1 %2 tool -d -o -xemtex/texinput/latex2e/tools/.tex %1:\
if %PC%==error goto erend

:d0
if %PC%==0 goto df0
cls
echo.
echo.
for %%c in (A,C) do if %TeX%==%%c goto dm2
echo Unpack fmtman.bat
for %%c in (tex386,Ctex386) do if %PC%==%%c goto dm1
call %eminst%\instb.bat %1 %2 cyrt -d -o texfmts/fmt/fmtman.bat %emtexdir%\
goto dm3
:dm1
if NOT exist %emtexdir%\BTEXFMTS\*.* md %emtexdir%\BTEXFMTS
md %emtexdir%\BTEXFMTS\FMT
call %eminst%\instb.bat %1 %2 cyrt -o texfmts/fmt/fmtman.bat %emtexdir%\BTEXFMTS\FMT\
goto dm3
:dm2
echo Unpack fmtman.bat and rtfmtman.bat
if %PC%==tex386 goto dm21
call %eminst%\instb.bat %1 %2 cyrt -d -o texfmts/fmt/*.bat %emtexdir%\
goto dm3
:dm21
if NOT exist %emtexdir%\BTEXFMTS\*.* md %emtexdir%\BTEXFMTS
md %emtexdir%\BTEXFMTS\FMT
call %eminst%\instb.bat %1 %2 cyrt -o texfmts/fmt/*.bat %emtexdir%\BTEXFMTS\FMT\
:dm3
if %PC%==error goto erend

if "%MC%"=="0" goto df0
cls
echo.
echo.
echo CREATING batchfiles for DVIDRV (viewing/printing programs)
echo dvidrv dviscr%MC% @fx_lh @view %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>%emtexdir%\BIN\vx_lh.bat
echo dvidrv dviscr%MC% @p6h_lh @view %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>%emtexdir%\BIN\vq_lh.bat
echo dvidrv dviscr%MC% @lj_lh @view %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>%emtexdir%\BIN\vl_lh.bat
echo dvidrv dviscr%MC% @ljh_lh @view %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>%emtexdir%\BIN\vh_lh.bat
echo dvidrv dvidot%MC% fx80 @fx_lh /fl=-1/po=prn %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 >%emtexdir%\BIN\px_lh.bat
echo dvidrv dvidot%MC% lqh @p6h_lh /fl=-1/po=prn %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 >%emtexdir%\BIN\pq_lh.bat
echo dvidrv dvihplj%MC% @lj_lh /fl=-1/po=prn %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>%emtexdir%\BIN\pl_lh.bat
echo ::for deskjet add option: " /op=deskjet ">>%emtexdir%\BIN\pl_lh.bat
echo ::you may also edit file %emtexdir%\data\dj.cnf and add " @dj " to batch file>>%emtexdir%\BIN\pl_lh.bat
echo dvidrv dvihplj%MC% @ljh_lh /og=600/om=2000/fl=-1/po=prn %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>%emtexdir%\BIN\ph_lh.bat
if %FNT%==0 goto d1
echo dvidrv dviscr%MC% @%FNT%_lh @view %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>%emtexdir%\BIN\v_lh.bat
if %FNT%==ljh copy %emtexdir%\BIN\ph_lh.bat %emtexdir%\BIN\p_lh.bat
if %FNT%==lj  copy %emtexdir%\BIN\pl_lh.bat %emtexdir%\BIN\p_lh.bat
if %FNT%==fx  copy %emtexdir%\BIN\px_lh.bat %emtexdir%\BIN\p_lh.bat
if %FNT%==p6h copy %emtexdir%\BIN\pq_lh.bat %emtexdir%\BIN\p_lh.bat
:d1
copy %emtexdir%\BIN\vl_lh.bat %emtexdir%\BIN\v_lh.bat
copy %emtexdir%\BIN\pl_lh.bat %emtexdir%\BIN\p_lh.bat

:d2
if %FNT%==0 goto df0
echo.
echo Copying font libraries
echo.
echo Copy font libraries in your Font directory :
%eminst%\ask.exe %FNT%_base.fli, %FNT%_more.fli, %FNT%_bms.fli, %FNT%_blh.fli ? (Y/N),yYnN
echo.
if errorlevel 3 goto df0
call %eminst%\instb.bat /copy %1 %2 %FNT%_base.fli %FNT%_base.fli
if %PC%==error goto erend
call %eminst%\instb.bat /copy %1 %2 %FNT%_more.fli %FNT%_more.fli
if %PC%==error goto erend
call %eminst%\instb.bat /copy %1 %2 %FNT%_bms.fli %FNT%_bms.fli
if %PC%==error goto erend
%eminst%\ask.exe Copy Russian fonts : %FNT%_blh.fli ? (Y/N),yYnN
echo.
if errorlevel 3 goto df0
call %eminst%\instb.bat /copy %1 %2 %FNT%_blh.fli %FNT%_blh.fli
if %PC%==error goto erend

:df0
if %MF%==0 goto df7
cls
echo.
echo.
echo Unpack basman.bat
for %%c in (mf386,Cmf386) do if %MF%==%%c goto df2
call %eminst%\instb.bat %1 %2 cyrt -d -o mfbases/bas/basman.bat %emtexdir%\
if %PC%==error goto erend
goto df3
:df2
md %emtexdir%\BMFBASES\BAS
call %eminst%\instb.bat %1 %2 cyrt -o mfbases/bas/basman.bat %emtexdir%\BMFBASES\BAS\
if %PC%==error goto erend

:df3
if NOT exist %emtexdir%\MFJOB\dvidrvlh.mfj goto df7
echo.
echo Copying added data for dvidrv.mfj.
if exist %emtexdir%\MFJOB\dvidrv.lhj goto df4
echo (Old file is renamed to dvidrv.mlh)
copy %emtexdir%\MFJOB\dvidrv.mfj %emtexdir%\MFJOB\DVIDRV.LHJ
:df4
copy %emtexdir%\MFJOB\dvidrvlh.mfj + %emtexdir%\MFJOB\dvidrv.lhj %emtexdir%\MFJOB\DVIDRV.MFJ

:df7
set TeX=
set NF=
set AM=
for %%c in (tex*,dvidrv) do if exist %emtexdir%\BIN\%%c.exe goto ds1
if %PC%==0 goto ds2
:ds1
for %%c in (dvips16,dvips32) do if exist %emtexdir%\BIN\%%c.exe goto ds2
set DS=Y
goto ds3
:ds2
set DS=N
:ds3
for %%c in (%LA%,%LAe%) do if %%c==Y goto ds4
for %%c in (LATEX209,LATEX2E) do if exist %emtexdir%\TEXINPUT\%%c\*.* goto ds4
set LA=
set LAe=
set MI=A
goto ds6
:ds4
set MI=N
set LA=
set LAe=
for %%c in (makeindx,mkidx32) do if exist %emtexdir%\BIN\%%c.exe goto ds5
set MI=Y
:ds5
set BI=N
set TC=N
set PI=N
if NOT exist %emtexdir%\BIN\bibtex*.exe     set BI=Y
if NOT exist %emtexdir%\BIN\texcad.exe      set TC=Y
if NOT exist %emtexdir%\TEXINPUT\PICTEX\*.* set PI=Y
for %%c in (%DS%,%MI%,%BI%,%TC%,%PI%) do if "%%c"=="Y" goto ds6
if %DS%==Y goto di41
if %DS%==N goto rs0
:ds6
cls
echo.
echo.
echo **************************************************************************
echo ??? Installation of additional package(s)
echo.
if "%MI%"=="A" goto ds61
if "%MI%"=="Y" echo     *) MakeIndex
if "%MI%"=="N" echo     +) MakeIndex
if "%BI%"=="Y" echo     *) BibTeX
if "%BI%"=="N" echo     +) BibTeX
if "%TC%"=="Y" echo     *) TeXcad
if "%TC%"=="N" echo     +) TeXcad
if "%PI%"=="Y" echo     *) PicTeX
if "%PI%"=="N" echo     +) PicTeX
:ds61
if "%DS%"=="Y" echo     *) DVIPS
if "%DS%"=="N" echo     +) DVIPS
echo.
echo + installed; * not installed
%eminst%\ask.exe Do you want to install anything ? (Y/N),yYnN
echo.
if errorlevel 3 goto rs0

:di1
cls
echo.
echo.
if "%MI%"=="Y" goto di10
%eminst%\ask.exe ??? MakeIndex already installed. Overwrite ? (Y/N),yYnN
echo.
if errorlevel 3 goto di2
goto di11
:di10
%eminst%\ask.exe ??? Do you want to install MakeIndex ? (Y/N),yYnN
echo.
if errorlevel 3 goto di2
:di11
echo.
echo Unpack MakeIndex files
call %eminst%\instb.bat %1 %2 makeindx -d -o %1:\
if %PC%==error goto erend

:di2
echo.
if "%BI%"=="Y" goto di20
%eminst%\ask.exe ??? BibTeX already installed. Overwrite ? (Y/N),yYnN
echo.
if errorlevel 3 goto di3
goto di21
:di20
%eminst%\ask.exe ??? Do you want to install BibTeX ? (Y/N),yYnN
echo.
if errorlevel 3 goto di3
:di21
echo.
echo Unpack BibTeX files
call %eminst%\instb.bat %1 %2 bibt -d -o %1:\
if %PC%==error goto erend

:di3
echo.
if "%TC%"=="Y" goto di30
%eminst%\ask.exe ??? TeXcad already installed. Overwrite ? (Y/N),yYnN
echo.
if errorlevel 3 goto di3a
goto di31
:di30
%eminst%\ask.exe ??? Do you want to install TeXcad ? (Y/N),yYnN
echo.
if errorlevel 3 goto di3a
:di31
echo.
echo Unpack TeXCad files
call %eminst%\instb.bat %1 %2 texcad @%eminst%\texcad.ls -d -o %1:\
if %PC%==error goto erend

:di3a
echo.
if "%PI%"=="Y" goto di3a0
%eminst%\ask.exe ??? PicTeX already installed. Overwrite ? (Y/N),yYnN
echo.
if errorlevel 3 goto di4
goto di3a1
:di3a0
%eminst%\ask.exe ??? Do you want to install PicTeX ? (Y/N),yYnN
echo.
if errorlevel 3 goto di4
:di3a1
echo.
echo Unpack PicTeX files
call %eminst%\instb.bat %1 %2 pictex -d -o %1:\
if %PC%==error goto erend

:di4
cls
echo.
echo.
if "%DS%"=="Y" goto di40
%eminst%\ask.exe ??? DVIPS already installed. Overwrite ? (Y/N),yYnN
echo.
if errorlevel 3 goto rs0
goto di41
:di40
%eminst%\ask.exe ??? Do you want to install DVIPS ? (Y/N),yYnN
echo.
if errorlevel 3 goto rs0
:di41
echo.
echo Unpack DVIPS files
call %eminst%\instb.bat %1 %2 psex -d -o @%eminst%\dvips.lsc %1:\
if %PC%==error goto erend
call %eminst%\instb.bat %1 %2 cyrt -d -o bin/dvips*.* data/dvips/*.* %emtexdir%\
if %PC%==error goto erend
echo.
echo Unpack DVIPS virtual fonts (VF)
if not exist %emtexdir%\VF\LH\*.* md %emtexdir%\VF>nul
md %emtexdir%\VF\DVIPS>nul
call %eminst%\instb.bat %1 %2 psex -o texfonts/vf/*.* %emtexdir%\VF\DVIPS\
if %PC%==error goto erend
echo.
echo Creating batch-files for DVIPS
echo @echo off>%emtexdir%\BIN\ps_lj.bat
echo @echo off>%emtexdir%\BIN\ps_ljh.bat
echo @echo off>%emtexdir%\BIN\dvips.bat
echo ::ps_lj  -- Creation of Postscript file>>%emtexdir%\BIN\ps_lj.bat
echo ::ps_ljh -- Creation of Postscript file>>%emtexdir%\BIN\ps_ljh.bat
echo ::dvips  -- Creation of Postscript file>>%emtexdir%\BIN\dvips.bat
for %%c in (tex,tex186,Ctex,Ctex186) do if NOT %PC%==%%c goto di411
echo dvips16.exe -P lj_lh %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>%emtexdir%\BIN\ps_lj.bat
echo dvips16.exe -P ljh_lh %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>%emtexdir%\BIN\ps_ljh.bat
if %FNT%==ljh echo dvips16.exe -P ljh_lh %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>%emtexdir%\BIN\dvips.bat
if NOT %FNT%==ljh echo dvips16.exe -P lj_lh %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>%emtexdir%\BIN\dvips.bat
goto di412
:di411
echo dvips32.exe -P lj_lh %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>%emtexdir%\BIN\ps_lj.bat
echo dvips32.exe -P ljh_lh %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>%emtexdir%\BIN\ps_ljh.bat
if %FNT%==ljh echo dvips32.exe -P ljh_lh %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>%emtexdir%\BIN\dvips.bat
if NOT %FNT%==ljh echo dvips32.exe -P lj_lh %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>%emtexdir%\BIN\dvips.bat
:di412
echo.
echo Unpack PostScript utilites
call %eminst%\instb.bat %1 %2 psutils -o psutils/bin-emx/*.* %emtexdir%\BIN\
call %eminst%\instb.bat %1 %2 psutils -o psutils/readme.os2 %emtexdir%\DOC\DVIPS\
if %PC%==error goto erend

:rs0
cls
echo.
echo.
echo LAST
echo Creating file set_texr.bat for emTeX environments

if NOT exist %emtexdir%\BIN\set_texr.bat goto rs1
%eminst%\ask.exe File set_texr.bat already exists. Overwrite ? (Y/N),yYnN
echo.
if errorlevel 3 goto lact
:rs1
echo @echo off>%emtexdir%\BIN\set_texr.bat
echo set emtexdir=%emtexdir%>>%emtexdir%\BIN\set_texr.bat
echo set dvidrvfonts=%dvidrvfonts%>>%emtexdir%\BIN\set_texr.bat
echo.>>%emtexdir%\BIN\set_texr.bat
echo set emtexopt=/mt15000/mf45000>>%emtexdir%\BIN\set_texr.bat
echo.
echo.
echo ??? Choose online editor (called after `e'(edit) option):
echo     TeX Editor (te.exe -- supported by CyrTUG package*) -- 1
echo     MultiEdit  (me.exe -- if you have installed it )    -- 2
rem echo     Lexicon    -- 3
echo *!! TeX Editor works with files which have size less than 65kb only
rem echo NOTE. If you have doubts choose 1.
%eminst%\ask.exe Enter number,123
echo.
rem if errorlevel 3 goto rle
if errorlevel 2 goto rme
echo set emtexed=te /L%%%%3 %%%%2 /:%%%%1>>%emtexdir%\BIN\set_texr.bat
goto rs2
:rme
echo set emtexed=me /L%%%%1 %%%%2 %%%%3>>%emtexdir%\BIN\set_texr.bat
goto rs2
:rle
rem echo set emtexed=lexicon %%%%2 %%%%3>>%emtexdir%\BIN\set_texr.bat
:rs2
echo.>>%emtexdir%\BIN\set_texr.bat

echo set texinput=%%emtexdir%%\TEXINPUT!!>>%emtexdir%\BIN\set_texr.bat
echo rem trick for Norton Commander and other command shells>>%emtexdir%\BIN\set_texr.bat
echo set save_texinput=%%texinput%%;%%emtexdir%%\TEXINPUT\LATEX2E!!>>%emtexdir%\BIN\set_texr.bat
echo.>>%emtexdir%\BIN\set_texr.bat

echo set virtfonts=%%emtexdir%%\VF!>>%emtexdir%\BIN\set_texr.bat
echo.>>%emtexdir%\BIN\set_texr.bat

if %PC%==0 goto rs3
if %PC%==tex set MF=mf
for %%c in (186,386) do if %PC%==tex%%c set MF=mf%%c
if NOT %MF%==0 goto rs4
:rs3
if exist %emtexdir%\BIN\tex.exe set MF=mf
for %%c in (186,386) do if exist %emtexdir%\BIN\tex%%c.exe set MF=mf%%c
if NOT %MF%==0 goto rs4
for %%c in (mf,mf186,mf386) do if exist %emtexdir%\BIN\%%c.exe set MF=mf%%c
:rs4
if %MF%==mf    echo set mfjobopt=>>%emtexdir%\BIN\set_texr.bat
if %MF%==mf186 echo set mfjobopt=/1>>%emtexdir%\BIN\set_texr.bat
if %MF%==mf386 echo set mfjobopt=/3>>%emtexdir%\BIN\set_texr.bat
echo.>>%emtexdir%\BIN\set_texr.bat

if %DS%==Y goto rs5
echo rem for DVIPS: you may uncomment this line>>%emtexdir%\BIN\set_texr.bat
echo rem set texconfig=%%emtexdir%%\DATA\DVIPS>>%emtexdir%\BIN\set_texr.bat
goto rs6
:rs5
echo rem for DVIPS: you may comment this line>>%emtexdir%\BIN\set_texr.bat
echo set texconfig=%%emtexdir%%\DATA\DVIPS>>%emtexdir%\BIN\set_texr.bat
:rs6
echo.>>%emtexdir%\BIN\set_texr.bat

echo rem Check for set_texr installation>>%emtexdir%\BIN\set_texr.bat
echo set emtex=%1>>%emtexdir%\BIN\set_texr.bat
echo if "%%emtex%%"=="" goto nosets>>%emtexdir%\BIN\set_texr.bat
echo.>>%emtexdir%\BIN\set_texr.bat

echo echo.>>%emtexdir%\BIN\set_texr.bat
echo echo TeX environments successfully installed>>%emtexdir%\BIN\set_texr.bat
echo goto end>>%emtexdir%\BIN\set_texr.bat
echo.>>%emtexdir%\BIN\set_texr.bat

echo :nosets>>%emtexdir%\BIN\set_texr.bat
echo cls>>%emtexdir%\BIN\set_texr.bat
echo set>>%emtexdir%\BIN\set_texr.bat
echo echo ***>>%emtexdir%\BIN\set_texr.bat
echo echo У Вас возможно некорректно заданы переменные сред для работы с TeXом>>%emtexdir%\BIN\set_texr.bat
echo echo Последняя строка до *** должна быть: EMTEX=%1>>%emtexdir%\BIN\set_texr.bat
echo echo Если вы видите оборванную (последнюю) строку или ее вообще нет,>>%emtexdir%\BIN\set_texr.bat
echo echo задайте строку>>%emtexdir%\BIN\set_texr.bat
echo echo.>>%emtexdir%\BIN\set_texr.bat
echo echo    shell = c:\command.com /p /e:1024>>%emtexdir%\BIN\set_texr.bat
echo echo.>>%emtexdir%\BIN\set_texr.bat
echo echo в файле config.sys и перезагрузите компьютер.>>%emtexdir%\BIN\set_texr.bat
echo pause>>%emtexdir%\BIN\set_texr.bat
echo :end>>%emtexdir%\BIN\set_texr.bat

:lact
cls
echo.
echo LAST ACTIONS
echo.
echo Deleting temporary files from %eminst%\
if exist %eminst%\*.ls  del %eminst%\*.ls
if exist %eminst%\*.log del %eminst%\*.log
if NOT exist %emtexdir%\BIN\*.* goto help
echo.
echo Copying ask.exe to %emtexdir%\BIN
if NOT exist %emtexdir%\BIN\ask.exe copy %eminst%\ask.exe %emtexdir%\BIN

:help
%eminst%\ask.exe QUESTION: Do you need last help ? English Russian or None (E/R/N),rReEnN
echo.
if errorlevel 5 goto end
if errorlevel 3 goto eng
if errorlevel 1 goto rus
:rus
call %eminst%\insthlpr.bat %1
goto end
:eng
call %eminst%\insthlpe.bat %1
goto end

:usage
echo This file is satellite to eminst98.bat and cinst98.bat

:end
cls
echo.
echo.
echo KILLING TEMPORARY SET ENVIRONMENTS
echo.
SET PC=
SET MF=
SET FNT=
SET MC=
SET TeX=
SET LA=
SET LAe=
SET AM=
SET NF=
SET DS=
SET BI=
SET TC=
SET MI=
SET PI=
echo Are the paths %1:\EMTEX\BIN [;%1:\EMX\BIN] placed in PATH line of autoexec.bat
echo (see below) :
echo.
PATH
echo.
echo If they are you may run set_texr.bat with TeX environments just now.
echo NOTE. If you however installed under Command Shell you wan't get anything.
if exist %emtexdir%\BIN\set_texr.bat %emtexdir%\BIN\ask.exe Do you want to run set_texr.bat just now ? (Y/N),yYnN
echo.
if errorlevel 3 goto endi
call %emtexdir%\BIN\set_texr.bat

:endi
echo.
echo THE END OF INSTALLATION
echo ***********************
goto vend
:erend
echo.
echo See you again . . .
:vend
