From 1834eadb298db6c7a8bf9e028f6d99713c1e342b Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sun, 27 Aug 2017 03:52:09 +1000 Subject: [PATCH] made skex2 use the previous include-external-files feature so you can run it outside the kernel. --- build.cfg | 2 +- exec/skex2.lua | 106 +++++++++++++++++++++++++++++++++ modules/applications/skex2.lua | 98 ------------------------------ 3 files changed, 107 insertions(+), 99 deletions(-) create mode 100644 exec/skex2.lua delete mode 100644 modules/applications/skex2.lua diff --git a/build.cfg b/build.cfg index d92d703..3205c5b 100755 --- a/build.cfg +++ b/build.cfg @@ -15,7 +15,7 @@ modules/lib/sha256.lua modules/net/net-ext.lua modules/applications/luash.lua modules/applications/genkernel.lua -modules/applications/skex2.lua +fwrap skex exec/skex2.lua modules/util/tape.lua modules/util/fs-automount.lua modules/setup.lua diff --git a/exec/skex2.lua b/exec/skex2.lua new file mode 100644 index 0000000..691985a --- /dev/null +++ b/exec/skex2.lua @@ -0,0 +1,106 @@ +local tA = {...} +local ft, p, fp, ct, il, it, c, C = {}, 1, fp or tA[1] or "", {}, "", {}, "", C -- file table, pointer, filename, command table, input line, input table, command, content +function ct.readfile(fp,rp) + if not fp then return end + if not rp then ft = {} end + local f=io.open(fp,"rb") + if f then + C=f:read("*a") + f:close() + for l in C:gmatch("[^\n]+") do + ft[#ft+1] = l + end + end +end +function ct.writefile(nfp) + if not nfp then nfp = fp end + print(nfp) + f=io.open(nfp,"wb") + if f then + for k,v in ipairs(ft) do + print(v) + f:write(v.."\n") + end + coroutine.yield() + f:close() + coroutine.yield() + print(f.b) + end +end +function ct.list(s,e) + s,e = s or 1, e or #ft + for i = s,e do + if ft[i] then + print(tostring(i).."\t"..ft[i]) + end + end +end +function ct.sp(np) + if np then + if np > #ft then + np = #ft + elseif np < 1 then + np = 0 + end + p=np + end +end +function ct.pointer(np) + ct.sp(np) + print(p) +end +function ct.insert(np) + ct.sp(np) + while true do + io.write(tostring(p).."\t") + local l=io.read() + if l == "." then break end + table.insert(ft,p,l) + p=p+1 + end +end +function ct.append(np) + if np then np=np+1 end + ct.insert(np) +end +function ct.substitute(np) + ct.sp(np) + table.remove(ft,p) + ct.insert(np) +end +function ct.delete(np) + ct.sp(np) + table.remove(ft,p) +end +function ct.filename(np) + if np then fp = np end + print(fp) +end + +ct.o = ct.readfile +ct.w = ct.writefile +ct.l = ct.list +ct.p = ct.pointer +ct.i = ct.insert +ct.a = ct.append +ct.s = ct.substitute +ct.d = ct.delete +ct.f = ct.filename + +ct.readfile(fp) + +while true do + io.write("skex2> ") + il,it=io.read(),{} + for w in il:gmatch("%S+") do + it[#it+1] = w + end + c=table.remove(it,1) + if c == "quit" or c == "q" then + break + elseif c:sub(1,1) == "!" then + print(pcall(load(c:sub(2)))) + elseif ct[c] ~= nil then + ct[c](table.unpack(it)) + end +end diff --git a/modules/applications/skex2.lua b/modules/applications/skex2.lua deleted file mode 100644 index 4cf2c1b..0000000 --- a/modules/applications/skex2.lua +++ /dev/null @@ -1,98 +0,0 @@ -function skex2(fp) - local ft, p, fp, ct, il, it, c, C = {}, 1, fp or "", {}, "", {}, "", C -- file table, pointer, filename, command table, input line, input table, command, content - function ct.readfile(fp,rp) - if not fp then return end - if not rp then ft = {} end - local f=io.open(fp,"rb") - if f then - C=f:read("*a") - f:close() - for l in C:gmatch("[^\n]+") do - ft[#ft+1] = l - end - end - end - function ct.writefile(nfp) - if not nfp then nfp = fp end - print(nfp) - f=io.open(nfp,"wb") - if f then - for k,v in ipairs(ft) do - f:write(v.."\n") - end - f:close() - end - end - function ct.list(s,e) - s,e = s or 1, e or #ft - for i = s,e do - if ft[i] then - print(tostring(i).."\t"..ft[i]) - end - end - end - function ct.sp(np) - if np then p=(tonumber(np)%#ft)+1 end - end - function ct.pointer(np) - ct.sp(np) - print(p) - end - function ct.insert(np) - ct.sp(np) - while true do - local l=io.read() - if l == "." then break end - table.insert(ft,p,l) - p=p+1 - end - end - function ct.append(np) - if np then np=np+1 end - ct.insert(np) - end - function ct.substitute(np) - ct.sp(np) - table.remove(ft,p) - ct.insert(np) - end - function ct.delete(np) - ct.sp(np) - table.remove(ft,p) - end - function ct.filename(np) - if np then fp = np end - print(fp) - end - - ct.o = ct.readfile - ct.w = ct.writefile - ct.l = ct.list - ct.p = ct.pointer - ct.i = ct.insert - ct.a = ct.append - ct.s = ct.substitute - ct.d = ct.delete - ct.f = ct.filename - - ct.readfile(fp) - - while true do - io.write("skex2> ") - il,it=io.read(),{} - for w in il:gmatch("%S+") do - it[#it+1] = w - end - c=table.remove(it,1) - if c == "quit" or c == "q" then - break - elseif c:sub(1,1) == "!" then - print(pcall(load(c:sub(2)))) - elseif ct[c] ~= nil then - ct[c](table.unpack(it)) - end - end -end -if not skex then - skex = skex2 -end