From bc10e60257b5b448e6fcc7bfaeef633fa2e19735 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Thu, 10 Jul 2014 13:14:00 +0200 Subject: beta 2014.07.10 13:14 --- tex/context/base/file-lib.lua | 89 ++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 52 deletions(-) (limited to 'tex/context/base/file-lib.lua') diff --git a/tex/context/base/file-lib.lua b/tex/context/base/file-lib.lua index 409559cd3..7489a317b 100644 --- a/tex/context/base/file-lib.lua +++ b/tex/context/base/file-lib.lua @@ -11,8 +11,16 @@ if not modules then modules = { } end modules ['file-lib'] = { local format = string.format -local trace_files = false trackers.register("resolvers.readfile", function(v) trace_files = v end) -local report_files = logs.reporter("files","readfile") +local trace_libraries = false trackers.register("resolvers.libraries", function(v) trace_libraries = v end) +----- trace_files = false trackers.register("resolvers.readfile", function(v) trace_files = v end) + +local report_library = logs.reporter("files","library") +----- report_files = logs.reporter("files","readfile") + +local suffixonly = file.suffix +local removesuffix = file.removesuffix + +local getreadfilename = resolvers.getreadfilename local loaded = { } local defaultpatterns = { "%s" } @@ -25,45 +33,6 @@ local function defaultfailure(name) report_files("asked name %a, not found",name) end --- function commands.uselibrary(specification) -- todo; reporter --- local name = specification.name --- if name and name ~= "" then --- local patterns = specification.patterns or defaultpatterns --- local action = specification.action or defaultaction --- local failure = specification.failure or defaultfailure --- local onlyonce = specification.onlyonce --- local files = utilities.parsers.settings_to_array(name) --- local truename = environment.truefilename --- local done = false --- for i=1,#files do --- local filename = files[i] --- if not loaded[filename] then --- if onlyonce then --- loaded[filename] = true -- todo: base this on return value --- end --- for i=1,#patterns do --- local somename = format(patterns[i],filename) --- if truename then --- somename = truename(somename) --- end --- local foundname = resolvers.getreadfilename("any",".",somename) or "" --- if foundname ~= "" then --- action(name,foundname) --- done = true --- break --- end --- end --- if done then --- break --- end --- end --- end --- if failure and not done then --- failure(name) --- end --- end --- end - function commands.uselibrary(specification) -- todo: reporter local name = specification.name if name and name ~= "" then @@ -73,6 +42,11 @@ function commands.uselibrary(specification) -- todo: reporter local onlyonce = specification.onlyonce local files = utilities.parsers.settings_to_array(name) local truename = environment.truefilename + local function found(filename) + local somename = truename and truename(filename) or filename + local foundname = getreadfilename("any",".",somename) + return foundname ~= "" and foundname + end for i=1,#files do local filename = files[i] if loaded[filename] then @@ -81,20 +55,31 @@ function commands.uselibrary(specification) -- todo: reporter if onlyonce then loaded[filename] = true -- todo: base this on return value end - local done = false - for i=1,#patterns do - local somename = format(patterns[i],filename) - if truename then - somename = truename(somename) + local foundname = nil + local barename = removesuffix(filename) + -- direct search (we have an explicit suffix) + if barename ~= filename then + foundname = found(filename) + if trace_libraries then + report_library("checking %a: %s",filename,foundname or "not found") end - local foundname = resolvers.getreadfilename("any",".",somename) or "" - if foundname ~= "" then - action(name,foundname) - done = true - break + end + if not foundname then + -- pattern based search + for i=1,#patterns do + local wanted = format(patterns[i],barename) + foundname = found(wanted) + if trace_libraries then + report_library("checking %a as %a: %s",filename,wanted,foundname or "not found") + end + if foundname then + break + end end end - if failure and not done then + if foundname then + action(name,foundname) + elseif failure then failure(name) end end -- cgit v1.2.3