From 3ec6ecb14b734ea40ee013d10909744e59dbdffa Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 15 Dec 2015 15:26:37 +0000 Subject: Add getopt module --- src/rspamadm/getopt.lua.in | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/rspamadm/getopt.lua.in (limited to 'src/rspamadm') diff --git a/src/rspamadm/getopt.lua.in b/src/rspamadm/getopt.lua.in new file mode 100644 index 000000000..d069d2d5f --- /dev/null +++ b/src/rspamadm/getopt.lua.in @@ -0,0 +1,31 @@ +local function getopt(arg, options) + local tab = {} + for k, v in ipairs(arg) do + if string.sub(v, 1, 2) == "--" then + local x = string.find(v, "=", 1, true) + if x then tab[string.sub(v, 3, x - 1)] = string.sub(v, x + 1) + else tab[string.sub(v, 3)] = true + end + elseif string.sub(v, 1, 1) == "-" then + local y = 2 + local l = string.len(v) + local jopt + while (y <= l) do + jopt = string.sub(v, y, y) + if string.find(options, jopt, 1, true) then + if y < l then + tab[jopt] = string.sub(v, y + 1) + y = l + else + tab[jopt] = arg[k + 1] + end + else + tab[jopt] = true + end + y = y + 1 + end + end + end + return tab +end + -- cgit v1.2.3