summaryrefslogtreecommitdiff
path: root/tex/context/base/data-res.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/data-res.lua')
-rw-r--r--tex/context/base/data-res.lua174
1 files changed, 80 insertions, 94 deletions
diff --git a/tex/context/base/data-res.lua b/tex/context/base/data-res.lua
index 897adb5c4..fe5ca1db0 100644
--- a/tex/context/base/data-res.lua
+++ b/tex/context/base/data-res.lua
@@ -43,15 +43,25 @@ local initializesetter = utilities.setters.initialize
local ostype, osname, osenv, ossetenv, osgetenv = os.type, os.name, os.env, os.setenv, os.getenv
-resolvers.cacheversion = '1.0.1'
-resolvers.configbanner = ''
-resolvers.homedir = environment.homedir
-resolvers.criticalvars = allocate { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF", "TEXMF", "TEXOS" }
-resolvers.luacnfspec = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,}/web2c}' -- rubish path
-resolvers.luacnfname = 'texmfcnf.lua'
-resolvers.luacnfstate = "unknown"
+resolvers.cacheversion = '1.0.1'
+resolvers.configbanner = ''
+resolvers.homedir = environment.homedir
+resolvers.criticalvars = allocate { "SELFAUTOLOC", "SELFAUTODIR", "SELFAUTOPARENT", "TEXMFCNF", "TEXMF", "TEXOS" }
+resolvers.luacnfname = 'texmfcnf.lua'
+resolvers.luacnfstate = "unknown"
+
+-- resolvers.luacnfspec = '{$SELFAUTODIR,$SELFAUTOPARENT}{,{/share,}/texmf{-local,}/web2c}' -- what a rubish path
+-- resolvers.luacnfspec = 'selfautoparent:{/texmf{-local,}{,/web2c},}}'
+
+resolvers.luacnfspec = {
+ "selfautoparent:/texmf-local",
+ "selfautoparent:/texmf-local/web2c",
+ "selfautoparent:/texmf",
+ "selfautoparent:/texmf/web2c",
+ "selfautoparent:",
+}
-local unset_variable = "unset"
+local unset_variable = "unset"
local formats = resolvers.formats
local suffixes = resolvers.suffixes
@@ -136,10 +146,11 @@ end
resolvers.getenv = getenv
resolvers.env = getenv
-local function resolve(key)
- local value = instance.variables[key] or ""
- return (value ~= "" and value) or getenv(key) or ""
-end
+--~ local function resolve(key)
+--~ local value = instance.variables[key] or ""
+--~ return (value ~= "" and value) or getenv(key) or ""
+--~ end
+--~
local dollarstripper = lpeg.stripper("$")
local inhibitstripper = P("!")^0 * Cs(P(1)^0)
@@ -151,27 +162,12 @@ local somethingelse = P(";") * ((1-S("!{}/\\"))^1 * P(";") / "")
+ P(";") * (P(";") / "")
+ P(1)
-local pattern = Cs( (somevariable * (somekey/resolve) + somethingelse)^1 )
-
-local function expandvars(lst) -- simple vars
- for k=1,#lst do
- local lk = lst[k]
- lst[k] = lpegmatch(pattern,lk) or lk
- end
-end
-
+--~ local pattern = Cs( (somevariable * (somekey/resolve) + somethingelse)^1 )
+--~
--~ local function expandvars(lst) -- simple vars
---~ local variables, getenv = instance.variables, resolvers.getenv
---~ local function resolve(a)
---~ local va = variables[a] or ""
---~ return (va ~= "" and va) or getenv(a) or ""
---~ end
--~ for k=1,#lst do
---~ local var = lst[k]
---~ var = gsub(var,"%$([%a%d%_%-]+)",resolve)
---~ var = gsub(var,";+",";")
---~ var = gsub(var,";[!{}/\\]+;",";")
---~ lst[k] = var
+--~ local lk = lst[k]
+--~ lst[k] = lpegmatch(pattern,lk) or lk
--~ end
--~ end
@@ -184,34 +180,24 @@ local pattern = Cs (
+ slash^2 / "/.-/"
+ (1-slash) * P(-1) * Cc("/")
+ P(1)
- )^1 * Cc("$")
+ )^1 * Cc("$") -- yes or no $
)
+local cache = { }
+
local function makepathexpression(str)
if str == "." then
return "^%./$"
else
- return lpegmatch(pattern,str)
+ local c = cache[str]
+ if not c then
+ c = lpegmatch(pattern,str)
+ cache[str] = c
+ end
+ return c
end
end
---~ local function makepathexpression(str)
---~ if str == "." then
---~ return "^%./$"
---~ else
---~ local expression
---~ if not find(str,"/$") then
---~ expression = str .. "/"
---~ else
---~ expression = str
---~ end
---~ expression = gsub(expression,"([%-%.])","%%%1") -- this also influences
---~ expression = gsub(expression,"//+$", '/.*') -- later usage of pathname
---~ expression = gsub(expression,"//", '/.-/') -- not ok for /// but harmless
---~ return "^" .. expression .. "$"
---~ end
---~ end
-
local function resolve(key)
local value = instance.variables[key]
if value and value ~= "" then
@@ -231,13 +217,6 @@ local function expandedvariable(var) -- simple vars
return lpegmatch(pattern,var) or var
end
---~ local function expandedvariable(var) -- simple vars
---~ var = gsub(var,"%$([%a%d%_%-]+)",resolve)
---~ var = gsub(var,";+",";")
---~ var = gsub(var,";[!{}/\\]+;",";")
---~ return var
---~ end
-
local function entry(entries,name)
if name and name ~= "" then
name = lpegmatch(dollarstripper,name)
@@ -289,14 +268,26 @@ local function identify_configuration_files()
reportcriticalvariables()
resolvers.expandvariables()
local cnfpaths = expandedpathfromlist(resolvers.splitpath(cnfspec))
- expandvars(cnfpaths) --- hm
+ -- expandvars(cnfpaths) --- hm
local luacnfname = resolvers.luacnfname
for i=1,#cnfpaths do
local filename = collapsepath(filejoin(cnfpaths[i],luacnfname))
- if lfs.isfile(filename) then
- specification[#specification+1] = filename
+ local realname = resolvers.resolve(filename) -- no shortcut
+ -- if trace_locating then
+ -- report_resolvers("checking configuration file '%s'",filename)
+ -- end
+ if lfs.isfile(realname) then
+ specification[#specification+1] = filename -- or realname?
+ if trace_locating then
+ report_resolvers("found configuration file '%s'",realname)
+ end
+ elseif trace_locating then
+ report_resolvers("unknown configuration file '%s'",realname)
end
end
+ if trace_locating then
+ report_resolvers()
+ end
end
end
@@ -308,7 +299,8 @@ local function load_configuration_files()
local filename = specification[i]
local pathname = filedirname(filename)
local filename = filejoin(pathname,luacnfname)
- local blob = loadfile(filename)
+ local realname = resolvers.resolve(filename) -- no shortcut
+ local blob = loadfile(realname)
if blob then
local setups = instance.setups
local data = blob()
@@ -410,6 +402,8 @@ local function collapse_configuration_data() -- potential optimization: pass sta
end
end
+-- scheme magic
+
-- database loading
local function load_file_databases()
@@ -429,34 +423,24 @@ local function locate_file_databases()
local texmfpaths = resolvers.expandedpathlist('TEXMF')
for i=1,#texmfpaths do
local path = collapsepath(texmfpaths[i])
- local stripped = lpegmatch(inhibitstripper,path)
+ local stripped = lpegmatch(inhibitstripper,path) -- the !! thing
if stripped ~= "" then
local runtime = stripped == path
path = resolvers.cleanpath(path)
- if lfs.isdir(path) then
- local spec = resolvers.splitmethod(stripped)
- if spec.scheme == "cache" or spec.scheme == "file" then
- stripped = spec.path
- elseif runtime and (spec.noscheme or spec.scheme == "file") then
- stripped = "tree:///" .. stripped
- end
- if trace_locating then
- if runtime then
- report_resolvers("locating list of '%s' (runtime)",path)
- else
- report_resolvers("locating list of '%s' (cached)",path)
- end
- end
- methodhandler('locators',stripped) -- nothing done with result
- else
- if trace_locating then
- if runtime then
- report_resolvers("skipping list of '%s' (runtime)",path)
- else
- report_resolvers("skipping list of '%s' (cached)",path)
- end
+ local spec = resolvers.splitmethod(stripped)
+ if spec.scheme == "cache" or spec.scheme == "file" then
+ stripped = spec.path
+ elseif runtime and (spec.noscheme or spec.scheme == "file") then
+ stripped = "tree:///" .. stripped
+ end
+ if trace_locating then
+ if runtime then
+ report_resolvers("locating list of '%s' (runtime)",path)
+ else
+ report_resolvers("locating list of '%s' (cached)",path)
end
end
+ methodhandler('locators',stripped)
end
end
if trace_locating then
@@ -584,16 +568,16 @@ function resolvers.expandvariables()
local engine, progname = instance.engine, instance.progname
if type(engine) ~= "string" then instance.engine, engine = "", "" end
if type(progname) ~= "string" then instance.progname, progname = "", "" end
- if engine ~= "" then environment['engine'] = engine end
- if progname ~= "" then environment['progname'] = progname end
+ if engine ~= "" then environment.engine = engine end
+ if progname ~= "" then environment.progname = progname end
for k,v in next, environment do
expansions[k] = v
end
- for k,v in next, environment do -- move environment to expansions (variables are already in there)
- if not expansions[k] then expansions[k] = v end
- end
+ -- for k,v in next, environment do -- move environment to expansions (variables are already in there)
+ -- if expansions[k] == nil then expansions[k] = v end
+ -- end
for k,v in next, variables do -- move variables to expansions
- if not expansions[k] then expansions[k] = v end
+ if expansions[k] == nil then expansions[k] = v end
end
repeat
local busy = false
@@ -847,7 +831,8 @@ local function collect_files(names)
if type(blobfile) == 'string' then
if not dname or find(blobfile,dname) then
local kind = hash.type
- local search = filejoin(blobpath,blobfile,bname)
+--~ local search = filejoin(blobpath,blobfile,bname)
+local search = filejoin(blobroot,blobfile,bname)
local result = methodhandler('concatinators',hash.type,blobroot,blobfile,bname)
if trace_detail then
report_resolvers("match: kind '%s', search '%s', result '%s'",kind,search,result)
@@ -860,7 +845,8 @@ local function collect_files(names)
local vv = blobfile[kk]
if not dname or find(vv,dname) then
local kind = hash.type
- local search = filejoin(blobpath,vv,bname)
+--~ local search = filejoin(blobpath,vv,bname)
+local search = filejoin(blobroot,vv,bname)
local result = methodhandler('concatinators',hash.type,blobroot,vv,bname)
if trace_detail then
report_resolvers("match: kind '%s', search '%s', result '%s'",kind,search,result)
@@ -1105,8 +1091,8 @@ local function collect_instance_files(filename,askedformat,allresults) -- todo :
local f = fl[2]
local d = dirlist[k]
if find(d,expression) then
- --- todo, test for readable
- result[#result+1] = fl[3]
+ -- todo, test for readable
+ result[#result+1] = resolvers.resolve(fl[3]) -- no shortcut
done = true
if allresults then
if trace_detail then