-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/magik6k/OpenComputers int…
…o master-MC1.7.10
- Loading branch information
Showing
81 changed files
with
8,179 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/resources/assets/opencomputers/loot/Plan9k/bin/arp.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
local network = require "network" | ||
|
||
local function fillText(text, n) | ||
for k = 1, n - #text do | ||
text = text .. " " | ||
end | ||
return text | ||
end | ||
|
||
local maxlen = {8, 5} | ||
|
||
for interface in pairs(network.info.getInfo().interfaces) do | ||
maxlen[2] = maxlen[2] < #interface+1 and #interface+1 or maxlen[2] | ||
for _, host in ipairs(network.info.getArpTable(interface)) do | ||
maxlen[1] = maxlen[1] < #host+1 and #host+1 or maxlen[1] | ||
end | ||
end | ||
|
||
print(fillText("Address", maxlen[1])..fillText("Iface", maxlen[2])) | ||
|
||
for interface in pairs(network.info.getInfo().interfaces) do | ||
for _, host in ipairs(network.info.getArpTable(interface)) do | ||
print(fillText(host, maxlen[1])..fillText(interface, maxlen[2])) | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
src/main/resources/assets/opencomputers/loot/Plan9k/bin/cat.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
local args = {...} | ||
if #args == 0 then | ||
repeat | ||
local read = require("term").read() | ||
if read then | ||
io.write(read) | ||
end | ||
until not read | ||
else | ||
for i = 1, #args do | ||
local file, reason = io.open(args[i]) | ||
if not file then | ||
io.stderr:write(reason .. "\n") | ||
return | ||
end | ||
repeat | ||
local line = file:read("*L") | ||
if line then | ||
io.write(line) | ||
end | ||
until not line | ||
file:close() | ||
io.write("\n") | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/opencomputers/loot/Plan9k/bin/clear.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
local term = require("term") | ||
|
||
term.clear() |
52 changes: 52 additions & 0 deletions
52
src/main/resources/assets/opencomputers/loot/Plan9k/bin/components.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
local component = require("component") | ||
local shell = require("shell") | ||
local text = require("text") | ||
|
||
local args, options = shell.parse(...) | ||
local count = tonumber(options.limit) or math.huge | ||
|
||
local components = {} | ||
local padTo = 1 | ||
|
||
if #args == 0 then -- get all components if no filters given. | ||
args[1] = "" | ||
end | ||
for _, filter in ipairs(args) do | ||
for address, name in component.list(filter) do | ||
if name:len() > padTo then | ||
padTo = name:len() + 2 | ||
end | ||
components[address] = name | ||
end | ||
end | ||
|
||
padTo = padTo + 8 - padTo % 8 | ||
for address, name in pairs(components) do | ||
io.write(text.padRight(name, padTo) .. address .. '\n') | ||
|
||
if options.l then | ||
local proxy = component.proxy(address) | ||
local padTo = 1 | ||
local methods = {} | ||
for name, member in pairs(proxy) do | ||
if type(member) == "table" or type(member) == "function" then | ||
if name:len() > padTo then | ||
padTo = name:len() + 2 | ||
end | ||
table.insert(methods, name) | ||
end | ||
end | ||
table.sort(methods) | ||
padTo = padTo + 8 - padTo % 8 | ||
|
||
for _, name in ipairs(methods) do | ||
local doc = tostring(proxy[name]) | ||
io.write(" " .. text.padRight(name, padTo) .. doc .. '\n') | ||
end | ||
end | ||
|
||
count = count - 1 | ||
if count <= 0 then | ||
break | ||
end | ||
end |
140 changes: 140 additions & 0 deletions
140
src/main/resources/assets/opencomputers/loot/Plan9k/bin/cp.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
local fs = require("filesystem") | ||
local shell = require("shell") | ||
|
||
local args, options = shell.parse(...) | ||
if #args < 2 then | ||
io.write("Usage: cp [-inrv] <from...> <to>\n") | ||
io.write(" -i: prompt before overwrite (overrides -n option).\n") | ||
io.write(" -n: do not overwrite an existing file.\n") | ||
io.write(" -r: copy directories recursively.\n") | ||
io.write(" -u: copy only when the SOURCE file differs from the destination\n") | ||
io.write(" file or when the destination file is missing.\n") | ||
io.write(" -v: verbose output.\n") | ||
io.write(" -x: stay on original source file system.") | ||
return | ||
end | ||
|
||
local from = {} | ||
for i = 1, #args - 1 do | ||
table.insert(from, fs.resolve(args[i])) | ||
end | ||
local to = fs.resolve(args[#args]) | ||
|
||
local function status(from, to) | ||
if options.v then | ||
io.write(from .. " -> " .. to .. "\n") | ||
end | ||
os.sleep(0) -- allow interrupting | ||
end | ||
|
||
local result, reason | ||
|
||
local function prompt(message) | ||
io.write(message .. " [Y/n]\n") | ||
local result = io.read() | ||
return result and (result == "" or result:sub(1, 1):lower() == "y") | ||
end | ||
|
||
local function areEqual(path1, path2) | ||
local f1 = io.open(path1, "rb") | ||
if not f1 then | ||
return nil, "could not open `" .. path1 .. "' for update test" | ||
end | ||
local f2 = io.open(path2, "rb") | ||
if not f2 then | ||
f1:close() | ||
return nil, "could not open `" .. path2 .. "' for update test" | ||
end | ||
local result = true | ||
local chunkSize = 4 * 1024 | ||
repeat | ||
local s1, s2 = f1:read(chunkSize), f2:read(chunkSize) | ||
if s1 ~= s2 then | ||
result = false | ||
break | ||
end | ||
until not s1 or not s2 | ||
f1:close() | ||
f2:close() | ||
return result | ||
end | ||
|
||
local function isMount(path) | ||
path = fs.canonical(path) | ||
for _, mountPath in fs.mounts() do | ||
if path == fs.canonical(mountPath) then | ||
return true | ||
end | ||
end | ||
end | ||
|
||
local function recurse(fromPath, toPath) | ||
status(fromPath, toPath) | ||
if fs.isDirectory(fromPath) then | ||
if not options.r then | ||
io.write("omitting directory `" .. fromPath .. "'\n") | ||
return true | ||
end | ||
if fs.canonical(fromPath) == fs.canonical(fs.path(toPath)) then | ||
return nil, "cannot copy a directory, `" .. fromPath .. "', into itself, `" .. toPath .. "'\n" | ||
end | ||
if fs.exists(toPath) and not fs.isDirectory(toPath) then | ||
-- my real cp always does this, even with -f, -n or -i. | ||
return nil, "cannot overwrite non-directory `" .. toPath .. "' with directory `" .. fromPath .. "'" | ||
end | ||
if options.x and isMount(fromPath) then | ||
return true | ||
end | ||
fs.makeDirectory(toPath) | ||
for file in fs.list(fromPath) do | ||
local result, reason = recurse(fs.concat(fromPath, file), fs.concat(toPath, file)) | ||
if not result then | ||
return nil, reason | ||
end | ||
end | ||
return true | ||
else | ||
if fs.exists(toPath) then | ||
if fs.canonical(fromPath) == fs.canonical(toPath) then | ||
return nil, "`" .. fromPath .. "' and `" .. toPath .. "' are the same file" | ||
end | ||
if fs.isDirectory(toPath) then | ||
if options.i then | ||
if not prompt("overwrite `" .. toPath .. "'?") then | ||
return true | ||
end | ||
elseif options.n then | ||
return true | ||
else -- yes, even for -f | ||
return nil, "cannot overwrite directory `" .. toPath .. "' with non-directory" | ||
end | ||
else | ||
if options.u then | ||
if areEqual(fromPath, toPath) then | ||
return true | ||
end | ||
end | ||
if options.i then | ||
if not prompt("overwrite `" .. toPath .. "'?") then | ||
return true | ||
end | ||
elseif options.n then | ||
return true | ||
end | ||
-- else: default to overwriting | ||
end | ||
fs.remove(toPath) | ||
end | ||
return fs.copy(fromPath, toPath) | ||
end | ||
end | ||
for _, fromPath in ipairs(from) do | ||
local toPath = to | ||
if fs.isDirectory(toPath) then | ||
toPath = fs.concat(toPath, fs.name(fromPath)) | ||
end | ||
result, reason = recurse(fromPath, toPath) | ||
if not result then | ||
error(reason, 0) | ||
end | ||
end |
76 changes: 76 additions & 0 deletions
76
src/main/resources/assets/opencomputers/loot/Plan9k/bin/dd.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
local shell = require "shell" | ||
local filesystem = require "filesystem" | ||
|
||
local args = {...} | ||
local options = {} | ||
options.count = math.huge | ||
options.bs = 1 | ||
options["if"] = "-" | ||
options.of = "-" | ||
|
||
for _, arg in pairs(args) do | ||
local k, v = arg:match("(%w+)=(.+)") | ||
if not k then | ||
print("Ilegal argument: " .. arg) | ||
return | ||
end | ||
options[k] = v | ||
end | ||
|
||
if type(options.count) == "string" then options.count = tonumber(options.count) or math.huge end | ||
if type(options.bs) == "string" then options.bs = tonumber(options.bs) or 1 end | ||
|
||
local reader | ||
local writer | ||
|
||
if options["if"] == "-" then | ||
reader = { | ||
read = io.read, | ||
close = function()end | ||
} | ||
else | ||
local inHnd = filesystem.open(options["if"], "r") | ||
reader = { | ||
read = function(...)return inHnd:read(...)end, | ||
close = function()inHnd:close()end | ||
} | ||
end | ||
|
||
if options.of == "-" then | ||
io.output():setvbuf("full", options.bs) | ||
writer = { | ||
write = function(data)return io.write(data) end, | ||
close = function()io.output():setvbuf("no")end | ||
} | ||
else | ||
local outHnd = filesystem.open(options.of, "w") | ||
writer = { | ||
write = function(...)return outHnd:write(...)end, | ||
close = function()outHnd:close()end | ||
} | ||
end | ||
|
||
local start = computer.uptime() | ||
local dcount = 0 | ||
|
||
for n = 1, options.count do | ||
local data = reader.read(options.bs) | ||
if not data then | ||
print("End of input") | ||
break | ||
end | ||
local wrote = writer.write(data) | ||
dcount = dcount + (wrote and options.bs or 0) | ||
if not wrote then | ||
print("Output full") | ||
break | ||
end | ||
end | ||
|
||
local time = computer.uptime() - start | ||
|
||
reader.close() | ||
writer.close() | ||
|
||
print(dcount .. " bytes (" .. (dcount / 1024) .. " KB) copied, " .. time .. "s, " .. (dcount / time / 1024) .. " KB/s") | ||
|
71 changes: 71 additions & 0 deletions
71
src/main/resources/assets/opencomputers/loot/Plan9k/bin/df.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
local fs = require("filesystem") | ||
local shell = require("shell") | ||
local text = require("text") | ||
|
||
local args, options = shell.parse(...) | ||
|
||
local function formatSize(size) | ||
if not options.h then | ||
return tostring(size) | ||
end | ||
local sizes = {"", "K", "M", "G"} | ||
local unit = 1 | ||
local power = options.si and 1000 or 1024 | ||
while size > power and unit < #sizes do | ||
unit = unit + 1 | ||
size = size / power | ||
end | ||
return math.floor(size * 10) / 10 .. sizes[unit] | ||
end | ||
|
||
local mounts = {} | ||
if #args == 0 then | ||
for proxy, path in fs.mounts() do | ||
mounts[path] = proxy | ||
end | ||
else | ||
for i = 1, #args do | ||
local proxy, path = fs.get(args[i]) | ||
if not proxy then | ||
io.stderr:write(args[i], ": no such file or directory\n") | ||
else | ||
mounts[path] = proxy | ||
end | ||
end | ||
end | ||
|
||
local result = {{"Filesystem", "Used", "Available", "Use%", "Mounted on"}} | ||
for path, proxy in pairs(mounts) do | ||
local label = proxy.getLabel() or proxy.address | ||
local used, total = proxy.spaceUsed(), proxy.spaceTotal() | ||
local available, percent | ||
if total == math.huge then | ||
used = used or "N/A" | ||
available = "unlimited" | ||
percent = "0%" | ||
else | ||
available = total - used | ||
percent = used / total | ||
if percent ~= percent then -- NaN | ||
available = "N/A" | ||
percent = "N/A" | ||
else | ||
percent = math.ceil(percent * 100) .. "%" | ||
end | ||
end | ||
table.insert(result, {label, formatSize(used), formatSize(available), tostring(percent), path}) | ||
end | ||
|
||
local m = {} | ||
for _, row in ipairs(result) do | ||
for col, value in ipairs(row) do | ||
m[col] = math.max(m[col] or 1, value:len()) | ||
end | ||
end | ||
|
||
for _, row in ipairs(result) do | ||
for col, value in ipairs(row) do | ||
io.write(text.padRight(value, m[col] + 2)) | ||
end | ||
io.write("\n") | ||
end |
Oops, something went wrong.