diff options
Diffstat (limited to 'src/luaotfload-configuration.lua')
-rw-r--r-- | src/luaotfload-configuration.lua | 136 |
1 files changed, 130 insertions, 6 deletions
diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index dfa222c..10e791a 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -5,7 +5,7 @@ -- REQUIREMENTS: Luaotfload 2.5 or above -- AUTHOR: Philipp Gesang (Phg), <phg42.2a@gmail.com> -- VERSION: same as Luaotfload --- MODIFIED: 2014-07-13 14:19:32+0200 +-- MODIFIED: 2014-07-24 21:49:31+0200 ------------------------------------------------------------------------------- -- @@ -24,16 +24,17 @@ config.luaotfload = { } local status_file = "luaotfload-status" local luaotfloadstatus = require (status_file) -local string = string -local stringsub = string.sub local stringexplode = string.explode -local stringstrip = string.strip local stringfind = string.find +local stringformat = string.format +local string = string +local stringstrip = string.strip +local stringsub = string.sub -local table = table local tableappend = table.append -local tablecopy = table.copy local tableconcat = table.concat +local tablecopy = table.copy +local table = table local tabletohash = table.tohash local math = math @@ -42,8 +43,10 @@ local mathfloor = math.floor local io = io local ioloaddata = io.loaddata local iopopen = io.popen +local iowrite = io.write local os = os +local osdate = os.date local osgetenv = os.getenv local lpeg = require "lpeg" @@ -475,6 +478,92 @@ local option_spec = { } ------------------------------------------------------------------------------- +--- FORMATTERS +------------------------------------------------------------------------------- + +local indent = " " +local format_string = function (var, val) + return stringformat (indent .. "%s = %s", var, val) +end + +local format_integer = function (var, val) + return stringformat (indent .. "%s = %d", var, val) +end + +local format_boolean = function (var, val) + return stringformat (indent .. "%s = %s", var, val == true and "true" or "false") +end + +local format_section = function (title) + return stringformat ("[%s]", title) +end + +local commented = function (str) + return ";" .. str +end + +local underscore_replacer = lpeg.replacer ("_", "-", true) + +local dashed = function (var) + --- INI spec dictates that dashes are valid in variable names, not + --- underscores. + return underscore_replacer (var) or var +end + +local conf_header = [==[ +;;----------------------------------------------------------------------------- +;; Luaotfload Configuration +;;----------------------------------------------------------------------------- +;; +;; This file was generated by luaotfload-tool +;; on %s. Configuration variables +;; are documented in the manual to luaotfload.conf(5). +;; +;;----------------------------------------------------------------------------- + +]==] + +local conf_footer = [==[ + +;; vim:filetype=dosini:expandtab:shiftwidth=2 +]==] + +--- Each dumpable variable (the ones mentioned in the man page) receives a +--- formatter that will be used in dumping the variable. Each value receives a +--- “commented” flag that indicates whether or not the line should be printed +--- as a comment. + +local formatters = { + db = { + compress = { false, format_boolean }, + formats = { false, format_string }, + max_fonts = { false, format_integer }, + scan_local = { false, format_boolean }, + skip_read = { false, format_boolean }, + strip = { false, format_boolean }, + update_live = { false, format_boolean }, + }, + misc = { + bisect = { false, format_boolean }, + statistics = { false, format_boolean }, + termwidth = { true , format_integer }, + version = { true , format_string }, + }, + paths = { + cache_dir = { false, format_string }, + names_dir = { false, format_string }, + index_file = { false, format_string }, + lookups_file = { false, format_string }, + }, + run = { + color_callback = { false, format_string }, + definer = { false, format_string }, + log_level = { false, format_integer }, + resolver = { false, format_string }, + }, +} + +------------------------------------------------------------------------------- --- MAIN FUNCTIONALITY ------------------------------------------------------------------------------- @@ -689,6 +778,40 @@ local apply_defaults = function () return reconfigure () end +local dump = function () + local sections = table.sortedkeys (config.luaotfload) + local confdata = { } + for i = 1, #sections do + local section = sections[i] + local vars = config.luaotfload[section] + local varnames = table.sortedkeys (vars) + local sformats = formatters[section] + if sformats then + confdata[#confdata + 1] = format_section (section) + for j = 1, #varnames do + local var = varnames[j] + local val = vars[var] + local comment, sformat = unpack (sformats[var] or { }) + if sformat then + local dashedvar = dashed (var) + if comment then + confdata[#confdata + 1] = commented (sformat (dashedvar, val)) + else + confdata[#confdata + 1] = sformat (dashedvar, val) + end + end + end + confdata[#confdata + 1] = "" + end + end + if next(confdata) then + iowrite (stringformat (conf_header, + osdate ("%Y-%m-d %H:%M:%S", os.time ()))) + iowrite (tableconcat (confdata, "\n")) + iowrite (conf_footer) + end +end + ------------------------------------------------------------------------------- --- EXPORTS ------------------------------------------------------------------------------- @@ -700,5 +823,6 @@ config.actions = { apply = apply, apply_defaults = apply_defaults, reconfigure = reconfigure, + dump = dump, } |