diff --git a/src/net/torvald/terrarum/StateVTTest.kt b/src/net/torvald/terrarum/StateVTTest.kt index e7f6cc88b..fe7e25a49 100644 --- a/src/net/torvald/terrarum/StateVTTest.kt +++ b/src/net/torvald/terrarum/StateVTTest.kt @@ -22,7 +22,7 @@ class StateVTTest : BasicGameState() { // HiRes: 100x64, LoRes: 80x25 val computerInside = BaseTerrarumComputer(8) val vt = SimpleTextTerminal(SimpleTextTerminal.WHITE, 80, 25, - computerInside, colour = false, hires = false) + computerInside, colour = true, hires = false) val vtUI = Image(vt.displayW, vt.displayH) diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 6ed9358fb..b195dccc4 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -100,14 +100,14 @@ constructor(gamename: String) : StateBasedGame(gamename) { gc.graphics.clear() // clean up any 'dust' in the buffer - addState(StateVTTest()) + //addState(StateVTTest()) //addState(StateTestingSandbox()) //addState(StateSplash()) //addState(StateMonitorCheck()) //addState(StateFontTester()) - //ingame = StateInGame() - //addState(ingame) + ingame = StateInGame() + addState(ingame) } companion object { diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/dsh.lua b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/dsh.lua index 6cd94acd9..3c75c4abb 100755 --- a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/dsh.lua +++ b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/dsh.lua @@ -30,7 +30,7 @@ local function endsWithSlash(p) return p:byte(#p) == 47 end -__DSHDEBUG__ = 0x51621D +--__DSHDEBUG__ = 0x51621D local function debug(msg) if __DSHDEBUG__ then print("DEBUG", msg) end @@ -55,32 +55,29 @@ local function cd(tArgs) -- parse dir by delimeter '/' if (dir:byte(1) == 47) then -- if dir begins with '/' - os.workingDir = {""} - end + os.setWorkingDir(dir) + else + for word in string.gmatch(dir, "[^/]+") do - for word in string.gmatch(dir, "[^/]+") do - -- 'execute' directory - -- Rules: '..' pops os.workingDir - -- if dir begins with '/', re-build os.workingDir - -- otherwise, push the 'word' to os.workingDir - if (word == "..") then - if (#os.workingDir > 1) then - os.workingDir[#os.workingDir] = nil -- pops an element to oblivion - else + machine.println("CD word: "..word) + + -- 'execute' directory + -- Rules: '..' pops os.workingDir + -- if dir begins with '/', re-build os.workingDir + -- otherwise, push the 'word' to os.workingDir + if (word == "..") then + os.popWorkingDir() + elseif (word == ".") then -- pass + else + os.pushWorkingDir(word) end - elseif (word == ".") then - -- pass - else - table.insert(os.workingDir, word) end end - - -- check if the directory exists if not fs.isDir(os.fullWorkPath()) then os.errorNoSuchFileOrDir("cd: "..dir) - os.workingDir = oldWorkingDir + os.workingDir = shallowCopy(oldWorkingDir) return end end diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/lessismore.lua b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/lessismore.lua index 3e08e310b..df511f43d 100755 --- a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/lessismore.lua +++ b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/lessismore.lua @@ -31,8 +31,8 @@ local function printUsage() end if args[1] == nil or #args[1] <= 0 then printUsage() return end -if not fs.exists(args[1]) then os.errorNoSuchFileOrDir(args[1]) return end -if not fs.isFile(args[1]) then os.errorIsDir(args[1]) return end +filepath = os.expandPath(args[1]) +if not fs.isFile(filepath) then os.errorNoSuchFile(filepath) return end function log10(n) if n < 1 then return 0 @@ -55,7 +55,7 @@ end lines = {} displayHeight = term.height() - 1 -- bottom one line for prompt -local file = fs.open(args[1], "r") +local file = fs.open(filepath, "r") local line = "" repeat line = file.readLine() diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/ls.lua b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/ls.lua new file mode 100644 index 000000000..83655db98 --- /dev/null +++ b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/ls.lua @@ -0,0 +1,10 @@ +local args = {...} + +local dir = os.fullWorkPath()--(#args < 1) and os.fullWorkPath() or args[1] + +local list = fs.list("/"..dir) +table.sort(list) + +for _, v in ipairs(list) do + print(v) +end \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/msh.lua b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/bin/msh.lua old mode 100644 new mode 100755 diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/boot/efi b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/boot/efi old mode 100644 new mode 100755 diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/etc/.dshrc b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/etc/.dshrc old mode 100644 new mode 100755 index 573a78722..2b702dee7 --- a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/etc/.dshrc +++ b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/etc/.dshrc @@ -1,8 +1,8 @@ -- dsh aliases os.dshenv.aliases = { - lua = "exec msh", + lua = "msh", sh = "dsh", - shutdown = "exit", - less = "exec lessismore", - more = "exec lessismore" + shutdown = "exit", -- should be a separate program that actually halts the system + less = "lessismore", + more = "lessismore" } \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/etc/_boot.lua b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/etc/_boot.lua index fcd777760..5aad2b2ae 100755 --- a/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/etc/_boot.lua +++ b/src/net/torvald/terrarum/virtualcomputer/assets/loots/dummix/etc/_boot.lua @@ -23,10 +23,61 @@ end if not _G.os then _G.os = {} end os.version = "0.0" os.EXIT_SUCCESS = 0 -os.workingDir = {"", "home"} -- index 1 must be ""! +os.workingDir = {"home"} os.path = "home/bin/;/usr/bin/;/bin/" -- infamous $path os.fullWorkPath = function() - return table.concat(os.workingDir, "/") + local ret = table.concat(os.workingDir, "/") -- there's nothing wrong with this. + + if computer.verbose then + machine.println("workingDir size: "..#os.workingDir) + machine.println("fullWorkPath: "..ret) + end + return ret +end +os.setWorkingDir = function(s) + if s:byte(#s) == 47 then + s = string.sub(s, 1, #s - 1) + end + if s:byte(1) == 47 then + s = string.sub(s, 2, #s) + end + + if computer.verbose then + machine.println("renew working dir; '"..s.."'") + end + + local oldWorkingDir = {table.unpack(os.workingDir)} + + -- renew working directory, EVEN IF s STARTS WITH '/' + local t = {} + for word in string.gmatch(s, "[^/]+") do + table.insert(t, word) + end + + os.workingDir = t + + -- check if the directory exists + if not fs.isDir(s) then + os.errorNoSuchFileOrDir("cd: "..s) + os.workingDir = oldWorkingDir + return + end +end +os.pushWorkingDir = function(s) + if (s == "..") then + error("cannot push '..' to working directory.") + else + table.insert(os.workingDir, s) + + if computer.verbose then + machine.println("pushing '"..s.."' to working directory.") + end + end +end +os.popWorkingDir = function() + if (#os.workingDir > 1) then + table.remove(os.workingDir) + end end -- @param "path/of/arbitrary" -- @return /working/dir/path/of/arbitrary diff --git a/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt b/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt index 15ccf09f8..94ac875ff 100644 --- a/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt +++ b/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt @@ -139,6 +139,8 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) { override fun call(path: LuaValue) : LuaValue { Filesystem.ensurePathSanity(path) + println("ListFiles: got path ${path.checkIBM437()}") + val table = LuaTable() val file = File(computer.getRealPath(path)).absoluteFile try { @@ -162,7 +164,10 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) { override fun call(path: LuaValue) : LuaValue { Filesystem.ensurePathSanity(path) - return LuaValue.valueOf(Files.isDirectory(Paths.get(computer.getRealPath(path)).toAbsolutePath())) + val isDir = Files.isDirectory(Paths.get(computer.getRealPath(path)).toAbsolutePath()) + val exists = Files.exists(Paths.get(computer.getRealPath(path)).toAbsolutePath()) + + return LuaValue.valueOf(isDir || exists) } }