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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
if not modules then modules = { } end modules ['regi-ini'] = {
version = 1.001,
comment = "companion to regi-ini.tex",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local utf = unicode.utf8
local char, utfchar = string.char, utf.char
local texsprint = tex.sprint
local ctxcatcodes = tex.ctxcatcodes
--[[ldx--
<p>Regimes take care of converting the input characters into
<l n='utf'/> sequences. The conversion tables are loaded at
runtime.</p>
--ldx]]--
regimes = regimes or { }
regimes.data = regimes.data or { }
regimes.utf = regimes.utf or { }
regimes.synonyms = regimes.synonyms or { }
storage.register("regimes/synonyms", regimes.synonyms, "regimes.synonyms")
-- setmetatable(regimes.data,_empty_table_)
regimes.currentregime = "utf"
--[[ldx--
<p>We will hook regime handling code into the input methods.</p>
--ldx]]--
function regimes.number(n)
if type(n) == "string" then return tonumber(n,16) else return n end
end
function regimes.setsynonym(synonym,target)
regimes.synonyms[synonym] = target
end
function regimes.truename(regime)
texsprint(ctxcatcodes,(regime and regimes.synonyms[synonym] or regime) or regimes.currentregime)
end
function regimes.load(regime)
regime = regimes.synonyms[regime] or regime
if not regimes.data[regime] then
environment.loadluafile("regi-"..regime, 1.001)
if regimes.data[regime] then
regimes.utf[regime] = { }
for k,v in pairs(regimes.data[regime]) do
regimes.utf[regime][char(k)] = utfchar(v)
end
end
end
end
function regimes.translate(line,regime)
regime = regimes.synonyms[regime] or regime
if regime and line then
local rur = regimes.utf[regime]
if rur then
return line:gsub("(.)", rur) -- () redundant
end
end
return line
end
function regimes.enable(regime)
regime = regimes.synonyms[regime] or regime
if regimes.data[regime] then
regimes.currentregime = regime
local translate = regimes.translate
resolvers.install_text_filter('input',function(s)
return translate(s,regime)
end)
else
regimes.disable()
end
end
function regimes.disable()
regimes.currentregime = "utf"
resolvers.install_text_filter('input',nil)
end
|