cleaned up modules and exec

This commit is contained in:
Izaya 2017-10-14 08:11:01 +11:00
parent 249b4c4614
commit ac27dc473c
7 changed files with 0 additions and 476 deletions

View File

@ -1,49 +0,0 @@
local tA = {...}
local si = tA[1]
spawn("lua shell",function()
os.setenv("sI",si)
_ENV = shutil.genenv()
coroutine.yield()
log(pcall(login))
print(_VERSION)
while true do
write((os.getenv("PWD") or "").."> ")
local inp=readln()
if not inp then break end
if inp:sub(1,1) == "!" then
local pth = os.getenv("PATH") or "."
local s,ptt = inp:sub(2), {}
for w in s:gmatch("%S+") do table.insert(ptt,w) end
local prg = table.remove(ptt,1)
for d in pth:gmatch("[^:]+") do
_,lex = pcall(fs.exists,d.."/"..prg..".lua")
_,nex = pcall(fs.exists,d.."/"..prg)
if lex then
run(d.."/"..prg..".lua",table.unpack(ptt))
break
elseif nex then
run(d.."/"..prg,table.unpack(ptt))
break
end
end
elseif inp:sub(1,1) == "$" then
local s,ptt = inp:sub(2), {}
for w in s:gmatch("%S+") do table.insert(ptt,w) end
local prg = table.remove(ptt,1)
local r={pcall(_ENV[prg],table.unpack(ptt))}
if r[1] == true then
table.remove(r,1)
end
print(table.unpack(r))
else
if inp:sub(1,1) == "=" then
inp="return "..inp:sub(2)
end
local r={pcall(load(inp,"shell","bt",_ENV))}
if r[1] == true then
table.remove(r,1)
end
print(table.unpack(r))
end
end
end)

View File

@ -1,27 +0,0 @@
local tA = {...}
local nport = tonumber(tA[1])
local fpath = tostring(tA[2])
for m in component.list("modem") do
log("[nbsrv] opening port on "..m)
component.invoke(m,"open",nport)
end
local f=io.open(fpath,"rb")
local nbdata = f:read("*a")
f:close()
spawn("nbsrv: "..tostring(nport)..","..fpath,function() log(xpcall(function()
while true do
local _, laddress, raddress, port, _, payload = event.pull("modem_message")
if port == nport and type(payload) == "string" then
if payload:len() == 36 then
local sraddress,spayload = raddress:sub(1,8),payload:sub(1,8)
log("[nbsrv] request from "..sraddress.."/"..spayload.." on port "..tostring(port))
for i = 1, nbdata:len(), 2048 do
component.invoke(laddress,"send",raddress,port,nbdata:sub(i,i+2047))
end
component.invoke(laddress,"send",raddress,port,".")
log("[nbsrv] served request from "..sraddress.."/"..spayload)
end
end
end
end)) end)
log("[nbsrv] nbsrv started.")

View File

