diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/core-job.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/core-job.lua | 152 |
1 files changed, 100 insertions, 52 deletions
diff --git a/Master/texmf-dist/tex/context/base/core-job.lua b/Master/texmf-dist/tex/context/base/core-job.lua index b963227a50f..fb4f76de15c 100644 --- a/Master/texmf-dist/tex/context/base/core-job.lua +++ b/Master/texmf-dist/tex/context/base/core-job.lua @@ -6,33 +6,14 @@ if not modules then modules = { } end modules ['core-job'] = { license = "see context related readme files" } --- will move +local texsprint, texprint, format, find, gmatch = tex.sprint, tex.print, string.format, string.find, string.gmatch -commands.writestatus = ctx.writestatus - -function commands.doifelse(b) - tex.sprint(tex.texcatcodes,(b and "\\firstoftwoarguments") or "\\secondoftwoarguments") -end -function commands.doif(b) - tex.sprint(tex.texcatcodes,(b and "\\firstofoneargument") or "\\gobbleoneargument") -end -function commands.doifnot(b) - tex.sprint(tex.texcatcodes,(b and "\\gobbleoneargument") or "\\firstofoneargument") -end -cs.testcase = commands.doifelse - -local format = string.format - -function commands. def(cs,value) tex.sprint(tex.ctxcatcodes,format( "\\def\\%s{%s}",cs,value)) end -function commands.edef(cs,value) tex.sprint(tex.ctxcatcodes,format("\\edef\\%s{%s}",cs,value)) end -function commands.gdef(cs,value) tex.sprint(tex.ctxcatcodes,format("\\gdef\\%s{%s}",cs,value)) end -function commands.xdef(cs,value) tex.sprint(tex.ctxcatcodes,format("\\xdef\\%s{%s}",cs,value)) end - -function commands.cs(cs,args) tex.sprint(tex.ctxcatcodes,format("\\csname %s\\endcsname %s",cs,args or"")) end +local ctxcatcodes = tex.ctxcatcodes +local texcatcodes = tex.texcatcodes -- main code -local function find_file(name,maxreadlevel) +function resolvers.findctxfile(name,maxreadlevel) local function exists(n) if io.exists(n) then return n @@ -44,7 +25,7 @@ local function find_file(name,maxreadlevel) end return nil end - if input.aux.qualified_path(name) then + if file.is_qualified_path(name) then return name else -- not that efficient, too many ./ lookups @@ -61,41 +42,40 @@ local function find_file(name,maxreadlevel) end end end - return input.find_file(texmf.instance,name) or "" + return resolvers.find_file(name) or "" end end function commands.processfile(name,maxreadlevel) - name = find_file(name,maxreadlevel) + name = resolvers.findctxfile(name,maxreadlevel) if name ~= "" then - -- tex.sprint(tex.ctxcatcodes,string.format("\\input %s\\relax",name)) - tex.print(tex.ctxcatcodes,string.format("\\input %s",name)) + texsprint(ctxcatcodes,format("\\input %s\\relax",name)) -- we need \input {name} end end function commands.doifinputfileelse(name,maxreadlevel) - commands.doifelse(find_file(name,maxreadlevel) ~= "") + commands.doifelse(resolvers.findctxfile(name,maxreadlevel) ~= "") end function commands.locatefilepath(name,maxreadlevel) - tex.sprint(tex.texcatcodes,file.dirname(find_file(name,maxreadlevel))) + texsprint(texcatcodes,file.dirname(resolvers.findctxfile(name,maxreadlevel))) end function commands.usepath(paths,maxreadlevel) - input.register_extra_path(texmf.instance,paths) - tex.sprint(tex.texcatcodes,table.concat(texmf.instance.extra_paths or {}, "")) + resolvers.register_extra_path(paths) + texsprint(texcatcodes,table.concat(resolvers.instance.extra_paths or {}, "")) end function commands.usesubpath(subpaths,maxreadlevel) - input.register_extra_path(texmf.instance,nil,subpaths) - tex.sprint(tex.texcatcodes,table.concat(texmf.instance.extra_paths or {}, "")) + resolvers.register_extra_path(nil,subpaths) + texsprint(texcatcodes,table.concat(resolvers.instance.extra_paths or {}, "")) end function commands.usezipfile(name,tree) if tree and tree ~= "" then - input.usezipfile(texmf.instance,string.format("zip:///%s?tree=%s",name,tree)) + resolvers.usezipfile(format("zip:///%s?tree=%s",name,tree)) else - input.usezipfile(texmf.instance,string.format("zip:///%s",name)) + resolvers.usezipfile(format("zip:///%s",name)) end end @@ -108,39 +88,107 @@ end --~ </exa:variables> local function convertexamodes(str) - local x, t = xml.convert(str), { } + local x = xml.convert(str) for e, d, k in xml.elements(x,"exa:variable") do local dk = d[k] local label = dk.at and dk.at.label if label and label ~= "" then - local data = xml.content(dk) + local data = xml.content(dk) or "" local mode = label:match("^mode:(.+)$") if mode then - tex.sprint(tex.ctxcatcodes,string.format("\\enablemode[%s:%s]",mode,data)) - end - if data:find("{}") then - t[#t+1] = string.format("%s={%s}",mode,data) - else - t[#t+1] = string.format("%s=%s",mode,data) + texsprint(ctxcatcodes,format("\\enablemode[%s:%s]",mode,data)) end + texsprint(ctxcatcodes,format("\\setvariable{exa:variables}{%s}{%s}",label,data:gsub("([{}])","\\%1"))) end end - if #t > 0 then - tex.sprint(tex.ctxcatcodes,string.format("\\setvariables[exa:variables][%s]",table.concat(t,","))) - end end --- we need a system file option: ,. .. etc + paths but no tex lookup so input.find_file is wrong here +-- we need a system file option: ,. .. etc + paths but no tex lookup so resolvers.find_file is wrong here function commands.loadexamodes(filename) if not filename or filename == "" then - filename = file.stripsuffix(tex.jobname) + filename = file.removesuffix(tex.jobname) end - filename = input.find_file(texmf.instance,file.addsuffix(filename,'ctm')) or "" + filename = resolvers.find_file(file.addsuffix(filename,'ctm')) or "" if filename ~= "" then - commands.writestatus("examodes","loading " .. filename) -- todo: message system + commands.writestatus("examodes","loading %s",filename) -- todo: message system convertexamodes(io.loaddata(filename)) else - commands.writestatus("examodes","no mode file " .. filename) -- todo: message system + commands.writestatus("examodes","no mode file %s",filename) -- todo: message system end end + +function commands.logoptionfile(name) + -- todo: xml if xml logmode + local f = io.open(name) + if f then + texio.write_nl("log","%\n%\tbegin of optionfile\n%\n") + for line in f:lines() do + texio.write("log",format("%%\t%s\n",line)) + end + texio.write("log","%\n%\tend of optionfile\n%\n") + f:close() + end +end + +--~ set functions not ok and not faster on mk runs either +--~ +--~ local function doifcommonelse(a,b) +--~ local ba = find(a,",") +--~ local bb = find(b,",") +--~ if ba and bb then +--~ for sa in gmatch(a,"[^ ,]+") do +--~ for sb in gmatch(b,"[^ ,]+") do +--~ if sa == sb then +--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",sa,"}") +--~ return true +--~ end +--~ end +--~ end +--~ elseif ba then +--~ for sa in gmatch(a,"[^ ,]+") do +--~ if sa == b then +--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",b,"}") +--~ return true +--~ end +--~ end +--~ elseif bb then +--~ for sb in gmatch(b,"[^ ,]+") do +--~ if a == sb then +--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",a,"}") +--~ return true +--~ end +--~ end +--~ else +--~ if a == b then +--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",a,"}") +--~ return true +--~ end +--~ end +--~ texsprint(ctxcatcodes,"\\let\\commalistelement\\empty") +--~ return false +--~ end +--~ local function doifinsetelse(a,b) +--~ local bb = find(b,",") +--~ if bb then +--~ for sb in gmatch(b,"[^ ,]+") do +--~ if a == sb then +--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",a,"}") +--~ return true +--~ end +--~ end +--~ else +--~ if a == b then +--~ texsprint(ctxcatcodes,"\\def\\commalistelement{",a,"}") +--~ return true +--~ end +--~ end +--~ texsprint(ctxcatcodes,"\\let\\commalistelement\\empty") +--~ return false +--~ end +--~ function commands.doifcommon (a,b) commands.doif (doifcommonelse(a,b)) end +--~ function commands.doifnotcommon (a,b) commands.doifnot (doifcommonelse(a,b)) end +--~ function commands.doifcommonelse(a,b) commands.doifelse(doifcommonelse(a,b)) end +--~ function commands.doifinset (a,b) commands.doif (doifinsetelse(a,b)) end +--~ function commands.doifnotinset (a,b) commands.doifnot (doifinsetelse(a,b)) end +--~ function commands.doifinsetelse (a,b) commands.doifelse(doifinsetelse(a,b)) end |