summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/mlib-run.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/mlib-run.lua')
-rw-r--r--tex/context/base/mkiv/mlib-run.lua273
1 files changed, 141 insertions, 132 deletions
diff --git a/tex/context/base/mkiv/mlib-run.lua b/tex/context/base/mkiv/mlib-run.lua
index 11bd1a9be..6962340c5 100644
--- a/tex/context/base/mkiv/mlib-run.lua
+++ b/tex/context/base/mkiv/mlib-run.lua
@@ -123,41 +123,7 @@ local mpbasepath = lpeg.instringchecker(P("/metapost/") * (P("context") + P("bas
local realtimelogging do
- local finders = { }
- mplib.finders = finders -- also used in meta-lua.lua
-
- local new_instance = mplib.new
-
- local function validftype(ftype)
- if ftype == "mp" then
- return "mp"
- else
- return nil
- end
- end
-
- finders.file = function(specification,name,mode,ftype)
- return resolvers.findfile(name,validftype(ftype))
- end
-
- -- this will be redone in lmtx
-
- local function i_finder(name,mode,ftype) -- fake message for mpost.map and metafun.mpvi
- local specification = url.hashed(name)
- local finder = finders[specification.scheme] or finders.file
- local found = finder(specification,name,mode,validftype(ftype))
- return found
- end
-
- local function o_finder(name,mode,ftype)
- return name
- end
-
- o_finder = sandbox.register(o_finder,sandbox.filehandlerone,"mplib output finder")
-
- local function finder(name,mode,ftype)
- return (mode == "w" and o_finder or i_finder)(name,mode,validftype(ftype))
- end
+ -- begin of logger code
local report_logger = logs.reporter("metapost log")
local report_error = logs.reporter("metapost error")
@@ -189,121 +155,144 @@ local realtimelogging do
end
end
- -- experiment, todo: per instance, just a push / pop ?
+ -- end of logger code
- local findtexfile = resolvers.findtexfile
- local opentexfile = resolvers.opentexfile
- local splitlines = string.splitlines
+ -- begin of logger code
- local function writetoterminal(terminaldata,maxterm,d)
- local t = type(d)
- local n = 0
- if t == "string" then
- d = splitlines(d)
- n = #d
- for i=1,#d do
- maxterm = maxterm + 1
- terminaldata[maxterm] = d[i]
- end
- elseif t == "table" then
- for i=1,#d do
- local l = d[i]
- if find(l,"[\n\r]") then
- local s = splitlines(l)
- local m = #s
- for i=1,m do
- maxterm = maxterm + 1
- terminaldata[maxterm] = s[i]
- end
- n = n + m
- else
- maxterm = maxterm + 1
- terminaldata[maxterm] = d[i]
- n = 1
- end
- end
- end
- if trace_terminal then
- report_metapost("writing %i lines, in cache %s",n,maxterm)
- end
- return maxterm
- end
+ local finders = { }
+ mplib.finders = finders -- also used in meta-lua.lua
- local function readfromterminal(terminaldata,maxterm,nowterm)
- if nowterm >= maxterm then
- terminaldata[nowterm] = false
- maxterm = 0
- nowterm = 0
- if trace_terminal then
- report_metapost("resetting, maxcache %i",#terminaldata)
- end
- return maxterm, nowterm, nil
+ local new_instance = mplib.new
+
+ local function validftype(ftype)
+ if ftype == "mp" then
+ return "mp"
else
- if nowterm > 0 then
- terminaldata[nowterm] = false
- end
- nowterm = nowterm + 1
- local s = terminaldata[nowterm]
- if trace_terminal then
- report_metapost("reading line %i: %s",nowterm,s)
- end
- return maxterm, nowterm, s
+ return nil
end
end
- local function fileopener()
+ finders.file = function(specification,name,mode,ftype)
+ return resolvers.findfile(name,validftype(ftype))
+ end
- -- these can go into the table itself
+ -- end of finder code
- local terminaldata = { }
- local maxterm = 0
- local nowterm = 0
+ if CONTEXTLMTXMODE > 0 then
- local terminal = {
- name = "terminal",
- close = function()
- -- terminal = { }
- -- maxterm = 0
- -- nowterm = 0
- end,
- reader = function()
- local line
- maxterm, nowterm, line = readfromterminal(terminaldata,maxterm,nowterm)
- return line
- end,
- writer = function(d)
- maxterm = writetoterminal(terminaldata,maxterm,d)
- end,
- }
+ local findtexfile = resolvers.findtexfile
+ local opentexfile = resolvers.opentexfile
+ local splitlines = string.splitlines
+
+ local function writetoterminal(terminaldata,maxterm,d)
+ local t = type(d)
+ local n = 0
+ if t == "string" then
+ d = splitlines(d)
+ n = #d
+ for i=1,#d do
+ maxterm = maxterm + 1
+ terminaldata[maxterm] = d[i]
+ end
+ elseif t == "table" then
+ for i=1,#d do
+ local l = d[i]
+ if find(l,"[\n\r]") then
+ local s = splitlines(l)
+ local m = #s
+ for i=1,m do
+ maxterm = maxterm + 1
+ terminaldata[maxterm] = s[i]
+ end
+ n = n + m
+ else
+ maxterm = maxterm + 1
+ terminaldata[maxterm] = d[i]
+ n = 1
+ end
+ end
+ end
+ if trace_terminal then
+ report_metapost("writing %i lines, in cache %s",n,maxterm)
+ end
+ return maxterm
+ end
- return function(name,mode,kind)
- if name == "terminal" then
- -- report_metapost("opening terminal")
- return terminal
- elseif mode == "w" then
- local f = io.open(name,"wb")
- if f then
- -- report_metapost("opening file %a for writing",full)
- return {
- name = full,
- writer = function(s) return f:write(s) end, -- io.write(f,s)
- close = function() f:close() end,
- }
+ local function readfromterminal(terminaldata,maxterm,nowterm)
+ if nowterm >= maxterm then
+ terminaldata[nowterm] = false
+ maxterm = 0
+ nowterm = 0
+ if trace_terminal then
+ report_metapost("resetting, maxcache %i",#terminaldata)
end
+ return maxterm, nowterm, nil
else
- local full = findtexfile(name,validftype(ftype))
- if full then
- -- report_metapost("opening file %a for reading",full)
- return opentexfile(full)
+ if nowterm > 0 then
+ terminaldata[nowterm] = false
+ end
+ nowterm = nowterm + 1
+ local s = terminaldata[nowterm]
+ if trace_terminal then
+ report_metapost("reading line %i: %s",nowterm,s)
end
+ return maxterm, nowterm, s
end
end
- end
+ local function fileopener()
+
+ -- these can go into the table itself
+
+ local terminaldata = { }
+ local maxterm = 0
+ local nowterm = 0
+
+ local terminal = {
+ name = "terminal",
+ close = function()
+ -- terminal = { }
+ -- maxterm = 0
+ -- nowterm = 0
+ end,
+ reader = function()
+ local line
+ maxterm, nowterm, line = readfromterminal(terminaldata,maxterm,nowterm)
+ return line
+ end,
+ writer = function(d)
+ maxterm = writetoterminal(terminaldata,maxterm,d)
+ end,
+ }
+
+ return function(name,mode,kind)
+ if name == "terminal" then
+ -- report_metapost("opening terminal")
+ return terminal
+ elseif mode == "w" then
+ local f = io.open(name,"wb")
+ if f then
+ -- report_metapost("opening file %a for writing",full)
+ return {
+ name = full,
+ writer = function(s) return f:write(s) end, -- io.write(f,s)
+ close = function() f:close() end,
+ }
+ end
+ else
+ local full = findtexfile(name,validftype(ftype))
+ if full then
+ -- report_metapost("opening file %a for reading",full)
+ return opentexfile(full)
+ end
+ end
+ end
- -- end of experiment
+ end
- if CONTEXTLMTXMODE > 0 then
+ local function finder(name,mode,kind)
+ return findtexfile(name,kind)
+ end
function mplib.new(specification)
local openfile = fileopener()
@@ -317,17 +306,37 @@ local realtimelogging do
return instance
end
+ mplib.finder = finder
+
else
+ local function i_finder(name,mode,ftype) -- fake message for mpost.map and metafun.mpvi
+ local specification = url.hashed(name)
+ local finder = finders[specification.scheme] or finders.file
+ local found = finder(specification,name,mode,validftype(ftype))
+ return found
+ end
+
+ local function o_finder(name,mode,ftype)
+ return name
+ end
+
+ o_finder = sandbox.register(o_finder,sandbox.filehandlerone,"mplib output finder")
+
+ local function finder(name,mode,ftype)
+ return (mode == "w" and o_finder or i_finder)(name,mode,validftype(ftype))
+ end
+
function mplib.new(specification)
specification.find_file = finder
specification.run_logger = logger
return new_instance(specification)
end
+ mplib.finder = finder
+
end
- mplib.finder = finder
end