type-ini.lua /size: 2833 b    last modification: 2021-10-28 13:50
1if not modules then modules = { } end modules ['type-ini'] = {
2    version   = 1.001,
3    comment   = "companion to type-ini.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9local gsub = string.gsub
10local lpegmatch, P, Cs = lpeg.match, lpeg.P, lpeg.Cs
11
12-- more code will move here
13
14local commands   = commands
15local context    = context
16local implement  = interfaces.implement
17
18local uselibrary = resolvers.uselibrary
19
20local p_strip    = Cs((P("type-") * (P("imp-")^0))^0/"" * P(1)^0)
21
22local report     = logs.reporter("fonts","typescripts")
23
24local function action(name,foundname)
25    context.loadfoundtypescriptfile(name,foundname)
26end
27
28local patterns = {
29    "type-imp-%s.mkxl",
30    "type-imp-%s.mkiv",
31    "type-imp-%s.tex"
32}
33
34local function failure(name)
35    if name == "loc" then
36        -- ignore
37    else
38        report("unknown library %a",name)
39    end
40end
41
42implement {
43    name      = "loadtypescriptfile",
44    arguments = "string",
45    actions   = function(name) -- a more specific name
46        uselibrary {
47            name     = lpegmatch(p_strip,name) or name,
48            patterns = patterns,
49            action   = action,
50            failure  = failure,
51            onlyonce = false, -- will become true
52        }
53    end
54}
55
56local patterns = {
57    "type-imp-%s.mkxl",
58    "type-imp-%s.mkiv",
59    "type-imp-%s.tex",
60    -- obsolete
61    "type-%s.mkiv",
62    "type-%s.tex"
63}
64
65-- local name_one   = nil
66-- local name_two   = nil
67--
68-- local function failure_two(name)
69--     report("unknown library %a or %a",name_one,name_two)
70-- end
71--
72-- local function failure_one(name)
73--     name_two = gsub(name,"%-.*$","")
74--     if name == "loc" then
75--         -- ignore
76--     elseif name_two == name then
77--         report("unknown library %a",name_one)
78--     else
79--         resolvers.uselibrary {
80--             name     = name_two,
81--             patterns = patterns,
82--             action   = action,
83--             failure  = failure_two,
84--             onlyonce = false, -- will become true
85--         }
86--     end
87-- end
88--
89-- function commands.doprocesstypescriptfile(name)
90--     name_one = lpegmatch(p_strip,name) or name
91--     uselibrary {
92--         name     = name_one,
93--         patterns = patterns,
94--         action   = action,
95--         failure  = failure_one,
96--         onlyonce = false, -- will become true
97--     }
98-- end
99
100implement {
101    name      = "doprocesstypescriptfile",
102    arguments = "string",
103    actions   = function(name)
104        uselibrary {
105            name     = lpegmatch(p_strip,name) or name,
106            patterns = patterns,
107            action   = action,
108            failure  = failure,
109            onlyonce = false, -- will become true
110        }
111    end
112}
113