mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
setup for exec() and multi-process
This commit is contained in:
parent
d5bb8fd814
commit
cbf30ffa40
1 changed files with 32 additions and 2 deletions
|
|
@ -1726,6 +1726,7 @@ clite.lib = {
|
|||
}
|
||||
if (s.length > 0)
|
||||
parts.push(s);
|
||||
// TODO: resolve all paths passed as arguments? - catches ~ and * etc
|
||||
return parts;
|
||||
},
|
||||
getFileType:function(fd) {
|
||||
|
|
@ -1776,7 +1777,7 @@ clite.lib = {
|
|||
return clite.io.types.FT_UNKOWN;
|
||||
},
|
||||
getBuffer:function() {
|
||||
return Object.create({
|
||||
var buff = Object.create({
|
||||
buffer:{
|
||||
data:'',
|
||||
pos:0
|
||||
|
|
@ -1788,14 +1789,42 @@ clite.lib = {
|
|||
var i = b.indexOf('\n');
|
||||
if (b < 0)
|
||||
return b;
|
||||
this.buffer.pos += i;
|
||||
return b.substring(0,i);
|
||||
},
|
||||
write:function(txt) {
|
||||
this.buffer.data += txt;
|
||||
}
|
||||
});
|
||||
return buff;
|
||||
},
|
||||
exec:function(args,io) {
|
||||
fork:function(io) {
|
||||
},
|
||||
exec:function(path,args,io) {
|
||||
var fd = clite.io.open(path);
|
||||
if (!fd) {
|
||||
clite.term.writeLine('Shell: unknown command: '+args[0]);
|
||||
io.exit(-1);
|
||||
return false;
|
||||
}
|
||||
|
||||
var pid = clite.proc.add(args.join(' '),fd.node.data.content);
|
||||
io.exit = function(v) {
|
||||
clite.shell.exit(pid,v);
|
||||
}
|
||||
|
||||
var r = clite.core.execSafe(function() {
|
||||
var rr = fd.node.data.content(args,Object.create(clite.shell.env),io);
|
||||
if (typeof rr == 'number')
|
||||
io.exit(rr);
|
||||
});
|
||||
if (!r) {
|
||||
clite.term.writeLine('Shell: error in command:'+args[0]);
|
||||
io.exit(-2);
|
||||
return false;
|
||||
}
|
||||
clite.io.close(fd);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
clite.lib.api = { // this is passed to programs via include('stdlib')
|
||||
|
|
@ -1804,5 +1833,6 @@ clite.lib.api = { // this is passed to programs via include('stdlib')
|
|||
resolvePath:clite.lib.resolvePath,
|
||||
getFileType:clite.lib.getFileType,
|
||||
strToArgs:clite.lib.strToArgs,
|
||||
fork:clite.lib.fork,
|
||||
exec:clite.lib.exec
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue