From 9afeb024d17a036934405aa4c6d8727e39652130 Mon Sep 17 00:00:00 2001 From: Robert Gadzerfraud Date: Thu, 24 Apr 2014 18:37:37 -0600 Subject: [PATCH 1/2] Modify option parsing to ignore - and --, add support for equal sign --- .../resources/assets/opencomputers/lua/rom/init.lua | 2 +- .../assets/opencomputers/lua/rom/lib/shell.lua | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/resources/assets/opencomputers/lua/rom/init.lua b/src/main/resources/assets/opencomputers/lua/rom/init.lua index 99afa57f3..e6e7417fd 100644 --- a/src/main/resources/assets/opencomputers/lua/rom/init.lua +++ b/src/main/resources/assets/opencomputers/lua/rom/init.lua @@ -11,7 +11,7 @@ computer.pushSignal("init") -- so libs know components are initialized. while true do require("term").clear() io.write(_OSVERSION .. " (" .. math.floor(computer.totalMemory() / 1024) .. "k RAM)\n") - local result, reason = os.execute(os.getenv("SHELL") .. " -") + local result, reason = os.execute(os.getenv("SHELL")) if not result then io.stderr:write((tostring(reason) or "unknown error") .. "\n") print("Press any key to continue.") diff --git a/src/main/resources/assets/opencomputers/lua/rom/lib/shell.lua b/src/main/resources/assets/opencomputers/lua/rom/lib/shell.lua index a8b0c20d6..0669b43e7 100644 --- a/src/main/resources/assets/opencomputers/lua/rom/lib/shell.lua +++ b/src/main/resources/assets/opencomputers/lua/rom/lib/shell.lua @@ -152,9 +152,13 @@ function shell.parse(...) local options = {} for i = 1, params.n do local param = params[i] - if type(param) == "string" and unicode.sub(param, 1, 2) == "--" then - options[unicode.sub(param, 3)] = true - elseif type(param) == "string" and unicode.sub(param, 1, 1) == "-" then + if type(param) == "string" and unicode.sub(param, 1, 2) == "--" and param ~= "--" then + if param:match("%-%-(.-)=") ~= nil then + options[param:match("%-%-(.-)=")] = param:match("=(.*)") + else + options[unicode.sub(param, 3)] = true + end + elseif type(param) == "string" and unicode.sub(param, 1, 1) == "-" and param ~= "--" and param ~= "-" then for j = 2, unicode.len(param) do options[unicode.sub(param, j, j)] = true end From 501e82411db1de1b3617c5f44551d3ca6c254457 Mon Sep 17 00:00:00 2001 From: Robert Gadzerfraud Date: Thu, 24 Apr 2014 18:39:27 -0600 Subject: [PATCH 2/2] convert indentation to spaces --- .../resources/assets/opencomputers/lua/rom/lib/shell.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/assets/opencomputers/lua/rom/lib/shell.lua b/src/main/resources/assets/opencomputers/lua/rom/lib/shell.lua index 0669b43e7..c07df9ddd 100644 --- a/src/main/resources/assets/opencomputers/lua/rom/lib/shell.lua +++ b/src/main/resources/assets/opencomputers/lua/rom/lib/shell.lua @@ -153,11 +153,11 @@ function shell.parse(...) for i = 1, params.n do local param = params[i] if type(param) == "string" and unicode.sub(param, 1, 2) == "--" and param ~= "--" then - if param:match("%-%-(.-)=") ~= nil then - options[param:match("%-%-(.-)=")] = param:match("=(.*)") - else + if param:match("%-%-(.-)=") ~= nil then + options[param:match("%-%-(.-)=")] = param:match("=(.*)") + else options[unicode.sub(param, 3)] = true - end + end elseif type(param) == "string" and unicode.sub(param, 1, 1) == "-" and param ~= "--" and param ~= "-" then for j = 2, unicode.len(param) do options[unicode.sub(param, j, j)] = true