@ -1,67 +0,0 @@
function skex(s)
local c,cs,cT,lT,lP="","",{},{},1
local function lf(s)
local f=io.open(s,"rb")
c=f:read("*a")
f:close()
end
local function wf(s)
local f,c=io.open(s,"wb")
for k,v in ipairs(lT) do f:write(v.."\n") end
f:close()
end
if s then
lf(s)
for l in c:gmatch("[^\n]+") do lT[#lT+1]=l end
end
while true do
cs=io.read()
cT={}
for w in cs:gmatch("%S+") do cT[#cT+1]=w end
if cT[1] == "q" then break
elseif cT[1] == "l" then
for i = (tonumber(cT[2]) or 1), (tonumber(cT[3]) or #lT) do
if lT[i] then
print(tostring(i).."\t"..(lT[i] or ""))
end
end
elseif cT[1] == "a" or cT[1] == "i" or cT[1] == "s" then
if tonumber(cT[2]) then lP=tonumber(cT[2]) end
if cT[1] == "s" then for i = 1,tonumber(cT[3]) do table.remove(lT,i+(tonumber(cT[2])-1)) end end
if cT[1] == "a" then lP=lP+1 end
while true do
cs=io.read()
if cs~="." then
table.insert(lT,lP,cs)
lP=lP+1
else break end
end
elseif cT[1] == "f" then
s=cT[2] or s
print(s)
elseif cT[1] == "e" then
c=""
for k,v in ipairs(lT) do c=c..v.."\n" end
print(pcall(load(c)))
elseif cT[1] == "r" then
s=cT[2] or s
wf(s)
elseif cT[1] == "w" then
s=cT[2] or s
wf(s)
elseif cT[1] == "d" then
for i = 1, tonumber(cT[3])-tonumber(cT[2]) do
table.remove(lT,cT[2])
end
elseif cT[1] == "p" then
lP=tonumber(cT[2]) or lP
print(lP)
elseif cs:sub(1,1) == "!" then
c=""
for k,v in ipairs(lT) do c=c..v.."\n" end
print(pcall(load(cs:sub(2))))
else
print("?")
end
end
end

View File

@ -1,97 +0,0 @@
if component then
function log(...)
for k,v in ipairs({...}) do
component.invoke(component.list("ocemu")(),"log",v)
end
end
print=log
else log = print
end
do -- so local works
-- task format:
-- {
-- ["n"] = "name",
-- ["c"] = coroutine of task,
-- ["e"] = { table, of, environment, variables },
-- ["p"] = parent pid,
-- ["u"] = user ID,
-- ["ep"]= event queue pointer
-- }
local tT,nP,rg,eq,p = {},1,_G,{},1 -- taskTable,nextPid,real _G,event queue
_G.cT,sbt,C,T = 0,{},coroutine,table -- currentTask,sandboxTable
function _G.spawn(n,f,e)
tT[nP] = {}
sbt[nP] = {}
setmetatable(sbt[nP],{__index=_G})
_ENV = sbt[nP]
tT[nP].c = coroutine.create(f)
_ENV = rg
tT[nP].n = n
tT[nP].p = cT or -1
if tT[cT] then
tT[nP].u,tT[nP].ep,tT[nP].e = tT[cT].u,tT[cT].ep,e or tT[cT].e or {}
else
tT[nP].u,tT[nP].ep,tT[nP].e = 0,1,{}
end
nP = nP + 1
end
function _G.sched()
_G.sched = nil
while #tT > 0 do
eq[#eq+1]={computer.pullSignal(p)} -- add the latest event to the eq
if #eq > 16 then
table.remove(eq,1) -- remove the earliest if the eq is full
for pid,proc in ipairs(tT) do
if proc.ep > 1 then
proc.ep = proc.ep - 1 -- decrement pointers for tasks to keep them on the same ones
end
end
end
for pid,proc in ipairs(tT) do
if coroutine.status(proc.c) == "dead" then
tT[pid] = nil
else
cT=pid
sbt[pid].ev = eq[#eq] -- make an ev for MultICE compat
coroutine.resume(proc.c)
end
end
end
end
_G.event = {}
function event.get() -- get the next event in the queue, or nil
if eq[tT[cT].ep] then
tT[cT].ep = tT[cT].ep + 1
if tT[cT].ep > 17 then
tT[cT].ep = 17
end
return eq[tT[cT].ep - 1]
end
end
function event.pull(t) -- return or wait for the next event, optionally with the first param matching t
while true do
local e = event.get()
if e then
if t then
if e[1] == t then
return table.unpack(e)
end
else
return table.unpack(e)
end
end
coroutine.yield()
end
end
event.push = computer.pushSignal
function os.getenv(k)
if tT[cT] then
return tT[cT].e[k]
end
end
function os.setenv(k,v)
if tT[cT] then
tT[cT].e[k] = v
end
end
end

View File

@ -1,27 +0,0 @@
net = {}
net.id = computer.address():sub(1,8)
net.vlan = 1
net.np = 4096
net.tm = {}
function net.send(id,po,msg) -- id, port, message
event.push("sendmsg",id,po,msg)
end
spawn("network daemon",function ()
for a,t in component.list("modem") do
table.insert(net.tm,component.proxy(a))
component.proxy(a).open(net.vlan)
end
while true do
local ev = {event.pull()}
if ev[1] == "sendmsg" then
local eT = ev
for k,v in ipairs(net.tm) do
v.broadcast(net.vlan,net.np,eT[2],net.id,eT[3],eT[4])
end
elseif ev[1] == "modem_message" then
if ev[7] == net.id then
event.push("net_msg",ev[8],ev[9],ev[10])
end
end
end
end)

View File

@ -1,48 +0,0 @@
function tty(gA,sA,sI,fg,bg) -- gpuAddress,screenAddress,sessionID,foreground,background
local gP,cx,cy,bg,fg = component.proxy(gA),1,1,bg or 0x000000, fg or 0xffffff -- basic setup from here
gP.bind(sA)
local sx, sy = gP.getResolution()
gP.setResolution(sx,sy)
gP.setForeground(fg)
gP.setBackground(bg)
gP.fill(1,1,sx,sy," ")
gP.setDepth(gp.maxDepth())
local function cv() -- check cursor position
if cx > sx then cx,cy=1,cy+1 end
if cx < 1 then cx,cy=sx,cy-1 end
if cy < 1 then cx,cy=1,1 end
if cy > sy then gP.copy(1,2,sx,sy-1,0,-1) gP.fill(1,sy,sx,1," ") cx,cy=1,sy end
end
local function ic(s)
local cc,fg,bg=gP.get(cx,cy)
if s then fG,bG = bg,fg else fG,bG = fg,bg end
gP.setForeground(bG)
gP.setBackground(fG)
gP.set(cx,cy,cc)
gP.setForeground(fG)
gP.setBackground(bG)
end
local function wl(str) -- write line
for c in str:gmatch(".") do
if c == "\n" then cx,cy=1,cy+1
elseif c == "\r" then cx=1
elseif c == "\f" then cx=1 cy=1 gP.fill(1, 1, sx, sy, " ")
elseif c == "\t" then cx=(cx+8-((cx+8)%8))+1
elseif c == "\127" or c == "\008" then cx=cx-1 gP.set(cx,cy," ")
else gP.set(cx,cy,c) cx=cx+1
end cv()
end
end
spawn("tty",function() log(pcall(function() -- spawns the listener
local csi = os.getenv("sI")
log(csi)
while true do
_,si,str=event.pull("display")
if si == csi then
wl(str)
ic()
end
end
end)) end)
end

View File

@ -1,161 +0,0 @@
tape = {}
tape.types = {}
tape.types["!"] = "executable"
tape.types["t"] = "tar"
tape.types["d"] = "data"
tape.types["D"] = "directory"
tape.types["f"] = "file"
function tape.records(addr) -- { { type, start, end, length } }
local tp,ct = {},0
addr = addr or component.list("tape_drive")()
local t = component.proxy(addr)
local function read(n)
n=n or 1
ct=ct+n
return t.read(n)
end
local function seek(n)
n=n or 1
ct=ct+n
return t.seek(n)
end
while true do
local ty = read()
if not tape.types[ty] then break end
tp[#tp+1] = {ty,ct+8} -- type, start,
local ln = tonumber(read(8)) or 0
tp[#tp][#tp[#tp]+1] = ct+ln -- end
tp[#tp][#tp[#tp]+1] = ln -- length
seek(ln)
end
return tp
end
function tape.precords(addr)
tape.rewind(addr)
local pt = tape.records(addr)
for k,v in ipairs(pt) do
print(k.."\t"..v[1].."\t"..v[2].."\t"..v[3].."\t"..v[4])
end
end
function tape.drecord(n,addr)
addr = addr or component.list("tape_drive")()
tape.rewind(addr)
local pt = tape.records(addr)
tape.rewind(addr)
local t = component.proxy(addr)
print(pt[n][2]-9)
t.seek(pt[n][2]-9)
t.write("\0")
tape.rewind()
end
function tape.wrecord(c,ty,s,addr)
ty = ty or "!"
addr = addr or component.list("tape_drive")()
local t = component.proxy(addr)
if s then
t.seek(-math.huge)
t.seek(s)
end
local fh=ty:sub(1,1)..string.format("%8d",c:len())
print("Header: "..fh)
t.write(fh)
t.write(c)
end
function tape.rrecord(pn,addr)
addr = addr or component.list("tape_drive")()
pn = pn or 1
local t = component.proxy(addr)
local pP = t.seek(-math.huge)
local pt = tape.records(addr)
t.seek(-math.huge)
local pstart,plen = pt[pn][2],pt[pn][4]
t.seek(pstart)
C=t.read(plen)
t.seek(-math.huge)
t.seek(pP)
return C
end
function tape.nrecord(addr)
addr = addr or component.list("tape_drive")()
local t = component.proxy(addr)
local pP = t.seek(-math.huge)
local pt = tape.records(addr)
t.seek(-math.huge)
t.seek(pP)
return pt[#pt][3]
end
function tape.rewind(addr)
addr = addr or component.list("tape_drive")()
local t = component.proxy(addr)
t.seek(-math.huge)
end
function tape.parsefile(str)
return str:sub(1,64):gsub("\0",""), str:sub(65)
end
function tape.unparsefile(fname,str)
local nul = "\0"
nul=nul:rep(64-#fname)
fname=nul..fname
return fname..str
end
function tape.mkdir(str,addr)
tape.wrecord(str,"D",tape.nrecord(),addr)
end
function tape.wfile(fname,fcont,addr)
tape.wrecord(str,"f",tape.nrecord(),addr)
end
function tape.wtree(addr)
local ft = {""}
local rft = {}
addr = addr or component.list("tape_drive")()
local t = component.proxy(addr)
for _,d in ipairs(ft) do
local ls = fs.list(d)
for k,v in ipairs(ls) do
v=d..v
if fs.isdir(v) then
ft[#ft+1] = v
else
rft[#rft+1] = v
end
end
end
tape.rewind(addr)
t.seek(tape.nrecord(addr))
for k,v in ipairs(ft) do
if v ~= "" then
print(v)
local fh="D"..string.format("%8d",v:len())
t.write(fh)
t.write(v)
end
end
for k,v in ipairs(rft) do
print(v)
local f=io.open(v,"rb")
local fc = f:read("*a")
local fc = tape.unparsefile(v,fc)
f:close()
local fh="f"..string.format("%8d",fc:len())
t.write(fh)
t.write(fc)
end
end
function tape.rtree(pref,addr)
tape.rewind()
local pt = tape.records()
for k,v in ipairs(pt) do
if v[1] == "D" then
print(tostring(k).."\t"..v[1].."\t"..pref..tape.rrecord(k))
fs.mkdir(pref..tape.rrecord(k))
elseif v[1] == "f" then
local fn,fc = tape.parsefile(tape.rrecord(k))
print(tostring(k).."\t"..v[1].."\t"..pref..fn)
local f=io.open(pref..fn,"wb")
f:write(fc)
f:close()
end
computer.beep()
coroutine.yield()
end
end