TextLooksSupport.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
written by Bill Paxton, February 1981
last edit by Bill Paxton, December 22, 1981 1:57 pm
last edit by Maxwell, January 5, 1983 12:48 pm
last edit by Russ Atkinson, July 22, 1983 10:03 am
Doug Wyatt, March 2, 1985 4:23:37 pm PST
Michael Plass, March 29, 1985 2:26:31 pm PST
Internal support interface for TextLooks.
DIRECTORY
Basics USING [NonNegative],
TextLooks USING [BaseRuns, FlatMax, Looks, MaxOffset, noLooks, Runs];
TextLooksSupport: CEDAR DEFINITIONS
IMPORTS Basics
SHARES TextLooks
= BEGIN OPEN TextLooks;
BaseRun:
PROC [x: BaseRuns, index:
INT, lower:
NAT ← 0, upper:
NAT ←
LAST[
NAT]]
RETURNS [
NAT];
ExtractRuns:
PROC [base: BaseRuns, ref: Runs, start, len:
INT, index:
NAT ← 0]
RETURNS [
NAT];
-- value is next index
CountRunsAfterChanges:
PROC [ref: Runs, start, len:
INT, limit:
INT ← MaxOffset,
remove, add: Looks, merge:
BOOL ←
FALSE, firstLooks: Looks ← noLooks
]
RETURNS [count:
NAT, nonempty:
BOOL, lastLooks: Looks];
ExtractRunsAfterChanges:
PROC [base: BaseRuns, ref: Runs, remove, add: Looks,
start:
INT, len:
INT, index:
NAT ← 0]
RETURNS [
NAT];
-- value is next index
CopyRuns:
PROC [to, from: BaseRuns, toLoc, fromLoc, nRuns:
NAT];
MakeRun: PROC [len: INT] RETURNS [new: Runs];
TryFlatSubstr:
PROC [base: Runs, start, len:
INT, limit:
INT ← FlatMax]
RETURNS [BaseRuns];
TryFlatConcat:
PROC [base, rest: Runs, baseLen, restLen:
INT]
RETURNS [new: BaseRuns];
TryFlatConcatRest:
PROC [base, rest: Runs, baseLen, restLen, numRuns:
INT,
merge:
BOOL, looks: Looks]
RETURNS [BaseRuns];
ModifyLooks:
PROC [old, remove, add: Looks]
RETURNS [Looks];
modified looks are == (old & ~remove) v add
MergeChanges:
PROC [oldrem, oldadd, rem, add: Looks]
RETURNS [newrem, newadd: Looks];
((lks & ~oldrem) v oldadd) & ~rem) v add ==
lks & ~(oldrem v rem)) v ((oldadd & ~rem) v add
thus, newrem ← oldrem v rem, newadd ← (oldadd & ~rem) v add
LooksAND:
PROC [looks1, looks2: Looks]
RETURNS [Looks];
compute looks1 & looks2
LooksOR:
PROC [looks1, looks2: Looks]
RETURNS [Looks];
compute looks1 v looks2
LooksNOT:
PROC [looks: Looks]
RETURNS [Looks];
compute ~looks
TbaseSize:
PROC [x: BaseRuns]
RETURNS [
INT];
InsertRun:
PROC [base: BaseRuns, len:
INT, looks: Looks, index:
NAT]
RETURNS [
NAT];
NewBase:
PROC [runs:
NAT]
RETURNS [BaseRuns];
FindBaseRuns:
PROC [x: BaseRuns, start, len:
INT]
RETURNS [first, last:
NAT];
BaseRunLengths:
PROC [x: BaseRuns, start, len:
INT, first, last:
NAT]
RETURNS [firstLen, lastLen:
INT];
Short:
PROC [x:
INT]
RETURNS [
NAT] =
INLINE {
RETURN[x] };
quick range check and shortening
NonNeg:
PROC [x:
INT]
RETURNS [
INT] =
INLINE {
RETURN[Basics.NonNegative[x]] };
CheckLongSub:
PROC [x, y:
INT]
RETURNS [
INT] =
INLINE {
RETURN[NonNeg[x-y]] };
END.