Date: Fri, 11 Jul 2014 21:26:54 GMT From: pedrosouza@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r270732 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua Message-ID: <201407112126.s6BLQsa7098531@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pedrosouza Date: Fri Jul 11 21:26:54 2014 New Revision: 270732 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=270732 Log: WIP: config.lua Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua Fri Jul 11 19:40:50 2014 (r270731) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua Fri Jul 11 21:26:54 2014 (r270732) @@ -1,15 +1,67 @@ config = {}; +modules = {}; + +function config.setKey(k, n, v) + if modules[k] == nil then + modules[k] = {}; + end + modules[k][n] = v; +end pattern_table = { - [1] = {str = "^%s*(#.*)", process = function(k, v) print("Processed(comment) -> "..k.."\n"); end }, - [2] = {str = "^%s*([%w_]+)_load%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) print("Processed(load) -> "..k..":"..v.."\n"); end }, --module_load="value" - [3] = {str = "^%s*([%w_]+)_name%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) print("Processed(name) -> "..k..":"..v.."\n"); end }, --module_name="value" - [4] = {str = "^%s*([%w_]+)_type%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) print("Processed(type) -> "..k..":"..v.."\n"); end }, --module_type="value" - [5] = {str = "^%s*([%w_]+)_flags%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) print("Processed(flags) -> "..k..":"..v.."\n"); end }, --module_flags="value" - [6] = {str = "^%s*([%w_]+)_before%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) print("Processed(before) -> "..k..":"..v.."\n"); end }, --module_before="value" - [7] = {str = "^%s*([%w_]+)_after%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) print("Processed(after) -> "..k..":"..v.."\n"); end }, --module_after="value" - [8] = {str = "^%s*([%w_]+)_error%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) print("Processed(error) -> "..k..":"..v.."\n"); end }, --module_error="value" - [9] = {str = "^%s*([%w%p]+)%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) print("Processed(environment) -> "..k..":"..v.."\n"); end } --env_var="value" + [1] = {str = "^%s*(#.*)", process = function(k, v) end }, +-- module_load="value" + [2] = {str = "^%s*([%w_]+)_load%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + process = function(k, v) + if modules[k] == nil then + modules[k] = {}; + end + modules[k].load = string.upper(v); + end }, +-- module_name="value" + [3] = {str = "^%s*([%w_]+)_name%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + process = function(k, v) + config.setKey(k, "name", v); + end }, +-- module_type="value" + [4] = {str = "^%s*([%w_]+)_type%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + process = function(k, v) + config.setKey(k, "type", v); + end }, +-- module_flags="value" + [5] = {str = "^%s*([%w_]+)_flags%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + process = function(k, v) + config.setKey(k, "flags", v); + end }, +-- module_before="value" + [6] = {str = "^%s*([%w_]+)_before%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + process = function(k, v) + config.setKey(k, "before", v); + end }, +-- module_after="value" + [7] = {str = "^%s*([%w_]+)_after%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + process = function(k, v) + config.setKey(k, "after", v); + end }, +-- module_error="value" + [8] = {str = "^%s*([%w_]+)_error%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + process = function(k, v) + config.setKey(k, "error", v); + end }, +-- exec="command" + [9] = {str = "^%s*exec%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + process = function(k, v) + if loader.perform(k) ~= 0 then + print("Failed to exec '"..k.."'"); + end + end }, +-- env_var="value" + [10] = {str = "^%s*([%w%p]+)%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + process = function(k, v) + if loader.perform("set "..k.."="..v) ~= 0 then + print("Failed to set '"..k.."' with value: "..v); + end + end } }; function config.isValidComment(c) @@ -21,7 +73,40 @@ return true; end -function config.load(name) +function config.loadmod(mod) + for k, v in pairs(mod) do + if v.load == "YES" then + local str = "load "; + if v.flags ~= nil then str = str .. v.flags .. " "; end + if v.type ~= nil then str = str .. "-t " .. v.type .. " "; end + if v.name ~= nil then str = str .. v.name; else str = str .. k; end + + if v.before ~= nil then + if loader.perform(v.before) ~= 0 then + print("Failed to execute '"..v.before.."' before loading '"..k.."'\n"); + end + end + + if loader.perform(str) ~= 0 then + print("Failed to execute '" .. str .. "'\n"); + if v.error ~= nil then + loader.perform(v.error); + end + end + + if v.after ~= nil then + if loader.perform(v.after) ~= 0 then + print("Failed to execute '"..v.after.."' after loading '"..k.."'\n"); + end + end + + else + print("Skiping module '".. k .. "'\n"); + end + end +end + +function config.parse(name) local f = io.open(name); if f == nil then print("Failed to open config : " .. name);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407112126.s6BLQsa7098531>