(view source code of which.rex as plain text)
/* WHICH, Version 1.00 for Windows *//* Rexx "port" of UNIX' WHICH command *//* that also looks for DLL's *//* Written by Rob van der Woude *//* Initialize RexxUtil */If RxFuncQuery( "SysLoadFuncs" ) <> 0 Then Do
Call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
Call SysLoadFuncsEnd/* Display empty line */Say/* 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
EndParse Value params With dummy1'"'longfilename'"'dummy2
If longfilename <> "" Then Do
If dummy1||dummy2 <> "" Then Call Syntax
filename = longfilenamelongname = 1
EndElse Do
Parse Value params With filename dummy
If filename <> "" Then Do
If dummy <> "" Then Call Syntax
longname = 0
EndElse Do
Call Syntax
EndEnd/* Check if extension was given */pathext = Translate( Value( "PATHEXT", , "ENVIRONMENT" ) )
Do i = 1 By 1 Until pathext = ""
Parse Value pathext With commandext.i";"pathext
If commandext.i <> "" Then commandext.0 = i
Endi = commandext.0 + 1
commandext.i = ".DLL"
i = commandext.0 + 2
commandext.i = ".SYS"
i = commandext.0 + 3
commandext.i = ".OCX"
commandext.0 = iaddext = 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", , "ENVIRONMENT" ) )
path. = ""
path.0 = 1
/* Add current directory as first PATH entry */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 = iEnd/* 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, "?", " " )
EndCall SysFileTree file, "found.", "FO"
If found.0 = 1 Then Do
If longname = 0 Then Do
Call FileFound file EndElse Do
file = Translate( Translate( file, " ", "?" ) )
If file = Translate( found.1 ) Then Do
Call FileFound file End End End EndElse Do j = 1 To commandext.0 - 3
file = path.i||filename||commandext.j
If longname = 1 Then Do
file = Translate( file, "?", " " )
EndCall SysFileTree file, "found.", "FO"
If found.0 = 1 Then Do
If longname = 0 Then Do
Call FileFound file EndElse Do
file = Translate( Translate( file, " ", "?" ) )
If file = Translate( found.1 ) Then Do
Call FileFound file End End End EndEndSay "Not found: "||filename
Exit 1
FileFound:If longname = 1 Then Do
Say 'Found: "'||arg( 1 )||'"'
EndElse Do
Say "Found: "||arg( 1 )
EndExit 0
ReturnSyntax: Procedure
SaySay "Which.rex, Version 1.00 for Regina Rexx for Windows"
Say "UNIX-like WHICH utility for Windows that can search for"
Say ".DLL, .OCX and .SYS files as well"
SaySay "Usage: WHICH program_name"
SaySay 'Where: "program_name" is any program name with or without extension,'
Say " but always without drive and/or path."
SaySay "Returns: The first file with a valid or specified extension found in the PATH."
SaySay "If program_name is specified without extension, all extensions from the PATHEXT"
Say "environment variable will be searched for."
Say "Files with .DLL, .OCX or .SYS extension will be ignored unless the extension is"
Say "specified."
Say "Spaces in long file names are allowed, wildcards aren't."
SaySay "Written by Rob van der Woude"
Say "http://www.robvanderwoude.com"
Exit 9
Returnpage last modified: 2025-10-11; loaded in 0.0068 seconds