AnnotateProperties.mesa
Beach, May 1982
Paxton July 9, 1982 1:52 pm
McGregor September 10, 1982 2:18 pm
Maxwell, January 14, 1983 8:44 am
Plass, April 21, 1983 10:59 am
Russ Atkinson, September 29, 1983 11:51 am
DIRECTORY
Atom USING [GetPName],
FS USING [Error],
Commander USING [CommandProc, Handle, Register],
EditSpan USING [CannotDoEdit, Delete, InsertTextNode],
IO USING [EndOfStream, GetTokenRope, PutFR, PutRope, RIS, STREAM],
NodeProps USING [GetProp, GetSpecs, MapProps, MapPropsAction, PutProp, true],
ProcessExtras USING [CheckForAbort],
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, FS, Commander, EditSpan, IO, NodeProps, ProcessExtras, PutGet, Rope, TextEdit, TextNode, WindowManager = {
rootNode: TextNode.Ref;
annotationNode: TextNode.RefTextNode;
commentAtom: ATOM = $Comment;
propertyAnnotationAtom: ATOM = $PropertyAnnotation;
trueRope: Rope.ROPE = "TRUE";
DoAnnotations: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
ENABLE UNWIND => WindowManager.UnWaitCursor[];
execOut: IO.STREAM = cmd.out;
filename: Rope.ROPE;
tabIndent: NAT ← 8;
commandLineStream: IO.STREAM = IO.RIS[cmd.commandLine];
annotate: BOOL ← cmd.procData.clientData = $Annotate;
WindowManager.WaitCursor[];
DO
-- process each file in command line
filename ←
IO.GetTokenRope[commandLineStream
! IO.EndOfStream => {filename ← NIL; CONTINUE}].token;
IF Rope.Size[filename]=0 THEN EXIT;
IF Rope.Find[filename,"."] = -1
THEN
-- add .mesa extension
filename ← Rope.Cat[filename,".mesa"];
{
ENABLE
FS.Error => {
execOut.PutRope[filename];
execOut.PutRope[" not found.\n"];
result ← $Warning;
msg ← "Some files not found";
LOOP };
ProcessExtras.CheckForAbort[];
rootNode ← PutGet.FromFile[filename];
ProcessExtras.CheckForAbort[];
};
IF annotate
THEN AddAnnotationNodes[]
ELSE PruneAnnotationNodes[];
[] ← PutGet.ToFile[filename, rootNode];
ENDLOOP;
WindowManager.UnWaitCursor[];
};
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, "<<RootNode"];
[] ← NodeProps.MapProps[rootNode, AnnotateProps];
[] ← 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.PutFR["<<NodeLevel: %d", [integer[level]]]];
[] ← NodeProps.MapProps[thisNode, AnnotateProps];
[] ← TextEdit.AppendRope[rootNode, annotationNode, ">>"];
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",
DoAnnotations,
"Annotate a Tioga document by inserting nodes identifying properties and styles of each node",
$Annotate];
Commander.Register[
"PruneAnnotations",
DoAnnotations,
"Prune the nodes created by the AnnotateProperties command",
$Prune];
}.