<<-- WalnutDocumentRopeImpl.Mesa>> <<-- written by Bill Paxton. March 31, 1983>> <<-- last written by Paxton. March 31, 1983 9:22 am>> <<-- Last Edited by: Willie-Sue, June 24, 1983 2:30 pm >> DIRECTORY Rope, TextNode, WalnutDocumentRope; WalnutDocumentRopeImpl: CEDAR PROGRAM IMPORTS TextNode, Rope EXPORTS WalnutDocumentRope SHARES Rope = BEGIN ObjectRope: TYPE = object node Rope.RopeRep; Create: PUBLIC PROC [doc: TextNode.Ref] RETURNS [r: Rope.ROPE] = { docSize: INT = TextNode.LocOffset[[doc,0], TextNode.LastLocWithin[doc]]; RETURN [NEW[ObjectRope _ [node[object[docSize,TextNode.FirstChild[doc],Fetch,NIL,NIL]]]]] }; Fetch: PROC [data: REF, index: INT] RETURNS [CHAR] = { doc: TextNode.Ref _ NARROW[data]; loc: TextNode.Location = TextNode.LocRelative[[doc,0], index]; n: TextNode.RefTextNode = TextNode.NarrowToTextNode[loc.node]; IF n=NIL THEN ERROR; IF loc.where >= Rope.Size[n.rope] THEN RETURN ['\n]; RETURN [Rope.Fetch[n.rope, loc.where]] }; END.