diff options
Diffstat (limited to 'scripts/context/lua/mtx-patterns.lua')
-rw-r--r-- | scripts/context/lua/mtx-patterns.lua | 93 |
1 files changed, 88 insertions, 5 deletions
diff --git a/scripts/context/lua/mtx-patterns.lua b/scripts/context/lua/mtx-patterns.lua index 2dcd3db54..1abe90385 100644 --- a/scripts/context/lua/mtx-patterns.lua +++ b/scripts/context/lua/mtx-patterns.lua @@ -27,6 +27,8 @@ local helpinfo = [[ <flag name="path"><short>source path where hyph-foo.tex files are stored</short></flag> <flag name="destination"><short>destination path</short></flag> <flag name="specification"><short>additional patterns: e.g.: =cy,hyph-cy,welsh</short></flag> + <flag name="compress"><short>compress data</short></flag> + <flag name="words"><short>update words in given file</short></flag> </subcategory> </category> </flags> @@ -413,6 +415,8 @@ function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenation if not comment or comment == "" then comment = "% no comment" end if not type(destination) == "string" then destination = "." end + local compression = environment.arguments.compress and "zlib" or nil + local lines = string.splitlines(comment) for i=1,#lines do if not find(lines[i],"^%%") then @@ -429,9 +433,12 @@ function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenation local patterndata, hyphenationdata if nofpatternsnew > 0 then + local data = concat(patternsnew," ") patterndata = { n = nofpatternsnew, - data = concat(patternsnew," ") or nil, + compression = compression, + length = #data, + data = compression and zlib.compress(data,9) or data, characters = concat(table.sortedkeys(pusednew),""), minhyphenmin = 1, -- determined by pattern author minhyphenmax = 1, -- determined by pattern author @@ -442,10 +449,13 @@ function scripts.patterns.save(destination,mnemonic,name,patternsnew,hyphenation } end if nofhyphenationsnew > 0 then + local data = concat(hyphenationsnew," ") hyphenationdata = { - n = nofhyphenationsnew, - data = concat(hyphenationsnew," "), - characters = concat(table.sortedkeys(husednew),""), + n = nofhyphenationsnew, + compression = compression, + length = #data, + data = compression and zlib.compress(data,9) or data, + characters = concat(table.sortedkeys(husednew),""), } else hyphenationdata = { @@ -543,12 +553,83 @@ function scripts.patterns.convert() end end +local function valid(filename) + local specification = table.load(filename) + if not specification then + return false + end + local lists = specification.lists + if not lists then + return false + end + return specification, lists +end + +function scripts.patterns.words() + if environment.arguments.update then + local compress = environment.arguments.compress + for i=1,#environment.files do + local filename = environment.files[i] + local fullname = resolvers.findfile(filename) + if fullname and fullname ~= "" then + report("checking file %a",fullname) + local specification, lists = valid(fullname) + if specification and #lists> 0 then + report("updating %a of language %a",filename,specification.language) + for i=1,#lists do + local entry = lists[i] + local filename = entry.filename + if filename then + local fullname = resolvers.findfile(filename) + if fullname then + report("adding words from %a",fullname) + local data = io.loaddata(fullname) or "" + data = string.strip(data) + data = string.gsub(data,"%s+"," ") + if compress then + entry.data = zlib.compress(data,9) + entry.compression = "zlib" + entry.length = #data + else + entry.data = data + entry.compression = nil + entry.length = #data + end + else + entry.data = "" + entry.compression = nil + entry.length = 0 + end + else + entry.data = "" + entry.compression = nil + entry.length = 0 + end + end + specification.version = "1.00" + specification.timestamp = os.localtime() + report("updated file %a is saved",filename) + table.save(filename,specification) + else + report("no file %a",filename) + end + else + report("nothing done") + end + end + else + report("provide --update") + end +end + if environment.argument("check") then scripts.patterns.prepare() scripts.patterns.check() elseif environment.argument("convert") then scripts.patterns.prepare() scripts.patterns.convert() +elseif environment.argument("words") then + scripts.patterns.words() -- for the moment here elseif environment.argument("exporthelp") then application.export(environment.argument("exporthelp"),environment.files[1]) else @@ -558,7 +639,7 @@ end -- mtxrun --script pattern --check hyph-*.tex -- mtxrun --script pattern --check --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns -- mtxrun --script pattern --convert --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns/tex --destination=e:/tmp/patterns --- mtxrun --script pattern --convert --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns/txt --destination=e:/tmp/patterns +-- mtxrun --script pattern --convert --path=c:/data/develop/svn-hyphen/trunk/hyph-utf8/tex/generic/hyph-utf8/patterns/txt --destination=e:/tmp/patterns --compress -- copy /Y *.hyp e:\tex-context\tex\texmf-context\tex\context\patterns -- copy /Y *.pat e:\tex-context\tex\texmf-context\tex\context\patterns @@ -569,3 +650,5 @@ end -- move /Y *.pat e:\tex-context\tex\texmf-mine\tex\context\patterns -- move /Y *.rme e:\tex-context\tex\texmf-mine\tex\context\patterns -- move /Y *.lua e:\tex-context\tex\texmf-mine\tex\context\patterns + +-- mtxrun --script pattern --words --update word-th.lua --compress |