@@ -9,10 +9,10 @@ local function diff_u(fn1,fn2)
99 local function eol ()if c == ' \r ' then local d = f :read (1 )f :seek (" cur" ,- 1 )return d ~= ' \n ' end return c == ' \n ' end
1010 o = o + 1 table.insert (l ,c )if eol ()then break end end
1111 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
12- local f1 ,f2 ,size = open (fn1 ),open (fn2 ),string.packsize (PF )
12+ local f1 ,f2 ,ps = open (fn1 ),open (fn2 ),string.packsize (PF )
1313 local function cmp (x ,y )
14- local l1 ,c1 ,o1 = string.unpack (PF ,f1 ,(x - 1 )* size + 1 )
15- local l2 ,c2 ,o2 = string.unpack (PF ,f2 ,(y - 1 )* size + 1 )
14+ local l1 ,c1 ,o1 = string.unpack (PF ,f1 ,(x - 1 )* ps + 1 )
15+ local l2 ,c2 ,o2 = string.unpack (PF ,f2 ,(y - 1 )* ps + 1 )
1616 if l1 ~= l2 or c1 ~= c2 then return false end
1717 local function bin ()
1818 local function line (fn ,o ,l )
@@ -23,13 +23,11 @@ local function diff_u(fn1,fn2)
2323 return b1 == b2 end return bin ()end
2424 local function print_table ()
2525 -- TODO: store and reverse lookup this table to find the least amount of changes
26- local il ,jl =# f1 // size ,# f2 // size
26+ local il ,jl =# f1 // ps ,# f2 // ps
2727 for i = 1 ,il do
28- local row = {}
29- for j = 1 ,jl do table.insert (row ,cmp (i ,j ) and " 1" or " 0" )end
28+ local row = {}for j = 1 ,jl do table.insert (row ,cmp (i ,j )and " 1" or " 0" )end
3029 print (table.concat (row , " " ))end end
31- print_table ()
32- end
30+ print_table ()end
3331if # arg < 2 or # arg % 2 ~= 0 then print (arg [- 1 ].. " " .. arg [0 ].. [[ old new...
3432
3533Compare differences between files, print them as unified context.
0 commit comments