diff options
Diffstat (limited to 'luaotfload-tool.lua')
-rwxr-xr-x | luaotfload-tool.lua | 113 |
1 files changed, 55 insertions, 58 deletions
diff --git a/luaotfload-tool.lua b/luaotfload-tool.lua index 8bc590a..35765b5 100755 --- a/luaotfload-tool.lua +++ b/luaotfload-tool.lua @@ -9,7 +9,10 @@ -- MODIFIED: 2014-01-14 13:17:04+0100 ----------------------------------------------------------------------- -local version = "2.5" --- <int: major>.<int: minor><alpha: fixes> +luaotfload = luaotfload or { } +local version = "2.5" --- <int: major>.<int: minor>-<int: fixes> +luaotfload.version = version +luaotfload.self = "luaotfload-tool" --[[doc-- @@ -104,8 +107,6 @@ if not luaotfloadconfig.strip then luaotfloadconfig.strip = true end -luaotfloadconfig.self = "luaotfload-tool" - config.lualibs = config.lualibs or { } config.lualibs.verbose = false config.lualibs.prefer_merged = true @@ -141,23 +142,24 @@ require"luaotfload-basics-gen.lua" texio.write, texio.write_nl = backup.write, backup.write_nl utilities = backup.utilities -require"luaotfload-override.lua" --- this populates the logs.* namespace +require"luaotfload-log.lua" --- this populates the luaotfload.log.* namespace require"luaotfload-parsers" --- fonts.conf and request syntax require"luaotfload-database" require"alt_getopt" -local names = fonts.names - +local names = fonts.names local status_file = "luaotfload-status" local luaotfloadstatus = require (status_file) luaotfloadconfig.status = luaotfloadstatus - local sanitize_fontname = names.sanitize_fontname -local pathdata = names.path -local names_plain = pathdata.index.lua -local names_gzip = names_plain .. ".gz" -local names_bin = pathdata.index.luc +local log = luaotfload.log +local report = log.report + +local pathdata = names.path +local names_plain = pathdata.index.lua +local names_gzip = names_plain .. ".gz" +local names_bin = pathdata.index.luc local help_messages = { ["luaotfload-tool"] = [[ @@ -248,7 +250,7 @@ Enter 'luaotfload-tool --help' for a larger list of options. local help_msg = function (version) local template = help_messages[version] iowrite(stringformat(template, - luaotfloadconfig.self, + luaotfload.self, -- names_plain, names_gzip, names_bin, @@ -265,8 +267,8 @@ local about = [[ local version_msg = function ( ) local out = function (...) texiowrite_nl (stringformat (...)) end - out (about, luaotfloadconfig.self) - out ("%s version %q", luaotfloadconfig.self, version) + out (about, luaotfload.self) + out ("%s version %q", luaotfload.self, version) out ("revision %q", luaotfloadstatus.notes.revision) out ("database version %q", names.version) out ("Lua interpreter: %s; version %q", runtime[1], runtime[2]) @@ -681,9 +683,9 @@ local show_font_info = function (basename, askedname, detail, warnings) if nfonts > 0 then -- true type collection local subfont if askedname then - logs.names_report(true, 1, "resolve", - [[%s is part of the font collection %s]], - askedname, basename) + report (true, 1, "resolve", + [[%s is part of the font collection %s]], + askedname, basename) subfont = subfont_by_name(shortinfo, askedname) end if subfont then @@ -692,11 +694,11 @@ local show_font_info = function (basename, askedname, detail, warnings) show_full_info(fullname, subfont, warnings) end else -- list all subfonts - logs.names_report(true, 1, "resolve", - [[%s is a font collection]], basename) + report (true, 1, "resolve", + [[%s is a font collection]], basename) for subfont = 1, nfonts do - logs.names_report(true, 1, "resolve", - [[Showing info for font no. %d]], n) + report (true, 1, "resolve", + [[Showing info for font no. %d]], n) show_info_items(shortinfo[subfont]) if detail == true then show_full_info(fullname, subfont, warnings) @@ -710,8 +712,7 @@ local show_font_info = function (basename, askedname, detail, warnings) end end else - logs.names_report(true, 1, "resolve", - "Font %s not found", filename) + report (true, 1, "resolve", "Font %s not found", filename) end end @@ -735,10 +736,9 @@ action_pending.generate = false --- this is the default action local actions = { } --- (jobspec -> (bool * bool)) list actions.loglevel = function (job) - logs.set_loglevel(job.log_level) - logs.names_report("info", 3, "util", - "Setting log level", "%d", job.log_level) - logs.names_report("log", 2, "util", "Lua=%s", _VERSION) + log.set_loglevel(job.log_level) + report ("info", 3, "util", "Setting log level", "%d", job.log_level) + report ("log", 2, "util", "Lua=%q", _VERSION) return true, true end @@ -764,8 +764,7 @@ end actions.generate = function (job) local fontnames, savedname fontnames = names.update(fontnames, job.force_reload, job.dry_run) - logs.names_report("info", 2, "db", - "Fonts in the database: %i", #fontnames.mappings) + report ("info", 2, "db", "Fonts in the database: %i", #fontnames.mappings) if names.data() then return true, true end @@ -777,7 +776,7 @@ actions.flush = function (job) if success then local success = names.save_lookups() if success then - logs.names_report("info", 2, "cache", "Lookup cache emptied") + report ("info", 2, "cache", "Lookup cache emptied") return true, true end end @@ -793,8 +792,8 @@ local cache_directives = { actions.cache = function (job) local directive = cache_directives[job.cache] if not directive or type(directive) ~= "function" then - logs.names_report("info", 2, "cache", - "Invalid font cache directive %s.", job.cache) + report ("info", 2, "cache", + "Invalid font cache directive %s.", job.cache) return false, false end if directive() then @@ -838,28 +837,27 @@ actions.query = function (job) end if success then - logs.names_report(false, 0, - "resolve", "Font %q found!", query) + report (false, 0, "resolve", "Font %q found!", query) if subfont then - logs.names_report(false, 0, "resolve", - "Resolved file name %q, subfont nr. %q", + report (false, 0, "resolve", + "Resolved file name %q, subfont nr. %q", foundname, subfont) else - logs.names_report(false, 0, "resolve", - "Resolved file name %q", foundname) + report (false, 0, "resolve", + "Resolved file name %q", foundname) end if job.show_info then show_font_info (foundname, query, job.full_info, job.warnings) iowrite "\n" end else - logs.names_report(false, 0, - "resolve", "Cannot find %q in index.", query) - logs.names_report(false, 0, - "resolve", "Hint: use the --fuzzy option to display suggestions.", query) + report (false, 0, "resolve", "Cannot find %q in index.", query) + report (false, 0, "resolve", + "Hint: use the --fuzzy option to display suggestions.", + query) if job.fuzzy == true then - logs.names_report(false, 0, - "resolve", "Looking for close matches, this may take a while ...") + report (false, 0, "resolve", + "Looking for close matches, this may take a while ...") local _success = names.find_closest(query, job.fuzzy_limit) end end @@ -957,7 +955,7 @@ actions.list = function (job) local nmappings = #mappings if criterion == "*" then - logs.names_report(false, 1, "list", "All %d entries", nmappings) + report (false, 1, "list", "All %d entries", nmappings) for i=1, nmappings do local entry = mappings[i] local fields = get_fields(entry, asked_fields) @@ -972,12 +970,12 @@ actions.list = function (job) criterion = criterion[1] asked_fields = set_primary_field(asked_fields, criterion) - logs.names_report(false, 1, "list", "By %s", criterion) + report (false, 1, "list", "By %s", criterion) --- firstly, build a list of fonts to operate on local targets = { } if asked_value then --- only those whose value matches - logs.names_report(false, 2, "list", "Restricting to value %s", asked_value) + report (false, 2, "list", "Restricting to value %s", asked_value) for i=1, nmappings do local entry = mappings[i] if entry[criterion] @@ -1022,7 +1020,7 @@ actions.list = function (job) end end local ntargets = #targets - logs.names_report(false, 2, "list", "%d entries", ntargets) + report (false, 2, "list", "%d entries", ntargets) --- now, output the collection for i=1, ntargets do @@ -1150,7 +1148,7 @@ local process_cmdline = function ( ) -- unit -> jobspec elseif v == "log" then local str = optarg[n] if str then - finalizers = logs.set_logout(str, finalizers) + finalizers = log.set_logout(str, finalizers) end elseif v == "find" then action_pending["query"] = true @@ -1230,24 +1228,23 @@ local main = function ( ) -- unit -> int local actionname = action_sequence[i] local exit = false if action_pending[actionname] then - logs.names_report("log", 3, "util", "Preparing for task", - "%s", actionname) + report ("log", 3, "util", "Preparing for task", "%s", actionname) local action = actions[actionname] local success, continue = action(job) if not success then - logs.names_report(false, 0, "util", - "Could not finish task", "%s", actionname) + report (false, 0, "util", + "Could not finish task", "%s", actionname) retval = -1 exit = true elseif not continue then - logs.names_report(false, 3, "util", - "Task completed, exiting", "%s", actionname) - exit = true + report (false, 3, "util", + "Task completed, exiting", "%s", actionname) + exit = true else - logs.names_report(false, 3, "util", - "Task completed successfully", "%s", actionname) + report (false, 3, "util", + "Task completed successfully", "%s", actionname) end end if exit then break end |