summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/luatools.lua45
-rw-r--r--scripts/context/lua/mtx-context.lua2
-rw-r--r--scripts/context/lua/mtx-convert.lua2
-rw-r--r--scripts/context/lua/mtx-mptopdf.lua105
-rw-r--r--scripts/context/lua/mtx-texworks.lua24
-rw-r--r--scripts/context/lua/mtxrun.lua164
-rw-r--r--scripts/context/stubs/mswin/luatools.lua45
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua164
-rwxr-xr-xscripts/context/stubs/unix/luatools45
-rwxr-xr-xscripts/context/stubs/unix/mtxrun164
10 files changed, 527 insertions, 233 deletions
diff --git a/scripts/context/lua/luatools.lua b/scripts/context/lua/luatools.lua
index a74302b52..8568595a6 100644
--- a/scripts/context/lua/luatools.lua
+++ b/scripts/context/lua/luatools.lua
@@ -1722,21 +1722,23 @@ function os.resultof(command)
end
end
---~ os.type : windows | unix (new, we already guessed os.platform)
---~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.type : windows | unix (new, we already guessed os.platform)
+--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.platform : extended os.name with architecture
if not io.fileseparator then
if find(os.getenv("PATH"),";") then
- io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
+ io.fileseparator, io.pathseparator, os.type = "\\", ";", os.type or "mswin"
else
- io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
+ io.fileseparator, io.pathseparator, os.type = "/" , ":", os.type or "unix"
end
end
-os.platform = os.platform or os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.type = os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.name = os.name or (os.type == "windows" and "mswin" ) or "linux"
function os.launch(str)
- if os.platform == "windows" then
+ if os.type == "windows" then
os.execute("start " .. str) -- os.spawn ?
else
os.execute(str .. " &") -- os.spawn ?
@@ -1778,18 +1780,20 @@ end
-- no need for function anymore as we have more clever code and helpers now
-os.platform = os.name
+os.platform = os.name or os.type or "linux"
os.libsuffix = 'so'
+os.binsuffix = ''
local name = os.name
-if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" or os.type == "windows" then
if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
os.platform = "mswin-64"
else
os.platform = "mswin"
end
os.libsuffix = 'dll'
+ os.binsuffix = 'exe'
else
local architecture = os.getenv("HOSTTYPE") or ""
if architecture == "" then
@@ -4558,7 +4562,7 @@ resolvers.generators.notfound = { nil }
resolvers.cacheversion = '1.0.1'
resolvers.cnfname = 'texmf.cnf'
resolvers.luaname = 'texmfcnf.lua'
-resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.homedir = os.env[os.type == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
local dummy_path_expr = "^!*unset/*$"
@@ -4969,8 +4973,8 @@ function resolvers.getownpath()
resolvers.ownpath = os.selfdir
else
local binary = resolvers.ownbin
- if os.platform == "windows" then
- binary = file.replacesuffix(binary,"exe")
+ if os.binsuffix ~= "" then
+ binary = file.replacesuffix(binary,os.binsuffix)
end
for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
local b = file.join(p,binary)
@@ -6181,11 +6185,11 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
dirlist[i] = file.dirname(filelist[i][2]) .. "/"
end
end
- local doscan
if trace_detail then
logs.report("fileio","checking filename '%s'",filename)
end
-- a bit messy ... esp the doscan setting here
+ local doscan
for k=1,#pathlist do
local path = pathlist[k]
if find(path,"^!!") then doscan = false else doscan = true end
@@ -6193,22 +6197,25 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = false
-- using file list
if filelist then
+ local expression
-- compare list entries with permitted pattern -- /xx /xx//
if not find(pathname,"/$") then
- pathname = pathname .. "/"
+ expression = pathname .. "/"
+ else
+ expression = pathname
end
- pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
- pathname = gsub(pathname,"//+$", '/.*') -- later usage of pathname
- pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
- local expr = "^" .. pathname .. "$"
+ expression = gsub(expression,"([%-%.])","%%%1") -- this also influences
+ expression = gsub(expression,"//+$", '/.*') -- later usage of pathname
+ expression = gsub(expression,"//", '/.-/') -- not ok for /// but harmless
+ expression = "^" .. expression .. "$"
if trace_detail then
- logs.report("fileio","using pattern %s for path %s",expr,path)
+ logs.report("fileio","using pattern '%s' for path '%s'",expression,pathname)
end
for k=1,#filelist do
local fl = filelist[k]
local f = fl[2]
local d = dirlist[k]
- if find(d,expr) then
+ if find(d,expression) then
--- todo, test for readable
result[#result+1] = fl[3]
resolvers.register_in_trees(f) -- for tracing used files
diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua
index 857f95efd..d80c7242b 100644
--- a/scripts/context/lua/mtx-context.lua
+++ b/scripts/context/lua/mtx-context.lua
@@ -469,7 +469,7 @@ function scripts.context.multipass.makeoptionfile(jobname,ctxdata,kindofrun,curr
setalways( "\\setupsystem[inputfile=%s]",environment.argument("input") or environment.files[1] or "\\jobname")
setvalue ("result" , "\\setupsystem[file=%s]")
setalways( "\\setupsystem[\\c!n=%s,\\c!m=%s]", kindofrun or 0, currentrun or 0)
- -- setalways( "\\setupsystem[\\c!type=%s]",os.platform)
+ -- setalways( "\\setupsystem[\\c!type=%s]",os.type) -- windows or unix
setvalues("path" , "\\usepath[%s]")
setvalue ("setuppath" , "\\setupsystem[\\c!directory={%s}]")
setvalue ("randomseed" , "\\setupsystem[\\c!random=%s]")
diff --git a/scripts/context/lua/mtx-convert.lua b/scripts/context/lua/mtx-convert.lua
index cb514720e..fe43c12f2 100644
--- a/scripts/context/lua/mtx-convert.lua
+++ b/scripts/context/lua/mtx-convert.lua
@@ -11,7 +11,7 @@ if not modules then modules = { } end modules ['mtx-convert'] = {
graphics = graphics or { }
graphics.converters = graphics.converters or { }
-local gsprogram = (os.platform == "windows" and "gswin32c") or "gs"
+local gsprogram = (os.type == "windows" and "gswin32c") or "gs"
local gstemplate = "%s -q -sDEVICE=pdfwrite -dEPSCrop -dNOPAUSE -dNOCACHE -dBATCH -dAutoRotatePages=/None -dProcessColorModel=/DeviceCMYK -sOutputFile=%s %s -c quit"
function graphics.converters.eps(oldname,newname)
diff --git a/scripts/context/lua/mtx-mptopdf.lua b/scripts/context/lua/mtx-mptopdf.lua
index 4243625ad..69950e008 100644
--- a/scripts/context/lua/mtx-mptopdf.lua
+++ b/scripts/context/lua/mtx-mptopdf.lua
@@ -10,74 +10,61 @@ scripts = scripts or { }
scripts.mptopdf = scripts.mptopdf or { }
scripts.mptopdf.aux = scripts.mptopdf.aux or { }
-do
- -- setup functions and variables here
+local dosish = os.type == 'windows'
+local miktex = dosish and environment.TEXSYSTEM and environment.TEXSYSTEM:find("miktex")
+local escapeshell = environment.SHELL and environment.SHELL:find("sh") and true
- local dosish, miktex, escapeshell = false, false, false
+function scripts.mptopdf.aux.find_latex(fname)
+ local d = io.loaddata(fname) or ""
+ return d:find("\\documentstyle") or d:find("\\documentclass") or d:find("\\begin{document}")
+end
- if os.platform == 'windows' then
- dosish = true
- if environment.TEXSYSTEM and environment.TEXSYSTEM:find("miktex") then
- miktex = true
+function scripts.mptopdf.aux.do_convert (fname)
+ local command, done, pdfdest = "", 0, ""
+ if fname:find(".%d+$") or fname:find("%.mps$") then
+ if miktex then
+ command = "pdftex -undump=mptopdf"
+ else
+ command = "pdftex -fmt=mptopdf -progname=context"
end
- end
- if environment.SHELL and environment.SHELL:find("sh") then
- escapeshell = true
- end
-
- function scripts.mptopdf.aux.find_latex(fname)
- local d = io.loaddata(fname) or ""
- return d:find("\\documentstyle") or d:find("\\documentclass") or d:find("\\begin{document}")
- end
-
- function scripts.mptopdf.aux.do_convert (fname)
- local command, done, pdfdest = "", 0, ""
- if fname:find(".%d+$") or fname:find("%.mps$") then
- if miktex then
- command = "pdftex -undump=mptopdf"
- else
- command = "pdftex -fmt=mptopdf -progname=context"
- end
- if dosish then
- command = string.format('%s \\relax "%s"',command,fname)
- else
- command = string.format('%s \\\\relax "%s"',command,fname)
- end
- os.execute(command)
- local name, suffix = file.nameonly(fname), file.extname(fname)
- local pdfsrc = name .. ".pdf"
- if lfs.isfile(pdfsrc) then
- pdfdest = name .. "-" .. suffix .. ".pdf"
- os.rename(pdfsrc, pdfdest)
- if lfs.isfile(pdfsrc) then -- rename failed
- file.copy(pdfsrc, pdfdest)
- end
- done = 1
+ if dosish then
+ command = string.format('%s \\relax "%s"',command,fname)
+ else
+ command = string.format('%s \\\\relax "%s"',command,fname)
+ end
+ os.execute(command)
+ local name, suffix = file.nameonly(fname), file.extname(fname)
+ local pdfsrc = name .. ".pdf"
+ if lfs.isfile(pdfsrc) then
+ pdfdest = name .. "-" .. suffix .. ".pdf"
+ os.rename(pdfsrc, pdfdest)
+ if lfs.isfile(pdfsrc) then -- rename failed
+ file.copy(pdfsrc, pdfdest)
end
+ done = 1
end
- return done, pdfdest
end
+ return done, pdfdest
+end
- function scripts.mptopdf.aux.make_mps(fn,latex,rawmp,metafun)
- local rest, mpbin = latex and " --tex=latex " or " ", ""
- if rawmp then
- if metafun then
- mpbin = "mpost --progname=mpost --mem=metafun"
- else
- mpbin = "mpost --mem=mpost"
- end
+function scripts.mptopdf.aux.make_mps(fn,latex,rawmp,metafun)
+ local rest, mpbin = latex and " --tex=latex " or " ", ""
+ if rawmp then
+ if metafun then
+ mpbin = "mpost --progname=mpost --mem=metafun"
else
- if latex then
- mpbin = "mpost --mem=mpost"
- else
- mpbin = "texexec --mptex"
- end
+ mpbin = "mpost --mem=mpost"
end
- local runner = mpbin .. rest .. fn
- logs.simple("running: %s\n", runner)
- return (os.execute(runner))
- end
-
+ else
+ if latex then
+ mpbin = "mpost --mem=mpost"
+ else
+ mpbin = "texexec --mptex"
+ end
+ end
+ local runner = mpbin .. rest .. fn
+ logs.simple("running: %s\n", runner)
+ return (os.execute(runner))
end
function scripts.mptopdf.convertall()
diff --git a/scripts/context/lua/mtx-texworks.lua b/scripts/context/lua/mtx-texworks.lua
index 401408b32..e2063ad7e 100644
--- a/scripts/context/lua/mtx-texworks.lua
+++ b/scripts/context/lua/mtx-texworks.lua
@@ -23,26 +23,28 @@ local texworkssignal = "texworks-context.rme"
local texworkininame = "texworks.ini"
function scripts.texworks.start(indeed)
- local is_mswin = os.platform == "windows"
- local workname = (is_mswin and "texworks.exe") or "texworks"
+ local workname = (os.type == "windows" and "texworks.exe") or "texworks"
local fullname = nil
local binpaths = file.split_path(os.getenv("PATH")) or file.split_path(os.getenv("path"))
- local datapath = resolvers.find_file(texworkssignal,"other text files") or ""
+ local usedsignal = texworkssignal
+ local datapath = resolvers.find_file(usedsignal,"other text files") or ""
if datapath ~= "" then
datapath = file.dirname(datapath) -- data
if datapath == "" then
- datapath = resolvers.ownpath
+ datapath = resolvers.clean_path(lfs.currentdir())
end
else
- datapath = resolvers.find_file(texworkininame,"other text files") or ""
+ usedsignal = texworkininame
+ datapath = resolvers.find_file(usedsignal,"other text files") or ""
if datapath == "" then
- datapath = resolvers.find_file(string.lower(texworkininame),"other text files") or ""
+ usedsignal = string.lower(usedsignal)
+ datapath = resolvers.find_file(usedsignal,"other text files") or ""
end
if datapath ~= "" and lfs.isfile(datapath) then
datapath = file.dirname(datapath) -- TUG
datapath = file.dirname(datapath) -- data
if datapath == "" then
- datapath = resolvers.ownpath
+ datapath = resolvers.clean_path(lfs.currentdir())
end
end
end
@@ -56,7 +58,7 @@ function scripts.texworks.start(indeed)
end
for i=1,#binpaths do
local p = file.join(binpaths[i],workname)
- if lfs.isfile(p) then
+ if lfs.isfile(p) and lfs.attributes(p,"size") > 10000 then -- avoind stub
fullname = p
break
end
@@ -71,8 +73,10 @@ function scripts.texworks.start(indeed)
os.setenv("TW_INIPATH",datapath)
os.setenv("TW_LIBPATH",datapath)
if not indeed or environment.argument("verbose") then
- logs.simple("data path: %s", datapath)
- logs.simple("full name: %s", fullname)
+ logs.simple("used signal: %s", usedsignal)
+ logs.simple("data path : %s", datapath)
+ logs.simple("full name : %s", fullname)
+ logs.simple("set paths : TW_INIPATH TW_LIBPATH")
end
if indeed then
os.launch(fullname)
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 4ebfc1124..89cda6978 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -1731,21 +1731,23 @@ function os.resultof(command)
end
end
---~ os.type : windows | unix (new, we already guessed os.platform)
---~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.type : windows | unix (new, we already guessed os.platform)
+--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.platform : extended os.name with architecture
if not io.fileseparator then
if find(os.getenv("PATH"),";") then
- io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
+ io.fileseparator, io.pathseparator, os.type = "\\", ";", os.type or "mswin"
else
- io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
+ io.fileseparator, io.pathseparator, os.type = "/" , ":", os.type or "unix"
end
end
-os.platform = os.platform or os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.type = os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.name = os.name or (os.type == "windows" and "mswin" ) or "linux"
function os.launch(str)
- if os.platform == "windows" then
+ if os.type == "windows" then
os.execute("start " .. str) -- os.spawn ?
else
os.execute(str .. " &") -- os.spawn ?
@@ -1787,18 +1789,20 @@ end
-- no need for function anymore as we have more clever code and helpers now
-os.platform = os.name
+os.platform = os.name or os.type or "linux"
os.libsuffix = 'so'
+os.binsuffix = ''
local name = os.name
-if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" or os.type == "windows" then
if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
os.platform = "mswin-64"
else
os.platform = "mswin"
end
os.libsuffix = 'dll'
+ os.binsuffix = 'exe'
else
local architecture = os.getenv("HOSTTYPE") or ""
if architecture == "" then
@@ -4484,6 +4488,9 @@ local concat, remove, insert = table.concat, table.remove, table.insert
local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
local format, upper, lower, gmatch, gsub, find, rep = string.format, string.upper, string.lower, string.gmatch, string.gsub, string.find, string.rep
+-- beware, this is not xpath ... e.g. position is different (currently) and
+-- we have reverse-sibling as reversed preceding sibling
+
--[[ldx--
<p>This module can be used stand alone but also inside <l n='mkiv'/> in
which case it hooks into the tracker code. Therefore we provide a few
@@ -4711,7 +4718,43 @@ apply_axis['attribute'] = function(list)
return { }
end
-apply_axis['following'] = function(list)
+apply_axis['namespace'] = function(list)
+ return { }
+end
+
+apply_axis['following'] = function(list) -- incomplete
+--~ local collected = { }
+--~ for l=1,#list do
+--~ local ll = list[l]
+--~ local p = ll.__p__
+--~ local d = p.dt
+--~ for i=ll.ni+1,#d do
+--~ local di = d[i]
+--~ if type(di) == "table" then
+--~ collected[#collected+1] = di
+--~ break
+--~ end
+--~ end
+--~ end
+--~ return collected
+ return { }
+end
+
+apply_axis['preceding'] = function(list) -- incomplete
+--~ local collected = { }
+--~ for l=1,#list do
+--~ local ll = list[l]
+--~ local p = ll.__p__
+--~ local d = p.dt
+--~ for i=ll.ni-1,1,-1 do
+--~ local di = d[i]
+--~ if type(di) == "table" then
+--~ collected[#collected+1] = di
+--~ break
+--~ end
+--~ end
+--~ end
+--~ return collected
return { }
end
@@ -4719,25 +4762,48 @@ apply_axis['following-sibling'] = function(list)
local collected = { }
for l=1,#list do
local ll = list[l]
-print(xml.tostring(ll))
- if ll.special ~= true then -- catch double root
- collected[#collected+1] = ll
+ local p = ll.__p__
+ local d = p.dt
+ for i=ll.ni+1,#d do
+ local di = d[i]
+ if type(di) == "table" then
+ collected[#collected+1] = di
+ end
end
end
return collected
---~ return { }
end
-apply_axis['namespace'] = function(list)
- return { }
-end
-
-apply_axis['preceding'] = function(list)
- return { }
+apply_axis['preceding-sibling'] = function(list)
+ local collected = { }
+ for l=1,#list do
+ local ll = list[l]
+ local p = ll.__p__
+ local d = p.dt
+ for i=1,ll.ni-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ collected[#collected+1] = di
+ end
+ end
+ end
+ return collected
end
-apply_axis['preceding-sibling'] = function(list)
- return { }
+apply_axis['reverse-sibling'] = function(list) -- reverse preceding
+ local collected = { }
+ for l=1,#list do
+ local ll = list[l]
+ local p = ll.__p__
+ local d = p.dt
+ for i=ll.ni-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ collected[#collected+1] = di
+ end
+ end
+ end
+ return collected
end
apply_axis['auto-descendant-or-self'] = apply_axis['descendant-or-self']
@@ -4843,13 +4909,19 @@ local function apply_nodes(list,directive,nodes)
end
end
+local quit_expression = false
+
local function apply_expression(list,expression,order)
local collected = { }
+ quit_expression = false
for l=1,#list do
local ll = list[l]
if expression(list,ll,l,order) then -- nasty, alleen valid als n=1
collected[#collected+1] = ll
end
+ if quit_expression then
+ break
+ end
end
return collected
end
@@ -4873,7 +4945,8 @@ local lp_builtin = P (
P("index") / "(ll.ni or 1)" +
P("match") / "(ll.mi or 1)" +
P("text") / "(ll.dt[1] or '')" +
- P("name") / "(ll.ns~='' and ll.ns..':'..ll.tg)" +
+--~ P("name") / "(ll.ns~='' and ll.ns..':'..ll.tg)" +
+ P("name") / "((ll.ns~='' and ll.ns..':'..ll.tg) or ll.tg)" +
P("tag") / "ll.tg" +
P("ns") / "ll.ns"
) * ((spaces * P("(") * spaces * P(")"))/"")
@@ -4903,6 +4976,7 @@ local nested = lpeg.P{lparent * (noparent + lpeg.V(1))^0 * rparent}
local value = lpeg.P(lparent * lpeg.C((noparent + nested)^0) * rparent) -- lpeg.P{"("*C(((1-S("()"))+V(1))^0)*")"}
local lp_child = Cc("expr.child(ll,'") * R("az","AZ","--","__")^1 * Cc("')")
+local lp_number = S("+-") * R("09")^1
local lp_string = Cc("'") * R("az","AZ","--","__")^1 * Cc("'")
local lp_content = (P("'") * (1-P("'"))^0 * P("'") + P('"') * (1-P('"'))^0 * P('"'))
@@ -4911,6 +4985,7 @@ local cleaner
local lp_special = (C(P("name")+P("text")+P("tag")+P("count")+P("child"))) * value / function(t,s)
if expressions[t] then
s = s and s ~= "" and cleaner:match(s)
+--~ print("!!!",t,s)
if s and s ~= "" then
return "expr." .. t .. "(ll," .. s ..")"
else
@@ -4940,9 +5015,11 @@ local converter = Cs (
cleaner = Cs ( (
--~ lp_fastpos +
lp_reserved +
+ lp_number +
lp_string +
1 )^1 )
+
--~ expr
local template_e = [[
@@ -5025,6 +5102,7 @@ local register_following = { kind = "axis", axis = "following"
local register_following_sibling = { kind = "axis", axis = "following-sibling" } -- , apply = apply_axis["following-sibling"] }
local register_preceding = { kind = "axis", axis = "preceding" } -- , apply = apply_axis["preceding"] }
local register_preceding_sibling = { kind = "axis", axis = "preceding-sibling" } -- , apply = apply_axis["preceding-sibling"] }
+local register_reverse_sibling = { kind = "axis", axis = "reverse-sibling" } -- , apply = apply_axis["reverse-sibling"] }
local register_auto_descendant_or_self = { kind = "axis", axis = "auto-descendant-or-self" } -- , apply = apply_axis["auto-descendant-or-self"] }
local register_auto_descendant = { kind = "axis", axis = "auto-descendant" } -- , apply = apply_axis["auto-descendant"] }
@@ -5051,8 +5129,8 @@ local parser = Ct { "patterns", -- can be made a bit faster by moving pattern ou
step = ((V("shortcuts") + P("/") + V("axis")) * spaces * V("nodes")^0 + V("error")) * spaces * V("expressions")^0 * spaces * V("finalizer")^0,
axis = V("descendant") + V("child") + V("parent") + V("self") + V("root") + V("ancestor") +
- V("descendant_or_self") + V("following") + V("following_sibling") +
- V("preceding") + V("preceding_sibling") + V("ancestor_or_self") +
+ V("descendant_or_self") + V("following_sibling") + V("following") +
+ V("reverse_sibling") + V("preceding_sibling") + V("preceding") + V("ancestor_or_self") +
#(1-P(-1)) * Cc(register_auto_child),
initial = (P("/") * spaces * Cc(register_initial_child))^-1,
@@ -5086,6 +5164,7 @@ local parser = Ct { "patterns", -- can be made a bit faster by moving pattern ou
following_sibling = P('following-sibling::') * Cc(register_following_sibling ),
preceding = P('preceding::') * Cc(register_preceding ),
preceding_sibling = P('preceding-sibling::') * Cc(register_preceding_sibling ),
+ reverse_sibling = P('reverse-sibling::') * Cc(register_reverse_sibling ),
nodes = (V("nodefunction") * spaces * P("(") * V("nodeset") * P(")") + V("nodetest") * V("nodeset")) / register_nodes,
@@ -5350,6 +5429,18 @@ expressions.undefined = function(s)
return s == nil
end
+expressions.quit = function(s)
+ if s or s == nil then
+ quit_expression = true
+ end
+ return true
+end
+
+expressions.print = function(...)
+ print(...)
+ return true
+end
+
expressions.contains = find
expressions.find = find
expressions.upper = upper
@@ -7292,7 +7383,7 @@ resolvers.generators.notfound = { nil }
resolvers.cacheversion = '1.0.1'
resolvers.cnfname = 'texmf.cnf'
resolvers.luaname = 'texmfcnf.lua'
-resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.homedir = os.env[os.type == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
local dummy_path_expr = "^!*unset/*$"
@@ -7703,8 +7794,8 @@ function resolvers.getownpath()
resolvers.ownpath = os.selfdir
else
local binary = resolvers.ownbin
- if os.platform == "windows" then
- binary = file.replacesuffix(binary,"exe")
+ if os.binsuffix ~= "" then
+ binary = file.replacesuffix(binary,os.binsuffix)
end
for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
local b = file.join(p,binary)
@@ -8915,11 +9006,11 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
dirlist[i] = file.dirname(filelist[i][2]) .. "/"
end
end
- local doscan
if trace_detail then
logs.report("fileio","checking filename '%s'",filename)
end
-- a bit messy ... esp the doscan setting here
+ local doscan
for k=1,#pathlist do
local path = pathlist[k]
if find(path,"^!!") then doscan = false else doscan = true end
@@ -8927,22 +9018,25 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = false
-- using file list
if filelist then
+ local expression
-- compare list entries with permitted pattern -- /xx /xx//
if not find(pathname,"/$") then
- pathname = pathname .. "/"
+ expression = pathname .. "/"
+ else
+ expression = pathname
end
- pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
- pathname = gsub(pathname,"//+$", '/.*') -- later usage of pathname
- pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
- local expr = "^" .. pathname .. "$"
+ expression = gsub(expression,"([%-%.])","%%%1") -- this also influences
+ expression = gsub(expression,"//+$", '/.*') -- later usage of pathname
+ expression = gsub(expression,"//", '/.-/') -- not ok for /// but harmless
+ expression = "^" .. expression .. "$"
if trace_detail then
- logs.report("fileio","using pattern %s for path %s",expr,path)
+ logs.report("fileio","using pattern '%s' for path '%s'",expression,pathname)
end
for k=1,#filelist do
local fl = filelist[k]
local f = fl[2]
local d = dirlist[k]
- if find(d,expr) then
+ if find(d,expression) then
--- todo, test for readable
result[#result+1] = fl[3]
resolvers.register_in_trees(f) -- for tracing used files
diff --git a/scripts/context/stubs/mswin/luatools.lua b/scripts/context/stubs/mswin/luatools.lua
index a74302b52..8568595a6 100644
--- a/scripts/context/stubs/mswin/luatools.lua
+++ b/scripts/context/stubs/mswin/luatools.lua
@@ -1722,21 +1722,23 @@ function os.resultof(command)
end
end
---~ os.type : windows | unix (new, we already guessed os.platform)
---~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.type : windows | unix (new, we already guessed os.platform)
+--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.platform : extended os.name with architecture
if not io.fileseparator then
if find(os.getenv("PATH"),";") then
- io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
+ io.fileseparator, io.pathseparator, os.type = "\\", ";", os.type or "mswin"
else
- io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
+ io.fileseparator, io.pathseparator, os.type = "/" , ":", os.type or "unix"
end
end
-os.platform = os.platform or os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.type = os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.name = os.name or (os.type == "windows" and "mswin" ) or "linux"
function os.launch(str)
- if os.platform == "windows" then
+ if os.type == "windows" then
os.execute("start " .. str) -- os.spawn ?
else
os.execute(str .. " &") -- os.spawn ?
@@ -1778,18 +1780,20 @@ end
-- no need for function anymore as we have more clever code and helpers now
-os.platform = os.name
+os.platform = os.name or os.type or "linux"
os.libsuffix = 'so'
+os.binsuffix = ''
local name = os.name
-if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" or os.type == "windows" then
if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
os.platform = "mswin-64"
else
os.platform = "mswin"
end
os.libsuffix = 'dll'
+ os.binsuffix = 'exe'
else
local architecture = os.getenv("HOSTTYPE") or ""
if architecture == "" then
@@ -4558,7 +4562,7 @@ resolvers.generators.notfound = { nil }
resolvers.cacheversion = '1.0.1'
resolvers.cnfname = 'texmf.cnf'
resolvers.luaname = 'texmfcnf.lua'
-resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.homedir = os.env[os.type == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
local dummy_path_expr = "^!*unset/*$"
@@ -4969,8 +4973,8 @@ function resolvers.getownpath()
resolvers.ownpath = os.selfdir
else
local binary = resolvers.ownbin
- if os.platform == "windows" then
- binary = file.replacesuffix(binary,"exe")
+ if os.binsuffix ~= "" then
+ binary = file.replacesuffix(binary,os.binsuffix)
end
for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
local b = file.join(p,binary)
@@ -6181,11 +6185,11 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
dirlist[i] = file.dirname(filelist[i][2]) .. "/"
end
end
- local doscan
if trace_detail then
logs.report("fileio","checking filename '%s'",filename)
end
-- a bit messy ... esp the doscan setting here
+ local doscan
for k=1,#pathlist do
local path = pathlist[k]
if find(path,"^!!") then doscan = false else doscan = true end
@@ -6193,22 +6197,25 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = false
-- using file list
if filelist then
+ local expression
-- compare list entries with permitted pattern -- /xx /xx//
if not find(pathname,"/$") then
- pathname = pathname .. "/"
+ expression = pathname .. "/"
+ else
+ expression = pathname
end
- pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
- pathname = gsub(pathname,"//+$", '/.*') -- later usage of pathname
- pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
- local expr = "^" .. pathname .. "$"
+ expression = gsub(expression,"([%-%.])","%%%1") -- this also influences
+ expression = gsub(expression,"//+$", '/.*') -- later usage of pathname
+ expression = gsub(expression,"//", '/.-/') -- not ok for /// but harmless
+ expression = "^" .. expression .. "$"
if trace_detail then
- logs.report("fileio","using pattern %s for path %s",expr,path)
+ logs.report("fileio","using pattern '%s' for path '%s'",expression,pathname)
end
for k=1,#filelist do
local fl = filelist[k]
local f = fl[2]
local d = dirlist[k]
- if find(d,expr) then
+ if find(d,expression) then
--- todo, test for readable
result[#result+1] = fl[3]
resolvers.register_in_trees(f) -- for tracing used files
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index 4ebfc1124..89cda6978 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -1731,21 +1731,23 @@ function os.resultof(command)
end
end
---~ os.type : windows | unix (new, we already guessed os.platform)
---~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.type : windows | unix (new, we already guessed os.platform)
+--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.platform : extended os.name with architecture
if not io.fileseparator then
if find(os.getenv("PATH"),";") then
- io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
+ io.fileseparator, io.pathseparator, os.type = "\\", ";", os.type or "mswin"
else
- io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
+ io.fileseparator, io.pathseparator, os.type = "/" , ":", os.type or "unix"
end
end
-os.platform = os.platform or os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.type = os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.name = os.name or (os.type == "windows" and "mswin" ) or "linux"
function os.launch(str)
- if os.platform == "windows" then
+ if os.type == "windows" then
os.execute("start " .. str) -- os.spawn ?
else
os.execute(str .. " &") -- os.spawn ?
@@ -1787,18 +1789,20 @@ end
-- no need for function anymore as we have more clever code and helpers now
-os.platform = os.name
+os.platform = os.name or os.type or "linux"
os.libsuffix = 'so'
+os.binsuffix = ''
local name = os.name
-if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" or os.type == "windows" then
if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
os.platform = "mswin-64"
else
os.platform = "mswin"
end
os.libsuffix = 'dll'
+ os.binsuffix = 'exe'
else
local architecture = os.getenv("HOSTTYPE") or ""
if architecture == "" then
@@ -4484,6 +4488,9 @@ local concat, remove, insert = table.concat, table.remove, table.insert
local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
local format, upper, lower, gmatch, gsub, find, rep = string.format, string.upper, string.lower, string.gmatch, string.gsub, string.find, string.rep
+-- beware, this is not xpath ... e.g. position is different (currently) and
+-- we have reverse-sibling as reversed preceding sibling
+
--[[ldx--
<p>This module can be used stand alone but also inside <l n='mkiv'/> in
which case it hooks into the tracker code. Therefore we provide a few
@@ -4711,7 +4718,43 @@ apply_axis['attribute'] = function(list)
return { }
end
-apply_axis['following'] = function(list)
+apply_axis['namespace'] = function(list)
+ return { }
+end
+
+apply_axis['following'] = function(list) -- incomplete
+--~ local collected = { }
+--~ for l=1,#list do
+--~ local ll = list[l]
+--~ local p = ll.__p__
+--~ local d = p.dt
+--~ for i=ll.ni+1,#d do
+--~ local di = d[i]
+--~ if type(di) == "table" then
+--~ collected[#collected+1] = di
+--~ break
+--~ end
+--~ end
+--~ end
+--~ return collected
+ return { }
+end
+
+apply_axis['preceding'] = function(list) -- incomplete
+--~ local collected = { }
+--~ for l=1,#list do
+--~ local ll = list[l]
+--~ local p = ll.__p__
+--~ local d = p.dt
+--~ for i=ll.ni-1,1,-1 do
+--~ local di = d[i]
+--~ if type(di) == "table" then
+--~ collected[#collected+1] = di
+--~ break
+--~ end
+--~ end
+--~ end
+--~ return collected
return { }
end
@@ -4719,25 +4762,48 @@ apply_axis['following-sibling'] = function(list)
local collected = { }
for l=1,#list do
local ll = list[l]
-print(xml.tostring(ll))
- if ll.special ~= true then -- catch double root
- collected[#collected+1] = ll
+ local p = ll.__p__
+ local d = p.dt
+ for i=ll.ni+1,#d do
+ local di = d[i]
+ if type(di) == "table" then
+ collected[#collected+1] = di
+ end
end
end
return collected
---~ return { }
end
-apply_axis['namespace'] = function(list)
- return { }
-end
-
-apply_axis['preceding'] = function(list)
- return { }
+apply_axis['preceding-sibling'] = function(list)
+ local collected = { }
+ for l=1,#list do
+ local ll = list[l]
+ local p = ll.__p__
+ local d = p.dt
+ for i=1,ll.ni-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ collected[#collected+1] = di
+ end
+ end
+ end
+ return collected
end
-apply_axis['preceding-sibling'] = function(list)
- return { }
+apply_axis['reverse-sibling'] = function(list) -- reverse preceding
+ local collected = { }
+ for l=1,#list do
+ local ll = list[l]
+ local p = ll.__p__
+ local d = p.dt
+ for i=ll.ni-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ collected[#collected+1] = di
+ end
+ end
+ end
+ return collected
end
apply_axis['auto-descendant-or-self'] = apply_axis['descendant-or-self']
@@ -4843,13 +4909,19 @@ local function apply_nodes(list,directive,nodes)
end
end
+local quit_expression = false
+
local function apply_expression(list,expression,order)
local collected = { }
+ quit_expression = false
for l=1,#list do
local ll = list[l]
if expression(list,ll,l,order) then -- nasty, alleen valid als n=1
collected[#collected+1] = ll
end
+ if quit_expression then
+ break
+ end
end
return collected
end
@@ -4873,7 +4945,8 @@ local lp_builtin = P (
P("index") / "(ll.ni or 1)" +
P("match") / "(ll.mi or 1)" +
P("text") / "(ll.dt[1] or '')" +
- P("name") / "(ll.ns~='' and ll.ns..':'..ll.tg)" +
+--~ P("name") / "(ll.ns~='' and ll.ns..':'..ll.tg)" +
+ P("name") / "((ll.ns~='' and ll.ns..':'..ll.tg) or ll.tg)" +
P("tag") / "ll.tg" +
P("ns") / "ll.ns"
) * ((spaces * P("(") * spaces * P(")"))/"")
@@ -4903,6 +4976,7 @@ local nested = lpeg.P{lparent * (noparent + lpeg.V(1))^0 * rparent}
local value = lpeg.P(lparent * lpeg.C((noparent + nested)^0) * rparent) -- lpeg.P{"("*C(((1-S("()"))+V(1))^0)*")"}
local lp_child = Cc("expr.child(ll,'") * R("az","AZ","--","__")^1 * Cc("')")
+local lp_number = S("+-") * R("09")^1
local lp_string = Cc("'") * R("az","AZ","--","__")^1 * Cc("'")
local lp_content = (P("'") * (1-P("'"))^0 * P("'") + P('"') * (1-P('"'))^0 * P('"'))
@@ -4911,6 +4985,7 @@ local cleaner
local lp_special = (C(P("name")+P("text")+P("tag")+P("count")+P("child"))) * value / function(t,s)
if expressions[t] then
s = s and s ~= "" and cleaner:match(s)
+--~ print("!!!",t,s)
if s and s ~= "" then
return "expr." .. t .. "(ll," .. s ..")"
else
@@ -4940,9 +5015,11 @@ local converter = Cs (
cleaner = Cs ( (
--~ lp_fastpos +
lp_reserved +
+ lp_number +
lp_string +
1 )^1 )
+
--~ expr
local template_e = [[
@@ -5025,6 +5102,7 @@ local register_following = { kind = "axis", axis = "following"
local register_following_sibling = { kind = "axis", axis = "following-sibling" } -- , apply = apply_axis["following-sibling"] }
local register_preceding = { kind = "axis", axis = "preceding" } -- , apply = apply_axis["preceding"] }
local register_preceding_sibling = { kind = "axis", axis = "preceding-sibling" } -- , apply = apply_axis["preceding-sibling"] }
+local register_reverse_sibling = { kind = "axis", axis = "reverse-sibling" } -- , apply = apply_axis["reverse-sibling"] }
local register_auto_descendant_or_self = { kind = "axis", axis = "auto-descendant-or-self" } -- , apply = apply_axis["auto-descendant-or-self"] }
local register_auto_descendant = { kind = "axis", axis = "auto-descendant" } -- , apply = apply_axis["auto-descendant"] }
@@ -5051,8 +5129,8 @@ local parser = Ct { "patterns", -- can be made a bit faster by moving pattern ou
step = ((V("shortcuts") + P("/") + V("axis")) * spaces * V("nodes")^0 + V("error")) * spaces * V("expressions")^0 * spaces * V("finalizer")^0,
axis = V("descendant") + V("child") + V("parent") + V("self") + V("root") + V("ancestor") +
- V("descendant_or_self") + V("following") + V("following_sibling") +
- V("preceding") + V("preceding_sibling") + V("ancestor_or_self") +
+ V("descendant_or_self") + V("following_sibling") + V("following") +
+ V("reverse_sibling") + V("preceding_sibling") + V("preceding") + V("ancestor_or_self") +
#(1-P(-1)) * Cc(register_auto_child),
initial = (P("/") * spaces * Cc(register_initial_child))^-1,
@@ -5086,6 +5164,7 @@ local parser = Ct { "patterns", -- can be made a bit faster by moving pattern ou
following_sibling = P('following-sibling::') * Cc(register_following_sibling ),
preceding = P('preceding::') * Cc(register_preceding ),
preceding_sibling = P('preceding-sibling::') * Cc(register_preceding_sibling ),
+ reverse_sibling = P('reverse-sibling::') * Cc(register_reverse_sibling ),
nodes = (V("nodefunction") * spaces * P("(") * V("nodeset") * P(")") + V("nodetest") * V("nodeset")) / register_nodes,
@@ -5350,6 +5429,18 @@ expressions.undefined = function(s)
return s == nil
end
+expressions.quit = function(s)
+ if s or s == nil then
+ quit_expression = true
+ end
+ return true
+end
+
+expressions.print = function(...)
+ print(...)
+ return true
+end
+
expressions.contains = find
expressions.find = find
expressions.upper = upper
@@ -7292,7 +7383,7 @@ resolvers.generators.notfound = { nil }
resolvers.cacheversion = '1.0.1'
resolvers.cnfname = 'texmf.cnf'
resolvers.luaname = 'texmfcnf.lua'
-resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.homedir = os.env[os.type == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
local dummy_path_expr = "^!*unset/*$"
@@ -7703,8 +7794,8 @@ function resolvers.getownpath()
resolvers.ownpath = os.selfdir
else
local binary = resolvers.ownbin
- if os.platform == "windows" then
- binary = file.replacesuffix(binary,"exe")
+ if os.binsuffix ~= "" then
+ binary = file.replacesuffix(binary,os.binsuffix)
end
for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
local b = file.join(p,binary)
@@ -8915,11 +9006,11 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
dirlist[i] = file.dirname(filelist[i][2]) .. "/"
end
end
- local doscan
if trace_detail then
logs.report("fileio","checking filename '%s'",filename)
end
-- a bit messy ... esp the doscan setting here
+ local doscan
for k=1,#pathlist do
local path = pathlist[k]
if find(path,"^!!") then doscan = false else doscan = true end
@@ -8927,22 +9018,25 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = false
-- using file list
if filelist then
+ local expression
-- compare list entries with permitted pattern -- /xx /xx//
if not find(pathname,"/$") then
- pathname = pathname .. "/"
+ expression = pathname .. "/"
+ else
+ expression = pathname
end
- pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
- pathname = gsub(pathname,"//+$", '/.*') -- later usage of pathname
- pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
- local expr = "^" .. pathname .. "$"
+ expression = gsub(expression,"([%-%.])","%%%1") -- this also influences
+ expression = gsub(expression,"//+$", '/.*') -- later usage of pathname
+ expression = gsub(expression,"//", '/.-/') -- not ok for /// but harmless
+ expression = "^" .. expression .. "$"
if trace_detail then
- logs.report("fileio","using pattern %s for path %s",expr,path)
+ logs.report("fileio","using pattern '%s' for path '%s'",expression,pathname)
end
for k=1,#filelist do
local fl = filelist[k]
local f = fl[2]
local d = dirlist[k]
- if find(d,expr) then
+ if find(d,expression) then
--- todo, test for readable
result[#result+1] = fl[3]
resolvers.register_in_trees(f) -- for tracing used files
diff --git a/scripts/context/stubs/unix/luatools b/scripts/context/stubs/unix/luatools
index a74302b52..8568595a6 100755
--- a/scripts/context/stubs/unix/luatools
+++ b/scripts/context/stubs/unix/luatools
@@ -1722,21 +1722,23 @@ function os.resultof(command)
end
end
---~ os.type : windows | unix (new, we already guessed os.platform)
---~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.type : windows | unix (new, we already guessed os.platform)
+--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.platform : extended os.name with architecture
if not io.fileseparator then
if find(os.getenv("PATH"),";") then
- io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
+ io.fileseparator, io.pathseparator, os.type = "\\", ";", os.type or "mswin"
else
- io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
+ io.fileseparator, io.pathseparator, os.type = "/" , ":", os.type or "unix"
end
end
-os.platform = os.platform or os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.type = os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.name = os.name or (os.type == "windows" and "mswin" ) or "linux"
function os.launch(str)
- if os.platform == "windows" then
+ if os.type == "windows" then
os.execute("start " .. str) -- os.spawn ?
else
os.execute(str .. " &") -- os.spawn ?
@@ -1778,18 +1780,20 @@ end
-- no need for function anymore as we have more clever code and helpers now
-os.platform = os.name
+os.platform = os.name or os.type or "linux"
os.libsuffix = 'so'
+os.binsuffix = ''
local name = os.name
-if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" or os.type == "windows" then
if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
os.platform = "mswin-64"
else
os.platform = "mswin"
end
os.libsuffix = 'dll'
+ os.binsuffix = 'exe'
else
local architecture = os.getenv("HOSTTYPE") or ""
if architecture == "" then
@@ -4558,7 +4562,7 @@ resolvers.generators.notfound = { nil }
resolvers.cacheversion = '1.0.1'
resolvers.cnfname = 'texmf.cnf'
resolvers.luaname = 'texmfcnf.lua'
-resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.homedir = os.env[os.type == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
local dummy_path_expr = "^!*unset/*$"
@@ -4969,8 +4973,8 @@ function resolvers.getownpath()
resolvers.ownpath = os.selfdir
else
local binary = resolvers.ownbin
- if os.platform == "windows" then
- binary = file.replacesuffix(binary,"exe")
+ if os.binsuffix ~= "" then
+ binary = file.replacesuffix(binary,os.binsuffix)
end
for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
local b = file.join(p,binary)
@@ -6181,11 +6185,11 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
dirlist[i] = file.dirname(filelist[i][2]) .. "/"
end
end
- local doscan
if trace_detail then
logs.report("fileio","checking filename '%s'",filename)
end
-- a bit messy ... esp the doscan setting here
+ local doscan
for k=1,#pathlist do
local path = pathlist[k]
if find(path,"^!!") then doscan = false else doscan = true end
@@ -6193,22 +6197,25 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = false
-- using file list
if filelist then
+ local expression
-- compare list entries with permitted pattern -- /xx /xx//
if not find(pathname,"/$") then
- pathname = pathname .. "/"
+ expression = pathname .. "/"
+ else
+ expression = pathname
end
- pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
- pathname = gsub(pathname,"//+$", '/.*') -- later usage of pathname
- pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
- local expr = "^" .. pathname .. "$"
+ expression = gsub(expression,"([%-%.])","%%%1") -- this also influences
+ expression = gsub(expression,"//+$", '/.*') -- later usage of pathname
+ expression = gsub(expression,"//", '/.-/') -- not ok for /// but harmless
+ expression = "^" .. expression .. "$"
if trace_detail then
- logs.report("fileio","using pattern %s for path %s",expr,path)
+ logs.report("fileio","using pattern '%s' for path '%s'",expression,pathname)
end
for k=1,#filelist do
local fl = filelist[k]
local f = fl[2]
local d = dirlist[k]
- if find(d,expr) then
+ if find(d,expression) then
--- todo, test for readable
result[#result+1] = fl[3]
resolvers.register_in_trees(f) -- for tracing used files
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index 4ebfc1124..89cda6978 100755
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -1731,21 +1731,23 @@ function os.resultof(command)
end
end
---~ os.type : windows | unix (new, we already guessed os.platform)
---~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.type : windows | unix (new, we already guessed os.platform)
+--~ os.name : windows | msdos | linux | macosx | solaris | .. | generic (new)
+--~ os.platform : extended os.name with architecture
if not io.fileseparator then
if find(os.getenv("PATH"),";") then
- io.fileseparator, io.pathseparator, os.platform = "\\", ";", os.type or "windows"
+ io.fileseparator, io.pathseparator, os.type = "\\", ";", os.type or "mswin"
else
- io.fileseparator, io.pathseparator, os.platform = "/" , ":", os.type or "unix"
+ io.fileseparator, io.pathseparator, os.type = "/" , ":", os.type or "unix"
end
end
-os.platform = os.platform or os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.type = os.type or (io.pathseparator == ";" and "windows") or "unix"
+os.name = os.name or (os.type == "windows" and "mswin" ) or "linux"
function os.launch(str)
- if os.platform == "windows" then
+ if os.type == "windows" then
os.execute("start " .. str) -- os.spawn ?
else
os.execute(str .. " &") -- os.spawn ?
@@ -1787,18 +1789,20 @@ end
-- no need for function anymore as we have more clever code and helpers now
-os.platform = os.name
+os.platform = os.name or os.type or "linux"
os.libsuffix = 'so'
+os.binsuffix = ''
local name = os.name
-if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" then
+if name == "windows" or name == "mswin" or name == "win32" or name == "msdos" or os.type == "windows" then
if os.getenv("PROCESSOR_ARCHITECTURE") == "AMD64" then
os.platform = "mswin-64"
else
os.platform = "mswin"
end
os.libsuffix = 'dll'
+ os.binsuffix = 'exe'
else
local architecture = os.getenv("HOSTTYPE") or ""
if architecture == "" then
@@ -4484,6 +4488,9 @@ local concat, remove, insert = table.concat, table.remove, table.insert
local type, next, tonumber, tostring, setmetatable, loadstring = type, next, tonumber, tostring, setmetatable, loadstring
local format, upper, lower, gmatch, gsub, find, rep = string.format, string.upper, string.lower, string.gmatch, string.gsub, string.find, string.rep
+-- beware, this is not xpath ... e.g. position is different (currently) and
+-- we have reverse-sibling as reversed preceding sibling
+
--[[ldx--
<p>This module can be used stand alone but also inside <l n='mkiv'/> in
which case it hooks into the tracker code. Therefore we provide a few
@@ -4711,7 +4718,43 @@ apply_axis['attribute'] = function(list)
return { }
end
-apply_axis['following'] = function(list)
+apply_axis['namespace'] = function(list)
+ return { }
+end
+
+apply_axis['following'] = function(list) -- incomplete
+--~ local collected = { }
+--~ for l=1,#list do
+--~ local ll = list[l]
+--~ local p = ll.__p__
+--~ local d = p.dt
+--~ for i=ll.ni+1,#d do
+--~ local di = d[i]
+--~ if type(di) == "table" then
+--~ collected[#collected+1] = di
+--~ break
+--~ end
+--~ end
+--~ end
+--~ return collected
+ return { }
+end
+
+apply_axis['preceding'] = function(list) -- incomplete
+--~ local collected = { }
+--~ for l=1,#list do
+--~ local ll = list[l]
+--~ local p = ll.__p__
+--~ local d = p.dt
+--~ for i=ll.ni-1,1,-1 do
+--~ local di = d[i]
+--~ if type(di) == "table" then
+--~ collected[#collected+1] = di
+--~ break
+--~ end
+--~ end
+--~ end
+--~ return collected
return { }
end
@@ -4719,25 +4762,48 @@ apply_axis['following-sibling'] = function(list)
local collected = { }
for l=1,#list do
local ll = list[l]
-print(xml.tostring(ll))
- if ll.special ~= true then -- catch double root
- collected[#collected+1] = ll
+ local p = ll.__p__
+ local d = p.dt
+ for i=ll.ni+1,#d do
+ local di = d[i]
+ if type(di) == "table" then
+ collected[#collected+1] = di
+ end
end
end
return collected
---~ return { }
end
-apply_axis['namespace'] = function(list)
- return { }
-end
-
-apply_axis['preceding'] = function(list)
- return { }
+apply_axis['preceding-sibling'] = function(list)
+ local collected = { }
+ for l=1,#list do
+ local ll = list[l]
+ local p = ll.__p__
+ local d = p.dt
+ for i=1,ll.ni-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ collected[#collected+1] = di
+ end
+ end
+ end
+ return collected
end
-apply_axis['preceding-sibling'] = function(list)
- return { }
+apply_axis['reverse-sibling'] = function(list) -- reverse preceding
+ local collected = { }
+ for l=1,#list do
+ local ll = list[l]
+ local p = ll.__p__
+ local d = p.dt
+ for i=ll.ni-1,1,-1 do
+ local di = d[i]
+ if type(di) == "table" then
+ collected[#collected+1] = di
+ end
+ end
+ end
+ return collected
end
apply_axis['auto-descendant-or-self'] = apply_axis['descendant-or-self']
@@ -4843,13 +4909,19 @@ local function apply_nodes(list,directive,nodes)
end
end
+local quit_expression = false
+
local function apply_expression(list,expression,order)
local collected = { }
+ quit_expression = false
for l=1,#list do
local ll = list[l]
if expression(list,ll,l,order) then -- nasty, alleen valid als n=1
collected[#collected+1] = ll
end
+ if quit_expression then
+ break
+ end
end
return collected
end
@@ -4873,7 +4945,8 @@ local lp_builtin = P (
P("index") / "(ll.ni or 1)" +
P("match") / "(ll.mi or 1)" +
P("text") / "(ll.dt[1] or '')" +
- P("name") / "(ll.ns~='' and ll.ns..':'..ll.tg)" +
+--~ P("name") / "(ll.ns~='' and ll.ns..':'..ll.tg)" +
+ P("name") / "((ll.ns~='' and ll.ns..':'..ll.tg) or ll.tg)" +
P("tag") / "ll.tg" +
P("ns") / "ll.ns"
) * ((spaces * P("(") * spaces * P(")"))/"")
@@ -4903,6 +4976,7 @@ local nested = lpeg.P{lparent * (noparent + lpeg.V(1))^0 * rparent}
local value = lpeg.P(lparent * lpeg.C((noparent + nested)^0) * rparent) -- lpeg.P{"("*C(((1-S("()"))+V(1))^0)*")"}
local lp_child = Cc("expr.child(ll,'") * R("az","AZ","--","__")^1 * Cc("')")
+local lp_number = S("+-") * R("09")^1
local lp_string = Cc("'") * R("az","AZ","--","__")^1 * Cc("'")
local lp_content = (P("'") * (1-P("'"))^0 * P("'") + P('"') * (1-P('"'))^0 * P('"'))
@@ -4911,6 +4985,7 @@ local cleaner
local lp_special = (C(P("name")+P("text")+P("tag")+P("count")+P("child"))) * value / function(t,s)
if expressions[t] then
s = s and s ~= "" and cleaner:match(s)
+--~ print("!!!",t,s)
if s and s ~= "" then
return "expr." .. t .. "(ll," .. s ..")"
else
@@ -4940,9 +5015,11 @@ local converter = Cs (
cleaner = Cs ( (
--~ lp_fastpos +
lp_reserved +
+ lp_number +
lp_string +
1 )^1 )
+
--~ expr
local template_e = [[
@@ -5025,6 +5102,7 @@ local register_following = { kind = "axis", axis = "following"
local register_following_sibling = { kind = "axis", axis = "following-sibling" } -- , apply = apply_axis["following-sibling"] }
local register_preceding = { kind = "axis", axis = "preceding" } -- , apply = apply_axis["preceding"] }
local register_preceding_sibling = { kind = "axis", axis = "preceding-sibling" } -- , apply = apply_axis["preceding-sibling"] }
+local register_reverse_sibling = { kind = "axis", axis = "reverse-sibling" } -- , apply = apply_axis["reverse-sibling"] }
local register_auto_descendant_or_self = { kind = "axis", axis = "auto-descendant-or-self" } -- , apply = apply_axis["auto-descendant-or-self"] }
local register_auto_descendant = { kind = "axis", axis = "auto-descendant" } -- , apply = apply_axis["auto-descendant"] }
@@ -5051,8 +5129,8 @@ local parser = Ct { "patterns", -- can be made a bit faster by moving pattern ou
step = ((V("shortcuts") + P("/") + V("axis")) * spaces * V("nodes")^0 + V("error")) * spaces * V("expressions")^0 * spaces * V("finalizer")^0,
axis = V("descendant") + V("child") + V("parent") + V("self") + V("root") + V("ancestor") +
- V("descendant_or_self") + V("following") + V("following_sibling") +
- V("preceding") + V("preceding_sibling") + V("ancestor_or_self") +
+ V("descendant_or_self") + V("following_sibling") + V("following") +
+ V("reverse_sibling") + V("preceding_sibling") + V("preceding") + V("ancestor_or_self") +
#(1-P(-1)) * Cc(register_auto_child),
initial = (P("/") * spaces * Cc(register_initial_child))^-1,
@@ -5086,6 +5164,7 @@ local parser = Ct { "patterns", -- can be made a bit faster by moving pattern ou
following_sibling = P('following-sibling::') * Cc(register_following_sibling ),
preceding = P('preceding::') * Cc(register_preceding ),
preceding_sibling = P('preceding-sibling::') * Cc(register_preceding_sibling ),
+ reverse_sibling = P('reverse-sibling::') * Cc(register_reverse_sibling ),
nodes = (V("nodefunction") * spaces * P("(") * V("nodeset") * P(")") + V("nodetest") * V("nodeset")) / register_nodes,
@@ -5350,6 +5429,18 @@ expressions.undefined = function(s)
return s == nil
end
+expressions.quit = function(s)
+ if s or s == nil then
+ quit_expression = true
+ end
+ return true
+end
+
+expressions.print = function(...)
+ print(...)
+ return true
+end
+
expressions.contains = find
expressions.find = find
expressions.upper = upper
@@ -7292,7 +7383,7 @@ resolvers.generators.notfound = { nil }
resolvers.cacheversion = '1.0.1'
resolvers.cnfname = 'texmf.cnf'
resolvers.luaname = 'texmfcnf.lua'
-resolvers.homedir = os.env[os.platform == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
+resolvers.homedir = os.env[os.type == "windows" and 'USERPROFILE'] or os.env['HOME'] or '~'
resolvers.cnfdefault = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,.local,}/web2c}'
local dummy_path_expr = "^!*unset/*$"
@@ -7703,8 +7794,8 @@ function resolvers.getownpath()
resolvers.ownpath = os.selfdir
else
local binary = resolvers.ownbin
- if os.platform == "windows" then
- binary = file.replacesuffix(binary,"exe")
+ if os.binsuffix ~= "" then
+ binary = file.replacesuffix(binary,os.binsuffix)
end
for p in gmatch(os.getenv("PATH"),"[^"..io.pathseparator.."]+") do
local b = file.join(p,binary)
@@ -8915,11 +9006,11 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
dirlist[i] = file.dirname(filelist[i][2]) .. "/"
end
end
- local doscan
if trace_detail then
logs.report("fileio","checking filename '%s'",filename)
end
-- a bit messy ... esp the doscan setting here
+ local doscan
for k=1,#pathlist do
local path = pathlist[k]
if find(path,"^!!") then doscan = false else doscan = true end
@@ -8927,22 +9018,25 @@ local function collect_instance_files(filename,collected) -- todo : plugin (scan
done = false
-- using file list
if filelist then
+ local expression
-- compare list entries with permitted pattern -- /xx /xx//
if not find(pathname,"/$") then
- pathname = pathname .. "/"
+ expression = pathname .. "/"
+ else
+ expression = pathname
end
- pathname = gsub(pathname,"([%-%.])","%%%1") -- this also influences
- pathname = gsub(pathname,"//+$", '/.*') -- later usage of pathname
- pathname = gsub(pathname,"//", '/.-/') -- not ok for /// but harmless
- local expr = "^" .. pathname .. "$"
+ expression = gsub(expression,"([%-%.])","%%%1") -- this also influences
+ expression = gsub(expression,"//+$", '/.*') -- later usage of pathname
+ expression = gsub(expression,"//", '/.-/') -- not ok for /// but harmless
+ expression = "^" .. expression .. "$"
if trace_detail then
- logs.report("fileio","using pattern %s for path %s",expr,path)
+ logs.report("fileio","using pattern '%s' for path '%s'",expression,pathname)
end
for k=1,#filelist do
local fl = filelist[k]
local f = fl[2]
local d = dirlist[k]
- if find(d,expr) then
+ if find(d,expression) then
--- todo, test for readable
result[#result+1] = fl[3]
resolvers.register_in_trees(f) -- for tracing used files