diff options
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | lualibs-gzip.lua | 54 | ||||
-rw-r--r-- | lualibs-util-str.lua | 45 | ||||
-rw-r--r-- | lualibs.dtx | 20 | ||||
-rw-r--r-- | test-lualibs.lua | 1 | ||||
-rw-r--r-- | whatsnew.lua | 1 |
7 files changed, 116 insertions, 10 deletions
@@ -1,4 +1,8 @@ History of the lualibs package +2013/11/03 v2.1/ + * sync with Context beta as of 2013-11-01 + * add l-gzip + 2013/07/23 v2.0c/ * sync with Context beta as of 2013-07-14 @@ -41,6 +41,7 @@ Source files: lualibs-compat.lua tex/luatex/lualibs/lualibs-compat.lua lualibs-dir.lua tex/luatex/lualibs/lualibs-dir.lua lualibs-file.lua tex/luatex/lualibs/lualibs-file.lua + lualibs-gzip.lua tex/luatex/lualibs/lualibs-gzip.lua lualibs-function.lua tex/luatex/lualibs/lualibs-function.lua lualibs-io.lua tex/luatex/lualibs/lualibs-io.lua lualibs-lpeg.lua tex/luatex/lualibs/lualibs-lpeg.lua diff --git a/lualibs-gzip.lua b/lualibs-gzip.lua new file mode 100644 index 0000000..5100e47 --- /dev/null +++ b/lualibs-gzip.lua @@ -0,0 +1,54 @@ +if not modules then modules = { } end modules ['l-gzip'] = { + version = 1.001, + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +if not gzip then + + -- no fallback yet + + return + +end + +local suffix, suffixes = file.suffix, file.suffixes + +function gzip.load(filename) + local f = io.open(filename,"rb") + if not f then + -- invalid file + elseif suffix(filename) == "gz" then + f:close() + local g = gzip.open(filename,"rb") + if g then + local str = g:read("*all") + g:close() + return str + end + else + local str = f:read("*all") + f:close() + return str + end +end + +function gzip.save(filename,data) + if suffix(filename) ~= "gz" then + filename = filename .. ".gz" + end + local f = io.open(filename,"wb") + if f then + local s = zlib.compress(data or "",9,nil,15+16) + f:write(s) + f:close() + return #s + end +end + +function gzip.suffix(filename) + local suffix, extra = suffixes(filename) + local gzipped = extra == "gz" + return suffix, gzipped +end diff --git a/lualibs-util-str.lua b/lualibs-util-str.lua index 295fc00..09fa26f 100644 --- a/lualibs-util-str.lua +++ b/lualibs-util-str.lua @@ -264,6 +264,33 @@ function number.signed(i) end end +local zero = P("0")^1 / "" +local plus = P("+") / "" +local minus = P("-") +local separator = S(".") +local digit = R("09") +local trailing = zero^1 * #S("eE") +local exponent = (S("eE") * (plus + Cs((minus * zero^0 * P(-1))/"") + minus) * zero^0 * (P(-1) * Cc("0") + P(1)^1)) +local pattern_a = Cs(minus^0 * digit^1 * (separator/"" * trailing + separator * (trailing + digit)^0) * exponent) +local pattern_b = Cs((exponent + P(1))^0) + +function number.sparseexponent(f,n) + if not n then + n = f + f = "%e" + end + local tn = type(n) + if tn == "string" then -- cast to number + local m = tonumber(n) + if m then + return lpegmatch((f == "%e" or f == "%E") and pattern_a or pattern_b,format(f,m)) + end + elseif tn == "number" then + return lpegmatch((f == "%e" or f == "%E") and pattern_a or pattern_b,format(f,n)) + end + return tostring(n) +end + local preamble = [[ local type = type local tostring = tostring @@ -282,6 +309,7 @@ local autosingle = string.autosingle local autodouble = string.autodouble local sequenced = table.sequenced local formattednumber = number.formatted +local sparseexponent = number.sparseexponent ]] local template = [[ @@ -376,6 +404,16 @@ local format_E = function(f) return format("format('%%%sE',a%s)",f,n) end +local format_j = function(f) + n = n + 1 + return format("sparseexponent('%%%se',a%s)",f,n) +end + +local format_J = function(f) + n = n + 1 + return format("sparseexponent('%%%sE',a%s)",f,n) +end + local format_x = function(f) n = n + 1 return format("format('%%%sx',a%s)",f,n) @@ -602,6 +640,8 @@ local format_extension = function(extensions,f,name) end end +-- aA b cC d eE f gG hH iI jJ lL mM N o p qQ r sS tT uU wW xX + local builder = Cs { "start", start = ( ( @@ -625,11 +665,11 @@ local builder = Cs { "start", + V("t") + V("T") + V("l") + V("L") + V("I") - + V("h") -- new + V("w") -- new + V("W") -- new + V("a") -- new + V("A") -- new + + V("j") + V("J") -- stripped e E + V("m") + V("M") -- new -- + V("*") -- ignores probably messed up % @@ -674,6 +714,9 @@ local builder = Cs { "start", ["w"] = (prefix_any * P("w")) / format_w, -- %w => n spaces (optional prefix is added) ["W"] = (prefix_any * P("W")) / format_W, -- %W => mandate prefix, no specifier -- + ["j"] = (prefix_any * P("j")) / format_j, -- %j => %e (float) stripped exponent (irrational) + ["J"] = (prefix_any * P("J")) / format_J, -- %J => %E (float) stripped exponent (irrational) + -- ["m"] = (prefix_tab * P("m")) / format_m, -- %m => xxx.xxx.xxx,xx (optional prefix instead of .) ["M"] = (prefix_tab * P("M")) / format_M, -- %M => xxx,xxx,xxx.xx (optional prefix instead of ,) -- diff --git a/lualibs.dtx b/lualibs.dtx index 45283cf..43e567a 100644 --- a/lualibs.dtx +++ b/lualibs.dtx @@ -34,7 +34,7 @@ \input docstrip.tex \Msg{************************************************************************} \Msg{* Installation} -\Msg{* Package: lualibs 2013/07/23 v2.0c Lua additional functions.} +\Msg{* Package: lualibs 2013/11/03 v2.1 Lua additional functions.} \Msg{************************************************************************} \keepsilent @@ -101,7 +101,7 @@ and the derived file lualibs.lua. %<*driver> \NeedsTeXFormat{LaTeX2e} \ProvidesFile{lualibs.drv} - [2013/07/23 v2.0c Lua Libraries.] + [2013/11/03 v2.1 Lua Libraries.] \documentclass{ltxdoc} \usepackage{fancyvrb,xspace} \usepackage[x11names]{xcolor} @@ -202,7 +202,7 @@ and the derived file lualibs.lua. % \GetFileInfo{lualibs.drv} % % \title{The \identifier{lualibs} package} -% \date{2013/07/23 v2.0c} +% \date{2013/11/03 v2.1} % \author{Élie Roux · \email{elie.roux@telecom-bretagne.eu}\\ % Philipp Gesang · \email{philipp.gesang@alumni.uni-heidelberg.de}} % @@ -315,6 +315,7 @@ and the derived file lualibs.lua. % lualibs-io.lua & l-io.lua & reading and writing files \\ % lualibs-os.lua & l-os.lua & platform specific code \\ % lualibs-file.lua & l-file.lua & filesystem operations \\ +% lualibs-gzip.lua & l-gzip.lua & wrapper for \identifier{lgzip} \\ % lualibs-md5.lua & l-md5.lua & checksum functions \\ % lualibs-dir.lua & l-dir.lua & directory handling \\ % lualibs-unicode.lua & l-unicode.lua & utf and unicode \\ @@ -417,8 +418,8 @@ lualibs = lualibs or { } lualibs.module_info = { name = "lualibs", - version = 2.00, - date = "2013/07/23", + version = 2.10, + date = "2013/11/03", description = "ConTeXt Lua standard libraries.", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang", copyright = "PRAGMA ADE / ConTeXt Development Team", @@ -572,8 +573,8 @@ local loadmodule = lualibs.loadmodule local lualibs_basic_module = { name = "lualibs-basic", - version = 2.00, - date = "2013/07/23", + version = 2.10, + date = "2013/11/03", description = "ConTeXt Lua libraries -- basic collection.", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang", copyright = "PRAGMA ADE / ConTeXt Development Team", @@ -611,6 +612,7 @@ if loaded == false then loadmodule("lualibs-io.lua") loadmodule("lualibs-os.lua") loadmodule("lualibs-file.lua") + loadmodule("lualibs-gzip.lua") loadmodule("lualibs-md5.lua") loadmodule("lualibs-dir.lua") loadmodule("lualibs-unicode.lua") @@ -653,8 +655,8 @@ lualibs = lualibs or { } local lualibs_extended_module = { name = "lualibs-extended", - version = 2.00, - date = "2013/07/23", + version = 2.10, + date = "2013/11/03", description = "ConTeXt Lua libraries -- extended collection.", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang", copyright = "PRAGMA ADE / ConTeXt Development Team", diff --git a/test-lualibs.lua b/test-lualibs.lua index 55cecfb..c592c6e 100644 --- a/test-lualibs.lua +++ b/test-lualibs.lua @@ -3,6 +3,7 @@ local luafiles = { "lualibs-boolean.lua", "lualibs-compat.lua", "lualibs-dir.lua", "lualibs-file.lua", + "lualibs-gzip.lua", "lualibs-function.lua", "lualibs-io.lua", "lualibs-lpeg.lua", "lualibs-lua.lua", "lualibs-math.lua", "lualibs-md5.lua", diff --git a/whatsnew.lua b/whatsnew.lua index 30cf837..0c0ca9b 100644 --- a/whatsnew.lua +++ b/whatsnew.lua @@ -46,6 +46,7 @@ local filenames = { "dir", "file", "function", + "gzip", "io", "lpeg", "lua", |