diff options
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-unzip.lua')
-rw-r--r-- | Master/texmf-dist/scripts/context/lua/mtx-unzip.lua | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-unzip.lua b/Master/texmf-dist/scripts/context/lua/mtx-unzip.lua index f990f421032..645863426db 100644 --- a/Master/texmf-dist/scripts/context/lua/mtx-unzip.lua +++ b/Master/texmf-dist/scripts/context/lua/mtx-unzip.lua @@ -1,20 +1,32 @@ +if not modules then modules = { } end modules ['mtx-unzip'] = { + 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" +} + -- maybe --pattern -logs.extendbanner("Simple Unzipper 0.10") +local format = string.format -messages.help = [[ +local helpinfo = [[ --list list files in archive --junk flatten unzipped directory structure --extract extract files ]] +local application = logs.application { + name = "mtx-unzip", + banner = "Simple Unzipper 0.10", + helpinfo = helpinfo, +} + +local report = application.report + scripts = scripts or { } scripts.unzipper = scripts.unzipper or { } -function scripts.unzipper.help() - logs.help(messages.help) -end - function scripts.unzipper.opened() local filename = environment.files[1] if filename and filename ~= "" then @@ -24,7 +36,7 @@ function scripts.unzipper.opened() return zipfile end end - logs.report("unzip", "no zip file: " .. filename) + report("no zip file: %s",filename) return false end @@ -36,10 +48,13 @@ function scripts.unzipper.list() if #k.filename > n then n = #k.filename end end local files, paths, compressed, uncompressed = 0, 0, 0, 0 + local template_a = "%-"..n.."s" + local template_b = "%-"..n.."s % 9i % 9i" + local template_c = "\n%-"..n.."s % 9i % 9i" for k in zipfile:files() do if k.filename:find("/$") then paths = paths + 1 - print(string.format("%s", k.filename:rpadd(n," "))) + print(format(template_a, k.filename)) else files = files + 1 local cs, us = k.compressed_size, k.uncompressed_size @@ -49,10 +64,10 @@ function scripts.unzipper.list() if us > uncompressed then uncompressed = us end - print(string.format("%s % 9i % 9i", k.filename:rpadd(n," "),cs,us)) + print(format(template_b,k.filename,cs,us)) end - end - print(string.format("\n%s % 9i % 9i", (files .. " files, " .. paths .. " directories"):rpadd(n," "),compressed,uncompressed)) + end -- check following pattern, n is not enough + print(format(template_c,files .. " files, " .. paths .. " directories",compressed,uncompressed)) end end @@ -91,11 +106,11 @@ function scripts.unzipper.extract() end if environment.arguments["h"] or environment.arguments["help"] then - scripts.unzipper.help() + application.help() elseif environment.arguments["l"] or environment.arguments["list"] then scripts.unzipper.list(zipfile) elseif environment.files[1] then -- implicit --extract scripts.unzipper.extract(zipfile) else - scripts.unzipper.help() + application.help() end |