-- CS.Mesa, last edit February 21, 1983 7:25 pm
-- replacement for Subr.Mesa in the Cedar world

	DIRECTORY
	File: TYPE USING[Capability, delete, grow, Permissions, read, shrink, write],
	IO: TYPE USING [Handle, refAny, Value],
	Rope: TYPE USING [Equal, ROPE, Text],
	RopeInline: TYPE USING [InlineFlatten],
	Stream: TYPE USING[Handle],
	TimeStamp: TYPE USING [Stamp];
	
CS: CEDAR DEFINITIONS IMPORTS IO, Rope, RopeInline = {

-- variables
z: ZONE;	-- use this zone to allocate all REF's

-- signals
FileErrorType: TYPE = {notFound, wrongVersion};
FileError: ERROR[error: FileErrorType];

-- CONSTANTS
Read: File.Permissions = File.read;
Write: File.Permissions = File.write + File.grow + File.shrink + File.delete;
ReadWrite: File.Permissions = Read + Write;

PTimeStamp: TYPE = REF TimeStamp.Stamp;

-- call this to make sure module is started
Init: PROC;

-- iostream utilities
SetPFCodes: PROC[h: IO.Handle];

-- rope utilities
RopeToString: PROC[to: LONG STRING, from: Rope.ROPE];
IntToCard: PROC[int: INT] RETURNS[CARDINAL];
EndsIn: PROC[str: Rope.ROPE, suf: LONG STRING] RETURNS[BOOL];
EqualRS: PROC[r: Rope.ROPE, s: LONG STRING] RETURNS[equal: BOOL];
EquivalentRS: PROC[r: Rope.ROPE, s: LONG STRING] RETURNS[equivalent: BOOL];

-- other
Confirm: PROC[dch: CHAR, in, out: IO.Handle] RETURNS[CHAR];

NewStream: PROC [name: Rope.Text, access: File.Permissions] 
	RETURNS [Stream.Handle];

-- npages should not include the leader page;  I'll add +1
NewFile: PROC[name: Rope.Text, access: File.Permissions, npages: CARDINAL]
	RETURNS[File.Capability];


-- INLINES
EqualRope: PROC[a,b: Rope.ROPE] RETURNS[equal: BOOL] = INLINE {
	RETURN[Rope.Equal[s1: a, s2: b, case: TRUE]];
	};

EquivalentRope: PROC[a,b: Rope.ROPE] RETURNS[equal: BOOL] = INLINE {
	RETURN[Rope.Equal[s1: a, s2: b, case: FALSE]];
	};

MakeTS: PROC[ts: TimeStamp.Stamp] RETURNS[IO.Value] = INLINE {
	RETURN[IO.refAny[NEW[TimeStamp.Stamp ← ts]]];
	};

Flat: PROC[r: Rope.ROPE] RETURNS[fr: Rope.Text] = INLINE {
	RETURN[RopeInline.InlineFlatten[r]];
	};

}.