mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
more pipe stuffs
This commit is contained in:
@@ -28,7 +28,12 @@ function bootFromPort(port) {
|
||||
else throw "No Bootsector"
|
||||
}
|
||||
catch (e) {
|
||||
printerrln(`No bootable medium on COM ${port+1}`)
|
||||
if ("No Bootsector" == e)
|
||||
printerrln(`No bootable medium on COM ${port+1}`)
|
||||
else
|
||||
printerrln(`Boot failed with errors:\n\n${e}`)
|
||||
|
||||
serial.printerr(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +157,7 @@ showHowtoEnterMenu()
|
||||
let bootable = probeBootable()
|
||||
let sysRq = false
|
||||
let tmr = sys.nanoTime()
|
||||
while (sys.nanoTime() - tmr < 5 * 1000000000.0) {
|
||||
while (sys.nanoTime() - tmr < 3 * 1000000000.0) {
|
||||
sysRq = sys.getSysrq()
|
||||
if (sysRq) break
|
||||
sys.spin()
|
||||
|
||||
@@ -76,8 +76,7 @@ filesystem._close = (portNo) => {
|
||||
filesystem._flush = (portNo) => {
|
||||
com.sendMessage(portNo, "FLUSH");
|
||||
};
|
||||
// @return true if operation committed successfully, false if:
|
||||
// - opening file with R-mode and target file does not exists
|
||||
// @return disk status code (0 for successful operation)
|
||||
// throws if:
|
||||
// - java.lang.NullPointerException if path is null
|
||||
// - Error if operation mode is not "R", "W" nor "A"
|
||||
|
||||
@@ -456,6 +456,34 @@ shell.execute = function(line) {
|
||||
}
|
||||
};
|
||||
shell.pipes = {}; // syntax: _G.shell.pipes[name] = contents; all pipes are named pipes just like in Windows
|
||||
shell.currentlyActivePipes = []; // pipe queue. Use shell.getPipe() to dequeue and shell.pushPipe() to enqueue.
|
||||
shell._rndstr = '0123456789+qwfpgjluyarstdhneiozxcvbkm/QWFPGJLUYARSTDHNEIOZXCVBKM'
|
||||
shell.generateRandomName = function() {
|
||||
let name = ''
|
||||
while (true) {
|
||||
name = "anonpipe_"
|
||||
for (let k = 0; k < 32; k++) {
|
||||
name += shell._rndstr[(Math.random() * 64)|0]
|
||||
}
|
||||
if (shell.pipes[name] == undefined) break
|
||||
}
|
||||
return name
|
||||
}
|
||||
shell.getPipe = function() {
|
||||
let n = shell.currentlyActivePipes.shift()
|
||||
return (n != undefined) ? shell.pipes[n] : undefined
|
||||
}
|
||||
shell.pushAnonPipe = function(contents) {
|
||||
let name = shell.generateRandomName()
|
||||
shell.pushPipe(name, contents)
|
||||
}
|
||||
shell.pushPipe = function(name, contents) {
|
||||
shell.pipes[name] = contents
|
||||
shell.currentlyActivePipes.unshift(name)
|
||||
}
|
||||
shell.hasPipe = function() {
|
||||
return shell.currentlyActivePipes[0] != undefined
|
||||
}
|
||||
Object.freeze(shell);
|
||||
_G.shell = shell;
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
if (exec_args[1] === undefined) {
|
||||
println('Missing filename ("less -?" for help)');
|
||||
return 0;
|
||||
}
|
||||
let filename = exec_args[1]
|
||||
|
||||
/*let help = "\n
|
||||
SUMMARY OF COMMANDS\n
|
||||
@@ -10,27 +7,46 @@ SUMMARY OF COMMANDS\n
|
||||
q Q Exit
|
||||
\n"*/
|
||||
|
||||
if (exec_args[1].startsWith("-?")) {
|
||||
println("less <filename>");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let fileOpened = filesystem.open(_G.shell.getCurrentDrive(), _G.shell.resolvePathInput(exec_args[1]).string, "R");
|
||||
if (!fileOpened) {
|
||||
printerrln(_G.shell.resolvePathInput(exec_args[1]).string+": cannot open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
let scroll = 0;
|
||||
let pan = -1;
|
||||
let termW = con.getmaxyx()[1];
|
||||
let termH = con.getmaxyx()[0] - 1;
|
||||
let buf = "";
|
||||
let fileContent = filesystem.readAll(_G.shell.getCurrentDrive());
|
||||
let fileContent = undefined
|
||||
let key = -1;
|
||||
let panSize = termW >> 1;
|
||||
let scrollSize = termH >> 3;
|
||||
|
||||
let startAddr = -1;
|
||||
let paintCur = 0;
|
||||
let cy = 1;
|
||||
let cx = 1;
|
||||
let char = -1;
|
||||
|
||||
let numbuf = 0;
|
||||
|
||||
if (filename === undefined && _G.shell.hasPipe()) {
|
||||
fileContent = _G.shell.getPipe()
|
||||
}
|
||||
else if (filename === undefined) {
|
||||
println('Missing filename ("less -?" for help)');
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (filename.startsWith("-?")) {
|
||||
println("less <filename>");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let fileOpened = filesystem.open(_G.shell.getCurrentDrive(), _G.shell.resolvePathInput(filename).string, "R");
|
||||
if (fileOpened != 0) {
|
||||
printerrln(_G.shell.resolvePathInput(filename).string+": cannot open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fileContent = filesystem.readAll(_G.shell.getCurrentDrive());
|
||||
}
|
||||
|
||||
// initialise some helper variables
|
||||
let lineToBytes = [0];
|
||||
let maxPan = 0;
|
||||
@@ -45,13 +61,8 @@ for (let i = 0; i < fileContent.length; i++) {
|
||||
}
|
||||
}
|
||||
|
||||
let startAddr = -1;
|
||||
let paintCur = 0;
|
||||
let cy = 1;
|
||||
let cx = 1;
|
||||
let char = -1;
|
||||
|
||||
let numbuf = 0;
|
||||
|
||||
|
||||
let resetKeyReadStatus = function() {
|
||||
numbuf = 0;
|
||||
|
||||
Reference in New Issue
Block a user