4 # prcontext <pattern> <# lines of context>
5 # (for platforms that don't have grep -C)
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]
22 if { [regexp $pattern $line match matchline
] } {
23 if { [ expr [expr $index - $num] < 0 ] } {
26 set bottom
[expr $index - $num]
28 set endLineNum
[ expr [expr $index + $num] + 1]
29 while {$bottom < $endLineNum} {
30 set output
[lindex $lines $bottom]
32 set bottom
[expr $bottom + 1]
35 set index
[expr $index + 1]