summaryrefslogtreecommitdiff
path: root/tex/context/base/luat-exe.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-05-14 10:40:15 +0300
committerMarius <mariausol@gmail.com>2012-05-14 10:40:15 +0300
commit86301645de1fc594ca94a2a722fce813c16966b1 (patch)
treec8723188d4d356086f97a40e36499ce883711b37 /tex/context/base/luat-exe.lua
parent8d448442950011295b60f1ea7385887e043388e9 (diff)
downloadcontext-86301645de1fc594ca94a2a722fce813c16966b1.tar.gz
beta 2012.05.14 09:19
Diffstat (limited to 'tex/context/base/luat-exe.lua')
-rw-r--r--tex/context/base/luat-exe.lua64
1 files changed, 46 insertions, 18 deletions
diff --git a/tex/context/base/luat-exe.lua b/tex/context/base/luat-exe.lua
index 42c17ded5..0e9a94313 100644
--- a/tex/context/base/luat-exe.lua
+++ b/tex/context/base/luat-exe.lua
@@ -17,8 +17,16 @@ resolvers.executers = resolvers.executers or { }
local executers = resolvers.executers
local permitted = { }
+
local osexecute = os.execute
+local osexec = os.exec
+local osspawn = os.spawn
+local iopopen = io.popen
+
local execute = osexecute
+local exec = osexec
+local spawn = osspawn
+local popen = iopopen
local function register(...)
local t = { ... }
@@ -28,33 +36,47 @@ local function register(...)
end
end
-local function finalize() -- todo: os.exec, todo: report ipv print
- execute = function(...)
- -- todo: make more clever first split
- local t, name, arguments = { ... }, "", ""
- local one = t[1]
- if #t == 1 then
- if type(one) == 'table' then
- name, arguments = one, concat(t," ",2,#t)
+local function prepare(...)
+ -- todo: make more clever first split
+ local t = { ... }
+ local one = t[1]
+ if #t == 1 then
+ if type(one) == 'table' then
+ return one, concat(t," ",2,#t)
+ else
+ local name, arguments = match(one,"^(.-)%s+(.+)$")
+ if name and arguments then
+ return name, arguments
else
- name, arguments = match(one,"^(.-)%s+(.+)$")
- if not (name and arguments) then
- name, arguments = one, ""
- end
+ return one, ""
end
- else
- name, arguments = one, concat(t," ",2,#t)
end
+ else
+ return one, concat(t," ",2,#t)
+ end
+end
+
+local function executer(action)
+ return function(...)
+ local name, arguments = prepare(...)
for k=1,#permitted do
local v = permitted[k]
if find(name,v) then
- osexecute(name .. " " .. arguments)
+ return action(name .. " " .. arguments)
-- print("executed: " .. name .. " " .. arguments)
else
report_executers("not permitted: %s %s",name,arguments)
end
end
+ return action("")
end
+end
+
+local function finalize() -- todo: os.exec, todo: report ipv print
+ execute = executer(osexecute)
+ exec = executer(osexec)
+ spawn = executer(osspawn)
+ popen = executer(iopopen)
finalize = function()
report_executers("already finalized")
end
@@ -62,11 +84,17 @@ local function finalize() -- todo: os.exec, todo: report ipv print
report_executers("already finalized, no registration permitted")
end
os.execute = execute
+ os.exec = exec
+ os.spawn = spawn
+ io.popen = popen
end
-executers.finalize = function(...) finalize(...) end
-executers.register = function(...) register(...) end
-executers.execute = function(...) execute (...) end
+executers.finalize = function(...) return finalize(...) end
+executers.register = function(...) return register(...) end
+executers.execute = function(...) return execute (...) end
+executers.exec = function(...) return exec (...) end
+executers.spawn = function(...) return spawn (...) end
+executers.popen = function(...) return popen (...) end
local execution_mode directives.register("system.executionmode", function(v) execution_mode = v end)
local execution_list directives.register("system.executionlist", function(v) execution_list = v end)