Nmap Development mailing list archives
Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July)
From: Patrick Donnelly <batrick () batbytes com>
Date: Fri, 20 Jul 2012 10:54:32 -0400
On Thu, Jul 19, 2012 at 7:08 PM, David Fifield <david () bamsoftware com> wrote:
I can deal with the field names being lower-case and identifier-like; maybe people will even prefer them that way. But the fact that "md5" and "sha1" are not on adjacent lines is galling. Maybe a special kind of table format that keeps order (i.e., an array of name-value pairs)? That would seem to require a higher-level function with which to set output values.
You can get an ordered dictionary in Lua with some metamethod magic:
local table = require "table"
function ordered_new ()
local t = {}
local reverse = {}
local order = {}
local function iterator ()
for i, key in ipairs(order) do
coroutine.yield(key, t[key])
end
end
local mt = {
__newindex = function (t, k, v)
if reverse[k] then
rawset(t, k, v)
if v == nil then
table.remove(order, reverse[k])
reverse[k] = nil
end
else
table.insert(order, k)
reverse[k] = #order
rawset(t, k, v)
end
end,
__pairs = function (t)
return coroutine.wrap(iterator)
end,
}
return setmetatable(t, mt)
end
local test = ordered_new()
test.a = 1
test.b = 2
test[1] = 4
test.foo = 3
for k,v in pairs(test) do
print(k,v)
end
prints:
a 1
b 2
1 4
foo 3
--
- Patrick Donnelly
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/
Current thread:
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 19)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 19)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) Patrick Donnelly (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) Patrick Donnelly (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 20)
- Re: XML structured script output (storing results per script instance) David Fifield (Jul 31)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Jul 31)
- Re: XML structured script output (storing results per script instance) David Fifield (Jul 31)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Aug 01)
- Re: XML structured script output (storing results per script instance) Daniel Miller (Aug 01)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Aug 01)
- Re: XML structured script output (storing results per script instance) Daniel Miller (Aug 02)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Jul 31)
