summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/file-syn.lua
blob: b6ad27c832547916a47bb499025dedfa7834f74a (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
if not modules then modules = { } end modules ['file-syn'] = {
    version   = 1.001,
    comment   = "companion to file-syn.mkvi",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}


environment.filesynonyms = environment.filesynonyms or { }
local filesynonyms       = environment.filesynonyms

local settings_to_array  = utilities.parsers.settings_to_array
local findfile           = resolvers.findfile

local implement          = interfaces.implement

local report_files       = logs.reporter("files")

storage.register("environment/filesynonyms", filesynonyms, "environment.filesynonyms")

local function truefilename(name)
    local realname = filesynonyms[name] or name
    if realname ~= name then
        return truefilename(realname)
    else
        return realname
    end
end

environment.truefilename = truefilename

function environment.definefilesynonym(name,realname)
    local names = settings_to_array(name)
    for i=1,#names do
        local name = names[i]
        local synonym = filesynonyms[name]
        if synonym then
            interfaces.showmessage("files",1,{ name or "?", realname or "?", synonym or "?" })
        end
        filesynonyms[name] = realname
    end
end

function environment.definefilefallback(name,alternatives)
    local names = settings_to_array(alternatives)
    for i=1,#names do
        local realname = findfile(names[i])
        if realname ~= "" then
            filesynonyms[name] = realname
            break
        end
    end
end

implement {
    name      = "truefilename",
    actions   = { truefilename, context },
    arguments = "string"
}

implement {
    name      = "definefilesynonym",
    actions   = environment.definefilesynonym,
    arguments = { "string", "string" }
}

implement {
    name      = "definefilefallback",
    actions   = environment,definefilefallback,
    arguments = { "string", "string" }
}