def dumpToEndOfFile(self, tag, f, s, line, printTrailing): trailingLines = 0 while 1: if not s: s = g.readlineForceUnixNewline(f) if len(s) == 0: break trailingLines += 1 if self.printTrailingMismatches and printTrailing: z = tag + str(line) tag2 = z.rjust(6) + "+:" self.dump(tag2, s) s = None self.show(tag + str(trailingLines) + " trailing lines") return trailingLines
def compare_open_files(self, f1, f2, name1, name2): # self.show("compare_open_files") lines1 = 0; lines2 = 0; mismatches = 0; printTrailing = True sentinelComment1 = sentinelComment2 = None if self.openOutputFile(): self.show("1: " + name1) self.show("2: " + name2) self.show("") s1 = s2 = None #@+<< handle opening lines >> #@+node:ekr.20031218072017.3639: *4* << handle opening lines >> if self.ignoreSentinelLines: s1 = g.readlineForceUnixNewline(f1); lines1 += 1 s2 = g.readlineForceUnixNewline(f2); lines2 += 1 # Note: isLeoHeader may return None. sentinelComment1 = self.isLeoHeader(s1) sentinelComment2 = self.isLeoHeader(s2) if not sentinelComment1: self.show("no @+leo line for " + name1) if not sentinelComment2: self.show("no @+leo line for " + name2) if self.ignoreFirstLine1: if s1 is None: g.readlineForceUnixNewline(f1); lines1 += 1 s1 = None if self.ignoreFirstLine2: if s2 is None: g.readlineForceUnixNewline(f2); lines2 += 1 s2 = None #@-<< handle opening lines >> while 1: if s1 is None: s1 = g.readlineForceUnixNewline(f1); lines1 += 1 if s2 is None: s2 = g.readlineForceUnixNewline(f2); lines2 += 1 #@+<< ignore blank lines and/or sentinels >> #@+node:ekr.20031218072017.3640: *4* << ignore blank lines and/or sentinels >> # Completely empty strings denotes end-of-file. if s1: if self.ignoreBlankLines and s1.isspace(): s1 = None; continue if self.ignoreSentinelLines and sentinelComment1 and self.isSentinel(s1, sentinelComment1): s1 = None; continue if s2: if self.ignoreBlankLines and s2.isspace(): s2 = None; continue if self.ignoreSentinelLines and sentinelComment2 and self.isSentinel(s2, sentinelComment2): s2 = None; continue #@-<< ignore blank lines and/or sentinels >> n1 = len(s1); n2 = len(s2) if n1 == 0 and n2 != 0: self.show("1.eof***:") if n2 == 0 and n1 != 0: self.show("2.eof***:") if n1 == 0 or n2 == 0: break match = self.compare_lines(s1, s2) if not match: mismatches += 1 #@+<< print matches and/or mismatches >> #@+node:ekr.20031218072017.3641: *4* << print matches and/or mismatches >> if self.limitCount == 0 or mismatches <= self.limitCount: if match and self.printMatches: if self.printBothMatches: z1 = "1." + str(lines1) z2 = "2." + str(lines2) self.dump(z1.rjust(6) + ' :', s1) self.dump(z2.rjust(6) + ' :', s2) else: self.dump(str(lines1).rjust(6) + ' :', s1) if not match and self.printMismatches: z1 = "1." + str(lines1) z2 = "2." + str(lines2) self.dump(z1.rjust(6) + '*:', s1) self.dump(z2.rjust(6) + '*:', s2) #@-<< print matches and/or mismatches >> #@+<< warn if mismatch limit reached >> #@+node:ekr.20031218072017.3642: *4* << warn if mismatch limit reached >> if self.limitCount > 0 and mismatches >= self.limitCount: if printTrailing: self.show("") self.show("limit count reached") self.show("") printTrailing = False #@-<< warn if mismatch limit reached >> s1 = s2 = None # force a read of both lines. #@+<< handle reporting after at least one eof is seen >> #@+node:ekr.20031218072017.3643: *4* << handle reporting after at least one eof is seen >> if n1 > 0: lines1 += self.dumpToEndOfFile("1.", f1, s1, lines1, printTrailing) if n2 > 0: lines2 += self.dumpToEndOfFile("2.", f2, s2, lines2, printTrailing) self.show("") self.show("lines1:" + str(lines1)) self.show("lines2:" + str(lines2)) self.show("mismatches:" + str(mismatches))
def compare_open_files(self, f1, f2, name1, name2): # self.show("compare_open_files") lines1 = 0 lines2 = 0 mismatches = 0 printTrailing = True sentinelComment1 = sentinelComment2 = None if self.openOutputFile(): self.show("1: " + name1) self.show("2: " + name2) self.show("") s1 = s2 = None #@+<< handle opening lines >> #@+node:ekr.20031218072017.3639: *4* << handle opening lines >> if self.ignoreSentinelLines: s1 = g.readlineForceUnixNewline(f1) lines1 += 1 s2 = g.readlineForceUnixNewline(f2) lines2 += 1 # Note: isLeoHeader may return None. sentinelComment1 = self.isLeoHeader(s1) sentinelComment2 = self.isLeoHeader(s2) if not sentinelComment1: self.show("no @+leo line for " + name1) if not sentinelComment2: self.show("no @+leo line for " + name2) if self.ignoreFirstLine1: if s1 == None: g.readlineForceUnixNewline(f1) lines1 += 1 s1 = None if self.ignoreFirstLine2: if s2 == None: g.readlineForceUnixNewline(f2) lines2 += 1 s2 = None #@-<< handle opening lines >> while 1: if s1 == None: s1 = g.readlineForceUnixNewline(f1) lines1 += 1 if s2 == None: s2 = g.readlineForceUnixNewline(f2) lines2 += 1 #@+<< ignore blank lines and/or sentinels >> #@+node:ekr.20031218072017.3640: *4* << ignore blank lines and/or sentinels >> # Completely empty strings denotes end-of-file. if s1 and len(s1) > 0: if self.ignoreBlankLines and len(s1.strip()) == 0: s1 = None continue if self.ignoreSentinelLines and sentinelComment1 and self.isSentinel( s1, sentinelComment1): s1 = None continue if s2 and len(s2) > 0: if self.ignoreBlankLines and len(s2.strip()) == 0: s2 = None continue if self.ignoreSentinelLines and sentinelComment2 and self.isSentinel( s2, sentinelComment2): s2 = None continue #@-<< ignore blank lines and/or sentinels >> n1 = len(s1) n2 = len(s2) if n1 == 0 and n2 != 0: self.show("1.eof***:") if n2 == 0 and n1 != 0: self.show("2.eof***:") if n1 == 0 or n2 == 0: break match = self.compare_lines(s1, s2) if not match: mismatches += 1 #@+<< print matches and/or mismatches >> #@+node:ekr.20031218072017.3641: *4* << print matches and/or mismatches >> if self.limitCount == 0 or mismatches <= self.limitCount: if match and self.printMatches: if self.printBothMatches: z1 = "1." + str(lines1) z2 = "2." + str(lines2) self.dump(z1.rjust(6) + ' :', s1) self.dump(z2.rjust(6) + ' :', s2) else: self.dump(str(lines1).rjust(6) + ' :', s1) if not match and self.printMismatches: z1 = "1." + str(lines1) z2 = "2." + str(lines2) self.dump(z1.rjust(6) + '*:', s1) self.dump(z2.rjust(6) + '*:', s2) #@-<< print matches and/or mismatches >> #@+<< warn if mismatch limit reached >> #@+node:ekr.20031218072017.3642: *4* << warn if mismatch limit reached >> if self.limitCount > 0 and mismatches >= self.limitCount: if printTrailing: self.show("") self.show("limit count reached") self.show("") printTrailing = False #@-<< warn if mismatch limit reached >> s1 = s2 = None # force a read of both lines. #@+<< handle reporting after at least one eof is seen >> #@+node:ekr.20031218072017.3643: *4* << handle reporting after at least one eof is seen >> if n1 > 0: lines1 += self.dumpToEndOfFile("1.", f1, s1, lines1, printTrailing) if n2 > 0: lines2 += self.dumpToEndOfFile("2.", f2, s2, lines2, printTrailing) self.show("") self.show("lines1:" + str(lines1)) self.show("lines2:" + str(lines2)) self.show("mismatches:" + str(mismatches))