@@ -14,17 +14,19 @@ local function patch(pf)
1414 w ,e = io.open (f ," w" )if not r then return abort ()end
1515 r ,e = io.open (f .. " .orig" )if not w then return abort ()end
1616 if wf then wf :close ()end if rf then rf :close ()end wf ,wl ,rf ,rl ,h = w ,0 ,r ,0 ,nil return true end
17+ local function R ()rl = rl + 1 return rf :read (" *l" )end
18+ local function W (s )wl = wl + 1 return wf :write (s )end
1719 local function writeRemainder ()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
18- if wf then local rest = rf : read ( " *l " )while rest do wf : write (rest .. ' \n ' )rest = rf : read ( " *l " )end wf :close ()wf ,wl = nil ,0 end rf :close ()rf ,rl ,h = nil ,0 ,nil end
20+ if wf then local rest = R ( )while rest do W (rest .. ' \n ' )rest = R ( )end wf :close ()wf ,wl = nil ,0 end rf :close ()rf ,rl ,h = nil ,0 ,nil end
1921 local n = pf :read (" *l" )while n do
2022 local l ,ls = n n = pf :read (" *l" )ls = l :sub (1 ,1 )
2123 if ls == ' +' then
22- if l :sub (2 ,4 )~= " ++ " then wf : write (l :sub (2 ).. (n and n :match (" ^\\ No newline at end of file" )and " " or ' \n ' ))wl = wl + 1 end
24+ if l :sub (2 ,4 )~= " ++ " then W (l :sub (2 ).. (n and n :match (" ^\\ No newline at end of file" )and " " or ' \n ' ))end
2325 elseif ls == ' -' then
2426 if l :sub (2 ,4 )== " -- " then local fn = parseFileName (l )if rf then writeRemainder ()end if setPatchFile (fn )then cp = fn print (" \n '" .. cp .. " ':" )end
25- else rl = rl + 1 if rf : read ( " *l " )~= l :sub (2 )then print (M )os.exit (1 )end end
27+ elseif R ( )~= l :sub (2 )then print (M )os.exit (1 )end
2628 elseif ls == ' ' then
27- if rf then local c ,i = rf : read ( " *l " ),l :sub (2 )rl = rl + 1 if c == i then if wf then wf : write (i .. ' \n ' )wl = wl + 1 end else print (M )os.exit (1 )end end
29+ 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
2830 elseif ls == ' @' then if l :sub (2 ,3 )== " @ " then
2931 local function parseHunkHeader ()
3032 local function split (i ,d )local r = {}for m in (i .. d ):gmatch (" (.-)" .. d )do table.insert (r ,m )end return r end
@@ -36,8 +38,8 @@ local function patch(pf)
3638 io.write (" \t @@ -" .. h .o .s .. " ," .. h .o .l .. " +" .. h .n .s .. " ," .. h .n .l .. " @@: " )
3739 local s = h .o .s > 0 and (h .o .s - 1 )- rl or 0 if s < 0 then print (M )os.exit (1 )end
3840 for _ = 1 ,s do
39- local ctx = rf : read ( " *l " )if not ctx then print (M )os.exit (1 )end
40- rl = rl + 1 if wf then wf : write (ctx .. " \n " )wl = wl + 1 end end end end end end
41+ local ctx = R ( )if not ctx then print (M )os.exit (1 )end
42+ if wf then W (ctx .. " \n " )end end end end end end
4143 if rf then writeRemainder ()end end
4244if # arg < 1 then print (arg [- 1 ].. " " .. arg [0 ].. [[ diff...
4345
0 commit comments