From: Tobias Ulmer Date: Thu, 9 Aug 2012 08:29:31 +0000 (+0200) Subject: Remove the collections module X-Git-Tag: e2factory-2.3.13rc1~176 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=e71e198549a5f72a4048eb76ade97bcd47cc8ba7;p=e2factory.git Remove the collections module The single use of string.explode is replaced by an inline version of the same functionality. Signed-off-by: Tobias Ulmer --- diff --git a/generic/collection.lua b/generic/collection.lua deleted file mode 100644 index e0d30a7..0000000 --- a/generic/collection.lua +++ /dev/null @@ -1,202 +0,0 @@ ---[[ - e2factory, the emlix embedded build system - - Copyright (C) 2007-2009 Gordon Hecker , emlix GmbH - Copyright (C) 2007-2009 Oskar Schirmer , emlix GmbH - Copyright (C) 2007-2008 Felix Winkelmann, emlix GmbH - - For more information have a look at http://www.e2factory.org - - e2factory is a registered trademark by emlix GmbH. - - This file is part of e2factory, the emlix embedded build system. - - e2factory is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -]] - --- Topological sorting --- --- table.tsort(DAG) -> ARRAY --- --- Expects a table of tables as input, where each sub-table contains --- the node name followed by its dependencies, and returns a topologically --- sorted array of all entries. --- When DAG is cyclic, return nil - -function table.tsort(dag) - local sorted = {} - local adjust = {} - local colour = {} - local function visit(u, path) - local p = path - if p[u] then sorted = nil end - if sorted and not colour[u] then - local v = adjust[u] - colour[u] = true - if v then - p[u] = true - for i = 1, #v do visit(v[i], p) end - p[u] = nil - end - if sorted then table.insert(sorted, u) end - end - end - for i = 1, #dag do - local l = {} - for j = 2, #dag[i] do table.insert(l, dag[i][j]) end - adjust[dag[i][1]] = l - end - for i = 1, #dag do visit(dag[i][1], {}) end - return sorted -end - - --- Table operations --- --- table.reverse(TABLE) -> TABLE' --- --- Reverse array elements and return new table. --- --- table.map(TABLE, FUNCTION) -> TABLE' --- --- Map over table elements creating new table. FUNCTION is called for each --- table value and the result will be stored under the same key as the original --- value. --- --- table.filter(TABLE, FUNCTION) -> TABLE' --- --- Returns a new table with all elements from TABLE removed that do not --- satisfy the predicate FUNCTION. --- --- --- table.grep(TABLE, PATTERN) -> TABLE' --- --- Filter strings matching a pattern. --- --- table.print(TABLE, [OUT]) --- --- Prints table contents on OUT, which defaults to io.stdout. --- --- table.compare(TABLE1, TABLE2, [FUNCTION]) -> BOOL --- --- Compares tables element by element by passing each pair of elements --- to FUNCTION (which defaults to "function(x, y) return x == y end"). --- --- table.find(TABLE, VAL, [FUNCTION]) -> KEY, VAL --- --- Searches TABLE for an entry VAL and returns the key (and value). FUNCTION --- is the comparison function used to compare the values and defaults to --- "function(x, y) return x == y end". - -function table.reverse(t) - local t2 = {} - local len = #t - local j = 1 - for i = len, 1, -1 do - t2[ j ] = t[ i ] - j = j + 1 - end - return t2 -end - -function table.map(t, f) - local t2 = {} - for k, x in pairs(t) do - t2[ k ] = f(x) - end - return t2 -end - -function table.filter(t, f) - local t2 = {} - local i = 1 - for k, x in pairs(t) do - if f(x) then - t2[ i ] = x - i = i + 1 - end - end - return t2 -end - -function table.grep(t, p) - local function match(x) - return string.find(x, p) - end - return table.filter(t, match) -end - -function table.print(t, out) - local out = out or io.stdout - out:write(tostring(t), ":\n") - for k, v in pairs(t) do - print("", k, "->", v) - end -end - -function table.compare(t1, t2, p) - local p = p or function(x, y) return x == y end - if #t1 ~= #t2 then return false - else - for k, v in pairs(t1) do - local x = t2[ k ] - if not p(v, x) then return false end - end - return true - end -end - -function table.find(t, x, cmp) - cmp = cmp or function(x, y) return x == y end - for k, v in pairs(t) do - if cmp(v, x) then return k, v end - end - return nil -end - - --- String operations --- --- string.trim(STRING) -> STRING' --- --- Removes whitespace on both sides from string. --- --- string.explode(STRING) -> ARRAY --- --- Convert string into array of characters (one-element strings). --- --- string.split(STRING, PATTERN) -> ARRAY --- --- Split string into elements matching PATTERN. - -function string.trim(str) - return string.match(str, "^%s*(.*%S)%s*$") or "" -end - -function string.explode(str) - local t = {} - for i = 1, #str do - table.insert(t, string.sub(str, i, i)) - end - return t -end - -function string.split(str, pat) - local t = {} - pat = pat or "%S+" - for x in string.gmatch(str, pat) do - table.insert(t, x) - end - return t -end diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 3b0e944..b4105f6 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -1341,7 +1341,6 @@ function parse_e2versionfile(filename) filename) v.tag = match() or abort("invalid tag name `", l, "' in e2 version file ", filename) - --table.print(v) log(3, "using e2 branch " .. v.branch .. " tag " .. v.tag) return v end diff --git a/generic/e2option.lua b/generic/e2option.lua index e5af076..6be99cc 100644 --- a/generic/e2option.lua +++ b/generic/e2option.lua @@ -28,7 +28,6 @@ module("e2option", package.seeall) require("e2lib") require("e2util") -require("collection") local plugin = require("plugin") local err = require("err") @@ -322,7 +321,11 @@ function parse(args) end end else - local set = string.explode(opt) + local set = {} + for i = 1, string.len(opt) do + table.insert(set, string.sub(opt, i, i)) + end + for k, v in pairs(set) do if not options[ v ] then e2lib.abort(string.format("invalid option: %s\n".. diff --git a/global/Makefile b/global/Makefile index 74c7cc7..2f13db3 100644 --- a/global/Makefile +++ b/global/Makefile @@ -36,7 +36,7 @@ GLOBALLUATOOLS = e2-create-project e2-fetch-project e2-install-e2 e2-root GLOBALSHTOOLS = e2-locate-project-root e2ssh GLOBALTOOLS = $(GLOBALLUATOOLS) $(GLOBALSHTOOLS) CLEAN_FILES = *~ $(GLOBALTOOLS) *.lc e2 $(SCRIPTS) *.lua e2-su *.sh e2.conf -LUA_LIBS = strict.lua collection.lua plugin.lua e2lib.lua +LUA_LIBS = strict.lua plugin.lua e2lib.lua LUA_LIBS += e2option.lua hash.lua tools.lua transport.lua cache.lua url.lua LUA_LIBS += generic_git.lua luafile.lua err.lua lock.lua LUA_LIBS += buildconfig.lua diff --git a/local/Makefile b/local/Makefile index 2759212..005f237 100644 --- a/local/Makefile +++ b/local/Makefile @@ -46,7 +46,7 @@ LUA_LIBS = e2option.lua luafile.lua generic_git.lua err.lua LUA_LIBS += e2tool.lua scm.lua git.lua svn.lua cvs.lua files.lua LUA_LIBS += tools.lua transport.lua cache.lua LUA_LIBS += environment.lua plugin.lua url.lua hash.lua lock.lua -LUA_LIBS += policy.lua strict.lua collection.lua e2build.lua +LUA_LIBS += policy.lua strict.lua e2build.lua LUA_LIBS += e2lib.lua buildconfig.lua LOCALTOOLS = $(LOCALSHTOOLS) $(LOCALLUATOOLS) diff --git a/local/e2tool.lua b/local/e2tool.lua index b2124ec..43aaa08 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -32,7 +32,6 @@ module("e2tool", package.seeall) require("e2lib") require("strict") -require("collection") local err = require("err") require("scm") require("files")