File: SXTest.mesa
Last Edited by: Beretta, June 17, 1985 5:26:35 pm PDT
gbb January 7, 1986 6:27:25 pm PST
DIRECTORY
CD USING [Rect],
Commander USING [CommandProc, Register],
IO USING [BreakProc, CharClass, EndOf, EndOfStream, Error, GetChar, GetInt, GetLineRope, GetTokenRope, int, Put, PutF, PutFR, Reset, RIS, rope, STREAM],
Process USING [Detach],
Rope USING [Cat, Length, ROPE, SkipOver, Substr],
RopeList USING [Compare, Cons, Sort],
SXQuadTree USING [Store, QuadTreeRoot, Rectangle],
ViewerIO USING [CreateViewerStreams],
ViewerTools USING [FindExistingViewer, InhibitUserEdits, Viewer];
SXTest: CEDAR MONITOR
IMPORTS Commander, IO, Process, Rope, RopeList, SXQuadTree, ViewerIO, ViewerTools =
BEGIN
ROPE: TYPE = Rope.ROPE;
windowCount: INT ← 0; -- a count of the number of test windows created.
counter: INT ← 0; -- general purpose;
quadTree: SXQuadTree.QuadTreeRoot;
MakeTestWindow: ENTRY Commander.CommandProc = BEGIN
Puts up a test window.
title: ROPE;
windowCount ← windowCount+1;
title ← IO.PutFR ["Spinifex maintenance test window # %g", IO.int[windowCount]];
TRUSTED {Process.Detach[FORK Test [title]];}
END;
MakeQTTestWindow: ENTRY Commander.CommandProc = BEGIN
Puts up a test window.
title: ROPE;
windowCount ← windowCount+1;
title ← IO.PutFR ["Spinifex Quad Tree test window # %g", IO.int[windowCount]];
TRUSTED {Process.Detach[FORK QTTest [title]];}
END;
MakeCoreTestWindow: ENTRY Commander.CommandProc = BEGIN
Puts up a test window.
title: ROPE;
windowCount ← windowCount+1;
title ← IO.PutFR ["SX Core test %g", IO.int[windowCount]];
TRUSTED {Process.Detach[FORK CoreTest [title]];}
END;
Test: PROC[title: ROPE] = BEGIN
Creates typescript window separate from CommandTool with given title.
parList: ROPE;
parameters, sortedPar: LIST OF ROPE;
in, out: IO.STREAM;
nothingToDo: BOOL;
[in: in, out: out] ← ViewerIO.CreateViewerStreams[title];
DO  -- Read a parameter list, terminated by a CR:
ENABLE IO.Error =>
IF ec = SyntaxError THEN {
IO.Reset [in];
out.PutF ["\nIncorrect input. Please retype.\n\n"];
LOOP}
ELSE EXIT;
IO.PutF [stream: out,
format: "%lType a parameter list and terminate with CR to sort it:\n%l",
v1: IO.rope["e"], v2: IO.rope["E"]];
parList ← IO.GetLineRope[in];
[parameters, nothingToDo] ← PiecifyParameters [parList];
IF nothingToDo THEN {out.Put [IO.rope["Par list empty\n"]]; LOOP};
sortedPar ← SortParameters [parameters];
parList ← RebuildParList [sortedPar];
IO.PutF [stream: out,
format: "%l\nThe sorted parameter list is:%l\n%g\n\n",
v1: IO.rope["b"], v2: IO.rope["B"], v3: IO.rope[parList]];
ENDLOOP;
END; -- Test
CoreTest: PROC[title: ROPE] = BEGIN
Creates typescript window separate from CommandTool with given title.
in, out: IO.STREAM;
viewer: ViewerTools.Viewer;
[in: in, out: out] ← ViewerIO.CreateViewerStreams [title];
viewer ← ViewerTools.FindExistingViewer [title];
ViewerTools.InhibitUserEdits [viewer]
END; -- CoreTest
QTTest: PROC[title: ROPE] = BEGIN
Creates typescript window separate from CommandTool with given title.
nr: REF INT;
r: CD.Rect;
rect: REF SXQuadTree.Rectangle;
in, out: IO.STREAM;
[in: in, out: out] ← ViewerIO.CreateViewerStreams [title];
DO  -- Read a parameter list, terminated by a CR:
ENABLE IO.Error =>
IF ec = SyntaxError THEN {
IO.Reset [in];
out.PutF ["\nIncorrect input. Please retype.\n\n"];
LOOP}
ELSE EXIT;
IO.PutF [stream: out,
format: "%lType lower left and upper right coordinates and terminate with CR to insert the rectangle:\n%l",
v1: IO.rope["e"], v2: IO.rope["E"]];
r.x1 ← IO.GetInt [in]; r.y1 ← IO.GetInt [in];
r.x2 ← IO.GetInt [in]; r.y2 ← IO.GetInt [in];
counter ← SUCC [counter];
nr ← NEW [INT]; nr^ ← counter;
rect ← NEW [SXQuadTree.Rectangle];
rect.interestBound ← r;
rect.dimDecr ← [0, 0, 0, 0];
rect.nodeInformation ← nr;
quadTree ← SXQuadTree.Store [quadTree, rect];
IO.PutF [stream: out,
format: "\nRectangle %g inserted in quadtree, size: %g, %g; %g, %g.\n\n",
v1: IO.int [counter],
v2: IO.int [quadTree.size.x1],
v3: IO.int [quadTree.size.y1],
v4: IO.int [quadTree.size.x2],
v5: IO.int [quadTree.size.y2]];
ENDLOOP;
END; -- QTTest
PiecifyParameters: PROCEDURE [r: ROPE] RETURNS [rList: LIST OF ROPE, empty: BOOL] =
The rope is piecified into a list of parameters.
BEGIN
ParProc: IO.BreakProc = {RETURN [IF char = ', THEN sepr ELSE other]};
buffer: IO.STREAM ~ IO.RIS [rope: r]; -- reconvert rope into stream
rope: ROPE;
length, nonSpace: INT;
-- Skip leading parenthesis
IF IO.GetChar [buffer] # '{ THEN ERROR;
empty ← IO.EndOf [buffer];
DO-- rip off subrope until next comma and add to list of ropes
BEGIN
rope ← IO.GetTokenRope[stream: buffer,
breakProc: ParProc
! IO.EndOfStream => GOTO eos].token;
nonSpace ← Rope.SkipOver [s: rope, pos: 0, skip: " "];
length ← Rope.Length [base: rope];
IF (nonSpace < length) AND (nonSpace > 0) THEN
rope ← Rope.Substr[base: rope, start: nonSpace, len: length-nonSpace];
rList ← RopeList.Cons [list: rList, r: rope];
EXITS
eos => RETURN [rList, empty]
END
ENDLOOP;
END; -- PiecifyParameters
SortParameters: PROCEDURE [unsorted: LIST OF ROPE] RETURNS [sorted: LIST OF ROPE] =
Sorts the list of ropes
BEGIN
sorted ← RopeList.Sort[list: unsorted, compareProc: RopeList.Compare]
END; -- SortParameters
RebuildParList: PROCEDURE [list: LIST OF ROPE] RETURNS [rope: ROPE] =
Rebuilds the parameters list from the list of parameters
BEGIN
rope ← "{";
rope ← Rope.Cat [r1: "{", r2: list.first];
FOR l: LIST OF ROPE ← list.rest, l.rest WHILE l # NIL DO
rope ← Rope.Cat [r1: rope, r2: ", ", r3: l.first]
ENDLOOP;
END; -- RebuildParList
Commander.Register [key: "Test", proc: MakeTestWindow, doc: "A simple Spinifex test program"];
Commander.Register [key: "QTTest", proc: MakeQTTestWindow, doc: "Spinifex quad tree test program"];
Commander.Register [key: "CoreTest", proc: MakeCoreTestWindow, doc: "Prints the contents of the current core sesign created by Spinifex"];
END.