Skip to content

Commit f329c12

Browse files
committed
Expand loops for debugging.
1 parent c9fa38f commit f329c12

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

xtra/DIFF.LUA

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ 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 table.insert(m,{y=y,x=x})end end end
17+
h,w,la,m=#f1//ps,#f2//ps,1,{}
18+
for x=1,h do
19+
for y=la,w do
20+
if cmp(x,y)then
21+
table.insert(m,{y=y,x=x})
22+
la=y
23+
break
24+
end
25+
end
26+
end la=nil
1827
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
1928
local function pfl(p,s)return(p..s:gsub('\n$',''):gsub('\r$',''))end
2029
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
@@ -23,12 +32,28 @@ local function diff_u(fn1,fn2)
2332
for _,v in ipairs(u.l)do print(v)end end u=nil end
2433
local function init()if not u then local k,l=math.max(i-3,1),math.max(j-3,1)u={e=0,l={},o={s=k,l=0},n={s=l,l=0}}
2534
for z=k,i-1 do table.insert(u.l,pfl(" ",get(fn1,f1,z)))u.o.l,u.n.l=u.o.l+1,u.n.l+1 end end end
26-
local k=2 while k<=#m do if m[k].x>m[k-1].x then table.remove(m,k-1)else k=k+1 end end
35+
--local k=2 while k<=#m do if m[k].x>m[k-1].x then table.remove(m,k-1)else k=k+1 end end
2736
--TODO: convert to sequences
2837
for _,p in ipairs(m)do
29-
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
30-
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
31-
if u then if u.e<4 and i<=h 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
38+
while i<p.x do
39+
init()
40+
table.insert(u.l,pfl("-",get(fn1,f1,i)))
41+
i,u.o.l,u.e=i+1,u.o.l+1,0
42+
end
43+
while j<p.y do
44+
init()
45+
table.insert(u.l,pfl("+",get(fn2,f2,j)))
46+
j,u.n.l,u.e=j+1,u.n.l+1,0
47+
end
48+
if u then
49+
if u.e<4 and i<=h then
50+
table.insert(u.l,pfl(" ",get(fn1,f1,i)))
51+
u.e,u.o.l,u.n.l=u.e+1,u.o.l+1,u.n.l+1
52+
else
53+
flush()
54+
end
55+
end i,j=i+1,j+1
56+
end
3257
local function nlc()if la then la=la:sub(-1)if la~='\n'and la~='\r'then table.insert(u.l,"\\ No newline at end of file")end end end
3358
while i<=h do init()la=get(fn1,f1,i,ps)table.insert(u.l,pfl("-",la))i,u.o.l,u.e=i+1,u.o.l+1,0 end nlc()
3459
while j<=w do init()la=get(fn2,f2,j,ps)table.insert(u.l,pfl("+",la))j,u.n.l,u.e=j+1,u.n.l+1,0 end nlc()

0 commit comments

Comments
 (0)