setup for loading "binaries" from plain text

This commit is contained in:
Lisa Milne 2025-08-30 21:28:55 +10:00
parent 717cf09ba2
commit 62d8fedc38
2 changed files with 35 additions and 24 deletions

View file

@ -2354,18 +2354,14 @@ Options:
});
if (window.location.protocol == 'file:')
clite.commands.load('exp',function(args,env,io) {
var stdio = io.include('stdio');
var stdlib = io.include('stdlib');
clite.commands.load('exp',`
var stdio = io.include('stdio');
function main(argc,argv) {
stdio.printf('%d %d %d\n',stdlib.getuid(),stdlib.getgid(),io.pid);
return 0;
}
return main(args.length,args);
});
function main(argc,argv) {
stdio.printf('hello world\\n');
return 0;
}
`);
// insert commands above this line
}

View file

@ -345,7 +345,11 @@ cat /etc/greeting
if (!f)
return;
f.mode = clite.lib.modestr('-rwxr-xr-x');
f.data.content = fn;
if (typeof fn === 'string') {
f.data.content = new Function('args','env','io',fn+';return main(args.length,args);');
}else{
f.data.content = fn;
}
if (typeof suid === 'boolean' && suid == true)
f.mode |= clite.io.modes.S_ISUID;
if (typeof sgid === 'boolean' && sgid == true)
@ -355,7 +359,11 @@ cat /etc/greeting
if (!f)
return;
f.mode = clite.lib.modestr('-rw-rw-r--');
f.data.content = 'function main'+fn.toString().substring(8);
if (typeof fn === 'string') {
f.data.content = fn;
}else{
f.data.content = fn.toString().substring(8);
}
}
}
@ -1648,18 +1656,25 @@ clite.io = {
}
}
}
if (typeof fd.node.data.content != 'string')
return false;
if (typeof data != 'string')
return false;
if (fd.pos + data.length >= fd.node.data.content.length) {
fd.node.data.content = fd.node.data.content.substring(0,fd.pos)+data;
fd.pos = fd.node.data.content.length;
if (typeof data === 'function') {
if (typeof fd.node.data.content !== 'string' && typeof fd.node.data.content !== 'function')
return false;
fd.node.data.content = data;
fd.pos = 0;
}else{
var b = fd.node.data.content.substring(0,fd.pos);
var e = fd.node.data.content.substring(fd.pos+data.length);
fd.node.data.content = b+data+e;
fd.pos += data.length;
if (typeof fd.node.data.content != 'string')
return false;
if (typeof data != 'string')
return false;
if (fd.pos + data.length >= fd.node.data.content.length) {
fd.node.data.content = fd.node.data.content.substring(0,fd.pos)+data;
fd.pos = fd.node.data.content.length;
}else{
var b = fd.node.data.content.substring(0,fd.pos);
var e = fd.node.data.content.substring(fd.pos+data.length);
fd.node.data.content = b+data+e;
fd.pos += data.length;
}
}
fd.node.time.modify = clite.time.sec();
clite.vfs.saveFile(fd.path);