DIRECTORY Rope USING [MaxLen, ROPE], TextLooks USING [Runs]; TextNode: CEDAR DEFINITIONS = BEGIN ROPE: TYPE ~ Rope.ROPE; MaxLen: INT ~ Rope.MaxLen; Runs: TYPE ~ TextLooks.Runs; Node: TYPE = REF NodeBody; NodeBody: TYPE = RECORD [ next: Node, -- points to next sibling, or if last=true, to parent child: Node, -- points to first child, if any, of this node props: Props, -- points to node property list formatName: ATOM _ NIL, -- name of format for the node last: BOOL _ FALSE, -- true if this is last sibling hasstyledef: BOOL _ FALSE, -- true if node has StyleDef prop (accelerator) hasprefix: BOOL _ FALSE, -- true if node has Prefix prop (accelerator) haspostfix: BOOL _ FALSE, -- true if node has Postfix prop (accelerator) hascharprops: BOOL _ FALSE, -- true if node has CharProps prop (accelerator) hascharsets: BOOL _ FALSE, -- true if node has CharSets prop (accelerator) hasartwork: BOOL _ FALSE, -- true if node has Artwork prop (accelerator) deleted: BOOL _ FALSE, -- true if has been deleted or is root pending delete dirty: BOOL _ FALSE, -- true if has been edited (contents, or children moved, inserted, ...) new: BOOL _ FALSE, -- true if created during this editing session (i.e., not from file) comment: BOOL _ FALSE, -- true if node is a comment count: [0..countMax] _ 0, -- incremented by text edit routines rope: ROPE, runs: Runs ]; Props: TYPE = REF PropsBody; PropsBody: TYPE = RECORD [name: ATOM, value: REF, next: Props]; countMax: NAT = 31; -- 5 bits for count Location: TYPE = RECORD [node: Node, where: INT _ 0]; nodeItself: INT = -1; nullLocation: Location = [node: NIL, where: nodeItself]; MakeNodeLoc: PROC [n: Node] RETURNS [Location]; NewTextNode: PROC RETURNS [Node]; Parent: PROC [n: Node] RETURNS [Node]; Root: PROC [n: Node] RETURNS [Node]; Next: PROC [n: Node] RETURNS [Node]; Previous: PROC [n: Node, parent: Node _ NIL] RETURNS [Node]; Forward: PROC [node: Node] RETURNS [nx: Node, levelDelta: INTEGER]; Backward: PROC [node: Node, parent: Node _ NIL] RETURNS [back, backparent: Node, levelDelta: INTEGER]; StepForward: PROC [node: Node] RETURNS [Node]; StepBackward: PROC [node: Node, parent: Node _ NIL] RETURNS [Node]; Level: PROC [node: Node] RETURNS [level: INTEGER]; ForwardClipped: PROC [node: Node, maxLevel: INTEGER, nodeLevel: INTEGER _ 0] RETURNS [nx: Node, nxLevel: INTEGER]; BackwardClipped: PROC [node: Node, maxLevel: INTEGER, parent: Node _ NIL, nodeLevel: INTEGER _ 0] RETURNS [back, backparent: Node, backLevel: INTEGER]; LocRelative: PROC [location: Location, count: INT, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [Location]; LocWithin: PROC [n: Node, count: INT, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [Location]; LocOffset: PROC [loc1, loc2: Location, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [count: INT]; BadArgs: ERROR; LocNumber: PROC [at: Location, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [count: INT]; FirstSibling: PROC [n: Node] RETURNS [Node]; LastSibling: PROC [n: Node] RETURNS [Node]; LastWithin: PROC [n: Node] RETURNS [Node]; LastLocWithin: PROC [n: Node] RETURNS [Location]; FirstChild: PROC [n: Node] RETURNS [Node]; LastChild: PROC [n: Node] RETURNS [Node]; NthChild: PROC [n: Node, location: INT _ 0] RETURNS [child: Node]; NthSibling: PROC [n: Node, cnt: INT _ 0] RETURNS [Node]; CountChildren: PROC [n: Node] RETURNS [count: INT]; CountFollowing: PROC [n: Node] RETURNS [count: INT]; CountToParent: PROC [n: Node] RETURNS [count: INT, parent: Node]; CountToChild: PROC [parent, child: Node] RETURNS [count: INT]; NodeRope: PROC [n: Node] RETURNS [ROPE]; NodeRuns: PROC [n: Node] RETURNS [Runs]; NodeProps: PROC [n: Node] RETURNS [Props]; NodeFormat: PROC [n: Node] RETURNS [ATOM]; IsLastSibling: PROC [n: Node] RETURNS [BOOL]; EndPos: PROC [n: Node] RETURNS [INT]; END. \TextNode.mesa Copyright c 1985, 1986 by Xerox Corporation. All rights reserved. written by Bill Paxton. December 1980 last written by Paxton. December 21, 1982 9:46 am Last Edited by: Maxwell, January 5, 1983 12:37 pm Rick Beach, March 27, 1985 1:08:21 pm PST Michael Plass, March 26, 1985 12:18:42 pm PST Doug Wyatt, September 5, 1986 2:51:23 pm PDT where >= length of text means at end where = loc in [0..length) means before that character e.g., where = 0 means at start of text where = nodeItself means location is the node itself rather than in its contents returns next sibling of n returns NIL if n is last sibling returns previous sibling of n returns NIL if n is first sibling runs faster if can supply parent returns next node in standard tree walk order levelDelta is level(node)-level(nx), where level is depth in tree levelDelta = 0 if nx and node are siblings levelDelta = 1 if nx is child of node levelDelta < 0 if do Parent* and Next to reach nx from node for backing through tree runs faster if can supply parent levelDelta same as for Forward returns next node in standard tree walk order returns preceding node in standard tree walk order Level[Root[x]] == 0; Level[FirstChild[n]]=Level[n]+1 like Forward, but limits how deep will go in tree if pass nodeLevel=0, correct value will be computed nxLevel = Level[nx] <= MAX[maxLevel,Level[node]] like Backward, but limits how deep will go in tree backLevel = Level[back] <= MAX[maxLevel,Level[node]] count is interpreted as a character offset from given location returns location corresponding to count adds in break at the end of each text subnode if skipCommentNodes is true, then ignores them in walking the tree returns character offset of location2 relative to location1 loc1 and loc2 can be in same node but loc2 must not be in node before loc1 or get ERROR BadArgs if skipCommentNodes is true, then ignores them in walking the tree returns character offset of location relative to root returns the last node within the branch i.e., goes to last child of last child of last child ... until no child returns the last location within the branch Κ#˜codešœ ™ Kšœ Οmœ7™BKšœ%™%Kšœ1™1K™1K™)K™-K™,—K˜šΟk ˜ Kšœžœ žœ˜Kšœ žœ˜—K˜KšΠblœžœž ˜Kšœž˜˜Kšžœžœžœ˜Kšœžœ˜Kšœžœ˜K˜Kšœžœžœ ˜šœ žœžœ˜Kšœ Οc5˜AKšœ  .˜;Kšœ ˜-Kšœ žœžœ ˜6Kšœžœžœ ˜3Kšœ žœžœ /˜JKšœ žœžœ -˜FKšœ žœžœ .˜HKšœžœžœ 0˜LKšœ žœžœ /˜JKšœ žœžœ .˜HKšœ žœžœ 5˜LKšœžœžœ G˜\Kšœžœžœ D˜WKšœ žœžœ ˜3Kšœ $˜>Kšœžœ˜ K˜ Kšœ˜K˜—Kšœžœžœ ˜š œ žœžœžœ žœ˜?K˜—šœ žœ ˜'K˜—K˜šœ žœžœžœ˜5Kšœ$™$šœ6™6Kšœ&™&—KšœP™PK˜—šœ žœ˜K˜—šœ žœ˜8K˜—šΟn œžœ žœ ˜/K˜—K˜š‘ œžœžœ˜!K˜—š‘œžœ žœ˜&K˜—š‘œžœ žœ˜$K˜—š‘œžœ žœ˜$Kšœ™Kšœžœ™ K˜—š‘œžœžœžœ˜™>Kšœ5™5Kšœ-™-KšœB™BK˜—š‘ œžœžœ žœžœžœžœ ˜jK˜—š‘ œžœ žœžœžœžœ žœ˜mKšœ;™;Kšœ!™!Kšœ0žœ™=KšœB™BK˜—šœ žœ˜K˜—š‘ œžœžœžœžœžœ žœ˜eKšœ5™5K˜—K˜š‘ œžœ žœ˜,K˜—š‘ œžœ žœ˜+K˜—š‘ œžœ žœ˜*Kšœ(™(KšœG™GK˜—š‘ œžœ žœ ˜1Kšœ,™,K˜—K˜š‘ œžœ žœ˜*K˜—š‘ œžœ žœ˜)K˜—š‘œžœžœžœ˜BK˜—š‘ œžœžœžœ˜8K˜—K˜š‘ œžœ žœ žœ˜3K˜—š‘œžœ žœ žœ˜4K˜—š‘ œžœ žœ žœ˜AK˜—š‘ œžœžœ žœ˜>K˜—K˜š‘œžœ žœžœ˜(K˜—š‘œžœ žœ˜(K˜—š‘ œžœ žœ ˜*K˜—š‘ œžœ žœžœ˜*K˜—š‘ œžœ žœžœ˜-K˜—š‘œžœ žœžœ˜%K˜——K˜Kšžœ˜—…—"‘