diff options
author | Taco Hoekwater <taco@elvenkind.com> | 2009-08-23 11:11:32 +0000 |
---|---|---|
committer | Taco Hoekwater <taco@elvenkind.com> | 2009-08-23 11:11:32 +0000 |
commit | 8fc3039c82d48605b5ca8b2eda3f4fdd755681e1 (patch) | |
tree | 3cd9bbdd599bc4d1ac0409e167fee2136e4c0ec9 /Master/texmf-dist/scripts/context/lua/mtx-tools.lua | |
parent | 850fc99b7cd3ae7a20065531fe866ff7bae642ec (diff) |
this is context 2009.08.19 17:10
git-svn-id: svn://tug.org/texlive/trunk@14827 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-tools.lua')
-rw-r--r-- | Master/texmf-dist/scripts/context/lua/mtx-tools.lua | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-tools.lua b/Master/texmf-dist/scripts/context/lua/mtx-tools.lua new file mode 100644 index 00000000000..87fd51dc60d --- /dev/null +++ b/Master/texmf-dist/scripts/context/lua/mtx-tools.lua @@ -0,0 +1,57 @@ +if not modules then modules = { } end modules ['mtx-tools'] = { + version = 1.002, + comment = "companion to mtxrun.lua", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- data tables by Thomas A. Schmitz + +local find, gsub = string.find, string.gsub + +scripts = scripts or { } +scripts.tools = scripts.tools or { } + +local bomb_1, bomb_2 = "^\254\255", "^\239\187\191" + +function scripts.tools.disarmutfbomb() + local force, done = environment.argument("force"), false + for _, name in ipairs(environment.files) do + if lfs.isfile(name) then + local data = io.loaddata(name) + if not data then + -- just skip + elseif find(data,bomb_1) then + logs.simple("file '%s' has a 2 character utf bomb",name) + if force then + io.savedata(name,(gsub(data,bomb_1,""))) + end + done = true + elseif find(data,bomb_2) then + logs.simple("file '%s' has a 3 character utf bomb",name) + if force then + io.savedata(name,(gsub(data,bomb_2,""))) + end + done = true + else + -- logs.simple("file '%s' has no utf bomb",name) + end + end + end + if done and not force then + logs.simple("use --force to do a real disarming") + end +end + +logs.extendbanner("All Kind Of Tools 1.0",true) + +messages.help = [[ +--disarmutfbomb remove utf bomb if present +]] + +if environment.argument("disarmutfbomb") then + scripts.tools.disarmutfbomb() +else + logs.help(messages.help) +end |