From fe972ddd11a0fb216ae9a333f789109997d1b63f Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Mon, 18 Dec 2023 21:44:02 +1000 Subject: [PATCH] a bunch of little fixes --- clite/bios.js | 20 +++++++++++++++++++ clite/commands.js | 19 +++++++----------- clite/core.js | 51 +++++++++++++++++++++++++++++++---------------- clite/shell.js | 2 -- 4 files changed, 61 insertions(+), 31 deletions(-) diff --git a/clite/bios.js b/clite/bios.js index b80ff64..ed3c433 100644 --- a/clite/bios.js +++ b/clite/bios.js @@ -101,6 +101,12 @@ var bios = { bios.input.upload.data.callback = d.fn; bios.input.upload.data.file = d.file; bios.input.setState(2); + break; + case 4: + bios.boot.shutdown(!d); + if (d == true) + setTimeout(bios.boot.reboot,10); + break; default:; } }, @@ -250,6 +256,20 @@ var bios = { bios.core.writeStringVGA(1,7,'Error in bootable entry point',4); bios.core.writeStringVGA(1,8,err.message,6); } + }, + shutdown:function(complete) { + var s = Array.from(document.getElementsByTagName('src')); + s.forEach(function(el,i) { + if (i>0) + el.parentNode.removeChild(el); + }); + if (!complete) + return; + document.body.innerHTML = 'The system has shutdown'; + bios = null; + }, + reboot:function() { + setTimeout(bios.boot.preBoot,1000); } }, init:function() { diff --git a/clite/commands.js b/clite/commands.js index a69d836..a106bea 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -3,10 +3,6 @@ clite.commands.data = function() { clite.commands.load('help',function(args,env,io) { var stdio = io.include('stdio'); - if (args.length > 1) { - // TODO: implement command help lookup - stdio.printf('help with arguments is a work in progress\n'); - } stdio.printf(` Welcome to CLIte (pronounced like 'site' with an added L). @@ -133,24 +129,23 @@ Options: dirs.forEach(function(dir,index) { if (dirs.length > 1) stdio.printf('%s:\n',dir); - var fd = stdio.open(dir,stdio.flags.O_RDONLY|stdio.flags.O_SYNC); - if (!fd) { - stdio.fprintf(io.stderr,'cannot open directory: %s\n',dir); - return; - } - var st = stdio.fstatat(fd,stdio.flags.AT_SYMLINK_NOFOLLOW); + var st = stdio.lstat(dir); if (!st) { stdio.fprintf(io.stderr,'cannot read file: %s\n',dir); stdio.close(fd); return; } if (st.type != stdio.types.FT_DIR) { - writeNodeData(st,fd); - stdio.close(fd); + writeNodeData(st,dir); if (!one && !long) stdio.write(io.stdout,'\n'); return; } + var fd = stdio.open(dir,stdio.flags.O_RDONLY|stdio.flags.O_SYNC); + if (!fd) { + stdio.fprintf(io.stderr,'cannot open directory: %s\n',dir); + return; + } var e; while ((e = stdio.read(fd)) != null) { if (e[0] == '.' && !all) diff --git a/clite/core.js b/clite/core.js index 87e72be..10885f8 100644 --- a/clite/core.js +++ b/clite/core.js @@ -57,33 +57,24 @@ var clite = { }, reboot:function() { clite.log.write('The system is rebooting'); - // TODO: this all needs redoing with bios calls setTimeout(function() { - clite.log.write('Bringing down the system'); - var s = Array.from(document.getElementsByTagName('src')); - s.forEach(function(el,i) { - if (i>0) - el.parentNode.removeChild(el); - }); clite.console.clear(); + clite.log.write('Bringing down the system'); clite.log.write('Resetting system core'); var b = clite.state.bios; delete clite; clite = null; - setTimeout(b.boot.preBoot,100); + b.io.write(4,true); },10); }, shutdown:function() { clite.log.write('The system is shutting down'); - // TODO: this all needs redoing with bios calls setTimeout(function() { - var s = Array.from(document.getElementsByTagName('src')); - s.forEach(function(el) { - el.parentNode.removeChild(el); - }); clite.console.clear(); + clite.log.write('Bringing down the system'); delete clite; clite = null; + b.io.write(4,false); },10); }, hostname:function() { @@ -898,6 +889,34 @@ clite.user = { }] }; var env = {}; + function getNextUid() { + let id = data.users.length; + let accepted = false; + while (!accepted) { + accepted = true; + for (var i=0; i