RopeFrom.mesa
Bill Paxton, February 1981
McGregor, August 11, 1982 10:31 am
Russ Atkinson, July 21, 1983 7:06 pm
This file defines routines for creating ropes from files, strings, and characters; also for creating flat ropes from other ones. The characters go into CharsArrays to get fast access via RopeReader's (q.v.). A shared CharsArray is used to hold text for chars, strings, and ropes; also for short files. Long files use RopeFiles.
RopeFrom:
CEDAR DEFINITIONS
= BEGIN
Offset: TYPE = INT;
MaxLen: Offset = LAST[Offset];
MaxNat: NAT = LAST[NAT];
ROPE: TYPE = Rope.ROPE;
File:
PROC [
file: FS.OpenFile,
start: Offset ← 0,
byte address in file where rope will start
0 means first page after leader page
length: Offset ← MaxLen,
defaults to rest of file beyond start
activate: BOOL ← FALSE,
fileLen: Offset ← MaxLen]
RETURNS [ROPE];
... if activate is true, the system will start swapping the characters into real memory
... fileLen is size of entire file in bytes, excluding leader page (let this be defaulted if you're not sure of it)
Stream:
PROC [stream:
IO.
STREAM, length: Offset ← MaxLen]
RETURNS [rope:
ROPE];
... reads length chars from stream and puts them in a rope.
String:
PROC
[string: REF READONLY TEXT, start: NAT ← 0, len: NAT ← LAST[NAT]] RETURNS [ROPE];
... copies len characters from string starting at start.
Character: PROC [char: CHAR] RETURNS [ROPE];
Byte:
PROC [x:
UNSPECIFIED]
RETURNS [
ROPE] =
INLINE {
RETURN [Character[LOOPHOLE[x,CHAR]]];
};
FlatSubstr:
PROC [rope:
ROPE, start: Offset ← 0, len: Offset ← MaxLen]
RETURNS [
ROPE];
FlatConcat:
PROC
[base, rest: ROPE, baseSize, restSize: Offset ← MaxLen, tryAppend: BOOL ← TRUE]
RETURNS [ROPE];
TryAppendConcat:
PROC
[base, rest: ROPE, baseSize, restSize: Offset ← MaxLen] RETURNS [ROPE];
... tries to append rest by copying to buffer directly after base; returns NIL if cannot
FlatReplace:
PROC [
base: ROPE, start: Offset ← 0, len: Offset ← MaxLen, replace: ROPE ← NIL,
size, baseSize, repSize: Offset ← MaxLen]
RETURNS [ROPE];
... returns a new rope with the given range replaced
FlatDelete:
PROC
[base: ROPE, start: Offset ← 0, len, baseSize: Offset ← MaxLen] RETURNS [ROPE] = INLINE {
RETURN [FlatReplace[base, start, len, NIL, MaxLen, baseSize, 0]];
};
FlatInsert:
PROC
[dest: ROPE, destLoc: Offset ← 0, source: ROPE, destSize, sourceSize: Offset ← MaxLen]
RETURNS [ROPE] = INLINE {
RETURN [FlatReplace[dest, destLoc, 0, source, MaxLen, destSize, sourceSize]];
};
FlatCopy:
PROC
[dest: ROPE, destLoc: Offset ← 0, source: ROPE, start: Offset ← 0, len: Offset ← MaxLen, destSize: Offset ← MaxLen]
RETURNS [ROPE];
FlatReplaceByChar:
PROC
[base: ROPE, char: CHAR, start: Offset ← 0, len, baseSize: Offset ← MaxLen, tryAppend: BOOL ← TRUE]
RETURNS [new: ROPE];
TryAppendReplaceByChar:
PROC
[base: ROPE, char: CHAR, start: Offset ← 0, len, baseSize: Offset ← MaxLen]
RETURNS [new: ROPE];
FlatInsertChar:
PROC
[base: ROPE, char: CHAR, loc: Offset ← 0, baseSize: Offset ← MaxLen, tryAppend: BOOL ← TRUE]
RETURNS [ROPE] = INLINE {
RETURN [FlatReplaceByChar[base,char,loc,0,baseSize,tryAppend]];
};
TryFlatInsertChar:
PROC
[base: ROPE, char: CHAR, loc: Offset ← 0, baseSize: Offset ← MaxLen]
RETURNS [ROPE] = INLINE {
RETURN [TryAppendReplaceByChar[base,char,loc,0,baseSize]];
};
FlatAppendChar:
PROC
[base: ROPE, char: CHAR, baseSize: Offset ← MaxLen, tryAppend: BOOL ← TRUE]
RETURNS [ROPE] = INLINE {
RETURN [FlatReplaceByChar[base,char,MaxLen,0,baseSize,tryAppend]];
};
TryFlatAppendChar:
PROC
[base: ROPE, char: CHAR, baseSize: Offset ← MaxLen] RETURNS [ROPE] = INLINE {
RETURN [TryAppendReplaceByChar[base,char,MaxLen,0,baseSize]];
};
FlatAppendByte:
PROC
[base: ROPE, x: UNSPECIFIED, baseSize: Offset ← MaxLen, tryAppend: BOOL ← TRUE]
RETURNS [ROPE] = INLINE {
RETURN [FlatAppendChar[base,LOOPHOLE[x,CHAR],baseSize,tryAppend]];
};
TryFlatAppendByte:
PROC
[base: ROPE, x: UNSPECIFIED, baseSize: Offset ← MaxLen]
RETURNS [ROPE] = INLINE {
RETURN [TryFlatAppendChar[base,LOOPHOLE[x,CHAR],baseSize]];
};
FlatReplaceByString:
PROC
[base: ROPE, string: REF READONLY TEXT, stringStart: NAT ← 0, stringNum: NAT ← MaxNat, start: Offset ← 0, len, baseSize: Offset ← MaxLen, tryAppend: BOOL ← TRUE]
RETURNS [new: ROPE];
TryAppendReplaceByString:
PROC
[base: ROPE, string: REF READONLY TEXT, stringStart: NAT ← 0, stringNum: NAT ← MaxNat, start: Offset ← 0, len, baseSize: Offset ← MaxLen]
RETURNS [new: ROPE];
FlatInsertString:
PROC
[base: ROPE, string: REF READONLY TEXT, stringStart: NAT ← 0, stringNum: NAT ← MaxNat, loc: Offset ← 0, baseSize: Offset ← MaxLen, tryAppend: BOOL ← TRUE]
RETURNS [ROPE] = INLINE {
-- string is inserted at loc
-- inserts stringNum chars from string starting with stringStart
RETURN [FlatReplaceByString[base,string,stringStart,stringNum,loc,0,baseSize,tryAppend]];
};
TryFlatInsertString:
PROC
[base: ROPE, string: REF READONLY TEXT, stringStart: NAT ← 0, stringNum: NAT ← MaxNat, loc: Offset ← 0, baseSize: Offset ← MaxLen]
RETURNS [ROPE] = INLINE {
-- string is inserted at loc
-- inserts stringNum chars from string starting with stringStart
RETURN [TryAppendReplaceByString[base,string,stringStart,stringNum,loc,0,baseSize]];
};
FlatAppendString:
PROC
[base: ROPE, string: REF READONLY TEXT, stringStart: NAT ← 0, stringNum: NAT ← MaxNat, baseSize: Offset ← MaxLen, tryAppend: BOOL ← TRUE]
RETURNS [ROPE] = INLINE {
RETURN [FlatReplaceByString[base,string,stringStart,stringNum,MaxLen,0,baseSize,tryAppend]];
};
TryFlatAppendString:
PROC
[base: ROPE, string: REF READONLY TEXT, stringStart: NAT ← 0, stringNum: NAT ← MaxNat, baseSize: Offset ← MaxLen]
RETURNS [ROPE] = INLINE {
RETURN [TryAppendReplaceByString[base,string,stringStart,stringNum,MaxLen,0,baseSize]];
};
-- ***** miscellaneous internal stuff
StartRopeFrom: PROC; -- for initialization only
StartRopeFromEdit: PROC; -- for initialization only
StartRopeFromFile: PROC; -- for initialization only
qZone: ZONE; -- quantized zone for use within RopeEditing config
pZone: ZONE; -- prefixed zone for use within RopeEditing config
END.
Changes due to Nuclear conversion
RRA, July 21, 1983 7:02 pm, reformatted; change File.Capability to FS.OpenFile; removed okToMapFile argument from the File procedure (not relevant)