add uname() to stdlib, and add uname command

This commit is contained in:
Lisa Milne 2023-11-24 16:08:39 +10:00
parent 0d35fbf4a1
commit 3b9fe3fd6b
3 changed files with 114 additions and 7 deletions

View file

@ -555,5 +555,89 @@ Options:
return 0;
});
clite.commands.load('uname',function(args,env,io) {
var stdlib = io.include('stdlib');
var sysname = false;
var nodename = false;
var release = false;
var version = false;
var machine = false;
function help() {
io.write(`
uname - print system information
Options:
-a All, equivalent to -mnrsv
-m Print the hardware info (User Agent)
-n Print the network name
-r Print the operating system release
-s Print the operating system name
-v Print the operating system version
-? Print this help information
`);
}
for (var i=1; i<args.length; i++) {
if (args[i][0] == '-') {
for (var j=1; j<args[i].length; j++) {
switch (args[i][j]) {
case '?':
help();
return 0;
break;
case 'a':
machine = true;
nodename = true;
release = true;
sysname = true;
version = true;
break;
case 'm':
machine = true;
break;
case 'n':
nodename = true;
break;
case 'r':
release = true;
break;
case 's':
sysname = true;
break;
case 'v':
version = true;
break;
default:
io.error('unknown argument: -'+args[i][j]);
}
}
}else{
io.error('unknown argument: '+args[i]);
}
}
if (!machine && !nodename && !release && !sysname && !version)
sysname = true;
var ut = stdlib.uname();
var txt = '';
if (sysname)
txt += ut.sysname+' ';
if (nodename)
txt += ut.nodename+' ';
if (release)
txt += ut.release+' ';
if (version)
txt += ut.version+' ';
if (machine)
txt += ut.machine;
io.write(txt);
return 0;
});
// insert commands above this line
}

View file

@ -1,6 +1,6 @@
var clite = {
state:{
version:'0.1-14',
version:'0.1-15',
isinit:false
},
core:{
@ -225,10 +225,11 @@ guest:x:1:1:guest:/usr/home/guest:/bin/sh
if (window.location.protocol == 'file:') {
// work around the file: problems by just not loading files, here's a temporary filesystem
var d = `
clite/core.js:/usr/clite/core.js:0:0:-rw-r-----
clite/core.css:/usr/clite/web/core.css:0:0:-rw-r-----
clite/core.js:/usr/clite/core.js:0:0:-rw-r--r--
clite/core.css:/usr/clite/web/core.css:0:0:-rw-r--r--
data/intro.txt:/usr/share/introduction:0:0:-rw-rw-r--
data/about.txt:/usr/share/site/about:0:0:-rw-rw-r--`;
data/about.txt:/usr/share/site/about:0:0:-rw-rw-r--
readme.txt:/usr/clite/readme:0:0:-rw-r--r--`;
init2(d);
return;
}
@ -1895,6 +1896,15 @@ clite.lib = {
});
return buff;
},
uname:function() {
return Object.create({
sysname:'CLIte',
nodename:'localhost',
release:clite.state.version,
version:clite.state.version,
machine:navigator.userAgent
});
},
fork:function(env,io,call) {
var pid = clite.proc.add(call);
if (!pid)
@ -1932,6 +1942,7 @@ clite.lib.api = { // this is passed to programs via include('stdlib')
dirname:clite.lib.dirname,
resolvePath:clite.lib.resolvePath,
strToArgs:clite.lib.strToArgs,
uname:clite.lib.uname,
fork:clite.lib.fork,
exec:clite.lib.exec
};

View file

@ -9,8 +9,8 @@ CLIte is licensed under the GNU Affero General Public License, V3.
A functioning test instance of CLIte is available at
http://www.ltmnet.com/clite/index.html
CLite has also been designed, with some work-arounds, to work locally
without a web server. Just download or clone the git repository
CLite has also been designed, with some work-arounds and bugs, to work
locally without a web server. Just download or clone the git repository
locally and open index.html in your browser.
The following commands are currently available in the CLIte shell:
@ -34,6 +34,8 @@ file - determines the file type
reboot - reboots the system, this will force-reload all javascript, so
helps get around issues with browser cache
uname - prints system information
Under Development:
view - file viewer, should display files something like the way a
@ -83,7 +85,7 @@ clite.commands.load('name',function(args,env,io) {
The load function is only available during boot time, and will:
1. load the program into the vfs at /bin/name
2. load the source of the program into the vfs at /usr/src/name
2. load the source of the program into the vfs at /usr/src/name.js
The function in the second argument is roughly equivalent to main() in C.
This function takes 3 arguments:
@ -158,6 +160,16 @@ stdlib: io.include('stdlib')
for passing to exec(), supports quotes and so on:
'ls -l /var' -> ['ls','-l','var']
uname()
returns an object containing system information:
{
sysname:'CLIte', // system name, always 'CLIte'
nodename:'localhost', // network hostname, currently always 'localhost'
release:'0.1...', // contains the current CLIte version as stored in clite.state.version
version:'0.1...', // same as release
machine:navigator.userAgent // contains the browser user agent string
}
fork(env,io,call)
Creates a new process, with environment and io data passed to it.
Returns the pid of the new process, or 0 on failure.