[llvm-commits] CVS: llvm/test/Scripts/prcontext.py

John Criswell criswell at cs.uiuc.edu
Mon Aug 2 15:29:00 PDT 2004



Changes in directory llvm/test/Scripts:

prcontext.py added (r1.1)

---
Log message:

New python script that print a specified number of lines surrounding a
located pattern.
In other words, grep -C for Solaris.


---
Diffs of the changes:  (+29 -0)

Index: llvm/test/Scripts/prcontext.py
diff -c /dev/null llvm/test/Scripts/prcontext.py:1.1
*** /dev/null	Mon Aug  2 17:29:00 2004
--- llvm/test/Scripts/prcontext.py	Mon Aug  2 17:28:50 2004
***************
*** 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
+ 





More information about the llvm-commits mailing list