diff options
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-context.lua')
-rw-r--r-- | Master/texmf-dist/scripts/context/lua/mtx-context.lua | 408 |
1 files changed, 129 insertions, 279 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-context.lua b/Master/texmf-dist/scripts/context/lua/mtx-context.lua index 49d40dda8c4..4e8c364d57f 100644 --- a/Master/texmf-dist/scripts/context/lua/mtx-context.lua +++ b/Master/texmf-dist/scripts/context/lua/mtx-context.lua @@ -12,7 +12,7 @@ if not modules then modules = { } end modules['mtx-context'] = { local type, next, tostring, tonumber = type, next, tostring, tonumber local format, gmatch, match, gsub, find = string.format, string.gmatch, string.match, string.gsub, string.find local quote, validstring = string.quote, string.valid -local sort, concat, insert, sortedhash = table.sort, table.concat, table.insert, table.sortedhash +local sort, concat, insert, sortedhash, tohash = table.sort, table.concat, table.insert, table.sortedhash, table.tohash local settings_to_array = utilities.parsers.settings_to_array local appendtable = table.append local lpegpatterns, lpegmatch, Cs, P = lpeg.patterns, lpeg.match, lpeg.Cs, lpeg.P @@ -34,7 +34,7 @@ local formatters = string.formatters local application = logs.application { name = "mtx-context", - banner = "ConTeXt Process Management 1.02", + banner = "ConTeXt Process Management 1.03", -- helpinfo = helpinfo, -- table with { category_a = text_1, category_b = text_2 } or helpstring or xml_blob helpinfo = "mtx-context.xml", } @@ -209,7 +209,11 @@ local persistent_runfiles = { } local special_runfiles = { - "%-mpgraph", "%-mprun", "%-temp%-" + "%-mpgraph", "%-mprun", "%-temp%-", +} + +local extra_runfiles = { + "^l_m_t_x_.-%.pdf$", } local function purge_file(dfile,cfile) @@ -514,35 +518,7 @@ local function result_save_keep(oldbase,newbase) end end --- executing luatex - -local function flags_to_string(flags,prefix) -- context flags get prepended by c: - local t = { } - for k, v in table.sortedhash(flags) do - if prefix then - k = format("c:%s",k) - end - if not v or v == "" or v == '""' then - -- no need to flag false - elseif v == true then - t[#t+1] = format('--%s',k) - elseif type(v) == "string" then - t[#t+1] = format('--%s=%s',k,quote(v)) - else - t[#t+1] = format('--%s=%s',k,tostring(v)) - end - end - return concat(t," ") -end - -local function luatex_command(l_flags,c_flags,filename,engine) - return format('%s %s %s "%s"', - engine or (status and status.luatex_engine) or "luatex", - flags_to_string(l_flags), - flags_to_string(c_flags,true), - filename - ) -end +-- use mtx-plain instead local plain_formats = { ["plain"] = "plain", @@ -563,10 +539,10 @@ local function run_plain(plainformat,filename) local pdfview = getargument("autopdf") or getargument("closepdf") if pdfview then pdf_close(resultname,pdfview) - os.execute(command) + os.execute(command) -- maybe also a proper runner pdf_open(resultname,pdfview) else - os.execute(command) + os.execute(command) -- maybe also a proper runner end end end @@ -599,8 +575,32 @@ local function run_texexec(filename,a_purge,a_purgeall) end end +-- executing luatex + +local function flags_to_string(flags,prefix) + -- context flags get prepended by c: ... this will move to the sbx module + local t = { } + for k, v in table.sortedhash(flags) do + if prefix then + k = format("c:%s",k) + end + if not v or v == "" or v == '""' then + -- no need to flag false + elseif v == true then + t[#t+1] = format('--%s',k) + elseif type(v) == "string" then + t[#t+1] = format('--%s=%s',k,quote(v)) + else + t[#t+1] = format('--%s=%s',k,tostring(v)) + end + end + return concat(t," ") +end + function scripts.context.run(ctxdata,filename) -- + local verbose = false + -- local a_nofile = getargument("nofile") local a_engine = getargument("engine") -- @@ -627,9 +627,10 @@ function scripts.context.run(ctxdata,filename) return end -- - local interface = validstring(getargument("interface")) or "en" + local interface = validstring(getargument("interface")) or "en" local formatname = formatofinterface[interface] or "cont-en" - local formatfile, scriptfile = resolvers.locateformat(formatname) -- regular engine ! + local formatfile, + scriptfile = resolvers.locateformat(formatname) -- regular engine ! if not formatfile or not scriptfile then report("warning: no format found, forcing remake (commandline driven)") scripts.context.make(formatname) @@ -667,17 +668,6 @@ function scripts.context.run(ctxdata,filename) local a_nodates = getargument("nodates") local a_trailerid = getargument("trailerid") local a_nocompression = getargument("nocompression") - - -- the following flag is not officially supported because i cannot forsee - -- side effects (so no bug reports please) .. we provide --sandbox that - -- does similar things but tries to ensure that context works as expected - - -- local a_safer = getargument("safer") - -- - -- if a_safer then - -- report("warning: using the luatex safer options, processing is not guaranteed") - -- end - -- a_batchmode = (a_batchmode and "batchmode") or (a_nonstopmode and "nonstopmode") or (a_scrollmode and "scrollmode") or nil -- @@ -820,8 +810,8 @@ function scripts.context.run(ctxdata,filename) -- ["safer"] = a_safer, -- better use --sandbox -- ["no-mktex"] = true, -- ["file-line-error-style"] = true, - ["fmt"] = formatfile, - ["lua"] = scriptfile, +-- ["fmt"] = formatfile, +-- ["lua"] = scriptfile, ["jobname"] = jobname, ["jithash"] = a_jithash, } @@ -868,15 +858,17 @@ function scripts.context.run(ctxdata,filename) c_flags.noarrange = a_noarrange or a_arrange or nil c_flags.profile = a_profile and (tonumber(a_profile) or 0) or nil -- - local command = luatex_command(l_flags,c_flags,mainfile,a_engine) - -- - report("run %s: %s",currentrun,command) print("") -- cleaner, else continuation on same line --- local returncode, errorstring = os.spawn(command) - local returncode = os.execute(command) + local returncode = environment.run_format( + formatfile, + scriptfile, + mainfile, + flags_to_string(l_flags), + flags_to_string(c_flags,true), + verbose + ) -- todo: remake format when no proper format is found if not returncode then --- report("fatal error: no return code, message: %s",errorstring or "?") report("fatal error: no return code") if resultname then result_save_error(oldbase,newbase) @@ -908,6 +900,15 @@ function scripts.context.run(ctxdata,filename) -- end -- + if environment.arguments["ansilog"] then + local logfile = file.replacesuffix(jobname,"log") + local logdata = io.loaddata(logfile) or "" + if logdata ~= "" then + io.savedata(logfile,(gsub(logdata,"%[.-m",""))) + end + end + -- + -- -- this will go away after we update luatex -- local syncctx = fileaddsuffix(jobname,"syncctx") @@ -922,10 +923,17 @@ function scripts.context.run(ctxdata,filename) c_flags.currentrun = c_flags.currentrun + 1 c_flags.noarrange = nil -- - local command = luatex_command(l_flags,c_flags,mainfile,a_engine) - -- report("arrange run: %s",command) - local returncode, errorstring = os.spawn(command) + -- + local returncode = environment.run_format( + formatfile, + scriptfile, + mainfile, + flags_to_string(l_flags), + flags_to_string(c_flags,true), + verbose + ) + -- if not returncode then report("fatal error: no return code, message: %s",errorstring or "?") os.exit(1) @@ -985,7 +993,7 @@ function scripts.context.run(ctxdata,filename) report() report("making epub file: ",command) report() - os.execute(command) + os.execute(command) -- todo: also a runner end -- if a_timing then @@ -1047,20 +1055,24 @@ function scripts.context.pipe() -- still used? io.savedata(filename,"\\relax") report("entering scrollmode using '%s' with optionfile, end job with \\end",filename) end - local command = luatex_command(l_flags,c_flags,filename) - os.spawn(command) + local returncode = environment.run_format( + formatfile, + scriptfile, + filename, + flags_to_string(l_flags), + flags_to_string(c_flags,true), + verbose + ) if getargument("purge") then scripts.context.purge_job(filename) elseif getargument("purgeall") then scripts.context.purge_job(filename,true) removefile(filename) end + elseif formatname then + report("error, no format found with name: %s, aborting",formatname) else - if formatname then - report("error, no format found with name: %s, aborting",formatname) - else - report("error, no format found (provide formatname or interface)") - end + report("error, no format found (provide formatname or interface)") end end @@ -1231,7 +1243,7 @@ function scripts.context.autoctx() if chunk then ctxname = match(chunk,"<%?context%-directive%s+job%s+ctxfile%s+([^ ]-)%s*?>") end - elseif suffix == "tex" or suffix == "mkiv" then + elseif suffix == "tex" or suffix == "mkiv" or suffix == "mkxl" then local analysis = preamble_analyze(firstfile) ctxname = analysis.ctxfile or analysis.ctx end @@ -1245,66 +1257,27 @@ function scripts.context.autoctx() scripts.context.run(ctxdata) end --- no longer ok as mlib-run misses something: - --- local template = [[ --- \starttext --- \directMPgraphic{%s}{input "%s"} --- \stoptext --- ]] --- --- local loaded = false --- --- function scripts.context.metapost() --- local filename = environment.filenames[1] or "" --- if not loaded then --- dofile(resolvers.findfile("mlib-run.lua")) --- loaded = true --- commands = commands or { } --- commands.writestatus = report -- no longer needed --- end --- local formatname = getargument("format") or "metafun" --- if formatname == "" or type(formatname) == "boolean" then --- formatname = "metafun" --- end --- if getargument("pdf") then --- local basename = removesuffix(filename) --- local resultname = getargument("result") or basename --- local jobname = "mtx-context-metapost" --- local tempname = fileaddsuffix(jobname,"tex") --- io.savedata(tempname,format(template,"metafun",filename)) --- environment.filenames[1] = tempname --- setargument("result",resultname) --- setargument("once",true) --- scripts.context.run() --- scripts.context.purge_job(jobname,true) --- scripts.context.purge_job(resultname,true) --- elseif getargument("svg") then --- metapost.directrun(formatname,filename,"svg") --- else --- metapost.directrun(formatname,filename,"mps") --- end --- end - --- -- - function scripts.context.version() - local name = resolvers.findfile("context.mkiv") - if name ~= "" then - report("main context file: %s",name) - local data = io.loaddata(name) - if data then - local version = match(data,"\\edef\\contextversion{(.-)}") - if version then - report("current version: %s",version) + local list = { "context.mkiv", "context.mkxl" } + for i=1,#list do + local base = list[i] + local name = resolvers.findfile(base) + if name ~= "" then + report("main context file: %s",name) + local data = io.loaddata(name) + if data then + local version = match(data,"\\edef\\contextversion{(.-)}") + if version then + report("current version: %s",version) + else + report("context version: unknown, no timestamp found") + end else - report("context version: unknown, no timestamp found") + report("context version: unknown, load error") end else - report("context version: unknown, load error") + report("main context file: unknown, %a not found",base) end - else - report("main context file: unknown, 'context.mkiv' not found") end end @@ -1340,15 +1313,15 @@ function scripts.context.purge_job(jobname,all,mkiitoo,fulljobname) end function scripts.context.purge(all,pattern,mkiitoo) - local all = all or getargument("all") - local pattern = getargument("pattern") or (pattern and (pattern.."*")) or "*.*" - local files = dir.glob(pattern) - local obsolete = table.tohash(obsolete_results) - local temporary = table.tohash(temporary_runfiles) - local synctex = table.tohash(synctex_runfiles) - local persistent = table.tohash(persistent_runfiles) - local generic = table.tohash(generic_files) - local deleted = { } + local all = all or getargument("all") + local pattern = getargument("pattern") or (pattern and (pattern.."*")) or "*.*" + local files = dir.glob(pattern) + local obsolete = tohash(obsolete_results) + local temporary = tohash(temporary_runfiles) + local synctex = tohash(synctex_runfiles) + local persistent = tohash(persistent_runfiles) + local generic = tohash(generic_files) + local deleted = { } for i=1,#files do local name = files[i] local suffix = filesuffix(name) @@ -1362,6 +1335,11 @@ function scripts.context.purge(all,pattern,mkiitoo) end end end + for i=1,#extra_runfiles do + if find(basename,extra_runfiles[i]) then + deleted[#deleted+1] = purge_file(name) + end + end end if #deleted > 0 then report("purged files: %s", concat(deleted,", ")) @@ -1422,17 +1400,19 @@ local function touchfiles(suffix,kind,path) end end +local tobetouched = tohash { "mkii", "mkiv", "mkvi", "mkxl", "mklx" } + function scripts.context.touch() if getargument("expert") then local touch = getargument("touch") local kind = getargument("kind") local path = getargument("basepath") - if touch == "mkii" or touch == "mkiv" or touch == "mkvi" then -- mkix mkxi + if tobetouched[touch] then -- mkix mkxi ctix ctxi touchfiles(touch,kind,path) else - touchfiles("mkii",kind,path) - touchfiles("mkiv",kind,path) - touchfiles("mkvi",kind,path) + for touch in sortedhash(tobetouched) do + touchfiles(touch,kind,path) + end end else report("touching needs --expert") @@ -1442,7 +1422,8 @@ end -- modules local labels = { "title", "comment", "status" } -local cards = { "*.mkvi", "*.mkiv", "*.mkxi", "*.mkix", "*.tex" } +local cards = { "*.mkiv", "*.mkvi", "*.mkix", "*.mkxi", "*.mkxl", "*.mklx", "*.tex" } +local valid = tohash { "mkiv", "mkvi", "mkix", "mkxi", "mkxl", "mklx", "tex" } function scripts.context.modules(pattern) local list = { } @@ -1468,7 +1449,7 @@ function scripts.context.modules(pattern) if not done[base] then done[base] = true local suffix = filesuffix(base) - if suffix == "tex" or suffix == "mkiv" or suffix == "mkvi" or suffix == "mkix" or suffix == "mkxi" then + if valid[suffix] then local prefix, rest = match(base,"^([xmst])%-(.*)") if prefix then v = resolvers.findfile(base) -- so that files on my dev path are seen @@ -1588,148 +1569,10 @@ function scripts.context.logcategories() scripts.context.run() end --- updating (often one will use mtx-update instead) - function scripts.context.timed(action) statistics.timed(action,true) end -local zipname = "cont-tmf.zip" -local mainzip = "http://www.pragma-ade.com/context/latest/" .. zipname -local validtrees = { "texmf-local", "texmf-context" } -local selfscripts = { "mtxrun.lua" } -- was: { "luatools.lua", "mtxrun.lua" } - -function zip.loaddata(zipfile,filename) -- should be in zip lib - local f = zipfile:open(filename) - if f then - local data = f:read("*a") - f:close() - return data - end - return nil -end - -function scripts.context.update() - local force = getargument("force") - local socket = require("socket") - local http = require("socket.http") - local basepath = resolvers.findfile("context.mkiv") or "" - if basepath == "" then - report("quiting, no 'context.mkiv' found") - return - end - local basetree = basepath.match(basepath,"^(.-)tex/context/base/.*context.mkiv$") or "" - if basetree == "" then - report("quiting, no proper tds structure (%s)",basepath) - return - end - local function is_okay(basetree) - for _, tree in next, validtrees do - local pattern = gsub(tree,"%-","%%-") - if find(basetree,pattern) then - return tree - end - end - return false - end - local okay = is_okay(basetree) - if not okay then - report("quiting, tree '%s' is protected",okay) - return - else - report("updating tree '%s'",okay) - end - if not lfs.chdir(basetree) then - report("quiting, unable to change to '%s'",okay) - return - end - report("fetching '%s'",mainzip) - local latest = http.request(mainzip) - if not latest then - report("context tree '%s' can be updated, use --force",okay) - return - end - io.savedata("cont-tmf.zip",latest) - if false then - -- variant 1 - os.execute("mtxrun --script unzip cont-tmf.zip") - else - -- variant 2 - local zipfile = zip.open(zipname) - if not zipfile then - report("quiting, unable to open '%s'",zipname) - return - end - local newfile = zip.loaddata(zipfile,"tex/context/base/mkiv/context.mkiv") - if not newfile then - report("quiting, unable to open '%s'","context.mkiv") - return - end - local oldfile = io.loaddata(resolvers.findfile("context.mkiv")) or "" - local function versiontonumber(what,str) - local version = match(str,"\\edef\\contextversion{(.-)}") or "" - local year, month, day, hour, minute = match(str,"\\edef\\contextversion{(%d+)%.(%d+)%.(%d+) *(%d+)%:(%d+)}") - if year and minute then - local time = os.time { year=year,month=month,day=day,hour=hour,minute=minute} - report("%s version: %s (%s)",what,version,time) - return time - else - report("%s version: %s (unknown)",what,version) - return nil - end - end - local oldversion = versiontonumber("old",oldfile) - local newversion = versiontonumber("new",newfile) - if not oldversion or not newversion then - report("quiting, version cannot be determined") - return - elseif oldversion == newversion then - report("quiting, your current version is up-to-date") - return - elseif oldversion > newversion then - report("quiting, your current version is newer") - return - end - for k in zipfile:files() do - local filename = k.filename - if find(filename,"/$") then - lfs.mkdir(filename) - else - local data = zip.loaddata(zipfile,filename) - if data then - if force then - io.savedata(filename,data) - end - report(filename) - end - end - end - for _, scriptname in next, selfscripts do - local oldscript = resolvers.findfile(scriptname) or "" - if oldscript ~= "" and is_okay(oldscript) then - local newscript = "./scripts/context/lua/" .. scriptname - local data = io.loaddata(newscript) or "" - if data ~= "" then - report("replacing script '%s' by '%s'",oldscript,newscript) - if force then - io.savedata(oldscript,data) - end - end - else - report("keeping script '%s'",oldscript) - end - end - if force then - scripts.context.make() - end - end - if force then - report("context tree '%s' has been updated",okay) - else - report("context tree '%s' can been updated (use --force)",okay) - end -end - -- getting it done if getargument("timedlog") then @@ -1753,6 +1596,17 @@ end do + local htmlerrorpage = getargument("htmlerrorpage") + if htmlerrorpage == "scite" then + directives.enable("system.showerror=scite") + elseif htmlerrorpage then + directives.enable("system.showerror") + end + +end + +do + local silent = getargument("silent") if type(silent) == "string" then directives.enable(format("logs.blocked={%s}",silent)) @@ -1786,15 +1640,11 @@ elseif getargument("generate") then scripts.context.timed(function() scripts.context.generate() end) elseif getargument("ctx") and not getargument("noctx") then scripts.context.timed(scripts.context.ctx) --- elseif getargument("mp") or getargument("metapost") then --- scripts.context.timed(scripts.context.metapost) elseif getargument("version") then application.identify() scripts.context.version() elseif getargument("touch") then scripts.context.touch() -elseif getargument("update") then - scripts.context.update() elseif getargument("expert") then application.help("expert", "special") elseif getargument("showmodules") or getargument("modules") then |