2018-05-17 16:19:04 +10:00
|
|
|
local serial = require "serialization"
|
|
|
|
|
|
|
|
local tArgs = {...}
|
|
|
|
local infile = tArgs[1]
|
|
|
|
local minfile = tArgs[1]..".min"
|
|
|
|
local outfile = tArgs[2]
|
|
|
|
local dbug = true
|
2018-05-17 16:36:32 +10:00
|
|
|
if not outfile then dbug = false end
|
2018-05-17 16:19:04 +10:00
|
|
|
|
|
|
|
local function dprint(...)
|
|
|
|
if dbug then
|
|
|
|
print(...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local replacements={
|
|
|
|
{" "," "},
|
|
|
|
{"\n ","\n"},
|
|
|
|
{"\n\n","\n"},
|
|
|
|
{" == ","=="},
|
|
|
|
{" ~= ","~="},
|
|
|
|
{" >= ",">="},
|
|
|
|
{" <= ","<="},
|
|
|
|
{" > ",">"},
|
|
|
|
{" < ","<"},
|
|
|
|
{" = ","="},
|
|
|
|
{", ",","},
|
|
|
|
{" %+ ","+"},
|
|
|
|
{" %- ","-"},
|
|
|
|
{" %/ ","/"},
|
|
|
|
{" %* ","*"},
|
|
|
|
{" \n","\n"},
|
2018-05-19 03:31:02 +10:00
|
|
|
{" %.%. ",".."},
|
2018-05-19 13:36:32 +10:00
|
|
|
{"([%)%}])%s(%a)","%1%2"},
|
|
|
|
{"(%d)%s([G-Zg-z])","%1%2"},
|
|
|
|
{"([\"'])%s(%a)","%1%2"},
|
2018-05-17 16:19:04 +10:00
|
|
|
{"%-%-.-\n",""},
|
|
|
|
}
|
|
|
|
|
|
|
|
local initr = #replacements
|
|
|
|
|
|
|
|
local fmin = io.open(minfile,"rb")
|
|
|
|
if fmin then
|
|
|
|
local nreplacements = serial.unserialize(fmin:read("*a"))
|
|
|
|
for k,v in ipairs(nreplacements) do
|
|
|
|
table.insert(replacements,1+k,v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
dprint(tostring(#replacements - initr).." replacements loaded.")
|
|
|
|
|
|
|
|
local fin = io.open(infile,"rb")
|
|
|
|
local ss = fin:read("*a")
|
|
|
|
fin:close()
|
|
|
|
|
|
|
|
local initl = ss:len()
|
|
|
|
|
|
|
|
for k,v in ipairs(replacements) do
|
|
|
|
while ss:find(v[1]) ~= nil do
|
|
|
|
ss=ss:gsub(v[1],v[2])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-17 16:36:32 +10:00
|
|
|
dprint("Delta: "..tostring(initl - ss:len()).." bytes")
|
2018-05-17 16:19:04 +10:00
|
|
|
|
|
|
|
if outfile then
|
|
|
|
local outf = io.open(outfile,"wb")
|
|
|
|
outf:write(ss)
|
|
|
|
outf:close()
|
|
|
|
else
|
|
|
|
print(ss)
|
|
|
|
end
|