A few folks have asked for the 5.0 version of my FIND script that uses HPPATH
to locate a file, so here it is. You can see the code eliminated by the 5.5
word() evaluator function. (note to James, please use this version since it
fixes a bug in the version I gave you earlier)
PARM file, cmd=''
ANYPARM args=![""]
# This command file locates a file that based on HPPATH.
# If 'cmd' is not empty then it will be executed and passed 'file' and 'args'
# as parameters.
if len(hppath) = 0 then
echo HPPATH is empty!
return
endif
setvar _find_file "!file"
setvar _find_i 0
setvar _find_done false
while not (_find_done) and _find_i < len(hppath) do
# setvar _find_qualifier word(hppath,", ;",,_find_i,_find_i+1)
# (begin 5.0 version)
setvar _find_path_rht rht(hppath,len(hppath)-_find_i)
# account for any leading spaces
while _find_i < len(hppath) and lft(_find_path_rht,1) = ' ' do
setvar _find_i _find_i+1
setvar _find_path_rht _find_path_rht - ' '
endwhile
setvar _find_j 0
while setvar(_find_j,_find_j+1) <= len(_find_path_rht) and &
not (str(_find_path_rht,_find_j,1)=',' or &
str(_find_path_rht,_find_j,1)=';' or &
str(_find_path_rht,_find_j,1)=' ') do
endwhile
# _find_j indexes delim in _find_path_rht or beyond len(_find_path_rht)
setvar _find_qualifier rtrim(lft(_find_path_rht,_find_j-1))
setvar _find_i _find_i+_find_j
# _find_i indexes next delim in hppath
# (end 5.0 version)
if _find_qualifier <> '' then
if lft(_find_qualifier,1) = '.' or lft(_find_qualifier,1) = '/' then
# posix path element -- append filename
setvar _find_fullname _find_qualifier+"/"+_find_file
else
# mpe path element -- prepend filename
setvar _find_fullname _find_file+"."+_find_qualifier
endif
# see if file exists
if finfo(_find_fullname,'exists') then
# found file
setvar _find_done true
echo !_find_fullname
# see if 'cmd' should be executed
if '!cmd' <> '' then
echo
echo Invoking !cmd...
continue
!cmd !_find_fullname !args
endif
endif
endif
endwhile
# see if we found the file
if not _find_done then
echo Could not locate !_find_file using your HPPATH.
echo HPPATH = !hppath
endif
deletevar _find_@
--
|