-- WalnutStream.Mesa
-- Contents: types and procedures which take an explicit stream parameter

-- Last Edited by: Willie-Sue, January 3, 1984 1:42 pm


DIRECTORY
 GVRetrieve USING[Handle],
IO USING [STREAM],
 Rope USING [ROPE],
 WalnutLog USING [LogEntryType, MsgRec];

WalnutStream: CEDAR DEFINITIONS =

BEGIN

ROPE: TYPE = Rope.ROPE;

-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-- utility routines for parsing log-style files

ReadPrefixInfo: PROC[strm: IO.STREAM, headersPos: INT]
  RETURNS[msgID: ROPE, categories: ROPE, outOfSynch: BOOL];

FindStartOfEntry: PROC[strm: IO.STREAM, doReport: BOOL]
RETURNS[startPos, prefixLength, entryLength: INT, entryChar: CHAR];

TagAndValue: PROC[strm: IO.STREAM, inc: INT] RETURNS[tag, value: ROPE];

RopeFromStream: PROC[strm: IO.STREAM, startPos, len: INT] RETURNS[ROPE];
-- reads arbitrary length ROPE from a stream

MsgRecFromStream: PROC[strm: IO.STREAM, prefixLength, msgLength: INT]
RETURNS[msgRec: WalnutLog.MsgRec];

ReadOldMailFile: PROC[strm: IO.STREAM, defaultPrefix: ROPE] RETURNS [ok: BOOL];

IsStart: PROC[line: ROPE] RETURNS[startFound: BOOL, relPos: INT];
-- returns TRUE if *start* is the last 7 chars in line

-- UpdateFromStream is implemented in WalnutUpdateImpl

UpdateFromStream: PROC[strm: IO.STREAM, startPos: INT] RETURNS[success: BOOL];
-- reads entries from strm, starting at startPos, and updates the database by making
-- calls into WalnutDB

ExpungeFromStream: PROC[strm: IO.STREAM, doUpdates, tailRewrite: BOOL]
  RETURNS[startExpungePos: INT, ok: BOOL, tempLog: IO.STREAM];
-- Dumping is driven from the log file (strm) & preserves the bits that came from Grapevine
-- Dumps all the Msgs in the database to a tempLog, setting all
-- their body pointers to reference the NEW log; does NOT copy tempLog to strm

FlushAndSetCreateDate: PROC[strm: IO.STREAM];
-- flushes the stream and sets the create date to BasicTime.Now

-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-- the following procs write on strm

MakeLogEntry: PROC [ strm: IO.STREAM, entryType: WalnutLog.LogEntryType,
  entryText: ROPE, msgID: ROPENIL, doFlush: BOOLTRUE]
  RETURNS [endStrmPos, prefixLength, entryLength: INT];

GVLogEntry: PROC [strm: IO.STREAM, gvH: GVRetrieve.Handle, prefix: ROPE]
RETURNS [lastIndex: INT, ok: BOOL];

END.