lualoader: Refactor config line expressions
A couple of issues addressed: 1.) Modules with - in the name were not recognized as modules 2.) The module regex was repeated for each place a module name may appear 3.) The 'strip leading space' bits were repeated for each expression 4.) The trailing 'comment validation' stuff was repeated every expression #4 still has some more work to be done. exec lines, for instance, don't capture a 'value' -- there's only one capture pattern. This throws off the 'c' value that we match, so the trailing bits aren't *actually* being validated. This isn't a new issue, though, so a future comit will address this.
This commit is contained in:
parent
b83a355d70
commit
058c692e15
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=338168
@ -54,6 +54,8 @@ local MSG_KERNLOADING = "Loading kernel..."
|
|||||||
local MSG_MODLOADING = "Loading configured modules..."
|
local MSG_MODLOADING = "Loading configured modules..."
|
||||||
local MSG_MODLOADFAIL = "Could not load one or more modules!"
|
local MSG_MODLOADFAIL = "Could not load one or more modules!"
|
||||||
|
|
||||||
|
local MODULEEXPR = '([%w-_]+)'
|
||||||
|
|
||||||
local function restoreEnv()
|
local function restoreEnv()
|
||||||
-- Examine changed environment variables
|
-- Examine changed environment variables
|
||||||
for k, v in pairs(env_changed) do
|
for k, v in pairs(env_changed) do
|
||||||
@ -121,14 +123,19 @@ local function processEnvVar(value)
|
|||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- str in this table is a regex pattern. It will automatically be anchored to
|
||||||
|
-- the beginning of a line and any preceding whitespace will be skipped. The
|
||||||
|
-- pattern should have no more than two captures patterns, which correspond to
|
||||||
|
-- the two parameters (usually 'key' and 'value') that are passed to the
|
||||||
|
-- process function. All trailing characters will be validated.
|
||||||
local pattern_table = {
|
local pattern_table = {
|
||||||
{
|
{
|
||||||
str = "^%s*(#.*)",
|
str = "(#.*)",
|
||||||
process = function(_, _) end,
|
process = function(_, _) end,
|
||||||
},
|
},
|
||||||
-- module_load="value"
|
-- module_load="value"
|
||||||
{
|
{
|
||||||
str = "^%s*([%w_]+)_load%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
|
str = MODULEEXPR .. "_load%s*=%s*\"([%w%s%p]-)\"",
|
||||||
process = function(k, v)
|
process = function(k, v)
|
||||||
if modules[k] == nil then
|
if modules[k] == nil then
|
||||||
modules[k] = {}
|
modules[k] = {}
|
||||||
@ -138,49 +145,49 @@ local pattern_table = {
|
|||||||
},
|
},
|
||||||
-- module_name="value"
|
-- module_name="value"
|
||||||
{
|
{
|
||||||
str = "^%s*([%w_]+)_name%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
|
str = MODULEEXPR .. "_name%s*=%s*\"([%w%s%p]-)\"",
|
||||||
process = function(k, v)
|
process = function(k, v)
|
||||||
setKey(k, "name", v)
|
setKey(k, "name", v)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- module_type="value"
|
-- module_type="value"
|
||||||
{
|
{
|
||||||
str = "^%s*([%w_]+)_type%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
|
str = MODULEEXPR .. "_type%s*=%s*\"([%w%s%p]-)\"",
|
||||||
process = function(k, v)
|
process = function(k, v)
|
||||||
setKey(k, "type", v)
|
setKey(k, "type", v)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- module_flags="value"
|
-- module_flags="value"
|
||||||
{
|
{
|
||||||
str = "^%s*([%w_]+)_flags%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
|
str = MODULEEXPR .. "_flags%s*=%s*\"([%w%s%p]-)\"",
|
||||||
process = function(k, v)
|
process = function(k, v)
|
||||||
setKey(k, "flags", v)
|
setKey(k, "flags", v)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- module_before="value"
|
-- module_before="value"
|
||||||
{
|
{
|
||||||
str = "^%s*([%w_]+)_before%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
|
str = MODULEEXPR .. "_before%s*=%s*\"([%w%s%p]-)\"",
|
||||||
process = function(k, v)
|
process = function(k, v)
|
||||||
setKey(k, "before", v)
|
setKey(k, "before", v)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- module_after="value"
|
-- module_after="value"
|
||||||
{
|
{
|
||||||
str = "^%s*([%w_]+)_after%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
|
str = MODULEEXPR .. "_after%s*=%s*\"([%w%s%p]-)\"",
|
||||||
process = function(k, v)
|
process = function(k, v)
|
||||||
setKey(k, "after", v)
|
setKey(k, "after", v)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- module_error="value"
|
-- module_error="value"
|
||||||
{
|
{
|
||||||
str = "^%s*([%w_]+)_error%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
|
str = MODULEEXPR .. "_error%s*=%s*\"([%w%s%p]-)\"",
|
||||||
process = function(k, v)
|
process = function(k, v)
|
||||||
setKey(k, "error", v)
|
setKey(k, "error", v)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
-- exec="command"
|
-- exec="command"
|
||||||
{
|
{
|
||||||
str = "^%s*exec%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
|
str = "exec%s*=%s*\"([%w%s%p]-)\"",
|
||||||
process = function(k, _)
|
process = function(k, _)
|
||||||
if cli_execute_unparsed(k) ~= 0 then
|
if cli_execute_unparsed(k) ~= 0 then
|
||||||
print(MSG_FAILEXEC:format(k))
|
print(MSG_FAILEXEC:format(k))
|
||||||
@ -189,7 +196,7 @@ local pattern_table = {
|
|||||||
},
|
},
|
||||||
-- env_var="value"
|
-- env_var="value"
|
||||||
{
|
{
|
||||||
str = "^%s*([%w%p]+)%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
|
str = "([%w%p]+)%s*=%s*\"([%w%s%p]-)\"",
|
||||||
process = function(k, v)
|
process = function(k, v)
|
||||||
if setEnv(k, processEnvVar(v)) ~= 0 then
|
if setEnv(k, processEnvVar(v)) ~= 0 then
|
||||||
print(MSG_FAILSETENV:format(k, v))
|
print(MSG_FAILSETENV:format(k, v))
|
||||||
@ -198,7 +205,7 @@ local pattern_table = {
|
|||||||
},
|
},
|
||||||
-- env_var=num
|
-- env_var=num
|
||||||
{
|
{
|
||||||
str = "^%s*([%w%p]+)%s*=%s*(-?%d+)%s*(.*)",
|
str = "([%w%p]+)%s*=%s*(-?%d+)",
|
||||||
process = function(k, v)
|
process = function(k, v)
|
||||||
if setEnv(k, processEnvVar(v)) ~= 0 then
|
if setEnv(k, processEnvVar(v)) ~= 0 then
|
||||||
print(MSG_FAILSETENV:format(k, tostring(v)))
|
print(MSG_FAILSETENV:format(k, tostring(v)))
|
||||||
@ -390,7 +397,8 @@ function config.parse(text)
|
|||||||
local found = false
|
local found = false
|
||||||
|
|
||||||
for _, val in ipairs(pattern_table) do
|
for _, val in ipairs(pattern_table) do
|
||||||
local k, v, c = line:match(val.str)
|
local pattern = '^%s*' .. val.str .. '%s*(.*)';
|
||||||
|
local k, v, c = line:match(pattern)
|
||||||
if k ~= nil then
|
if k ~= nil then
|
||||||
found = true
|
found = true
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user