C+ C NAME: C iSearchTree C PURPOSE: C Displays a rudimentary directory tree from the top directory downwards C CALLING SEQUENCE: subroutine iSearchTree(cSearch, nFound, cFound) C INPUTS: C cTopDir character top directory and file name wild card C nFound integer max # files returned C OUTPUTS: C nFound integer # files found C cFound character(*)*(*) fully-qualified file names C INCLUDE: include 'dirspec.h' include 'filparts.h' !include 'openfile.h' C CALLS: C iCheckDirectory, iGetDirectoryFragment C Say, iGetFileSpec, Str2Str, iSearch, iSetFileSpec, LocFirstLen C MODIFICATION HISTORY: C MAR-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Extracted from program libsd.f (subroutine SD_TREE) C- character cSearch *(*) integer nFound character cFound(*)*(*) character cSay*11 /'iSearchTree'/ character cTree *4096 character cSubStr *4096 character cTopDisk * (FIL__LENGTH) character cTopDir * (FIL__LENGTH) character cFullDir * (FIL__LENGTH) character cUpDir * (FIL__LENGTH) character cNowDir * (FIL__LENGTH) character cSubDir * (FIL__LENGTH) character cFoundOne* (FIL__LENGTH) character cWild * (FIL__LENGTH) logical bTrue /.TRUE./ integer Str2Str nLen = len(cTree) I = iSetFileSpec(cSearch) I = iGetFileSpec(0,FIL__DIRECTORY,cTopDir) I = iGetFileSpec(FIL__NAME,FIL__TYPE,cWild) nFoundMax = nFound nFound = 0 if (iCheckDirectory(cTopDir) .eq. 0) return cTree = ' ' iTopDisk = iGetFileSpec(0,FIL__DEVICE,cTopDisk) I = iGetDirectoryFragment(2,cUpDir ) ! Parent fragment I = iGetDirectoryFragment(3,cNowDir) ! Last fragment iLen = 0 iLen = iLen+Str2Str('(',cTree(iLen+1:)) iLen = iLen+Str2Str(cNowDir,cTree(iLen+1:)) iLen = iLen+Str2Str(')',cTree(iLen+1:)) iDepth = iLen ! Skip top directory do while (bTrue) ! TR_DIVE: !------- ! Construct full directory name with wildcard extension to search for subdirectories I = 0 I = I+Str2Str(cTopDisk, cFullDir(I+1:)) I = I+Str2Str(cLead , cFullDir(I+1:)) if (cUpDir .ne. cNoWhere .and. (.not. bNoRoot .or. cUpDir .ne. cRoot) ) then I = I+Str2Str(cUpDir ,cFullDir(I+1:)) I = I+Str2Str(cDivide,cFullDir(I+1:)) end if I = I+Str2Str(cNowDir, cFullDir(I+1:)) I = I+Str2Str(cTrail , cFullDir(I+1:)) !------- ! Search for files in directory cFullDir cFullDir = cFullDir(:I)//cWild ! Don't change value of I iStat = 1 do while (iSearch(iStat,cFullDir,cFoundOne) .eq. 1) if (nFound .eq. nFoundMax) then begin call Say(cSay,'W','incomplete','not all matching files returned') return end if nFound = nFound+1 cFound(nFound) = cFoundOne iStat = 0 end do !------- ! Search for subdirectories in cFullDir I = I+Str2Str('*'//cDirExt,cFullDir(I+1:)) I = Str2Str('(',cSubStr) iStat = -11 do while (iSearch(iStat,cFullDir,cSubDir) .eq. 1) iStat = 10 !------- ! Check whether directory needs to be excluded (Unix only) J = iSetFileSpec(cSubDir) !------- ! In DOS, cSubDir = ' ' for the default ('.') and parent ('..') directory. J = iGetFileSpec(FIL__NAME,FIL__NAME,cSubDir) if (cOpSys .ne. OS__VMS) then ! If file type = . only then clear the dot if (iGetFileSpec(FIL__TYPE,FIL__TYPE,cSubDir(J+1:)) .eq. 1) cSubDir(J+1:) = ' ' end if !------- ! On an optical disk (VAX) the root contains a directory ! 000000.DIR. To avoid an infinite loop it is necessary to check ! for this. Note that in DOS, cRoot=' ', i.e. directories with ! file name cSubDir = ' ' are intercepted too (not really necessary). if (cSubDir .ne. cRoot) then if (I .ne. 1) I = I+Str2Str(',',cSubStr(I+1:)) I = I+Str2Str(cSubDir,cSubStr(I+1:)) end if end do I = I+Str2Str(')',cSubStr(I+1:)) if (I .gt. 2) then ! Subdirs found if (iLen+I .gt. nLen) call Say(cSay,'E','cTree','string not long enough') cTree(iDepth+I:iLen+I ) = cTree(iDepth:iLen) !call ShiftStr(iDepth,iLen,I,cTree)! Needed in MS-Fortran cTree(iDepth:iDepth+I-1) = cSubStr(:I) iLen = iLen+I end if iLeft = iLen-iDepth+1 if (cTree(iDepth:iDepth) .eq. ')') then 29 continue ! TR_CLIMB: Up one directory if (iLeft .le. 2) return ! TR_SCREEN: LEFT="))" or LEFT=")": Finished !! I = 0 I = I+Str2Str(cLead ,cSubDir(I+1:)) I = I+Str2Str(cUpDir,cSubDir(I+1:)) I = I+Str2Str(cTrail,cSubDir(I+1:)) I = iSetFileSpec(cSubDir) I = iGetDirectoryFragment(2,cUpDir ) I = iGetDirectoryFragment(3,cNowDir) if (cTree(iDepth+1:iDepth+1) .eq. ')') then ! More than one ")" on a row iLeft = iLeft -1 ! Skip first of a sequence of ")" iDepth = iDepth+1 go to 29 end if iLeft = iLeft-2 ! Skip ")," iDepth = iDepth+2 else if (cTree(iDepth:iDepth) .eq. '(') then I = 0 I = I+Str2Str(cLead ,cSubDir(I+1:)) if (cUpDir .ne. cNoWhere) then I = I+Str2Str(cUpDir ,cSubDir(I+1:)) I = I+Str2Str(cDivide,cSubDir(I+1:)) end if I = I+Str2Str(cNowDir,cSubDir(I+1:)) I = I+Str2Str(cTrail ,cSubDir(I+1:)) I = iSetFileSpec(cSubDir) I = iGetDirectoryFragment(0,cUpDir) end if iLeft = iLeft-1 ! Skip "(" iDepth = iDepth+1 end if I = min(LocFirstLen(',',cTree(iDepth:iLen)),LocFirstLen(')',cTree(iDepth:iLen))) cNowDir = cTree(iDepth:iDepth+I-2) ! Next subdirectory to be searched iDepth = iDepth+I-1 ! Skip subdirectory end do return end