summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mlib-run.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mlib-run.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mlib-run.lua107
1 files changed, 80 insertions, 27 deletions
diff --git a/Master/texmf-dist/tex/context/base/mlib-run.lua b/Master/texmf-dist/tex/context/base/mlib-run.lua
index 72c16775d4f..f42b5359438 100644
--- a/Master/texmf-dist/tex/context/base/mlib-run.lua
+++ b/Master/texmf-dist/tex/context/base/mlib-run.lua
@@ -36,6 +36,7 @@ local report_metapost = logs.reporter("metapost")
local texerrormessage = logs.texerrormessage
local format, gsub, match, find = string.format, string.gsub, string.match, string.find
+local emptystring = string.is_empty
local starttiming, stoptiming = statistics.starttiming, statistics.stoptiming
@@ -57,30 +58,63 @@ function metapost.resetlastlog()
metapost.lastlog = ""
end
-local function finder(name, mode, ftype) -- we can use the finder to intercept btex/etex
+-- local function realfinder(name, mode, ftype)
+-- if mode == "w" then
+-- return name
+-- elseif file.is_qualified_path(name) then
+-- return name
+-- else
+-- return resolvers.findfile(name,ftype)
+-- end
+-- end
+
+local function i_finder(name, mode, ftype) -- fake message for mpost.map and metafun.mpvi
+ name = file.is_qualified_path(name) and name or resolvers.findfile(name,ftype)
+ if not (find(name,"/metapost/context/base/") or find(name,"/metapost/context/") or find(name,"/metapost/base/")) then
+ local data, found, forced = metapost.checktexts(io.loaddata(name) or "")
+ if found then
+ local temp = luatex.registertempfile(name,true)
+ io.savedata(temp,data)
+ name = temp
+ end
+ end
+ return name
+end
+
+local function o_finder(name, mode, ftype)
+ return name
+end
+
+local function finder(name, mode, ftype)
if mode == "w" then
- return name
- elseif file.is_qualified_path(name) then
- return name
+ return o_finder(name, mode, ftype)
else
- return resolvers.findfile(name,ftype)
+ return i_finder(name, mode, ftype)
end
end
-local function finder(name, mode, ftype) -- we use the finder to intercept btex/etex
- if mode ~= "w" then
- name = file.is_qualified_path(name) and name or resolvers.findfile(name,ftype)
- if not (find(name,"/metapost/context/base/") or find(name,"/metapost/context/") or find(name,"/metapost/base/")) then
- local data, found, forced = metapost.checktexts(io.loaddata(name) or "")
- if found then
- local temp = luatex.registertempfile(name,true)
- io.savedata(temp,data)
- name = temp
- end
+local i_limited = false
+local o_limited = false
+
+directives.register("system.inputmode", function(v)
+ if not i_limited then
+ local i_limiter = io.i_limiter(v)
+ if i_limiter then
+ i_finder = i_limiter.protect(i_finder)
+ i_limited = true
end
end
- return name
-end
+end)
+
+directives.register("system.outputmode", function(v)
+ if not o_limited then
+ local o_limiter = io.o_limiter(v)
+ if o_limiter then
+ o_finder = o_limiter.protect(o_finder)
+ o_limited = true
+ end
+ end
+end)
-- -- --
@@ -223,7 +257,7 @@ else
if not mpx then
result = { status = 99, error = "out of memory"}
else
- result = mpx:execute(format(preamble, file.replacesuffix(name,"mp")))
+ result = mpx:execute(format(preamble, file.addsuffix(name,"mp")))
end
stoptiming(mplib)
metapost.reporterror(result)
@@ -232,14 +266,31 @@ else
function metapost.checkformat(mpsinput)
local mpsversion = environment.version or "unset version"
- local mpsinput = file.addsuffix(mpsinput or "metafun", "mp")
- report_metapost("loading '%s' (experimental metapost version two)",mpsinput)
- local mpx, result = metapost.load(mpsinput)
- if mpx then
- return mpx
+ local mpsinput = mpsinput or "metafun"
+ local foundfile = ""
+ if file.suffix(mpsinput) ~= "" then
+ foundfile = finder(mpsinput) or ""
+ end
+ if foundfile == "" then
+ foundfile = finder(file.replacesuffix(mpsinput,"mpvi")) or ""
+ end
+ if foundfile == "" then
+ foundfile = finder(file.replacesuffix(mpsinput,"mpiv")) or ""
+ end
+ if foundfile == "" then
+ foundfile = finder(file.replacesuffix(mpsinput,"mp")) or ""
+ end
+ if foundfile == "" then
+ report_metapost("loading '%s' fails, format not found",mpsinput)
else
- report_metapost("error in loading '%s'",mpsinput)
- metapost.reporterror(result)
+ report_metapost("loading '%s': %s",mpsinput,foundfile)
+ local mpx, result = metapost.load(foundfile)
+ if mpx then
+ return mpx
+ else
+ report_metapost("error in loading '%s'",mpsinput)
+ metapost.reporterror(result)
+ end
end
end
@@ -287,8 +338,10 @@ end
local mp_inp, mp_log, mp_tag = { }, { }, 0
+-- key/values
+
function metapost.process(mpx, data, trialrun, flusher, multipass, isextrapass, askedfig)
- local converted, result = false, {}
+ local converted, result = false, { }
if type(mpx) == "string" then
mpx = metapost.format(mpx) -- goody
end
@@ -323,7 +376,7 @@ function metapost.process(mpx, data, trialrun, flusher, multipass, isextrapass,
if not metapost.reporterror(result) then
if metapost.showlog then
local str = (result.term ~= "" and result.term) or "no terminal output"
- if not string.is_empty(str) then
+ if not emptystring(str) then
metapost.lastlog = metapost.lastlog .. "\n" .. str
report_metapost("log: %s",str)
end