1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-23 10:58:06 +11:00

Improve installer minification somewhat

This commit is contained in:
20kdc 2018-04-25 01:04:34 +01:00
parent 6f2c1e2f2f
commit 2081cd8e49
7 changed files with 133 additions and 50 deletions

87
bonecrunch.lua Normal file
View File

@ -0,0 +1,87 @@
-- This is released into the public domain.
-- No warranty is provided, implied or otherwise.
-- This program tries to crunch down the installer a bit further.
-- Specific target in mind, it has no support for string escapes.
-- It also does this:
for i = 1, 3 do
print(io.read())
end
local sequences = {
{"\n", " "},
{" ", " "},
{" #", "#"},
{"# ", "#"},
{" ,", ","},
{", ", ","},
{" (", "("},
{"( ", "("},
{" )", ")"},
{") ", ")"},
{" <", "<"},
{"< ", "<"},
{" >", ">"},
{"> ", ">"},
{" *", "*"},
{"* ", "*"},
{" ~", "~"},
{"~ ", "~"},
{" /", "/"},
{"/ ", "/"},
{" %", "%"},
{"% ", "%"},
{" =", "="},
{"= ", "="},
{" -", "-"},
{"- ", "-"},
{" +", "+"},
{"+ ", "+"},
{".. ", ".."},
{" ..", ".."},
{"\"\" ", "\"\""},
{"=0 t", "=0t"},
{">0 t", ">0t"},
{">1 t", ">1t"},
{"=1 w", "=1w"},
{"=380 l", "=380l"},
{"=127 t", "=127t"},
{"=128 t", "=128t"},
{">255 t", ">255t"},
{"=512 t", "=512t"}
}
local function pass(buffer)
local ob = ""
local smode = false
while #buffer > 0 do
if not smode then
local ds = true
while ds do
ds = false
for _, v in ipairs(sequences) do
if buffer:sub(1, #(v[1])) == v[1] then
buffer = v[2] .. buffer:sub(#(v[1]) + 1)
ds = true
end
end
end
end
local ch = buffer:sub(1, 1)
buffer = buffer:sub(2)
ob = ob .. ch
if ch == "\"" then
smode = not smode
end
end
return ob
end
local op = io.read("*a")
while true do
local np = pass(op)
if np == op then
io.write(np)
return
end
op = np
end

View File

@ -52,7 +52,7 @@ local function runBlock(blk)
end
end
while true do
while 1 do
local blkd = io.read(512)
runBlock(blkd)
if #blkd < 512 then

View File

@ -3,36 +3,38 @@
local sector = io.write -- XX
-- BUNDIVIDE reference implementation for integration XX
local Cs,Cbu,Cb,Cw,Cp,Ct,Ci,CP,CB,CD={},128,"",128,"",""
CP=function(d,b)
Ct=Ct..d
CP = function(d,b)
Ct = Ct .. d
while#Ct>2 do
b=Ct:byte()
Ct=Ct:sub(2)
if b==127then
b=Ct:byte()
Ct=Ct:sub(2)
if b==127then
b=Ct:byte()+254
if b>255then
b=b-256
b = Ct:byte()
Ct = Ct:sub(2)
if b == 127 then
b = Ct:byte()
Ct = Ct:sub(2)
if b == 127 then
b = Ct:byte()+254
if b > 255then
b = b - 256
end
Ct=Ct:sub(2)
Ct = Ct:sub(2)
else
b=b+127
b = b + 127
end
end
Cp=Cp..string.char(b)
if #Cp==512then
Cp = Cp..string.char(b)
if #Cp == 512 then
sector(Cp)
Cp=""
Cp = ""
end
end
end
for i=128,127+Cbu do Cs[i]=("\x00"):rep(512) end
Cs[Cw]=""
CB=function(d,i,d2,x,y)
for i = 128, 127 + Cbu do
Cs[i] = ("\x00"):rep(512)
end
Cs[Cw] = ""
CB = function (d, i, d2, x, y)
i=1
while i<=#d-2 do
while i <= #d - 2 do
b=d:byte(i)
d2=d:sub(i,i)
i=i+1
@ -41,13 +43,15 @@ CB=function(d,i,d2,x,y)
Ci=1
end
else
if b>=128then
x=d:byte(i)i=i+1
y=(d:byte(i)+((x%2)*256))i=i+1
d2=Cs[b]:sub(y+1,y+3+math.floor(x/2))
if b >= 128 then
x = d:byte(i)
i = i + 1
y=d:byte(i) + ((x % 2) * 256)
i = i + 1
d2=Cs[b]:sub(y + 1,y + 3 + math.floor(x / 2))
end
Cs[Cw]=Cs[Cw]..d2
if #Cs[Cw]>=512then
if #Cs[Cw]>=512 then
CP(Cs[Cw])
Cw=((Cw-127)%Cbu)+128
Cs[Cw]=""
@ -56,9 +60,9 @@ CB=function(d,i,d2,x,y)
end
return i
end
CD=function(d)
Cb=Cb..d
Cb=Cb:sub(CB(Cb))
CD = function(d)
Cb = Cb .. d
Cb = Cb:sub(CB(Cb))
end
CD(io.read("*a")) -- XX
--D.remove("init-bdivide.lua")--

View File

@ -10,11 +10,8 @@ local src = io.open("com2/bundiv.lua", "r")
while true do
local line = src:read()
if not line then
src:close()
io.write("--[[")
io.flush()
os.execute("cat com2/code.tar.bd")
io.write("]]")
src:close()
return
end
local endix = line:sub(#line-1,#line)

View File

@ -1,11 +1,10 @@
-- KOSNEO inst.
-- This is released into the public domain.
-- No warranty is provided, implied or otherwise.
local C, O, G, D = component, computer
if not C then
error("Copy to init.lua on a blank disk. Thank you!")
error("Copy as init.lua to a blank disk, then remove all other disks and reboot. Thank you!")
end
local sa = C.list("screen", true)()
@ -28,16 +27,12 @@ end
D = C.proxy(O.getBootAddress())
local tF = nil
local tFN = "Starting..."
local tFSR = 0
local tW = 0
local tFN,tFSR,tW,tF="Starting...",0,0
local convoct
convoct = function (oct)
local function tO(oct)
local v = oct:byte(#oct) - 0x30
if #oct > 1 then
return (convoct(oct:sub(1, #oct - 1)) * 8) + v
return (tO(oct:sub(1, #oct - 1)) * 8) + v
end
return v
end
@ -56,7 +51,7 @@ local function tA(s)
end
else
tFN = s:sub(1, 100):gsub("\x00", "")
local sz = convoct(s:sub(125, 135))
local sz = tO(s:sub(125, 135))
if tFN:sub(1, 5) ~= "code/" then
tW = math.ceil(sz / 512)
else
@ -79,12 +74,8 @@ local function tA(s)
end
end
local dieCB = function () end
local sN = 0
local sC = 0
local function sector(n)
local sN,sC,dieCB,sector=0,0
function sector(n)
tA(n)
sN = sN + 1
if G then

View File

@ -14,6 +14,7 @@ while true do
end
df:close()
local df = io.open("code.tar", "rb")
f:write("dieCB = function () end")
f:write("sC = " .. sc .. "\n")
while true do
local d = df:read(512)

View File

@ -7,7 +7,10 @@ rm code.tar
# Hey, look behind you, there's nothing to see here.
# ... ok, are they seriously all named "Mann"?
tar --owner=gray:0 --group=mann:0 -cf code.tar code
lua heroes.lua `wc -c code.tar` > inst.lua
lua heroes.lua `wc -c code.tar` | lua bonecrunch.lua > inst.lua
echo -n "--[[" >> inst.lua
cat com2/code.tar.bd >> inst.lua
echo -n "]]" >> inst.lua
stat repobuild/data/app-claw/local.lua && rm -rf repobuild
mkdir repobuild