geturl.js

This commit is contained in:
minjaesong
2022-09-22 23:25:46 +09:00
parent 2dc6f581cc
commit 7a0874b4a3
4 changed files with 63 additions and 14 deletions

View File

@@ -628,7 +628,10 @@ _TVDOS.DRV.FS.NET.sread = (fd) => {
com.sendMessage(port[0], "GET " + url)
com.waitUntilReady(port[0])
return com.pullMessage(port[0])
if (com.getStatusCode(port[0]) == 0)
return com.pullMessage(port[0])
else
return null
}
_TVDOS.DRV.FS.NET.flush = () => {}

View File

@@ -0,0 +1,47 @@
let url = exec_args[1]
if (url === undefined) {
println("geturl: missing URL")
println("Usage: geturl [URL]")
return 1
}
let baseurl = url.split('#').head()
baseurl = baseurl.split('?').head()
let filename = baseurl.split('/').last()
// look for network device
let netDrive = undefined
Object.entries(_TVDOS.DRIVEINFO).forEach(([letter, info])=>{
// println(`${letter} - ${info.name}, ${info.type}`)
if (!netDrive && info.type == "HTTP")
netDrive = letter
})
if (!netDrive) {
println("No Internet-connected network device found.")
return 1
}
let netfile = files.open(`${netDrive}:/${url.replace("://", ":")}`)
println(`Opening network file ${netfile.fullPath}`)
let savefile = files.open(_G.shell.resolvePathInput(filename).full)
let hostname = url.split('://')[1].split('/').head()
println(`Connecting to ${hostname}...`)
let response = netfile.sread()
if (response == null) {
println(`Unable to resolve ${hostname}`)
return 1
}
response = response.trimNull()
if (response.length == 0) {
println(`The webpage does not exist or has zero length`)
return 2
}
println(`Length: ${response.length}`)
println(`Saving to '${filename}'`)
savefile.swrite(response)
println(`'${filename}' saved`)

View File

@@ -30,15 +30,15 @@ if (filename === undefined && _G.shell.hasPipe()) {
}
else if (filename === undefined) {
println('Missing filename ("less -?" for help)');
return 0;
return 1;
}
else {
if (filename.startsWith("-?")) {
println("less <filename>");
return 0;
return 1;
}
let file = files.open(`${_G.shell.getCurrentDrive()}:/${_G.shell.resolvePathInput(filename).string}`)
let file = files.open(`${_G.shell.resolvePathInput(filename).full}`)
if (!file.exists) {
printerrln(_G.shell.resolvePathInput(filename).string+": cannot open");
return 1;

View File

@@ -67,6 +67,15 @@ class VM(
init {
println("[VM] Creating new VM with ID of $id, memsize $memsize")
peripheralTable[0] = PeripheralEntry(
IOSpace(this),
HW_RESERVE_SIZE,
MMIO_SIZE.toInt() - 256,
64
)
init()
}
@@ -78,16 +87,6 @@ class VM(
fun init() {
killAllContexts()
peripheralTable[0] = PeripheralEntry(
IOSpace(this),
HW_RESERVE_SIZE,
MMIO_SIZE.toInt() - 256,
64
)
println("[VM] Creating new VM with ID of $id, memsize $memsize")
startTime = System.currentTimeMillis()
mallocMap.clear()