summaryrefslogtreecommitdiff
path: root/src/luaotfload-tool.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/luaotfload-tool.lua')
-rwxr-xr-xsrc/luaotfload-tool.lua87
1 files changed, 78 insertions, 9 deletions
diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua
index 03e7db3..5c7cb1d 100755
--- a/src/luaotfload-tool.lua
+++ b/src/luaotfload-tool.lua
@@ -48,6 +48,7 @@ kpse.set_program_name "luatex"
local ioopen = io.open
local iowrite = io.write
local kpsefind_file = kpse.find_file
+local mathfloor = math.floor
local next = next
local osdate = os.date
local ostype = os.type
@@ -113,8 +114,11 @@ config.lualibs.prefer_merged = true
config.lualibs.load_extended = true
require "lualibs"
-local tabletohash = table.tohash
+local iosavedata = io.savedata
+local lfsisfile = lfs.isfile
local stringsplit = string.split
+local tableserialize = table.serialize
+local tabletohash = table.tohash
--[[doc--
\fileent{luatex-basics-gen.lua} calls functions from the
@@ -256,7 +260,7 @@ local help_msg = function (version)
names_gzip,
names_bin,
caches.getwritablepath (
- luaotfloadconfig.cache_dir)))
+ luaotfloadconfig.cache_dir)))
end
local about = [[
@@ -288,7 +292,7 @@ local head_adornchars = {
}
local textwidth = 80
-local wd_leftcolumn = math.floor(textwidth * .25)
+local wd_leftcolumn = mathfloor(textwidth * .25)
local key_fmt = stringformat([[%%%ds]], wd_leftcolumn)
local val_fmt = [[%s]]
local fieldseparator = ":"
@@ -771,13 +775,56 @@ actions.generate = function (job)
return false, false
end
+-------------------------------------------------------------------------------
+--- bisect mode
+-------------------------------------------------------------------------------
+
+local bisect_status_path = caches.getwritablepath "bisect"
+local bisect_status_file = bisect_status_path .."/" .. "luaotfload-bisect-status.lua"
+local bisect_status_fmt = [[
+--[==[-------------------------------------------------------------------------
+ This file is generated by Luaotfload. It can be safely deleted.
+ Creation date: %s.
+-------------------------------------------------------------------------]==]--
+
+%s
+
+--- vim:ft=lua:ts=8:et:sw=2
+]]
+
+local write_bisect_status = function (data)
+ local payload = tableserialize (data, true)
+ local status = stringformat (bisect_status_fmt,
+ osdate ("%Y-%m-d %H:%M:%S", os.time ()),
+ payload)
+ if status and iosavedata (bisect_status_file, status) then
+ report ("info", 4, "bisect",
+ "Bisection state written to %s.", bisect_status_file)
+ return true
+ end
+ report ("info", 0, "bisect",
+ "Failed to write bisection state to %s.", bisect_status_file)
+ return false
+end
+
--[[doc--
bisect_start -- Begin a bisect session. Determines the number of
fonts and sets the initial high, low, and pivot values.
+
--doc]]--
local bisect_start = function ()
+ report ("info", 2, "bisect",
+ "Starting bisection of font database %q.", bisect_status_file)
+ local n = names.count_font_files ()
+ local pivot = mathfloor (n / 2)
+ local data = { { 1, n, pivot } }
+ report ("info", 0, "bisect", "Initializing pivot to %d.", pivot)
+ if write_bisect_status (data) then
+ return true
+ end
+ return false
end
--[[doc--
@@ -806,6 +853,25 @@ end
--doc]]--
local bisect_status = function ()
+ report ("info", 4, "bisect", "Testing for status file: %q.", bisect_status_file)
+ if not lfsisfile (bisect_status_file) then
+ report ("info", 2, "bisect", "No such file: %q.", bisect_status_file)
+ report ("info", 0, "bisect", "Not in bisect mode.")
+ return true
+ end
+ report ("info", 4, "bisect", "Reading status file: %q.", bisect_status_file)
+ local status = pcall (dofile, bisect_status_file)
+ if not status then
+ report ("info", 0, "bisect", "Could not read status file.")
+ return false
+ end
+ report ("info", 0, "bisect", "Bisecting through %d font files.", #status)
+ for i = #status, 1, -1 do
+ local step = status[i]
+ report ("info", 0, "bisect", "Step %d: lo=%d, hi=%d, pivot=%d.",
+ i, unpack (step))
+ end
+ return true
end
local bisect_modes = {
@@ -820,10 +886,13 @@ actions.bisect = function (job)
local mode = job.bisect
local runner = bisect_modes[mode]
if not runner then
- report ("info", 0, "cache", "Unknown bisect directive %q.", mode)
+ report ("info", 0, "bisect", "Unknown directive %q.", mode)
return false, false
end
- return true, false
+ if runner (job) then
+ return true, false
+ end
+ return false, false
end
actions.flush = function (job)
@@ -1270,7 +1339,7 @@ local process_cmdline = function ( ) -- unit -> jobspec
end
elseif v == "bisect" then
result.bisect = optarg[n]
- actions_pending.bisect = true
+ action_pending.bisect = true
end
end
@@ -1299,16 +1368,16 @@ local main = function ( ) -- unit -> int
if not success then
report (false, 0, "util",
- "Could not finish task", "%s", actionname)
+ "Failed to execute task.", "%s", actionname)
retval = -1
exit = true
elseif not continue then
report (false, 3, "util",
- "Task completed, exiting", "%s", actionname)
+ "Task completed, exiting.", "%s", actionname)
exit = true
else
report (false, 3, "util",
- "Task completed successfully", "%s", actionname)
+ "Task completed successfully.", "%s", actionname)
end
end
if exit then break end