IOTioga.mesa
Copyright Ó 1990, 1991, 1992 by Xerox Corporation. All rights reserved.
Bier, January 15, 1990 5:20:07 pm PST
Doug Wyatt, January 30, 1992 3:16 pm PST
Contents: Some IO streams produce Tioga files as output. These routines allow client control of the character set, character looks, character properties, node properties, and node nesting levels of the Tioga document as it is emitted.
DIRECTORY
IO USING [STREAM],
Rope USING [ROPE],
Tioga USING [CharSet, Looks, noLooks, allLooks, PropList],
TiogaAccess USING [Writer];
IOTioga: CEDAR DEFINITIONS ~ BEGIN
STREAM: TYPE ~ IO.STREAM;
ROPE: TYPE ~ Rope.ROPE;
Character set
CharSet: TYPE ~ Tioga.CharSet;
SetCharSet: PROC [self: STREAM, charSet: CharSet ¬ 0];
Sets the character set. This is normally zero, but may be changed to refer to special characters outside the usual CHAR range (see the Xerox Character Code Standard). Subsequent characters sent to the stream will have the 16-bit character code (charSet*256+ORD[char]).
GetCharSet: PROC [self: STREAM] RETURNS [CharSet];
Returns the current character set.
Looks
Looks: TYPE ~ Tioga.Looks;
noLooks: Looks ~ Tioga.noLooks;
allLooks: Looks ~ Tioga.allLooks;
LooksFromRope: PROC [ROPE] RETURNS [Looks];
Turns the rope into Looks. The result has a TRUE bit for every Look character appearing in the rope. Other characters in the rope are ignored. Case is important (use lower case)!
RopeFromLooks: PROC [Looks] RETURNS [ROPE];
Turns the Looks into a rope. LooksFromRope[RopeFromLooks[x]]=x.
ChangeLooks: PROC [self: STREAM, remove, add: Looks ¬ noLooks];
First removes, then adds the specified looks (compare TextLooksSupport.ModifyLooks).
Subsequent characters sent to the stream will have the new looks.
AddLooks: PROC [self: STREAM, looks: Looks]
~ INLINE { ChangeLooks[self: self, remove: noLooks, add: looks] };
RemoveLooks: PROC [self: STREAM, looks: Looks]
~ INLINE { ChangeLooks[self: self, remove: looks, add: noLooks] };
SetLooks: PROC [self: STREAM, looks: Looks]
~ INLINE { ChangeLooks[self: self, remove: allLooks, add: looks] };
ClearLooks: PROC [self: STREAM]
~ INLINE { ChangeLooks[self: self, remove: allLooks, add: noLooks] };
GetLooks: PROC [self: STREAM] RETURNS [Looks];
Returns the current looks.
Character properties
Note: clients of this interface must regard a PropList as immutable!
PropList: TYPE ~ Tioga.PropList;
PropPut: PROC [propList: PropList, key: REF, val: REF] RETURNS [PropList];
Returns a PropList containing (key, val). Get[Put[propList, key, val], key]=val.
PropGet: PROC [propList: PropList, key: REF] RETURNS [val: REF];
Returns val associated with key, NIL if none. Uses REF equality to compare keys.
SetCharProps: PROC [self: STREAM, propList: PropList];
Sets the list of character properties. The supplied propList must not later be modified.
Subsequent characters sent to the stream will have the new properties.
GetCharProps: PROC [self: STREAM] RETURNS [PropList];
Returns the current list of character properties.
Node properties
SetNodeProp: PROC [self: STREAM, name: ATOM, value: REF];
Sets a node property for the current node.
GetNodeProp: PROC [self: STREAM, name: ATOM] RETURNS [value: REF];
Returns the current node properties.
MapPropsAction: TYPE ~ PROC [name: ATOM, value: REF] RETURNS [quit: BOOL ¬ FALSE];
same as TextEdit.MapPropsAction
MapNodeProps: PROC [self: STREAM, action: MapPropsAction] RETURNS [BOOL];
Calls action for each of the current node properties.
FormatFromRope: PROC [ROPE] RETURNS [ATOM];
Turns the rope into a suitable $Format property value (forces lower case).
SetFormat: PROC [self: STREAM, format: ATOM];
Sets the $Format property of the current node.
Equivalent to SetNodeProp[self, $Format, format].
GetFormat: PROC [self: STREAM] RETURNS [ATOM];
Gets the $Format property of the current node.
Equivalent to NARROW[GetNodeProp[self, $Format], ATOM].
CommentFromBool: PROC [BOOL] RETURNS [REF];
Turns the boolean into a suitable $Comment property value (by table lookup).
BoolFromComment: PROC [REF] RETURNS [BOOL];
Turns a $Comment property value into a boolean.
SetComment: PROC [self: STREAM, comment: BOOL];
Sets the $Comment property of the current node.
Equivalent to SetNodeProp[self, $Comment, CommentFromBool[comment]].
GetComment: PROC [self: STREAM] RETURNS [BOOL];
Gets the $Comment property of the current node.
Equivalent to BoolFromComment[GetNodeProp[self, $Comment]].
Tree structure
SetLevel: PROC [self: STREAM, level: CARDINAL];
Sets the nesting level of the current node, which must not exceed the nesting level of the node that precedes it by more than 1. <<Signal otherwise>>
GetLevel: PROC [self: STREAM] RETURNS [level: CARDINAL];
Returns the current (absolute) nesting level.
Break: PROC [self: STREAM];
Creates a new node after the last character that was sent to self. Characters added to self after this call will be placed in this new node. The new node has the same nesting level as the previous node. Use SetLevel to change the nesting level.
Stream creation
CreateTiogaAccessStream: PROC RETURNS [STREAM];
Creates an IOTioga stream directed at a TiogaAccess.Writer. Typical use:
stream: STREAM ~ IOTioga.CreateTiogaAccessStream[];
EmitDocument[stream]; -- can use all the IOTioga operations
TiogaAccess.WriteFile[IOTioga.WriterFromStream[stream], "Foo.tioga"];
WriterFromStream: PROC [self: STREAM] RETURNS [TiogaAccess.Writer];
Returns the TiogaAccess.Writer associated with the stream.
Exceptions
Signal: SIGNAL [code: ATOM, msg: ROPE];
END.