@@ -6,35 +6,36 @@ local function patch(pf)
66 local function PFN (l )local f = l :sub (5 ,5 )
77 if f == ' "' or f == " '" then return l :match (f .. " ([^" .. f .. " ]+)" .. f ,5 )
88 else f = {}for v in string.gmatch (l ," %S+" )do table.insert (f ,v )end return f [2 ]end end
9+ local function A ()if rf then rf :close ()end if wf then wf :close ()end h ,rf ,wf ,wl ,rl = nil ,nil ,nil ,0 ,0 end
910 local function SPF (f )rl ,wl = 0 ,0 rf ,e = io.open (f )wf ,e = io.tmpfile ()if e then print (" \t " .. e )rf ,wf = nil ,nil end return not e end
1011 local function R ()rl = rl + 1 return rf :read (" *l" )end
1112 local function RW (x )x :seek (" set" ,0 )end
1213 local function CF (a ,b )local l ,t ,s = 0 ,a :seek (" end" )RW (a )s = a :read (" *l" )repeat b :write (s .. (l +# s < t and " \n " or " " ))l = l +# s s = a :read (" *l" )until not s end
1314 local function W (s )wl = wl + 1 return wf :write (s )end
14- local function EPF ()if h then if (h .o .l > 0 and h .o .s > 0 )and (h .o .l ~= rl - (h .o .s - 1 )or h .n .l ~= wl - (h .n .s - 1 ))then print (M )os.exit ( 1 )else print (P )end end
15+ local function EPF ()if h then if (h .o .l > 0 and h .o .s > 0 )and (h .o .l ~= rl - (h .o .s - 1 )or h .n .l ~= wl - (h .n .s - 1 ))then print (M )A ( )else print (P )end end
1516 if rf and wf then local r ,f ,l = R ()while r do W (r .. ' \n ' )r = R ()end
1617 local function B ()local n = cp :match (" (.*)%.[^%.]*" ).. " .bak" f = io.open (n ," a+" )
1718 local function C ()RW (f )RW (rf )repeat r ,l = R (),rf :read (" *l" )if r ~= l then return 1 end until not r or not l end
1819 if f :seek ()~= rf :seek ()or C ()then f :close ()f = assert (io.open (n ," w" ))CF (rf ,f )end end
19- B ()rf :close ()rf = assert (io.open (cp ," w" ))CF (wf ,rf )wf :close ()wf ,wl = nil ,0 end
20- rf :close ()rf ,rl ,h = nil ,0 ,nil end
21- local n = pf :read (" *l" )while n do local l ,f = n n = pf :read (" *l" )f = l :sub (1 ,1 )if f == ' +' then
22- if l :sub (2 ,4 )~= " ++ " then W (l :sub (2 ).. (n and n :match (" ^\\ No newline at end of file" )and " " or ' \n ' ))end
23- elseif f == ' -' then
20+ B ()rf :close ()rf = assert (io.open (cp ," w" ))CF (wf ,rf )end
21+ A ()end
22+ local n = pf :read (" *l" )while n do local l ,f = n n = pf :read (" *l" )f = l :sub (1 ,1 )if f == ' -' then
2423 if l :sub (2 ,4 )== " -- " then local fn = PFN (l )if rf then EPF ()end if SPF (fn )then print (" \t " .. fn .. " :" )cp = fn end
25- elseif R ()~= l :sub (2 )then print (M )os.exit (1 )end
24+ elseif not rf or not wf or R ()~= l :sub (2 )then print (M )A ()end
25+ elseif rf and wf then if f == ' +' then
26+ if l :sub (2 ,4 )~= " ++ " then W (l :sub (2 ).. (n and n :match (" ^\\ No newline at end of file" )and " " or ' \n ' ))end
2627 elseif f == ' ' then
27- if rf then local c ,i = R (),l :sub (2 )if c == i then if wf then W (i .. ' \n ' )end else print (M )os.exit ( 1 )end end
28+ if rf then local c ,i = R (),l :sub (2 )if c == i then if wf then W (i .. ' \n ' )end else print (M )A ( )end end
2829 elseif f == ' @' then if l :sub (2 ,3 )== " @ " then
2930 local function PHH ()local function S (i ,d )local r = {}for m in (i .. d ):gmatch (" (.-)" .. d )do table.insert (r ,m )end return r end
3031 local s ,o ,w = S (l ," " ),{},{}if s [2 ]then o = S (s [2 ]," ," )end if s [3 ]then w = S (s [3 ]," ," )end
3132 if o [1 ]then o [1 ]= o [1 ]:sub (2 )end if w [1 ]then w [1 ]= w [1 ]:sub (2 )end
3233 return {o = {s = tonumber (o [1 ]),l = tonumber (o [2 ])or 1 },n = {s = tonumber (w [1 ]),l = tonumber (w [2 ])or 1 }}end
33- if h then if h .o .l ~= rl - (h .o .s - 1 )or h .n .l ~= wl - (h .n .s - 1 )then print (M )os.exit ( 1 )else print (P )end end
34- h = PHH ()if h then io.write (" \t\t @@ -" .. h .o .s .. " ," .. h .o .l .. " +" .. h .n .s .. " ," .. h .n .l .. " @@: " )local s = h .o .s > 0 and (h .o .s - 1 )- rl or 0 if s < 0 then print (M )os.exit ( 1 )end
34+ if h then if h .o .l ~= rl - (h .o .s - 1 )or h .n .l ~= wl - (h .n .s - 1 )then print (M )A ( )else print (P )end end
35+ h = PHH ()if h then io.write (" \t\t @@ -" .. h .o .s .. " ," .. h .o .l .. " +" .. h .n .s .. " ," .. h .n .l .. " @@: " )local s = h .o .s > 0 and (h .o .s - 1 )- rl or 0 if s < 0 then print (M )A ( )end
3536 for _ = 1 ,s do
36- local r = R ()if not r then print (M )os.exit ( 1 )end
37- if wf then W (r .. " \n " )end end end end end end
37+ local r = R ()if not r then print (M )A ( )end
38+ if wf then W (r .. " \n " )end end end end end end end
3839 if rf then EPF ()end end
3940if # arg < 1 then print (arg [- 1 ].. " " .. arg [0 ].. [[ diff...
4041
0 commit comments