20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
if val then return os.execute(cmd) else
local fd = io.popen(cmd,'r')
local t = fd:read('*a')
return chomp(t), fd:close()
end
end
local function dump(v,pfx)
pfx = pfx or ''
local np = pfx .. ' '
if type(v) == 'string' then
return string.format('%q', v)
elseif type(v) == 'table' then
local str = ''
for k,v in pairs(v) do
str = str .. string.format('%s[%s] = %s\n', np, dump(k,np), dump(v,np))
end
return '{\n' .. str .. pfx .. '}\n'
else
return string.format('%s', v)
end
end
local ping = function(path)
................................................................................
s = ({
yes = true, ['true'] = true, on = true, ['1'] = true;
no = false, ['false'] = false, off = false, ['0'] = false;
})[string.lower(s)]
if not s then return false end
return true
end
return {
exec = exec;
dump = dump;
ping = ping;
chomp = chomp;
map = map;
tobool = tobool;
append = function(a,b)
for _, v in pairs(b) do a[#a+1] = v end
end;
has = function(haystack,needle,eq)
eq = eq or function(a,b) return a == b end
for k,v in pairs(haystack) do
if eq(needle,v) then return k end
end
end;
parseargs = function(a)
local raw = false
local opts, args = {}, {}
for i,v in ipairs(a) do
if v == '--' then
raw = true
|
|
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
if val then return os.execute(cmd) else
local fd = io.popen(cmd,'r')
local t = fd:read('*a')
return chomp(t), fd:close()
end
end
local function dump(v,pfx,cyc)
pfx = pfx or ''
cyc = cyc or {}
local np = pfx .. ' '
if type(v) == 'table' then
if cyc[v] then return '<...>' else cyc[v] = true end
end
if type(v) == 'string' then
return string.format('%q', v)
elseif type(v) == 'table' then
local str = ''
for k,v in pairs(v) do
local tkey, tval = dump(k,np,cyc), dump(v,np,cyc)
str = str .. string.format('%s[%s] = %s\n', np, tkey,tval)
end
return '{\n' .. str .. pfx .. '}\n'
else
return string.format('%s', v)
end
end
local ping = function(path)
................................................................................
s = ({
yes = true, ['true'] = true, on = true, ['1'] = true;
no = false, ['false'] = false, off = false, ['0'] = false;
})[string.lower(s)]
if not s then return false end
return true
end
if ping '/dev/urandom' then
local r = io.open('/dev/urandom')
local ent = r:read(8) r:close()
local seed = 1 for i = 1, 8 do
seed = seed * string.byte(string.sub(ent,i,i))
end
math.randomseed(seed)
else math.randomseed(os.time()) end
return {
exec = exec;
dump = dump;
ping = ping;
chomp = chomp;
map = map;
tobool = tobool;
rndstr = function(len)
local s = ''
for i=1,len do
local ofs = math.random(0,10 + 26)
if ofs >= 10 then ofs = 0x60 + (ofs - 10)
else ofs = 0x30 + ofs end
s = s .. string.char(ofs)
end
return s
end;
append = function(a,b)
for _, v in pairs(b) do a[#a+1] = v end
end;
has = function(haystack,needle,eq)
eq = eq or function(a,b) return a == b end
for k,v in pairs(haystack) do
if eq(needle,v) then return k end
end
end;
ingest = function(f)
local h = io.open(f, 'r')
if h == nil then return nil end
local txt = f:read('*a') f:close()
return chomp(txt)
end;
parseargs = function(a)
local raw = false
local opts, args = {}, {}
for i,v in ipairs(a) do
if v == '--' then
raw = true
|