ISMessageImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
MKaplan, September 10, 1985 2:36:14 am PDT
DIRECTORY
Atom USING [PropList, PutPropOnList],
Rope USING [ROPE, Length, Fetch],
FS USING [StreamOpen],
IO USING [PutF, PutBlock, Value, STREAM, Close, GetIndex, GetChar],
TiogaAccess USING [TiogaChar, WriteFile, GetInternalProp, Put, Looks, Writer, Create],
ISMessage;
ISMessageImpl: CEDAR PROGRAM
IMPORTS Atom, Rope, TiogaAccess, IO, FS
EXPORTS ISMessage
~ BEGIN
stream: IO.STREAM;
Close: PUBLIC PROC ~ {
IO.Close[stream];
};
OpenTempFile: PUBLIC PROC ~ {
stream ← FS.StreamOpen["ISTest.out", $create];
};
CloseTempFile: PUBLIC PROC ~ {
IO.Close[stream];
};
ReopenTempFile: PUBLIC PROC ~ {
stream ← FS.StreamOpen["ISTest.out"];
};
GetTempFileChar: PUBLIC PROC RETURNS [c: CHAR] ~ {
RETURN[IO.GetChar[stream]];
};
GetIndex: PUBLIC PROC RETURNS [INT] ~ {
RETURN[IO.GetIndex[stream]];
};
PutF: PUBLIC PROC [format: Rope.ROPENIL, v1, v2, v3, v4, v5: IO.Value ← [null[]]] ~ {
IO.PutF[stream, format, v1, v2, v3, v4, v5];
};
PutBlock: PUBLIC PROC [block: REF READONLY TEXT, startIndex: NAT ← 0, count: NATNAT.LAST] ~ {
IO.PutBlock[stream, block, startIndex, count];
};
tc: TiogaAccess.TiogaChar;
tcFormat: ATOMNIL;
pl: Atom.PropList;
LooksFromLooksChars: PROC [lookChars: Rope.ROPE] RETURNS [l: TiogaAccess.Looks ← ALL[FALSE]] ~ {
FOR j: INT IN [0..Rope.Length[lookChars]) DO
l[Rope.Fetch[lookChars, j]] ← TRUE;
ENDLOOP;
};
tiogaOutputFN: Rope.ROPE;
writer: TiogaAccess.Writer;
OpenTiogaOutput: PUBLIC PROC [fileName: Rope.ROPE] ~ {
tiogaOutputFN ← fileName;
writer ← TiogaAccess.Create[];
tc ← [comment: FALSE,
charSet: 0,
char: 0C,
format: NIL,
looks: ALL[FALSE],
endOfNode: FALSE,
deltaLevel: 0];
};
WriteTiogaOutputFile: PUBLIC PROC ~ {
IF tc.char=0C THEN ERROR; --A TiogaDeltaLevel[] should have been last thing done--
TiogaAccess.Put[writer, tc];
TiogaAccess.WriteFile[writer, tiogaOutputFN];
};
WriteTiogaRope: PUBLIC PROC [rope: Rope.ROPE, lookChars: Rope.ROPE ← "", comment: BOOLFALSE] ~ {
Write the chars in the rope to tioga output file. Don't write last char, in case next char starts a new node (so properties have to be added to last byte of rope)
looks: TiogaAccess.Looks = LooksFromLooksChars[lookChars];
IF tc.char#0C THEN TiogaAccess.Put[writer, tc];
tc.char ← 0C;
tc.comment ← comment;
tc.looks ← looks;
tc.deltaLevel ← 0;
tc.format ← NIL;
tc.endOfNode ← FALSE;
tc.propList ← NIL;
FOR i: INT IN [0..Rope.Length[rope]) DO
IF tc.char#0C THEN TiogaAccess.Put[writer, tc];
tc.char ← Rope.Fetch[rope, i];
ENDLOOP;
};
TiogaDeltaLevel: PUBLIC PROC [d: INT] ~ {
Set deltaLevel for current TiogaChar, and terminate node
IF tc.char=0C THEN RETURN; --hack hack--
tc.propList ← pl;
tc.format ← tcFormat;
pl ← NIL;
tcFormat ← NIL;
tc.deltaLevel ← d;
tc.endOfNode ← TRUE;
IF tc.char#'\n THEN ERROR; --Tioga nodes should all end in newlines--
No need to write out: will get done on next call to WriteTiogaRope, or before writing to file.
};
WriteTiogaProp: PUBLIC PROC [prop: ATOM, value: Rope.ROPE] ~ {
Save prop. on plist, to be added to last TiogaChar of this node when deltaLevel given in TiogaDeltaLevel
pl ← Atom.PutPropOnList[pl, prop, TiogaAccess.GetInternalProp[prop, value]];
};
WriteTiogaFormat: PUBLIC PROC [format: ATOM] ~ {
tcFormat ← format;
};
END.