From owner-svn-src-head@freebsd.org Sat Mar 24 04:03:56 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8EC25F682EE; Sat, 24 Mar 2018 04:03:56 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3C84F76431; Sat, 24 Mar 2018 04:03:56 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 35C8219D2; Sat, 24 Mar 2018 04:03:56 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w2O43uCC053692; Sat, 24 Mar 2018 04:03:56 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2O43uNT053691; Sat, 24 Mar 2018 04:03:56 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201803240403.w2O43uNT053691@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 24 Mar 2018 04:03:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r331477 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 331477 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Mar 2018 04:03:56 -0000 Author: kevans Date: Sat Mar 24 04:03:55 2018 New Revision: 331477 URL: https://svnweb.freebsd.org/changeset/base/331477 Log: lualoader: Privatize some more config.lua bits These functions are also not quite suitable for a public API, so privatize them to config. Modified: head/stand/lua/config.lua Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Sat Mar 24 04:00:01 2018 (r331476) +++ head/stand/lua/config.lua Sat Mar 24 04:03:55 2018 (r331477) @@ -92,6 +92,16 @@ local function setEnv(key, value) return loader.setenv(key, value) end +-- name here is one of 'name', 'type', flags', 'before', 'after', or 'error.' +-- These are set from lines in loader.conf(5): ${key}_${name}="${value}" where +-- ${key} is a module name. +local function setKey(key, name, value) + if modules[key] == nil then + modules[key] = {} + end + modules[key][name] = value +end + local pattern_table = { { str = "^%s*(#.*)", @@ -111,42 +121,42 @@ local pattern_table = { { str = "^%s*([%w_]+)_name%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) - config.setKey(k, "name", v) + setKey(k, "name", v) end, }, -- module_type="value" { str = "^%s*([%w_]+)_type%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) - config.setKey(k, "type", v) + setKey(k, "type", v) end, }, -- module_flags="value" { str = "^%s*([%w_]+)_flags%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) - config.setKey(k, "flags", v) + setKey(k, "flags", v) end, }, -- module_before="value" { str = "^%s*([%w_]+)_before%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) - config.setKey(k, "before", v) + setKey(k, "before", v) end, }, -- module_after="value" { str = "^%s*([%w_]+)_after%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) - config.setKey(k, "after", v) + setKey(k, "after", v) end, }, -- module_error="value" { str = "^%s*([%w_]+)_error%s*=%s*\"([%w%s%p]-)\"%s*(.*)", process = function(k, v) - config.setKey(k, "error", v) + setKey(k, "error", v) end, }, -- exec="command" @@ -178,6 +188,73 @@ local pattern_table = { }, } +local function isValidComment(line) + if line ~= nil then + local s = line:match("^%s*#.*") + if s == nil then + s = line:match("^%s*$") + end + if s == nil then + return false + end + end + return true +end + +local function loadModule(mod, silent) + local status = true + local pstatus + 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 + pstatus = cli_execute_unparsed(v.before) == 0 + if not pstatus and not silent then + print(MSG_FAILEXBEF:format(v.before, k)) + end + status = status and pstatus + end + + if cli_execute_unparsed(str) ~= 0 then + if not silent then + print(MSG_FAILEXMOD:format(str)) + end + if v.error ~= nil then + cli_execute_unparsed(v.error) + end + status = false + end + + if v.after ~= nil then + pstatus = cli_execute_unparsed(v.after) == 0 + if not pstatus and not silent then + print(MSG_FAILEXAF:format(v.after, k)) + end + status = status and pstatus + end + +-- else +-- if not silent then +-- print("Skipping module '". . k .. "'") +-- end + end + end + + return status +end + + local function readFile(name, silent) local f = io.open(name) if f == nil then @@ -252,82 +329,6 @@ function config.setCarouselIndex(id, idx) carousel_choices[id] = idx end --- name here is one of 'name', 'type', flags', 'before', 'after', or 'error.' --- These are set from lines in loader.conf(5): ${key}_${name}="${value}" where --- ${key} is a module name. -function config.setKey(key, name, value) - if modules[key] == nil then - modules[key] = {} - end - modules[key][name] = value -end - -function config.isValidComment(line) - if line ~= nil then - local s = line:match("^%s*#.*") - if s == nil then - s = line:match("^%s*$") - end - if s == nil then - return false - end - end - return true -end - -function config.loadmod(mod, silent) - local status = true - local pstatus - 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 - pstatus = cli_execute_unparsed(v.before) == 0 - if not pstatus and not silent then - print(MSG_FAILEXBEF:format(v.before, k)) - end - status = status and pstatus - end - - if cli_execute_unparsed(str) ~= 0 then - if not silent then - print(MSG_FAILEXMOD:format(str)) - end - if v.error ~= nil then - cli_execute_unparsed(v.error) - end - status = false - end - - if v.after ~= nil then - pstatus = cli_execute_unparsed(v.after) == 0 - if not pstatus and not silent then - print(MSG_FAILEXAF:format(v.after, k)) - end - status = status and pstatus - end - --- else --- if not silent then --- print("Skipping module '". . k .. "'") --- end - end - end - - return status -end - -- Returns true if we processed the file successfully, false if we did not. -- If 'silent' is true, being unable to read the file is not considered a -- failure. @@ -358,7 +359,7 @@ function config.parse(text) if k ~= nil then found = true - if config.isValidComment(c) then + if isValidComment(c) then val.process(k, v) else print(MSG_MALFORMED:format(n, @@ -520,7 +521,7 @@ function config.loadelf() end print(MSG_MODLOADING) - if not config.loadmod(modules, not config.verbose) then + if not loadModule(modules, not config.verbose) then print(MSG_MODLOADFAIL) end end