From: Eric S. Raymond Date: Wed, 3 Sep 2003 15:30:50 +0000 (+0000) Subject: Correct off-by-one error. X-Git-Tag: 1.0~37 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=4600db19390ffb1361efe8444b868c2721b54f10;p=comparator.git Correct off-by-one error. --- diff --git a/filterator b/filterator index ddb2f7f..2ec0ac4 100755 --- a/filterator +++ b/filterator @@ -5,7 +5,7 @@ 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', @@ -63,25 +63,38 @@ if __name__ == '__main__': 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