3 # This script will find all files that include certain regular expression.
4 # If the files are not in the list provided, the script will return error.
6 set ProgName [ lindex [ split $argv0 "/" ] end ]
9 puts "Usage: $ProgName <expr1> <expr2> \[ <file> ... \]"
10 puts "\texpr1 - file list expression (vtk*.h)"
11 puts "\texpr2 - search string expression (vtkSet.*Macro)"
12 puts "\tfile - files that should be ignore"
23 # Parse command line arguments
24 set FileExpression [ lindex $argv 0 ]
25 set SearchMessage [ lindex $argv 1 ]
26 set IgnoreFileListIn [ lrange $argv 2 end ]
28 foreach { file } $IgnoreFileListIn {
29 set IgnoreFileList "$IgnoreFileList [ glob $file ]"
31 #puts "Searching for $SearchMessage in $FileExpression"
32 #puts "Ignore list: $IgnoreFileList"
34 # Find regular expression in the string
35 proc FindString { InFile SearchString } {
36 if [ catch { open $InFile r } inchan ] {
37 puts stderr "Cannot open $InFile"
42 while { ! [eof $inchan] } {
44 if [ regexp $SearchString $line matches ] {
45 puts "$InFile: Found $SearchString on line $lcount"
49 set lcount [ expr $lcount + 1 ]
55 # Get all files that match expression
57 if [ catch { [ set files [ glob $FileExpression ] ] } result ] {
58 regsub {\\\*} $FileExpression "*" FileExpression
59 if [ catch { [ set files [ glob $FileExpression ] ] } nresult ] {
60 #puts "Cannot expand the expression: \"$FileExpression\""
61 #puts "Error: $nresult"
66 if { [ llength $files ] < 1 } {
67 puts "Cannot find any files that match your file expression"
72 foreach { a } $files {
73 regsub -all {\\} $a {/} b
74 if { [ lsearch $IgnoreFileList $b ] >= 0 } {
77 set count [ expr $count + [ FindString $a $SearchMessage ] ]
83 puts "Found \"$SearchMessage\" $count times"