@@ -8,19 +8,16 @@ local function diff_u(fn1,fn2)
88 local o ,p = 0 ," "
99 local function crc32 (s )local c = M for i = 1 ,# s do local byte = s :byte (i )c = (c >> 8 )~CT [(c ~byte )&0xFF ]end return (~c )&M end
1010 while true do local ls ,l = o ,{}
11- while true do local c = f :read (1 )if not c then break end
11+ while true do local c = f :read (1 )if not c then break end
1212 local function eol ()if c == ' \r ' then local d = f :read (1 )f :seek (" cur" ,- 1 )return d ~= ' \n ' end return c == ' \n ' end
1313 o = o + 1 table.insert (l ,c )if eol ()then break end end
14- if # l == 0 then break end l = table.concat (l )local ln ,c =# l ,crc32 (l )p = p .. string.pack (PF ,ln ,c ,ls )end
15- f :close ()return p end
14+ if # l == 0 then break end l = table.concat (l )local ln ,c =# l ,crc32 (l )p = p .. string.pack (PF ,ln ,c ,ls )end f :close ()return p end
1615 -- TODO: Replace this code with myers algorithm
1716 local f1 ,f2 ,size = open (fn1 ),open (fn2 ),string.packsize (PF )
1817 local function printFile (f )local len =# f // size
1918 for i = 1 ,len do local length ,crc ,offset = string.unpack (PF ,f ,(i - 1 )* size + 1 )
2019 print ((" Offset: %06d | Length: %03d | CRC32: %08X" ):format (offset ,length ,crc ))end end
21- printFile (f1 )
22- printFile (f2 )
23- end
20+ printFile (f1 )printFile (f2 )end
2421if # arg < 2 or# arg % 2 ~= 0 then print (arg [- 1 ].. " " .. arg [0 ].. [[ old new...
2522
2623Compare differences between files, print them as unified context.
0 commit comments