AlgebraCmd: Commander.CommandProc ~ {
PROC [cmd: Handle] RETURNS [result: REF ← NIL, msg: ROPE ← NIL]
fullCIFFName, fullRulesFName, cellName: ROPE;
fileName: ROPE ← NIL;
ropeStream: IO.STREAM ← IO.RIS[cmd.commandLine];
IF lock
THEN {
msg ← "\nWait for the previous Remote Algebra to finish !\nJob not sent.\n";
RETURN;
};
lock ← TRUE;
fileName ← FSExpandFromStream[ropeStream];
fullRulesFName ← FSExpandFromStream[ropeStream];
cellName ← IO.GetTokenRope[ropeStream, IO.IDProc ! IO.EndOfStream => CONTINUE].token;
msg ← ExecuteRemoteAlgebra[fileName];
IF msg#NIL THEN lock ← FALSE; -- n.b. releases the lock if error from BridgeDriver.StartSession
};
ExecuteRemoteAlgebra:
PUBLIC
PROC [fileName:
ROPE]
RETURNS [errmsg:
ROPE] ~ {
name, password, machine, algebraCmd, CIFFName, RulesFName: ROPE;
magicString: ROPE ← "RBatch\ncd /user/csl/arnon; csh .login; cd /user/csl/arnon/Sturgis; /user/csl/arnon/Sturgis/algebra ";
name, password, machine, algebraCmd: ROPE;
[name, password] ← UserCredentials.Get[];
name ← Rope.Substr[name, 0, Rope.Index[name, 0, "."]]; -- get rid of the ".pa"
name ← Rope.Translate[base: name, translator: MyLower];
machine ← Rope.Cat[ThisMachine.Name[], " "];
CIFFName ← PrepareFFName[fullCIFFName];
RulesFName ← PrepareFFName[fullRulesFName];
algebraCmd ← Rope.Cat[magicString, machine, CIFFName, RulesFName, cellName];
algebraCmd ← Rope.Cat[magicString, machine, PrepareFFName[fileName] ];
errmsg ← BridgeDriver.StartSession["vaxc", name, password, algebraCmd];
};
SAC2PolynomialBinaryOp: PUBLIC PROC [varSeq, firstArg, secondArg: ROPE] RETURNS [result: IO.STREAM] ~ {
errmsg: ROPE;
name, password, machine, algebraCmd: ROPE;
magicString: ROPE ← "RBatch\ncd /user/csl/arnon; csh .login; cd /user/csl/arnon/INTRPTR; /user/csl/arnon/INTRPTR/RunInterpreter ";
intialScript: ROPE ← "V \n #v \n E \n #1 $ \n E \n #2 $ \n G 1 2 \n W \n L 3 \n \n H \n Q \n";
fileName: ROPE ← "SacPolyBinaryOp.inData";
out: IO.STREAM ← FS.StreamOpen[fileName: fileName, accessOptions: $create,wDir: FSExtras.GetWDir[] ]; -- also could use CommandTool.FileNames interface; in any event, FSExtras.GetWDir seems to just be returning /// as WD, i.e. trivial effect. Probably result of call not coming from a Commander.CommandProc
fullFName: ROPE ← FS.ExpandName[fileName].fullFName;
finalScript: ROPE ← intialScript;
position: INT ← -1;
position ← Rope.Find[finalScript, "#v"];
finalScript ← Rope.Replace[base: finalScript, start: position, len: Rope.Length["#v"], with: varSeq];
position ← Rope.Find[finalScript, "#1"];
finalScript ← Rope.Replace[base: finalScript, start: position, len: Rope.Length["#1"], with: firstArg];
position ← Rope.Find[finalScript, "#2"];
finalScript ← Rope.Replace[base: finalScript, start: position, len: Rope.Length["#2"], with: secondArg];
out.PutRope[finalScript];
out.Close[];
[name, password] ← UserCredentials.Get[];
name ← Rope.Substr[name, 0, Rope.Index[name, 0, "."]]; -- get rid of the ".pa"
name ← Rope.Translate[base: name, translator: MyLower];
machine ← Rope.Cat[ThisMachine.Name[], " "];
fullFName ← StripExtension[fullFName, ".inData"];
algebraCmd ← Rope.Cat[magicString, machine, PrepareFFName[fullFName] ];
UNTIL lock=FALSE DO ENDLOOP; -- wait until previous request finishes
lock ← TRUE;
errmsg ← BridgeDriver.StartSession["vaxc", name, password, algebraCmd];
IF errmsg#NIL THEN {
lock ← FALSE; -- n.b. releases the lock if error from BridgeDriver.StartSession
RETURN[NIL];
};
UNTIL lock=FALSE DO ENDLOOP; -- wait
RETURN[globalOutputStream];
};