summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/luat-tre.lua
blob: e749a5b330a00e9a3de6b36bd706408ca8b14b8c (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
-- filename : luat-tre.lua
-- comment  : companion to luat-lib.tex
-- 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['luat-tre'] = 1.001

-- \input tree://oeps1/**/oeps.tex

do

    local done, found = { }, { }

    function input.finders.tree(instance,specification,filetype)
        local fnd = found[specification]
        if not fnd then
            local spec = input.splitmethod(specification).path or ""
            if spec ~= "" then
                local path, name = file.dirname(spec), file.basename(spec)
                if path == "" then path = "." end
                local hash = done[path]
                if not hash then
                    local pattern = path .. "/*" -- we will use the proper splitter
                    hash = dir.glob(pattern)
                    done[path] = hash
                end
                local pattern = "/" .. name:gsub("([%.%-%+])", "%%%1") .. "$"
                for k, v in pairs(hash) do
                    if v:find(pattern) then
                        found[specification] = v
                        return v
                    end
                end
            end
            fnd = unpack(input.finders.notfound)
            found[specification] = fnd
        end
        return fnd
    end

    input.openers.tree = input.openers.generic
    input.loaders.tree = input.loaders.generic

end