summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2012-05-29 00:12:00 +0200
committerHans Hagen <pragma@wxs.nl>2012-05-29 00:12:00 +0200
commitc99d2bf28d96648c7d1852c9f5705d58655baeab (patch)
treea47017352408734b8e51883a475fd41c00956978 /scripts
parent64fa8007415f14472d59bdeaa4745815f13318f3 (diff)
downloadcontext-c99d2bf28d96648c7d1852c9f5705d58655baeab.tar.gz
beta 2012.05.29 00:12
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtx-patterns.lua54
1 files changed, 38 insertions, 16 deletions
diff --git a/scripts/context/lua/mtx-patterns.lua b/scripts/context/lua/mtx-patterns.lua
index d76606a6b..fbcb251b1 100644
--- a/scripts/context/lua/mtx-patterns.lua
+++ b/scripts/context/lua/mtx-patterns.lua
@@ -157,7 +157,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored)
local hyphenations, patterns, comment, stripset = "", "", "", ""
local splitpatternsnew, splithyphenationsnew = { }, { }
local splitpatternsold, splithyphenationsold = { }, { }
- local usedpatterncharacters, usedhyphenationcharacters = { }, { }
+ local usedpatterncharactersnew, usedhyphenationcharactersnew = { }, { }
if lfs.isfile(patfile) then
report("using txt files %s.[hyp|pat|lic].txt",name)
comment, patterns, hyphenations = io.loaddata(licfile) or "", io.loaddata(patfile) or "", io.loaddata(hypfile) or ""
@@ -258,7 +258,7 @@ function scripts.patterns.load(path,name,mnemonic,ignored)
if not cdb then
report("no entry in chardata for character %s (0x%04X)",char(b),b)
else
- local ct = cd[b].category
+ local ct = cdb.category
if ct == "lu" or ct == "ll" then
used[char(b)] = true
elseif ct == "nd" then
@@ -272,10 +272,10 @@ function scripts.patterns.load(path,name,mnemonic,ignored)
end
end
end
- return used
+ return used
end
- usedpatterncharacters = check(splitpatternsnew,byte("."))
- usedhyphenationcharacters = check(splithyphenationsnew,byte("-"))
+ usedpatterncharactersnew = check(splitpatternsnew,byte("."))
+ usedhyphenationcharactersnew = check(splithyphenationsnew,byte("-"))
for k, v in next, stripped do
report("entries that contain character %s (0x%04X) have been omitted",char(k),k)
end
@@ -350,16 +350,36 @@ function scripts.patterns.load(path,name,mnemonic,ignored)
if not okay then
report("no valid file %s.*",name)
end
- return okay, splitpatternsnew, splithyphenationsnew, splitpatternsold, splithyphenationsold, comment, stripset, usedpatterncharacters, usedhyphenationcharacters
+
+ local function getused(t)
+ local u = { }
+ for k, v in next, t do
+ if ignored and ignored[k] then
+ elseif replaced_whatever[k] then
+ else
+ u[k] = v
+ end
+ end
+ return u
+ end
+ local usedpatterncharactersold = getused(usedpatterncharactersnew)
+ local usedhyphenationcharactersold = getused(usedhyphenationcharactersnew)
+
+ return okay,
+ splitpatternsnew, splithyphenationsnew, splitpatternsold, splithyphenationsold, comment, stripset,
+ usedpatterncharactersnew, usedhyphenationcharactersnew, usedpatterncharactersold, usedhyphenationcharactersold
end
-function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenationsnew,patternsold,hyphenationsold,comment,stripped,pused,hused,ignored)
+function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenationsnew,patternsold,hyphenationsold,comment,stripped,
+ pusednew,husednew,pusedold,husedold,ignored)
local nofpatternsnew, nofhyphenationsnew = #patternsnew, #hyphenationsnew
local nofpatternsold, nofhyphenationsold = #patternsold, #hyphenationsold
report("language %s has %s old and %s new patterns and %s old and %s new exceptions",mnemonic,nofpatternsold,nofpatternsnew,nofhyphenationsold,nofhyphenationsnew)
if mnemonic ~= "??" then
- local pu = concat(table.sortedkeys(pused), " ")
- local hu = concat(table.sortedkeys(hused), " ")
+ local punew = concat(table.sortedkeys(pusednew), " ")
+ local hunew = concat(table.sortedkeys(husednew), " ")
+ local puold = concat(table.sortedkeys(pusedold), " ")
+ local huold = concat(table.sortedkeys(husedold), " ")
local rmefile = file.join(destination,"lang-"..mnemonic..".rme")
local patfile = file.join(destination,"lang-"..mnemonic..".pat")
@@ -367,7 +387,7 @@ function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenation
local luafile = file.join(destination,"lang-"..mnemonic..".lua") -- suffix might change to llg
local topline = "% generated by mtxrun --script pattern --convert"
- local banner = "% for comment and copyright, see " .. rmefile
+ local banner = "% for comment and copyright, see " .. file.basename(rmefile)
report("saving language data for %s",mnemonic)
if not comment or comment == "" then comment = "% no comment" end
if not type(destination) == "string" then destination = "." end
@@ -391,7 +411,7 @@ function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenation
patterndata = {
n = nofpatternsnew,
data = concat(patternsnew," ") or nil,
- characters = concat(table.sortedkeys(pused),""),
+ characters = concat(table.sortedkeys(pusednew),""),
minhyphenmin = 1, -- determined by pattern author
minhyphenmax = 1, -- determined by pattern author
}
@@ -404,7 +424,7 @@ function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenation
hyphenationdata = {
n = nofhyphenationsnew,
data = concat(hyphenationsnew," "),
- characters = concat(table.sortedkeys(hused),""),
+ characters = concat(table.sortedkeys(husednew),""),
}
else
hyphenationdata = {
@@ -427,8 +447,8 @@ function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenation
os.remove(luafile)
io.savedata(rmefile,format("%s\n\n%s",topline,comment))
- io.savedata(patfile,format("%s\n\n%s\n\n%% used: %s\n\n\\patterns{\n%s}",topline,banner,pu,concat(patternsold,"\n")))
- io.savedata(hypfile,format("%s\n\n%s\n\n%% used: %s\n\n\\hyphenation{\n%s}",topline,banner,hu,concat(hyphenationsold,"\n")))
+ io.savedata(patfile,format("%s\n\n%s\n\n%% used: %s\n\n\\patterns{\n%s}",topline,banner,puold,concat(patternsold,"\n")))
+ io.savedata(hypfile,format("%s\n\n%s\n\n%% used: %s\n\n\\hyphenation{\n%s}",topline,banner,huold,concat(hyphenationsold,"\n")))
io.savedata(luafile,table.serialize(data,true))
end
end
@@ -475,9 +495,11 @@ function scripts.patterns.convert()
local mnemonic, name, ignored = v[1], v[2], v[4]
if not only or only[mnemonic] then
report("converting language %s, file %s", mnemonic, name)
- local okay, patternsnew, hyphenationsnew, patternsold, hyphenationsold, comment, stripped, pused, hused = scripts.patterns.load(path,name,mnemonic,ignored)
+ local okay, patternsnew, hyphenationsnew, patternsold, hyphenationsold, comment, stripped,
+ pusednew, husednew, pusedold, husedold = scripts.patterns.load(path,name,mnemonic,ignored)
if okay then
- scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenationsnew,patternsold,hyphenationsold,comment,stripped,pused,hused,ignored)
+ scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenationsnew,patternsold,hyphenationsold,comment,stripped,
+ pusednew,husednew,pusedold,husedold,ignored)
else
report("convertion aborted due to error(s)")
end