summaryrefslogtreecommitdiff
path: root/scripts/context/lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-04-11 10:29:07 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-04-11 10:29:07 +0200
commit57a61e4673116076f5bbff7600e6dad376af9173 (patch)
tree8261af49f1576dcfea0f152300d22e1a64ae907f /scripts/context/lua
parent274c32699e7826f7590248f91aa1bfbf5b07c8ee (diff)
downloadcontext-57a61e4673116076f5bbff7600e6dad376af9173.tar.gz
2016-04-10 23:57:00
Diffstat (limited to 'scripts/context/lua')
-rw-r--r--scripts/context/lua/mtx-context.lua1
-rw-r--r--scripts/context/lua/mtx-fonts.lua34
-rw-r--r--scripts/context/lua/mtx-interface.lua398
-rw-r--r--scripts/context/lua/mtxrun.lua8
4 files changed, 241 insertions, 200 deletions
diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua
index 7c64687b9..dce9170cc 100644
--- a/scripts/context/lua/mtx-context.lua
+++ b/scripts/context/lua/mtx-context.lua
@@ -731,6 +731,7 @@ function scripts.context.run(ctxdata,filename)
end
end
--
+ -- todo: --output-file=... in luatex
--
local l_flags = {
["interaction"] = a_batchmode,
diff --git a/scripts/context/lua/mtx-fonts.lua b/scripts/context/lua/mtx-fonts.lua
index 79c8cf65e..a83d8fc48 100644
--- a/scripts/context/lua/mtx-fonts.lua
+++ b/scripts/context/lua/mtx-fonts.lua
@@ -242,17 +242,18 @@ end
local function showfeatures(tag,specification)
report()
- report("mapping : %s",tag)
- report("fontname: %s",specification.fontname)
- report("fullname: %s",specification.fullname)
- report("filename: %s",specification.filename)
- report("family : %s",specification.familyname or "<nofamily>")
- report("weight : %s",specification.weight or "<noweight>")
- report("style : %s",specification.style or "<nostyle>")
- report("width : %s",specification.width or "<nowidth>")
- report("variant : %s",specification.variant or "<novariant>")
- report("subfont : %s",subfont(specification.subfont))
- report("fweight : %s",fontweight(specification.fontweight))
+ report("mapping : %s",tag)
+ report("fontname : %s",specification.fontname)
+ report("fullname : %s",specification.fullname)
+ report("filename : %s",specification.filename)
+ report("family : %s",specification.familyname or "<nofamily>")
+ -- report("subfamily : %s",specification.subfamilyname or "<nosubfamily>")
+ report("weight : %s",specification.weight or "<noweight>")
+ report("style : %s",specification.style or "<nostyle>")
+ report("width : %s",specification.width or "<nowidth>")
+ report("variant : %s",specification.variant or "<novariant>")
+ report("subfont : %s",subfont(specification.subfont))
+ report("fweight : %s",fontweight(specification.fontweight))
-- maybe more
local features = fonts.helpers.getfeatures(specification.filename,specification.format)
if features then
@@ -306,11 +307,12 @@ local function list_specifications(t,info)
local v = s[k]
local entry = t[v]
s[k] = {
- entry.familyname or "<nofamily>",
- entry.weight or "<noweight>",
- entry.style or "<nostyle>",
- entry.width or "<nowidth>",
- entry.variant or "<novariant>",
+ entry.familyname or "<nofamily>",
+ -- entry.subfamilyname or "<nosubfamily>",
+ entry.weight or "<noweight>",
+ entry.style or "<nostyle>",
+ entry.width or "<nowidth>",
+ entry.variant or "<novariant>",
entry.fontname,
entry.filename,
subfont(entry.subfont),
diff --git a/scripts/context/lua/mtx-interface.lua b/scripts/context/lua/mtx-interface.lua
index d0c889c9f..c5fb7c595 100644
--- a/scripts/context/lua/mtx-interface.lua
+++ b/scripts/context/lua/mtx-interface.lua
@@ -21,9 +21,7 @@ local helpinfo = [[
<flags>
<category name="basic">
<subcategory>
- <flag name="interfaces"><short>generate context interface files</short></flag>
- <flag name="messages"><short>generate context message files</short></flag>
- <flag name="labels"><short>generate context label files</short></flag>
+ <flag name="interfaces"><short>generate context mkii interface files</short></flag>
</subcategory>
<subcategory>
<flag name="context"><short>equals <ref name="interfaces"/> <ref name="messages"/> <ref name="languages"/></short></flag>
@@ -228,87 +226,229 @@ function flushers.textpad(collected)
end
end
+-- function scripts.interface.editor(editor,split,forcedinterfaces)
+-- local interfaces= forcedinterfaces or environment.files
+-- if #interfaces == 0 then
+-- interfaces= userinterfaces
+-- end
+-- local xmlfile = resolvers.findfile("cont-en.xml") or ""
+-- if xmlfile == "" then
+-- report("unable to locate cont-en.xml")
+-- end
+-- local collected = { }
+-- for i=1,#interfaces do
+-- local interface = interfaces[i]
+-- local keyfile = resolvers.findfile(format("keys-%s.xml",interface)) or ""
+-- if keyfile == "" then
+-- report("unable to locate keys-*.xml")
+-- else
+-- local commands = { }
+-- local mappings = { }
+-- local environments = { }
+-- local x = xml.load(keyfile)
+-- for e, d, k in xml.elements(x,"/cd:interface/cd:commands/cd:command") do -- somehow this was variable
+-- local at = d[k].at
+-- local name, value = at.name, at.value
+-- if name and value then
+-- mappings[name] = value
+-- end
+-- end
+-- local x = xml.load(xmlfile)
+-- for e, d, k in xml.elements(x,"/cd:interface/cd:command") do
+-- local at = d[k].at
+-- local name, type = at.name, at["type"]
+-- if name and name ~= "" then
+-- local remapped = mappings[name] or name
+-- if type == "environment" then
+-- if split then
+-- environments[#environments+1] = remapped
+-- else
+-- commands[#commands+1] = "start" .. remapped
+-- commands[#commands+1] = "stop" .. remapped
+-- end
+-- else
+-- commands[#commands+1] = remapped
+-- end
+-- end
+-- end
+-- if #commands > 0 then
+-- sort(commands)
+-- sort(environments)
+-- collected[interface] = {
+-- commands = commands,
+-- environments = environments,
+-- }
+-- end
+-- end
+-- end
+-- -- awaiting completion of the xml file
+-- local definitions = dofile(resolvers.findfile("mult-def.lua"))
+-- if definitions then
+-- local commands = { en = { } }
+-- for command, languages in next, definitions.commands do
+-- commands.en[languages.en or command] = true
+-- for language, command in next, languages do
+-- local c = commands[language]
+-- if c then
+-- c[command] = true
+-- else
+-- commands[language] = { [command] = true }
+-- end
+-- end
+-- end
+-- for language, data in next, commands do
+-- local fromlua = data
+-- local fromxml = collected[language].commands
+-- for i=1,#fromxml do
+-- local c = fromxml[i]
+-- if not fromlua[c] then
+-- -- print(language,c)
+-- fromlua[c] = true
+-- end
+-- end
+-- collected[language].commands = table.sortedkeys(fromlua)
+-- end
+-- end
+-- --
+-- flushers[editor](collected)
+-- end
+
+-- function scripts.interface.editor(editor,split,forcedinterfaces)
+-- local interfaces= forcedinterfaces or environment.files
+-- if #interfaces == 0 then
+-- interfaces= userinterfaces
+-- end
+-- --
+-- local filename = "context-en.xml"
+-- local xmlfile = resolvers.findfile(filename) or ""
+-- if xmlfile == "" then
+-- report("unable to locate %a",filename)
+-- return
+-- end
+-- local x = xml.load(xmlfile)
+-- --
+-- local filename = "mult-def.lua"
+-- local deffile = resolvers.findfile(filename) or ""
+-- if deffile == "" then
+-- report("unable to locate %a",filename)
+-- return
+-- end
+-- local interface = dofile(filename)
+-- if not interface or not next(interface) then
+-- report("invalid file %a",filename)
+-- return
+-- end
+-- local variables = interface.variables
+-- local constants = interface.constants
+-- local commands = interface.commands
+-- local elements = interface.elements
+-- local collected = { }
+-- for i=1,#interfaces do
+-- local interface = interfaces[i]
+-- local i_commands = { }
+-- local i_environments = { }
+-- local start = elements.start[interface] or elements.start.en
+-- local stop = elements.stop [interface] or elements.stop .en
+-- for e, d, k in xml.elements(x,"cd:interface/cd:command") do
+-- local at = d[k].at
+-- local name = at["name"] or ""
+-- local type = at["type"]
+-- if name ~= "" then
+-- local c = commands[name]
+-- local n = c and (c[interface] or c.en) or name
+-- if type ~= "environment" then
+-- i_commands[#i_commands+1] = n
+-- elseif split then
+-- i_environments[#i_environments+1] = n
+-- else
+-- -- variables ?
+-- i_commands[#i_commands+1] = start .. n
+-- i_commands[#i_commands+1] = stop .. n
+-- end
+-- end
+-- end
+-- if #i_commands > 0 then
+-- sort(i_commands)
+-- sort(i_environments)
+-- collected[interface] = {
+-- commands = i_commands,
+-- environments = i_environments,
+-- }
+-- end
+-- end
+-- --
+-- flushers[editor](collected)
+-- end
+
function scripts.interface.editor(editor,split,forcedinterfaces)
local interfaces= forcedinterfaces or environment.files
if #interfaces == 0 then
interfaces= userinterfaces
end
- local xmlfile = resolvers.findfile("cont-en.xml") or ""
+ --
+ local filename = "i-context.xml"
+ local xmlfile = resolvers.findfile(filename) or ""
if xmlfile == "" then
- report("unable to locate cont-en.xml")
+ report("unable to locate %a",filename)
+ return
+ end
+ --
+ local filename = "mult-def.lua"
+ local deffile = resolvers.findfile(filename) or ""
+ if deffile == "" then
+ report("unable to locate %a",filename)
+ return
+ end
+ local interface = dofile(deffile)
+ if not interface or not next(interface) then
+ report("invalid file %a",filename)
+ return
end
+ local variables = interface.variables
+ local constants = interface.constants
+ local commands = interface.commands
+ local elements = interface.elements
+ --
local collected = { }
+ --
+ local xmlroot = xml.load(xmlfile)
+ xml.include(xmlroot,"cd:interfacefile","filename",true,function(s)
+ return io.loaddata(resolvers.findfile(s))
+ end)
+ --
for i=1,#interfaces do
- local interface = interfaces[i]
- local keyfile = resolvers.findfile(format("keys-%s.xml",interface)) or ""
- if keyfile == "" then
- report("unable to locate keys-*.xml")
- else
- local commands = { }
- local mappings = { }
- local environments = { }
- local x = xml.load(keyfile)
- for e, d, k in xml.elements(x,"/cd:interface/cd:commands/cd:command") do -- somehow this was variable
- local at = d[k].at
- local name, value = at.name, at.value
- if name and value then
- mappings[name] = value
- end
- end
- local x = xml.load(xmlfile)
- for e, d, k in xml.elements(x,"/cd:interface/cd:command") do
- local at = d[k].at
- local name, type = at.name, at["type"]
- if name and name ~= "" then
- local remapped = mappings[name] or name
- if type == "environment" then
- if split then
- environments[#environments+1] = remapped
- else
- commands[#commands+1] = "start" .. remapped
- commands[#commands+1] = "stop" .. remapped
- end
- else
- commands[#commands+1] = remapped
- end
- end
- end
- if #commands > 0 then
- sort(commands)
- sort(environments)
- collected[interface] = {
- commands = commands,
- environments = environments,
- }
- end
- end
- end
- -- awaiting completion of the xml file
- local definitions = dofile(resolvers.findfile("mult-def.lua"))
- if definitions then
- local commands = { en = { } }
- for command, languages in next, definitions.commands do
- commands.en[languages.en or command] = true
- for language, command in next, languages do
- local c = commands[language]
- if c then
- c[command] = true
+ local interface = interfaces[i]
+ local i_commands = { }
+ local i_environments = { }
+ local start = elements.start[interface] or elements.start.en
+ local stop = elements.stop [interface] or elements.stop .en
+ for e in xml.collected(xmlroot,"cd:interface/cd:command") do
+ local at = e.at
+ local name = at["name"] or ""
+ local type = at["type"]
+ if name ~= "" then
+ local c = commands[name]
+ local n = c and (c[interface] or c.en) or name
+ if at.generated == "yes" then
+ -- skip (for now)
+ elseif type ~= "environment" then
+ i_commands[#i_commands+1] = n
+ elseif split then
+ i_environments[#i_environments+1] = n
else
- commands[language] = { [command] = true }
+ -- variables ?
+ i_commands[#i_commands+1] = start .. n
+ i_commands[#i_commands+1] = stop .. n
end
end
end
- for language, data in next, commands do
- local fromlua = data
- local fromxml = collected[language].commands
- for i=1,#fromxml do
- local c = fromxml[i]
- if not fromlua[c] then
- -- print(language,c)
- fromlua[c] = true
- end
- end
- collected[language].commands = table.sortedkeys(fromlua)
+ if #i_commands > 0 then
+ sort(i_commands)
+ sort(i_environments)
+ collected[interface] = {
+ commands = i_commands,
+ environments = i_environments,
+ }
end
end
--
@@ -341,7 +481,7 @@ function scripts.interface.check()
end
end
-function scripts.interface.interfaces()
+function scripts.interface.mkii()
local filename = resolvers.findfile(environment.files[1] or "mult-def.lua") or ""
if filename ~= "" then
local interface = dofile(filename)
@@ -386,6 +526,7 @@ function scripts.interface.interfaces()
end
-- we could just replace attributes
for language, _ in next, commands.setuplayout do
+ -- keyword files
local texresult, xmlresult = { }, { }
texresult[#texresult+1] = format("%% this file is auto-generated, don't edit this file\n%%")
xmlresult[#xmlresult+1] = format("<?xml version='1.0'?>\n",tag)
@@ -402,9 +543,10 @@ function scripts.interface.interfaces()
report("saving interface definitions '%s'",texfilename)
io.savedata(xmlfilename,concat(xmlresult,"\n"))
report("saving interface translations '%s'",xmlfilename)
+ -- mkii files
if language ~= "en" and xmldata ~= "" then
local newdata = xmldata:gsub("(<cd:interface.*language=.)en(.)","%1"..language.."%2",1)
--- newdata = replace(newdata, 'cd:command', 'name', interface.commands, interface.elements, language)
+ -- newdata = replace(newdata, 'cd:command', 'name', interface.commands, interface.elements, language)
newdata = replace(newdata, 'cd:string', 'value', interface.commands, interface.elements, language)
newdata = replace(newdata, 'cd:variable' , 'value', interface.variables, nil, language)
newdata = replace(newdata, 'cd:parameter', 'name', interface.constants, nil, language)
@@ -415,6 +557,7 @@ function scripts.interface.interfaces()
io.savedata(xmlfilename,newdata)
report("saving interface specification '%s'",xmlfilename)
end
+ -- mkiv is generated otherwise
end
end
end
@@ -439,33 +582,6 @@ function scripts.interface.preprocess()
end
end
--- function scripts.interface.messages()
--- local filename = resolvers.findfile(environment.files[1] or "mult-mes.lua") or ""
--- if filename ~= "" then
--- local messages = dofile(filename)
--- report("messages for * loaded from '%s'",filename)
--- report()
--- for i=1,#messageinterfaces do
--- local interface = messageinterfaces[i]
--- local texresult = { }
--- for category, data in next, messages do
--- for tag, message in next, data do
--- if tag ~= "files" then
--- local msg = message[interface] or message["all"] or message["en"]
--- if msg then
--- texresult[#texresult+1] = format("\\setinterfacemessage{%s}{%s}{%s}",category,tag,msg)
--- end
--- end
--- end
--- end
--- texresult[#texresult+1] = format("%%\n\\endinput")
--- local interfacefile = format("mult-m%s.mkii",interface)
--- io.savedata(interfacefile,concat(texresult,"\n"))
--- report("messages for '%s' saved in '%s'",interface,interfacefile)
--- end
--- end
--- end
-
function scripts.interface.toutf()
local filename = environment.files[1]
if filename then
@@ -509,88 +625,10 @@ function scripts.interface.toutf()
end
end
--- function scripts.interface.labels()
--- require("char-def.lua")
--- require("lang-txt.lua")
--- local interfaces = require("mult-def.lua")
--- local variables = interfaces.variables
--- local contextnames = { }
--- for unicode, data in next, characters.data do
--- local contextname = data.contextname
--- if contextname then
--- contextnames[utfchar(unicode)] = "\\" .. contextname .. " "
--- end
--- end
--- contextnames["i"] = nil
--- contextnames["'"] = nil
--- contextnames["\\"] = nil
--- local function flush(f,kind,what,expand,namespace,prefix)
--- local whatdata = languages.data.labels[what]
--- f:write("\n")
--- f:write(format("%% %s => %s\n",what,kind))
--- for tag, data in table.sortedpairs(whatdata) do
--- if not data.hidden then
--- f:write("\n")
--- for language, text in table.sortedpairs(data.labels) do
--- if text ~= "" then
--- if expand then
--- text = utfgsub(text,".",contextnames)
--- text = gsub(text," ", "\ ")
--- end
--- if namespace and namespace[tag] then
--- tag = prefix .. tag
--- end
--- if find(text,",") then
--- text = "{" .. text .. "}"
--- end
--- if text == "" then
--- -- skip
--- else
--- if type(text) == "table" then
--- f:write(format("\\setup%stext[\\s!%s][%s={{%s},}]\n",kind,language,tag,text))
--- else
--- f:write(format("\\setup%stext[\\s!%s][%s={{%s},{%s}}]\n",kind,language,tag,text[1],text[2]))
--- end
--- end
--- end
--- end
--- end
--- end
--- end
--- function flushall(txtname,expand)
--- local f = io.open(txtname,"w")
--- if f then
--- report("saving '%s'",txtname)
--- f:write("% this file is auto-generated, don't edit this file\n")
--- flush(f,"head","titles",expand,variables,"\\v!")
--- flush(f,"label","texts",expand,variables,"\\v!")
--- flush(f,"mathlabel","functions",expand)
--- flush(f,"taglabel","tags",expand)
--- f:write("\n")
--- f:write("\\endinput\n")
--- f:close()
--- end
--- end
--- flushall("lang-txt.mkii",true)
--- flushall("lang-txt.mkiv",false)
--- end
-
local ea = environment.argument
-if ea("context") then
- scripts.interface.interfaces()
- -- scripts.interface.messages()
- -- scripts.interface.labels()
-elseif ea("interfaces") or ea("messages") or ea("labels") then
- if ea("interfaces") then
- scripts.interface.interfaces()
- end
- -- if ea("messages") then
- -- scripts.interface.messages()
- -- end
- -- if ea("labels") then
- -- scripts.interface.labels()
- -- end
+if ea("mkii") then
+ scripts.interface.mkii()
elseif ea("preprocess") then
scripts.interface.preprocess()
elseif ea("toutf") then
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 176598941..d0251f8b9 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -7972,7 +7972,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["trac-log"] = package.loaded["trac-log"] or true
--- original size: 30753, stripped down to: 21355
+-- original size: 30767, stripped down to: 21355
if not modules then modules={} end modules ['trac-log']={
version=1.001,
@@ -8016,7 +8016,7 @@ local report,subreport,status,settarget,setformats,settranslations
local direct,subdirect,writer,pushtarget,poptarget,setlogfile,settimedlog,setprocessor,setformatters,newline
if tex and (tex.jobname or tex.formatname) then
if texio.setescape then
- texio.setescape(0)
+ texio.setescape(0)
end
local function useluawrites()
local texio_write_nl=texio.write_nl
@@ -18735,8 +18735,8 @@ end -- of closure
-- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-fil.lua util-sac.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua
-- skipped libraries : -
--- original bytes : 796558
--- stripped bytes : 288905
+-- original bytes : 796572
+-- stripped bytes : 288919
-- end library merge