mirror of
https://github.com/sigmasternchen/Wish
synced 2025-03-15 15:38:54 +00:00
new cat, some changes in file-system and consequenses
This commit is contained in:
parent
af997c65c5
commit
249d953f3f
5 changed files with 42 additions and 25 deletions
|
@ -3,43 +3,43 @@ var CatClass = function() {
|
||||||
CatClass.prototype = new Process();
|
CatClass.prototype = new Process();
|
||||||
CatClass.prototype.buffer = new Array();
|
CatClass.prototype.buffer = new Array();
|
||||||
CatClass.prototype.stream;
|
CatClass.prototype.stream;
|
||||||
|
CatClass.prototype.index = 0;
|
||||||
CatClass.prototype.main = function(args) {
|
CatClass.prototype.main = function(args) {
|
||||||
|
console.log("cat: started");
|
||||||
this.files['stdout'].write("not ready yet");
|
console.log("cat: checking for input stream");
|
||||||
this.exit(0);
|
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
this.stream = this.files['stdin'];
|
console.log("cat: found stdin");
|
||||||
|
this.file = this.files['stdin'];
|
||||||
} else {
|
} else {
|
||||||
this.stream = new AppStream();
|
|
||||||
var env = this.Environment;
|
var env = this.Environment;
|
||||||
var name = args[1];
|
var name = args[1];
|
||||||
if (name.substring(0, 1) != "/")
|
if (name.substring(0, 1) != "/")
|
||||||
name = env.array['PWD'] + name;
|
name = env.array['PWD'] + "/" + name;
|
||||||
name = Kernel.Filesystem.shortenPath(name);
|
name = Kernel.Filesystem.shortenPath(name);
|
||||||
|
console.log("cat: found " + name);
|
||||||
var file = new File(name);
|
var file = new File(name);
|
||||||
if ((!name) || (!file.exists())) {
|
if ((!name) || (!file.exists())) {
|
||||||
this.files['stdout'].write("cat: " + name.replace("\033", "\\033") + ": No such file or directory\n");
|
this.files['stdout'].write("cat: " + name.replace("\033", "\\033") + ": No such file or directory\n");
|
||||||
this.exit(1);
|
this.exit(1);
|
||||||
}
|
}
|
||||||
this.stream.fromFile(file);
|
this.file = file;
|
||||||
}
|
}
|
||||||
Kernel.Scheduler.add(this);
|
Kernel.Scheduler.add(this);
|
||||||
}
|
}
|
||||||
CatClass.prototype.tick = function() {
|
CatClass.prototype.tick = function() {
|
||||||
var stdout = this.files['stdout'];
|
var stdout = this.files['stdout'];
|
||||||
var code = this.stream.read();
|
var text = this.file.read(200, this.index);
|
||||||
if (code) {
|
for (var i = 0; i < text.length; i++) {
|
||||||
if (KeyCodes.isEnter(code)) {
|
if (KeyCodes.isEnter(text.charCodeAt(i)) || (text.charAt(i) == "\n")) {
|
||||||
stdout.write(this.buffer.join("") + "\n");
|
stdout.write(this.buffer.join(""));
|
||||||
this.buffer = new Array();
|
this.buffer = new Array();
|
||||||
} else {
|
|
||||||
this.buffer.push(KeyCodes.normalKey(code));
|
|
||||||
}
|
}
|
||||||
if (this.stream.eof) {
|
if (text.charAt(i) == EOF) {
|
||||||
stdout.write(this.buffer.join("") + "\n");
|
stdout.write(this.buffer.join(""));
|
||||||
|
this.buffer = new Array();
|
||||||
this.exit(0);
|
this.exit(0);
|
||||||
}
|
}
|
||||||
} else {
|
this.buffer.push(text.charAt(i));
|
||||||
}
|
}
|
||||||
|
this.index += 100;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ WshClass.prototype.tick = function() {
|
||||||
stdout.write("Welcome to WishOS 0.1 (WOSKernel 0.1)\n\n");
|
stdout.write("Welcome to WishOS 0.1 (WOSKernel 0.1)\n\n");
|
||||||
console.log("wsh: loading profile");
|
console.log("wsh: loading profile");
|
||||||
var prof = new File("/etc/profile.d/env.json");
|
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();
|
prof.close();
|
||||||
for (var i = 0; i < array.length; i++) {
|
for (var i = 0; i < array.length; i++) {
|
||||||
while(array[i][1].indexOf("\\033") != -1)
|
while(array[i][1].indexOf("\\033") != -1)
|
||||||
|
@ -57,6 +57,7 @@ WshClass.prototype.tick = function() {
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
var char = stdin.read(1);
|
var char = stdin.read(1);
|
||||||
|
char = char.replace(EOF, "");
|
||||||
if (!char.length)
|
if (!char.length)
|
||||||
break;
|
break;
|
||||||
var code = char.charCodeAt(0);
|
var code = char.charCodeAt(0);
|
||||||
|
@ -208,9 +209,9 @@ WshClass.prototype.parseLine = function() {
|
||||||
prog.files['stdin'] = this.files['stdin'];
|
prog.files['stdin'] = this.files['stdin'];
|
||||||
prog.files['stdout'] = this.files['stdout'];
|
prog.files['stdout'] = this.files['stdout'];
|
||||||
prog.Environment = this.Environment;
|
prog.Environment = this.Environment;
|
||||||
console.log("wsh: program startet: " + file);
|
console.log("wsh: program start: " + file);
|
||||||
prog.main(params);
|
prog.main(params);
|
||||||
|
console.log("wsh: main shut down");
|
||||||
}
|
}
|
||||||
WshClass.prototype.tryFile = function(name) {
|
WshClass.prototype.tryFile = function(name) {
|
||||||
var file = new File(name);
|
var file = new File(name);
|
||||||
|
|
|
@ -39,6 +39,9 @@ const MODE_APPND = 4;
|
||||||
const MODE_THROW = 5;
|
const MODE_THROW = 5;
|
||||||
const MODE_CREATE = 6;
|
const MODE_CREATE = 6;
|
||||||
|
|
||||||
|
// special chars
|
||||||
|
const EOF = String.fromCharCode(26);
|
||||||
|
|
||||||
var OS = function() {
|
var OS = function() {
|
||||||
}
|
}
|
||||||
OS.system;
|
OS.system;
|
||||||
|
@ -461,6 +464,7 @@ InnerFile.prototype.permissions = PERM_GR | PERM_UW | PERM_UR;
|
||||||
InnerFile.prototype.parent; // id
|
InnerFile.prototype.parent; // id
|
||||||
InnerFile.prototype.mountPoint;
|
InnerFile.prototype.mountPoint;
|
||||||
InnerFile.prototype.removeReaded = false;
|
InnerFile.prototype.removeReaded = false;
|
||||||
|
InnerFile.prototype.neverEnds = false;
|
||||||
InnerFile.prototype.content = "";
|
InnerFile.prototype.content = "";
|
||||||
InnerFile.prototype.created = 0;
|
InnerFile.prototype.created = 0;
|
||||||
InnerFile.prototype.changed = 0;
|
InnerFile.prototype.changed = 0;
|
||||||
|
@ -520,6 +524,8 @@ Kernel.Filesystem.initCon = function() {
|
||||||
Kernel.msgSuccess(true);
|
Kernel.msgSuccess(true);
|
||||||
}
|
}
|
||||||
Kernel.Filesystem.shortenPath = function(path) {
|
Kernel.Filesystem.shortenPath = function(path) {
|
||||||
|
while (path.indexOf("//") != -1)
|
||||||
|
path = path.replace("//", "/");
|
||||||
if (path == "/")
|
if (path == "/")
|
||||||
return "/";
|
return "/";
|
||||||
if (path.substring(path.length - 1) == "/")
|
if (path.substring(path.length - 1) == "/")
|
||||||
|
@ -529,7 +535,7 @@ Kernel.Filesystem.shortenPath = function(path) {
|
||||||
var parts = path.split("/");
|
var parts = path.split("/");
|
||||||
for (var i = 0; i < parts.length; i++) {
|
for (var i = 0; i < parts.length; i++) {
|
||||||
if (!parts[i])
|
if (!parts[i])
|
||||||
throw("format error");
|
throw("format error: " + path);
|
||||||
if (parts[i].length == 0) {
|
if (parts[i].length == 0) {
|
||||||
parts.splice(0, i);
|
parts.splice(0, i);
|
||||||
i = 0;
|
i = 0;
|
||||||
|
@ -588,15 +594,21 @@ Kernel.Filesystem.read = function(path, length, index, readMode) {
|
||||||
if (length !== undefined) {
|
if (length !== undefined) {
|
||||||
if (index !== undefined) {
|
if (index !== undefined) {
|
||||||
text = content.substring(index, length + index);
|
text = content.substring(index, length + index);
|
||||||
|
if ((text.length < length) && (!file.neverEnds))
|
||||||
|
text += EOF;
|
||||||
if (file.removeReaded)
|
if (file.removeReaded)
|
||||||
content = content.substring(length + index);
|
content = content.substring(length + index);
|
||||||
} else {
|
} else {
|
||||||
text = content.substring(0, length);
|
text = content.substring(0, length);
|
||||||
|
if ((text.length < length) && (!file.neverEnds))
|
||||||
|
text += EOF;
|
||||||
if (file.removeReaded)
|
if (file.removeReaded)
|
||||||
content = content.substring(length);
|
content = content.substring(length);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
text = content;
|
text = content;
|
||||||
|
if (!file.neverEnds)
|
||||||
|
text += EOF;
|
||||||
if (file.removeReaded)
|
if (file.removeReaded)
|
||||||
content = "";
|
content = "";
|
||||||
}
|
}
|
||||||
|
@ -808,6 +820,7 @@ Kernel.Filesystem.devfs.populate = function() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tty.removeReaded = true;
|
tty.removeReaded = true;
|
||||||
|
tty.neverEnds = true;
|
||||||
tty.onRead = function () {
|
tty.onRead = function () {
|
||||||
var tmp = Kernel.IO.input();
|
var tmp = Kernel.IO.input();
|
||||||
for (var i = 0; i < tmp.length; i++) {
|
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");
|
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) {
|
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") {
|
if (typeof content == "string") {
|
||||||
|
|
||||||
Kernel.Filesystem.basefs.files = Kernel.Filesystem.basefs.interpretFile(JSON.parse(content), NO_PARENT, NO_MOUNTPOINT); // not mounted yet
|
Kernel.Filesystem.basefs.files = Kernel.Filesystem.basefs.interpretFile(JSON.parse(content), NO_PARENT, NO_MOUNTPOINT); // not mounted yet
|
||||||
Kernel.next();
|
Kernel.next();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -51,7 +51,9 @@ InitClass.prototype.tick = function() {
|
||||||
Emulator.output("\nloading /etc/inittab.json ...");
|
Emulator.output("\nloading /etc/inittab.json ...");
|
||||||
var file = new File("/etc/inittab.json");
|
var file = new File("/etc/inittab.json");
|
||||||
this.files[file.path] = file;
|
this.files[file.path] = file;
|
||||||
this.inittab = JSON.parse(file.read());
|
file = file.read();
|
||||||
|
file = file.replace(EOF, "");
|
||||||
|
this.inittab = JSON.parse(file);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
this.state++;
|
this.state++;
|
||||||
|
|
|
@ -35,6 +35,7 @@ LoginClass.prototype.tick = function() {
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
var char = stdin.read(1);
|
var char = stdin.read(1);
|
||||||
|
char = char.replace(EOF, "");
|
||||||
if (!(char.length))
|
if (!(char.length))
|
||||||
break;
|
break;
|
||||||
var code = (new String(char)).charCodeAt(0);
|
var code = (new String(char)).charCodeAt(0);
|
||||||
|
@ -59,6 +60,7 @@ LoginClass.prototype.tick = function() {
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
var char = stdin.read(1);
|
var char = stdin.read(1);
|
||||||
|
char = char.replace(EOF, "");
|
||||||
if (!char.length)
|
if (!char.length)
|
||||||
break;
|
break;
|
||||||
var code = (new String(char)).charCodeAt(0);
|
var code = (new String(char)).charCodeAt(0);
|
||||||
|
@ -79,7 +81,7 @@ LoginClass.prototype.tick = function() {
|
||||||
this.username = this.username.join("");
|
this.username = this.username.join("");
|
||||||
this.cpassword = Sha256.hash(this.password.join(""));
|
this.cpassword = Sha256.hash(this.password.join(""));
|
||||||
var file = new File("/etc/passwd.json");
|
var file = new File("/etc/passwd.json");
|
||||||
this.users = JSON.parse(file.read());
|
this.users = JSON.parse(file.read().replace(EOF, ""));
|
||||||
file.close();
|
file.close();
|
||||||
this.state++;
|
this.state++;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue