mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-12 15:44:05 +09:00
command.js: fixing bad path syntax on shell.execute
This commit is contained in:
@@ -46,6 +46,16 @@ if (!String.prototype.startsWith) {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!String.prototype.endsWith) {
|
||||
Object.defineProperty(String.prototype, 'endsWith', {
|
||||
value: function(search, this_len) {
|
||||
if (this_len === undefined || this_len > this.length) {
|
||||
this_len = this.length;
|
||||
}
|
||||
return this.substring(this_len - search.length, this_len) === search;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!Array.prototype.filter){
|
||||
Array.prototype.filter = function(func, thisArg) {
|
||||
'use strict';
|
||||
|
||||
@@ -13,11 +13,11 @@ _TVDOS.getPath = function() {
|
||||
};
|
||||
// initial values
|
||||
_TVDOS.variables = {
|
||||
DOSDIR: "\\tvdos\\",
|
||||
DOSDIR: "\\tvdos",
|
||||
LANG: "EN",
|
||||
PATH: "\\tvdos\\bin\\",
|
||||
PATH: "\\tvdos\\bin",
|
||||
PATHEXT: ".com;.bat;.js",
|
||||
HELPPATH: "\\tvdos\\help\\",
|
||||
HELPPATH: "\\tvdos\\help",
|
||||
OS_NAME: "Terrarum Virtual DOS",
|
||||
OS_VERSION: _TVDOS.VERSION
|
||||
};
|
||||
|
||||
@@ -5,6 +5,8 @@ let shell_pwd = [""];
|
||||
let goInteractive = false;
|
||||
let goFancy = false;
|
||||
|
||||
let DEBUG_PRINT = true;
|
||||
|
||||
const welcome_text = "TSVM Disk Operating System, version " + _TVDOS.VERSION;
|
||||
|
||||
function print_prompt_text() {
|
||||
@@ -36,6 +38,18 @@ function greet() {
|
||||
println(welcome_text);
|
||||
}
|
||||
|
||||
function trimStartRevSlash(s) {
|
||||
let cnt = 0;
|
||||
while (cnt < s.length) {
|
||||
let chr = s[cnt];
|
||||
|
||||
if (chr != '\\') break;
|
||||
|
||||
cnt += 1;
|
||||
}
|
||||
|
||||
return s.substring(cnt);
|
||||
}
|
||||
|
||||
let shell = {};
|
||||
// example input: echo "the string" > subdir\test.txt
|
||||
@@ -199,6 +213,7 @@ shell.execute = function(line) {
|
||||
|
||||
let fileExists = false;
|
||||
let searchDir = (cmd.startsWith("\\")) ? [""] : ["\\"+shell_pwd.join("\\")].concat(_TVDOS.getPath());
|
||||
|
||||
let pathExt = [];
|
||||
// fill pathExt using %PATHEXT% but also capitalise them
|
||||
if (cmd.split(".")[1] === undefined)
|
||||
@@ -209,7 +224,13 @@ shell.execute = function(line) {
|
||||
searchLoop:
|
||||
for (let i = 0; i < searchDir.length; i++) {
|
||||
for (let j = 0; j < pathExt.length; j++) {
|
||||
let path = (searchDir[i] + cmd + pathExt[j]).substring(1); // without substring, this will always prepend revslash
|
||||
let search = searchDir[i]; if (!search.endsWith('\\')) search += '\\';
|
||||
let path = trimStartRevSlash(search + cmd + pathExt[j]);
|
||||
|
||||
if (DEBUG_PRINT) {
|
||||
serial.println("[command.js > shell.execute] file search path: "+path);
|
||||
}
|
||||
|
||||
if (filesystem.open(CURRENT_DRIVE, path, "R")) {
|
||||
fileExists = true;
|
||||
break searchLoop;
|
||||
|
||||
Reference in New Issue
Block a user