UXExecImpl.mesa
Copyright Ó 1988, 1991 by Xerox Corporation. All rights reserved.
Eduardo Pelegri-Llopart, November 30, 1988 11:57:58 am PST
A terrible and very short-lived hack.
DIRECTORY
Rope,
UXExec,
UXStrings;
UXExecImpl: CEDAR PROGRAM
IMPORTS Rope, UXStrings
EXPORTS UXExec
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
empty: UXStrings.UnixString;
MaxArg: INT ~ UXExec.MaxArg;
Envp: TYPE ~ REF Env;
Env: TYPE ~ RECORD [foo: SEQUENCE COMPUTED NAT OF UXStrings.UnixString];
argv: Envp;
envp: Envp;
ExecVE: PROC [file: UXStrings.UnixString, argv: Envp, env: Envp] ~ TRUSTED MACHINE CODE {
"execve"
};
ExecL: PROC [file: UXStrings.UnixString, arg0: UXStrings.UnixString, arg1: UXStrings.UnixString, arg2: UXStrings.UnixString] ~ TRUSTED MACHINE CODE {
"execl"
};
Execute: PUBLIC PROC [fileRope: Rope.ROPE, commandRope: Rope.ROPE] ~ {
fileString: UXStrings.UnixString ~ UXStrings.Create[from: fileRope];
pos: INT ¬ 0;
length: INT ~ Rope.Length[commandRope];
index: INT ¬ 0;
pos ¬ commandRope.SkipOver[skip: " ", pos: pos];
argv ¬ NEW [Env [ 20 ]];
envp ¬ NEW [Env [ 20 ]];
WHILE pos < length DO
pos1: INT ~ commandRope.SkipTo[skip: " ", pos: pos];
sub: ROPE ~ commandRope.Substr[start: pos, len: pos1-pos];
argString: UXStrings.UnixString ~ UXStrings.Create[from: sub];
TRUSTED {
argv[index] ¬ argString;
};
index ¬ index + 1;
pos ¬ commandRope.SkipOver[skip: " ", pos: pos1];
ENDLOOP;
TRUSTED {
argv[index] ¬ empty;
envp[0] ¬ empty;
};
ExecVE[fileString, argv, envp];
};
UnixFork is NOT exported. Having the nested call breaks things
UnixFork: PROC RETURNS [pid: INT] ~ {
unixFork: PROC RETURNS [pid: INT] ~ TRUSTED MACHINE CODE {
"vfork"
};
RETURN [ unixFork[] ];
};
Wait: PUBLIC PROC [statusp: POINTER TO INT] RETURNS [pid: INT] ~ {
wait: PROC [statusp: POINTER TO INT] RETURNS [pid: INT] ~ TRUSTED MACHINE CODE {
"wait"
};
RETURN[ wait[statusp] ];
};
END.