OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / lib / vtk / testing / FindString.tcl
1 #!/usr/bin/tclsh
2
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.
5
6 set ProgName [ lindex [ split $argv0 "/" ] end ]
7
8 if { $argc < 2 } {
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"
13
14     puts ""
15     puts "You provided:"
16     foreach { a } $argv {
17         puts "$a"
18     }
19
20     exit 1
21 }
22
23 # Parse command line arguments
24 set FileExpression [ lindex $argv 0 ]
25 set SearchMessage  [ lindex $argv 1 ]
26 set IgnoreFileListIn [ lrange $argv 2 end ]
27 set IgnoreFileList {}
28 foreach { file } $IgnoreFileListIn {
29    set IgnoreFileList "$IgnoreFileList [ glob $file ]"
30 }
31 #puts "Searching for $SearchMessage in $FileExpression"
32 #puts "Ignore list: $IgnoreFileList"
33
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"
38         return 0
39     }
40     set res 0
41     set lcount 1
42     while { ! [eof $inchan] } {
43         gets $inchan line
44         if [ regexp $SearchString $line matches ] {
45             puts "$InFile: Found $SearchString on line $lcount"
46             puts "$line"
47             set res 1
48         }
49         set lcount [ expr $lcount + 1 ]
50     }
51     close $inchan
52     return $res
53 }
54
55 # Get all files that match expression
56 set files ""
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"
62         #exit 1
63     }
64 }
65
66 if { [ llength $files ] < 1 } {
67     puts "Cannot find any files that match your file expression"
68     exit 1
69 }
70
71 set count 0
72 foreach { a } $files {
73    regsub -all {\\} $a {/} b 
74    if { [ lsearch $IgnoreFileList $b ] >= 0 } {
75         puts "Ignoring: $b"
76     } else {
77         set count [ expr $count + [ FindString $a $SearchMessage ] ]
78     }
79 }
80
81 if { $count > 0 } {
82     puts "" 
83     puts "Found \"$SearchMessage\" $count times"
84     exit 1
85 }
86
87 exit 0