import os, sys, re, getopt
# Template for parsing the output from shredfilter. Grabs from second tree.
-shredline = re.compile("-> ([^:]*):([0-9]+)-([0-9]+)")
+shredline = re.compile("([^:]*):([0-9]+):([0-9]+)")
# Tokens to be removed when checking whether a shred is significant
C_junk = [r'\bbreak\b', r'\bcase\b',r'\bcontinue\b', r'\bdefault\b',
elif opt == '-n':
nofilter = True
+ # skip the SCF header
+ while True:
+ line = sys.stdin.readline()
+ if not line or line == '%%\n':
+ break
+
count = 0
+ locations = []
while True:
line = sys.stdin.readline()
if not line:
break
m = shredline.search(line)
- file = m.group(1)
- start = int(m.group(2))
- end = int(m.group(3))
- rfp = open(file)
- for i in range(start):
- rfp.readline()
- text = ""
- for i in range(start, end):
- text += rfp.readline()
- rfp.close()
- if nofilter or nontrivial(text):
- count += 1
- print "%%%%#%%%% %s:%s-%s:" % (file, start, end)
- sys.stdout.write(text)
- #print `nontrivial(text)`
+ if m:
+ locations.append((m.group(1), int(m.group(2)), int(m.group(3))))
+ if line == '%%\n':
+ for (file, start, end) in locations:
+ try:
+ rfp = open(file)
+ for i in range(start-1):
+ rfp.readline()
+ text = ""
+ for i in range(start, end):
+ text += rfp.readline()
+ rfp.close()
+ if nofilter or nontrivial(text):
+ count += 1
+ print "%%%%#%%%% %s:%s-%s:" % (file, start, end)
+ sys.stdout.write(text)
+ #print `nontrivial(text)`
+ locations = []
+ break
+ except IOError:
+ pass
print "%d overlaps." % count