-- CS.mesa
-- last edit by Schmidt, July 1, 1982 11:29 am
-- last edit by Satterthwaite, April 28, 1983 4:44 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];
  AbortMyself: SIGNAL;

 -- 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 READONLY TimeStamp.Stamp;

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

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

 -- rope utilities
  RopeToString: UNSAFE PROC[to: LONG STRING, from: Rope.ROPE];
  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: UNSAFE PROC[name: Rope.Text, access: File.Permissions] 
	RETURNS[Stream.Handle];

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


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

  EquivalentRope: PROC[a, b: Rope.ROPE] RETURNS[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[Rope.Text] ~ INLINE {
	RETURN[RopeInline.InlineFlatten[r]]};

  }.