lualoader: Drop excessive parenthesizing
This was also a convenience convention (for me) that is not very lua-tic. Drop it. I've maintained some parentheses where I'd prefer them, for example, 'if x or y or (z and w) then', but these situations are far and few between.
This commit is contained in:
+33
-33
@@ -31,7 +31,7 @@ local config = require('config')
|
||||
local core = {}
|
||||
|
||||
local compose_loader_cmd = function(cmd_name, argstr)
|
||||
if (argstr ~= nil) then
|
||||
if argstr ~= nil then
|
||||
cmd_name = cmd_name .. " " .. argstr
|
||||
end
|
||||
return cmd_name
|
||||
@@ -43,23 +43,23 @@ end
|
||||
-- This will also parse arguments to autoboot, but the with_kernel argument
|
||||
-- will need to be explicitly overwritten to false
|
||||
local parse_boot_args = function(argv, with_kernel)
|
||||
if (#argv == 0) then
|
||||
if #argv == 0 then
|
||||
return nil, ""
|
||||
end
|
||||
if (with_kernel == nil) then
|
||||
if with_kernel == nil then
|
||||
with_kernel = true
|
||||
end
|
||||
local kernel_name
|
||||
local argstr = ""
|
||||
|
||||
for k, v in ipairs(argv) do
|
||||
if (with_kernel) and (v:sub(1,1) ~= "-") then
|
||||
if with_kernel and v:sub(1,1) ~= "-" then
|
||||
kernel_name = v
|
||||
else
|
||||
argstr = argstr .. " " .. v
|
||||
end
|
||||
end
|
||||
if (with_kernel) then
|
||||
if with_kernel then
|
||||
return kernel_name, argstr
|
||||
else
|
||||
return argstr
|
||||
@@ -72,7 +72,7 @@ function boot(...)
|
||||
local cmd_name = ""
|
||||
cmd_name, argv = core.popFrontTable(argv)
|
||||
local kernel, argstr = parse_boot_args(argv)
|
||||
if (kernel ~= nil) then
|
||||
if kernel ~= nil then
|
||||
loader.perform("unload")
|
||||
config.selectkernel(kernel)
|
||||
end
|
||||
@@ -102,11 +102,11 @@ core.MENU_SUBMENU = "submenu"
|
||||
core.MENU_CAROUSEL_ENTRY = "carousel_entry"
|
||||
|
||||
function core.setVerbose(b)
|
||||
if (b == nil) then
|
||||
if b == nil then
|
||||
b = not core.verbose
|
||||
end
|
||||
|
||||
if (b == true) then
|
||||
if b == true then
|
||||
loader.setenv("boot_verbose", "YES")
|
||||
else
|
||||
loader.unsetenv("boot_verbose")
|
||||
@@ -115,11 +115,11 @@ function core.setVerbose(b)
|
||||
end
|
||||
|
||||
function core.setSingleUser(b)
|
||||
if (b == nil) then
|
||||
if b == nil then
|
||||
b = not core.su
|
||||
end
|
||||
|
||||
if (b == true) then
|
||||
if b == true then
|
||||
loader.setenv("boot_single", "YES")
|
||||
else
|
||||
loader.unsetenv("boot_single")
|
||||
@@ -130,23 +130,23 @@ end
|
||||
function core.getACPIPresent(checkingSystemDefaults)
|
||||
local c = loader.getenv("hint.acpi.0.rsdp")
|
||||
|
||||
if (c ~= nil) then
|
||||
if (checkingSystemDefaults == true) then
|
||||
if c ~= nil then
|
||||
if checkingSystemDefaults == true then
|
||||
return true
|
||||
end
|
||||
-- Otherwise, respect disabled if it's set
|
||||
c = loader.getenv("hint.acpi.0.disabled")
|
||||
return (c == nil) or (tonumber(c) ~= 1)
|
||||
return c == nil or tonumber(c) ~= 1
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function core.setACPI(b)
|
||||
if (b == nil) then
|
||||
if b == nil then
|
||||
b = not core.acpi
|
||||
end
|
||||
|
||||
if (b == true) then
|
||||
if b == true then
|
||||
loader.setenv("acpi_load", "YES")
|
||||
loader.setenv("hint.acpi.0.disabled", "0")
|
||||
loader.unsetenv("loader.acpi_disabled_by_user")
|
||||
@@ -159,10 +159,10 @@ function core.setACPI(b)
|
||||
end
|
||||
|
||||
function core.setSafeMode(b)
|
||||
if (b == nil) then
|
||||
if b == nil then
|
||||
b = not core.sm
|
||||
end
|
||||
if (b == true) then
|
||||
if b == true then
|
||||
loader.setenv("kern.smp.disabled", "1")
|
||||
loader.setenv("hw.ata.ata_dma", "0")
|
||||
loader.setenv("hw.ata.atapi_dma", "0")
|
||||
@@ -189,14 +189,14 @@ function core.kernelList()
|
||||
local kernels = {}
|
||||
local unique = {}
|
||||
local i = 0
|
||||
if (k ~= nil) then
|
||||
if k ~= nil then
|
||||
i = i + 1
|
||||
kernels[i] = k
|
||||
unique[k] = true
|
||||
end
|
||||
|
||||
for n in v:gmatch("([^; ]+)[; ]?") do
|
||||
if (unique[n] == nil) then
|
||||
if unique[n] == nil then
|
||||
i = i + 1
|
||||
kernels[i] = n
|
||||
unique[n] = true
|
||||
@@ -209,19 +209,19 @@ function core.kernelList()
|
||||
for file in lfs.dir("/boot") do
|
||||
local fname = "/boot/" .. file
|
||||
|
||||
if (file == "." or file == "..") then
|
||||
if file == "." or file == ".." then
|
||||
goto continue
|
||||
end
|
||||
|
||||
if (lfs.attributes(fname, "mode") ~= "directory") then
|
||||
if lfs.attributes(fname, "mode") ~= "directory" then
|
||||
goto continue
|
||||
end
|
||||
|
||||
if (lfs.attributes(fname .. "/kernel", "mode") ~= "file") then
|
||||
if lfs.attributes(fname .. "/kernel", "mode") ~= "file" then
|
||||
goto continue
|
||||
end
|
||||
|
||||
if (unique[file] == nil) then
|
||||
if unique[file] == nil then
|
||||
i = i + 1
|
||||
kernels[i] = file
|
||||
unique[file] = true
|
||||
@@ -257,33 +257,33 @@ end
|
||||
function core.isSerialBoot()
|
||||
local c = loader.getenv("console")
|
||||
|
||||
if (c ~= nil) then
|
||||
if (c:find("comconsole") ~= nil) then
|
||||
if c ~= nil then
|
||||
if c:find("comconsole") ~= nil then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local s = loader.getenv("boot_serial")
|
||||
if (s ~= nil) then
|
||||
if s ~= nil then
|
||||
return true
|
||||
end
|
||||
|
||||
local m = loader.getenv("boot_multicons")
|
||||
if (m ~= nil) then
|
||||
if m ~= nil then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function core.isSystem386()
|
||||
return (loader.machine_arch == "i386")
|
||||
return loader.machine_arch == "i386"
|
||||
end
|
||||
|
||||
-- This may be a better candidate for a 'utility' module.
|
||||
function core.shallowCopyTable(tbl)
|
||||
local new_tbl = {}
|
||||
for k, v in pairs(tbl) do
|
||||
if (type(v) == "table") then
|
||||
if type(v) == "table" then
|
||||
new_tbl[k] = core.shallowCopyTable(v)
|
||||
else
|
||||
new_tbl[k] = v
|
||||
@@ -297,9 +297,9 @@ end
|
||||
-- for our uses
|
||||
function core.popFrontTable(tbl)
|
||||
-- Shouldn't reasonably happen
|
||||
if (#tbl == 0) then
|
||||
if #tbl == 0 then
|
||||
return nil, nil
|
||||
elseif (#tbl == 1) then
|
||||
elseif #tbl == 1 then
|
||||
return tbl[1], {}
|
||||
end
|
||||
|
||||
@@ -307,7 +307,7 @@ function core.popFrontTable(tbl)
|
||||
local new_tbl = {}
|
||||
-- This is not a cheap operation
|
||||
for k, v in ipairs(tbl) do
|
||||
if (k > 1) then
|
||||
if k > 1 then
|
||||
new_tbl[k - 1] = v
|
||||
end
|
||||
end
|
||||
@@ -319,7 +319,7 @@ end
|
||||
-- generally be set upon execution of the kernel. Because of this, we can't (or
|
||||
-- don't really want to) detect/disable ACPI on !i386 reliably. Just set it
|
||||
-- enabled if we detect it and leave well enough alone if we don't.
|
||||
if (core.isSystem386()) and (core.getACPIPresent(false)) then
|
||||
if core.isSystem386() and core.getACPIPresent(false) then
|
||||
core.setACPI(true)
|
||||
end
|
||||
return core
|
||||
|
||||
Reference in New Issue
Block a user