SpiceCDCmds.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Created by Pradeep Sindhu, March 31, 1986 6:25:43 pm PST
Pradeep Sindhu, April 29, 1986 0:19:46 am PDT
Bertrand Serlet October 17, 1986 10:46:42 pm PDT
Christian Jacobi, January 7, 1987 2:58:17 pm PST
Christian LeCocq March 5, 1987 5:34:09 pm PST
DIRECTORY
Ascii, BasicTime, BridgeDriver, CD, CDCells, CDCommandOps, CDIO, CDOps, CDSequencer, CedarProcess, Core, CoreOps, FSBackdoor, HashTable, IO, Rope, SinixOps, Sisyph, UserCredentials, TerminalIO, SpiceOps;
SpiceCDCmds:
CEDAR
PROGRAM
IMPORTS Ascii, BasicTime, BridgeDriver, CDCells, CDCommandOps, CDIO, CDOps, CedarProcess, CoreOps, HashTable, FSBackdoor, IO, Rope, SinixOps, Sisyph, UserCredentials, TerminalIO, SpiceOps
EXPORTS SpiceOps
~ BEGIN
ROPE: TYPE = Rope.ROPE;
waitingProcess: CedarProcess.Process;
pendingSimulations: PUBLIC HashTable.Table;
stop: BOOL ← FALSE;
magicString: ROPE ← "RBatch\ncd spice ;spice ";
magicString2: ROPE ← " rw ";
criterion: ROPE ← "*.spo!*";
simNumber: PUBLIC LONG CARDINAL;
Command Procs
ExtractSelectedObjAndSpiceIt:
PROC [comm: CDSequencer.Command] = {
selected: CD.Instance;
multiple: BOOL;
wDir: ROPE ← CDIO.GetWorkingDirectory[comm.design];
shortFN, fileName, msg: ROPE;
cellType: Core.CellType;
[selected, multiple] ← CDOps.SelectedInstance[comm.design];
IF ~IsSingleSelectedAndCell[selected, multiple] THEN RETURN;
cellType ← NARROW [SinixOps.ExtractCDInstance[selected, comm.design, Sisyph.mode].result];
WHILE SinixOps.IsIcon[Sisyph.mode.decoration, cellType]
DO
cellType ← CoreOps.Recast[cellType];
ENDLOOP;
IF CoreOps.GetCellTypeName[cellType]=
NIL
THEN shortFN ← "SpiceInputDeck"
ELSE shortFN ← CoreOps.GetCellTypeName[cellType];
fileName ← Rope.Cat[wDir, shortFN, ".spice"];
SpiceOps.WriteSpiceDeck[cellType, fileName];
msg ← ExecuteRemoteSpice[shortFN];
TerminalIO.PutRopes[fileName, ": ", IF msg#NIL THEN msg ELSE "sended to remote host"]
};
ExecuteRemoteSpice:
PUBLIC
PROC [fileName:
ROPE]
RETURNS [errmsg:
ROPE] ~ {
name, password, spiceCmd: 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];
spiceCmd ← Rope.Cat[magicString, fileName, magicString2];
errmsg ← BridgeDriver.StartSession["vaxc", name, password, spiceCmd];
};
MyLower: Rope.TranslatorType ~ {
RETURN[Ascii.Lower[old]]};
StartWatching:
PROC ~ {
IF waitingProcess=
NIL
OR CedarProcess.GetStatus[waitingProcess]#busy
THEN
waitingProcess ← CedarProcess.Fork[WaitForListings, criterion];
};
Internal Utilities
IsSingleSelectedAndCell:
PROC [selected:
CD.Instance, multiple:
BOOL]
RETURNS [
BOOL] = {
IF ~IsSingleSelected[selected, multiple] THEN RETURN [FALSE];
IF ~CDCells.IsCell[selected.ob]
THEN {
TerminalIO.PutRope["\n** Selected instance is not a cell—can't do it.\n"];
RETURN[FALSE];
};
RETURN[TRUE];
};
IsSingleSelected:
PROC [selected:
CD.Instance, multiple:
BOOL]
RETURNS [
BOOL] = {
IF selected=
NIL
THEN {
TerminalIO.PutRope["\n** No current selection--can't do it.\n"];
RETURN[FALSE];
};
IF multiple
THEN {
TerminalIO.PutRope["\n** Multiple instances selected--can't do it.\n"];
RETURN[FALSE];
};
RETURN[TRUE];
};
WaitForListings: CedarProcess.ForkableProc ~ {
PROC [data: REF] RETURNS [results: REF ← NIL]
Wait until a file having a name matching the criterion is created, then call the call-back proc
matchCriterion: ROPE ← NARROW[data];
event: REF READONLY FSBackdoor.CreateEvent ← NIL;
UNTIL stop
DO
event ← FSBackdoor.NextCreateEvent[event];
IF Rope.Match[pattern: matchCriterion, object: event.fName, case:
FALSE]
THEN {
SpiceOps.DisplaySpiceListing[event.fName ! IO.Error, IO.EndOfStream => {TerminalIO.PutRopes[event.fName, " is not coherent\n"]; CONTINUE;}];
};
ENDLOOP;
};
Initialization
pendingSimulations ← HashTable.Create[equal: HashTable.RopeEqual, hash: HashTable.HashRope];
simNumber ← LOOPHOLE[BasicTime.Now[], LONG CARDINAL];
CDCommandOps.RegisterWithMenu[menu: $OtherProgramMenu, entry: "Sisyph -> Spice", proc: ExtractSelectedObjAndSpiceIt, key: $ExtractToSpice];
StartWatching[];
END.