Let it work again

This commit is contained in:
Marcel Krüger 2020-05-26 19:29:58 +02:00
parent e3551937fa
commit 63de6d8141
3 changed files with 48 additions and 337 deletions

View File

@ -153,6 +153,7 @@ token.luacmd("write", function(_, immediate) -- \write
node.direct.write(whatsit) node.direct.write(whatsit)
end end
end, "protected") end, "protected")
local lua_call_cmd = token.command_id'lua_call' local lua_call_cmd = token.command_id'lua_call'
token.luacmd("immediate", function() -- \immediate token.luacmd("immediate", function() -- \immediate
local next_tok = token.scan_token() local next_tok = token.scan_token()
@ -166,17 +167,17 @@ end, "protected")
-- local name = token.scan_string() -- local name = token.scan_string()
-- print('Missing \\pdf' .. name) -- print('Missing \\pdf' .. name)
-- end -- end
if status.ini_version then
function fixupluafunctions()
tex.setcount("global", "e@alloc@luafunction@count", predefined_luafunctions)
end
else
local prepared_code = lua.bytecode[1] local prepared_code = lua.bytecode[1]
if prepared_code then
prepared_code() prepared_code()
prepared_code, lua.bytecode[1] = nil, nil lua.bytecode[1] = nil
function fixupluafunctions() function fixupluafunctions()
new_luafunction = luatexbase.new_luafunction new_luafunction = luatexbase.new_luafunction
fixupluafunctions = nil fixupluafunctions = nil
end end
else
function fixupluafunctions()
tex.setcount("global", "e@alloc@luafunction@count", predefined_luafunctions)
end
end end
require'luametalatex-back-pdf' require'luametalatex-back-pdf'

View File

@ -1,328 +1,20 @@
do do
ffi.cdef[[ local ourpath = arg[0]:match('^%-%-lua=(.*)luametalatex%-init%.lua$')
typedef enum kpse = assert(package.loadlib(ourpath .. 'kpse.so', 'luaopen_kpse'))()
{
kpse_gf_format,
kpse_pk_format,
kpse_any_glyph_format,
kpse_tfm_format,
kpse_afm_format,
kpse_base_format,
kpse_bib_format,
kpse_bst_format,
kpse_cnf_format,
kpse_db_format,
kpse_fmt_format,
kpse_fontmap_format,
kpse_mem_format,
kpse_mf_format,
kpse_mfpool_format,
kpse_mft_format,
kpse_mp_format,
kpse_mppool_format,
kpse_mpsupport_format,
kpse_ocp_format,
kpse_ofm_format,
kpse_opl_format,
kpse_otp_format,
kpse_ovf_format,
kpse_ovp_format,
kpse_pict_format,
kpse_tex_format,
kpse_texdoc_format,
kpse_texpool_format,
kpse_texsource_format,
kpse_tex_ps_header_format,
kpse_troff_font_format,
kpse_type1_format,
kpse_vf_format,
kpse_dvips_config_format,
kpse_ist_format,
kpse_truetype_format,
kpse_type42_format,
kpse_web2c_format,
kpse_program_text_format,
kpse_program_binary_format,
kpse_miscfonts_format,
kpse_web_format,
kpse_cweb_format,
kpse_enc_format,
kpse_cmap_format,
kpse_sfd_format,
kpse_opentype_format,
kpse_pdftex_config_format,
kpse_lig_format,
kpse_texmfscripts_format,
kpse_lua_format,
kpse_fea_format,
kpse_cid_format,
kpse_mlbib_format,
kpse_mlbst_format,
kpse_clua_format,
kpse_ris_format,
kpse_bltxml_format,
kpse_last_format /* one past last index */
} kpse_file_format_type;
typedef enum {
kpse_glyph_source_normal,
kpse_glyph_source_alias,
kpse_glyph_source_maketex,
kpse_glyph_source_fallback_res,
kpse_glyph_source_fallback
} kpse_glyph_source_type;
typedef enum {
kpse_src_implicit,
kpse_src_compile,
kpse_src_texmf_cnf,
kpse_src_client_cnf,
kpse_src_env,
kpse_src_x,
kpse_src_cmdline
} kpse_src_type;
typedef struct {
const char *name;
unsigned dpi;
kpse_file_format_type format;
kpse_glyph_source_type source;
} kpse_glyph_file_type;
void *kpathsea_new(void);
void kpathsea_set_program_name(void*, const char*, const char*);
void kpathsea_init_prog(void*, const char*, unsigned, const char *, const char *);
const char *kpathsea_find_file(void*, const char *, kpse_file_format_type, int);
const char *kpathsea_find_glyph(void*, const char *, unsigned, kpse_file_format_type, kpse_glyph_file_type*);
const char *kpathsea_brace_expand(void*, const char *);
const char *kpathsea_path_expand(void*, const char *);
const char *kpathsea_var_expand(void*, const char *);
const char *kpathsea_var_value(void*, const char *);
void kpathsea_set_program_enabled (void *, kpse_file_format_type, int, kpse_src_type);
int kpathsea_in_name_ok(void*, const char *);
int kpathsea_out_name_ok(void*, const char *);
void kpathsea_finish(void*);
const char *kpathsea_version_string;
]]
local kpse_glyph_file_type = ffi.typeof'kpse_glyph_file_type'
local type_remap = {
-- These are the command line/LuaTeX names
gf = "kpse_gf_format",
pk = "kpse_pk_format",
["bitmap font"] = "kpse_any_glyph_format",
tfm = "kpse_tfm_format",
afm = "kpse_afm_format",
base = "kpse_base_format",
bib = "kpse_bib_format",
bst = "kpse_bst_format",
cnf = "kpse_cnf_format",
["ls-R"] = "kpse_db_format",
fmt = "kpse_fmt_format",
map = "kpse_fontmap_format",
mem = "kpse_mem_format",
mf = "kpse_mf_format",
mfpool = "kpse_mfpool_format",
mft = "kpse_mft_format",
mp = "kpse_mp_format",
mppool = "kpse_mppool_format",
["MetaPost support"] = "kpse_mpsupport_format",
ocp = "kpse_ocp_format",
ofm = "kpse_ofm_format",
opl = "kpse_opl_format",
otp = "kpse_otp_format",
ovf = "kpse_ovf_format",
ovp = "kpse_ovp_format",
["graphic/figure"] = "kpse_pict_format",
tex = "kpse_tex_format",
["TeX system documentation"] = "kpse_texdoc_format",
texpool = "kpse_texpool_format",
["TeX system sources"] = "kpse_texsource_format",
["PostScript header"] = "kpse_tex_ps_header_format",
["Troff fonts"] = "kpse_troff_font_format",
["type1 fonts"] = "kpse_type1_format",
vf = "kpse_vf_format",
["dvips config"] = "kpse_dvips_config_format",
ist = "kpse_ist_format",
["truetype fonts"] = "kpse_truetype_format",
["type42 fonts"] = "kpse_type42_format",
["web2c files"] = "kpse_web2c_format",
["other text files"] = "kpse_program_text_format",
["other binary files"] = "kpse_program_binary_format",
["mics fonts"] = "kpse_miscfonts_format",
web = "kpse_web_format",
cweb = "kpse_cweb_format",
["enc files"] = "kpse_enc_format",
["cmap files"] = "kpse_cmap_format",
["subfont definition files"] = "kpse_sfd_format",
["opentype fonts"] = "kpse_opentype_format",
["pdftex config"] = "kpse_pdftex_config_format",
["lig files"] = "kpse_lig_format",
texmfscripts = "kpse_texmfscripts_format",
lua = "kpse_lua_format",
["font feature files"] = "kpse_fea_format",
["cid maps"] = "kpse_cid_format",
mlbib = "kpse_mlbib_format",
mlbst = "kpse_mlbst_format",
clua = "kpse_clua_format",
ris = "kpse_ris_format",
bltxml = "kpse_bltxml_format",
-- Some additional aliases to make naming more consistant
any_glyph = "kpse_any_glyph_format",
db = "kpse_db_format",
fontmap = "kpse_fontmap_format",
mpsupport = "kpse_mpsupport_format",
pict = "kpse_pict_format",
texdoc = "kpse_texdoc_format",
texsource = "kpse_texsource_format",
tex_ps_header = "kpse_tex_ps_header_format",
troff_font = "kpse_troff_font_format",
type1 = "kpse_type1_format",
dvips_config = "kpse_dvips_config_format",
truetype = "kpse_truetype_format",
type42 = "kpse_type42_format",
web2c = "kpse_web2c_format",
program_text = "kpse_program_text_format",
program_binary = "kpse_program_binary_format",
miscfonts = "kpse_miscfonts_format",
enc = "kpse_enc_format",
cmap = "kpse_cmap_format",
sfd = "kpse_sfd_format",
opentype = "kpse_opentype_format",
pdftex_config = "kpse_pdftex_config_format",
lig = "kpse_lig_format",
fea = "kpse_fea_format",
cid = "kpse_cid_format",
-- And some other aliases
eps = "kpse_pict_format",
pfb = "kpse_type1_format",
ttc = "kpse_truetype_format",
ttf = "kpse_truetype_format",
otf = "kpse_opentype_format",
text = "kpse_program_text_format",
binary = "kpse_program_binary_format",
}
local kpselib = ffi.load("kpathsea")
local realarg0
if arg[1]:sub(1,7) == "--arg0=" then
realarg0 = arg[1]:sub(8)
else
local i = 0
while arg[i] do
realarg0 = arg[i]
i = i-1
end end
end
local file_format = ffi.typeof'kpse_file_format_type'
local NULL = ffi.new("const char*", nil)
local function get_string(s) return s ~= NULL and ffi.string(s) end
local function set_program_name (t, arg0, progname)
kpselib.kpathsea_set_program_name(t.cdata, arg0 or realarg0, progname)
return t
end
local methods = {
init_prog = function(t, prefix, dpi, mode, fallback)
kpselib.kpathsea_init_prog(t.cdata, prefix, dpi, mode, fallback)
end,
find_file = function(t, name, ...)
local ftype, must_exist = "kpse_tex_format", 0
for i=select('#', ...),1,-1 do
local arg = select(i, ...)
local argtype = type(arg)
if argtype == "string" then
ftype = arg
elseif argtype == "number" then
must_exist = arg
elseif argtype == "boolean" then
must_exist = arg and 1 or 0
end
end
ftype = type_remap[ftype] or ftype
if ftype == "kpse_gf_format" or ftype == "kpse_pk_format"
or ftype == "kpse_any_glyph_format" then
local glyph_file = kpse_glyph_file_type()
local res = kpselib.kpathsea_find_glyph(t.cdata, name, must_exist, ftype, glyph_file)
if res ~= NULL then
return ffi.string(res), ffi.string(glyph_file.name), glyph_file.dpi, glyph_file.format, glyph_file.source
end
else
return get_string(kpselib.kpathsea_find_file(t.cdata, name, ftype, must_exist > 0 and 1 or 0))
end
end,
-- show_path = function(t, ftype)
-- error [[Not yet implemented]]
-- end,
expand_braces = function(t, path)
return get_string(kpselib.kpathsea_brace_expand(t.cdata, path))
end,
expand_path = function(t, path)
return get_string(kpselib.kpathsea_path_expand(t.cdata, path))
end,
expand_var = function(t, var)
return get_string(kpselib.kpathsea_var_expand(t.cdata, var))
end,
var_value = function(t, var)
return get_string(kpselib.kpathsea_var_value(t.cdata, var))
end,
set_maketex = function(t, ftype, value, src)
ftype = type_remap[ftype] or ftype
kpselib.kpathsea_set_program_enabled(t.cdata, ftype, value and 1 or 0, src or "kpse_src_cmdline")
end,
finish = function(t)
if t.cdata then
kpselib.kpathsea_finish(t.cdata)
end
end,
}
local meta = {
__index = methods,
__gc = methods.finish,
}
local global_kpse = setmetatable({cdata = kpselib.kpathsea_new()}, meta)
kpse = {
set_program_name = function(...)
set_program_name(global_kpse, ...)
end,
set_maketex = function(...)
return global_kpse:set_maketex(...)
end,
init_prog = function(...)
return global_kpse:init_prog(...)
end,
new = function(...)
return set_program_name(setmetatable({cdata = kpselib.kpathsea_new()}, meta), ...)
end,
expand_braces = function(...)
return global_kpse:expand_braces(...)
end,
expand_path = function(...)
return global_kpse:expand_path(...)
end,
expand_var = function(...)
return global_kpse:expand_var(...)
end,
var_value = function(...)
return global_kpse:var_value(...)
end,
find_file = function(...)
return global_kpse:find_file(...)
end,
version = function()
return ffi.string(kpselib.kpathsea_version_string)
end,
}
end
--
-- unicode = {utf8 = utf8}
-- utf8.byte = utf8.codepoint
do do
local progname local arg0, progname
for _, a in ipairs(arg) do if a:sub(1,11) == "--progname=" then for _, a in ipairs(arg) do
if a:sub(1,11) == "--progname=" then
progname = a:sub(12) progname = a:sub(12)
end end elseif a:sub(1,7) == "--arg0=" then
kpse.set_program_name(nil, progname) arg0 = a:sub(8)
end
end
kpse.set_program_name(arg0, progname)
end end
package.searchers[2] = function(modname) package.searchers[2] = function(modname)
local filename = kpse.find_file(modname, "kpse_lua_format", true) local filename = kpse.find_file(modname, "lua", true)
if not filename then if not filename then
return string.format("\n\tno file located through kpse for %s", modname) return string.format("\n\tno file located through kpse for %s", modname)
end end
@ -332,7 +24,7 @@ package.searchers[2] = function(modname)
end end
return mod, filename return mod, filename
end end
kpse.set_maketex("kpse_fmt_format", true) -- kpse.set_maketex("kpse_fmt_format", true)
bit32 = require'luametalatex-bit32' bit32 = require'luametalatex-bit32'
kpse.init_prog("LUATEX", 400, "nexthi", nil) kpse.init_prog("LUATEX", 400, "nexthi", nil)
status.init_kpse = 1 status.init_kpse = 1
@ -366,16 +58,25 @@ callback.register('define_font', function(name, size)
end end
return id return id
end) end)
-- do -- callback.register('terminal_input', function(prompt)
-- local register = callback.register -- print('Input expected: ', prompt)
-- function callback.register(...) -- return 'AAA'
-- print('callback.register', ...) -- end)
-- return register(...)
-- end
-- end
callback.register('find_log_file', function(name) return name end) callback.register('find_log_file', function(name) return name end)
callback.register('find_data_file', function(name) return kpse.find_file(name, 'kpse_tex_format', true) end) -- callback.register('find_read_file', function(i, name) return kpse.find_file(name, 'tex', true) end)
callback.register('find_format_file', function(name) return kpse.find_file(name, 'kpse_fmt_format', true) end) callback.register('find_data_file', function(name, ...) return kpse.find_file(name, 'tex', true) end)
callback.register('read_data_file', function(name) error[[TODO]]return kpse.find_file(name, 'tex', true) end)
-- local file_meta = {\
callback.register('open_data_file', function(name)
local f = io.open(name)
return setmetatable({
reader = function() return f:read() end,
close = function()error[[1]] return f:close() end,
}, {
__gc = function()f:close()end,
})
end)
callback.register('find_format_file', function(name) return kpse.find_file(name, 'fmt', true) end)
callback.register('show_warning_message', function() callback.register('show_warning_message', function()
texio.write_nl('WARNING Tag: ' .. status.lastwarningtag) texio.write_nl('WARNING Tag: ' .. status.lastwarningtag)
texio.write_nl(status.lastwarningstring) texio.write_nl(status.lastwarningstring)
@ -389,6 +90,12 @@ end)
callback.register('pre_dump', function() callback.register('pre_dump', function()
lua.bytecode[1] = assert(load(table.concat(lua.prepared_code, ' '))) lua.bytecode[1] = assert(load(table.concat(lua.prepared_code, ' ')))
end) end)
function texconfig.init()
if not status.ini_version then
lua.bytecode[2]()
lua.bytecode[2] = nil
end
end
if status.ini_version then if status.ini_version then
lua.prepared_code = {} lua.prepared_code = {}
local code = package.searchers[2]('luametalatex-firstcode') local code = package.searchers[2]('luametalatex-firstcode')

View File

@ -24,9 +24,12 @@
\catcode`\}=2 \catcode`\}=2
\def\x{\everyjob{\luabytecode2}} \def\x{\everyjob{\luabytecode2}}
\expandafter\endgroup\x \expandafter\endgroup\x
\let\savedversionofeTeXversion\eTeXversion
\let\savedversionofdump\dump \let\savedversionofdump\dump
\let\dump\relax \let\dump\relax
\let\eTeXversion\relax
\input latex.ltx \input latex.ltx
\let\eTeXversion\savedversionofeTeXversion
% \input luametalatex-baseregisters % \input luametalatex-baseregisters
\let\dump\savedversionofdump \let\dump\savedversionofdump
\let\savedversionofdump\undefined \let\savedversionofdump\undefined