/* WHICH, Version 3.00 */ /* Rexx "port" of UNIX' WHICH command */ /* that also looks for DLL's in LIBPATH */ /* Written by Rob van der Woude */ /* Initialize RexxUtil */ if RxFuncQuery( "SysLoadFuncs" ) <> 0 then do call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs" call SysLoadFuncs end /* Parse command line parameters */ parse upper arg params invalid.0 = 7 invalid.1 = "*" invalid.2 = "?" invalid.3 = "/" invalid.4 = "\" invalid.5 = "," invalid.6 = ";" invalid.7 = ":" do i = 1 to invalid.0 if pos( invalid.i, params ) > 0 then call Syntax end parse value params with dummy1'"'longfilename'"'dummy2 if longfilename <> "" then do if dummy1||dummy2 <> "" then call Syntax filename = longfilename longname = 1 end else do parse value params with filename dummy if filename <> "" then do if dummy <> "" then call Syntax longname = 0 end else do call Syntax end end /* Check if extension was given */ commandext.0 = 5 commandext.1 = ".BAT" commandext.2 = ".CMD" commandext.3 = ".COM" commandext.4 = ".EXE" commandext.5 = ".DLL" addext = 1 chk4ext = right( filename, 4 ) do i = 1 to commandext.0 if chk4ext = commandext.i then addext = 0 end /* Read PATH from environment */ path = translate( value( "PATH", , "OS2ENVIRONMENT" ) ) if chk4ext = ".DLL" then do parse value path with ":\OS2\SYSTEM" -1 bootdrive +2 configsys = bootdrive||"\CONFIG.SYS" call linein configsys, 1, 0 do until lines( configsys ) = 0 line = strip( translate( linein( configsys ) ) ) if left( line, 8 ) = "LIBPATH=" then do parse value line with "LIBPATH="path leave end end end path. = "" path.0 = 1 path.1 = strip( directory( ), "T", "\" )||"\" do i = 2 by 1 until path = "" parse value path with path.i";"path if right( path.i, 1 ) <> "\" then path.i = path.i||"\" path.0 = i end /* Check if file can be found in PATH */ do i = 1 to path.0 until found.0 = 1 if addext = 0 then do file = path.i||filename if longname = 1 then do file = translate( file, "?", " " ) end call SysFileTree file, "found.", "FO" if found.0 = 1 then do if longname = 0 then do call FileFound file end else do file = translate( translate( file, " ", "?" ) ) if file = translate( found.1 ) then do call FileFound file end end end end else do j = 1 to commandext.0 file = path.i||filename||commandext.j if longname = 1 then do file = translate( file, "?", " " ) end call SysFileTree file, "found.", "FO" if found.0 = 1 then do if longname = 0 then do call FileFound file end else do file = translate( translate( file, " ", "?" ) ) if file = translate( found.1 ) then do call FileFound file end end end end end say "Not found: "||filename EXIT 1 FileFound: if longname = 1 then do say 'Found: "'||arg( 1 )||'"' end else do say "Found: "||arg( 1 ) end EXIT 0 return Syntax: procedure say say "WHICH, Version 3.00" say "UNIX-like WHICH utility for OS/2 that" say "can search for DLL's in LIBPATH as well" say "Written by Rob van der Woude" say say "Usage: WHICH program_name" say say " or: WHICH dll_name.DLL" say say "You may specify program_name with or without" say "extension. program_name as well as dll_name.DLL" say "should be specified without a drive or path." say say "Spaces in long file names are allowed, wildcards" say "aren't." EXIT 9 return