/[dejagnu]/dejagnu/lib/utils.exp
ViewVC logotype

Diff of /dejagnu/lib/utils.exp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by rsavoye, Mon Mar 17 02:25:07 2003 UTC revision 1.7 by rsavoye, Mon Jul 28 14:45:35 2003 UTC
# Line 25  Line 25 
25  #  #
26    
27  #  #
28  # Gets the directories in a directory  # Gets the directories in a directory, or in a directory tree.
29  #     args: the first is the dir to look in, the next  #     args: the first is the dir to look in, the next
30  #         is the pattern to match. It  #         is the pattern to match. It
31  #         defaults to *. Patterns are csh style  #         defaults to *. Patterns are csh style
32  #         globbing rules  #         globbing rules
33  #     returns: a list of dirs or NULL  #     options: -all  search the tree recursively
34    #     returns: a list of dirs or NULL; the root directory is not returned.
35  #  #
36  proc getdirs { args } {  proc getdirs { args } {
37      if { [lindex $args 0] == "-all" } {      if { [lindex $args 0] == "-all" } {
# Line 86  proc getdirs { args } { Line 87  proc getdirs { args } {
87  }  }
88    
89  #  #
90  # Finds all the files recursively  # Finds paths of all non-directory files, recursively, whose names match
91  #     rootdir - this is the directory to start the search  # a pattern.  Certain directory name are not searched (see proc getdirs).
92  #         from. This is and all subdirectories are search for  #     rootdir - search in this directory and its subdirectories, recursively.
93  #         filenames. Directory names are not included in the  #     pattern - specified with Tcl string match "globbing" rules.
94  #         list, but the filenames have path information.  #     returns: a possibly empty list of pathnames.
 #     pattern - this is the pattern to match. Patterns are csh style  
 #         globbing rules.  
 #     returns: a list or a NULL.  
95  #  #
96  proc find { rootdir pattern } {  proc find { rootdir pattern } {
97      # first find all the directories      set files [list]
98      set dirs "$rootdir "      if { [string length $rootdir] == 0 || [string length $pattern] == 0 } {
99      while 1 {          return $files
         set tmp $rootdir  
         set rootdir ""  
         if [string match "" $tmp] {  
             break  
         }  
         foreach i $tmp {  
             set j [getdirs -all $i]  
             if ![string match "" $j] {  
                 append dirs "$j "  
                 set rootdir $j  
                 unset j  
             } else {  
                 set rootdir ""  
             }  
         }  
         set tmp ""  
100      }      }
101    
102        # find all the directories
103        set dirs [concat [getdirs -all $rootdir] $rootdir]
104            
105      # find all the files that match the pattern      # find all the files in the directories that match the pattern
106      foreach i $dirs {      foreach i $dirs {
107          verbose "Looking in $i" 3          verbose "Looking in $i" 3
108          set tmp [glob -nocomplain $i/$pattern]          foreach match [glob -nocomplain $i/$pattern] {
109          if { [llength $tmp] != 0 } {              if ![file isdirectory $match] {
110              foreach j $tmp {                  lappend files $match
111                  if ![file isdirectory $j] {                  verbose "Adding $match to file list" 3
                     lappend files $j  
                     verbose "Adding $j to file list" 3  
                 }  
112              }              }
113          }          }
114      }      }
115        
     if ![info exists files] {  
         lappend files ""  
     }  
116      return $files      return $files
117  }  }
118    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26