if not modules then modules = { } end modules ['mtx-cache'] = {
version = 1.001,
comment = "companion to mtxrun.lua",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local format = string.format
scripts = scripts or { }
scripts.interface = scripts.interface or { }
local flushers = { }
local userinterfaces = { 'en','cs','de','it','nl','ro','fr','pe' }
local messageinterfaces = { 'en','cs','de','it','nl','ro','fr','pe','no' }
function flushers.scite(interface,collection)
local result, i = {}, 0
result[#result+1] = format("keywordclass.macros.context.%s=",interface)
for i=1,#collection do
local command = collection[i]
if i==0 then
result[#result+1] = "\\\n"
i = 5
else
i = i - 1
end
result[#result+1] = format("%s ",command)
end
io.savedata(format("cont-%s-scite.properties",interface), table.concat(result),"\n")
io.savedata(format("cont-%s-scite.lua",interface), table.serialize(collection,true))
end
function flushers.jedit(interface,collection)
local result = {}
result[#result+1] = ""
result[#result+1] = "\n"
result[#result+1] = ""
result[#result+1] = "\t"
result[#result+1] = "\t\t"
for i=1,#collection do
local command = collection[i]
result[#result+1] = format("\t\t\t%s",command)
end
result[#result+1] = "\t\t"
result[#result+1] = "\t"
result[#result+1] = ""
io.savedata(format("context-jedit-%s.xml",interface), table.concat(result),"\n")
end
function flushers.bbedit(interface,collection)
local result = {}
result[#result+1] = ""
result[#result+1] = "BBLMKeywordList"
result[#result+1] = ""
for i=1,#collection do
local command = collection[i]
result[#result+1] = format("\t\\%s",command)
end
result[#result+1] = ""
io.savedata(format("context-bbedit-%s.xml",interface), table.concat(result),"\n")
end
function flushers.raw(interface,collection)
for i=1,#collection do
local command = collection[i]
logs.simple(command)
end
end
function scripts.interface.editor(editor)
local interfaces= environment.files
if #interfaces == 0 then
interfaces= userinterfaces
end
local xmlfile = resolvers.find_file("cont-en.xml") or ""
if xmlfile == "" then
logs.simple("unable to locate cont-en.xml")
end
for i=1,#interfaces do
local interface = interfaces[i]
local keyfile = resolvers.find_file(format("keys-%s.xml",interface)) or ""
if keyfile == "" then
logs.simple("unable to locate keys-*.xml")
else
local collection = { }
local mappings = { }
local x = xml.load(keyfile)
for e, d, k in xml.elements(x,"cd:command") do
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: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
collection[#collection+1] = "start" .. remapped
collection[#collection+1] = "stop" .. remapped
else
collection[#collection+1] = remapped
end
end
end
if #collection > 0 then
table.sort(collection)
flushers[editor](interface,collection)
end
end
end
end
function scripts.interface.check()
local xmlfile = resolvers.find_file("cont-en.xml") or ""
if xmlfile ~= "" then
local f = io.open("cont-en-check.tex","w")
if f then
f:write("\\starttext\n")
local x = xml.load(xmlfile)
for e, d, k in xml.elements(x,"cd:command") do
local dk = d[k]
local at = dk.at
if at then
local name = xml.filter(dk,"cd:sequence/cd:string/attribute(value)")
if name and name ~= "" then
if at.type == "environment" then
name = "start" .. name
end
f:write(format("\\doifundefined{%s}{\\writestatus{check}{command '%s' is undefined}}\n",name,name))
end
end
end
f:write("\\stoptext\n")
f:close()
end
end
end
function scripts.interface.context()
local filename = resolvers.find_file(environment.files[1] or "mult-def.lua") or ""
if filename ~= "" then
local interface = dofile(filename)
if interface and next(interface) then
local variables, constants, commands, elements = interface.variables, interface.constants, interface.commands, interface.elements
local filename = resolvers.find_file("cont-en.xml") or ""
local xmldata = filename ~= "" and (io.loaddata(filename) or "")
local function flush(texresult,xmlresult,language,what,tag)
local t = interface[what]
texresult[#texresult+1] = format("%% definitions for interface %s for language %s\n%%",what,language)
xmlresult[#xmlresult+1] = format("\t\n",what,language)
xmlresult[#xmlresult+1] = format("\t",what)
local sorted = table.sortedkeys(t)
for i=1,#sorted do
local key = sorted[i]
local v = t[key]
local value = v[language] or v["en"]
if not value then
logs.simple(format("warning, no value for key '%s' for language '%s'",key,language))
else
local value = t[key][language] or t[key].en
texresult[#texresult+1] = format("\\setinterface%s{%s}{%s}",tag,key,value)
xmlresult[#xmlresult+1] = format("\t\t",tag,key,value)
end
end
xmlresult[#xmlresult+1] = format("\t\n",tag)
end
local function replace(str, element, attribute, category, othercategory, language)
return str:gsub(format("(<%s[^>]-%s=)([\"\'])([^\"\']-)([\"\'])",element,attribute), function(a,b,c)
local cc = category[c]
if not cc and othercategory then
cc = othercategory[c]
end
if cc then
ccl = cc[language]
if ccl then
return a .. b .. ccl .. b
end
end
return a .. b .. c .. b
end)
end
for language, _ in next, commands.setuplayout do
local texresult, xmlresult = { }, { }
texresult[#texresult+1] = format("%% this file is auto-generated, don't edit this file\n%%")
xmlresult[#xmlresult+1] = format("\n",tag)
xmlresult[#xmlresult+1] = format("\n",language)
flush(texresult,xmlresult,language,"variables","variable")
flush(texresult,xmlresult,language,"constants","constant")
flush(texresult,xmlresult,language,"elements", "element")
flush(texresult,xmlresult,language,"commands", "command")
texresult[#texresult+1] = format("%%\n\\endinput")
xmlresult[#xmlresult+1] = format("")
local texfilename = format("mult-%s.tex",language)
local xmlfilename = format("keys-%s.xml",language)
io.savedata(texfilename,table.concat(texresult,"\n"))
logs.simple(format("saving interface definitions '%s'",texfilename))
io.savedata(xmlfilename,table.concat(xmlresult,"\n"))
logs.simple(format("saving interface translations '%s'",xmlfilename))
if language ~= "en" and xmldata ~= "" then
local newdata = xmldata:gsub("(