aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanya Lattner <tonic@nondot.org>2004-11-13 21:03:22 +0000
committerTanya Lattner <tonic@nondot.org>2004-11-13 21:03:22 +0000
commit4913cdcc37497a033ab08fe0fd5489d3463fc0e3 (patch)
tree4495eaa620e2d462aedd9c1a3a92ca54b620036f
parentce7cafa9603b8d1b9c1af74f7354f7f51974ec70 (diff)
Rewrote prcontext.py in tcl.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17708 91177308-0d34-0410-b5e6-96231b3b80d8
-rwxr-xr-xtest/Scripts/prcontext.tcl36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/Scripts/prcontext.tcl b/test/Scripts/prcontext.tcl
new file mode 100755
index 0000000000..5ab0854b0b
--- /dev/null
+++ b/test/Scripts/prcontext.tcl
@@ -0,0 +1,36 @@
+#!/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]
+} \ No newline at end of file