DIRECTORY Rope, Mopcodes, RopeFrom; RopeEdit: CEDAR DEFINITIONS IMPORTS Rope, Mopcodes, RopeFrom SHARES Rope = BEGIN OPEN r:Rope, fromI:RopeFrom; ROPE: TYPE = Rope.ROPE; Offset: TYPE = INT; MaxLen: Offset = LAST[Offset]; MaxNat: NAT = LAST[NAT]; Substr: PROC [base: ROPE, start: Offset _ 0, len: Offset _ MaxLen] RETURNS [ROPE]; Concat: PROC [base, rest: ROPE, baseLen, restLen: Offset _ MaxLen] RETURNS [ROPE]; Replace: PROC [ base: ROPE, start: Offset _ 0, len: Offset _ MaxLen, replace: ROPE _ NIL, baseSize, repSize: Offset _ MaxLen] RETURNS [ROPE]; Delete: PROC [base: ROPE, start, len, baseSize: Offset] RETURNS [ROPE] = INLINE { RETURN [ Replace[base,start,len,NIL,baseSize,0]] }; Insert: PROC [ dest: ROPE, destLoc: Offset _ 0, source: ROPE, destSize, sourceSize: Offset _ MaxLen] RETURNS [ROPE] = INLINE { RETURN [ Replace[dest,destLoc,0,source,destSize,sourceSize]] }; Copy: PROC [ dest: ROPE, destLoc: Offset _ 0, source: ROPE, start: Offset _ 0, len: Offset _ MaxLen, destSize: Offset _ MaxLen] RETURNS [ROPE]; ReplaceByChar: PROC [ base: ROPE, char: CHAR, start: Offset _ 0, len, baseSize: Offset _ MaxLen] RETURNS [ROPE]; InsertChar: PROC [ base: ROPE, char: CHAR, loc: Offset _ 0, baseSize: Offset _ MaxLen] RETURNS [ROPE] = INLINE { RETURN [ReplaceByChar[base,char,loc,0,baseSize]] }; AppendChar: PROC [base: ROPE, char: CHAR, baseSize: Offset _ MaxLen] RETURNS [ROPE] = INLINE { RETURN [ReplaceByChar[base,char,MaxLen,0,baseSize]] }; AppendByte: PROC [base: ROPE, x: UNSPECIFIED, baseSize: Offset _ MaxLen] RETURNS [ROPE] = INLINE { RETURN [AppendChar[base,LOOPHOLE[x,CHAR],baseSize]] }; String: TYPE = REF READONLY TEXT; ReplaceByString: PROC [ base: ROPE, string: String, stringStart: NAT _ 0, stringNum: NAT _ MaxNat, start: Offset _ 0, len, baseSize: Offset _ MaxLen] RETURNS [new: ROPE]; InsertString: PROC [ base: ROPE, string: String, stringStart: NAT _ 0, stringNum: NAT _ MaxNat, loc: Offset _ 0, baseSize: Offset _ MaxLen] RETURNS [ROPE] = INLINE { RETURN [ ReplaceByString[base,string,stringStart,stringNum,loc,0,baseSize]] }; AppendString: PROC [ base: ROPE, string: String, stringStart:NAT _ 0, stringNum: NAT _ MaxNat, baseSize: Offset _ MaxLen] RETURNS [ROPE] = INLINE { RETURN [ ReplaceByString[base,string,stringStart,stringNum,MaxLen,0,baseSize]] }; Size: PROC [base: ROPE] RETURNS [Offset] = INLINE { -- copied from RopeInline.Mesa OPEN Rope; ExtendPositive: PROC [x: INTEGER] RETURNS [Offset] = TRUSTED MACHINE CODE {Mopcodes.zLI0}; FirstPtr: TYPE = LONG POINTER TO INTEGER; Tobject: TYPE = object node RopeRep; first: INTEGER; IF base = NIL THEN RETURN [0]; TRUSTED { IF (first _ LOOPHOLE[base,FirstPtr]^) >= 0 THEN RETURN [ExtendPositive[first]]; RETURN [LOOPHOLE[base, REF Tobject].size]} }; Fetch: PROC [rope: ROPE, index: Offset] RETURNS [CHAR] = INLINE { RETURN [Rope.Fetch[rope,index]] }; CountPieces: PROC [rope: ROPE] RETURNS [count: Offset] = INLINE { [,count,] _ RopeStats[rope] }; RopeStats: PROC [base: ROPE, start: Offset _ 0, len: Offset _ MaxLen] RETURNS [size, pieces, depth: Offset]; Flatten: PROC [rope: ROPE] RETURNS [ROPE] = INLINE { RETURN [fromI.FlatSubstr[rope,0,MaxLen]] }; SemiFlatten: PROC [base: ROPE] RETURNS [ROPE]; Depth: PROC [rope: ROPE] RETURNS [depth: INTEGER]; CharProperty: TYPE = {white, alphaNumeric, punctuation, illegal}; CharPropertyTable: TYPE = PACKED ARRAY CHAR OF CharProperty; charPropertyTable: REF READONLY CharPropertyTable; WhiteChar, BlankChar: PROC [char: CHAR] RETURNS [BOOLEAN] = INLINE { RETURN [charPropertyTable[char] = white] }; AlphaNumericChar: PROC [char: CHAR] RETURNS [BOOLEAN] = INLINE { RETURN [charPropertyTable[char] = alphaNumeric] }; PunctuationChar: PROC [char: CHAR] RETURNS [BOOLEAN] = INLINE { RETURN [charPropertyTable[char] = punctuation] }; IllegalChar: PROC [char: CHAR] RETURNS [BOOLEAN] = INLINE { RETURN [charPropertyTable[char] = illegal] }; TestCharProp: PROC [char: CHAR, property: CharProperty] RETURNS [BOOLEAN] = INLINE { RETURN [charPropertyTable[char] = property] }; GetCharProp: PROC [char: CHAR] RETURNS[property: CharProperty] = INLINE { RETURN [charPropertyTable[char]] }; CR: CHAR = 'M-100B; TAB: CHAR = 'I-100B; SP: CHAR = ' ; UpperCase: PROC [c: CHAR] RETURNS [CHAR] = INLINE { RETURN [IF c IN ['a..'z] THEN c-40B ELSE c] }; LowerCase: PROC [c: CHAR] RETURNS [CHAR] = INLINE { RETURN [IF c IN ['A..'Z] THEN c+40B ELSE c] }; END. °-- RopeEdit.mesa; written by Bill Paxton, February 1981 -- edited by McGregor, February 8, 1983 10:52 am -- edited by Paxton, August 24, 1982 9:53 am -- This module provides editing operations for ropes -- The edit functions are -- Replace, Delete, Insert, Copy -- ReplaceByChar, InsertChar, AppendChar, -- ReplaceByString, InsertString, AppendString -- Finally, there are a few miscellaneous Rope operations -- Size, Fetch, Flatten -- **** Editing Operations **** -- returns a subrope of the base -- returns the concatenation of two ropes -- returns a new rope with the given range replaced -- string is inserted at loc -- inserts stringNum chars from string starting with stringStart -- **** Miscellaneous Operations -- create a flat version of rope -- create a version with at most 5 pieces. -- avoids copying biggest existing pieces in base -- ***** Character property information -- Returns TRUE iff char has property=white. -- Returns TRUE iff char has property=alphaNumeric. -- Returns TRUE iff char has property=punctuation. -- Returns TRUE iff char has property=illegal. -- Returns TRUE iff char has property. -- Returns property {white, alphaNumeric, punctuation, illegal} for char. Ê·˜JšÏc7™7Jš0™0Jš,™,J˜Jš4™4J˜š™Jš ™ Jš)™)Jš.™.J˜—š9™9Jš™—J˜šÏk ˜ J˜J˜ J˜ —J˜Jšœ ž˜Jšžœ˜ Jšžœ˜ Jšžœžœ˜"J˜Jšžœžœžœ˜Jšœžœžœ˜Jšœžœ ˜Jšœžœžœžœ˜J˜J˜Jš™J˜šÏnœžœžœ*˜BJšžœžœ˜Jš ™ J˜—šŸœžœžœ$˜BJšžœžœ˜Jš)™)J˜—šŸœžœ˜Jšœžœ4žœžœ˜IJ˜#Jšžœžœ˜Jš3™3J˜—šŸœžœžœ˜7Jšžœžœžœžœ˜"Jšœžœ˜*J˜—šŸœžœ˜Jšœžœžœ˜.J˜&Jšžœžœžœžœ˜"J˜6J˜—šŸœžœ˜ Jšœžœ˜ Jšœžœ*˜6J˜Jšžœžœ˜J˜—šŸ œžœ˜Jšœžœžœ˜J˜2Jšžœžœ˜J˜—šŸ œžœ˜Jšœžœžœ-˜CJšžœžœ˜Jšžœžœ-˜