Skip to content

Commit 18f5fda

Browse files
committed
Initial implementation of hunk header parsing and verification.
1 parent 1ea7825 commit 18f5fda

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

xtra/PATCH.LUA

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
local function patch(p)
44
local pf, e = io.open(p)
5-
local ol, bl, cp, of, bf = 0, 0
5+
local ol, bl, cp, of, bf, hunk = 0, 0
66
if not pf then print(e) os.exit(1) end
77

88
local function parseFileName(l)
@@ -82,9 +82,20 @@ local function patch(p)
8282
new = { start = tonumber(new[1]), lines = tonumber(new[2]) or 1 }
8383
}
8484
end
85-
--TODO: Something useful with this table
86-
local hunk=parseHunkHeader()print("Hunk Header",hunk.old.start,hunk.old.lines,hunk.new.start,hunk.new.lines)
87-
--TODO: Jump through file to when hunk starts
85+
if hunk then
86+
if bl - hunk.old.start ~= hunk.old.lines or ol - hunk.new.start ~= hunk.new.lines then
87+
print("Malformed Hunk")
88+
end
89+
end
90+
hunk=parseHunkHeader()
91+
if hunk then
92+
local skip, line = hunk.old.start - 1
93+
if hunk.new.start - 1 ~= skip then print("Malformed Hunk") end
94+
while bl < skip do
95+
line, bl = bf:read("*l"), bl + 1
96+
if of then of:write(line .. '\n') ol = ol + 1 end
97+
end
98+
end
8899
end
89100
end
90101
end

0 commit comments

Comments
 (0)