(* Title: PageStream - Definitions LastEdit: "Mon Sep 17 14:21:57 1984" Author: jd/mjj Cambridge University Computer Laboratory Page-image stream *) DEFINITION MODULE PageStream; (* This module maps a stream onto a pages of lines of characters. Lines are delimited by the CharCodes.NewLineCh character (or by writing beyond the line width) and pages are delimited by the CharCodes.FormFeedCh characters (or by writing beyond the end of the last line on the page). Seeking and Telling within the current line are permitted, and procedures may be defined to be called when a new line is made available and when a new page is made available. *) FROM Streams IMPORT Stream, SeekMode; EXPORT QUALIFIED CreateOutput, SeekChar, TellChar, TellLine, TellPage, EventProc, LineEvent, PageEvent; TYPE EventProc = PROCEDURE (Stream, CARDINAL); PROCEDURE CreateOutput (s: Stream; pageWidth, pageLength: CARDINAL; insertTabs, lineFold: BOOLEAN): Stream; (* Manufactures a new stream from the old one by buffering up to pagewidth characters of output. Seek and Tell (or their simpler forms given below) are implemented within individual lines, that is, between newline characters. In this context, SeekMode beginning means the beginning of the current buffered line, and end the end of the line as defined by the maximum line length. After this call, the current page, line and character numbers are all 1. InsertTabs defines whether or not tab characters may be inserted in the output stream in place of sequences of spaces where this will not alter the spacing within the line. LineFold defines whether input lines which are longer than PageWidth will be folded to a new output line (TRUE) or clipped (FALSE); *) PROCEDURE SeekChar (s: Stream; seekMode: SeekMode; offset: INTEGER); (* Just like Streams.Seek except that we don't need LongINTEGER *) PROCEDURE TellChar (s: Stream): CARDINAL; (* Returns current char number in line in the range 1..pagewidth *) PROCEDURE TellLine (s: Stream): CARDINAL; (* Returns current line number in the range 1..pagelength *) PROCEDURE TellPage (s: Stream): CARDINAL; (* Returns current page number, >= 1 *) PROCEDURE PageEvent (s: Stream; P: EventProc); (* Defines a procedure which is called before writing the first character of each page. P may itself call Put, but will be called recursively if it causes a further new page. *) PROCEDURE LineEvent (s: Stream; P: EventProc); (* Defines a procedure which is called before writing the first character of each line of a page except the first. P may itself call Put, but will be called recursively on a new line. Note that P will not be called for the first line of the page, and the PageEvent will be called instead. *) END PageStream.