@@ -6,45 +6,26 @@ 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 SPF (f ) -- TODO: write patch to temporary file first
10- local r ,w local function abort ()print (e )if r then r :close ()end if w then w :close ()end return false end
11- r ,e = io.open (f )if not r then return abort ()end
12- w ,e = io.open (f .. " .orig" ," w" )if not w then return abort ()end
13- for m in r :lines ()do w :write (m .. ' \n ' )end r :close ()w :close ()
14- w ,e = io.open (f ," w" )if not r then return abort ()end
15- r ,e = io.open (f .. " .orig" )if not w then return abort ()end
16- 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
9+ 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
1710 local function R ()rl = rl + 1 return rf :read (" *l" )end
11+ local function RW (x )x :seek (" set" ,0 )end
1812 local function W (s )wl = wl + 1 return wf :write (s )end
19- local function WR ()
20- if h then
21- 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
22- print (M )os.exit (1 )
23- else
24- print (P )
25- end
26- end
27- if rf and wf then
28- local r = R ()
29- while r do
30- W (r .. ' \n ' )r = R ()
31- end
32- -- TODO: Write original to a backup here if it differs from the backup
33- -- TODO: reopen rf with write permissions and copy wf content to it
34- wf :close () -- TODO: close and nil rf here to
35- wf ,wl = nil ,0
36- end
37- rf :close ()rf ,rl ,h = nil ,0 ,nil
38- end
13+ local function WR ()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
14+ if rf and wf then local r = R ()while r do W (r .. ' \n ' )r = R ()end
15+ local function B ()local n ,f ,l = cp :match (" (.*)%.[^%.]*" ).. " .bak" f = io.open (n ," a+" )
16+ 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
17+ if f :seek ()~= rf :seek ()or C ()then RW (rf )f :close ()f = assert (io.open (n ," w" ))r = R ()repeat f :write (r .. ' \n ' )r = R ()until not r end end
18+ B ()rf :close ()rf = assert (io.open (cp ," w" ))RW (wf )r = wf :read (" *l" )repeat rf :write (r .. " \n " )r = wf :read (" *l" )until not r wf :close ()wf ,wl = nil ,0 end
19+ rf :close ()rf ,rl ,h = nil ,0 ,nil end
3920 local n = pf :read (" *l" )while n do local l ,f = n n = pf :read (" *l" )f = l :sub (1 ,1 )if f == ' +' then
4021 if l :sub (2 ,4 )~= " ++ " then W (l :sub (2 ).. (n and n :match (" ^\\ No newline at end of file" )and " " or ' \n ' ))end
4122 elseif f == ' -' then
42- if l :sub (2 ,4 )== " -- " then local fn = PFN (l )if rf then WR ()end if SPF (fn )then cp = fn print (" \t " .. cp .. " :" )end
23+ if l :sub (2 ,4 )== " -- " then local fn = PFN (l )if rf then WR ()end if SPF (fn )then print (" \t " .. fn .. " :" )cp = fn end
4324 elseif R ()~= l :sub (2 )then print (M )os.exit (1 )end
4425 elseif f == ' ' then
4526 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
4627 elseif f == ' @' then if l :sub (2 ,3 )== " @ " then
47- 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
28+ 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
4829 local s ,o ,w = S (l ," " ),{},{}if s [2 ]then o = S (s [2 ]," ," )end if s [3 ]then w = S (s [3 ]," ," )end
4930 if o [1 ]then o [1 ]= o [1 ]:sub (2 )end if w [1 ]then w [1 ]= w [1 ]:sub (2 )end
5031 return {o = {s = tonumber (o [1 ]),l = tonumber (o [2 ])or 1 },n = {s = tonumber (w [1 ]),l = tonumber (w [2 ])or 1 }}end
0 commit comments