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!" echo "Hello, world!"
fsh fsh
command

View File

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

View File

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

View File

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