summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-05-23 05:47:33 -0700
committerPhilipp Gesang <phg42.2a@gmail.com>2013-05-23 05:47:33 -0700
commitec6ddd136a1364a5c55e611cf6098c165b383ec0 (patch)
tree64a8366599b2e352c251f8e84e907d8c37c152e2
parent814392cdbd7fb04508e8def277b9620d1254ab60 (diff)
parentc437a26a8c912b66cb51ce90b95dc05f0a5d9fc4 (diff)
downloadlualibs-ec6ddd136a1364a5c55e611cf6098c165b383ec0.tar.gz
Merge pull request #13 from phi-gamma/master
sync
-rw-r--r--Makefile9
-rw-r--r--lualibs-file.lua19
-rw-r--r--lualibs-util-prs.lua13
-rw-r--r--whatsnew.lua171
4 files changed, 192 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 453d6cc..6916f1e 100644
--- a/Makefile
+++ b/Makefile
@@ -8,16 +8,18 @@ MODULES = $(filter-out $(UNPACKED),$(LUALIBS))
# Files grouped by generation mode
TESTSCRIPT = test-lualibs.lua
+DIFFSCRIPT = whatsnew.lua
+SCRIPTS = $(TESTSCRIPT) $(DIFFSCRIPT)
UNPACKED = lualibs.lua lualibs-extended.lua lualibs-basic.lua
COMPILED = $(DOC_DTX)
GENERATED = $(UNPACKED) $(DOC_DTX) $(MERGED)
-SOURCE = $(DTX) $(MODULES) $(TESTSCRIPT) LICENSE README Makefile NEWS
+SOURCE = $(DTX) $(MODULES) $(SCRIPTS) LICENSE README Makefile NEWS
MERGED = lualibs-basic-merged.lua lualibs-extended-merged.lua
# Files grouped by installation location
RUNFILES = $(UNPACKED) $(MODULES)
DOCFILES = $(DOC_DTX) LICENSE README NEWS
-SRCFILES = $(DTX) $(SRC_TEX) Makefile $(TESTSCRIPT)
+SRCFILES = $(DTX) $(SRC_TEX) Makefile $(SCRIPTS)
# The following definitions should be equivalent
# ALL_FILES = $(RUNFILES) $(DOCFILES) $(SRCFILES)
@@ -49,6 +51,9 @@ world: all ctan
check: $(TESTSCRIPT)
@texlua $(TESTSCRIPT)
+news: $(DIFFSCRIPT)
+ @texlua $(DIFFSCRIPT)
+
.PHONY: all doc unpack ctan tds world
%.pdf: %.dtx
diff --git a/lualibs-file.lua b/lualibs-file.lua
index deaaca7..a64ee86 100644
--- a/lualibs-file.lua
+++ b/lualibs-file.lua
@@ -585,18 +585,15 @@ end
-- end
-- end
--- a goodie: a dumb version of mkdirs:
+-- a goodie: a dumb version of mkdirs (not used in context itself, only
+-- in generic usage)
function lfs.mkdirs(path)
- local full
- for sub in gmatch(path,"([^\\/]+)") do
- if full then
- full = full .. "/" .. sub
- else
- full = sub
- end
- if not lfs.isdir(full) then
- lfs.mkdir(full)
- end
+ local full = ""
+ for sub in gmatch(path,"(/*[^\\/]+)") do -- accepts leading c: and /
+ full = full .. sub
+ -- lfs.isdir("/foo") mistakenly returns true on windows so
+ -- so we don't test and just make as that one is not too picky
+ lfs.mkdir(full)
end
end
diff --git a/lualibs-util-prs.lua b/lualibs-util-prs.lua
index cdf4975..9d2ffcc 100644
--- a/lualibs-util-prs.lua
+++ b/lualibs-util-prs.lua
@@ -372,9 +372,8 @@ local separator = S(' ,')
local key = C((1-equal)^1)
local value = dquote * C((1-dquote-escape*dquote)^0) * dquote
-local pattern = Cf(Ct("") * Cg(key * equal * value) * separator^0,rawset)^0 * P(-1)
-
-patterns.keq_to_hash_c = pattern
+----- pattern = Cf(Ct("") * Cg(key * equal * value) * separator^0,rawset)^0 * P(-1) -- was wrong
+local pattern = Cf(Ct("") * (Cg(key * equal * value) * separator^0)^1,rawset)^0 * P(-1)
function parsers.keq_to_hash(str)
if str and str ~= "" then
@@ -384,7 +383,7 @@ function parsers.keq_to_hash(str)
end
end
--- inspect(lpeg.match(pattern,[[key="value"]]))
+-- inspect(lpeg.match(pattern,[[key="value" foo="bar"]]))
local defaultspecification = { separator = ",", quote = '"' }
@@ -392,7 +391,7 @@ local defaultspecification = { separator = ",", quote = '"' }
-- database module
function parsers.csvsplitter(specification)
- specification = specification and table.setmetatableindex(specification,defaultspecification) or defaultspecification
+ specification = specification and table.setmetatableindex(specification,defaultspecification) or defaultspecification
local separator = specification.separator
local quotechar = specification.quote
local separator = S(separator ~= "" and separator or ",")
@@ -419,14 +418,14 @@ end
-- and this is a slightly patched version of a version posted by Philipp Gesang
-- local mycsvsplitter = utilities.parsers.rfc4180splitter()
---
+
-- local crap = [[
-- first,second,third,fourth
-- "1","2","3","4"
-- "a","b","c","d"
-- "foo","bar""baz","boogie","xyzzy"
-- ]]
---
+
-- local list, names = mycsvsplitter(crap,true) inspect(list) inspect(names)
-- local list, names = mycsvsplitter(crap) inspect(list) inspect(names)
diff --git a/whatsnew.lua b/whatsnew.lua
new file mode 100644
index 0000000..30cf837
--- /dev/null
+++ b/whatsnew.lua
@@ -0,0 +1,171 @@
+#!/usr/bin/env texlua
+--[===[--
+
+ whatsnew.lua -- Scan Context for changes in Lua libraries.
+ Part of the Lualibs package.
+ https://github.com/lualatex/lualibs
+
+ Copyright 2013 Philipp Gesang
+ License: GPL v2.0
+
+--]===]--
+
+-----------------------------------------------------------------------
+--- configuration
+-----------------------------------------------------------------------
+
+local prefixsep = "-"
+local namespace = "lualibs"
+local luasuffix = ".lua"
+local basedir = "/home/phg/context/tex/texmf-context/tex/context/base"
+local cmd_diff = [[diff "%s" "%s"]]
+
+-----------------------------------------------------------------------
+--- locals
+-----------------------------------------------------------------------
+
+local iopopen = io.popen
+local stringexplode = string.explode
+local stringformat = string.format
+local stringsub = string.sub
+local tableunpack = table.unpack
+
+-----------------------------------------------------------------------
+--- files
+-----------------------------------------------------------------------
+
+--- (prefix, keep) hash_t
+local namespaces = { { "l" , false },
+ { "util" , true },
+ { "trac" , true }, }
+
+--- (prefix, name list) hash_t
+local filenames = {
+ ["l"] = {
+ "boolean",
+ "dir",
+ "file",
+ "function",
+ "io",
+ "lpeg",
+ "lua",
+ "math",
+ "md5",
+ "number",
+ "os",
+ "package",
+ "set",
+ "string",
+ "table",
+ "unicode",
+ "url",
+ },
+
+ ["trac"] = { "inf" },
+
+ ["util"] = {
+ "deb",
+ "dim",
+ "env",
+ "jsn",
+ "lua",
+ "prs",
+ "sta",
+ "sto",
+ "str",
+ "tab",
+ "tpl",
+ },
+}
+
+-----------------------------------------------------------------------
+--- helpers
+-----------------------------------------------------------------------
+
+--- string -> string -> bool -> (string, string)
+local mknames = function (pfx, name, keeppfx)
+ local libname = basedir .. "/" .. pfx
+ .. prefixsep .. name .. luasuffix
+ local ourname = prefixsep .. name .. luasuffix
+ if keeppfx == true then
+ ourname = prefixsep .. pfx .. ourname
+ end
+ ourname = namespace .. ourname
+ ourname = "./" .. ourname
+ return ourname, libname
+end
+
+--- string -> (int * int)
+local count_changes = function (str)
+ local added, removed = 0, 0
+ for n, line in next, stringexplode(str, "\n") do
+ local first = stringsub(line, 1, 1)
+ if first == "<" then
+ removed = removed + 1
+ elseif first == ">" then
+ added = added + 1
+ end
+ end
+ return added, removed
+end
+
+--- string -> string -> (int * int)
+local run_diff = function (f1, f2)
+ local cmd = stringformat(cmd_diff, f1, f2)
+ local res = iopopen(cmd, "r")
+ local dat = res:read"*all"
+ res:close()
+ return count_changes(dat)
+end
+
+-----------------------------------------------------------------------
+--- main
+-----------------------------------------------------------------------
+
+local libs_done = 0
+local total_added = 0
+local total_removed = 0
+
+for n, namespace in next, namespaces do
+ local pfx, keeppfx = tableunpack(namespace)
+ local libs = filenames[pfx]
+ for i=1, #libs do
+ libs_done = libs_done + 1
+ local current = libs[i]
+ local from, to = mknames(pfx, current, keeppfx)
+ if lfs.isfile(from) and lfs.isfile(to) then
+ local added, removed = run_diff (from, to)
+ if added > 0 or removed > 0 then
+ total_added = total_added + added
+ total_removed = total_removed + removed
+ print(stringformat(
+ "(library %q (plus %d) (minus %d))",
+ from, added, removed
+ ))
+ end
+ else
+ if not lfs.isfile(from) then
+ print("cannot read file", from)
+ elseif not lfs.isfile(to) then
+ print("cannot read file", to)
+ end
+ goto fail
+ end
+ end
+end
+
+::done::
+if total_added == 0 and total_removed == 0 then
+ print "stagnation"
+else
+ print(stringformat(
+ "(progress (n-files %d) (added %d) (removed %d))",
+ libs_done, total_added, total_removed
+ ))
+end
+os.exit(0)
+
+::fail::
+print "fatal error"
+os.exit(1)
+