-- file: Protection.Mesa -- edited by McCreight, September 25, 1980 5:25 PM -- edited by Brotz, December 1, 1980 11:22 AM DIRECTORY ovD: FROM "OverviewDefs", prA: FROM "ProtectionAbstractions", prD: FROM "ProtectionDefs", Storage, vmD: FROM "VirtualMgrDefs"; Protection: PROGRAM IMPORTS prD, Storage EXPORTS prA, prD = PUBLIC BEGIN -- Implements protected fields for the editor by limiting selections -- to unprotected fields. -- Selection convention: a range is represented by a nonempty half open interval; a point is -- represented by an empty half open interval; selection beyond the message end is -- represented by the point [messageLength .. messageLength). ProtectedFields: PUBLIC TYPE = RECORD -- in prA [ next: ProtectedFieldPtr, start, end: ovD.CharIndex]; ProtectedFieldPtr: TYPE = POINTER TO ProtectedFields; ProtectionBug: SIGNAL = CODE; FindUnprotectedSubrange: PROCEDURE [pfp: ProtectedFieldPtr, rangePtr: POINTER TO vmD.MessageRange, fixStart: BOOLEAN _ TRUE] = -- Restricts range to -- lie within an unprotected field. fixStart=TRUE causes the restriction to -- be limited to that unprotected field in which the range start lies; otherwise -- the restriction is limited to that unprotected field in which the range end -- lies. BEGIN fixed: ovD.CharIndex; precProtField: ProtectedFieldPtr _ NIL; fixed _ IF fixStart THEN rangePtr.start ELSE rangePtr.end; WHILE pfp # NIL AND pfp.end <= fixed DO precProtField _ pfp; pfp _ pfp.next ENDLOOP; SELECT TRUE FROM pfp # NIL AND pfp.start <= fixed => -- fixed IN [pfp.start .. pfp.end) {rangePtr.start _ rangePtr.end _ IF fixStart THEN pfp.start ELSE pfp.end}; fixStart => IF pfp # NIL THEN rangePtr.end _ MIN[rangePtr.end, pfp.start]; ENDCASE => IF precProtField # NIL THEN rangePtr.start _ MAX[rangePtr.start, precProtField.end]; END; -- of FindUnprotectedSubrange -- AdjustProtFields: PROCEDURE[pfpp: POINTER TO ProtectedFieldPtr, actionIndex: ovD.CharIndex, deletedChars, insertedChars: CARDINAL] = -- Adjusts the indexes of protected fields to reflect an editing -- operation. Signals ProtectionBug if the editing operation overlapped -- a protected field. BEGIN deltaChars: INTEGER; pfp: ProtectedFieldPtr _ pfpp^; WHILE pfp#NIL AND pfp.end<=actionIndex DO pfp _ pfp.next ENDLOOP; IF pfp=NIL THEN RETURN; IF pfp.start