summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/context/lua/mtx-context.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-context.lua')
-rw-r--r--Master/texmf-dist/scripts/context/lua/mtx-context.lua146
1 files changed, 125 insertions, 21 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-context.lua b/Master/texmf-dist/scripts/context/lua/mtx-context.lua
index 4e8c364d57f..7ae350111be 100644
--- a/Master/texmf-dist/scripts/context/lua/mtx-context.lua
+++ b/Master/texmf-dist/scripts/context/lua/mtx-context.lua
@@ -11,7 +11,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 quote, validstring, splitstring = string.quote, string.valid, string.split
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
@@ -34,7 +34,7 @@ local formatters = string.formatters
local application = logs.application {
name = "mtx-context",
- banner = "ConTeXt Process Management 1.03",
+ banner = "ConTeXt Process Management 1.04",
-- helpinfo = helpinfo, -- table with { category_a = text_1, category_b = text_2 } or helpstring or xml_blob
helpinfo = "mtx-context.xml",
}
@@ -95,7 +95,9 @@ scripts.context = scripts.context or { }
if jit then -- already luajittex
setargument("engine","luajittex")
setargument("jit",nil)
-elseif getargument("jit") then -- relaunch luajittex
+elseif getargument("luatex") then -- relaunch luajittex
+ setargument("engine","luatex")
+elseif getargument("jit") or getargument("luajittex") then -- relaunch luajittex
-- bonus shortcut, we assume that --jit also indicates the engine
-- although --jit and --engine=luajittex are independent
setargument("engine","luajittex")
@@ -105,10 +107,11 @@ end
-- -- the platforms to use a similar approach to this.
local engine_new = file.nameonly(getargument("engine") or directives.value("system.engine"))
-local engine_old = file.nameonly(environment.ownbin)
+local engine_old = file.nameonly(environment.ownmain) or file.nameonly(environment.ownbin)
local function restart(engine_old,engine_new)
- local command = format("%s --luaonly %q %s --redirected",engine_new,environment.ownname,environment.reconstructcommandline())
+ local ownname = file.join(file.dirname(environment.ownname),"mtxrun.lua")
+ local command = format("%s --luaonly %q %s --redirected",engine_new,ownname,environment.reconstructcommandline())
report(format("redirect %s -> %s: %s",engine_old,engine_new,command))
local result = os.execute(command)
os.exit(result == 0 and 0 or 1)
@@ -124,6 +127,10 @@ end
-- setargument("engine",engine_new) -- later on we need this
-- end
+if environment.validengines[engine_new] and engine_new ~= environment.basicengines[engine_old] then
+ restart(engine_old,engine_new)
+end
+
-- so far
-- constants
@@ -213,6 +220,7 @@ local special_runfiles = {
}
local extra_runfiles = {
+ "^m_k_i_v_.-%.pdf$",
"^l_m_t_x_.-%.pdf$",
}
@@ -620,7 +628,7 @@ function scripts.context.run(ctxdata,filename)
-- files = { }
elseif #files > 0 then
-- the list of given files is processed using the stub file
- mainfile = usedfiles.yes
+ mainfile = usedfiles.yes -- this can become "" for luametatex/lmtx
filelist = files
files = { }
else
@@ -661,6 +669,7 @@ function scripts.context.run(ctxdata,filename)
local a_arrange = getargument("arrange")
local a_noarrange = getargument("noarrange")
local a_jithash = getargument("jithash")
+ local a_permitloadlib = getargument("permitloadlib")
local a_texformat = getargument("texformat")
local a_keeptuc = getargument("keeptuc")
local a_keeplog = getargument("keeplog")
@@ -706,7 +715,8 @@ function scripts.context.run(ctxdata,filename)
formatfile, scriptfile = resolvers.locateformat(formatname)
end
--
- a_jithash = validstring(a_jithash or analysis.jithash) or nil
+ a_jithash = validstring(a_jithash or analysis.jithash) or nil
+ a_permitloadlib = a_permitloadlib or analysis.permitloadlib or nil
--
if not formatfile or not scriptfile then
report("warning: no format found, forcing remake (source driven)")
@@ -732,6 +742,9 @@ function scripts.context.run(ctxdata,filename)
if formatfile and scriptfile then
local suffix = validstring(getargument("suffix"))
local resultname = validstring(getargument("result"))
+ if not resultname or resultname == "" then
+ resultname = validstring(analysis.result)
+ end
local resultpath = file.pathpart(resultname)
if resultpath ~= "" then
resultname = nil
@@ -810,24 +823,17 @@ 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,
+ ["permitloadlib"] = a_permitloadlib,
}
--
- if not a_timing then
- -- okay
- elseif c_flags.usemodule then
- c_flags.usemodule = format("timing,%s",c_flags.usemodule)
- else
- c_flags.usemodule = "timing"
- end
- --
local directives = { }
--
if a_nodates then
- directives[#directives+1] = format("backend.date=%s",type(a_nodates) == "string" and a_nodates or " no")
+ directives[#directives+1] = format("backend.date=%s",type(a_nodates) == "string" and a_nodates or "no")
end
--
if type(a_trailerid) == "string" then
@@ -848,6 +854,11 @@ function scripts.context.run(ctxdata,filename)
--
-- kindofrun: 1:first run, 2:successive run, 3:once, 4:last of maxruns
--
+ local engine = analysis.engine or "luametatex"
+ if engine == "luametatex" and (mainfile == usedfiles.yes or mainfile == usedfiles.nop) then
+ mainfile = "" -- we don't need that
+ end
+ --
for currentrun=1,maxnofruns do
--
c_flags.final = false
@@ -859,6 +870,7 @@ function scripts.context.run(ctxdata,filename)
c_flags.profile = a_profile and (tonumber(a_profile) or 0) or nil
--
print("") -- cleaner, else continuation on same line
+ --
local returncode = environment.run_format(
formatfile,
scriptfile,
@@ -1001,7 +1013,7 @@ function scripts.context.run(ctxdata,filename)
report("you can process (timing) statistics with:",jobname)
report()
report("context --extra=timing '%s'",jobname)
- report("mtxrun --script timing --xhtml [--launch --remove] '%s'",jobname)
+ -- report("mtxrun --script timing --xhtml [--launch --remove] '%s'",jobname)
report()
end
else
@@ -1348,6 +1360,8 @@ end
-- touching files (signals regeneration of formats)
+local newversion = false
+
local function touch(path,name,versionpattern,kind,kindpattern)
if path and path ~= "" then
name = filejoinname(path,name)
@@ -1356,9 +1370,11 @@ local function touch(path,name,versionpattern,kind,kindpattern)
end
local olddata = io.loaddata(name)
if olddata then
- local oldkind, newkind = "", kind or ""
- local oldversion, newversion = "", os.date("%Y.%m.%d %H:%M")
+ local oldkind = ""
+ local newkind = kind or ""
+ local oldversion = ""
local newdata
+ newversion = newversion or os.date("%Y.%m.%d %H:%M")
if versionpattern then
newdata = gsub(olddata,versionpattern,function(pre,mid,post)
oldversion = mid
@@ -1419,6 +1435,79 @@ function scripts.context.touch()
end
end
+function scripts.context.pages()
+ local filename = environment.files[1]
+ if filename then
+ local u = table.load(file.addsuffix(filename,"tuc"))
+ if u then
+ local p = u.structures.pages.collected
+ local l = u.structures.lists.collected
+ local page = environment.arguments.page
+ local list = environment.arguments.list
+ if type(page) == "string" then
+ page = settings_to_array(page)
+ end
+ if type(list) == "string" then
+ list = settings_to_array(list)
+ end
+ if page or list then
+ if page then
+ for i=1,#page do
+ page[i] = string.topattern(page[i])
+ end
+ for i=1,#p do
+ local pi = p[i]
+ local m = pi.marked
+ if m then
+ local ml = #m
+ for j=1,#page do
+ local n = page[j]
+ for k=1,ml do
+ if find(m[k],n) then
+ report("page : %04i %s",i,m[k])
+ end
+ end
+ end
+ end
+ end
+ end
+ if list then
+ for i=1,#list do
+ list[i] = string.topattern(list[i])
+ end
+ for i=1,#l do
+ local li = l[i]
+ local r = li.references
+ if r then
+ local rr = r.reference
+ if rr then
+ rr = splitstring(rr,",")
+ local rrl = #rr
+ for j=1,#list do
+ local n = list[j]
+ for k=1,rrl do
+ if find(rr[k],n) then
+ report("list : %04i %s",r.realpage,rr[k])
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ else
+ for i=1,#p do
+ local pi = p[i]
+ local m = pi.marked
+ if m then
+ report("page : %04i % t",i,m)
+ end
+ end
+ end
+ end
+ end
+end
+
-- modules
local labels = { "title", "comment", "status" }
@@ -1645,6 +1734,8 @@ elseif getargument("version") then
scripts.context.version()
elseif getargument("touch") then
scripts.context.touch()
+elseif getargument("pages") then
+ scripts.context.pages()
elseif getargument("expert") then
application.help("expert", "special")
elseif getargument("showmodules") or getargument("modules") then
@@ -1678,6 +1769,19 @@ elseif getargument("purge") then
elseif getargument("purgeall") then
-- only when no filename given, supports --pattern
scripts.context.purge(true,nil,true)
+elseif getargument("pattern") then
+ environment.filenames = dir.glob(getargument("pattern"))
+ scripts.context.timed(scripts.context.autoctx)
else
application.help("basic")
end
+
+-- we can wipe a signal file when done
+
+do
+
+ if getargument("wipebusy") then
+ os.remove("context-is-busy.tmp")
+ end
+
+end