DIRECTORY Atom USING [GetPName], CIFS USING [Error], Commander USING [CommandProc, Handle, Register], 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], WindowManager USING [UnWaitCursor, WaitCursor]; AnnotateProperties: CEDAR PROGRAM IMPORTS Atom, CIFS, Commander, EditSpan, IO, NodeProps, PutGet, Rope, TextEdit, TextNode, WindowManager = { rootNode: TextNode.Ref; annotationNode: TextNode.RefTextNode; commentAtom: ATOM = $Comment; propertyAnnotationAtom: ATOM = $PropertyAnnotation; trueRope: Rope.ROPE = "TRUE"; AnnotatePropertiesCommand: Commander.CommandProc = { [] _ DoAnnotations[cmd, TRUE] }; PruneAnnotationsCommand: Commander.CommandProc = { [] _ DoAnnotations[cmd, FALSE] }; DoAnnotations: PROC [cmd: Commander.Handle, annotate: BOOLEAN _ TRUE] RETURNS[ok: BOOLEAN _ TRUE] = { ENABLE UNWIND => WindowManager.UnWaitCursor[]; execOut: IO.STREAM = cmd.out; filename: Rope.ROPE; tabIndent: NAT _ 8; commandLineStream: IO.STREAM = IO.CreateInputStreamFromRope[cmd.commandLine]; WindowManager.WaitCursor[]; DO -- process each file in command line filename _ IO.GetToken[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]}; Commander.Register["AnnotateProperties", AnnotatePropertiesCommand, "Annotate a Tioga document by inserting nodes identifying properties and styles of each node"]; Commander.Register["PruneAnnotations", PruneAnnotationsCommand, "Prune the nodes created by the AnnotateProperties command"]; }. -- 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 Last Edited by: Maxwell, January 14, 1983 8:44 am Last Edited by: Plass, April 21, 1983 10:59 am Ê ˜JšÏc™Jš™Jš.™.Jš6™6J™1J™.šÏk ˜ Jšœžœ ˜Jšžœžœ ˜Jšœ žœ!˜0Jšœ žœ(˜6Jšžœ˜Jšœ žœ>˜MJšœžœ˜ Jšœžœžœ˜*Jšœ žœ˜Jšœ žœ7˜EJšœžœ˜/J˜—šœž ˜"Jšžœžœžœ@˜kJ˜—J˜J˜%Jšœ žœ ˜Jšœžœ˜3Jšœžœ ˜J˜šœ4˜4Jšœžœ˜ J˜—šœ2˜2Jšœžœ˜!J˜—šÏn œžœ#žœžœ˜EJšžœžœžœ˜Jšžœžœ!˜.Jšœ žœžœ ˜Jšœžœ˜Jšœ žœ˜Jšœžœžœžœ,˜MJ˜šžœ$˜'Jšœ žœ˜*Jšžœžœžœ˜#šžœžœ˜=J˜&—šœžœžœ ˜J˜J˜!Jšœžœ˜ Jšžœ˜—J˜%J˜šžœ ž˜J˜—šž˜J˜—J˜'Jšžœ˜—J˜J˜Jšžœ˜ J˜J˜—šŸœž œ˜!J˜Jšœžœ˜Jšžœ1žœžœ˜?J˜J˜Ešžœžœž˜J˜J˜"J˜,Jšžœ˜—J˜J˜—šŸœž œ˜#J˜J˜&šžœžœž˜šžœžœ˜ J˜ J˜"JšœVžœžœ˜—šž˜J˜"—Jšžœ˜—J˜J˜—šŸœžœžœžœ˜@Jšœ žœ˜šžœžœž˜šžœ?žœž˜IšžœMž˜SJšžœžœ˜ ———Jšžœžœ˜J˜J˜—šŸœž œ˜'J˜DJ˜AJ˜1J˜9J˜DJ˜?J˜J˜—šŸœž œ!žœ˜LJ˜EJšœ3žœžœ˜dJ˜1J˜9J˜DJ˜?J˜J˜—˜+JšœžœN˜aJ˜=Jšžœžœ˜J˜—J˜£J˜J˜}J˜J˜J˜—…—æö