review changes #1 (argument escaping and removing goto)

This commit is contained in:
mutlusun 2017-01-21 18:14:17 +01:00
parent 0bea7ffac6
commit fe0d762f11
3 changed files with 11 additions and 14 deletions

View File

@ -216,7 +216,7 @@ end
function helpers.sysctl_table(syspath)
return setmetatable({ _path = syspath },
{ __index = function(table, index)
local path = "sysctl -n " .. table._path .. "." .. index
local path = "sysctl -n " .. helpers.shellquote(table._path .. "." .. index)
local f = io.popen(path)
if f then
local s = f:read("*all")

View File

@ -3,6 +3,7 @@ local setmetatable = setmetatable
local tonumber = tonumber
local io = { popen = io.popen }
local math = { floor = math.floor }
local helpers = require("vicious.helpers")
local string = {
gmatch = string.gmatch,
gsub = string.gsub,
@ -15,7 +16,7 @@ local bat_freebsd = {}
local function worker(format, warg)
local battery = warg or "batt"
local bat_info = {}
local f = io.popen("acpiconf -i " .. battery)
local f = io.popen("acpiconf -i " .. helpers.shellquote(battery))
for line in f:lines("*line") do
for key,value in string.gmatch(line, "(.+):%s+(.+)") do
bat_info[key] = value

View File

@ -28,19 +28,15 @@ local function worker(format, warg)
local now = os.time()
for line in f:lines() do
if line:find("<Link") or line:find("Name ") then -- skipping missleading lines
goto continue
if not (line:find("<Link") or line:find("Name")) then -- skipping missleading lines
local split = { line:match(("([^%s]*)%s*"):rep(12)) }
if buffer == nil then
buffer = { tonumber(split[8]), tonumber(split[11]) } -- recv (field 8) and send (field 11)
else
buffer = { buffer[1] + tonumber(split[8]), buffer[2] + tonumber(split[11]) }
end
end
local split = { line:match(("([^%s]*)%s*"):rep(12)) }
if buffer == nil then
buffer = { tonumber(split[8]), tonumber(split[11]) } -- recv (field 8) and send (field 11)
else
buffer = { buffer[1] + tonumber(split[8]), buffer[2] + tonumber(split[11]) }
end
::continue::
end
f:close()