summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtx-base.lua46
-rw-r--r--scripts/context/lua/mtx-update.lua36
-rw-r--r--scripts/context/lua/mtxrun.lua146
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua146
-rwxr-xr-xscripts/context/stubs/unix/mtxrun146
5 files changed, 285 insertions, 235 deletions
diff --git a/scripts/context/lua/mtx-base.lua b/scripts/context/lua/mtx-base.lua
index f9bb3e14c..99a478b1e 100644
--- a/scripts/context/lua/mtx-base.lua
+++ b/scripts/context/lua/mtx-base.lua
@@ -10,23 +10,20 @@ logs.extendbanner("ConTeXt TDS Management Tool 1.35 (aka luatools)")
-- private option --noluc for testing errors in the stub
-local instance = resolvers.instance
+local instance = resolvers.instance
-instance.luaname = environment.arguments["luafile"] or ""
-instance.lualibs = environment.arguments["lualibs"] or nil
-instance.pattern = environment.arguments["pattern"] or nil
-instance.sortdata = environment.arguments["sort"] or false
+local pattern = environment.arguments["pattern"] or nil
+local fileformat = environment.arguments["format"] or "" -- nil ?
+local allresults = environment.arguments["all"] or false
+local trace = environment.arguments["trace"]
-local my_format = environment.arguments["format"] or "" -- nil ?
-local all_results = environment.arguments["all"] or false
-
-if type(instance.pattern) == 'boolean' then
+if type(pattern) == 'boolean' then
logs.simple("invalid pattern specification")
- instance.pattern = nil
+ pattern = nil
end
-if environment.arguments["trace"] then
- resolvers.settrace(environment.arguments["trace"]) -- move to mtxrun ?
+if trace then
+ resolvers.settrace(trace) -- move to mtxrun ?
end
runners = runners or { }
@@ -40,7 +37,6 @@ to regenerate the file database using "mtxrun --generate".
messages.help = [[
--generate generate file database
--variables show configuration variables
---expansions show expanded variables
--configurations show configuration order
--expand-braces expand complex variable
--expand-path expand variable (resolve paths)
@@ -51,12 +47,9 @@ messages.help = [[
--find-path report path of file
--make or --ini make luatex format
--run or --fmt= run luatex format
---luafile=str lua inifile (default is texmfcnf.lua)
---lualibs=list libraries to assemble (optional when --compile)
--compile assemble and compile lua inifile
--verbose give a bit more info
--all show all found files
---sort sort cached data
--format=str filter cf format specification (default 'tex', use 'any' for any match)
--pattern=str filter variables
--trackers=list enable given trackers
@@ -64,14 +57,14 @@ messages.help = [[
if environment.arguments["find-file"] then
resolvers.load()
- if instance.pattern then
- resolvers.dowithfilesandreport(resolvers.findfiles, { instance.pattern }, my_format, all_results)
+ if pattern then
+ resolvers.dowithfilesandreport(resolvers.findfiles, { pattern }, fileformat, allresults)
else
- resolvers.dowithfilesandreport(resolvers.findfiles, environment.files, my_format, all_results)
+ resolvers.dowithfilesandreport(resolvers.findfiles, environment.files, fileformat, allresults)
end
elseif environment.arguments["find-path"] then
resolvers.load()
- local path = resolvers.findpath(environment.files[1], my_format)
+ local path = resolvers.findpath(environment.files[1], fileformat)
print(path) -- quite basic, wil become function in logs
elseif environment.arguments["run"] then
resolvers.load("nofiles") -- ! no need for loading databases
@@ -99,9 +92,9 @@ elseif environment.arguments["var-value"] or environment.arguments["show-value"]
elseif environment.arguments["format-path"] then
resolvers.load()
logs.simple(caches.getwritablepath("format"))
-elseif instance.pattern then -- brrr
+elseif pattern then -- brrr
resolvers.load()
- resolvers.dowithfilesandreport(resolvers.findfiles, { instance.pattern }, my_format, all_results)
+ resolvers.dowithfilesandreport(resolvers.findfiles, { pattern }, fileformat, allresults)
elseif environment.arguments["generate"] then
instance.renewcache = true
trackers.enable("resolvers.locating")
@@ -110,12 +103,9 @@ elseif environment.arguments["make"] or environment.arguments["ini"] or environm
resolvers.load()
trackers.enable("resolvers.locating")
environment.make_format(environment.files[1] or "")
-elseif environment.arguments["variables"] or environment.arguments["show-variables"] then
- resolvers.load("nofiles")
- resolvers.listers.variables(false,instance.pattern)
-elseif environment.arguments["expansions"] or environment.arguments["show-expansions"] then
+elseif environment.arguments["variables"] or environment.arguments["show-variables"] or environment.arguments["expansions"] or environment.arguments["show-expansions"] then
resolvers.load("nofiles")
- resolvers.listers.expansions(false,instance.pattern)
+ resolvers.listers.variables(pattern)
elseif environment.arguments["configurations"] or environment.arguments["show-configurations"] then
resolvers.load("nofiles")
resolvers.listers.configurations()
@@ -126,5 +116,5 @@ elseif environment.files[1] == 'texmfcnf.lua' then
resolvers.listers.configurations()
else
resolvers.load()
- resolvers.dowithfilesandreport(resolvers.findfiles, environment.files, my_format, all_results)
+ resolvers.dowithfilesandreport(resolvers.findfiles, environment.files, fileformat, allresults)
end
diff --git a/scripts/context/lua/mtx-update.lua b/scripts/context/lua/mtx-update.lua
index 960dd516f..708565910 100644
--- a/scripts/context/lua/mtx-update.lua
+++ b/scripts/context/lua/mtx-update.lua
@@ -11,7 +11,7 @@ if not modules then modules = { } end modules ['mtx-update'] = {
-- Together with Arthur Reutenauer she made sure that it worked well on all
-- platforms that matter.
-local format, concat, gmatch = string.format, table.concat, string.gmatch
+local format, concat, gmatch, gsub = string.format, table.concat, string.gmatch, string.gsub
scripts = scripts or { }
scripts.update = scripts.update or { }
@@ -189,7 +189,7 @@ function scripts.update.synchronize()
local goodies = states.get("goodies") -- goodies (like editors)
local force = environment.argument("force")
- bin = string.gsub(bin,"\\","/")
+ bin = gsub(bin,"\\","/")
if not url:find("::$") then url = url .. "::" end
local ok = lfs.attributes(texroot,"mode") == "directory"
@@ -215,8 +215,8 @@ function scripts.update.synchronize()
local archives = {}
for i=1,#collection do
local archive = collection[i][1]
- archive = archive:gsub("<platform>", platform)
- archive = archive:gsub("<version>", version)
+ archive = gsub(archive,"<platform>",platform)
+ archive = gsub(archive,"<version>",version)
archives[#archives+1] = archive
end
return archives
@@ -287,12 +287,12 @@ function scripts.update.synchronize()
if platform then
for i=1,#collection do
local c = collection[i]
- local archive = c[1]:gsub("<platform>", platform)
- local destination = format("%s/%s", texroot, c[2]:gsub("<platform>", platform))
- destination = destination:gsub("\\","/")
- archive = archive:gsub("<version>",version)
+ local archive = gsub(c[1],"<platform>",platform)
+ local destination = format("%s/%s", texroot, gsub(c[2],"<platform>", platform))
+ destination = gsub(destination,"\\","/")
+ archive = gsub(archive,"<version>",version)
if osplatform == "windows" or osplatform == "mswin" then
- destination = destination:gsub("([a-zA-Z]):/", "/cygdrive/%1/")
+ destination = gsub(destination,"([a-zA-Z]):/", "/cygdrive/%1/")
end
individual[#individual+1] = { archive, destination }
end
@@ -358,17 +358,17 @@ function scripts.update.synchronize()
end
local function update_script(script, platform)
- local bin = bin:gsub("\\","/")
- local texroot = texroot:gsub("\\","/")
+ local bin = gsub(bin,"\\","/")
+ local texroot = gsub(texroot,"\\","/")
platform = scripts.update.platforms[platform]
if platform then
local command
if platform == 'mswin' then
- bin = bin:gsub("([a-zA-Z]):/", "/cygdrive/%1/")
- texroot = texroot:gsub("([a-zA-Z]):/", "/cygdrive/%1/")
- command = string.format("%s -t %s/texmf-context/scripts/context/lua/%s.lua %s/texmf-mswin/bin/", bin, texroot, script, texroot)
+ bin = gsub(bin,"([a-zA-Z]):/", "/cygdrive/%1/")
+ texroot = gsub(texroot,"([a-zA-Z]):/", "/cygdrive/%1/")
+ command = format("%s -t %s/texmf-context/scripts/context/lua/%s.lua %s/texmf-mswin/bin/", bin, texroot, script, texroot)
else
- command = string.format("%s -tgo --chmod=a+x %s/texmf-context/scripts/context/lua/%s.lua %s/texmf-%s/bin/%s", bin, texroot, script, texroot, platform, script)
+ command = format("%s -tgo --chmod=a+x %s/texmf-context/scripts/context/lua/%s.lua %s/texmf-%s/bin/%s", bin, texroot, script, texroot, platform, script)
end
logs.report("mtx update", format("updating %s for %s: %s", script, platform, command))
scripts.update.run(command)
@@ -391,7 +391,7 @@ function scripts.update.synchronize()
resolvers.load_tree(texroot) -- else we operate in the wrong tree
-- update filename database for pdftex/xetex
- scripts.update.run(format('mtxrun --tree="%s" bin:mktexlsr',texroot))
+ scripts.update.run(format('mtxrun --tree="%s" --direct mktexlsr',texroot))
-- update filename database for luatex
scripts.update.run(format('mtxrun --tree="%s" --generate',texroot))
@@ -420,7 +420,7 @@ function scripts.update.make()
resolvers.load_tree(texroot)
- scripts.update.run(format('mtxrun --tree="%s" bin:mktexlsr',texroot))
+ scripts.update.run(format('mtxrun --tree="%s" --direct mktexlsr',texroot))
scripts.update.run(format('mtxrun --tree="%s" --generate',texroot))
local askedformats = formats
@@ -453,7 +453,7 @@ function scripts.update.make()
if not force then
logs.report("make", "use --force to really make formats")
end
- scripts.update.run(format('mtxrun --tree="%s" bin:mktexlsr',texroot))
+ scripts.update.run(format('mtxrun --tree="%s" --direct mktexlsr',texroot))
scripts.update.run(format('mtxrun --tree="%s" --generate',texroot))
logs.report("make","done")
end
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index fd8d826f4..4ada628ea 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -2937,22 +2937,20 @@ end
local function globpattern(path,patt,recurse,action)
- if isdir(path) then
- if path == "/" then
- path = path .. "."
- elseif not find(path,"/$") then
- path = path .. '/'
- end
- for name in walkdir(path) do
- local full = path .. name
- local mode = attributes(full,'mode')
- if mode == 'file' then
- if find(full,patt) then
- action(full)
- end
- elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
- globpattern(full,patt,recurse,action)
+ if path == "/" then
+ path = path .. "."
+ elseif not find(path,"/$") then
+ path = path .. '/'
+ end
+ for name in walkdir(path) do
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if find(full,patt) then
+ action(full)
end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ globpattern(full,patt,recurse,action)
end
end
end
@@ -9441,6 +9439,7 @@ resolvers.settrace(osgetenv("MTX_INPUT_TRACE"))
if not resolvers.resolve then
function resolvers.resolve (s) return s end
function resolvers.unresolve(s) return s end
+ function resolvers.repath (s) return s end
end
@@ -10771,6 +10770,7 @@ function resolvers.newinstance() -- todo: all vars will become lowercase and alp
if v ~= nil then
v = checkedvariable(v) or ""
end
+ v = resolvers.repath(v) -- for taco who has a : separated osfontdir
t[k] = v
return v
end } )
@@ -11987,6 +11987,7 @@ resolvers.prefixes = prefixes
local gsub = string.gsub
local cleanpath, findgivenfile, expansion = resolvers.cleanpath, resolvers.findgivenfile, resolvers.expansion
local getenv = resolvers.getenv -- we can probably also use resolvers.expansion
+local P, Cs, lpegmatch = lpeg.P, lpeg.Cs, lpeg.match
prefixes.environment = function(str)
return cleanpath(expansion(str))
@@ -12050,8 +12051,6 @@ prefixes.home = function(str)
return cleanpath(file.join(getenv('HOME'),str))
end
-prefixes["~"] = prefixes.home
-
prefixes.env = prefixes.environment
prefixes.rel = prefixes.relative
prefixes.loc = prefixes.locate
@@ -12111,6 +12110,42 @@ if os.uname then
end
+if os.type == "unix" then
+
+ local pattern
+
+ local function makepattern(t,k,v)
+ local colon = P(":")
+ local p
+ for k, v in table.sortedpairs(prefixes) do
+ if p then
+ p = P(k) + p
+ else
+ p = P(k)
+ end
+ end
+ pattern = Cs((p * colon + colon/";" + P(1))^0)
+ if t then
+ t[k] = v
+ end
+ end
+
+ makepattern()
+
+ getmetatable(prefixes).__newindex = makepattern
+
+ function resolvers.repath(str)
+ return lpegmatch(pattern,str)
+ end
+
+else -- already the default:
+
+ function resolvers.repath(str)
+ return str
+ end
+
+end
+
end -- of closure
@@ -13245,7 +13280,7 @@ if not modules then modules = { } end modules ['data-lst'] = {
license = "see context related readme files"
}
--- used in mtxrun
+-- used in mtxrun, can be loaded later .. todo
local find, concat, upper, format = string.find, table.concat, string.upper, string.format
@@ -13261,51 +13296,43 @@ local function tabstr(str)
end
end
-local function list(list,report,pattern)
- pattern = pattern and pattern ~= "" and upper(pattern) or ""
- local instance = resolvers.instance
- local report = report or texio.write_nl
- local sorted = table.sortedkeys(list)
- local result = { }
- for i=1,#sorted do
- local key = sorted[i]
- if key ~= "" and (pattern == "" or find(upper(key),pattern)) then
- local raw = tabstr(rawget(list,key))
- local val = tabstr(list[key])
- local res = resolvers.resolve(val)
- if raw and raw ~= "" then
- if raw == val then
- if val == res then
- result[#result+1] = { key, raw }
- else
- result[#result+1] = { key, format('%s => %s',raw,res) }
- end
- else
- if val == res then
- result[#result+1] = { key, format('%s => %s',raw,val) }
- else
- result[#result+1] = { key, format('%s => %s => %s',raw,val,res) }
- end
- end
- else
- result[#result+1] = { key, "unset" }
+function resolvers.listers.variables(pattern)
+ local instance = resolvers.instance
+ local environment = instance.environment
+ local variables = instance.variables
+ local expansions = instance.expansions
+ local pattern = upper(pattern or "")
+ local configured = { }
+ local order = instance.order
+ for i=1,#order do
+ for k, v in next, order[i] do
+ if v ~= nil and configured[k] == nil then
+ configured[k] = v
end
end
end
- utilities.formatters.formatcolumns(result)
- for i=1,#result do
- report(result[i])
+ local env = table.fastcopy(environment)
+ local var = table.fastcopy(variables)
+ local exp = table.fastcopy(expansions)
+ for key, value in table.sortedpairs(configured) do
+ if key ~= "" and (pattern == "" or find(upper(key),pattern)) then
+ logs.simple(key)
+ logs.simple(" env: %s",tabstr(rawget(environment,key)) or "unset")
+ logs.simple(" var: %s",tabstr(configured[key]) or "unset")
+ logs.simple(" exp: %s",tabstr(expansions[key]) or "unset")
+ logs.simple(" res: %s",resolvers.resolve(expansions[key]) or "unset")
+ end
end
+ instance.environment = table.fastcopy(env)
+ instance.variables = table.fastcopy(var)
+ instance.expansions = table.fastcopy(exp)
end
-function resolvers.listers.variables (report,pattern) list(resolvers.instance.variables, report,pattern) end
-function resolvers.listers.expansions(report,pattern) list(resolvers.instance.expansions,report,pattern) end
-
function resolvers.listers.configurations(report)
local configurations = resolvers.instance.specification
local report = report or texio.write_nl
for i=1,#configurations do
- report(configurations[i])
+ report(resolvers.resolve(configurations[i]))
end
end
@@ -13776,8 +13803,8 @@ messages.help = [[
--generate generate file database
--variables show configuration variables
---expansions show expanded variables
--configurations show configuration order
+
--expand-braces expand complex variable
--expand-path expand variable (resolve paths)
--expand-var expand variable (resolve references)
@@ -14529,19 +14556,12 @@ elseif environment.argument("timedrun") then
runners.loadbase()
runners.timedrun(filename)
-elseif environment.argument("variables") or environment.argument("show-variables") then
-
- -- luatools: runners.execute_ctx_script("mtx-base","--variables",filename)
-
- resolvers.load("nofiles")
- resolvers.listers.variables(false,environment.argument("pattern"))
-
-elseif environment.argument("expansions") or environment.argument("show-expansions") then
+elseif environment.argument("variables") or environment.argument("show-variables") or environment.argument("expansions") or environment.argument("show-expansions") then
-- luatools: runners.execute_ctx_script("mtx-base","--expansions",filename)
resolvers.load("nofiles")
- resolvers.listers.expansions(false,environment.argument("pattern"))
+ resolvers.listers.variables(environment.argument("pattern"))
elseif environment.argument("configurations") or environment.argument("show-configurations") then
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index fd8d826f4..4ada628ea 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -2937,22 +2937,20 @@ end
local function globpattern(path,patt,recurse,action)
- if isdir(path) then
- if path == "/" then
- path = path .. "."
- elseif not find(path,"/$") then
- path = path .. '/'
- end
- for name in walkdir(path) do
- local full = path .. name
- local mode = attributes(full,'mode')
- if mode == 'file' then
- if find(full,patt) then
- action(full)
- end
- elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
- globpattern(full,patt,recurse,action)
+ if path == "/" then
+ path = path .. "."
+ elseif not find(path,"/$") then
+ path = path .. '/'
+ end
+ for name in walkdir(path) do
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if find(full,patt) then
+ action(full)
end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ globpattern(full,patt,recurse,action)
end
end
end
@@ -9441,6 +9439,7 @@ resolvers.settrace(osgetenv("MTX_INPUT_TRACE"))
if not resolvers.resolve then
function resolvers.resolve (s) return s end
function resolvers.unresolve(s) return s end
+ function resolvers.repath (s) return s end
end
@@ -10771,6 +10770,7 @@ function resolvers.newinstance() -- todo: all vars will become lowercase and alp
if v ~= nil then
v = checkedvariable(v) or ""
end
+ v = resolvers.repath(v) -- for taco who has a : separated osfontdir
t[k] = v
return v
end } )
@@ -11987,6 +11987,7 @@ resolvers.prefixes = prefixes
local gsub = string.gsub
local cleanpath, findgivenfile, expansion = resolvers.cleanpath, resolvers.findgivenfile, resolvers.expansion
local getenv = resolvers.getenv -- we can probably also use resolvers.expansion
+local P, Cs, lpegmatch = lpeg.P, lpeg.Cs, lpeg.match
prefixes.environment = function(str)
return cleanpath(expansion(str))
@@ -12050,8 +12051,6 @@ prefixes.home = function(str)
return cleanpath(file.join(getenv('HOME'),str))
end
-prefixes["~"] = prefixes.home
-
prefixes.env = prefixes.environment
prefixes.rel = prefixes.relative
prefixes.loc = prefixes.locate
@@ -12111,6 +12110,42 @@ if os.uname then
end
+if os.type == "unix" then
+
+ local pattern
+
+ local function makepattern(t,k,v)
+ local colon = P(":")
+ local p
+ for k, v in table.sortedpairs(prefixes) do
+ if p then
+ p = P(k) + p
+ else
+ p = P(k)
+ end
+ end
+ pattern = Cs((p * colon + colon/";" + P(1))^0)
+ if t then
+ t[k] = v
+ end
+ end
+
+ makepattern()
+
+ getmetatable(prefixes).__newindex = makepattern
+
+ function resolvers.repath(str)
+ return lpegmatch(pattern,str)
+ end
+
+else -- already the default:
+
+ function resolvers.repath(str)
+ return str
+ end
+
+end
+
end -- of closure
@@ -13245,7 +13280,7 @@ if not modules then modules = { } end modules ['data-lst'] = {
license = "see context related readme files"
}
--- used in mtxrun
+-- used in mtxrun, can be loaded later .. todo
local find, concat, upper, format = string.find, table.concat, string.upper, string.format
@@ -13261,51 +13296,43 @@ local function tabstr(str)
end
end
-local function list(list,report,pattern)
- pattern = pattern and pattern ~= "" and upper(pattern) or ""
- local instance = resolvers.instance
- local report = report or texio.write_nl
- local sorted = table.sortedkeys(list)
- local result = { }
- for i=1,#sorted do
- local key = sorted[i]
- if key ~= "" and (pattern == "" or find(upper(key),pattern)) then
- local raw = tabstr(rawget(list,key))
- local val = tabstr(list[key])
- local res = resolvers.resolve(val)
- if raw and raw ~= "" then
- if raw == val then
- if val == res then
- result[#result+1] = { key, raw }
- else
- result[#result+1] = { key, format('%s => %s',raw,res) }
- end
- else
- if val == res then
- result[#result+1] = { key, format('%s => %s',raw,val) }
- else
- result[#result+1] = { key, format('%s => %s => %s',raw,val,res) }
- end
- end
- else
- result[#result+1] = { key, "unset" }
+function resolvers.listers.variables(pattern)
+ local instance = resolvers.instance
+ local environment = instance.environment
+ local variables = instance.variables
+ local expansions = instance.expansions
+ local pattern = upper(pattern or "")
+ local configured = { }
+ local order = instance.order
+ for i=1,#order do
+ for k, v in next, order[i] do
+ if v ~= nil and configured[k] == nil then
+ configured[k] = v
end
end
end
- utilities.formatters.formatcolumns(result)
- for i=1,#result do
- report(result[i])
+ local env = table.fastcopy(environment)
+ local var = table.fastcopy(variables)
+ local exp = table.fastcopy(expansions)
+ for key, value in table.sortedpairs(configured) do
+ if key ~= "" and (pattern == "" or find(upper(key),pattern)) then
+ logs.simple(key)
+ logs.simple(" env: %s",tabstr(rawget(environment,key)) or "unset")
+ logs.simple(" var: %s",tabstr(configured[key]) or "unset")
+ logs.simple(" exp: %s",tabstr(expansions[key]) or "unset")
+ logs.simple(" res: %s",resolvers.resolve(expansions[key]) or "unset")
+ end
end
+ instance.environment = table.fastcopy(env)
+ instance.variables = table.fastcopy(var)
+ instance.expansions = table.fastcopy(exp)
end
-function resolvers.listers.variables (report,pattern) list(resolvers.instance.variables, report,pattern) end
-function resolvers.listers.expansions(report,pattern) list(resolvers.instance.expansions,report,pattern) end
-
function resolvers.listers.configurations(report)
local configurations = resolvers.instance.specification
local report = report or texio.write_nl
for i=1,#configurations do
- report(configurations[i])
+ report(resolvers.resolve(configurations[i]))
end
end
@@ -13776,8 +13803,8 @@ messages.help = [[
--generate generate file database
--variables show configuration variables
---expansions show expanded variables
--configurations show configuration order
+
--expand-braces expand complex variable
--expand-path expand variable (resolve paths)
--expand-var expand variable (resolve references)
@@ -14529,19 +14556,12 @@ elseif environment.argument("timedrun") then
runners.loadbase()
runners.timedrun(filename)
-elseif environment.argument("variables") or environment.argument("show-variables") then
-
- -- luatools: runners.execute_ctx_script("mtx-base","--variables",filename)
-
- resolvers.load("nofiles")
- resolvers.listers.variables(false,environment.argument("pattern"))
-
-elseif environment.argument("expansions") or environment.argument("show-expansions") then
+elseif environment.argument("variables") or environment.argument("show-variables") or environment.argument("expansions") or environment.argument("show-expansions") then
-- luatools: runners.execute_ctx_script("mtx-base","--expansions",filename)
resolvers.load("nofiles")
- resolvers.listers.expansions(false,environment.argument("pattern"))
+ resolvers.listers.variables(environment.argument("pattern"))
elseif environment.argument("configurations") or environment.argument("show-configurations") then
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index fd8d826f4..4ada628ea 100755
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -2937,22 +2937,20 @@ end
local function globpattern(path,patt,recurse,action)
- if isdir(path) then
- if path == "/" then
- path = path .. "."
- elseif not find(path,"/$") then
- path = path .. '/'
- end
- for name in walkdir(path) do
- local full = path .. name
- local mode = attributes(full,'mode')
- if mode == 'file' then
- if find(full,patt) then
- action(full)
- end
- elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
- globpattern(full,patt,recurse,action)
+ if path == "/" then
+ path = path .. "."
+ elseif not find(path,"/$") then
+ path = path .. '/'
+ end
+ for name in walkdir(path) do
+ local full = path .. name
+ local mode = attributes(full,'mode')
+ if mode == 'file' then
+ if find(full,patt) then
+ action(full)
end
+ elseif recurse and (mode == "directory") and (name ~= '.') and (name ~= "..") then
+ globpattern(full,patt,recurse,action)
end
end
end
@@ -9441,6 +9439,7 @@ resolvers.settrace(osgetenv("MTX_INPUT_TRACE"))
if not resolvers.resolve then
function resolvers.resolve (s) return s end
function resolvers.unresolve(s) return s end
+ function resolvers.repath (s) return s end
end
@@ -10771,6 +10770,7 @@ function resolvers.newinstance() -- todo: all vars will become lowercase and alp
if v ~= nil then
v = checkedvariable(v) or ""
end
+ v = resolvers.repath(v) -- for taco who has a : separated osfontdir
t[k] = v
return v
end } )
@@ -11987,6 +11987,7 @@ resolvers.prefixes = prefixes
local gsub = string.gsub
local cleanpath, findgivenfile, expansion = resolvers.cleanpath, resolvers.findgivenfile, resolvers.expansion
local getenv = resolvers.getenv -- we can probably also use resolvers.expansion
+local P, Cs, lpegmatch = lpeg.P, lpeg.Cs, lpeg.match
prefixes.environment = function(str)
return cleanpath(expansion(str))
@@ -12050,8 +12051,6 @@ prefixes.home = function(str)
return cleanpath(file.join(getenv('HOME'),str))
end
-prefixes["~"] = prefixes.home
-
prefixes.env = prefixes.environment
prefixes.rel = prefixes.relative
prefixes.loc = prefixes.locate
@@ -12111,6 +12110,42 @@ if os.uname then
end
+if os.type == "unix" then
+
+ local pattern
+
+ local function makepattern(t,k,v)
+ local colon = P(":")
+ local p
+ for k, v in table.sortedpairs(prefixes) do
+ if p then
+ p = P(k) + p
+ else
+ p = P(k)
+ end
+ end
+ pattern = Cs((p * colon + colon/";" + P(1))^0)
+ if t then
+ t[k] = v
+ end
+ end
+
+ makepattern()
+
+ getmetatable(prefixes).__newindex = makepattern
+
+ function resolvers.repath(str)
+ return lpegmatch(pattern,str)
+ end
+
+else -- already the default:
+
+ function resolvers.repath(str)
+ return str
+ end
+
+end
+
end -- of closure
@@ -13245,7 +13280,7 @@ if not modules then modules = { } end modules ['data-lst'] = {
license = "see context related readme files"
}
--- used in mtxrun
+-- used in mtxrun, can be loaded later .. todo
local find, concat, upper, format = string.find, table.concat, string.upper, string.format
@@ -13261,51 +13296,43 @@ local function tabstr(str)
end
end
-local function list(list,report,pattern)
- pattern = pattern and pattern ~= "" and upper(pattern) or ""
- local instance = resolvers.instance
- local report = report or texio.write_nl
- local sorted = table.sortedkeys(list)
- local result = { }
- for i=1,#sorted do
- local key = sorted[i]
- if key ~= "" and (pattern == "" or find(upper(key),pattern)) then
- local raw = tabstr(rawget(list,key))
- local val = tabstr(list[key])
- local res = resolvers.resolve(val)
- if raw and raw ~= "" then
- if raw == val then
- if val == res then
- result[#result+1] = { key, raw }
- else
- result[#result+1] = { key, format('%s => %s',raw,res) }
- end
- else
- if val == res then
- result[#result+1] = { key, format('%s => %s',raw,val) }
- else
- result[#result+1] = { key, format('%s => %s => %s',raw,val,res) }
- end
- end
- else
- result[#result+1] = { key, "unset" }
+function resolvers.listers.variables(pattern)
+ local instance = resolvers.instance
+ local environment = instance.environment
+ local variables = instance.variables
+ local expansions = instance.expansions
+ local pattern = upper(pattern or "")
+ local configured = { }
+ local order = instance.order
+ for i=1,#order do
+ for k, v in next, order[i] do
+ if v ~= nil and configured[k] == nil then
+ configured[k] = v
end
end
end
- utilities.formatters.formatcolumns(result)
- for i=1,#result do
- report(result[i])
+ local env = table.fastcopy(environment)
+ local var = table.fastcopy(variables)
+ local exp = table.fastcopy(expansions)
+ for key, value in table.sortedpairs(configured) do
+ if key ~= "" and (pattern == "" or find(upper(key),pattern)) then
+ logs.simple(key)
+ logs.simple(" env: %s",tabstr(rawget(environment,key)) or "unset")
+ logs.simple(" var: %s",tabstr(configured[key]) or "unset")
+ logs.simple(" exp: %s",tabstr(expansions[key]) or "unset")
+ logs.simple(" res: %s",resolvers.resolve(expansions[key]) or "unset")
+ end
end
+ instance.environment = table.fastcopy(env)
+ instance.variables = table.fastcopy(var)
+ instance.expansions = table.fastcopy(exp)
end
-function resolvers.listers.variables (report,pattern) list(resolvers.instance.variables, report,pattern) end
-function resolvers.listers.expansions(report,pattern) list(resolvers.instance.expansions,report,pattern) end
-
function resolvers.listers.configurations(report)
local configurations = resolvers.instance.specification
local report = report or texio.write_nl
for i=1,#configurations do
- report(configurations[i])
+ report(resolvers.resolve(configurations[i]))
end
end
@@ -13776,8 +13803,8 @@ messages.help = [[
--generate generate file database
--variables show configuration variables
---expansions show expanded variables
--configurations show configuration order
+
--expand-braces expand complex variable
--expand-path expand variable (resolve paths)
--expand-var expand variable (resolve references)
@@ -14529,19 +14556,12 @@ elseif environment.argument("timedrun") then
runners.loadbase()
runners.timedrun(filename)
-elseif environment.argument("variables") or environment.argument("show-variables") then
-
- -- luatools: runners.execute_ctx_script("mtx-base","--variables",filename)
-
- resolvers.load("nofiles")
- resolvers.listers.variables(false,environment.argument("pattern"))
-
-elseif environment.argument("expansions") or environment.argument("show-expansions") then
+elseif environment.argument("variables") or environment.argument("show-variables") or environment.argument("expansions") or environment.argument("show-expansions") then
-- luatools: runners.execute_ctx_script("mtx-base","--expansions",filename)
resolvers.load("nofiles")
- resolvers.listers.expansions(false,environment.argument("pattern"))
+ resolvers.listers.variables(environment.argument("pattern"))
elseif environment.argument("configurations") or environment.argument("show-configurations") then