This commit is contained in:
minjaesong
2020-11-12 14:37:37 +09:00
parent 88ef2e05ab
commit 8220732db9
6 changed files with 102 additions and 13 deletions

View File

@@ -52,6 +52,8 @@ function trimStartRevSlash(s) {
}
let shell = {};
shell.getPwd = function() { return shell_pwd; }
shell.getCurrentDrive = function() { return CURRENT_DRIVE; }
// example input: echo "the string" > subdir\test.txt
shell.parse = function(input) {
let tokens = [];
@@ -122,8 +124,7 @@ shell.parse = function(input) {
return tokens;
}
function resolvePathInput(input) {
shell.resolvePathInput = function(input) {
// replace slashes into revslashes
let pathstr = input.replaceAll('/','\\\\');
let startsWithSlash = input.startsWith('\\');
@@ -166,7 +167,7 @@ shell.coreutils = {
println(CURRENT_DRIVE+":"+shell_pwd.join("\\"));
return
}
let path = resolvePathInput(args[1])
let path = shell.resolvePathInput(args[1])
if (DEBUG_PRINT) serial.println("command.js > cd > pathstr = "+path.string);
// check if path is valid
@@ -181,7 +182,7 @@ shell.coreutils = {
printerrln("Syntax error");
return
}
let path = resolvePathInput(args[1])
let path = shell.resolvePathInput(args[1])
if (DEBUG_PRINT) serial.println("command.js > mkdir > pathstr = "+path.string);
// check if path is valid
@@ -320,6 +321,7 @@ shell.execute = function(line) {
}
};
Object.freeze(shell);
_G.shell = shell;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

30
assets/tvdos/bin/touch.js Normal file
View File

@@ -0,0 +1,30 @@
if (exec_args[1] === undefined) {
println("TOUCH - TVDOS file date and time setting utility");
println()
println("SYNOPSIS")
println(" TOUCH [/C] path")
println()
println("/C = don't create files that do not already exist")
return 1;
}
let path = _G.shell.resolvePathInput(exec_args[2] || exec_args[1]).string;
let driveLetter = _G.shell.getCurrentDrive();
let noNewFile = (exec_args[1] == "/c" || exec_args[1] == "/C");
let fileOpened = filesystem.open(driveLetter, path, "W");
if (!fileOpened) {
printerrln("TOUCH: Can't open "+driveLetter+":\\"+path+" due to IO error");
return 1;
}
if (!noNewFile) {
filesystem.mkFile(driveLetter);
}
let touched = filesystem.touch(driveLetter);
if (!touched) {
printerrln("TOUCH: Can't touch "+driveLetter+":\\"+path+" due to IO error");
return 1;
}
return 0;