TiogaAccess.mesa
Copyright Ó 1985, 1986, 1991 by Xerox Corporation. All rights reserved.
Michael Plass, March 25, 1985 10:04:18 am PST
Willie-s, February 12, 1991 2:03 pm PST
Doug Wyatt, December 17, 1991 11:48 pm PST
Provides for sequential processing of Tioga documents, including looks and formatting information.
DIRECTORY
PFS USING [ErrorGroup, OpenFile],
Rope USING [ROPE],
Tioga USING [Looks, CharSet, PropList, Node, Location];
TiogaAccess: CEDAR DEFINITIONS ~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
Basic types
Looks: TYPE ~ Tioga.Looks;
CharSet: TYPE ~ Tioga.CharSet; -- = Char.CharSet
PropList: TYPE ~ Tioga.PropList; -- = Prop.PropList
TiogaChar: TYPE ~ PACKED RECORD [
charSet: CharSet, -- used with char to represent an extended character
char: CHAR,
looks: Looks,
format: ATOM,
comment: BOOL,
endOfNode: BOOL,
deltaLevel: [-16000..1],
propList: PropList
Immutable! This is the character property list unless endOfNode is TRUE, in which case it is the node property list.
];
Property lists
The property lists have ATOMs for keys and REFs for values, the values being in their internal representation. Use GetExternalProp and GetInternalProp to translate between the internal REF ANY form and the external ROPE form. The format, comment, charsets and charprops properties are not replicated in the node property list. The property lists should be regarded as immutable.
GetExternalProp: PROC [key: ATOM, value: REF] RETURNS [ROPE];
GetInternalProp: PROC [key: ATOM, value: ROPE] RETURNS [REF];
Errors
Error: ERROR [group: PFS.ErrorGroup, expl: ROPE];
Clients may get errors from PFS or IO from the file-oriented operations.
The Reader type and its basic operations
Reader: TYPE ~ REF ReaderRep;
ReaderRep: TYPE;
FromNode: PROC [node: Tioga.Node, offset: INT ¬ 0] RETURNS [Reader];
Does not copy; the Reader must have exclusive access!
FromFile: PROC [fileName: ROPE] RETURNS [Reader];
FromOpenFile: PROC [openFile: PFS.OpenFile] RETURNS [Reader];
The OpenFile is closed by this call.
EndOf: PROC [reader: Reader] RETURNS [BOOL];
Get: PROC [reader: Reader] RETURNS [TiogaChar];
Peek: PROC [reader: Reader] RETURNS [TiogaChar];
GetNodeProps: PROC [reader: Reader] RETURNS [PropList];
Provides an advanced look at the property list that will accompany the next endOfNode.
The Writer type and its operations
Writer: TYPE ~ REF WriterRep;
WriterRep: TYPE;
Create: PROC RETURNS [Writer];
Put: PROC [writer: Writer, tiogaChar: TiogaChar];
format and comment fields are ignored unless tiogaChar.endOfNode is TRUE.
Nest: PROC [writer: Writer, delta: INT];
Changes the nesting level of the current node by the specified amount. May raise Error if an attempt is made to change the nesting level to an illegal value.
WriteFile: PROC [writer: Writer, fileName: ROPE];
The write operations do the write, and reset the writer to a clean state.
WriteOpenFile: PROC [writer: Writer, openFile: PFS.OpenFile];
Closes the OpenFile after writing it.
WriteReader: PROC [writer: Writer] RETURNS [Reader];
Good for processing the whole document again.
WriteNode: PROC [writer: Writer] RETURNS [Tioga.Node];
Returns the root node of the completed document.
Reset: PROC [writer: Writer];
Throws the currently accumulated contents away.
Subsidiary operations
DoneWith: PROC [reader: Reader];
Optional; frees up storage and locks sooner than garbage collector.
PeekRope: PROC [reader: Reader] RETURNS [ROPE];
Returns the contents of the remainder of the node as a rope.
SkipToNextNode: PROC [reader: Reader] RETURNS [deltaLevel: INT];
Discards data until the end of the current node.
CopyNode: PROC [writer: Writer, reader: Reader,
maxLength: INT ¬ INT.LAST] RETURNS [nodeEnd: BOOL];
Copies data until the end of the current node, or until maxLength chars have been copied.
Returns TRUE if current node was copied all the way to its end.
GetIndex: PROC [reader: Reader] RETURNS [INT];
Counts one per character, plus one per node; ignores anything created by PutBack.
GetLength: PROC [reader: Reader] RETURNS [INT];
Value of GetIndex[reader] when EndOf[reader] is TRUE.
GetPosition: PROC [reader: Reader] RETURNS [position: INT];
Like GetIndex, but doesn't count comment nodes. Corresponds to Tioga's Position button.
GetLocation: PROC [reader: Reader] RETURNS [Tioga.Location];
Returns the current Location in the document being read.
Provided for clients that need access to Tioga's lower level machinery.
SetIndex: PROC [reader: Reader, index: INT];
Discards anything created by PutBack before setting index.
SetPosition: PROC [reader: Reader, position: INT];
PutBack: PROC [reader: Reader, tiogaChar: TiogaChar];
Contents may differ from what was originally read.
FinishWrite: PROC [writer: Writer, action: PROC [root, first, last: Tioga.Node]];
END.