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