mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 20:29:48 +00:00
4913cdcc37
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17708 91177308-0d34-0410-b5e6-96231b3b80d8
36 lines
763 B
Tcl
Executable File
36 lines
763 B
Tcl
Executable File
#!/usr/bin/tclsh
|
|
#
|
|
# Usage:
|
|
# prcontext <pattern> <# lines of context>
|
|
# (for platforms that don't have grep -C)
|
|
|
|
|
|
#
|
|
# Get the arguments
|
|
#
|
|
set pattern [lindex $argv 0]
|
|
set num [lindex $argv 1]
|
|
|
|
|
|
#
|
|
# Get all of the lines in the file.
|
|
#
|
|
set lines [split [read stdin] \n]
|
|
|
|
set index 0
|
|
foreach line $lines {
|
|
if { [regexp $pattern $line match matchline] } {
|
|
if { [ expr [expr $index - $num] < 0 ] } {
|
|
set bottom 0
|
|
} else {
|
|
set bottom [expr $index - $num]
|
|
}
|
|
set endLineNum [ expr [expr $index + $num] + 1]
|
|
while {$bottom < $endLineNum} {
|
|
set output [lindex $lines $bottom]
|
|
puts $output
|
|
set bottom [expr $bottom + 1]
|
|
}
|
|
}
|
|
set index [expr $index + 1]
|
|
} |