1-- 2-- This is file `luatex-hyphen.lua', 3-- generated with the docstrip utility. 4-- 5-- The original source files were: 6-- 7-- luatex-hyphen.dtx (with options: `lua') 8-- 9-- This is a generated file (source: luatex-hyphen.dtx). 10-- 11-- Copyright (C) 2012 by The LuaLaTeX development team. 12-- 13-- This work is under the CC0 license. 14-- 15luatexhyphen = luatexhyphen or {} 16local luatexhyphen = luatexhyphen 17local function wlog(msg, ...) 18 texio.write_nl('log', 'luatex-hyphen: '..msg:format(...)) 19end 20local function err(msg, ...) 21 error('luatex-hyphen: '..msg:format(...), 2) 22end 23local dbname = "language.dat.lua" 24local language_dat 25local dbfile = kpse.find_file(dbname, 'lua') 26if not dbfile then 27 err("file not found: "..dbname) 28else 29 wlog('using data file: %s', dbfile) 30 language_dat = dofile(dbfile) 31end 32local function lookupname(name) 33 if language_dat[name] then 34 return language_dat[name], name 35 else 36 for canon, data in pairs(language_dat) do 37 for _,syn in ipairs(data.synonyms) do 38 if syn == name then 39 return data, canon 40 end 41 end 42 end 43 end 44end 45luatexhyphen.lookupname = lookupname 46local function loadlanguage(lname, id) 47 if id == 0 then 48 return 49 end 50 local msg = "loading%s patterns and exceptions for: %s (\\language%d)" 51 local ldata, cname = lookupname(lname) 52 if not ldata then 53 err("no entry in %s for this language: %s", dbname, lname) 54 end 55 if ldata.special then 56 if ldata.special:find('^disabled:') then 57 err("language disabled by %s: %s (%s)", dbname, cname, 58 ldata.special:gsub('^disabled:', '')) 59 elseif ldata.special == 'language0' then 60 err("\\language0 should be dumped in the format") 61 else 62 err("bad entry in %s for language %s") 63 end 64 end 65 wlog(msg, '', cname, id) 66 for _, item in ipairs{'patterns', 'hyphenation'} do 67 local filelist = ldata[item] 68 if filelist ~= nil and filelist ~= '' then 69 for _, file in ipairs(filelist:explode(',')) do 70 local file = kpse.find_file(file) or err("file not found: %s", file) 71 local fh = io.open(file, 'r') 72 local data = fh:read('*a') or err("file not readable: %s", f) 73 fh:close() 74 lang[item](lang.new(id), data) 75 end 76 else 77 if item == 'hyphenation' then item = item..' exceptions' end 78 wlog("info: no %s for this language", item) 79 end 80 end 81end 82luatexhyphen.loadlanguage = loadlanguage 83local function adddialect(dialect, language) 84 if dialect ~= '0' then 85 dialect = dialect:gsub('l@', '') 86 language = language:gsub('l@', '') 87 data = lookupname(language) 88 if data then 89 data.synonyms[#data.synonyms+1] = dialect 90 end 91 end 92end 93luatexhyphen.adddialect = adddialect 94-- 95-- End of File `luatex-hyphen.lua'. 96