Indentation change.
[llvm/avr.git] / test / Scripts / prcontext.tcl
blob5ab0854b0b3f3216c6b6c266a886405888c48f3c
1 #!/usr/bin/tclsh
3 # Usage:
4 # prcontext <pattern> <# lines of context>
5 # (for platforms that don't have grep -C)
9 # Get the arguments
11 set pattern [lindex $argv 0]
12 set num [lindex $argv 1]
16 # Get all of the lines in the file.
18 set lines [split [read stdin] \n]
20 set index 0
21 foreach line $lines {
22 if { [regexp $pattern $line match matchline] } {
23 if { [ expr [expr $index - $num] < 0 ] } {
24 set bottom 0
25 } else {
26 set bottom [expr $index - $num]
28 set endLineNum [ expr [expr $index + $num] + 1]
29 while {$bottom < $endLineNum} {
30 set output [lindex $lines $bottom]
31 puts $output
32 set bottom [expr $bottom + 1]
35 set index [expr $index + 1]