<<-- AnnotateProperties.mesa>> <<-- written by Beach, May 1982>> <<-- last written by Paxton July 9, 1982 1:52 pm>> <<-- last written by McGregor September 10, 1982 2:18 pm>> <> DIRECTORY Atom USING [GetPName], CIFS USING [Error], EditSpan USING [CannotDoEdit, Delete, InsertTextNode], IO, NodeProps USING [GetProp, GetSpecs, MapProps, MapPropsAction, PutProp, true], PutGet USING [FromFile, ToFile], Rope USING [Cat, Equal, Find, ROPE, Size], TextEdit USING [AppendRope], TextNode USING [FirstChild, Forward, MakeNodeSpan, Ref, RefTextNode], UserExec USING [CommandProc, ExecHandle, GetStreams, HistoryEvent, RegisterCommand], WindowManager USING [UnWaitCursor, WaitCursor]; AnnotateProperties: CEDAR PROGRAM IMPORTS Atom, CIFS, EditSpan, IO, NodeProps, PutGet, Rope, TextEdit, TextNode, UserExec, WindowManager = { rootNode: TextNode.Ref; annotationNode: TextNode.RefTextNode; commentAtom: ATOM = $Comment; propertyAnnotationAtom: ATOM = $PropertyAnnotation; trueRope: Rope.ROPE = "TRUE"; AnnotatePropertiesCommand: UserExec.CommandProc = { RETURN[DoAnnotations[exec, event, TRUE]] }; PruneAnnotationsCommand: UserExec.CommandProc = { RETURN[DoAnnotations[exec, event, FALSE]] }; DoAnnotations: PROC [exec: UserExec.ExecHandle, event: UserExec.HistoryEvent, annotate: BOOLEAN _ TRUE] RETURNS[ok: BOOLEAN _ TRUE] = { ENABLE UNWIND => WindowManager.UnWaitCursor[]; execOut: IO.STREAM = UserExec.GetStreams[exec].out; filename: Rope.ROPE; tabIndent: NAT _ 8; WindowManager.WaitCursor[]; DO -- process each file in command line filename _ IO.GetRope[event.commandLineStream]; IF Rope.Size[filename]=0 THEN EXIT; IF Rope.Find[filename,"."] = -1 THEN -- add .mesa extension filename _ Rope.Cat[filename,".mesa"]; { ENABLE CIFS.Error => { execOut.PutRope[filename]; execOut.PutRope[" not found.\n"]; ok _ FALSE; LOOP }; rootNode _ PutGet.FromFile[filename]; }; IF annotate THEN AddAnnotationNodes[] ELSE PruneAnnotationNodes[]; [] _ PutGet.ToFile[filename, rootNode]; ENDLOOP; WindowManager.UnWaitCursor[]; execOut.PutRope[" Done."]; RETURN[ok]; }; AddAnnotationNodes: PROCEDURE = { next: TextNode.Ref; level, levelDelta: INTEGER _ 1; IF AnAnnotationNode[TextNode.FirstChild[rootNode]] THEN RETURN; CreateRootAnnotationNode[]; [next, levelDelta] _ TextNode.Forward[TextNode.FirstChild[rootNode]]; WHILE next#NIL DO level _ level+levelDelta; CreateAnnotationNode[next, level]; [next, levelDelta] _ TextNode.Forward[next]; ENDLOOP; }; PruneAnnotationNodes: PROCEDURE = { next, prev: TextNode.Ref; [next, ] _ TextNode.Forward[rootNode]; WHILE next#NIL DO IF AnAnnotationNode[next] THEN { prev _ next; [next, ] _ TextNode.Forward[next]; EditSpan.Delete[root: rootNode, del: TextNode.MakeNodeSpan[prev, prev], saveForPaste: FALSE ! EditSpan.CannotDoEdit => CONTINUE]} ELSE [next, ] _ TextNode.Forward[next]; ENDLOOP; }; AnAnnotationNode: PROC [node: TextNode.Ref] RETURNS[BOOLEAN] = { propValue: REF; IF node#NIL THEN IF (propValue _ NodeProps.GetProp[node, propertyAnnotationAtom])#NIL THEN IF Rope.Equal[trueRope, NodeProps.GetSpecs[propertyAnnotationAtom, propValue]] THEN RETURN[TRUE]; RETURN[FALSE]; }; CreateRootAnnotationNode: PROCEDURE = { annotationNode _ EditSpan.InsertTextNode[rootNode, rootNode, child]; [] _ TextEdit.AppendRope[rootNode, annotationNode, "<>"]; NodeProps.PutProp[annotationNode, propertyAnnotationAtom, trueRope]; NodeProps.PutProp[annotationNode, commentAtom, NodeProps.true]; }; CreateAnnotationNode: PROCEDURE [thisNode: TextNode.Ref, level: INTEGER] = { annotationNode _ EditSpan.InsertTextNode[rootNode, thisNode, before]; [] _ TextEdit.AppendRope[rootNode, annotationNode, IO.PutFToRope["<>"]; NodeProps.PutProp[annotationNode, propertyAnnotationAtom, trueRope]; NodeProps.PutProp[annotationNode, commentAtom, NodeProps.true]; }; AnnotateProps: NodeProps.MapPropsAction = { nodeRope: Rope.ROPE _ Rope.Cat[", ", Atom.GetPName[name], ": ", NodeProps.GetSpecs[name, value]]; [] _ TextEdit.AppendRope[rootNode, annotationNode, nodeRope]; RETURN[FALSE]}; UserExec.RegisterCommand["AnnotateProperties", AnnotatePropertiesCommand, "Annotate a Tioga document by inserting nodes identifying properties and styles of each node"]; UserExec.RegisterCommand["PruneAnnotations", PruneAnnotationsCommand, "Prune the nodes created by the AnnotateProperties command"]; }.