mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-11 07:14:04 +09:00
set command for command.js
This commit is contained in:
@@ -272,6 +272,17 @@ if ('function' !== typeof Array.prototype.reduceRight) {
|
|||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (!Object.entries) {
|
||||||
|
Object.entries = function( obj ){
|
||||||
|
var ownProps = Object.keys( obj ),
|
||||||
|
i = ownProps.length,
|
||||||
|
resArray = new Array(i); // preallocate the Array
|
||||||
|
while (i--)
|
||||||
|
resArray[i] = [ownProps[i], obj[ownProps[i]]];
|
||||||
|
|
||||||
|
return resArray;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// NOTE TO PROGRAMMERS: this JS_INIT script does not, and must not be invoked with strict mode //
|
// NOTE TO PROGRAMMERS: this JS_INIT script does not, and must not be invoked with strict mode //
|
||||||
|
|||||||
@@ -8,10 +8,18 @@ _TVDOS.DRIVES["A"] = _BIOS.FIRST_BOOTABLE_PORT;
|
|||||||
//TODO
|
//TODO
|
||||||
|
|
||||||
|
|
||||||
_TVDOS.defaults = {
|
_TVDOS.getPath = function() {
|
||||||
path: [
|
return _TVDOS.variables.PATH.split(';');
|
||||||
"\\tvdos\\bin\\"
|
};
|
||||||
]
|
// initial values
|
||||||
|
_TVDOS.variables = {
|
||||||
|
DOSDIR: "\\tvdos\\",
|
||||||
|
LANG: "EN",
|
||||||
|
PATH: "\\tvdos\\bin\\",
|
||||||
|
PATHEXT: ".com;.bat;.js",
|
||||||
|
HELPPATH: "\\tvdos\\help\\",
|
||||||
|
OS_NAME: "Terrarum Virtual DOS",
|
||||||
|
OS_VERSION: _TVDOS.VERSION
|
||||||
};
|
};
|
||||||
Object.freeze(_TVDOS);
|
Object.freeze(_TVDOS);
|
||||||
|
|
||||||
@@ -80,6 +88,7 @@ var execApp = function(cmdsrc, args) {
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Boot script
|
// Boot script
|
||||||
|
serial.println("TVDOS.SYS initialised, running boot script...");
|
||||||
filesystem.open("A", "tvdos/bin/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"]);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
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 = [];
|
||||||
|
|
||||||
let goInteractive = false;
|
let goInteractive = false;
|
||||||
@@ -111,6 +110,14 @@ shell.parse = function(input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shell.coreutils = {
|
shell.coreutils = {
|
||||||
|
/* Args follow this format:
|
||||||
|
* <command-name> <1st arg> <2nd arg> ...
|
||||||
|
* NOTE:
|
||||||
|
* even if there's no 1st arg, length of args may not be 1, therefore don't:
|
||||||
|
* if (args.length < 2)
|
||||||
|
* but do instead:
|
||||||
|
* if (args[1] === undefined)
|
||||||
|
*/
|
||||||
cd: function(args) {
|
cd: function(args) {
|
||||||
if (args[1] === undefined) {
|
if (args[1] === undefined) {
|
||||||
println(shell_pwd.join("\\"));
|
println(shell_pwd.join("\\"));
|
||||||
@@ -136,6 +143,38 @@ shell.coreutils = {
|
|||||||
},
|
},
|
||||||
rem: function(args) {
|
rem: function(args) {
|
||||||
return 0;
|
return 0;
|
||||||
|
},
|
||||||
|
set: function(args) {
|
||||||
|
// print all the env vars
|
||||||
|
if (args[1] === undefined) {
|
||||||
|
Object.entries(_TVDOS.variables).forEach(function(a) { println(a[0]+"="+a[1]); })
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// parse key-value pair with splitter '='
|
||||||
|
let key = undefined; let value = undefined;
|
||||||
|
// if syntax "<key> = <value>" is used?
|
||||||
|
if ('=' == args[2]) {
|
||||||
|
key = args[1].toUpperCase(); value = args[3];
|
||||||
|
}
|
||||||
|
else if (args[2] === undefined) {
|
||||||
|
let pair = args[1].split('=');
|
||||||
|
key = pair[0].toUpperCase(); value = pair[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == undefined) throw SyntaxError("Input format must be 'key=value'");
|
||||||
|
|
||||||
|
// if value is undefined, show what envvar[key] has
|
||||||
|
if (value === undefined) {
|
||||||
|
if (_TVDOS.variables[key] === undefined)
|
||||||
|
println("Environment variable '"+key+"' not found");
|
||||||
|
else
|
||||||
|
println(_TVDOS.variables[key])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// TODO parse %var_name% line
|
||||||
|
_TVDOS.variables[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Object.freeze(shell.coreutils);
|
Object.freeze(shell.coreutils);
|
||||||
@@ -155,14 +194,18 @@ shell.execute = function(line) {
|
|||||||
// search through PATH for execution
|
// search through PATH for execution
|
||||||
|
|
||||||
let fileExists = false;
|
let fileExists = false;
|
||||||
let searchDir = (cmd.startsWith("\\")) ? [""] : ["\\"+shell_pwd.join("\\")].concat(_TVDOS.defaults.path);
|
let searchDir = (cmd.startsWith("\\")) ? [""] : ["\\"+shell_pwd.join("\\")].concat(_TVDOS.getPath());
|
||||||
|
let pathExt = [];
|
||||||
searchDir.forEach(function(it) { serial.println("Searchdir: "+it); });
|
// fill pathExt using %PATHEXT% but also capitalise them
|
||||||
|
if (cmd.split(".")[1] === undefined)
|
||||||
|
_TVDOS.variables.PATHEXT.split(';').forEach(function(it) { pathExt.push(it); pathExt.push(it.toUpperCase()); });
|
||||||
|
else
|
||||||
|
pathExt.push(""); // final empty extension
|
||||||
|
|
||||||
searchLoop:
|
searchLoop:
|
||||||
for (let i = 0; i < searchDir.length; i++) {
|
for (let i = 0; i < searchDir.length; i++) {
|
||||||
for (let j = 0; j < executableExtensions.length; j++) {
|
for (let j = 0; j < pathExt.length; j++) {
|
||||||
let path = (searchDir[i] + cmd + executableExtensions[j]).substring(1); // without substring, this will always prepend revslash
|
let path = (searchDir[i] + cmd + pathExt[j]).substring(1); // without substring, this will always prepend revslash
|
||||||
if (filesystem.open(CURRENT_DRIVE, path, "R")) {
|
if (filesystem.open(CURRENT_DRIVE, path, "R")) {
|
||||||
fileExists = true;
|
fileExists = true;
|
||||||
break searchLoop;
|
break searchLoop;
|
||||||
|
|||||||
Reference in New Issue
Block a user