diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luaotfload/luaotfload-parsers.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luaotfload/luaotfload-parsers.lua | 132 |
1 files changed, 81 insertions, 51 deletions
diff --git a/Master/texmf-dist/tex/luatex/luaotfload/luaotfload-parsers.lua b/Master/texmf-dist/tex/luatex/luaotfload/luaotfload-parsers.lua index 3a4faea9b56..0349cdc7738 100644 --- a/Master/texmf-dist/tex/luatex/luaotfload/luaotfload-parsers.lua +++ b/Master/texmf-dist/tex/luatex/luaotfload/luaotfload-parsers.lua @@ -2,24 +2,12 @@ ------------------------------------------------------------------------------- -- FILE: luaotfload-parsers.lua -- DESCRIPTION: various lpeg-based parsers used in Luaotfload --- REQUIREMENTS: Luaotfload > 2.4 --- AUTHOR: Philipp Gesang (Phg), <phg42.2a@gmail.com> --- VERSION: same as Luaotfload --- CREATED: 2014-01-14 10:15:20+0100 +-- REQUIREMENTS: Luaotfload >= 2.6 +-- AUTHOR: Philipp Gesang (Phg), <phg@phi-gamma.net> ------------------------------------------------------------------------------- -- -if not modules then modules = { } end modules ['luaotfload-parsers'] = { - version = "2.5", - comment = "companion to luaotfload-main.lua", - author = "Philipp Gesang", - copyright = "Luaotfload Development Team", - license = "GNU GPL v2.0" -} - -luaotfload = luaotfload or { } -luaotfload.parsers = luaotfload.parsers or { } -local parsers = luaotfload.parsers +local traversal_maxdepth = 42 --- prevent stack overflows local rawset = rawset @@ -40,8 +28,7 @@ local filedirname = file.dirname local io = io local ioopen = io.open -local log = luaotfload.log -local logreport = log.report +local logreport = print local string = string local stringsub = string.sub @@ -190,6 +177,7 @@ local p_cheapxml = header * root --doc]]-- --- string -> path list local fonts_conf_scanner = function (path) + logreport("both", 5, "db", "Read fontconfig file %s.", path) local fh = ioopen(path, "r") if not fh then logreport("both", 3, "db", "Cannot open fontconfig file %s.", path) @@ -197,12 +185,17 @@ local fonts_conf_scanner = function (path) end local raw = fh:read"*all" fh:close() + logreport("both", 7, "db", + "Reading fontconfig file %s completed (%d bytes).", + path, #raw) + logreport("both", 5, "db", "Scan fontconfig file %s.", path) local confdata = lpegmatch(p_cheapxml, raw) if not confdata then logreport("both", 3, "db", "Cannot scan fontconfig file %s.", path) return end + logreport("both", 7, "db", "Scan of fontconfig file %s completed.", path) return confdata end @@ -220,8 +213,9 @@ end read_fonts_conf_indeed() -- Scan paths included from fontconfig configuration files recursively. Called with eight arguments. - The first four are + The first five are + · the current recursion depth · the path to the file · the expanded $HOME · the expanded $XDG_CONFIG_HOME @@ -234,12 +228,13 @@ end --doc]]-- ---- string -> string -> string -> string +--- size_t -> string -> string -> string -> string --- -> string list -> string list -> string list --- -> (string -> fun option -> string list) --- -> tab * tab * tab local read_fonts_conf_indeed -read_fonts_conf_indeed = function (start, +read_fonts_conf_indeed = function (depth, + start, home, xdg_config_home, xdg_data_home, @@ -248,6 +243,18 @@ read_fonts_conf_indeed = function (start, dirs_done, find_files) + logreport ("both", 4, "db", + "Fontconfig scanner processing path %s.", + start) + if depth >= traversal_maxdepth then + --- prevent overflow of Lua call stack + logreport ("both", 0, "db", + "Fontconfig scanner hit recursion limit (%d); " + .. "aborting directory traversal.", + traversal_maxdepth) + return acc, done, dirs_done + end + local paths = fonts_conf_scanner(start) if not paths then --- nothing to do return acc, done, dirs_done @@ -273,6 +280,9 @@ read_fonts_conf_indeed = function (start, --- distributions (e.g. Context minimals) installed --- separately? if not (stringfind(path, "texmf") or dirs_done[path]) then + logreport ("log", 5, "db", + "New fontconfig path at %s.", + path) acc[#acc+1] = path dirs_done[path] = true end @@ -292,34 +302,45 @@ read_fonts_conf_indeed = function (start, end if lfsisfile(path) and kpsereadable_file(path) - and not done[path] then - --- we exclude path with texmf in them, as they should - --- be found otherwise - acc = read_fonts_conf_indeed(path, - home, - xdg_config_home, - xdg_data_home, - acc, - done, - dirs_done, - find_files) + if done[path] then + logreport("log", 3, "db", + "Skipping file at %s, already included.", path) + else + done[path] = true + acc = read_fonts_conf_indeed(depth + 1, + path, + home, + xdg_config_home, + xdg_data_home, + acc, + done, + dirs_done, + find_files) + end elseif lfsisdir(path) then --- arrow code ahead local config_files = find_files (path, conf_filter) for _, filename in next, config_files do if not done[filename] then - acc = read_fonts_conf_indeed(filename, - home, - xdg_config_home, - xdg_data_home, - acc, - done, - dirs_done, - find_files) + if done[path] then + logreport ("log", 3, "db", + "Skipping file at %s, already included.", path) + else + done[path] = true + acc = read_fonts_conf_indeed(depth + 1, + filename, + home, + xdg_config_home, + xdg_data_home, + acc, + done, + dirs_done, + find_files) + end end end end --- match “kind” - end --- iterate paths + end --- iterate paths end --inspect(acc) @@ -350,7 +371,8 @@ local read_fonts_conf = function (path_list, find_files) local done = { } ---> set: files inspected local dirs_done = { } ---> set: dirs in list for i=1, #path_list do --- we keep the state between files - acc, done, dirs_done = read_fonts_conf_indeed(path_list[i], + acc, done, dirs_done = read_fonts_conf_indeed(0, + path_list[i], home, xdg_config_home, xdg_data_home, @@ -362,10 +384,6 @@ local read_fonts_conf = function (path_list, find_files) return acc end -luaotfload.parsers.read_fonts_conf = read_fonts_conf - - - ------------------------------------------------------------------------------- --- MISC PARSERS ------------------------------------------------------------------------------- @@ -373,10 +391,8 @@ luaotfload.parsers.read_fonts_conf = read_fonts_conf local trailingslashes = slash^1 * P(-1) local stripslashes = C((1 - trailingslashes)^0) -parsers.stripslashes = stripslashes local splitcomma = Ct((C(noncomma^1) + comma)^1) -parsers.splitcomma = splitcomma @@ -616,8 +632,6 @@ local font_request = Ct(path_lookup * (colon^-1 * features)^-1 --- v2.5 parser: 1065 rules --- v1.2 parser: 230 rules -luaotfload.parsers.font_request = font_request - ------------------------------------------------------------------------------- --- INI FILES ------------------------------------------------------------------------------- @@ -694,7 +708,7 @@ local ini_variables = Cg (Cf (Ct "" * ini_variable^0, rawset), "variables") local ini_section = Ct (ini_heading * ini_variables) local ini_sections = skip_line^0 * ini_section^0 -local config = Ct (ini_sections) +local parse_config = Ct (ini_sections) --[=[doc-- @@ -726,6 +740,22 @@ local config = Ct (ini_sections) --doc]=]-- -luaotfload.parsers.config = config +return { + init = function () + logreport = luaotfload.log.report + luaotfload.parsers = { + --- parameters + traversal_maxdepth = traversal_maxdepth, + --- main parsers + read_fonts_conf = read_fonts_conf, + font_request = font_request, + config = parse_config, + --- common patterns + stripslashes = stripslashes, + splitcomma = splitcomma, + } + return true + end +} -- vim:ft=lua:tw=71:et:sw=2:sts=4:ts=8 |