<> <> <> <> DIRECTORY TerminalIO, CD, CDSequencer, CDOps, CDCommandOps, CDBasics, CDMenus USING [CreateEntry], IO; CDCountCommands: CEDAR PROGRAM IMPORTS TerminalIO, CD, CDMenus, CDSequencer, CDOps, CDCommandOps, IO = BEGIN <<--the global variables mare monitored using CDCommandOps.CallWithResource;>> <<--these variables are global so they can be used by MyDrawChild>> stopFlag: REF BOOLEAN = NEW[BOOLEAN]; rectCounter: INT; childCounter: INT; MyDrawChild: CD.DrawProc = BEGIN childCounter _ childCounter+1; inst.ob.class.drawMe[inst: inst, pos: inst.location, orient: inst.orientation, pr: pr]; END; MyDrawRect: CD.DrawRectProc = BEGIN rectCounter _ rectCounter+1; END; ProtectedCount: PROCEDURE [comm: CDSequencer.Command] = BEGIN myDrawRef: CD.DrawRef _ CD.CreateDrawRef[[ interestClip: CDBasics.universe, drawChild: MyDrawChild, drawRect: MyDrawRect, design: comm.design ]]; rectCounter _ childCounter _ 0; CDOps.DrawDesign[design: comm.design, pr: myDrawRef]; myDrawRef _ NIL; TerminalIO.WriteRope[IO.PutFR["rectangles %g objects %g\n", IO.int[rectCounter], IO.int[childCounter] ]]; END; <<>> CountComm: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Count rectangles\n"]; [] _ CDCommandOps.CallWithResource[ProtectedCount, comm, $myDrawRef, stopFlag]; END; CDMenus.CreateEntry[menu: $ProgramMenu, entry: "count rectangles", key: $CountRects]; CDSequencer.ImplementCommand[$CountRects, CountComm,, dontQueue]; END.