C+ C NAME: C iSearch C PURPOSE: C Search for file based on file name specification C CALLING SEQUENCE: integer function iSearch(jFIRST,cSearch,cFound) C INPUTS: C jFirst integer =1 on 1st call (set up for subsequent searches) C =0 on subsequent calls C Add 10 to iFirst to suppress the error message C when no file is found C Add 100 if you want to test for parsing errors only C cSearch character*(*) File specification to search for C OUTPUTS: C cFound character*(*) File specification of located file C = ' ' if no file is found C iSearch integer*4 0 : file not found C 1 : file found C 2 : error parsing cSearch (probably typo) C CALLS: C SetFileSpec, Say, SYS$PARSE,SYS$SEARCH C INCLUDE: include '($fabdef)' include '($namdef)' include '($rmsdef)' C RESTRICTIONS: C > The length of cSearch is stored in a byte and should not be larger than C 127 C > When a file on a foreign host is tested, the parsing apparently does C not include a test for directory existence, e.g. C CASSX1::DUA2:[NODIR] C will return iSearch=0, EVEN IF THE DIRECTORY DOES NOT EXIST !!!!! C (for a local directory iSearch=2 for a non-existing directory). C To check whether a directory exists on a foreign host, one should C test for the existence of the directory file: in the above example C a test for CASSX1::DUA2:[000000]NODIR.DIR would return 0 or 1 for C non-existing or existing directory, respectively. C PROCEDURE: C > Negative JFIRST values are used by the MS-DOS version of iSearch to C distinguish between a search for a directory or a regular file. C Since this is not needed for the VAX, negative JFIRST values are treated C the same as the opposite (positive) value. C > Scans a directory for files based on a specified search string C (wild cards permitted) and returns successive matching file C specifications. When no match is found, the returned specification is blank. C If the input is to checked for parsing, a valid cFound is returned C even if it does not exist. C The RMS system services SYS$PARSE and SYS$SEARCH are called, which C requires setting FAB and NAM blocks C MODIFICATION HISTORY: C KIM TOLBERT 3/1/86 C OCT-1992, Paul Hick: added option to suppress error message C- integer jFirst character cSearch*(*) character cFound *(*) integer SYS$PARSE integer SYS$SEARCH record /FABDEF/ FAB record /NAMDEF/ NAM character cLook *100 character cEXFOUND*100 iFirst = abs(jFirst) ! Don't remove abs() call iFirst = mod(iFirst,100) iError = iFirst/10 iFirst = mod(iFirst,10) iError = 1-iError if (iFirst .eq. 1) then FAB.FAB$B_BID = FAB$C_BID ! BLOCK IDENTIFIER FOR FAB BLOCK FAB.FAB$B_BLN = FAB$C_BLN ! LENGTH OF FAB BLOCK NAM.NAM$B_BID = NAM$C_BID ! BLOCK IDENTIFIER FOR NAM BLOCK NAM.NAM$B_BLN = NAM$C_BLN ! LENGTH OF NAM BLOCK FAB.FAB$L_NAM = %loc(NAM) FAB.FAB$L_FOP = IBSET(FAB.FAB$L_FOP, FAB$V_NAM) FAB.FAB$L_FNA = %loc(cSearch)! ADDRESS OF FILE SPEC. TO BE PROCESSED FAB.FAB$B_FNS = min(127,len(cSearch)) ! LENGTH OF FILE SPEC. TO BE PROCESSED NAM.NAM$L_RSA = %loc(cLook) ! RESULTANT STRING ADDRESS IN NAM BLOCK NAM.NAM$B_RSS = len(cLook) ! RESULTANT STRING SIZE IN NAM BLOCK NAM.NAM$L_ESA = %loc(cEXFOUND)! EXPANDED STRING AREA ADDRESS NAM.NAM$B_ESS = len(cEXFOUND)! EXPANDED STRING LENGTH iStatus = SYS$PARSE(FAB) ! ANALYZE FILE SPEC. AND FILL IN NAM if (.not. iStatus) then if (iError) call Say ('iSearch','W','Error','parsing '//cSearch) iSearch = 2 cFound = ' ' return end if end if iStatus = SYS$SEARCH(FAB) ! SEARCH FOR NEXT FILE MEETING SPECS. if (iStatus) then ! File found : 65537 iSearch = 1 cFound = cLook(:NAM.NAM$B_RSL) ! TRANSFER ONLY THOSE CHARACTERS FILLED else if (iFirst .eq. 1) then ! File not found if (iError) then if (NAM.NAM$B_RSL .ne. 0) then call Say('iSearch','W','Error','searching for '//cLook(:NAM.NAM$B_RSL)) else call Say('iSearch','W','Error','searching for '//cSearch) end if end if iSearch = 0 cFound = cLook(:NAM.NAM$B_RSL) else iSearch = 0 cFound = ' ' end if I = iSetFileSpec(cFound) return end