-- TTT.mesa -- Last Modified On November 30, 1982 2:21 pm By Paul Rovner DIRECTORY Convert, IO, Process USING[Detach], Rope, AMModel, WorldVM; TTT: PROGRAM IMPORTS Convert, IO, Process, Rope, AMModel, WorldVM = BEGIN OPEN Rope, AMModel; stream: IO.Handle; in: IO.Handle; stopEverything: BOOL _ FALSE; DelWatcher: SAFE PROC = TRUSTED {DO [] _ in.GetChar[ ! ANY => {stopEverything _ TRUE; EXIT}] ENDLOOP; }; root: Context = RootContext[WorldVM.LocalWorld[]]; --root: Context = RootContext[WorldVM.GetWorld["Jeeves"]]; PrintContextTree: PROC[root: Context, indentation: INT] = { proc: PROC[context: Context] RETURNS[stop: BOOL _ FALSE] = {IF stopEverything THEN RETURN[TRUE]; FOR i: INT IN [1..indentation] DO stream.PutRope[" "]; ENDLOOP; stream.PutRope["Context named "]; stream.PutRope[ContextName[context]]; stream.PutRope[", class = "]; SELECT ContextClass[context] FROM model => stream.PutRope["model"]; prog => stream.PutRope["prog"]; ENDCASE => ERROR; stream.PutRope["\n"]; PrintContextTree[context, indentation + 4]; }; -- START PrintContextTree HERE [] _ ContextChildren[root, proc]; }; PrintRootSections: PROC[root: Context, indentation: INT] = { proc: PROC[context: Context] RETURNS[stop: BOOL _ FALSE] = {section: Section; IF stopEverything THEN RETURN[TRUE]; section _ ContextSection[context]; FOR i: INT IN [1..indentation] DO stream.PutRope[" "]; ENDLOOP; stream.PutRope["Top-level section named "]; stream.PutRope[SectionName[section]]; stream.PutRope["\n"]; PrintSectionTree[section, indentation + 4]}; -- START PrintRootSections HERE [] _ ContextChildren[root, proc]; }; SourceRangeRope: PROC[source: Source] RETURNS[ans: ROPE _ NIL] = { WITH s: source SELECT FROM entire => ans _ "( Entire File )"; field => ans _ Rope.Cat["( first: ", Convert.ValueToRope[[signed[s.firstCharIndex]]], ", last: ", Convert.ValueToRope[[signed[s.lastCharIndex]]], " )"]; ENDCASE => ERROR; }; PrintSectionTree: PROC[root: Section, indentation: INT] = {proc: PROC[section: Section] RETURNS[stop: BOOL _ FALSE] = {sectionName: ROPE _ NIL; IF stopEverything THEN RETURN[TRUE]; FOR i: INT IN [1..indentation] DO stream.PutRope[" "]; ENDLOOP; stream.PutRope["Section named "]; sectionName _ SectionName[section ! ANY => CONTINUE]; stream.PutRope[IF sectionName = NIL THEN "--{can't get section name}--" ELSE sectionName]; stream.PutRope[", class = "]; SELECT SectionClass[section] FROM model => stream.PutRope["model"]; prog => stream.PutRope["prog"]; interface => stream.PutRope["interface"]; proc => stream.PutRope["proc"]; statement => {stream.PutRope["statement, source range: "]; stream.PutRope[SourceRangeRope[SectionSource[section]]]}; ENDCASE => ERROR; stream.PutRope["\n"]; PrintSectionTree[section, indentation + 4]}; -- START PrintSectionTree HERE [] _ SectionChildren[root, proc]; }; -- START HERE [in: in, out: stream] _ IO.CreateViewerStreams["TTT.log"]; stream.PutRope["Children of the root context ( "]; stream.PutRope[ContextName[root]]; stream.PutRope[" ) ...\n"]; Process.Detach[FORK DelWatcher[]]; PrintContextTree[root, 4]; --PrintRootSections[root, 4]; END.