Skip to content

Commit 2532668

Browse files
committed
Squish cmp().
1 parent 25d7f6c commit 2532668

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

xtra/DIFF.LUA

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,19 @@ local function diff_u(fn1,fn2)
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
1212
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)*ps+1)
15-
local l2,c2,o2=string.unpack(PF,f2,(y-1)*ps+1)
14+
local l1,c1,o1,l2,c2,o2=string.unpack(PF,f1,(x-1)*ps+1)l2,c2,o2=string.unpack(PF,f2,(y-1)*ps+1)
1615
if l1~=l2 or c1~=c2 then return false end
17-
local function bin()
18-
local function line(fn,o,l)
19-
local f,e=io.open(fn,"rb")if not f then return nil,e end
20-
f:seek("set",o)local get=f:read(l)f:close()return get end
21-
local b1,e,b2=line(fn1,o1,l1)if not b1 then error(e)end
22-
b2,e=line(fn2,o2,l2)if not b2 then error(e)end
23-
return b1==b2 end return bin()end
16+
local function line(fn,o,l)
17+
local f,e=io.open(fn,"rb")if not f then return nil,e end
18+
f:seek("set",o)local g=f:read(l)f:close()return g end
19+
local b1,e,b2=line(fn1,o1,l1)if not b1 then error(e)end b2,e=line(fn2,o2,l2)if not b2 then error(e)end
20+
return b1==b2 end
2421
local function print_table()
2522
--TODO: store and reverse lookup this table to find the least amount of changes
2623
local il,jl=#f1//ps,#f2//ps
2724
for i=1,il do
2825
local row={}for j=1,jl do table.insert(row,cmp(i,j)and"1"or"0")end
29-
print(table.concat(row, " "))end end
26+
print(table.concat(row," "))end end
3027
print_table()end
3128
if#arg<2 or#arg%2~=0 then print(arg[-1].." "..arg[0]..[[ old new...
3229

0 commit comments

Comments
 (0)