Date: Tue, 5 Aug 2014 18:34:47 GMT From: pedrosouza@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271945 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua Message-ID: <201408051834.s75IYlYN080851@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pedrosouza Date: Tue Aug 5 18:34:47 2014 New Revision: 271945 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271945 Log: Improved lua code style, added boot options menu shortcuts Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua Tue Aug 5 17:39:58 2014 (r271944) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua Tue Aug 5 18:34:47 2014 (r271945) @@ -9,59 +9,80 @@ end pattern_table = { - [1] = {str = "^%s*(#.*)", process = function(k, v) end }, + [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] = {}; + [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 - 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 }, + [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 }, + [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 }, + [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 }, + [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 }, + [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 }, + [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.."'\n"); + [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.."'\n"); + end 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.."\n"); + [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.."\n"); + end end - end } + } }; function config.isValidComment(c) @@ -84,7 +105,9 @@ if v.before ~= nil then if loader.perform(v.before) ~= 0 then - if not silent then print("Failed to execute '"..v.before.."' before loading '"..k.."'\n"); end + if not silent then + print("Failed to execute '"..v.before.."' before loading '"..k.."'\n"); + end status = false; end end @@ -99,7 +122,9 @@ if v.after ~= nil then if loader.perform(v.after) ~= 0 then - if not silent then print("Failed to execute '"..v.after.."' after loading '"..k.."'\n"); end + if not silent then + print("Failed to execute '"..v.after.."' after loading '"..k.."'\n"); + end status = false; end end @@ -236,12 +261,16 @@ if not file then file = "/boot/defaults/loader.conf"; end - if not config.parse(file) then print("Failed to parse configuration: '"..file.."'\n"); end + if not config.parse(file) then + print("Failed to parse configuration: '"..file.."'\n"); + end local f = loader.getenv("loader_conf_files"); if f ~= nil then for name in string.gmatch(f, "([%w%p]+)%s*") do - if not config.parse(name) then print("Failed to parse configuration: '"..name.."'\n"); end + if not config.parse(name) then + print("Failed to parse configuration: '"..name.."'\n"); + end end end Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua Tue Aug 5 17:39:58 2014 (r271944) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua Tue Aug 5 18:34:47 2014 (r271945) @@ -81,21 +81,41 @@ menu.options = { -- Boot multi user - ["1"] = {index = 1, name = color.highlight("B").."oot Multi user", func = function () core.setSingleUser(false); loader.perform("boot"); end}, + ["1"] = { + index = 1, + name = "Boot Multi user "..color.highlight("[Enter]"), + func = function () core.setSingleUser(false); loader.perform("boot"); end + }, -- boot single user - ["2"] = {index = 2, name = "Boot "..color.highlight("S").."ingle user", func = function () core.setSingleUser(true); loader.perform("boot"); end}, + ["2"] = { + index = 2, + name = "Boot "..color.highlight("S").."ingle user", + func = function () core.setSingleUser(true); loader.perform("boot"); end + }, -- escape to interpreter - ["3"] = {index = 3, name = color.highlight("E").."scape to lua interpreter", func = function () return true; end}, + ["3"] = { + index = 3, + name = color.highlight("Esc").."ape to lua interpreter", + func = function () return true; end + }, -- reboot - ["4"] = {index = 4, name = color.highlight("R").."eboot", func = function () loader.perform("reboot"); end}, + ["4"] = { + index = 4, + name = color.highlight("R").."eboot", + func = function () loader.perform("reboot"); end + }, -- boot options - ["5"] = {index = 5, name = "Boot "..color.highlight("O").."ptions", func = function () menu.run(boot_options); return false; end} + ["5"] = { + index = 5, + name = "Boot "..color.highlight("O").."ptions", + func = function () menu.run(boot_options); return false; end + } }; menu.options.alias = { - ["b"] = menu.options["1"], + ["\013"] = menu.options["1"], ["s"] = menu.options["2"], - ["e"] = menu.options["3"], + ["\027"] = menu.options["3"], ["r"] = menu.options["4"], ["o"] = menu.options["5"] }; @@ -109,10 +129,51 @@ end boot_options = { - ["1"] = {index = 1, name = "Back to menu", func = function () return true; end }, - ["2"] = {index = 2, name = "Load System defaults", func = function () core.setDefaults(); return false; end }, - ["3"] = {index = 3, getName = function () return OnOff("ACPI :", core.acpi); end, func = function () core.setACPI(); return false; end }, - ["4"] = {index = 4, getName = function () return OnOff("Safe Mode :", core.sm); end, func = function () core.setSafeMode(); return false; end }, - ["5"] = {index = 5, getName = function () return OnOff("Single user:", core.su); end, func = function () core.setSingleUser(); return false; end }, - ["6"] = {index = 6, getName = function () return OnOff("Verbose :", core.verbose); end, func = function () core.setVerbose(); return false; end } -} \ No newline at end of file + ["1"] = { + index = 1, + name = "Back to menu"..color.highlight(" [Backspace]"), + func = function () return true; end + }, + ["2"] = { + index = 2, + name = "Load System "..color.highlight("D").."efaults", + func = function () core.setDefaults(); return false; end + }, + ["3"] = { + index = 3, + getName = function () + return OnOff(color.highlight("A").."CPI :", core.acpi); + end, + func = function () core.setACPI(); return false; end + }, + ["4"] = { + index = 4, + getName = function () + return OnOff("Safe "..color.highlight("M").."ode :", core.sm); + end, + func = function () core.setSafeMode(); return false; end + }, + ["5"] = { + index = 5, + getName = function () + return OnOff(color.highlight("S").."ingle user:", core.su); + end, + func = function () core.setSingleUser(); return false; end + }, + ["6"] = { + index = 6, + getName = function () + return OnOff(color.highlight("V").."erbose :", core.verbose); + end, + func = function () core.setVerbose(); return false; end + } +} + +boot_options.alias = { + ["\08"] = boot_options["1"], + ["d"] = boot_options["2"], + ["a"] = boot_options["3"], + ["m"] = boot_options["4"], + ["s"] = boot_options["5"], + ["v"] = boot_options["6"] +}; \ No newline at end of file
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408051834.s75IYlYN080851>
