From b947fb3e95f8ff09fdae10949e7c33d316692f77 Mon Sep 17 00:00:00 2001 From: Tanya Lattner Date: Sat, 13 Nov 2004 21:03:22 +0000 Subject: [PATCH] Rewrote prcontext.py in tcl. llvm-svn: 17708 --- llvm/test/Scripts/prcontext.tcl | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 llvm/test/Scripts/prcontext.tcl diff --git a/llvm/test/Scripts/prcontext.tcl b/llvm/test/Scripts/prcontext.tcl new file mode 100755 index 000000000000..5ab0854b0b3f --- /dev/null +++ b/llvm/test/Scripts/prcontext.tcl @@ -0,0 +1,36 @@ +#!/usr/bin/tclsh +# +# Usage: +# prcontext <# 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