diff options
Diffstat (limited to 'scripts/context/lua/mtxrun.lua')
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 151 |
1 files changed, 120 insertions, 31 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 27e0cbfa6..fed0e13f4 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -5004,43 +5004,78 @@ local function ignore() end setmetatable(logs, { __index = function(t,k) t[k] = ignore ; return ignore end }) -local report, subreport, status, settarget +local report, subreport, status, settarget, setformatter + +local direct, subdirect, writer if tex and tex.jobname or tex.formatname then - local target = "term and log" + local valueiskey = { __index = function(t,k) t[k] = k return k end } -- will be helper + + local target = "term and log" + + local formats = { } setmetatable(formats, valueiskey) + local translations = { } setmetatable(translations,valueiskey) + + writer = function(...) + write_nl(target,...) + end report = function(a,b,c,...) if c then - write_nl(target,format("%-15s > %s\n",a,format(b,c,...))) + write_nl(target,format("%-15s > %s\n",translations[a],format(formats[b],c,...))) elseif b then - write_nl(target,format("%-15s > %s\n",a,b)) + write_nl(target,format("%-15s > %s\n",translations[a],formats[b])) elseif a then - write_nl(target,format("%-15s >\n", a)) + write_nl(target,format("%-15s >\n", translations[a])) else write_nl(target,"\n") end end - subreport = function(a,sub,b,c,...) + direct = function(a,b,c,...) if c then - write_nl(target,format("%-15s > %s > %s\n",a,sub,format(b,c,...))) + return format("%-15s > %s",translations[a],format(formats[b],c,...)) elseif b then - write_nl(target,format("%-15s > %s > %s\n",a,sub,b)) + return format("%-15s > %s",translations[a],formats[b]) elseif a then - write_nl(target,format("%-15s > %s >\n", a,sub)) + return format("%-15s >", translations[a]) + else + return "" + end + end + + subreport = function(a,s,b,c,...) + if c then + write_nl(target,format("%-15s > %s > %s\n",translations[a],translations[s],format(formats[b],c,...))) + elseif b then + write_nl(target,format("%-15s > %s > %s\n",translations[a],translations[s],formats[b])) + elseif a then + write_nl(target,format("%-15s > %s >\n", translations[a],translations[s])) else write_nl(target,"\n") end end + subdirect = function(a,s,b,c,...) + if c then + return format("%-15s > %s > %s",translations[a],translations[s],format(formats[b],c,...)) + elseif b then + return format("%-15s > %s > %s",translations[a],translations[s],formats[b]) + elseif a then + return format("%-15s > %s >", translations[a],translations[s]) + else + return "" + end + end + status = function(a,b,c,...) if c then - write_nl(target,format("%-15s : %s\n",a,format(b,c,...))) + write_nl(target,format("%-15s : %s\n",translations[a],format(formats[b],c,...))) elseif b then - write_nl(target,format("%-15s : %s\n",a,b)) -- b can have %'s + write_nl(target,format("%-15s : %s\n",translations[a],formats[b])) elseif a then - write_nl(target,format("%-15s :\n", a)) + write_nl(target,format("%-15s :\n", translations[a])) else write_nl(target,"\n") end @@ -5072,8 +5107,18 @@ if tex and tex.jobname or tex.formatname then end end + setformats = function(f) + formats = f + end + + settranslations = function(t) + translations = t + end + else + writer = write_nl + report = function(a,b,c,...) if c then write_nl(format("%-15s | %s",a,format(b,c,...))) @@ -5110,18 +5155,29 @@ else end end - settarget = ignore - pushtarget = ignore - poptarget = ignore + direct = ignore + subdirect = ignore + + settarget = ignore + pushtarget = ignore + poptarget = ignore + setformats = ignore + settranslations = ignore end -logs.report = report -logs.subreport = subreport -logs.status = status -logs.settarget = settarget -logs.pushtarget = pushtarget -logs.poptarget = poptarget +logs.report = report +logs.subreport = subreport +logs.status = status +logs.settarget = settarget +logs.pushtarget = pushtarget +logs.poptarget = poptarget +logs.setformats = setformats +logs.settranslations = settranslations + +logs.direct = direct +logs.subdirect = subdirect +logs.writer = writer -- installer @@ -5171,7 +5227,30 @@ function logs.reporter(category,subcategory) return reporter end -logs.new = logs.reporter +logs.new = logs.reporter -- for old times sake + +-- context specicific: this ends up in the macro stream + +local ctxreport = logs.writer + +function logs.setmessenger(m) + ctxreport = m +end + +function logs.messenger(category,subcategory) + -- we need to avoid catcode mess (todo: fast context) + if subcategory then + return function(...) + ctxreport(subdirect(category,subcategory,...)) + end + else + return function(...) + ctxreport(direct(category,...)) + end + end +end + +-- so far local function doset(category,value) if category == true then @@ -11851,17 +11930,20 @@ end local function doit(path,blist,bname,tag,kind,result,allresults) local done = false if blist and kind then + local resolve = resolvers.resolve -- added if type(blist) == 'string' then -- make function and share code if find(lower(blist),path) then - result[#result+1] = methodhandler('concatinators',kind,tag,blist,bname) or "" + local full = methodhandler('concatinators',kind,tag,blist,bname) or "" + result[#result+1] = resolve(full) done = true end else for kk=1,#blist do local vv = blist[kk] if find(lower(vv),path) then - result[#result+1] = methodhandler('concatinators',kind,tag,vv,bname) or "" + local full = methodhandler('concatinators',kind,tag,vv,bname) or "" + result[#result+1] = resolve(full) done = true if not allresults then break end end @@ -11871,15 +11953,22 @@ local function doit(path,blist,bname,tag,kind,result,allresults) return done end + local makewildcard = Cs( (P("^")^0 * P("/") * P(-1) + P(-1)) /".*" - + (P("^")^0 * P("/") / "") * (P("*")/".*" + P("-")/"%%-" + P("?")/"."+ P("\\")/"/" + P(1))^0 + + (P("^")^0 * P("/") / "")^0 * (P("*")/".*" + P("-")/"%%-" + P(".")/"%%." + P("?")/"."+ P("\\")/"/" + P(1))^0 ) -local function findwildcardfiles(filename,allresults) -- todo: remap: and lpeg - local result = { } - local path = lower(lpegmatch(makewildcard,filedirname (filename))) - local name = lower(lpegmatch(makewildcard,filebasename(filename))) +function resolvers.wildcardpattern(pattern) + return lpegmatch(makewildcard,pattern) or pattern +end + +local function findwildcardfiles(filename,allresults,result) -- todo: remap: and lpeg + result = result or { } + local base = filebasename(filename) + local dirn = filedirname(filename) + local path = lower(lpegmatch(makewildcard,dirn) or dirn) + local name = lower(lpegmatch(makewildcard,base) or base) local files, done = instance.files, false if find(name,"%*") then local hashes = instance.hashes @@ -11909,8 +11998,8 @@ local function findwildcardfiles(filename,allresults) -- todo: remap: and lpeg return result end -function resolvers.findwildcardfiles(filename) - return findwildcardfiles(filename,true) +function resolvers.findwildcardfiles(filename,result) + return findwildcardfiles(filename,true,result) end function resolvers.findwildcardfile(filename) |