summaryrefslogtreecommitdiff
path: root/obsolete/systems/os2/emtex-contrib/emtexTDS/tdsinst.cmd
blob: 29f49f928e961601b570de10d766fbb5f2187cbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
/* REXX */
/*
  tdsinst.cmd
  
  Copyright (C) 1998--2001 Walter Schmidt, Erlangen 
  
  emtex/TDS installation program
  
  to be run
  from a local directory, which must contain all required files
  
*/



/*
  Initialization:
*/  
INTRO = "Installation script for emTeX/TDS v0.56 as of 2001-09-30"
VERSION = 0.56
REQEMXREV = 60
REQEMXVER = "0.9d"

bootdrv = querybootdrv()
wrkdir = strip(directory(), "T", "\")

ret = RxFuncAdd("SysLoadFuncs", "REXXUTIL", "SysLoadFuncs")
call SysLoadFuncs

SIGNAL on error

/* Load text strings for SysFileDel and SysRmDir return codes.         */
CALL LoadDELRCText   /* provides text strings for SysFileDel return codes */
CALL LoadRDRCText    /* provides text strings for SysRmDir return codes   */

say 
say INTRO
say
say "On which drive do you want emTeX/TDS to be installed or updated?"
say "(hit <return> only to select the boot drive)"
answer = linein()
texdrive = translate(substr(answer,1,1)) || ":"
if texdrive = ":" then texdrive = bootdrv

ver = SysIni(texdrive"\texmf\emtex\data\EMTEXTDS.INI", "EMTEXTDS", "VERSION")
if ver = "ERROR:" then
   ver = 0
else do
   say
   say "emTeX/TDS version " || ver || " detected."
   say
end

/* full install or update only? 

   ver =  0    :  first install, no cleanup required
   ver =  0.1  :  force full install, despite higher version #
   ver <  0.53 :  full install
   ver >= 0.53 :  update only
*/

/* skip this step if full install is required, anyway */
if ver < 0.53 then signal checkfiles

say "By default, your emTeX/TDS system will be updated only."
say "However, you may also force a full reinstall."
say
say "Do you request a full reinstall? (y/n)"
answer = translate(substr(linein(),1,1))
if answer = "Y" then ver = 0.1


/* Determine the required files */
checkfiles:

if ver >= 0.55 then
  reqfile.0 = 1
else
if ver >= 0.53 then 
  reqfile.0 = 2
else
  reqfile.0 = 11

/* search for the files in the current directory  */
reqfile.1 =  "texmf.zip"
reqfile.2 =  "config.zip"
reqfile.3 =  "bibtex4b.zip"
reqfile.4 =  "dvid16h1.zip"
reqfile.5 =  "mf4b.zip"
reqfile.6 =  "mfjob12d.zip"
reqfile.7 =  "mfware.zip"
reqfile.8 =  "tex4b.zip"
reqfile.9 =  "texware.zip"
reqfile.10=  "makeindx.zip"
reqfile.11 =  "dvid16h2.zip"
if CheckRequiredFiles("V") then do
   do i = 1 to reqfile.0
      reqfile.i = wrkdir|| "\" || reqfile.i
   end
end
else signal fileerr

/* Last exit */
say
say "emTeX/TDS on drive " || texdrive || " will be installed/updated."
say "Continue? (y/n)"
answer = translate(substr(linein(),1,1))
if answer <> "Y" then signal cancel



/* 
   Step 0
   ------
   go to the target drive and create the texmf root directory
*/

call setlocal
call directory(texdrive||"\")
call sysmkdir("texmf")
call directory("\texmf")


/* 
   Step 1
   ------
   Check for unzip.exe
*/
if SysSearchPath("PATH", "unzip.exe") = "" then signal unziperr


/*
  Step 2
  ------
  Removing obsolete files created by previous versions
*/

/* skip this step, if this is the first install */
if ver = 0  then signal euro

say "Removing possibly obsolete files ..."

call SysFileDelete("emtex\bmfbases\makemf.cmd")
call SysFileDelete("doc\generic\german\gerdoc98.dvi")
call SysFileDelete("emtex\doc\bibtex.doc")
call SysFileDelete("emtex\doc\makeindx.doc")
call SysFileDelete("emtex\doc\makeindx.cpy")
call SysFileDelete("doc\emtexTDS\install.ger")
call SysFileDelete("doc\emtexTDS\install.eng")
call SysFileDelete("doc\latex\eurosans\readme")
call SysFileDelete("doc\latex\graphics\grfguide.ps")

call SysFileDelete("tex\latex\local\local.ins")

call SysFileDelete("tex\latex\amsmath\amstext.sty.org")

call SysFileDelete("doc\generic\german\gerdoc.tex")
call SysFileDelete("fonts\source\public\logo\manfnt.mf")
call SysFileDelete("fonts\tfm\public\logo\manfnt.tfm")
call SysFileDelete("source\generic\babel\lcydefs.tex")
call SysFileDelete("dvips\micropress\cmfonts.map")
/* files have been moved to other directory */

call SysFileDelete("emtex\bin\bibtex.exe")
call SysFileDelete("emtex\bin\makeindex.exe")
call SysFileDelete("emtex\bin\dvihplj.exe")
/* will be replaced later */


call ddt("tex\latex\base")

/*
call ddt("tex\latex\tools")
call ddt("tex\latex\graphics")
call ddt("tex\latex\cyrillic")
*/

call ddt("source\latex\babel")
call ddt("tex\latex\babel")
call ddt("doc\latex\babel")

call ddt("dvips\base")

call ddt("fonts\type1\ams")
call ddt("fonts\type1\public\cm")
call ddt("fonts\type1\public\logo")
call ddt("fonts\type1\public\misc")
call ddt("fonts\type1\public\rsfs")
call ddt("fonts\type1\public\wasy")

call ddt("fonts\source\public\logo")

call ddt("tex\latex\psnfss\pag")
call ddt("tex\latex\psnfss\pbk")
call ddt("tex\latex\psnfss\pcr")
call ddt("tex\latex\psnfss\phv")
call ddt("tex\latex\psnfss\pnc")
call ddt("tex\latex\psnfss\ppl")
call ddt("tex\latex\psnfss\psy")
call ddt("tex\latex\psnfss\ptm")
call ddt("tex\latex\psnfss\pzc")
call ddt("tex\latex\psnfss\pzd")

call ddt("source\latex\psnfss")
call ddt("doc\latex\psnfss")
call ddt("source\latex\mathpple")
call ddt("tex\latex\mathpple")
call ddt("doc\latex\mathpple")
call ddt("fonts\tfm\public\logo")
call ddt("dvips\bluesky")
call ddt("tex\latex\amslatex")
call ddt("doc\latex\amslatex")

call SysFileDelete("doc\emtextds\gsinstal.eng")
call SysFileDelete("doc\emtextds\gsinstal.ger")
call SysFileDelete("metafont\base\plain.mf.sav")

/*
call ddt("tex\latex\koma.script")
call ddt("doc\latex\koma-script")
call ddt("source\latex\koma-script")
*/

call SysFileDelete("tex\latex\amsmath\amsdtx.cls")

/* obsolete files, which are possibly not overwritten later */

say " done."


/* Step 2a
   -------
   Rename Adobe Euro Fonts, if present
*/
euro:

/* skip this step, if v=0 or v>=0.53 found */

if (ver  = 0) | (ver >= 0.53) then signal emtex

old.1 =  "\texmf\fonts\type1\adobe\eurofont\_1______.pfb"
old.2 =  "\texmf\fonts\type1\adobe\eurofont\_1B_____.pfb"  
old.3 =  "\texmf\fonts\type1\adobe\eurofont\_1I_____.pfb"  
old.4 =  "\texmf\fonts\type1\adobe\eurofont\_1BI____.pfb"  
old.5 =  "\texmf\fonts\type1\adobe\eurofont\_2______.pfb"  
old.6 =  "\texmf\fonts\type1\adobe\eurofont\_2B_____.pfb"  
old.7 =  "\texmf\fonts\type1\adobe\eurofont\_2I_____.pfb"  
old.8 =  "\texmf\fonts\type1\adobe\eurofont\_2BI____.pfb"  
old.9 =  "\texmf\fonts\type1\adobe\eurofont\_3______.pfb"  
old.10 = "\texmf\fonts\type1\adobe\eurofont\_3B_____.pfb"  
old.11 = "\texmf\fonts\type1\adobe\eurofont\_3I_____.pfb"  
old.12 = "\texmf\fonts\type1\adobe\eurofont\_3BI____.pfb"  

new.1 = "zpeurs.pfb" 
new.2 = "zpeubs.pfb"    
new.3 = "zpeuris.pfb"   
new.4 = "zpeubis.pfb"   
new.5 = "zpeurt.pfb"    
new.6 = "zpeubt.pfb"    
new.7 = "zpeurit.pfb"   
new.8 = "zpeubit.pfb"   
new.9 = "zpeur.pfb"     
new.10 = "zpeub.pfb"     
new.11 = "zpeuri.pfb"    
new.12 = "zpeubi.pfb"    

do i = 1 to 12
   if stream(old.i, "C", "QUERY EXISTS") <> "" & ,
      stream("\texmf\fonts\type1\adobe\eurofont\"||new.i, "C", "QUERY EXISTS") = "" then do
        "ren " old.i new.i
   end
end


/* 
  Step 3
  ------
  Install the required parts of the original emTeX distribution.
*/
emtex:

/* skip this step, if ver>=0.53 found */
if ver >= 0.53 then signal tds

/* Overwrite existing files */
ret=value("UNZIP", "-qqo", "OS2ENVIRONMENT")

say "Installing emTeX ..."

call SysMkDir("\texmf\doc")
call SysMkDir("\texmf\doc\bibtex")

/* reqfile.3 => bibtex4b. */
"unzip -j "||reqfile.3 || " emtex/doc/bibtex.doc -d \texmf\doc\bibtex"
"unzip -j "||reqfile.3 || " emtex/texinput/bibtex/* -d \texmf\doc\bibtex" 
"unzip "||reqfile.3 || " emtex/bin/bibtex32.exe"
"ren emtex\bin\bibtex32.exe bibtex.exe"

/* reqfile.4 => dvid16h1 */
"unzip "||reqfile.4|| " emtex/doc/adjust.dvi"
"unzip "||reqfile.4|| " emtex/book/german/dvidrv.inf"
"unzip "||reqfile.4|| " emtex/book/english/dvidrv.inf"
"unzip "||reqfile.4|| " emtex/data/dvidrv.err"
/* "unzip "||reqfile.4|| " emtex/bin/dvihplj.exe" */
"unzip "||reqfile.4|| " emtex/bin/dvipm.exe"
"unzip "||reqfile.4|| " emtex/bin/dvipm.ico"
"unzip "||reqfile.4|| " emtex/dll/dvipmres.dll"
"unzip "||reqfile.4|| " emtex/dll/emdll1x.dll"
"unzip "||reqfile.4|| " emtex/dll/emdll1x2.dll"
"unzip "||reqfile.4|| " emtex/dll/emdll2x.dll"
"unzip "||reqfile.4|| " emtex/help/dvipmeng.hlp"
"unzip "||reqfile.4|| " emtex/help/dvipmger.hlp"
"unzip "||reqfile.4|| " emtex/data/2a5_a4.cnf"

/* reqfile.5 => mf4b */
"unzip "||reqfile.5||" emtex/book/german/metafont.inf"
"unzip "||reqfile.5||" emtex/book/english/metafont.inf"
"unzip "||reqfile.5||" emtex/bin/mf386.exe"
"unzip "||reqfile.5||" emtex/bin/mfpm386.ovl"
"unzip "||reqfile.5||" emtex/bin/gftopk.exe"
"unzip "||reqfile.5||" emtex/bmfbases/mf.poo"
"unzip "||reqfile.5||" emtex/help/mfpmeng.hlp"
"unzip "||reqfile.5||" emtex/help/mfpmger.hlp"

/* reqfile.6 => mfjob12d */
"unzip "||reqfile.6||" emtex/book/german/mfjob.inf"
"unzip "||reqfile.6||" emtex/book/english/mfjob.inf"
"unzip "||reqfile.6||" emtex/bin/mfjob.exe"
"unzip "||reqfile.6||" emtex/bin/mfjob.ovl"

/* reqfile.7 => mfware */
"unzip "||reqfile.7||" emtex/bin/gftodvi.exe"
"unzip "||reqfile.7||" emtex/bin/mft.exe"
"unzip "||reqfile.7||" emtex/doc/german/mfware.doc"
"unzip "||reqfile.7||" emtex/doc/english/mfware.doc"

/* reqfile.8 => tex4b */
"unzip "||reqfile.8||" emtex/bin/htex386.exe"
"unzip "||reqfile.8||" emtex/htexfmts/tex.poo"
"unzip "||reqfile.8||" emtex/book/german/tex.inf"
"unzip "||reqfile.8||" emtex/book/english/tex.inf"

/* reqfile.9 => texware */
"unzip "||reqfile.9||" emtex/doc/german/texware.doc"
"unzip "||reqfile.9||" emtex/doc/english/texware.doc"
"unzip "||reqfile.9||" emtex/bin/pltotf.exe"
"unzip "||reqfile.9||" emtex/bin/tftopl.exe"
"unzip "||reqfile.9||" emtex/bin/vftovp.exe"
/* "unzip "||reqfile.9||" emtex/bin/vptovf.exe" */

/* reqfile.10 => makeindx */
"unzip "||reqfile.10||" emtex/bin/mkidx32.exe"
"ren emtex\bin\mkidx32.exe makeindex.exe"

/* reqfile.11 => dvid16h2 */
"unzip "||reqfile.11||" emtex/bin/dvihplj3.exe"
"ren emtex\bin\dvihplj3.exe dvihplj.exe"

call SysMkDir("\texmf\bibtex")
call SysMkDir("\texmf\bibtex\bib")
call SysMkDir("\texmf\bibtex\bst")

"unzip -j "||reqfile.3||" emtex\bibtex\bib\* -d \texmf\bibtex\bib"
"unzip -j "||reqfile.3||" emtex\bibtex\bst\* -d \texmf\bibtex\bst"

say " done."


/*
  Step 4
  ------
  Installing 
  - the non-emTeX parts of the TDS tree and
    customized cmd scripts for emtex,
  - the configuration files,
*/
tds:

say "Installing the texmf tree ..."
/* Overwrite existing files */
ret=value("UNZIP", "-qqo", "OS2ENVIRONMENT")
/* reqfile.1 => texmf */
"unzip "||reqfile.1

if reqfile.0 >= 2 then do
   /* here we have to ask before owerwriting configuration files: */
   ret=value("UNZIP", "-qq", "OS2ENVIRONMENT")
   /* reqfile.2 => config */
   "unzip "||reqfile.2
end

say " done."

/* The configuration file docstrip.cfg is special,    */
/* because its contents must reflect the drive letter */
/* where TeX is installed.                            */
/* This file is generated unless it's already present.*/
filename = texdrive || "\texmf\tex\latex\local\docstrip.cfg"
if stream(filename, "C", "QUERY EXISTS") = "" then do
   say "Creating the file docstrip.cfg ..."
   call lineout filename, "%% file docstrip.cfg, generated by tdsinst.cmd"
   call lineout filename, "%% do not edit this file!"
   call lineout filename, "\BaseDirectory{"||texdrive||"/texmf}"
   call lineout filename, "\UseTDS"
   call stream filename, "C", "CLOSE"
   say " done."
end


/*
  Step 5
  ------
  Creating a program object for dvipm
*/
/* skip this step, unless full install is required */
if ver > 0.1 then signal writever

say
say "Do you want an object for dvipm to be created on the desktop? (y/n)"
answer = translate(substr(linein(),1,1))
if  answer = "Y" then do
  say "Creating an object for the dvi viewer ..."
  res = make_po('dvipm', 'PM', texdrive||'\texmf\emtex\bin\dvipm.exe', '@vp.cnf %*', '')
  if res = 1  then say " done."
  else say " failed."
end


/*
  Step 5a
  --------
  Writing the version number
*/
writever:
call SysIni "\texmf\emtex\data\EMTEXTDS.INI", "EMTEXTDS", "VERSION", VERSION
say
say "Version number" VERSION "written."
say
say "All files of the emTeX/TDS system have been successfully installed."
"pause"


/*
  Step 6
  ------
  Checking emx
*/
say
say "I am going to check the EMX library now."
say
emxpaths = 0
currentrev = emxrevision()
say "emx rev. =" currentrev
if (currentrev = 0) then do
   call beep 440,250
   say
   say "I cannot find the emx runtime environment."
   say "Install the latest version of emx before using TeX!"
   "pause"
end
if (currentrev > 0) & (currentrev < REQEMXREV)then do
   call beep 440,250
   say
   say "The emx runtime environment found is not up to date."
   say "Install the latest version of emx before using TeX!"
   "pause"
end
else say "Ok."


/*
  Step 7
  ------
  Updating config.sys
*/

/* skip this step if ver > 0.5 found */
if ver > 0.5 then signal done 

configfile = bootdrv||"\config.sys"
if stream(configfile,"C","QUERY EXISTS") = "" then signal nobootdrv

call readconfig configfile

if checkvar("TMP") = "" then do
   tmpname = bootdrv||"\tmp"
   call SysMkDir tmpname
   call addvar "TMP", tmpname
   say
   say "Temporary files will be created in the directory" tmpname "."
   say 
end /* do */

call addvar "EMTEXDIR", texdrive||"\TEXMF\EMTEX"
call addvar "TEXMACROS", texdrive||"\TEXMF\TEX"
call addvar "TEXTFM", texdrive||"\TEXMF\FONTS\TFM!!;."
call addvar "BFONTS", texdrive||"\TEXMF\FONTS\PK"
call addvar "TYPE1FONTS", texdrive||"\TEXMF\FONTS\TYPE1"
call addvar "TEXCONFIG", texdrive||"\TEXMF\DVIPS!!"
call addvar "VFONTS", texdrive||"\TEXMF\FONTS\VF!!"
call addvar "EMTEXSWCHAR", "-"
call addvar "MFOPT", "-mp50000"
call addvar "MFJOBOPT", "-3 -i"
call addvar "MFINPUT", texdrive||"\TEXMF\FONTS\SOURCE!!;"||texdrive"\TEXMF\METAFONT!"
call addvar "INDEXSTYLE", texdrive||"\TEXMF\MAKEINDEX"
call addvar "BSTINPUT", texdrive||"\TEXMF\BIBTEX\BST"
call addvar "BIBINPUT", texdrive||"\TEXMF\BIBTEX\BIB"
if pathedit("PATH", texdrive||"\texmf\emtex\bin;") = 0 then signal updfailed
if pathedit( "HELP", texdrive||"\texmf\emtex\help;") = 0 then signal updfailed
if libpathedit(texdrive||"\texmf\emtex\dll;") = 0 then signal updfailed

say
say "The installation program is going to update the file config.sys now."
say "If you prefer to do this manually, then enter `n' below,"
say "otherwise enter `y' to continue."
say "Continue? (y/n)"
answer = translate(substr(linein(),1,1))
if answer <> "Y" then signal done

tempfile=SysTempFileName(bootdrv||"\config??.sys")
if tempfile="" then signal updfailed

signal on error name updfailed
savedfile = filespec("N", tempfile)
"ren" configfile savedfile
say
say "The file" configfile "has been renamed to" savedfile "."
res = writeconfig(configfile)
if res=0 then do
   call beep 440,250
   say "Writing a new file" configfile "failed".
   say "Rename" savedfile "to config.sys and apply the changes manually."
   end
else  do 
   say
   say "A new file" configfile "has been written."
   say "Shutdown and reboot OS/2 now to make the changes come into effect."
end


/* 
  exiting
*/
done:
say
say "Finis!"
exit


/*
  Error handling:
*/
nobootdrv:
say
say "The installation program could not locate the file config.sys"
say "and was unable to determine whether it needs to be updated."
say "Please, see the installation instructions for the changes required"
say "and how to apply them manually."
exit

updfailed:
say
say "Updating config.sys failed."
say "The file config.sys has *** not *** been changed."
say "Please, read the installation instructions"
say "and apply any changes manually."
exit

error: 
call beep 440,250
say
say 'Error: "'condition('D')'"' 'failed.'
exit

fileerr:
call beep 440,250
say
say "One or more of the files required to"
say "install or update emTeX/TDS were not found."
exit

unziperr:
call beep 440,250
say
say 'The required program "unzip.exe" could not be found.'
exit

cancel:
say "You have terminated the installation program."
exit


/* 
  Procedures used above: 
*/


/*
make_folder: procedure
  location = '<EMTEXTDS_FOLDER>'
  if \SysCreateObject('WPFolder', 'emTeX/TDS', '<WP_DESKTOP>', ,
                      'OBJECTID='||location, 'update') then do
    say 'Cannot create emTeX/TDS folder.'
    exit 1
  end
  return
*/

make_po: procedure
  parse arg title, progtype, exename, parameters, workdir
  
  options = 'PROGTYPE='||progtype||';' ||,
            'EXENAME='||exename||';'
            
  if parameters <> '' then 
    options = options || 'PARAMETERS='||parameters||';'
    
  if workdir <> '' then 
    options = options || 'STARTUPDIR='||workdir||';'
    
  if \SysCreateObject('WPProgram', title, '<WP_DESKTOP>', options, 'Update') then do
    say 'Cannot create program object.'
    return 0
  end
  else
    return 1


/*
   query boot drive 
   usage:   querybootdrv()
   returns: letter of boot drive incl. colon
*/
querybootdrv: PROCEDURE
bootdr = value('COMSPEC', , 'OS2ENVIRONMENT')
bootdr = filespec('D', bootdr)
if bootdr = "" then do
   say "Please, tell me the drive letter of the boot drive:"
   answer = linein()
   bootdr = substr(strip(answer),1,1)||":"
end
return bootdr


/* 
   Do all required files exist?
   usage:   CheckRequiredFiles() or CheckRequiredFiles("V")
   returns: 1 if all files found, 0 otherwise
*/
CheckRequiredFiles: PROCEDURE expose reqfile.
parse arg verbose
/* empty line, to make further messages more visible: */
if verbose = "V" then say 
res = 1
do i = 1 to reqfile.0
   if  stream(reqfile.i, "C", "QUERY EXISTS") = "" then do
     res = 0
     if verbose = "V" then say "missing file:" reqfile.i
   end
end
return res


/*
   read config file
   usage:   call readconfig filename
   returns: (nothing)
*/
readconfig: PROCEDURE expose config. cmax
parse arg infile
cmax=0
do while lines(infile) > 0
   cmax=cmax+1
   config.cmax=linein(infile)
end /* do */
call stream infile, "C", "CLOSE"
return


/*
   write config file
   usage:   call writeconfig filename
   returns: 1 if successful
            0 if writing the file failed
*/
writeconfig: PROCEDURE expose config. cmax
parse arg outfile
call SysFileDelete outfile
do i = 1 TO cmax
   if config.i <> "deleted" then do
      res = lineout(outfile, config.i)
   end
end /* do */
call stream outfile, "C", "CLOSE"
if res <> 0  then return 0
else return 1


/*
   search for a given environment variable
   usage:   checkvar(name)
   returns: setting
            "" if undefined or defined as empty
*/
checkvar: PROCEDURE expose config. cmax
parse upper arg name
i=0
name=strip(name)
trigger=" "||name||"="
do forever
   i=i+1
   if i>cmax then leave
   parse upper value config.i with junk (trigger) setting
   if (setting <> "") & (junk="SET") then leave
end /* do */
if i>cmax then return ""
else return setting


/*
   add environment variable, overwrites current setting
   usage:   call addvar name, value
   returns: (nothing)
*/
addvar: PROCEDURE expose config. cmax
parse arg name, value
name = strip(translate(name))
trigger=" "||name||"="
i=0
do forever
   i=i+1
   if i>cmax then leave
   parse upper value config.i with junk (trigger) setting
   if (setting <> "") & (junk = "SET") then leave
end /* do */
config.i = "SET " || name || "=" || value
if i>cmax then cmax=i
return



/* 
   delete environment variable
   usage:   delvar(name)
   returns: 1 if successful
            0 if variable not found
*/
delvar: PROCEDURE expose config. cmax
parse arg name
name=strip(translate(name))
trigger=" "||name||"="
i=0
do forever
   i=i+1
   if i>cmax then leave
   parse upper value config.i with junk (trigger) setting
   if (setting <> "") & (junk="SET") then leave
end /* do */
if i>cmax then return 0
else do
   config.i = "deleted"
   return 1
end /* do */


/* 
   edit a path
   usage:   pathedit(path, entry, op)
            op = "D" means "delete this entry"
            op = "A" (default) means "add entry"
   returns 1 if successful
           0 if path or entry to be deleted not found
           2 if entry to be added was already present
*/
pathedit: PROCEDURE expose config. cmax
parse upper arg path, directory, op
i=0
path=strip(path)
trigger = " "||path||"="
do forever
   i=i+1
   if i>cmax then leave
   parse upper value config.i with junk (trigger) setting
   if (setting <> "") & (junk="SET") then leave
end /* do */
if i>cmax then return 0
setting=strip(setting,"T")
if substr(directory,length(directory),1) <> ";" then directory = directory || ";"
if substr(setting,length(setting),1) <> ";" then setting = setting || ";"
if op="D" then do
   posi = pos(directory,setting)
   if posi<>0 then config.i= "SET " || path || "=" || delstr(setting, posi, length(directory))
   else return 0
end /* do */
else do
   if pos(directory,setting)<>0 then return 2
   else do
      setting=setting || directory
      config.i = "SET " || path || "=" || setting
   end /* do */
end /* do */
return 1


/* 
   edit LIBPATH
   usage:   libpathedit(entry, op)
            op = "D" means "delete this entry, if existing"
            op = "A" (default) means "add entry"
   returns: 1 if successful
            0 if LIBPATH or entry to be deleted not found
            2 if entry to be added was already present
*/
libpathedit: PROCEDURE expose config. cmax
parse upper arg directory, op
i=0
do forever
   i=i+1
   if i>cmax then leave
   parse upper value config.i with junk "LIBPATH" setting
   if (setting <> "") & (junk = "") then leave
end /* do */
if i>cmax then return 0
setting=strip(setting,"T")
if substr(directory,length(directory),1) <> ";" then directory = directory || ";"
if substr(setting,length(setting),1) <> ";" then setting = setting || ";"
if op="D" then do
   posi = pos(directory,setting)
   if posi<>0 then config.i= "LIBPATH" || delstr(setting, posi, length(directory))
   else return 0
end /* do */
else do
   if pos(directory,setting)<>0 then return 2
   else do
      setting=setting || directory
      config.i = "LIBPATH" || setting
   end /* do */
end /* do */
return 1


emxrevision: procedure
  call RxFuncAdd emx_revision, "emx", emx_revision
  signal on syntax name noemx
  tmp = emx_revision()
  signal off syntax
  call RxFuncDrop emx_revision
  return tmp
noemx: return 0


/*
  Procedures for deleting a directory tree
*/


DDT:
        parse arg user_dir
        /* Check to make sure the directory exists */
        rc=SysFileTree(user_dir,dir_list, 'D')
        IF dir_list.0 = 0  THEN
                DO
                     SAY user_dir 'not found.'
                     RETURN
                END
        
        DROP dir_list.
        
        /* Mark all the read-only files to be non read-only        */
        rc=SysFileTree(user_dir || '\*.*', dir_list, 'FSO', '****','----')
        
        DROP dir_list.
        
        /* Go through the list of files and delete each one        */
        rc=SysFileTree(user_dir || '\*.*', dir_list, 'FSO')
        DO x = 1 TO dir_list.0
        	rc = SysFileDelete(dir_list.x)
        	if rc <> 0 then SAY dir_list.x '........' DELRCText.RC
        END
        
        DROP dir_list.
        
        /* Go through all the subdirectories and remove them.        */
        /* We go backwards through the list in order to delete the   */
        /* lowest level sudirectories first and work our way back up */
        /* the tree.                                                 */
        rc=SysFileTree(user_dir || '\*.*', dir_list, 'DSO')
        DO x = dir_list.0 TO 1 BY -1
        	rc=SysRmDir(dir_list.x)
        	if RC <> 0 then SAY dir_list.x '........' RDRCText.RC
        END
        
        DROP dir_list.
        
        /* Delete the topmost directory */
        rc=SysRmDir(user_dir)
        SAY user_dir '........' RDRCText.RC
        
RETURN

LoadDELRCText:
	/* provides text strings for SysFileDel return codes */
	/* The return codes and strings are in the online Rexx manual */

	DELRCText.0 = 'File deleted successfully. '
	DELRCText.2 = 'Error.  File not found. '
	DELRCText.3 = 'Error.  Path not found. '
	DELRCText.5 = 'Error.  Access denied. '
	DELRCText.26 = 'Error.  Not DOS disk. '
	DELRCText.32 = 'Error.  Sharing violation. '
	DELRCText.36 = 'Error.  Sharing buffer exceeded. '
	DELRCText.87 = 'Error.  Invalid parameter. '
	DELRCText.206 = 'Error.  Filename exceeds range error. '
RETURN

LoadRDRCText:
	/* provides text strings for SysRmDir return codes */
	/* The return codes and strings are in the online Rexx manual */

	RDRCText.0 = 'Directory removal was successful. '
	RDRCText.2 = 'Error.  File not found. '
	RDRCText.3 = 'Error.  Path not found. '
	RDRCText.5 = 'Error.  Access denied. '
	RDRCText.16 = 'Error.  Current Directory. '
	RDRCText.26 = 'Error.  Not DOS disk. '
	RDRCText.87 = 'Error.  Invalid parameter. '
	RDRCText.108 = 'Error.  Drive locked. '
	RDRCText.206 = 'Error.  Filename exceeds range error. '
RETURN

/* finis */