<> <> <> <<>> DIRECTORY Graph USING [CaretIndex, Entity, EntityGroup, EntityGroupList, EntityHashSize, EntityList, GraphHandle, LastEntityColor, NestedEntities, NestedEntitiesList, SegmentDataList, Texts, ValueList, XY], GraphCleanUp, GraphPrivate USING [defaultColors, defaultFonts], ViewerOps USING [DestroyViewer]; GraphCleanUpImpl: CEDAR PROGRAM IMPORTS GraphPrivate, ViewerOps EXPORTS GraphCleanUp = { OPEN Graph, GraphPrivate; CleanUpHandle: PUBLIC PROC [handle: GraphHandle _ NIL, full: BOOL _ FALSE] RETURNS [GraphHandle] = { <> <> <> RETURN[IF handle = NIL THEN NIL ELSE IF full THEN DestroyHandle[handle] ELSE RemoveFat[handle] ] }; -- CleanUpHandle RemoveFat: PROC [handle: GraphHandle _ NIL] RETURNS [GraphHandle] = { IF handle # NIL THEN { OPEN handle; allTexts _ CleanUpTexts[allTexts, TRUE]; entityGroupList _ CleanUpEGL[entityGroupList, TRUE]; FOR i: INT IN [0..EntityHashSize) DO entityHash[i] _ CleanUpEL[entityHash[i], FALSE]; ENDLOOP; <> FOR i: CaretIndex IN CaretIndex DO chart.caretState[i]^ _ []; ENDLOOP; chart^ _ [viewer: chart.viewer, caretState: chart.caretState]; <<>> <> IF controller # NIL THEN { ViewerOps.DestroyViewer[controller.table]; controller.table _ NIL; }; <<>> <> graph.entityList _ CleanUpEL[graph.entityList, FALSE]; FOR i: CaretIndex IN CaretIndex DO graph.caret[i]^ _ []; ENDLOOP; FOR i: XY IN XY DO graph.target[i]^ _ []; ENDLOOP; graph.color^ _ defaultColors^; graph.font^ _ defaultFonts^; graph^ _ [caret: graph.caret, target: graph.target, color: graph.color, font: graph.font]; lastEntityColor _ LastEntityColor; lastTextId _ lastEntityId _ -1; zoomPt1 _ []; zoomPt2 _ []; waitingGraph _ FALSE; <> <> <> }; RETURN[handle]; }; -- RemoveFat DestroyHandle: PROC [handle: GraphHandle _ NIL] RETURNS [GraphHandle] = { IF handle # NIL THEN { OPEN handle; allTexts _ CleanUpTexts[allTexts, TRUE]; entityGroupList _ CleanUpEGL[entityGroupList, TRUE]; FOR i: INT IN [0..EntityHashSize) DO entityHash[i] _ CleanUpEL[entityHash[i], FALSE]; ENDLOOP; entityHash _ NIL; <> FOR i: CaretIndex IN CaretIndex DO chart.caretState[i]^ _ []; ENDLOOP; chart^ _ []; chart _ NIL; <<>> <> IF controller # NIL THEN { controller^ _ []; controller _ NIL; }; <<>> <> FOR i: CaretIndex IN CaretIndex DO graph.caret[i]^ _ []; ENDLOOP; FOR i: XY IN XY DO graph.target[i]^ _ []; ENDLOOP; graph.font^ _ ALL[]; graph^ _ []; graph _ NIL; imagerFonts _ ALL[NIL]; paintInfo _ NIL; handle _ NIL; }; RETURN[handle]; }; -- DestroyHandle CleanUpVL: PUBLIC PROC [vl: ValueList] RETURNS [ValueList] = { WHILE vl # NIL DO next: ValueList _ vl.rest; vl.rest _ NIL; vl _ next; ENDLOOP; RETURN[vl]; }; -- CleanUpVL CleanUpSDL: PUBLIC PROC [sdl: SegmentDataList] RETURNS [SegmentDataList] = { WHILE sdl # NIL DO next: SegmentDataList _ sdl.rest; sdl.first _ NIL; sdl.rest _ NIL; sdl _ next; ENDLOOP; RETURN[sdl]; }; -- CleanUpSDL <> CleanUpEGL: PROC [egl: EntityGroupList, everything: BOOL _ FALSE] RETURNS [EntityGroupList] = { WHILE egl # NIL DO next: EntityGroupList _ egl.rest; egl.first _ CleanUpEG[egl.first, everything]; egl.rest _ NIL; egl _ next; ENDLOOP; RETURN[egl]; }; -- CleanUpEGL CleanUpEG: PROC [eg: EntityGroup, everything: BOOL _ FALSE] RETURNS [EntityGroup] = { IF everything THEN { eg.x _ CleanUpEntity[eg.x]; eg.ys _ CleanUpNE[eg.ys, TRUE]; } ELSE eg^ _ []; eg _ NIL; RETURN[eg]; }; -- CleanUpEG CleanUpNEL: PROC [nel: NestedEntitiesList, everything: BOOL _ FALSE] RETURNS [NestedEntitiesList] = { WHILE nel # NIL DO next: NestedEntitiesList _ nel.rest; IF everything THEN nel.first _ CleanUpNE[nel.first, TRUE] ELSE nel.first _ NIL; nel.rest _ NIL; nel _ next; ENDLOOP; RETURN[nel]; }; -- CleanUpEGL CleanUpNE: PROC [ne: NestedEntities, everything: BOOL _ FALSE] RETURNS [NestedEntities] = { IF everything THEN { [] _ CleanUpEL[ne.entityList, TRUE]; [] _ CleanUpNEL[ne.children, TRUE]; }; ne^ _ []; ne _ NIL; RETURN[ne]; }; -- CleanUpNE CleanUpEL: PUBLIC PROC [el: EntityList, everything: BOOL _ FALSE] RETURNS [EntityList] = { WHILE el # NIL DO next: EntityList _ el.rest; IF everything THEN el.first _ CleanUpEntity[el.first] ELSE el.first _ NIL; el.rest _ NIL; el _ next; ENDLOOP; RETURN[el]; }; -- CleanUpEL CleanUpEntity: PROC [entity: Entity] RETURNS [Entity] = { IF entity # NIL THEN { entity.segments _ CleanUpSDL[entity.segments]; entity^ _ []; entity _ NIL; }; RETURN[entity]; }; -- CleanUpEntity CleanUpTexts: PUBLIC PROC [texts: Texts, everything: BOOL _ FALSE] RETURNS [Texts] = { WHILE texts # NIL DO next: Texts _ texts.rest; IF everything THEN texts.first^ _ []; texts.first _ NIL; texts.rest _ NIL; texts _ next; ENDLOOP; RETURN[texts]; }; -- CleanUpTexts }. LOG. Previous version erased 10/16/85 by a vandal. SChen, October 16, 1985 1:35:55 pm PDT, recreated.