summaryrefslogtreecommitdiff
path: root/scripts/context/lua/mtxrun.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/context/lua/mtxrun.lua')
-rw-r--r--scripts/context/lua/mtxrun.lua311
1 files changed, 123 insertions, 188 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 011ee8bb2..5a19d7960 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -1397,6 +1397,78 @@ end
+-- filename : l-set.lua
+-- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
+-- copyright: PRAGMA ADE / ConTeXt Development Team
+-- license : see context related readme files
+
+if not versions then versions = { } end versions['l-set'] = 1.001
+
+if not set then set = { } end
+
+do
+
+ local nums = { }
+ local tabs = { }
+ local concat = table.concat
+
+ set.create = table.tohash
+
+ function set.tonumber(t)
+ if next(t) then
+ local s = ""
+ -- we could save mem by sorting, but it slows down
+ for k, v in pairs(t) do
+ if v then
+ -- why bother about the leading space
+ s = s .. " " .. k
+ end
+ end
+ if not nums[s] then
+ tabs[#tabs+1] = t
+ nums[s] = #tabs
+ end
+ return nums[s]
+ else
+ return 0
+ end
+ end
+
+ function set.totable(n)
+ if n == 0 then
+ return { }
+ else
+ return tabs[n] or { }
+ end
+ end
+
+ function set.contains(n,s)
+ if type(n) == "table" then
+ return n[s]
+ elseif n == 0 then
+ return false
+ else
+ local t = tabs[n]
+ return t and t[s]
+ end
+ end
+
+end
+
+--~ local c = set.create{'aap','noot','mies'}
+--~ local s = set.tonumber(c)
+--~ local t = set.totable(s)
+--~ print(t['aap'])
+--~ local c = set.create{'zus','wim','jet'}
+--~ local s = set.tonumber(c)
+--~ local t = set.totable(s)
+--~ print(t['aap'])
+--~ print(t['jet'])
+--~ print(set.contains(t,'jet'))
+--~ print(set.contains(t,'aap'))
+
+
+
-- filename : l-os.lua
-- comment : split off from luat-lib
-- author : Hans Hagen, PRAGMA-ADE, Hasselt NL
@@ -4236,7 +4308,7 @@ do
end
function input.elapsedtime(instance)
- return string.format("%0.3f",instance.loadtime or 0)
+ return string.format("%0.3f",(instance and instance.loadtime) or 0)
end
function input.report_loadtime(instance)
@@ -4245,9 +4317,7 @@ function input.report_loadtime(instance)
end
end
-function input.loadtime(instance)
- tex.print(input.elapsedtime(instance))
-end
+input.loadtime = input.elapsedtime
function input.env(instance,key)
return instance.environment[key] or input.osenv(instance,key)
@@ -4275,6 +4345,7 @@ end
function input.identify_cnf(instance)
if #instance.cnffiles == 0 then
if instance.treepath ~= "" then
+ -- this is a special purpose branch, not really used
if instance.rootpath ~= "" then
local t = instance.treepath:splitchr(',')
for k,v in ipairs(t) do
@@ -4287,6 +4358,7 @@ function input.identify_cnf(instance)
instance.environment['TEXMFCNF'] = file.join(t[1] or '.','texmf/web2c')
end
if instance.rootpath ~= "" then
+ -- this assumes a single path, maybe do an expanded split here too
instance.environment['TEXMFCNF'] = file.join(instance.rootpath,'texmf/web2c')
instance.environment['SELFAUTOPARENT'] = instance.rootpath
end
@@ -4314,9 +4386,9 @@ function input.load_cnf(instance)
else
instance.rootpath = instance.cnffiles[1]
for k,fname in ipairs(instance.cnffiles) do
- instance.cnffiles[k] = fname:gsub("\\",'/')
+ instance.cnffiles[k] = fname:gsub("\\",'/') -- needed?
end
- for i = 1, 3 do
+ for i=1,3 do
instance.rootpath = file.dirname(instance.rootpath)
end
if instance.lsrmode then
@@ -4494,22 +4566,33 @@ function input.locatedatabase(instance,specification)
return input.methodhandler('locators', instance, specification)
end
+--~ poor mans solution, from before we had lfs.isdir
+--~
+--~ function input.locators.tex(instance,specification)
+--~ if specification and specification ~= '' then
+--~ local files = {
+--~ file.join(specification,'files'..input.lucsuffix),
+--~ file.join(specification,'files'..input.luasuffix),
+--~ file.join(specification,input.lsrname)
+--~ }
+--~ for _, filename in pairs(files) do
+--~ local f = io.open(filename)
+--~ if f then
+--~ input.logger('! tex locator', specification..' found')
+--~ input.aux.append_hash(instance,'file',specification,filename)
+--~ f:close()
+--~ return
+--~ end
+--~ end
+--~ input.logger('? tex locator', specification..' not found')
+--~ end
+--~ end
+
function input.locators.tex(instance,specification)
- if specification and specification ~= '' then
- local files = {
- file.join(specification,'files'..input.lucsuffix),
- file.join(specification,'files'..input.luasuffix),
- file.join(specification,input.lsrname)
- }
- for _, filename in pairs(files) do
- local f = io.open(filename)
- if f then
- input.logger('! tex locator', specification..' found')
- input.aux.append_hash(instance,'file',specification,filename)
- f:close()
- return
- end
- end
+ if specification and specification ~= '' and lfs.isdir(specification) then
+ input.logger('! tex locator', specification..' found')
+ input.aux.append_hash(instance,'file',specification,filename)
+ else
input.logger('? tex locator', specification..' not found')
end
end
@@ -4696,14 +4779,14 @@ function input.join_path(str)
return str
end
end
-function input.splitexpansions(instance)
- for k,v in pairs(instance.expansions) do
- local t = file.split_path(v)
- if #t > 1 then
- instance.expansions[k] = t
- end
- end
-end
+--~ function input.splitexpansions(instance)
+--~ for k,v in pairs(instance.expansions) do
+--~ local t = file.split_path(v)
+--~ if #t > 1 then
+--~ instance.expansions[k] = t
+--~ end
+--~ end
+--~ end
function input.splitexpansions(instance)
for k,v in pairs(instance.expansions) do
local t, h = { }, { }
@@ -4863,7 +4946,8 @@ function input.expand_variables(instance)
for k,v in pairs(instance.expansions) do
instance.expansions[k] = v:gsub("\\", '/')
end
- input.splitexpansions(instance)
+ -- ##########
+ --~ input.splitexpansions(instance) -- better not, fuzzy
end
function input.aux.expand_vars(instance,lst) -- simple vars
@@ -5083,80 +5167,6 @@ end
-- work that well; the parsing is ok, but dealing with the resulting
-- table is a pain because we need to work inside-out recursively
---~ function input.aux.splitpathexpr(str, t, validate)
---~ -- no need for optimization, only called a few times, we can use lpeg for the sub
---~ t = t or { }
---~ while true do
---~ local done = false
---~ while true do
---~ ok = false
---~ str = str:gsub("([^{},]+){([^{}]-)}", function(a,b)
---~ local t = { }
---~ for s in b:gmatch("([^,]+)") do
---~ t[#t+1] = a .. s
---~ end
---~ ok, done = true, true
---~ return "{" .. table.concat(t,",") .. "}"
---~ end)
---~ if not ok then break end
---~ end
---~ while true do
---~ ok = false
---~ str = str:gsub("{([^{}]-)}([^{},]+)", function(a,b)
---~ local t = { }
---~ for s in a:gmatch("([^,]+)") do
---~ t[#t+1] = s .. b
---~ end
---~ ok, done = true, true
---~ return "{" .. table.concat(t,",") .. "}"
---~ end)
---~ if not ok then break end
---~ end
---~ while true do
---~ ok = false
---~ str = str:gsub("([,{]){([^{}]+)}([,}])", function(a,b,c)
---~ ok, done = true, true
---~ return a .. b .. c
---~ end)
---~ if not ok then break end
---~ end
---~ if not done then break end
---~ end
---~ while true do
---~ ok = false
---~ str = str:gsub("{([^{}]-)}{([^{}]-)}", function(a,b)
---~ local t = { }
---~ for sa in a:gmatch("([^,]+)") do
---~ for sb in b:gmatch("([^,]+)") do
---~ t[#t+1] = sa .. sb
---~ end
---~ end
---~ ok = true
---~ return "{" .. table.concat(t,",") .. "}"
---~ end)
---~ if not ok then break end
---~ end
---~ while true do
---~ ok = false
---~ str = str:gsub("{([^{}]-)}", function(a)
---~ ok = true
---~ return a
---~ end)
---~ if not ok then break end
---~ end
---~ if validate then
---~ for s in str:gmatch("([^,]+)") do
---~ s = validate(s)
---~ if s then t[#t+1] = s end
---~ end
---~ else
---~ for s in str:gmatch("([^,]+)") do
---~ t[#t+1] = s
---~ end
---~ end
---~ return t
---~ end
-
function input.aux.splitpathexpr(str, t, validate)
-- no need for optimization, only called a few times, we can use lpeg for the sub
t = t or { }
@@ -5228,7 +5238,7 @@ function input.aux.splitpathexpr(str, t, validate)
return t
end
-function input.aux.expanded_path(instance,pathlist)
+function input.aux.expanded_path(instance,pathlist) -- maybe not a list, just a path
-- a previous version fed back into pathlist
local newlist, ok = { }, false
for _,v in ipairs(pathlist) do
@@ -5255,87 +5265,6 @@ function input.aux.expanded_path(instance,pathlist)
return newlist
end
---~ old one, imperfect and not that efficient
---~
---~ function input.aux.expanded_path(instance,pathlist)
---~ -- a previous version fed back into pathlist
---~ local i, n, oldlist, newlist, ok = 0, 0, { }, { }, false
---~ for _,v in ipairs(pathlist) do
---~ if v:find("[{}]") then
---~ ok = true
---~ break
---~ end
---~ end
---~ if ok then
---~ for _,v in ipairs(pathlist) do
---~ oldlist[#oldlist+1] = (v:gsub("([\{\}])", function(p)
---~ if p == "{" then
---~ i = i + 1
---~ if i > n then n = i end
---~ return "<" .. (i-1) .. ">"
---~ else
---~ i = i - 1
---~ return "</" .. i .. ">"
---~ end
---~ end))
---~ end
---~ for i=1,n do
---~ while true do
---~ local more = false
---~ local pattern = "^(.-)<"..(n-i)..">(.-)</"..(n-i)..">(.-)$"
---~ local t = { }
---~ for _,v in ipairs(oldlist) do
---~ local pre, mid, post = v:match(pattern)
---~ if pre and mid and post then
---~ more = true
---~ for vv in string.gmatch(mid..',',"(.-),") do -- (mid, "([^,]+)")
---~ if vv == '.' then
---~ t[#t+1] = pre..post
---~ else
---~ t[#t+1] = pre..vv..post
---~ end
---~ end
---~ else
---~ t[#t+1] = v
---~ end
---~ end
---~ oldlist = t
---~ if not more then break end
---~ end
---~ end
---~ if true then
---~ -- many dups are possible due to messy resolve / order can be messed up too, brr !
---~ local ok = { }
---~ for _,o in ipairs(oldlist) do
---~ for v in o:gmatch("([^,]+)") do
---~ if not ok[v] then
---~ ok[v] = true
---~ v = file.collapse_path(v)
---~ if v ~= "" and not v:find(instance.dummy_path_expr) then newlist[#newlist+1] = v end
---~ end
---~ end
---~ end
---~ else
---~ for _,v in ipairs(oldlist) do
---~ v = file.collapse_path(v)
---~ if v ~= "" and not v:find(instance.dummy_path_expr) then newlist[#newlist+1] = v end
---~ end
---~ end
---~ else
---~ for _,v in ipairs(pathlist) do
---~ for vv in string.gmatch(v..',',"(.-),") do
---~ vv = file.collapse_path(v)
---~ if vv ~= "" then newlist[#newlist+1] = vv end
---~ end
---~ end
---~ end
---~ return newlist
---~ end
-
---~ function input.is_readable(name) -- brrr, get rid of this
---~ return name:find("^zip##") or file.is_readable(name)
---~ end
-
input.is_readable = { }
function input.aux.is_readable(readable, name)
@@ -6115,6 +6044,10 @@ function input.update_script(instance,oldname,newname) -- oldname -> own.name, n
end
+--~ print(table.serialize(input.aux.splitpathexpr("/usr/share/texmf-{texlive,tetex}", {})))
+
+
+
if not modules then modules = { } end modules ['luat-tmp'] = {
version = 1.001,
comment = "companion to luat-lib.tex",
@@ -6169,7 +6102,8 @@ elseif lfs.attributes(caches.temp,"mode") ~= "directory" then
end
function caches.configpath(instance)
- return input.expand_var(instance,"TEXMFCNF")
+ return table.concat(instance.cnffiles,";")
+--~ return input.expand_var(instance,"TEXMFCNF")
end
function caches.treehash(instance)
@@ -6184,7 +6118,7 @@ end
function caches.setpath(instance,...)
if not caches.path then
if lfs and instance then
- for _,v in pairs(caches.paths) do
+ for _,v in pairs(caches.paths) do
for _,vv in pairs(input.expanded_path_list(instance,v)) do
if lfs.isdir(vv) then
caches.path = vv
@@ -6725,6 +6659,7 @@ own.libs = { -- todo: check which ones are really needed
'l-io.lua',
'l-md5.lua',
'l-number.lua',
+ 'l-set.lua',
'l-os.lua',
'l-file.lua',
'l-dir.lua',