diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-04-22 07:15:12 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-04-22 07:15:12 +0200 |
commit | 3657b9c19c70eb0b52dfa1c67956776a6fd77d4a (patch) | |
tree | 0ba8c6d9060a1554e2538652c5054e4142c16e15 | |
parent | a84ec1cd4b7cc06fec1d2cf5e5f5e0cbd9115637 (diff) | |
download | luaotfload-3657b9c19c70eb0b52dfa1c67956776a6fd77d4a.tar.gz |
[tool,db,conf] integrate defaults into new config model
-rw-r--r-- | src/luaotfload-configuration.lua | 67 | ||||
-rw-r--r-- | src/luaotfload-database.lua | 10 | ||||
-rwxr-xr-x | src/luaotfload-tool.lua | 29 |
3 files changed, 71 insertions, 35 deletions
diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index 973810a..d05a48b 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -24,6 +24,10 @@ local string = string local stringsub = string.sub local stringexplode = string.explode +local table = table +local tableappend = table.append +local tablecopy = table.copy + local io = io local ioloaddata = io.loaddata @@ -67,6 +71,27 @@ local config_paths = { } ------------------------------------------------------------------------------- +--- DEFAULTS +------------------------------------------------------------------------------- + +local luaotfload_defaults = { + misc = { + bisect = false, + version = luaotfload.version, + }, + paths = { + names_dir = "names", + cache_dir = "fonts", + index_file = "luaotfload-names.lua", + }, + db = { + formats = "otf,ttf,ttc,dfont", + reload = false, + strip = true, + }, +} + +------------------------------------------------------------------------------- --- OPTION SPECIFICATION ------------------------------------------------------------------------------- @@ -77,15 +102,18 @@ local function_t = "function" local option_spec = { db = { - formats = { - --- e.g. "otf ttf" -> { "otf", "ttf" } - in_t = string_t, - out_t = table_t, - transform = function (str) return stringexplode (str, " +") end - }, - reload = { - in_t = boolean_t, - }, + formats = { in_t = string_t, }, + reload = { in_t = boolean_t, }, + strip = { in_t = boolean_t, }, + }, + misc = { + bisect = { in_t = boolean_t, }, + version = { in_t = string_t, }, + }, + paths = { + names_dir = { in_t = string_t, }, + cache_dir = { in_t = string_t, }, + index_file = { in_t = string_t, }, }, } @@ -145,7 +173,7 @@ local add_config_paths = function (t) local path = t[i] result[#result + 1] = { path_t, path } end - config_paths = table.append (result, config_paths) + config_paths = tableappend (result, config_paths) end local process_options = function (opts) @@ -219,6 +247,17 @@ local process_options = function (opts) return new end +local apply = function (old, new) + if not old then + return tablecopy (new) + end + local result = tablecopy (old) + for var, val in next, new do + result[var] = val + end + return result +end + local read = function (extra) if extra then add_config_paths (extra) @@ -251,5 +290,11 @@ local read = function (extra) return ret end -config.read = read +------------------------------------------------------------------------------- +--- EXPORTS +------------------------------------------------------------------------------- + +config.defaults = luaotfload_defaults +config.read = read +config.apply = apply diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 7165d07..013e6e8 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -650,7 +650,7 @@ local style_category = { i = "italic", } -local type1_formats = { "tfm", "ofm", } +local type1_metrics = { "tfm", "ofm", } local dummy_findfile = resolvers.findfile -- from basics-gen @@ -692,8 +692,8 @@ crude_file_lookup_verbose = function (filename) end --- ofm and tfm, returns pair - for i=1, #type1_formats do - local format = type1_formats[i] + for i=1, #type1_metrics do + local format = type1_metrics[i] if resolvers.findfile(filename, format) then return file.addsuffix(filename, format), format, true end @@ -748,8 +748,8 @@ crude_file_lookup = function (filename) return found, nil, true end - for i=1, #type1_formats do - local format = type1_formats[i] + for i=1, #type1_metrics do + local format = type1_metrics[i] if resolvers.findfile(filename, format) then return file.addsuffix(filename, format), format, true end diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua index 5893d42..9b06ba9 100755 --- a/src/luaotfload-tool.lua +++ b/src/luaotfload-tool.lua @@ -95,18 +95,6 @@ config = config or { } local config = config local luaotfloadconfig = config.luaotfload or { } config.luaotfload = luaotfloadconfig -luaotfloadconfig.bisect = false -luaotfloadconfig.version = luaotfloadconfig.version or version -luaotfloadconfig.names_dir = luaotfloadconfig.names_dir or "names" -luaotfloadconfig.cache_dir = luaotfloadconfig.cache_dir or "fonts" -luaotfloadconfig.index_file = luaotfloadconfig.index_file - or "luaotfload-names.lua" -luaotfloadconfig.formats = luaotfloadconfig.formats - or "otf,ttf,ttc,dfont" -luaotfloadconfig.reload = false -if not luaotfloadconfig.strip then - luaotfloadconfig.strip = true -end config.lualibs = config.lualibs or { } config.lualibs.verbose = false @@ -147,11 +135,11 @@ require"luaotfload-basics-gen.lua" texio.write, texio.write_nl = backup.write, backup.write_nl utilities = backup.utilities -require"luaotfload-log.lua" --- this populates the luaotfload.log.* namespace -require"luaotfload-parsers" --- fonts.conf, configuration, and request syntax -require"luaotfload-configuration" --- configuration file handling -require"luaotfload-database" -require"alt_getopt" +require "luaotfload-log.lua" --- this populates the luaotfload.log.* namespace +require "luaotfload-parsers" --- fonts.conf, configuration, and request syntax +require "luaotfload-configuration" --- configuration file handling +require "luaotfload-database" +require "alt_getopt" local names = fonts.names local status_file = "luaotfload-status" @@ -757,10 +745,13 @@ actions.loglevel = function (job) end actions.config = function (job) - local config = luaotfload.config.read (job.extra_config) + local defaults = luaotfload.config.defaults + local vars = luaotfload.config.read (job.extra_config) + config.luaotfload = luaotfload.config.apply (defaults, vars) --if job.print_config == true then if true then - -- inspect (config) + --inspect (vars) + inspect (config.luaotfload) return true, false end return true, true |