@@ -14,7 +14,21 @@ local function diff_u(fn1,fn2)
1414 local l1 ,c1 ,o1 ,l2 ,c2 ,o2 ,b1 ,e ,b2 ,f = string.unpack (PF ,f1 ,(x - 1 )* ps + 1 )l2 ,c2 ,o2 = string.unpack (PF ,f2 ,(y - 1 )* ps + 1 )if l1 ~= l2 or c1 ~= c2 then return false end
1515 local function li (fn ,o ,l )f ,e = io.open (fn ," rb" )if not f then return nil ,e end f :seek (S ,o )local g = f :read (l )f :close ()return g end
1616 b1 ,e ,b2 = li (fn1 ,o1 ,l1 )if not b1 then error (e )end b2 ,e = li (fn2 ,o2 ,l2 )if not b2 then error (e )end return b1 == b2 end
17- h ,w ,m =# f1 // ps ,# f2 // ps ,{}for x = 1 ,h do for y = 1 ,w do if cmp (x ,y )then if # m > 0 and m [# m ].x == x then table.insert (m [# m ].y ,y )else table.insert (m ,{y = {y },x = x })end end end end
17+ h ,w ,m =# f1 // ps ,# f2 // ps ,{}
18+ local function inList (l ,v )for _ ,p in ipairs (l )do if v == p then return true end end return false end
19+ for x = 1 ,h do
20+ for y = 1 ,w do
21+ if cmp (x ,y )then
22+ if # m > 0 and m [# m ].x == x then
23+ table.insert (m [# m ].y ,y )
24+ elseif # m > 0 and m [# m ].x == x - 1 and inList (m [# m ].y ,y - 1 )then
25+ m [# m ].l = m [# m ].l + 1
26+ else
27+ table.insert (m ,{y = {y },x = x ,l = 1 })
28+ end
29+ end
30+ end
31+ end
1832 local function get (fn ,p ,x )local l ,_ ,o ,f ,r = string.unpack (PF ,p ,(x - 1 )* ps + 1 )f = assert (io.open (fn ," rb" ))f :seek (S ,o )r = f :read (l )f :close ()return r end
1933 local function pfl (p ,s )return (p .. s :gsub (' \n $' ,' ' ):gsub (' \r $' ,' ' ))end
2034 local function flush ()if # u .l > 0 then if u .e >= 4 then table.remove (u .l )u .o .l ,u .n .l = u .o .l - 1 ,u .n .l - 1 end
@@ -26,7 +40,7 @@ local function diff_u(fn1,fn2)
2640 -- TODO: Select correct y grid on each compare table
2741 for _ ,p in ipairs (m )do
2842 -- Temporary debug code
29- print (p .x , table.concat (p .y ," ," ))--[[
43+ print (p .x , p . l , table.concat (p .y ," ," ))--[[
3044 while i<p.x do init()table.insert(u.l,pfl("-",get(fn1,f1,i)))i,u.o.l,u.e=i+1,u.o.l+1,0 end
3145 while j<p.y do init()table.insert(u.l,pfl("+",get(fn2,f2,j)))j,u.n.l,u.e=j+1,u.n.l+1,0 end
3246 if u then if u.e<4 then table.insert(u.l,pfl(" ",get(fn1,f1,i)))u.e,u.o.l,u.n.l=u.e+1,u.o.l+1,u.n.l+1 else flush()end end i,j=i+1,j+1 end
0 commit comments