]> thyrsus.com Git - comparator.git/commitdiff
Correct off-by-one error.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 3 Sep 2003 15:30:50 +0000 (15:30 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 3 Sep 2003 15:30:50 +0000 (15:30 +0000)
filterator

index ddb2f7f6e26776d96ba6922b53018850d3522591..2ec0ac479e73810cb5a95cfa583ddf64d618adb5 100755 (executable)
@@ -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