1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-26 04:57:24 -05:00

replaced the editor with skex2 because it's infinitely better and works on PsychOS2 now

This commit is contained in:
XeonSquared 2019-07-28 19:53:25 +10:00
parent be8ba0a40b
commit aa570fcc4e

View File

@ -1,76 +1,108 @@
local tA = {...} local tA = {...}
local fn = tA[1] 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
local b,C,p = {},{},1 function ct.readfile(fp,rp)
local function sC() if not fp then return end
if p > #b then if not rp then ft = {} end
p = #b local f=io.open(fp,"rb")
end if f then
if p < 1 then C=f:read("*a")
p = 1 f:close()
for l in C:gmatch("[^\n]+") do
ft[#ft+1] = l
end
end end
end end
function C.i() function ct.writefile(nfp)
p=p-1 if not nfp then nfp = fp end
sC() 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(string.format("%4d\t %s",i,ft[i]))
end
end
end
function ct.sp(np)
np=tonumber(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(string.format("%4d\t %s",p,ft[p]))
end
function ct.insert(np)
ct.sp(np)
while true do while true do
io.write(tostring(p).."] ") io.write(string.format("%4d\t ",p))
l = io.read() local l=io.read()
if l == "." then break end if l == "." then break end
table.insert(b,p,l) table.insert(ft,p,l)
p=p+1 p=p+1
end end
end end
function C.l(s,e) function ct.append(np)
for i = s or 1, e or #b do ct.sp(np)
print(string.format("%4d\t %s",i,b[i]))
end
end
function C.a()
p=p+1 p=p+1
C.i() ct.insert()
end end
function C.p(n) function ct.substitute(np)
p=tonumber(n) or p ct.sp(np)
sC() table.remove(ft,p)
ct.insert(np)
end end
function C.d(n) function ct.delete(np)
n=tonumber(n) or 1 ct.sp(np)
for i = 1, n do table.remove(ft,p)
print(table.remove(b,p,i))
end
end end
function C.r(f) function ct.filename(np)
local f = fs.open(f) if np then fp = np end
if f then print(fp)
for l in f:read("*a"):gmatch("[^\n]+") do
table.insert(b,p,l)
p=p+1
end
f:close()
end
end
function C.w(f)
local f=fs.open(f,"wb")
if f then
for _,l in ipairs(b) do
f:write(l.."\n")
end
f:close()
end
end
if fn then
C.r(fn)
end 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 while true do
io.write("ed> ") io.write("skex2> ")
local l,c = io.read(),{} il,it=io.read(),{}
for w in l:gmatch("%S+") do for w in il:gmatch("%S+") do
c[#c+1] = w it[#it+1] = w
end end
local e=table.remove(c,1) c=table.remove(it,1)
if e == "q" then if c == "quit" or c == "q" then
break break
elseif C[e] then elseif c:sub(1,1) == "!" then
C[e](table.unpack(c)) print(pcall(load(c:sub(2))))
elseif ct[c] ~= nil then
ct[c](table.unpack(it))
end end
end end