From 2c4bb4e4fee25ed79f6183bff9200eba168c021d Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 24 Jul 2013 11:44:32 +0200 Subject: adapt makefile to conform to CTAN preferences according to Robin Fairbairns: > btw, the least error-prone format for the zip file is: > > xyz.zip -> > xyz.tds.zip (if available) > xyz/ > [actual distribution of package xyz] --- Makefile | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 6916f1e..556e56f 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) -- cgit v1.2.3 From cf4033d9e77993aede4c94349c87379a65893319 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 7 Aug 2013 13:11:10 +0200 Subject: sync with Context as of date --- Makefile | 1 + lualibs-boolean.lua | 4 ++-- lualibs-io.lua | 2 +- lualibs-os.lua | 24 ++++++++++++++++++------ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 556e56f..f04503a 100644 --- a/Makefile +++ b/Makefile @@ -112,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..3838b55 100644 --- a/lualibs-os.lua +++ b/lualibs-os.lua @@ -382,31 +382,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) -- cgit v1.2.3 From 2d2b012d75755fb9cc10a1cd3d070f83a569242b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 12 Aug 2013 16:27:59 +0200 Subject: sync with Context as of 2013-08-12 --- lualibs-os.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lualibs-os.lua b/lualibs-os.lua index 3838b55..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 -- cgit v1.2.3 From 36085526a0d2e5f35d0c6a9fc4daae0b6b69326f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 24 Aug 2013 12:55:14 +0200 Subject: sync with Context as of 2013-08-24 --- lualibs-util-str.lua | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3