mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-12 15:44:05 +09:00
touch.js
This commit is contained in:
@@ -317,8 +317,7 @@ basicInterpreterStatus.builtin = {
|
|||||||
if (seps[llll - 1] == ",") print("\t");
|
if (seps[llll - 1] == ",") print("\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
var resolvedargs = resolve(args[llll]);
|
var resolvedargs = resolve(args[llll]) || "";
|
||||||
if (resolvedargs === undefined) resolvedargs = "";
|
|
||||||
|
|
||||||
if (args[llll].type == "number")
|
if (args[llll].type == "number")
|
||||||
print(" "+resolvedargs+" ");
|
print(" "+resolvedargs+" ");
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ Object.freeze(_TVDOS);
|
|||||||
|
|
||||||
var filesystem = {};
|
var filesystem = {};
|
||||||
filesystem._toPorts = function(driveLetter) {
|
filesystem._toPorts = function(driveLetter) {
|
||||||
|
if (driveLetter.toUpperCase === undefined) {
|
||||||
|
throw Error("'"+driveLetter+"' (type: "+typeof driveLetter+") is not a valid drive letter");
|
||||||
|
}
|
||||||
let port = _TVDOS.DRIVES[driveLetter.toUpperCase()];
|
let port = _TVDOS.DRIVES[driveLetter.toUpperCase()];
|
||||||
if (port === undefined) {
|
if (port === undefined) {
|
||||||
throw Error("Drive letter '" + driveLetter.toUpperCase() + "' does not exist");
|
throw Error("Drive letter '" + driveLetter.toUpperCase() + "' does not exist");
|
||||||
@@ -76,9 +79,8 @@ filesystem.isDirectory = function(driveLetter) {
|
|||||||
let port = filesystem._toPorts(driveLetter);
|
let port = filesystem._toPorts(driveLetter);
|
||||||
com.sendMessage(port[0], "LISTFILES");
|
com.sendMessage(port[0], "LISTFILES");
|
||||||
let response = com.getStatusCode(port[0]);
|
let response = com.getStatusCode(port[0]);
|
||||||
|
|
||||||
return (response === 0);
|
return (response === 0);
|
||||||
}
|
};
|
||||||
filesystem.mkDir = function(driveLetter) {
|
filesystem.mkDir = function(driveLetter) {
|
||||||
let port = filesystem._toPorts(driveLetter);
|
let port = filesystem._toPorts(driveLetter);
|
||||||
com.sendMessage(port[0], "MKDIR");
|
com.sendMessage(port[0], "MKDIR");
|
||||||
@@ -89,7 +91,19 @@ filesystem.mkDir = function(driveLetter) {
|
|||||||
throw Error("Creating a directory failed with ("+response+"): "+status.message+"\n");
|
throw Error("Creating a directory failed with ("+response+"): "+status.message+"\n");
|
||||||
}
|
}
|
||||||
return (response === 0); // possible status codes: 0 (success), 1 (fail)
|
return (response === 0); // possible status codes: 0 (success), 1 (fail)
|
||||||
}
|
};
|
||||||
|
filesystem.touch = function(driveLetter) {
|
||||||
|
let port = filesystem._toPorts(driveLetter);
|
||||||
|
com.sendMessage(port[0], "TOUCH");
|
||||||
|
let response = com.getStatusCode(port[0]);
|
||||||
|
return (response === 0);
|
||||||
|
};
|
||||||
|
filesystem.mkFile = function(driveLetter) {
|
||||||
|
let port = filesystem._toPorts(driveLetter);
|
||||||
|
com.sendMessage(port[0], "MKFILE");
|
||||||
|
let response = com.getStatusCode(port[0]);
|
||||||
|
return (response === 0);
|
||||||
|
};
|
||||||
Object.freeze(filesystem);
|
Object.freeze(filesystem);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -110,6 +124,7 @@ var execApp = function(cmdsrc, args) {
|
|||||||
|
|
||||||
// Boot script
|
// Boot script
|
||||||
serial.println("TVDOS.SYS initialised, running boot script...");
|
serial.println("TVDOS.SYS initialised, running boot script...");
|
||||||
|
var _G = {};
|
||||||
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"]);
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ function trimStartRevSlash(s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let shell = {};
|
let shell = {};
|
||||||
|
shell.getPwd = function() { return shell_pwd; }
|
||||||
|
shell.getCurrentDrive = function() { return CURRENT_DRIVE; }
|
||||||
// example input: echo "the string" > subdir\test.txt
|
// example input: echo "the string" > subdir\test.txt
|
||||||
shell.parse = function(input) {
|
shell.parse = function(input) {
|
||||||
let tokens = [];
|
let tokens = [];
|
||||||
@@ -122,8 +124,7 @@ shell.parse = function(input) {
|
|||||||
|
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
shell.resolvePathInput = function(input) {
|
||||||
function resolvePathInput(input) {
|
|
||||||
// replace slashes into revslashes
|
// replace slashes into revslashes
|
||||||
let pathstr = input.replaceAll('/','\\\\');
|
let pathstr = input.replaceAll('/','\\\\');
|
||||||
let startsWithSlash = input.startsWith('\\');
|
let startsWithSlash = input.startsWith('\\');
|
||||||
@@ -166,7 +167,7 @@ shell.coreutils = {
|
|||||||
println(CURRENT_DRIVE+":"+shell_pwd.join("\\"));
|
println(CURRENT_DRIVE+":"+shell_pwd.join("\\"));
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let path = resolvePathInput(args[1])
|
let path = shell.resolvePathInput(args[1])
|
||||||
if (DEBUG_PRINT) serial.println("command.js > cd > pathstr = "+path.string);
|
if (DEBUG_PRINT) serial.println("command.js > cd > pathstr = "+path.string);
|
||||||
|
|
||||||
// check if path is valid
|
// check if path is valid
|
||||||
@@ -181,7 +182,7 @@ shell.coreutils = {
|
|||||||
printerrln("Syntax error");
|
printerrln("Syntax error");
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let path = resolvePathInput(args[1])
|
let path = shell.resolvePathInput(args[1])
|
||||||
if (DEBUG_PRINT) serial.println("command.js > mkdir > pathstr = "+path.string);
|
if (DEBUG_PRINT) serial.println("command.js > mkdir > pathstr = "+path.string);
|
||||||
|
|
||||||
// check if path is valid
|
// check if path is valid
|
||||||
@@ -320,6 +321,7 @@ shell.execute = function(line) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Object.freeze(shell);
|
Object.freeze(shell);
|
||||||
|
_G.shell = shell;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
30
assets/tvdos/bin/touch.js
Normal file
30
assets/tvdos/bin/touch.js
Normal 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;
|
||||||
@@ -40,7 +40,7 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
blockTransferPorts[1].attachDevice(TestFunctionGenerator())
|
blockTransferPorts[1].attachDevice(TestFunctionGenerator())
|
||||||
blockTransferPorts[0].attachDevice(TestDiskDrive(0, File("assets/")))
|
blockTransferPorts[0].attachDevice(TestDiskDrive(vm, 0, File("assets/")))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun composeBlockTransferStatus(portno: Int): Int {
|
private fun composeBlockTransferStatus(portno: Int): Int {
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package net.torvald.tsvm.peripheral
|
package net.torvald.tsvm.peripheral
|
||||||
|
|
||||||
import net.torvald.tsvm.VM
|
import net.torvald.tsvm.VM
|
||||||
|
import net.torvald.tsvm.VMJSR223Delegate
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class TestDiskDrive(private val driveNum: Int, theRootPath: File? = null) : BlockTransferInterface(false, true) {
|
class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath: File? = null) : BlockTransferInterface(false, true) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val STATE_CODE_STANDBY = 0
|
const val STATE_CODE_STANDBY = 0
|
||||||
@@ -306,7 +307,7 @@ class TestDiskDrive(private val driveNum: Int, theRootPath: File? = null) : Bloc
|
|||||||
}
|
}
|
||||||
else if (inputString.startsWith("MKDIR")) {
|
else if (inputString.startsWith("MKDIR")) {
|
||||||
if (!fileOpen) {
|
if (!fileOpen) {
|
||||||
statusCode = STATE_CODE_FILE_NOT_FOUND
|
statusCode = STATE_CODE_NO_FILE_OPENED
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (fileOpenMode < 1) {
|
if (fileOpenMode < 1) {
|
||||||
@@ -321,9 +322,51 @@ class TestDiskDrive(private val driveNum: Int, theRootPath: File? = null) : Bloc
|
|||||||
statusCode = STATE_CODE_SYSTEM_SECURITY_ERROR
|
statusCode = STATE_CODE_SYSTEM_SECURITY_ERROR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (inputString.startsWith("MKFILE")) {
|
||||||
|
if (!fileOpen) {
|
||||||
|
statusCode = STATE_CODE_NO_FILE_OPENED
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (fileOpenMode < 1) {
|
||||||
|
statusCode = STATE_CODE_OPERATION_NOT_PERMITTED
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
val f1 = file.createNewFile()
|
||||||
|
statusCode = if (f1) STATE_CODE_STANDBY else STATE_CODE_OPERATION_FAILED
|
||||||
|
return
|
||||||
|
}
|
||||||
|
catch (e: IOException) {
|
||||||
|
statusCode = STATE_CODE_SYSTEM_IO_ERROR
|
||||||
|
}
|
||||||
|
catch (e1: SecurityException) {
|
||||||
|
statusCode = STATE_CODE_SYSTEM_SECURITY_ERROR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (inputString.startsWith("TOUCH")) {
|
||||||
|
if (!fileOpen) {
|
||||||
|
statusCode = STATE_CODE_NO_FILE_OPENED
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (fileOpenMode < 1) {
|
||||||
|
statusCode = STATE_CODE_OPERATION_NOT_PERMITTED
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
val f1 = file.setLastModified(vm.worldInterface.currentTimeInMills())
|
||||||
|
statusCode = if (f1) STATE_CODE_STANDBY else STATE_CODE_OPERATION_FAILED
|
||||||
|
return
|
||||||
|
}
|
||||||
|
catch (e: IOException) {
|
||||||
|
statusCode = STATE_CODE_SYSTEM_IO_ERROR
|
||||||
|
}
|
||||||
|
catch (e1: SecurityException) {
|
||||||
|
statusCode = STATE_CODE_SYSTEM_SECURITY_ERROR
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (inputString.startsWith("WRITE")) {
|
else if (inputString.startsWith("WRITE")) {
|
||||||
if (!fileOpen) {
|
if (!fileOpen) {
|
||||||
statusCode = STATE_CODE_FILE_NOT_FOUND
|
statusCode = STATE_CODE_NO_FILE_OPENED
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (fileOpenMode < 0) {
|
if (fileOpenMode < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user