TiogaFileIO.mesa
Copyright Ó 1991, 1992 by Xerox Corporation. All rights reserved.
Doug Wyatt, October 22, 1991 11:11 am PDT
DIRECTORY
IO USING [STREAM];
TiogaFileIO: CEDAR DEFINITIONS ~ BEGIN
The external representation of a Tioga document has three parts:
part1, the data part, contains the text of each (non-comment) node, separated by newlines
part2, the comment part, contains the text of each comment node, separated by newlines
part3, the control part, contains everything else: looks, properties, tree structure ...
Tioga's file format encapsulates these three parts with some additional information that specifies the position and size of each part and identifies the file as a Tioga file. The procedures in this interface read and write the encapsulation.
If you read just the data part, which comes first in the file, you will see just the plain text of all the non-comment nodes in the document. Cedar's file streams (see PFS.StreamOpen) normally reveal just the data part; because of this trick, the compiler, for example, can read Tioga source files without being confused by the formatting or the arbitrary content of comment nodes (like the comment node you're reading now).
Since PFS must determine whether a file is a Tioga file, and if so where its data part ends, we define this skeletal part of Tioga's file format here in the IO package, so that PFS and Tioga can share it. All other details of Tioga's external representation are defined in the Tioga package.
Parts: TYPE ~ RECORD [isTioga: BOOL, start1, len1, start2, len2, start3, len3: INT ¬ 0];
If isTioga, start* and len* specify the locations of the three parts.
If ~isTioga, [start1..start1+len1) is the entire content, len2=len3=0.
GetParts: PROC [s: IO.STREAM, start: INT ¬ 0, len: INT ¬ INT.LAST] RETURNS [Parts];
Reads from s to determine whether [start..start+len) is a Tioga file.
s must support GetIndex/SetIndex/GetLength; len defaults to (GetLength[s]-start).
PutParts: PROC [s: IO.STREAM, put: PROC [s1, s2, s3: IO.STREAM]] RETURNS [len1: INT];
Writes a Tioga file to s; calls put to emit the three parts; returns the length of the data part.
END.