summaryrefslogtreecommitdiffstats
path: root/llvm/test/Scripts
diff options
context:
space:
mode:
authorJohn Criswell <criswell@uiuc.edu>2004-08-02 22:28:50 +0000
committerJohn Criswell <criswell@uiuc.edu>2004-08-02 22:28:50 +0000
commitbb4494c93a3593d555ddd511e40d938f4f9abe9a (patch)
treee9e3758488a5dc0432e22b09fbb67f4cf5138d59 /llvm/test/Scripts
parent9245f97f978c17bfa9854c5abaf6e5c729f6ef68 (diff)
downloadbcm5719-llvm-bb4494c93a3593d555ddd511e40d938f4f9abe9a.tar.gz
bcm5719-llvm-bb4494c93a3593d555ddd511e40d938f4f9abe9a.zip
New python script that print a specified number of lines surrounding a
located pattern. In other words, grep -C for Solaris. llvm-svn: 15425
Diffstat (limited to 'llvm/test/Scripts')
-rwxr-xr-xllvm/test/Scripts/prcontext.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/test/Scripts/prcontext.py b/llvm/test/Scripts/prcontext.py
new file mode 100755
index 00000000000..b91f618c57b
--- /dev/null
+++ b/llvm/test/Scripts/prcontext.py
@@ -0,0 +1,29 @@
+#
+# Usage:
+# prcontext <pattern> <# lines of context>
+#
+
+import sys
+
+#
+# Get the arguments
+#
+pattern=sys.argv[1]
+num=int(sys.argv[2])
+
+#
+# Get all of the lines in the file.
+#
+lines=sys.stdin.readlines()
+
+index=0
+for line in lines:
+ if ((line.find(pattern)) != -1):
+ if (index-num < 0):
+ bottom=0
+ else:
+ bottom=index-num
+ for output in lines[bottom:index+num+1]:
+ print output[:-1]
+ index=index+1
+
OpenPOWER on IntegriCloud