diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-15 15:26:37 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-15 15:26:37 +0000 |
commit | 3ec6ecb14b734ea40ee013d10909744e59dbdffa (patch) | |
tree | 21e5fc601258ca9f7c497b5bad9c9e1366f6a355 /src/rspamadm | |
parent | f2fbc6350aaf45330b9eb6f4e14fc55739c21cd4 (diff) | |
download | rspamd-3ec6ecb14b734ea40ee013d10909744e59dbdffa.tar.gz rspamd-3ec6ecb14b734ea40ee013d10909744e59dbdffa.zip |
Add getopt module
Diffstat (limited to 'src/rspamadm')
-rw-r--r-- | src/rspamadm/getopt.lua.in | 31 |
1 files changed, 31 insertions, 0 deletions
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 + |