RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
____________________________________________________________________________
Server: rpm5.org Name: Ralf S. Engelschall
Root: /v/rpm/cvs Email: rse@rpm5.org
Module: rpm lua Date: 24-Dec-2007 16:12:58
Branch: HEAD Handle: 2007122415125601
Modified files:
lua/local llocal.lua
rpm CHANGES
rpm/scripts Makefile.am
Removed files:
rpm/scripts lua-dump.lua
Log:
merge scripts/lua-dump.lua directly into lua/local/llocal.lua to make
it easily available
Summary:
Revision Changes Path
1.3 +85 -1 lua/local/llocal.lua
1.2017 +1 -0 rpm/CHANGES
1.47 +1 -1 rpm/scripts/Makefile.am
1.2 +0 -88 rpm/scripts/lua-dump.lua
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: lua/local/llocal.lua
============================================================================
$ cvs diff -u -r1.2 -r1.3 llocal.lua
--- lua/local/llocal.lua 24 Dec 2007 15:02:11 -0000 1.2
+++ lua/local/llocal.lua 24 Dec 2007 15:12:57 -0000 1.3
@@ -1,4 +1,8 @@
+-- ----------------------------------------------------------------------- --
+-- GLOBAL HACKS
+-- ----------------------------------------------------------------------- --
+
-- provide a generic regular expression constructor
-- based on the most powerful regular expression engine
rex.new = rex.newPCRE
@@ -6,9 +10,13 @@
rex.new = rex.newPOSIX
end
--- provide namespace
+-- provide additional "util" namespace
util = {}
+-- ----------------------------------------------------------------------- --
+-- UNIX grep(1) EMULATIONS
+-- ----------------------------------------------------------------------- --
+
-- "global regular expression print" on file content
function util.grep(expr, filename)
if not posix.stat(filename, "mode") then
@@ -48,6 +56,10 @@
return false
end
+-- ----------------------------------------------------------------------- --
+-- REGULAR EXPRESSION MATCHING/SUBSTITUTION
+-- ----------------------------------------------------------------------- --
+
-- regular expression based string matching
function util.rmatch(str, regex)
return rex.new(regex):match(str)
@@ -70,3 +82,75 @@
return result
end
+-- ----------------------------------------------------------------------- --
+-- RECURSIVE DATA DUMPING
+-- ----------------------------------------------------------------------- --
+
+-- WORK HORSE:
+-- dump a single object recursively into a string
+function util.dump_object(obj)
+ local dump = "<unknown>"
+ if type(obj) == "nil" then
+ dump = "nil"
+ elseif type(obj) == "number" then
+ dump = string.format("%d", obj)
+ elseif type(obj) == "string" then
+ local str = obj
+ str = string.gsub(str, "\\\\", "\\\\")
+ str = string.gsub(str, "\"", "\\\"")
+ str = string.gsub(str, "\r", "\\r")
+ str = string.gsub(str, "\n", "\\n")
+ str = string.gsub(str, ".",
+ function(c)
+ local n = string.byte(c)
+ if n < 32 or n >= 127 then
+ c = string.format("\\%03d", n)
+ end
+ return c
+ end
+ )
+ dump = "\"" .. str .. "\""
+ elseif type(obj) == "boolean" then
+ if obj then
+ dump = "true"
+ else
+ dump = "false"
+ end
+ elseif type(obj) == "table" then
+ dump = "{"
+ local first = true
+ for k, v in pairs(obj) do
+ if not first then
+ dump = dump .. ","
+ end
+ dump = dump .. " " .. util.dump_object(k) .. " = "
+ dump = dump .. util.dump_object(v)
+ first = false
+ end
+ dump = dump .. " }"
+ elseif type(obj) == "function" then
+ dump = "<function>"
+ elseif type(obj) == "thread" then
+ dump = "<thread>"
+ elseif type(obj) == "userdata" then
+ dump = "<userdata>"
+ end
+ return dump
+end
+
+-- CONVENIENCE FRONTEND:
+-- dump one or more objects recursively, one per line
+function util.dump(obj1, ...)
+ local dump = util.dump_object(obj1) .. "\n"
+ for _, obj in ipairs(arg) do
+ dump = dump .. util.dump_object(obj) .. "\n"
+ end
+ return dump
+end
+
+-- CONVENIENCE FRONTEND:
+-- dump one or more objects recursively, one per line, to stderr
+function util.dump_stderr(obj1, ...)
+ io.stderr:write(util.dump(obj1, unpack(arg)))
+end
+
@@ .
patch -p0 <<'@@ .'
Index: rpm/CHANGES
============================================================================
$ cvs diff -u -r1.2016 -r1.2017 CHANGES
--- rpm/CHANGES 24 Dec 2007 15:02:10 -0000 1.2016
+++ rpm/CHANGES 24 Dec 2007 15:12:56 -0000 1.2017
@@ -1,4 +1,5 @@
5.0b3 -> 5.0b4:
+ - rse: merge scripts/lua-dump.lua directly into lua/local/llocal.lua to make it always easily available
- rse: add local Lua functions util.rmatch() and util.rsubst() for regex matching/substitution
- rse: improve rex.new Lua object by using PCRE if possible and fallback to POSIX regex only
- rse: fix loading of "local" Lua extension: it has to come after the other extensions as uses them
@@ .
patch -p0 <<'@@ .'
Index: rpm/scripts/Makefile.am
============================================================================
$ cvs diff -u -r1.46 -r1.47 Makefile.am
--- rpm/scripts/Makefile.am 23 Dec 2007 22:50:05 -0000 1.46
+++ rpm/scripts/Makefile.am 24 Dec 2007 15:12:57 -0000 1.47
@@ -22,7 +22,7 @@
rpm.daily rpm.log rpm.xinetd \
rpmsort symset-table \
sql.prov sql.req symclash.py symclash.sh tcl.req tgpg trpm u_pkg.sh \
- vcheck lua-dump.lua vpkg-provides.sh vpkg-provides2.sh \
+ vcheck vpkg-provides.sh vpkg-provides2.sh \
macros.perl* macros.python* \
macros.php* find-*.php find-php-*
@@ .
rm -f rpm/scripts/lua-dump.lua <<'@@ .'
Index: rpm/scripts/lua-dump.lua
============================================================================
[NO CHANGE SUMMARY BECAUSE FILE AS A WHOLE IS JUST REMOVED]
@@ .
Received on Mon Dec 24 16:12:58 2007