summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/hyph-utf8/luatex-hyphen.lua
blob: 6b547fab7aca94475a55d6bb72c835ccd0d41ddd (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
-- 
--  This is file `luatex-hyphen.lua',
--  generated with the docstrip utility.
-- 
--  The original source files were:
-- 
--  luatex-hyphen.dtx  (with options: `lua')
--  
--  This is a generated file (source: luatex-hyphen.dtx).
--  
--  Copyright (C) 2012 by The LuaLaTeX development team.
--  
--  This work is under the CC0 license.
--  
luatexhyphen = luatexhyphen or {}
local luatexhyphen = luatexhyphen
local function wlog(msg, ...)
    texio.write_nl('log', 'luatex-hyphen: '..msg:format(...))
end
local function err(msg, ...)
    error('luatex-hyphen: '..msg:format(...), 2)
end
local dbname = "language.dat.lua"
local language_dat
local dbfile = kpse.find_file(dbname, 'lua')
if not dbfile then
    err("file not found: "..dbname)
else
    wlog('using data file: %s', dbfile)
    language_dat = dofile(dbfile)
end
local function lookupname(name)
    if language_dat[name] then
        return language_dat[name], name
    else
        for canon, data in pairs(language_dat) do
            for _,syn in ipairs(data.synonyms) do
                if syn == name then
                    return data, canon
                end
            end
        end
    end
end
luatexhyphen.lookupname = lookupname
local function loadlanguage(lname, id)
    if id == 0 then
        return
    end
    local msg = "loading%s patterns and exceptions for: %s (\\language%d)"
    local ldata, cname = lookupname(lname)
    if not ldata then
        err("no entry in %s for this language: %s", dbname, lname)
    end
    if ldata.special then
        if ldata.special:find('^disabled:') then
            err("language disabled by %s: %s (%s)", dbname, cname,
                ldata.special:gsub('^disabled:', ''))
        elseif ldata.special == 'language0' then
            err("\\language0 should be dumped in the format")
        else
            err("bad entry in %s for language %s")
        end
    end
    wlog(msg, '', cname, id)
    for _, item in ipairs{'patterns', 'hyphenation'} do
        local filelist = ldata[item]
        if filelist ~= nil and filelist ~= '' then
          for _, file in ipairs(filelist:explode(',')) do
            local file = kpse.find_file(file) or err("file not found: %s", file)
            local fh = io.open(file, 'r')
            local data = fh:read('*a') or err("file not readable: %s", f)
            fh:close()
            lang[item](lang.new(id), data)
          end
        else
            if item == 'hyphenation' then item = item..' exceptions' end
            wlog("info: no %s for this language", item)
        end
    end
end
luatexhyphen.loadlanguage = loadlanguage
local function adddialect(dialect, language)
    if dialect ~= '0' then
        dialect = dialect:gsub('l@', '')
        language = language:gsub('l@', '')
        data = lookupname(language)
        if data then
            data.synonyms[#data.synonyms+1] = dialect
        end
    end
end
luatexhyphen.adddialect = adddialect
-- 
--  End of File `luatex-hyphen.lua'.