forked from dwing4g/tes3-chinese-translation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtes3merge.lua
More file actions
88 lines (84 loc) · 2.28 KB
/
Copy pathtes3merge.lua
File metadata and controls
88 lines (84 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-- luajit tes3merge.lua old.txt new.txt patch_from.txt patch_to.txt
-- luajit tes3merge.lua nexus\tes3cn_Morrowind.ext.old.txt nexus\tes3cn_Morrowind.ext.txt tes3cn_Morrowind.ext.old.txt tes3cn_Morrowind.ext.txt
-- luajit tes3merge.lua nexus\tes3cn_Tribunal.ext.old.txt nexus\tes3cn_Tribunal.ext.txt tes3cn_Tribunal.ext.old.txt tes3cn_Tribunal.ext.txt
-- luajit tes3merge.lua nexus\tes3cn_Bloodmoon.ext.old.txt nexus\tes3cn_Bloodmoon.ext.txt tes3cn_Bloodmoon.ext.old.txt tes3cn_Bloodmoon.ext.txt
local function loadExt(filename, callback)
local k, e, c, m, n = nil, nil, nil, false, 0
for line in io.lines(filename) do
n = n + 1
if line ~= "" or m then
if not k then
if line:sub(1, 2) == "> " then
k = line
else
error("ERROR: invalid line(" .. n .. "): " .. line)
end
elseif not e then
e = line
m = line:sub(1, 3) == '"""' and not line:sub(4, -1):find '"""'
elseif e and m and not c then
e = e .. "\r\n" .. line
if line:find '"""' then
m = false
end
elseif not c then
c = line
m = line:sub(1, 3) == '"""' and not line:sub(4, -1):find '"""'
if not m then
callback(k, e, c)
k, e, c, m = nil, nil, nil, false
end
elseif c and m then
c = c .. "\r\n" .. line
if line:find '"""' then
callback(k, e, c)
k, e, c, m = nil, nil, nil, false
end
else
error("ERROR: invalid line(" .. n .. "): " .. line)
end
end
end
end
io.write("loading ", arg[1], " ... ")
local n = 0
local oldT = {}
loadExt(arg[1], function(k, e, c)
oldT[k] = c
n = n + 1
end)
print(n .. " items")
io.write("loading ", arg[2], " ... ")
local m, n = 0, 0
local newT = {}
loadExt(arg[2], function(k, e, c)
if oldT[k] ~= c then
newT[k] = c
m = m + 1
end
n = n + 1
end)
print(n .. " items, " .. m .. " modified")
local f = io.open(arg[4], "wb")
io.write("loading ", arg[3], " ... ")
m, n = 0, 0
loadExt(arg[3], function(k, e, c)
local done = false
local newC = newT[k]
if newC then
local oldC = oldT[k]
if c == oldC then
c = newC
elseif c ~= newC then
-- f:write(k, "\r\n", e, "\r\n<<<", oldC or "", "\r\n>>>", newC, "\r\n===", c, "\r\n\r\n")
-- done = true
m = m + 1
end
end
if not done then
f:write(k, "\r\n", e, "\r\n", c, "\r\n\r\n")
end
n = n + 1
end)
f:close()
print(n .. " items, " .. m .. " conflicted")