command.js to run batch file

This commit is contained in:
minjaesong
2020-11-04 16:10:33 +09:00
parent 3b2870ec9c
commit ab0827b96c
7 changed files with 26 additions and 10 deletions

View File

@@ -1,2 +1,3 @@
echo "Hello, world!"
fsh
fsh
command

View File

@@ -377,6 +377,9 @@ con.clear = function() {
con.curs_set = function(arg) {
print(String.fromCharCode(27,91)+"?25"+(((arg|0) == 0) ? "l" : "h"));
};
con.reset_graphics = function() {
println(String.fromCharCode(27,91,109));
};
Object.freeze(con);
// system management function
var system = {};

View File

@@ -80,6 +80,6 @@ var execApp = function(cmdsrc, args) {
///////////////////////////////////////////////////////////////////////////////
// Boot script
filesystem.open("A", "tvdos/command.js", "R");
filesystem.open("A", "tvdos/bin/command.js", "R");
let cmdsrc = filesystem.readAll("A");
execApp(cmdsrc, ["", "/c", "\\AUTOEXEC.BAT"]);

View File

@@ -1,6 +1,6 @@
let PROMPT_TEXT = ">";
let CURRENT_DRIVE = "A";
let executableExtensions = [".com",".bat",".js", ""]; Object.freeze(executableExtensions);
let shell_pwd = [];
const welcome_text = "TSVM Disk Operating System, version " + _TVDOS.VERSION;
@@ -109,6 +109,9 @@ shell.coreutils = {
args.forEach(function(it,i) { if (i > 0) print(it+" ") });
}
println();
},
rem: function(args) {
return 0;
}
};
Object.freeze(shell.coreutils);
@@ -117,6 +120,9 @@ shell.execute = function(line) {
let tokens = shell.parse(line);
let cmd = tokens[0];
// handle Ctrl-C
if (con.hitterminate()) return 1;
if (shell.coreutils[cmd.toLowerCase()] !== undefined) {
let retval = shell.coreutils[cmd.toLowerCase()](tokens);
return retval|0; // return value of undefined will cast into 0
@@ -129,11 +135,14 @@ shell.execute = function(line) {
searchDir.forEach(function(it) { serial.println("Searchdir: "+it); });
searchLoop:
for (let i = 0; i < searchDir.length; i++) {
let path = (searchDir[i] + cmd).substring(1); // without substring, this will always prepend revslash
if (filesystem.open(CURRENT_DRIVE, path, "R")) {
fileExists = true;
break;
for (let j = 0; j < executableExtensions.length; j++) {
let path = (searchDir[i] + cmd + executableExtensions[j]).substring(1); // without substring, this will always prepend revslash
if (filesystem.open(CURRENT_DRIVE, path, "R")) {
fileExists = true;
break searchLoop;
}
}
}
@@ -151,7 +160,9 @@ shell.execute = function(line) {
if ("BAT" == extension) {
// parse and run as batch file
let lines = prg.split('\n').filter(function(it) { return it.length > 0; });
lines.forEach(function(it) { println("Batch: " + it) }); // TODO
lines.forEach(function(line) {
shell.execute(line);
});
}
else {
return execApp(prg, tokens)|0; // return value of undefined will cast into 0
@@ -165,7 +176,7 @@ Object.freeze(shell);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (exec_args !== undefined) {
if (exec_args[1] !== undefined) {
// command /c <commands>
// ^[0] ^[1] ^[2]
if (exec_args[1].toLowerCase() == "/c") {
@@ -178,8 +189,8 @@ if (exec_args !== undefined) {
}
}
else {
con.reset_graphics();
println("Starting TVDOS...");
greet();
let cmdHistory = []; // zeroth element is the oldest

View File

@@ -371,6 +371,7 @@ class GraphicsAdapter(val vm: VM, val lcdMode: Boolean = false, lcdInvert: Boole
else if (arg == 0) {
ttyFore = TTY_FORE_DEFAULT
ttyBack = TTY_BACK_DEFAULT
blinkCursor = true
}
}