summaryrefslogtreecommitdiff
path: root/obsolete/systems/os2/emtex-contrib/emtexTDS/tdskill.cmd
blob: 30026d50dcdb7a1b272ec7b7f6b17a9ed8b031e2 (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
/* REXX */

/*
  tdskill.cmd, version v0.53
  
  This program uninstalls emtex/TDS
  
  Written by Walter Schmidt
  
  The code for removing a directory tree was written 
  by Mark Polly - Progressive Insurance, 1992
  
*/



/*
  Initialisation:
  ---------------
  Loading libraries, checking the current directory etc.
*/  
VERSION = 0.5

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

wrkdrive = substr(directory(),1)
say 
say "Uninstallation Tool for emTeX/TDS, v0.53 <2000-02-07>"
say

say "From which drive do you want emTeX/TDS to be removed?"
answer = linein()
if answer = "" then EXIT
texdrive = translate(substr(answer,1,1))

say
say "emTeX/TDS will be removed from drive " || texdrive || ":"
say "Continue? (y/n)"
answer = translate(substr(linein(),1,1))
if answer <> "Y" then exit

if wrkdrive = texdrive then call directory("\")
user_dir=texdrive||":\texmf"

/*
  Step 1
  ------
  Removing the texmf tree
*/

/* 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   */

/* 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.'
             /* proceed with updating config.sys */
             SIGNAL cfgupdate
        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 texmf directory */
rc=SysRmDir(user_dir)
SAY user_dir '........' RDRCText.RC


/*
   Step 2
   ------
   cleaning up config.sys
*/   
cfgupdate:
say
say "Do you want config.sys to be cleaned up? (y/n)"
answer = translate(substr(linein(),1,1))
if answer <> "Y" then EXIT

bootdrv= querybootdrv()
configfile = bootdrv||"\config.sys"
if stream(configfile,"C","QUERY EXISTS") = "" then do
  say "The file config.sys could not be located."
  say "Please, perform any changes manually."
  EXIT
end

say
say "Cleaning up config.sys ..."

call readconfig configfile

call delvar "EMTEXDIR"
call delvar "TEXMACROS"
call delvar "TEXTFM"
call delvar "BFONTS"
call delvar "VFONTS"
call delvar "TYPE1FONTS"
call delvar "TEXCONFIG"
call delvar "EMTEXSWCHAR"
call delvar "MFOPT"
call delvar "MFJOBOPT"
call delvar "MFINPUT"
call delvar "INDEXSTYLE"
call delvar "BSTINPUT"
call delvar "BIBINPUT", texdrive||":\TEXMF\BIBTEX\BIB"

call pathedit "PATH", texdrive||":\texmf\emtex\bin;", "D"
call pathedit "HELP", texdrive||":\texmf\emtex\help;", "D"
call libpathedit texdrive||":\texmf\emtex\dll;", "D"

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

signal on error name updfailed
savedfile = filespec("N", tempfile)
"@ren" configfile savedfile
say
say "Your current" configfile "has been renamed to" savedfile "."
res = writeconfig(configfile)
if res=0 then do
   call beep 440,500
   say "Writing a new file" configfile "failed".
   say "Rename" savedfile "to config.sys and perform 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
EXIT

updfailed:
say
say "Updating config.sys failed."
say "Your config.sys has *** not *** been changed."
say "Please, perform any changes manually."
EXIT


/*
   Local subroutines
*/
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
 


/*
   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


/*
   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

/* finis */