1- #! /usr/bin/env lua
1+ #! /usr/bin/env lua
22
3- CONTEXT_LINES = 3
3+ CL = 3
44local function diff_u (fn1 , fn2 )
55 local function open (fn ) local f , e = io.open (fn ) if not f then print (e ) os.exit (1 ) end return f end
66 local f1 , f2 , pre , add , del , p1 , p2 , x , y , h , l1 , l2 = open (fn1 ), open (fn2 ), {}, {}, {}, 0 , 0 , 0 , 0
@@ -51,19 +51,19 @@ local function diff_u(fn1, fn2)
5151 end
5252 local function diagonal ()
5353 flush_hunk ()
54- if # pre > CONTEXT_LINES then table.remove (pre , 1 ) end
54+ if # pre > CL then table.remove (pre , 1 ) end
5555 if p1 > 0 or p2 > 0 then
5656 if p1 > 0 and p2 > 0 then
57- if p1 > CONTEXT_LINES or p2 > CONTEXT_LINES then table.insert (buf .line , " " .. l2 ) end
57+ if p1 > CL or p2 > CL then table.insert (buf .line , " " .. l2 ) end
5858 p1 , p2 = p1 - 1 , p2 - 1
5959 elseif p1 > 0 then
60- if p1 > CONTEXT_LINES then table.insert (buf .line , " " .. l1 ) end
60+ if p1 > CL then table.insert (buf .line , " " .. l1 ) end
6161 p1 = p1 - 1
6262 elseif p2 > 0 then
63- if p2 > CONTEXT_LINES then table.insert (buf .line , " " .. l2 ) end
63+ if p2 > CL then table.insert (buf .line , " " .. l2 ) end
6464 p2 = p2 - 1
65- elseif p2 <= CONTEXT_LINES then table.insert (pre , l2 )
66- elseif p1 <= CONTEXT_LINES then table.insert (pre , l1 ) end
65+ elseif p2 <= CL then table.insert (pre , l2 )
66+ elseif p1 <= CL then table.insert (pre , l1 ) end
6767
6868 if p1 == 0 or p2 == 0 then flush_buf () table.insert (pre , l2 ) end
6969 else
@@ -72,12 +72,12 @@ local function diff_u(fn1, fn2)
7272 x , y , l1 , l2 = x + 1 , y + 1 , f1 :read (" *l" ), f2 :read (" *l" )
7373 end
7474 local function right ()
75- flush_pre () p1 = (CONTEXT_LINES * 2 ) + 1
75+ flush_pre () p1 = (CL * 2 ) + 1
7676 table.insert (del , l1 )
7777 x , l1 = x + 1 , f1 :read (" *l" )
7878 end
7979 local function down ()
80- flush_pre () p2 = (CONTEXT_LINES * 2 ) + 1
80+ flush_pre () p2 = (CL * 2 ) + 1
8181 table.insert (add , l2 )
8282 y , l2 = y + 1 , f2 :read (" *l" )
8383 end
0 commit comments