summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/luatexja/src/ltj-base.lua
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/generic/luatexja/src/ltj-base.lua')
-rw-r--r--macros/luatex/generic/luatexja/src/ltj-base.lua98
1 files changed, 50 insertions, 48 deletions
diff --git a/macros/luatex/generic/luatexja/src/ltj-base.lua b/macros/luatex/generic/luatexja/src/ltj-base.lua
index 3f4a0ba1f8..ad5bb816a5 100644
--- a/macros/luatex/generic/luatexja/src/ltj-base.lua
+++ b/macros/luatex/generic/luatexja/src/ltj-base.lua
@@ -30,25 +30,22 @@ do
--! LaTeX 形式のエラーメッセージ(\PackageError 等)を
--! Lua 関数の呼び出しで行う.
- local LF = "\n"
- local err_break = ""
+ local LF, BEL = "\n", "\a"
local err_main = ""
local err_help = ""
local function message_cont(str, c)
- return str:gsub(err_break, LF .. c)
+ return str:gsub(LF, LF .. c)
end
local function into_lines(str)
- return str:gsub(err_break, LF):explode(LF)
- end
-
- _error_set_break = function (str)
- err_break = str
+ return str:explode(LF)
end
_error_set_message = function (msgcont, main, help)
- err_main = message_cont(main, msgcont)
- err_help = into_lines(help)
+ err_main = message_cont(main, msgcont):gsub(BEL, LF)
+ err_help = (help and help~="") and into_lines(help)
+ or {"Sorry, I don't know how to help in this situation.",
+ "Maybe you should try asking a human?" }
end
_error_show = function (escchar)
@@ -67,7 +64,7 @@ do
local message_a = "Type H <return> for immediate help"
generic_error = function (msgcont, main, ref, help)
- local mainref = main..".\n\n"..ref.."\n"..message_a
+ local mainref = main..".\a\a"..ref..BEL..message_a
_error_set_message(msgcont, mainref, help)
_error_show(true)
end
@@ -79,7 +76,7 @@ do
local on_line = line and (" on input line "..tex.inputlineno) or ""
local newlinechar = tex.newlinechar
tex.newlinechar = -1
- texio.write_nl(out, br..main..on_line.."."..br)
+ texio.write_nl(out, br..mainc..on_line.."."..br)
tex.newlinechar = newlinechar
end
@@ -97,25 +94,25 @@ do
end
package_error = function (pkgname, main, help)
- generic_error("("..pkgname.." ",
+ generic_error("("..pkgname..") ",
"Package "..pkgname.." Error: "..main,
"See the "..pkgname.." package documentation for explanation.",
help)
end
package_warning = function (pkgname, main)
- generic_warning("("..pkgname.." ",
+ generic_warning("("..pkgname..") ",
"Package "..pkgname.." Warning: "..main)
end
package_warning_no_line = function (pkgname, main)
- generic_warning_no_line("("..pkgname.." ",
+ generic_warning_no_line("("..pkgname..") ",
"Package "..pkgname.." Warning: "..main)
end
package_info = function (pkgname, main)
- generic_info("("..pkgname.." ",
+ generic_info("("..pkgname..") ",
"Package "..pkgname.." Info: "..main)
end
package_info_no_line = function (pkgname, main)
- generic_info_no_line("("..pkgname.." ",
+ generic_info_no_line("("..pkgname..") ",
"Package "..pkgname.." Info: "..main)
end
@@ -231,6 +228,7 @@ end
require('lualibs-lpeg') -- string.split
require('lualibs-os') -- os.type
+require('lualibs-gzip') -- gzip.*
do
local kpse_var_value = kpse.var_value
@@ -248,6 +246,7 @@ do
local join, isreadable = file.join, file.isreadable
local tofile, serialize = table.tofile, table.serialize
local luc_suffix = jit and '.lub' or '.luc'
+ local dump = string.dump
-- determine save path
local savepath = ''
@@ -256,43 +255,56 @@ do
if not lfs.isdir(testpath) then dir.mkdirs(testpath) end
if lfs.isdir(testpath) then savepath = testpath; break end
end
+ local serial_spec = {functions=false, noquotes=true}
+
+ local function remove_file_if_exist(name)
+ if os.rename(name,name) then os.remove(name) end
+ end
+ local function remove_cache (filename)
+ local fullpath_wo_ext = savepath .. '/' .. filename .. '.lu'
+ remove_file_if_exist(fullpath_wo_ext .. 'a')
+ remove_file_if_exist(fullpath_wo_ext .. 'a.gz')
+ remove_file_if_exist(fullpath_wo_ext .. 'b')
+ remove_file_if_exist(fullpath_wo_ext .. 'c')
+ end
local function save_cache_luc(filename, t, serialized)
local fullpath = savepath .. '/' .. filename .. luc_suffix
- local s = serialized or serialize(t, 'return', false)
+ local s = serialized or serialize(t, 'return', false, serial_spec)
if s then
local sa = load(s)
local f = io.open(fullpath, 'wb')
if f and sa then
- f:write(string.dump(sa, true))
- texio.write('(save cache: ' .. fullpath .. ')')
+ f:write(dump(sa, true))
+ texio.write('log', '(save cache: ' .. fullpath .. ')')
+ f:close()
end
- f:close()
end
end
local function save_cache(filename, t)
- local fullpath = savepath .. '/' .. filename .. '.lua'
- local s = serialize(t, 'return', false)
+ local fullpath = savepath .. '/' .. filename .. '.lua.gz'
+ local s = serialize(t, 'return', false, serial_spec)
if s then
- local f = io.open(fullpath, 'w')
- if f then
- f:write(s)
- texio.write('(save cache: ' .. fullpath .. ')')
- end
- f:close()
- save_cache_luc(filename, t, s)
+ gzip.save(fullpath, s, 1)
+ texio.write('log', '(save cache: ' .. fullpath .. ')')
+ save_cache_luc(filename, t, s)
end
end
- local function load_cache_a(filename, outdate)
+ local function load_cache_a(filename, outdate, compressed)
local result
for _,v in pairs(path) do
local fn = join(v, cache_dir, filename)
- if isreadable(fn) then
- texio.write('(load cache: ' .. fn .. ')')
- result = loadfile(fn)
- result = result and result(); break
+ if isreadable(fn) then
+ texio.write('log','(load cache: ' .. filename .. ')')
+ if compressed then
+ result = loadstring(gzip.load(fn))
+ else
+ result = loadfile(fn)
+ end
+ result = result and result()
+ break
end
end
if (not result) or outdate(result) then
@@ -303,26 +315,17 @@ do
end
local function load_cache(filename, outdate)
- local r = load_cache_a(filename .. luc_suffix, outdate)
+ remove_file_if_exist(savepath .. '/' .. filename .. '.lua')
+ local r = load_cache_a(filename .. luc_suffix, outdate, false)
if r then
return r
else
- local r = load_cache_a(filename .. '.lua', outdate)
+ local r = load_cache_a(filename .. '.lua.gz', outdate, true)
if r then save_cache_luc(filename, r) end -- update the precompiled cache
return r
end
end
- local function remove_file_if_exist(name)
- if os.rename(name,name) then os.remove(name) end
- end
- local function remove_cache (filename)
- local fullpath_wo_ext = savepath .. '/' .. filename .. '.lu'
- remove_file_if_exist(fullpath_wo_ext .. 'a')
- remove_file_if_exist(fullpath_wo_ext .. 'b')
- remove_file_if_exist(fullpath_wo_ext .. 'c')
- end
-
ltjb.remove_cache = remove_cache
ltjb.load_cache = load_cache
ltjb.save_cache_luc = save_cache_luc
@@ -340,7 +343,6 @@ do
end
----
-ltjb._error_set_break = _error_set_break
ltjb._error_set_message = _error_set_message
ltjb._error_show = _error_show
ltjb._generic_warn_info = _generic_warn_info