Merge pull request #12 from XeonSquared/dev

more merging from dev
This commit is contained in:
Izaya 2017-06-13 14:58:49 +00:00 committed by GitHub
commit 3e98d1aaf6
38 changed files with 470 additions and 88 deletions

View File

@ -1,5 +1,5 @@
optimise no optimise no
listmods no listmods yes
test no test yes
log no log yes
opath kernel.lua opath kernel.lua

View File

@ -77,13 +77,13 @@ print(tostring(#tm).." modules loaded.\n")
-- Generate source -- Generate source
print("Generating source") print("Generating source")
if cfg.listmods == "yes" then if cfg.listmods == "yes" then
ss=ss.."modules,_OSVERSION={" ss=ss.."_MOD,_OSVERSION,_BD={"
for k,v in ipairs(tm) do for k,v in ipairs(tm) do
ss=ss..'"'..v..'",' ss=ss..'"'..v..'",'
end end
ss=ss.."}," ss=ss.."},"
if _OSVERSION == nil then if _OSVERSION == nil then
ss=ss..'"MultICE '..io.popen("git rev-parse HEAD"):read("*a"):sub(1,7)..'"\n' ss=ss..'"MultICE '..io.popen("git rev-parse HEAD"):read("*a"):sub(1,7)..'","'..os.date("%Y/%m/%d %H:%M %z")..'"\n'
else else
ss=ss..'"MultICE DR0"\n' ss=ss..'"MultICE DR0"\n'
end end

View File

@ -1,14 +1,11 @@
base/header.lua base/header.lua
drivers/dterm.lua
library/print.lua library/print.lua
drivers/keyboard.lua
library/net.lua
library/fs-min.lua library/fs-min.lua
library/fs-std.lua library/fs-std.lua
library/fs-ext.lua library/fs-ext.lua
library/fs-util.lua
util/fs-automount.lua util/fs-automount.lua
util/sinit.lua
applications/shutil.lua applications/shutil.lua
applications/evproxy-srv.lua
applications/evproxy-client.lua
applications/luash.lua applications/luash.lua
base/footer.lua base/footer.lua

View File

@ -0,0 +1,25 @@
base/loadlin.lua
base/header.lua
debug/ocemu-display.lua
debug/ocemu-heartbeat.lua
library/print.lua
library/fs-min.lua
library/fs-std.lua
library/fs-util.lua
util/fs-automount.lua
drivers/tty.lua
drivers/kbd.lua
util/autogpu.lua
library/net.lua
net/ping.lua
library/base64.lua
library/fs-ext.lua
library/readline.lua
applications/nshd.lua
applications/nshc.lua
applications/shutil.lua
applications/skex2.lua
applications/luash.lua
applications/ircbridge.lua
applications/autoluash.lua
base/footer.lua

View File

@ -0,0 +1,23 @@
base/loadlin.lua
base/header.lua
library/print.lua
library/fs-min.lua
library/fs-std.lua
library/fs-util.lua
util/fs-automount.lua
drivers/tty.lua
drivers/kbd.lua
util/autogpu.lua
library/net.lua
net/ping.lua
library/base64.lua
library/fs-ext.lua
library/readline.lua
applications/nshd.lua
applications/nshc.lua
applications/shutil.lua
applications/skex2.lua
applications/luash.lua
applications/ircbridge.lua
applications/autoluash.lua
base/footer.lua

24
configs/everything.cfg Normal file
View File

@ -0,0 +1,24 @@
base/loadlin.lua
base/header.lua
library/print.lua
library/fs-min.lua
library/fs-std.lua
library/fs-util.lua
util/fs-automount.lua
drivers/tty.lua
drivers/kbd.lua
util/autogpu.lua
library/net.lua
net/ping.lua
library/base64.lua
library/fs-ext.lua
library/readline.lua
applications/nshd.lua
applications/nshc.lua
applications/shutil.lua
applications/skex2.lua
applications/luash.lua
applications/ircbridge.lua
util/sinit.lua
applications/autoluash.lua
base/footer.lua

13
configs/headless.cfg Normal file
View File

@ -0,0 +1,13 @@
base/header.lua
library/print.lua
library/net.lua
library/readline.lua
applications/nshd.lua
applications/luash.lua
applications/shutil.lua
library/fs-min.lua
library/fs-std.lua
library/fs-ext.lua
util/fs-automount-min.lua
util/loadeeprom.lua
base/footer.lua

View File

@ -1,10 +1,12 @@
base/header.lua base/header.lua
drivers/dterm.lua
library/print.lua library/print.lua
drivers/keyboard.lua drivers/tty.lua
drivers/kbd.lua
util/autogpu.lua
library/net.lua library/net.lua
applications/shutil.lua library/readline.lua
applications/evproxy-client.lua applications/nshc.lua
applications/luash.lua applications/luash.lua
applications/autoluash.lua
util/loadeeprom.lua util/loadeeprom.lua
base/footer.lua base/footer.lua

View File

@ -1,7 +1,7 @@
# Building MultICE # Building MultICE
MultICE uses a relatively simple build system. It has been tested on Arch Linux, Debian Linux, OpenOS and Plan9k. MultICE uses a relatively simple build system. It has been tested on Arch Linux, Debian Linux, OpenOS and Plan9k.
## 1. Choose modules. ## 1. Choose modules.
The system is made out of modules from the `modules/` directory. When you run the build script, it assembles them, and optionally optomises the code for space. The system is made out of modules from the `modules/` directory. When you run the build script, it assembles them, and optionally optimises the code for space.
There are a number of preconfigured module sets in the `config/` directory, and you can of course you can write your own. There are a number of preconfigured module sets in the `config/` directory, and you can of course you can write your own.
The build system defaults to a file called `modules.cfg` in the current directory. You can specify a config file using `--modconfig=file.cfg`. The build system defaults to a file called `modules.cfg` in the current directory. You can specify a config file using `--modconfig=file.cfg`.

57
doc/skex2.md Normal file
View File

@ -0,0 +1,57 @@
# skex2
## interactive line editor
skex2 is a simple but functional line editor for MultICE.
### invocation
To start skex2, simply run skex(filename) from the Lua prompt.
### usage
Generally, commands and arguments are entered in the form of `command argument1 argument2 argument3` with the exception of inline execution, which is in the form of `!lua code here`.
If skex does not understand what you mean, it will output a line with a question mark.
### commands
#### q - quit skex2
Exits the program.
#### l \[start\] \[end\] - list contents
Output the lines from start to end, inclusive.
#### f \[filename\] - set the filename
This sets the filename to be used for I/O, or prints the current one.
#### r \[filename\] - load file
Reads from *filename* or the current set via **f**
#### w \[filename\] - write to file
Writes to *filename* or the current set via **f**
#### p \[line\] - print or set current line
As skex2 is a line editor, your pointer is a line, and this either prints the current one or sets a new one.
#### a \[line\] - append to buffer
Appends lines after the current line or *line* until a line with only . is entered.
#### i \[line\] - insert into buffer
Inserts lines before the current line or *line* until a line with only . is entered.
#### s \[line\] - replace line
Removes the current line or *line* and enters insert mode
#### e - executes the contents of the buffer
Basically converts it into one big string and loads it.

View File

@ -1,18 +1,20 @@
base/header.lua base/header.lua
drivers/dterm.lua
library/print.lua library/print.lua
drivers/keyboard.lua
library/net.lua
library/fs-min.lua library/fs-min.lua
library/fs-std.lua library/fs-std.lua
library/fs-ext.lua
library/fs-util.lua library/fs-util.lua
library/base64.lua
util/fs-automount.lua util/fs-automount.lua
net/ping.lua drivers/tty.lua
drivers/kbd.lua
util/autogpu.lua
library/net.lua
library/fs-ext.lua
library/readline.lua
library/base64.lua
applications/nshd.lua
applications/nshc.lua
applications/shutil.lua applications/shutil.lua
applications/evproxy-srv.lua
applications/evproxy-client.lua
applications/ircbridge.lua
applications/luash.lua applications/luash.lua
applications/ircbridge.lua
applications/autoluash.lua
base/footer.lua base/footer.lua

View File

@ -0,0 +1 @@
luash()

View File

@ -1,17 +0,0 @@
function nshc(evPP,nid)
write("\f")
while true do
if ev[1] == "net_msg" then
local V,msg=false,tostring(ev[4])
if ev[3] == evPP and ev[2] == nid then
if msg:sub(1,3) == "dis" then
h("display",msg:sub(4))
end
end
elseif ev[1] == "key_down" then
ns(nid,evPP,"key"..tostring(ev[3]))
end
C.yield()
end
end

View File

@ -1,20 +0,0 @@
evPP,tEPs="nsh",{}
s("netsh daemon",function()
while true do
if ev[1] == "net_msg" then
local V,msg=false,tostring(ev[4])
for k,v in ipairs(tEPs) do if ev[2] == v then V=true end end
if ev[3] == evPP and V then
if msg:sub(1,3) == "key" then
h("key_down",ev[2],tonumber(msg:sub(4)),0)
end
end
elseif ev[1] == "display" then
for k,v in ipairs(tEPs) do
ns(v,evPP,"dis"..tostring(ev[2]))
end
end
C.yield()
end
end)

View File

@ -26,7 +26,7 @@ function ircb(h,p,n) -- host, port
if t and f and p and ms then if t and f and p and ms then
t,f,p,ms = ub64(t),n..":"..ub64(f),ub64(p),ub64(ms) t,f,p,ms = ub64(t),n..":"..ub64(f),ub64(p),ub64(ms)
for k,v in ipairs(tM) do for k,v in ipairs(tM) do
v.broadcast(nP,t,f,p,ms) v.broadcast(nVL,nP,t,f,p,ms)
end end
end end
else else

View File

@ -29,7 +29,7 @@ function ircb(h,p,n) -- host, port
if t and f and p and ms then if t and f and p and ms then
t,f,p,ms = ub64(t),n..":"..ub64(f),ub64(p),ub64(ms) t,f,p,ms = ub64(t),n..":"..ub64(f),ub64(p),ub64(ms)
for k,v in ipairs(tM) do for k,v in ipairs(tM) do
v.broadcast(nP,t,f,p,ms) v.broadcast(nVL,nP,t,f,p,ms)
end end
end end
else else

View File

@ -1,7 +1,13 @@
function luash(si)
s("lua shell",function() s("lua shell",function()
if _OSVERSION and _BD then
write(_OSVERSION.." (built at ".._BD..")\t")
end
print(tostring(computer.freeMemory()/1024).."K free.",_G.motd)
print(_VERSION) print(_VERSION)
while true do while true do
h("display","> ") write("> ")
print(pcall(load(readln()))) print(pcall(load(readln())))
end end
end) end,si)
end

View File

@ -0,0 +1,30 @@
function nshc_w(evPP,nid)
local sI = E().sI or 1
while true do
if ev[1] == "net_msg" then
local V,msg=false,tostring(ev[4])
if ev[3] == evPP and ev[2] == nid then
if msg:sub(1,3) == "dis" then
write(msg:sub(4))
end
end
elseif ev[1] == "key" and ev[2] == sI and ev[3] == 29 and ev[4] == 27 then
break
elseif ev[1] == "key" and ev[2] == sI then
ns(nid,evPP,"key"..tostring(ev[3]))
end
C.yield()
end
ns(nid,evPP,"exit")
end
function nshc(P,nid)
ns(nid,P,"initnsh")
while true do
if ev[1] == "net_msg" and ev[2] == nid and ev[3] == P then
break
end
C.yield()
end
nshc_w(ev[4],nid)
end

View File

@ -0,0 +1,37 @@
function nshd_w(evPP,cA,sI)
s("netsh daemon - "..tostring(sI),function()
while true do
if ev[1] == "net_msg" then
local msg=tostring(ev[4])
if ev[3] == evPP and ev[2] == cA then
if msg:sub(1,3) == "key" then
h("key",tT[cT][3].sI,tonumber(msg:sub(4)),0)
elseif msg == "exit" then pcall(killsession,sI) break
end
end
elseif ev[1] == "display" and ev[3] == tT[cT][3].sI then
ns(cA,evPP,"dis"..tostring(ev[2]))
end
C.yield()
end
end,{["sI"]=sI})
end
function nshd(P)
s("nshd",function()
local Cc=1
while true do
if ev[1] == "net_msg" and ev[3] == P then
if ev[4] == "initnsh" then
nnID="nsh-"..tostring(Cc)
Cc=Cc+1
ns(ev[2],P,nnID)
nshd_w(nnID,ev[2],nnID)
luash({["sI"]=nnID})
print("[nshd]Spawned "..nnID.." for "..tostring(ev[2]))
end
end
C.yield()
end
end,{["sI"]="log"})
end

View File

@ -0,0 +1,10 @@
function pkill(P)
tT[P] = nil
end
function killsession(sI)
for k,v in ipairs(tT) do
if v[3].sI == sI then
pkill(k)
end
end
end

View File

@ -1,10 +1,12 @@
function ps() function ps()
local S=""
for k,v in pairs(tT) do for k,v in pairs(tT) do
print(v[1]) S=S..("pid: "..tostring(k).."\tname: "..tostring(v[1]).."\tenv={")
for l,w in pairs(v[3]) do S=S..(tostring(l).." = "..tostring(w)..", ") end
S=S.."}\n"
end end
return S
end end
function mem() function mem()
print("Total: "..tostring(computer.totalMemory()/1024).."K") return "Total:\t"..tostring(computer.totalMemory()/1024).."K\nFree:\t"..tostring(computer.freeMemory()/1024).."K\nUsed:\t"..tostring((computer.totalMemory()-computer.freeMemory())/1024).."K"
print("Free: "..tostring(computer.freeMemory()/1024).."K")
print("Used: "..tostring((computer.totalMemory()-computer.freeMemory())/1024).."K")
end end

View File

@ -0,0 +1,68 @@
function skex(s)
local c,cs,cT,lT,lP="","",{},{},1
local function lf(s)
local f=fopen(s,"rb")
local nc=fread(f,2048)
while nc ~= nil and nc ~= "" do
c=c..nc
nc=fread(f,2048)
end
end
local function wf(s)
local f,c=fopen(s,"wb"),""
for k,v in ipairs(lT) do fwrite(f,v.."\n") end
fclose(f)
end
if s then
lf(s)
for l in c:gmatch("(.-)\n") do lT[#lT+1]=l end
end
while true do
cs=readln()
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 = (TN(cT[2]) or 1), (TN(cT[3]) or #lT) do
print(TS(i).."\t"..(lT[i] or ""))
end
elseif cT[1] == "a" or cT[1] == "i" or cT[1] == "s" then
if TN(cT[2]) then lP=TN(cT[2]) end
if cT[1] == "s" then for i = 1,TN(cT[3]) do T.remove(lT,i+(TN(cT[2])-1)) end end
if cT[1] == "a" then lP=lP+1 end
while true do
cs=readln()
if cs~="." then
T.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, TN(cT[3])-TN(cT[2]) do
T.remove(lT,cT[2])
end
elseif cT[1] == "p" then
lP=TN(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

@ -5,7 +5,7 @@ while #tT > 0 do
if C.status(v[2])~="dead" then if C.status(v[2])~="dead" then
C.resume(v[2],table.unpack(ev)) C.resume(v[2],table.unpack(ev))
else else
T.remove(tT,k) tT[k] = nil
end end
end end
end end

View File

@ -1,10 +1,14 @@
tT,p,C,T={},1,coroutine,table tT,p,cT,pC,C,T,TS,TN={},1,1,1,coroutine,table,tostring,tonumber
function s(n,f,e) function E()
T.insert(tT,{n,C.create(f),(e or {})}) if tT[cT] ~= nil then return tT[cT][3] end
end end
function l() function l()
return eV return ev
end end
function h(...) function h(...)
computer.pushSignal(...) computer.pushSignal(...)
end end
function s(n,f,e)
tT[pC]={n,C.create(f),(e or E() or {})}
pC=pC+1
end

9
modules/base/loadlin.lua Normal file
View File

@ -0,0 +1,9 @@
if pcall(require,"computer") then
print("OpenOS detected.")
print(os.getenv("_"))
local computer = require "computer"
local process = require "process"
os.execute("cp "..os.getenv("_").." /tmp/init.lua")
computer.setBootAddress(computer.tmpAddress())
computer.shutdown(true)
end

View File

@ -0,0 +1,8 @@
s("ocemu display server",function()
while true do
if ev[1] == "display" then
component.invoke(component.list("ocemu")(),"log",ev[2] or "")
end
C.yield()
end
end)

View File

@ -0,0 +1,11 @@
_G.DEBUG=true
s("heartbeat",function()
while true do
if _G.DEBUG then
component.invoke(component.list("ocemu")(),"log","heartbeat:"..tostring(computer.uptime()))
component.invoke(component.list("ocemu")(),"log",T.unpack(ev))
component.invoke(component.list("ocemu")(),"log","processes:\n"..ps())
end
C.yield()
end
end)

10
modules/drivers/kbd.lua Normal file
View File

@ -0,0 +1,10 @@
function kbd(kA,sI)
s("kbd: "..kA:sub(1,8)..","..tostring(sI),function()
while true do
if ev[1] == "key_down" and ev[2] == kA then
h("key",sI,ev[3],ev[4])
end
C.yield()
end
end)
end

35
modules/drivers/tty.lua Normal file
View File

@ -0,0 +1,35 @@
function tty(gA,sA,sI,fg,bg)
local gP,cx,cy = component.proxy(gA),1,1
gP.bind(sA)
local sx, sy = gP.getResolution()
gP.setResolution(sx,sy)
gP.setForeground(bg or 0xFFFFFF)
gP.setBackground(bg or 0x000000)
gP.fill(1,1,sx,sy," ")
local function cv()
if cx > sx then cx,cy=1,cy+1 end
if cx < 1 then cx,cy=1,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 wl(str)
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+4-((cx+4)%4))+1
elseif c == "\127" then cx=cx-1 gP.set(cx,cy," ")
else gP.set(cx,cy,c) cx=cx+1
end cv()
end
end
s("tty: "..gA:sub(1,8)..","..sA:sub(1,8),function()
while true do
eT = ev
if eT[1] == "display" and eT[3] == sI then
wl(tostring(eT[2]))
end
C.yield()
end
end)
end

View File

@ -0,0 +1,6 @@
function b64(data)
return component.invoke(component.list("data")(),"encode64",data)
end
function ub64(data)
return component.invoke(component.list("data")(),"decode64",data)
end

View File

@ -21,6 +21,14 @@ function fread(h,n)
end end
return false return false
end end
function freadall(f)
local s=""
repeat
c=fread(f,2048)
s=s..c
until c==""
return s
end
function fwrite(h,d) function fwrite(h,d)
if hT[h] then if hT[h] then
return hT[h][1].write(hT[h][2],d) return hT[h][1].write(hT[h][2],d)

View File

@ -17,14 +17,9 @@ function fmove(i,o)
frm(i) frm(i)
end end
function fload(i) function fload(i)
local f,s = fopen(i,"rb"),"" local f = fopen(i,"rb")
if f then if f then
local c=fread(f,math.huge) return load(freadall(f))
repeat
s=s..c
c=fread(f,math.huge)
until c == nil
load(s)
end end
return false return false
end end

View File

@ -1,4 +1,4 @@
tM,nP,nID,nVL = {}, 4096, computer.address(), 1 tM,nP,nID,nVL = {}, 4096, computer.address():sub(1,8), 1
for a,t in component.list("modem") do for a,t in component.list("modem") do
table.insert(tM,component.proxy(a)) table.insert(tM,component.proxy(a))
component.proxy(a).open(nVL) component.proxy(a).open(nVL)

View File

@ -1,10 +1,10 @@
function print(...)
for k,v in pairs({...}) do
h("display",tostring(v).."\n")
end
end
function write(...) function write(...)
for k,v in pairs({...}) do for k,v in pairs({...}) do
h("display",tostring(v)) h("display",tostring(v),E().sI or 1)
end
end
function print(...)
for k,v in pairs({...}) do
write(tostring(v).."\n")
end end
end end

View File

@ -0,0 +1,19 @@
function readln()
local s,si="",E().sI or 1
write("|")
while true do
if ev[1] == "key" and ev[2] == si then
if ev[3] == 13 then
write("\127\n")
C.yield()
return s
elseif ev[3] == 8 then
if s:len()>0 then s=s:sub(1,-2) write("\127\127|") end
elseif ev[3] > 31 and ev[3] < 127 then
s=s..string.char(ev[3]) write("\127"..string.char(ev[3]).."|")
end
end
C.yield()
end
end

2
modules/util/autogpu.lua Normal file
View File

@ -0,0 +1,2 @@
tty(component.list("gpu")(),component.list("screen")(),1)
kbd(component.list("keyboard")(),1)

13
modules/util/sinit.lua Normal file
View File

@ -0,0 +1,13 @@
s("init",function()
local f=fopen("boot:/init.cfg","rb")
write("")
if f then
local c=freadall(f)
for l in c:gmatch("[^\n]+") do
write("[init] "..l..": ")
local pf=fload(l)
print(pcall(pf))
C.yield()
end
end
end)

View File

@ -25,6 +25,8 @@ replacements={
{"%-%-.-\n",""}, {"%-%-.-\n",""},
{"coroutine%.","C."}, {"coroutine%.","C."},
{"table%.","T."}, {"table%.","T."},
{"tostring","TS"},
{"tonumber","TN"},
} }
for k,v in ipairs(replacements) do for k,v in ipairs(replacements) do
while ss:find(v[1]) ~= nil do while ss:find(v[1]) ~= nil do