summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-08-24 04:00:06 -0700
committerPhilipp Gesang <phg42.2a@gmail.com>2013-08-24 04:00:06 -0700
commit3aacbae713dd9a3468578f56a75b74bb378a7de2 (patch)
treec48884db059a75ccab8a419e49983663c1c17ff8
parentd287bf5f8bc24ad366a3ff8e07dcb93d0f48bd03 (diff)
parent36085526a0d2e5f35d0c6a9fc4daae0b6b69326f (diff)
downloadlualibs-3aacbae713dd9a3468578f56a75b74bb378a7de2.tar.gz
Merge pull request #16 from phi-gamma/master
routine update to latest code
-rw-r--r--Makefile16
-rw-r--r--lualibs-boolean.lua4
-rw-r--r--lualibs-io.lua2
-rw-r--r--lualibs-os.lua32
-rw-r--r--lualibs-util-str.lua62
5 files changed, 101 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 6916f1e..f04503a 100644
--- a/Makefile
+++ b/Makefile
@@ -23,13 +23,14 @@ SRCFILES = $(DTX) $(SRC_TEX) Makefile $(SCRIPTS)
# The following definitions should be equivalent
# ALL_FILES = $(RUNFILES) $(DOCFILES) $(SRCFILES)
-ALL_FILES = $(GENERATED) $(SOURCE)
+ALL_FILES = $(SOURCE) $(filter-out $(SOURCE),$(GENERATED))
# Installation locations
FORMAT = luatex
RUNDIR = $(TEXMFROOT)/tex/$(FORMAT)/$(NAME)
DOCDIR = $(TEXMFROOT)/doc/$(FORMAT)/$(NAME)
SRCDIR = $(TEXMFROOT)/source/$(FORMAT)/$(NAME)
+DISTDIR = ./lualibs
TEXMFROOT = ./texmf
CTAN_ZIP = $(NAME).zip
@@ -54,7 +55,7 @@ check: $(TESTSCRIPT)
news: $(DIFFSCRIPT)
@texlua $(DIFFSCRIPT)
-.PHONY: all doc unpack ctan tds world
+.PHONY: all doc unpack ctan tds world check news
%.pdf: %.dtx
$(DO_PDFLATEX)
@@ -68,10 +69,16 @@ news: $(DIFFSCRIPT)
$(UNPACKED): lualibs.dtx
$(DO_TEX)
-$(CTAN_ZIP): $(SOURCE) $(COMPILED) $(GENERATED) $(TDS_ZIP)
+define make-ctandir
+@rm -r $(DISTDIR)
+@mkdir $(DISTDIR) && cp $(ALL_FILES) $(DISTDIR)
+endef
+
+$(CTAN_ZIP): $(ALL_FILES) $(TDS_ZIP)
@echo "Making $@ for CTAN upload."
@$(RM) -- $@
- @zip -9 $@ $^ >/dev/null
+ $(make-ctandir)
+ @zip -r -9 $@ $(DISTDIR) $(TDS_ZIP) >/dev/null
define run-install
@mkdir -p $(RUNDIR) && cp $(RUNFILES) $(RUNDIR)
@@ -105,5 +112,6 @@ clean:
mrproper: clean
@$(RM) -- $(GENERATED) $(ZIPS)
+ @$(RM) -r $(DISTDIR)
merge: $(MERGED)
diff --git a/lualibs-boolean.lua b/lualibs-boolean.lua
index f087f1a..8d11080 100644
--- a/lualibs-boolean.lua
+++ b/lualibs-boolean.lua
@@ -59,9 +59,9 @@ end
function string.is_boolean(str,default)
if type(str) == "string" then
- if str == "true" or str == "yes" or str == "on" or str == "t" then
+ if str == "true" or str == "yes" or str == "on" or str == "t" or str == "1" then
return true
- elseif str == "false" or str == "no" or str == "off" or str == "f" then
+ elseif str == "false" or str == "no" or str == "off" or str == "f" or str == "0" then
return false
end
end
diff --git a/lualibs-io.lua b/lualibs-io.lua
index e3a443b..52f166a 100644
--- a/lualibs-io.lua
+++ b/lualibs-io.lua
@@ -60,7 +60,7 @@ io.readall = readall
function io.loaddata(filename,textmode) -- return nil if empty
local f = io.open(filename,(textmode and 'r') or 'rb')
if f then
--- local data = f:read('*all')
+ -- local data = f:read('*all')
local data = readall(f)
f:close()
if #data > 0 then
diff --git a/lualibs-os.lua b/lualibs-os.lua
index a4c0ac8..8bfcf78 100644
--- a/lualibs-os.lua
+++ b/lualibs-os.lua
@@ -127,7 +127,13 @@ function io.popen (...) ioflush() return iopopen(...) end
function os.resultof(command)
local handle = io.popen(command,"r")
- return handle and handle:read("*all") or ""
+ if handle then
+ local result = handle:read("*all") or ""
+ handle:close()
+ return result
+ else
+ return ""
+ end
end
if not io.fileseparator then
@@ -382,31 +388,43 @@ end
local timeformat = format("%%s%s",os.timezone(true))
local dateformat = "!%Y-%m-%d %H:%M:%S"
+local lasttime = nil
+local lastdate = nil
function os.fulltime(t,default)
- t = tonumber(t) or 0
+ t = t and tonumber(t) or 0
if t > 0 then
-- valid time
elseif default then
return default
else
- t = nil
+ t = time()
end
- return format(timeformat,date(dateformat,t))
+ if t ~= lasttime then
+ lasttime = t
+ lastdate = format(timeformat,date(dateformat))
+ end
+ return lastdate
end
local dateformat = "%Y-%m-%d %H:%M:%S"
+local lasttime = nil
+local lastdate = nil
function os.localtime(t,default)
- t = tonumber(t) or 0
+ t = t and tonumber(t) or 0
if t > 0 then
-- valid time
elseif default then
return default
else
- t = nil
+ t = time()
+ end
+ if t ~= lasttime then
+ lasttime = t
+ lastdate = date(dateformat,t)
end
- return date(dateformat,t)
+ return lastdate
end
function os.converttime(t,default)
diff --git a/lualibs-util-str.lua b/lualibs-util-str.lua
index 13e1e09..295fc00 100644
--- a/lualibs-util-str.lua
+++ b/lualibs-util-str.lua
@@ -281,6 +281,7 @@ local tracedchar = string.tracedchar
local autosingle = string.autosingle
local autodouble = string.autodouble
local sequenced = table.sequenced
+local formattednumber = number.formatted
]]
local template = [[
@@ -520,6 +521,61 @@ local format_W = function(f) -- handy when doing depth related indent
return format("nspaces[%s]",tonumber(f) or 0)
end
+-- maybe to util-num
+
+local digit = patterns.digit
+local period = patterns.period
+local three = digit * digit * digit
+
+local splitter = Cs (
+ (((1 - (three^1 * period))^1 + C(three)) * (Carg(1) * three)^1 + C((1-period)^1))
+ * (P(1)/"" * Carg(2)) * C(2)
+)
+
+patterns.formattednumber = splitter
+
+function number.formatted(n,sep1,sep2)
+ local s = type(s) == "string" and n or format("%0.2f",n)
+ if sep1 == true then
+ return lpegmatch(splitter,s,1,".",",")
+ elseif sep1 == "." then
+ return lpegmatch(splitter,s,1,sep1,sep2 or ",")
+ elseif sep1 == "," then
+ return lpegmatch(splitter,s,1,sep1,sep2 or ".")
+ else
+ return lpegmatch(splitter,s,1,sep1 or ",",sep2 or ".")
+ end
+end
+
+-- print(number.formatted(1))
+-- print(number.formatted(12))
+-- print(number.formatted(123))
+-- print(number.formatted(1234))
+-- print(number.formatted(12345))
+-- print(number.formatted(123456))
+-- print(number.formatted(1234567))
+-- print(number.formatted(12345678))
+-- print(number.formatted(12345678,true))
+-- print(number.formatted(1234.56,"!","?"))
+
+local format_m = function(f)
+ n = n + 1
+ if not f or f == "" then
+ f = ","
+ end
+ return format([[formattednumber(a%s,%q,".")]],n,f)
+end
+
+local format_M = function(f)
+ n = n + 1
+ if not f or f == "" then
+ f = "."
+ end
+ return format([[formattednumber(a%s,%q,",")]],n,f)
+end
+
+--
+
local format_rest = function(s)
return format("%q",s) -- catches " and \n and such
end
@@ -574,6 +630,7 @@ local builder = Cs { "start",
+ V("W") -- new
+ V("a") -- new
+ V("A") -- new
+ + V("m") + V("M") -- new
--
+ V("*") -- ignores probably messed up %
)
@@ -617,6 +674,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
--
+ ["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 ,)
+ --
["a"] = (prefix_any * P("a")) / format_a, -- %a => '...' (forces tostring)
["A"] = (prefix_any * P("A")) / format_A, -- %A => "..." (forces tostring)
--
@@ -647,7 +707,7 @@ local function make(t,str)
p = lpegmatch(builder,str,1,"..",t._extensions_) -- after this we know n
if n > 0 then
p = format(template,preamble,t._preamble_,arguments[n],p)
--- print("builder>",p)
+-- print("builder>",p)
f = loadstripped(p)()
else
f = function() return str end