summaryrefslogtreecommitdiff
path: root/tex/context/base/data-met.lua
blob: 7f2e612e8a19a890e1096267db76aababc3357d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
if not modules then modules = { } end modules ['data-met'] = {
    version   = 1.100,
    comment   = "companion to luat-lib.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local find = string.find

local trace_locating   = false  trackers.register("resolvers.locating",   function(v) trace_locating   = v end)

local report_resolvers = logs.new("resolvers")

resolvers.locators     = { notfound = { nil } }  -- locate databases
resolvers.hashers      = { notfound = { nil } }  -- load databases
resolvers.generators   = { notfound = { nil } }  -- generate databases

function resolvers.splitmethod(filename)
    if not filename then
        return { } -- safeguard
    elseif type(filename) == "table" then
        return filename -- already split
    elseif not find(filename,"://") then
        return { scheme="file", path = filename, original = filename } -- quick hack
    else
        return url.hashed(filename)
    end
end

function resolvers.methodhandler(what, filename, filetype) -- ...
    filename = file.collapse_path(filename)
    local specification = (type(filename) == "string" and resolvers.splitmethod(filename)) or filename -- no or { }, let it bomb
    local scheme = specification.scheme
    local resolver = resolvers[what]
    if resolver[scheme] then
        if trace_locating then
            report_resolvers("handler '%s' -> '%s' -> '%s'",specification.original,what,table.sequenced(specification))
        end
        return resolver[scheme](filename,filetype)
    else
        return resolver.tex(filename,filetype) -- todo: specification
    end
end