TiogaAccess.mesa
Copyright (C) 1985, Xerox Corporation. All rights reserved.
Michael Plass, February 4, 1985 1:22:46 pm PST
Provides for sequential processing of Tioga documents, including looks and formatting information.
Buffers
Buffer: TYPE ~ REF BufferRep;
BufferRep:
TYPE ~
RECORD [length:
NAT, next: Buffer, seq:
SEQUENCE maxLength:
NAT
OF CharWithLooks];
Handy for passing around collections of elements; don't bother to use these to gain speed, but just where it makes sense to the logic of your program. May be chained to represent sequences longer than can be represented in one buffer.
ObtainBuffer:
PROC [pieceSize:
NAT ← 180]
RETURNS [Buffer];
ReleaseBuffer:
PROC [buffer: Buffer];
BufferSize:
PROC [buffer: Buffer]
RETURNS [
INT];
SetBufferSize:
PROC [buffer: Buffer, newSize:
INT];
Append:
PROC [buffer: Buffer, value: CharWithLooks];
Extends buffer if necessary.
Store:
PROC [buffer: Buffer, index:
INT, value: CharWithLooks];
Error if index >= BufferSize[buffer]
Fetch:
PROC [buffer: Buffer, index:
INT]
RETURNS [CharWithLooks];
The Reader type and its basic operations
Reader: TYPE ~ REF ReaderRep;
FromNothing:
PROC
RETURNS [Reader];
Not good for much except PutBack.
FromFile: PROC [fileName: Rope.ROPE] RETURNS [Reader];
FromOpenFile:
PROC [openFile:
FS.OpenFile]
RETURNS [Reader];
The OpenFile is closed by this call.
FromSelection:
PROC
RETURNS [Reader];
Makes a reader on a copy of the contents of the primary selection.
FromViewer:
PROC [viewer: ViewerClasses.Viewer]
RETURNS [Reader];
Must be a text or typescript viewer.
Makes a reader on a copy of the viewer contents.
EndOf:
PROC [reader: Reader]
RETURNS [
BOOLEAN];
GetNodeInfo:
PROC [reader: Reader]
RETURNS [NodeInfo];
Get:
PROC [reader: Reader]
RETURNS [CharWithLooks];
The Writer type and its operations
Writer: TYPE ~ REF WriterRep;
Create:
PROC
RETURNS [Writer];
Put:
PROC [writer: Writer, charWithLooks: CharWithLooks];
PutNodeInfo:
PROC [writer: Writer, nodeInfo: NodeInfo];
Sets the format and property information for the current node.
In case this is called more than once per node, the last one wins.
PutBuffer:
PROC [writer: Writer, buffer: Buffer, start:
INT ← 0, maxLength:
INT ←
INT.
LAST];
WriteFile:
PROC [writer: Writer, fileName: Rope.
ROPE];
The write operations do the write, and reset the writer to a clean state.
WriteOpenFile:
PROC [writer: Writer, openFile:
FS.OpenFile];
Closes the OpenFile after writing it.
WriteSelection:
PROC [writer: Writer];
Replaces the primary selection. Clients should use TiogaOps.CallWithLocks or equivalent to avoid race conditions with the user.
WriteViewer:
PROC [writer: Writer, viewer: ViewerClasses.Viewer];
Must be a text or typescript viewer.
Replaces the contents of the viewer.
WriteReader:
PROC [writer: Writer]
RETURNS [Reader];
Good for processing the whole document again.
Reset:
PROC [writer: Writer];
Throws the currently accumulated contents away.
Subsidiary Reader operations
DoneWith:
PROC [reader: Reader];
Optional; frees up storage and locks sooner than garbage collector.
GetBuffer:
PROC [reader: Reader, buffer: Buffer, start:
INT ← 0, maxLength:
INT ←
INT.
LAST]
RETURNS [endOfNode:
BOOLEAN];
BufferSize[buffer] is set to start + (number of chars read).
Stops with end-of-node marker or when maxLength characters have been read.
Returns TRUE if last thing in buffer is an end-of-node marker.
Peek:
PROC [reader: Reader]
RETURNS [CharWithLooks];
PeekRope:
PROC [reader: Reader]
RETURNS [Rope.
ROPE];
Returns the contents of the remainder of the node as a rope.
SkipToNextNode:
PROC [reader: Reader];
Discards data until the end of the current node.
CopyNode:
PROC [writer: Writer, reader: Reader, maxLength:
INT ←
INT.
LAST, copyInfo:
BOOLEAN ←
TRUE]
RETURNS [endOfNode:
BOOLEAN];
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.
If copyInfo, the NodeInfo of the node is copied as well.
GetNodeRefs:
PROC [reader: Reader]
RETURNS [root, current:
REF, offset:
INT];
Returns the root and current node of the document, and the offset into the current node.
Each REF may be narrowed into a TextNode.Ref
Provided for clients that need access to Tioga's style machinery.
GetIndex:
PROC [reader: Reader]
RETURNS [index:
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.
SetIndex:
PROC [reader: Reader, index:
INT];
Discards anything created by PutBack before setting index.
SetPosition:
PROC [reader: Reader, position:
INT];
PutBack: PROC [reader: Reader, charWithLooks: CharWithLooks];
PutBackBuffer:
PROC [reader: Reader, buffer: Buffer, start:
INT ← 0, maxLength:
INT ←
INT.
LAST];
Contents may differ from what was originally read.