summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2014-07-13 15:01:59 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2014-07-13 15:01:59 +0200
commitd84ce4ec794e634b853ca88925e1d20f6a1287e3 (patch)
tree57a3de8cbd900e45061820353391124bf2c41663
parente8b0693cc014c201a600aed32cec71044a72edce (diff)
downloadluaotfload-d84ce4ec794e634b853ca88925e1d20f6a1287e3.tar.gz
[features,conf] generalize feature option parsing
-rw-r--r--src/luaotfload-configuration.lua46
-rw-r--r--src/luaotfload-features.lua13
-rw-r--r--src/luaotfload-main.lua1
3 files changed, 27 insertions, 33 deletions
diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua
index 1e1e907..696bee6 100644
--- a/src/luaotfload-configuration.lua
+++ b/src/luaotfload-configuration.lua
@@ -28,6 +28,7 @@ local string = string
local stringsub = string.sub
local stringexplode = string.explode
local stringstrip = string.strip
+local stringfind = string.find
local table = table
local tableappend = table.append
@@ -349,6 +350,22 @@ local toarray = function (s)
return ret
end
+local tohash = function (s)
+ local result = { }
+ local fields = toarray (s)
+ for _, field in next, fields do
+ local var, val
+ if stringfind (field, "=") then
+ local tmp
+ var, tmp = lpegmatch (equalssplitter, field)
+ if tmp == "true" or tmp == "yes" then val = true else val = tmp end
+ else
+ var, val = field, true
+ end
+ result[var] = val
+ end
+ return result
+end
local option_spec = {
db = {
@@ -453,32 +470,7 @@ local option_spec = {
index_path_luc = { in_t = string_t, },
},
default_features = {
- global = {
- in_t = string_t,
- out_t = table_t,
- transform = function (s)
- --- Split key=value arguments into hash.
- local result = { }
- local fields = toarray (s)
- for _, field in next, fields do
- local var, val = lpegmatch (equalssplitter, field)
- if var and val then
- if val == "true" then
- result[var] = true
- else
- result[var] = val
- end
- end
- end
- return result
- end,
- },
- dflt = { in_t = string_t, out_t = table_t, transform = toarray, },
- arab = { in_t = string_t, out_t = table_t, transform = toarray, },
- deva = { in_t = string_t, out_t = table_t, transform = toarray, },
- khmr = { in_t = string_t, out_t = table_t, transform = toarray, },
- thai = { in_t = string_t, out_t = table_t, transform = toarray, },
- hang = { in_t = string_t, out_t = table_t, transform = toarray, },
+ __default = { in_t = string_t, out_t = table_t, transform = tohash, },
},
}
@@ -563,7 +555,7 @@ local process_options = function (opts)
end
for var, val in next, vars do
- local vspec = spec[var]
+ local vspec = spec[var] or spec.__default
local t_val = type (val)
if not vspec then
logreport ("both", 2, "conf",
diff --git a/src/luaotfload-features.lua b/src/luaotfload-features.lua
index 0dc7d0a..1fb6d7c 100644
--- a/src/luaotfload-features.lua
+++ b/src/luaotfload-features.lua
@@ -724,6 +724,8 @@ local support_incomplete = tabletohash({
--- (string, string) dict -> (string, string) dict
local set_default_features = function (speclist)
+ local default_features = luaotfload.features
+
speclist = speclist or { }
speclist[""] = nil --- invalid options stub
@@ -760,20 +762,19 @@ local set_default_features = function (speclist)
"Auto-selecting default features for script: %s.",
script)
- local requested = luaotfload.features.defaults[script]
+ local requested = default_features.defaults[script]
if not requested then
report("log", 1, "load",
"No default features for script %q, falling back to \"dflt\".",
script)
- requested = luaotfload.features.defaults.dflt
+ requested = default_features.defaults.dflt
end
- for i=1, #requested do
- local feat = requested[i]
- if speclist[feat] ~= false then speclist[feat] = true end
+ for feat, state in next, requested do
+ if not speclist[feat] then speclist[feat] = state end
end
- for feat, state in next, luaotfload.features.global do
+ for feat, state in next, default_features.global do
--- This is primarily intended for setting node
--- mode unless “base” is requested, as stated
--- in the manual.
diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua
index c7694ea..6616468 100644
--- a/src/luaotfload-main.lua
+++ b/src/luaotfload-main.lua
@@ -64,6 +64,7 @@ local luatexbase = luatexbase
local setmetatable = setmetatable
local type, next = type, next
local stringlower = string.lower
+local stringformat = string.format
local kpsefind_file = kpse.find_file
local lfsisfile = lfs.isfile