summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-04-15 00:14:23 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2013-04-15 00:14:23 +0200
commit25444ac8cd48cd5ad7ed32bfcc9a0a1314e2223a (patch)
treee56c6909cdfacac4f383f203fdd8c228c41fae76
parent7b6553218a35e5f74ad2013a1a16f54b8aa4f2ca (diff)
downloadluaotfload-25444ac8cd48cd5ad7ed32bfcc9a0a1314e2223a.tar.gz
rewrite filename logger
-rwxr-xr-xmkluatexfontdb.lua10
-rw-r--r--otfl-font-nms.lua95
-rw-r--r--otfl-luat-ovr.lua34
3 files changed, 69 insertions, 70 deletions
diff --git a/mkluatexfontdb.lua b/mkluatexfontdb.lua
index ec8396f..956fa18 100755
--- a/mkluatexfontdb.lua
+++ b/mkluatexfontdb.lua
@@ -24,11 +24,11 @@ _G.config = _G.config or { }
local config = _G.config
config.lualibs = config.lualibs or { }
config.lualibs.prefer_merged = false
-config.lualibs.load_extended = true
+config.lualibs.load_extended = false
require"lualibs"
require"otfl-basics-gen.lua"
-require"otfl-luat-ovr.lua"
+require"otfl-luat-ovr.lua" --- this populates the logs.* namespace
require"otfl-font-nms"
require"alt_getopt"
@@ -84,7 +84,9 @@ local short_options = "fqpvVh"
local force_reload = nil
local function process_cmdline()
- local options, _, _ = alt_getopt.get_ordered_opts (arg, short_options, long_options)
+ local options, _, _ = alt_getopt.get_ordered_opts (arg,
+ short_options,
+ long_options)
local log_level = 1
for _,v in next, options do
if v == "q" then
@@ -105,7 +107,7 @@ local function process_cmdline()
force_reload = 1
end
end
- names.set_log_level(log_level)
+ logs.set_loglevel(log_level)
end
local function generate(force)
diff --git a/otfl-font-nms.lua b/otfl-font-nms.lua
index 856046c..b2b5390 100644
--- a/otfl-font-nms.lua
+++ b/otfl-font-nms.lua
@@ -42,7 +42,6 @@ local utfgsub = unicode.utf8.gsub
local suppress_output = false
local trace_short = false --tracing adapted to rebuilding of the database inside a document
local trace_search = false --trackers.register("names.search", function(v) trace_search = v end)
-local trace_loading = false --trackers.register("names.loading", function(v) trace_loading = v end)
local function sanitize(str)
if str then
@@ -244,37 +243,11 @@ end
names.resolvespec = names.resolve
-function names.set_log_level(level)
- if level == 0 then
- suppress_output = true
- elseif level == 2 then
- trace_loading = true
- elseif level >= 3 then
- trace_loading = true
- trace_search = true
- end
-end
-
-local function log (category, fmt, ...)
- if not suppress_output then
- if fmt then
- texio.write_nl(format("luaotfload | %s: %s", category, format(fmt, ...)))
- elseif category then
- texio.write_nl(format("luaotfload | %s", category))
- else
- texio.write_nl(format("luaotfload |"))
- end
- io.flush()
- end
-end
-
local function font_fullinfo(filename, subfont, texmf)
local t = { }
local f = fontloader.open(filename, subfont)
if not f then
- if trace_loading then
- logs.report("error", "failed to open %s", filename)
- end
+ logs.names_loading("error", "failed to open %s", filename)
return
end
local m = fontloader.to_table(f)
@@ -304,9 +277,7 @@ local function font_fullinfo(filename, subfont, texmf)
end
else
-- no names table, propably a broken font
- if trace_loading then
- logs.report("broken font rejected", "%s", basefile)
- end
+ logs.names_loading("broken font rejected", "%s", basefile)
return
end
t.fontname = m.fontname
@@ -359,9 +330,7 @@ local function load_font(filename, fontnames, newfontnames, texmf)
newmappings[#newmappings+1] = mappings[v]
newstatus[basefile].index[index+1] = #newmappings
end
- if trace_loading then
- logs.report("font already indexed", "%s", basefile)
- end
+ logs.names_loading("font already indexed", "%s", basefile)
return
end
local info = fontloader.info(filename)
@@ -396,9 +365,7 @@ local function load_font(filename, fontnames, newfontnames, texmf)
newstatus[basefile].index[1] = index
end
else
- if trace_loading then
- logs.report("failed to load", "%s", basefile)
- end
+ logs.names_loading("failed to load", "%s", basefile)
end
end
end
@@ -479,33 +446,31 @@ end
local installed_fonts_scanned = false
local function scan_installed_fonts(fontnames, newfontnames)
- -- Try to query and add font list from operating system.
- -- This uses the lualatex-platform module.
- logs.info("Scanning fonts known to operating system...")
- local fonts = get_installed_fonts()
- if fonts and #fonts > 0 then
- installed_fonts_scanned = true
- if trace_search then
- logs.report("operating system fonts found", "%d", #fonts)
- end
- for key, value in next, fonts do
- local file = value.path
- if file then
- local ext = extname(file)
- if ext and font_extensions_set[ext] then
- file = path_normalize(file)
- if trace_loading then
- logs.report("loading font", "%s", file)
- end
- load_font(file, fontnames, newfontnames, false)
+ -- Try to query and add font list from operating system.
+ -- This uses the lualatex-platform module.
+ logs.info("Scanning fonts known to operating system...")
+ local fonts = get_installed_fonts()
+ if fonts and #fonts > 0 then
+ installed_fonts_scanned = true
+ if trace_search then
+ logs.report("operating system fonts found", "%d", #fonts)
+ end
+ for key, value in next, fonts do
+ local file = value.path
+ if file then
+ local ext = extname(file)
+ if ext and font_extensions_set[ext] then
+ file = path_normalize(file)
+ logs.names_loading("loading font", "%s", file)
+ load_font(file, fontnames, newfontnames, false)
+ end
end
- end
- end
- else
- if trace_search then
- logs.report("Could not retrieve list of installed fonts")
- end
- end
+ end
+ else
+ if trace_search then
+ logs.report("Could not retrieve list of installed fonts")
+ end
+ end
end
local function scan_dir(dirname, fontnames, newfontnames, texmf)
@@ -539,9 +504,7 @@ local function scan_dir(dirname, fontnames, newfontnames, texmf)
for _,file in next, list do
file = path_normalize(file)
- if trace_loading then
- logs.report("loading font", "%s", file)
- end
+ logs.names_loading("loading font", "%s", file)
load_font(file, fontnames, newfontnames, texmf)
end
end
diff --git a/otfl-luat-ovr.lua b/otfl-luat-ovr.lua
index 984dbf5..63ad6a7 100644
--- a/otfl-luat-ovr.lua
+++ b/otfl-luat-ovr.lua
@@ -11,9 +11,32 @@ local module_name = "luaotfload"
local texiowrite_nl = texio.write_nl
local stringformat = string.format
+local tableconcat = table.concat
local ioflush = io.flush
local dummyfunction = function() end
+--[[doc--
+We recreate the verbosity levels previously implemented in font-nms:
+
+ ==========================================================
+ lvl arg trace_loading trace_search suppress_output
+ ----------------------------------------------------------
+ (0) -> -q ⊥ ⊥ ⊤
+ (1) -> ∅ ⊥ ⊥ ⊥
+ (2) -> -v ⊤ ⊥ ⊥
+ (>2) -> -vv ⊤ ⊤ ⊥
+ ==========================================================
+
+--doc]]--
+local loglevel = 1 --- default
+
+local set_loglevel = function (n)
+ if type(n) == "number" then
+ loglevel = n
+ end
+end
+logs.set_loglevel = set_loglevel
+
function logs.report(category,fmt,...)
if fmt then
texiowrite_nl('log', stringformat("%s | %s: %s",module_name,category,stringformat(fmt,...)))
@@ -35,3 +58,14 @@ function logs.info(category,fmt,...)
ioflush()
end
+logs.names_loading = function (category, fmt, ...)
+ if loglevel > 1 then
+ local res = { module_name, " |" }
+ if category then res[#res+1] = " " .. category end
+ if fmt then res[#res+1] = ": " .. stringformat(fmt, ...) end
+ texiowrite_nl(tableconcat(res))
+ ioflush()
+ end
+end
+
+-- vim:tw=71:sw=4:ts=4:expandtab