parsav  Diff

Differences From Artifact [9dc63595c4]:

To Artifact [3d397d42e6]:


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