summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/data-fil.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/data-fil.lua')
-rw-r--r--tex/context/base/mkiv/data-fil.lua83
1 files changed, 57 insertions, 26 deletions
diff --git a/tex/context/base/mkiv/data-fil.lua b/tex/context/base/mkiv/data-fil.lua
index b699fc9e3..bbcc954b2 100644
--- a/tex/context/base/mkiv/data-fil.lua
+++ b/tex/context/base/mkiv/data-fil.lua
@@ -6,48 +6,57 @@ if not modules then modules = { } end modules ['data-fil'] = {
license = "see context related readme files"
}
+local ioopen = io.open
+local isdir = lfs.isdir
+
local trace_locating = false trackers.register("resolvers.locating", function(v) trace_locating = v end)
local report_files = logs.reporter("resolvers","files")
-local resolvers = resolvers
-local resolveprefix = resolvers.resolve
+local resolvers = resolvers
+local resolveprefix = resolvers.resolve
+local findfile = resolvers.findfile
+local scanfiles = resolvers.scanfiles
+local registerfilehash = resolvers.registerfilehash
+local appendhash = resolvers.appendhash
-local finders, openers, loaders, savers = resolvers.finders, resolvers.openers, resolvers.loaders, resolvers.savers
-local locators, hashers, generators, concatinators = resolvers.locators, resolvers.hashers, resolvers.generators, resolvers.concatinators
+local loadcachecontent = caches.loadcontent
-local checkgarbage = utilities.garbagecollector and utilities.garbagecollector.check
+local checkgarbage = utilities.garbagecollector and utilities.garbagecollector.check
-function locators.file(specification)
+function resolvers.locators.file(specification)
local filename = specification.filename
local realname = resolveprefix(filename) -- no shortcut
- if realname and realname ~= '' and lfs.isdir(realname) then
+ if realname and realname ~= '' and isdir(realname) then
if trace_locating then
report_files("file locator %a found as %a",filename,realname)
end
- resolvers.appendhash('file',filename,true) -- cache
+ appendhash('file',filename,true) -- cache
elseif trace_locating then
report_files("file locator %a not found",filename)
end
end
-function hashers.file(specification)
+function resolvers.hashers.file(specification)
local pathname = specification.filename
- local content = caches.loadcontent(pathname,'files')
- resolvers.registerfilehash(pathname,content,content==nil)
+ local content = loadcachecontent(pathname,'files')
+ registerfilehash(pathname,content,content==nil)
end
-function generators.file(specification)
+function resolvers.generators.file(specification)
local pathname = specification.filename
- local content = resolvers.scanfiles(pathname,false,true) -- scan once
- resolvers.registerfilehash(pathname,content,true)
+ local content = scanfiles(pathname,false,true) -- scan once
+ registerfilehash(pathname,content,true)
end
-concatinators.file = file.join
+resolvers.concatinators.file = file.join
+
+local finders = resolvers.finders
+local notfound = finders.notfound
function finders.file(specification,filetype)
local filename = specification.filename
- local foundname = resolvers.findfile(filename,filetype)
+ local foundname = findfile(filename,filetype)
if foundname and foundname ~= "" then
if trace_locating then
report_files("file finder: %a found",filename)
@@ -57,42 +66,64 @@ function finders.file(specification,filetype)
if trace_locating then
report_files("file finder: %a not found",filename)
end
- return finders.notfound()
+ return notfound()
end
end
-- The default textopener will be overloaded later on.
-function openers.helpers.textopener(tag,filename,f)
+local openers = resolvers.openers
+local notfound = openers.notfound
+local overloaded = false
+
+local function textopener(tag,filename,f)
return {
- reader = function() return f:read () end,
- close = function() logs.show_close(filename) return f:close() end,
+ reader = function() return f:read () end,
+ close = function() return f:close() end,
}
end
+function openers.helpers.textopener(...)
+ return textopener(...)
+end
+
+function openers.helpers.settextopener(opener)
+ if overloaded then
+ report_files("file opener: %s overloaded","already")
+ else
+ if trace_locating then
+ report_files("file opener: %s overloaded","once")
+ end
+ overloaded = true
+ textopener = opener
+ end
+end
+
function openers.file(specification,filetype)
local filename = specification.filename
if filename and filename ~= "" then
- local f = io.open(filename,"r")
+ local f = ioopen(filename,"r")
if f then
if trace_locating then
report_files("file opener: %a opened",filename)
end
- return openers.helpers.textopener("file",filename,f)
+ return textopener("file",filename,f)
end
end
if trace_locating then
report_files("file opener: %a not found",filename)
end
- return openers.notfound()
+ return notfound()
end
+local loaders = resolvers.loaders
+local notfound = loaders.notfound
+
function loaders.file(specification,filetype)
local filename = specification.filename
if filename and filename ~= "" then
- local f = io.open(filename,"rb")
+ local f = ioopen(filename,"rb")
if f then
- logs.show_load(filename)
if trace_locating then
report_files("file loader: %a loaded",filename)
end
@@ -109,5 +140,5 @@ function loaders.file(specification,filetype)
if trace_locating then
report_files("file loader: %a not found",filename)
end
- return loaders.notfound()
+ return notfound()
end