mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-10 23:04:04 +09:00
geturl.js
This commit is contained in:
@@ -628,7 +628,10 @@ _TVDOS.DRV.FS.NET.sread = (fd) => {
|
|||||||
com.sendMessage(port[0], "GET " + url)
|
com.sendMessage(port[0], "GET " + url)
|
||||||
com.waitUntilReady(port[0])
|
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 = () => {}
|
_TVDOS.DRV.FS.NET.flush = () => {}
|
||||||
|
|||||||
47
assets/disk0/tvdos/bin/geturl.js
Normal file
47
assets/disk0/tvdos/bin/geturl.js
Normal 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`)
|
||||||
@@ -30,15 +30,15 @@ if (filename === undefined && _G.shell.hasPipe()) {
|
|||||||
}
|
}
|
||||||
else if (filename === undefined) {
|
else if (filename === undefined) {
|
||||||
println('Missing filename ("less -?" for help)');
|
println('Missing filename ("less -?" for help)');
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (filename.startsWith("-?")) {
|
if (filename.startsWith("-?")) {
|
||||||
println("less <filename>");
|
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) {
|
if (!file.exists) {
|
||||||
printerrln(_G.shell.resolvePathInput(filename).string+": cannot open");
|
printerrln(_G.shell.resolvePathInput(filename).string+": cannot open");
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -67,6 +67,15 @@ class VM(
|
|||||||
|
|
||||||
|
|
||||||
init {
|
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()
|
init()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,16 +87,6 @@ class VM(
|
|||||||
fun init() {
|
fun init() {
|
||||||
killAllContexts()
|
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()
|
startTime = System.currentTimeMillis()
|
||||||
|
|
||||||
mallocMap.clear()
|
mallocMap.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user