New python script that print a specified number of lines surrounding a
[oota-llvm.git] / test / Scripts / prcontext.py
1 #
2 # Usage:
3 # prcontext <pattern> <# lines of context>
4 #
5
6 import sys
7
8 #
9 # Get the arguments
10 #
11 pattern=sys.argv[1]
12 num=int(sys.argv[2])
13
14 #
15 # Get all of the lines in the file.
16 #
17 lines=sys.stdin.readlines()
18
19 index=0
20 for line in lines:
21   if ((line.find(pattern)) != -1):
22     if (index-num < 0):
23       bottom=0
24     else:
25       bottom=index-num
26     for output in lines[bottom:index+num+1]:
27       print output[:-1]
28   index=index+1
29