diff --git a/wish-sys/sys-part/bin/cat.js b/wish-sys/sys-part/bin/cat.js index b33e187..b4210c3 100644 --- a/wish-sys/sys-part/bin/cat.js +++ b/wish-sys/sys-part/bin/cat.js @@ -3,43 +3,43 @@ var CatClass = function() { CatClass.prototype = new Process(); CatClass.prototype.buffer = new Array(); CatClass.prototype.stream; +CatClass.prototype.index = 0; CatClass.prototype.main = function(args) { - - this.files['stdout'].write("not ready yet"); - this.exit(0); - + console.log("cat: started"); + console.log("cat: checking for input stream"); if (args.length == 1) { - this.stream = this.files['stdin']; + console.log("cat: found stdin"); + this.file = this.files['stdin']; } else { - this.stream = new AppStream(); var env = this.Environment; var name = args[1]; if (name.substring(0, 1) != "/") - name = env.array['PWD'] + name; + name = env.array['PWD'] + "/" + name; name = Kernel.Filesystem.shortenPath(name); + console.log("cat: found " + name); var file = new File(name); if ((!name) || (!file.exists())) { this.files['stdout'].write("cat: " + name.replace("\033", "\\033") + ": No such file or directory\n"); this.exit(1); } - this.stream.fromFile(file); + this.file = file; } Kernel.Scheduler.add(this); } CatClass.prototype.tick = function() { var stdout = this.files['stdout']; - var code = this.stream.read(); - if (code) { - if (KeyCodes.isEnter(code)) { - stdout.write(this.buffer.join("") + "\n"); + var text = this.file.read(200, this.index); + for (var i = 0; i < text.length; i++) { + if (KeyCodes.isEnter(text.charCodeAt(i)) || (text.charAt(i) == "\n")) { + stdout.write(this.buffer.join("")); this.buffer = new Array(); - } else { - this.buffer.push(KeyCodes.normalKey(code)); } - if (this.stream.eof) { - stdout.write(this.buffer.join("") + "\n"); + if (text.charAt(i) == EOF) { + stdout.write(this.buffer.join("")); + this.buffer = new Array(); this.exit(0); } - } else { - } + this.buffer.push(text.charAt(i)); + } + this.index += 100; } diff --git a/wish-sys/sys-part/bin/wsh.js b/wish-sys/sys-part/bin/wsh.js index ffb38de..9518b6a 100644 --- a/wish-sys/sys-part/bin/wsh.js +++ b/wish-sys/sys-part/bin/wsh.js @@ -24,7 +24,7 @@ WshClass.prototype.tick = function() { stdout.write("Welcome to WishOS 0.1 (WOSKernel 0.1)\n\n"); console.log("wsh: loading profile"); var prof = new File("/etc/profile.d/env.json"); - var array = JSON.parse(prof.read()); + var array = JSON.parse(prof.read().replace(EOF, "")); prof.close(); for (var i = 0; i < array.length; i++) { while(array[i][1].indexOf("\\033") != -1) @@ -57,6 +57,7 @@ WshClass.prototype.tick = function() { break; case 2: var char = stdin.read(1); + char = char.replace(EOF, ""); if (!char.length) break; var code = char.charCodeAt(0); @@ -208,9 +209,9 @@ WshClass.prototype.parseLine = function() { prog.files['stdin'] = this.files['stdin']; prog.files['stdout'] = this.files['stdout']; prog.Environment = this.Environment; - console.log("wsh: program startet: " + file); + console.log("wsh: program start: " + file); prog.main(params); - + console.log("wsh: main shut down"); } WshClass.prototype.tryFile = function(name) { var file = new File(name); diff --git a/wish-sys/sys-part/kernel0.9.js b/wish-sys/sys-part/kernel0.9.js index 68ae692..592d37e 100644 --- a/wish-sys/sys-part/kernel0.9.js +++ b/wish-sys/sys-part/kernel0.9.js @@ -39,6 +39,9 @@ const MODE_APPND = 4; const MODE_THROW = 5; const MODE_CREATE = 6; +// special chars +const EOF = String.fromCharCode(26); + var OS = function() { } OS.system; @@ -461,6 +464,7 @@ InnerFile.prototype.permissions = PERM_GR | PERM_UW | PERM_UR; InnerFile.prototype.parent; // id InnerFile.prototype.mountPoint; InnerFile.prototype.removeReaded = false; +InnerFile.prototype.neverEnds = false; InnerFile.prototype.content = ""; InnerFile.prototype.created = 0; InnerFile.prototype.changed = 0; @@ -520,6 +524,8 @@ Kernel.Filesystem.initCon = function() { Kernel.msgSuccess(true); } Kernel.Filesystem.shortenPath = function(path) { + while (path.indexOf("//") != -1) + path = path.replace("//", "/"); if (path == "/") return "/"; if (path.substring(path.length - 1) == "/") @@ -529,7 +535,7 @@ Kernel.Filesystem.shortenPath = function(path) { var parts = path.split("/"); for (var i = 0; i < parts.length; i++) { if (!parts[i]) - throw("format error"); + throw("format error: " + path); if (parts[i].length == 0) { parts.splice(0, i); i = 0; @@ -588,15 +594,21 @@ Kernel.Filesystem.read = function(path, length, index, readMode) { if (length !== undefined) { if (index !== undefined) { text = content.substring(index, length + index); + if ((text.length < length) && (!file.neverEnds)) + text += EOF; if (file.removeReaded) content = content.substring(length + index); } else { text = content.substring(0, length); + if ((text.length < length) && (!file.neverEnds)) + text += EOF; if (file.removeReaded) content = content.substring(length); } } else { text = content; + if (!file.neverEnds) + text += EOF; if (file.removeReaded) content = ""; } @@ -808,6 +820,7 @@ Kernel.Filesystem.devfs.populate = function() { return false; } tty.removeReaded = true; + tty.neverEnds = true; tty.onRead = function () { var tmp = Kernel.IO.input(); for (var i = 0; i < tmp.length; i++) { @@ -841,7 +854,6 @@ Kernel.Filesystem.basefs.getRootStructure = function() { console.log("Filesystem: trying to get " + Kernel.Filesystem.basefs.baseURL + "/* recursive"); Emulator.Request.get(Kernel.Filesystem.basefs.baseURL + "/lib/kernel/files.php", "getStructure&dir=" + encodeURIComponent(Kernel.Filesystem.basefs.baseURL), true, function(content) { if (typeof content == "string") { - Kernel.Filesystem.basefs.files = Kernel.Filesystem.basefs.interpretFile(JSON.parse(content), NO_PARENT, NO_MOUNTPOINT); // not mounted yet Kernel.next(); return; diff --git a/wish-sys/sys-part/sbin/init.js b/wish-sys/sys-part/sbin/init.js index 6652367..c5c437d 100644 --- a/wish-sys/sys-part/sbin/init.js +++ b/wish-sys/sys-part/sbin/init.js @@ -51,7 +51,9 @@ InitClass.prototype.tick = function() { Emulator.output("\nloading /etc/inittab.json ..."); var file = new File("/etc/inittab.json"); this.files[file.path] = file; - this.inittab = JSON.parse(file.read()); + file = file.read(); + file = file.replace(EOF, ""); + this.inittab = JSON.parse(file); break; case 1: this.state++; diff --git a/wish-sys/sys-part/sbin/login.js b/wish-sys/sys-part/sbin/login.js index 0ebf9a4..d79021a 100644 --- a/wish-sys/sys-part/sbin/login.js +++ b/wish-sys/sys-part/sbin/login.js @@ -35,6 +35,7 @@ LoginClass.prototype.tick = function() { break; case 2: var char = stdin.read(1); + char = char.replace(EOF, ""); if (!(char.length)) break; var code = (new String(char)).charCodeAt(0); @@ -59,6 +60,7 @@ LoginClass.prototype.tick = function() { break; case 4: var char = stdin.read(1); + char = char.replace(EOF, ""); if (!char.length) break; var code = (new String(char)).charCodeAt(0); @@ -79,7 +81,7 @@ LoginClass.prototype.tick = function() { this.username = this.username.join(""); this.cpassword = Sha256.hash(this.password.join("")); var file = new File("/etc/passwd.json"); - this.users = JSON.parse(file.read()); + this.users = JSON.parse(file.read().replace(EOF, "")); file.close(); this.state++; break;