Модуль Texts Справочный лист

Module for reading and writing text files

Постоянные

Этот раздел пуст.

Типы

Text = POINTER TO TextDesc;

Text object

TextDesc = RECORD   len: INTEGER;  

(* Length of the text file in bytes (not characters!). *)

  changed: BOOLEAN  

(* TRUE if the text has been changed *)

END
;
Reader = RECORD   eot: BOOLEAN;  

(* TRUE if end of text has been reached *)

  col: INTEGER  

(* Color. Not used. *)

END
;

A rider on a text object to read it one character at a time

Scanner = RECORD(Reader)   nextCh: CHAR;  

(* A read-ahead character value *)

  line: INTEGER;  

(* Current line number *)

  class: INTEGER;  

(* One of the scanner class constants (see above) *)

  i: INTEGER;  

(* If class = Int, i = the value of the scanned integer *)

  x: REAL;  

(* If class = Real, x = the value of the scanned real number *)

  c: CHAR;  

(* If class = Char, c = the value of the scanned character *)

  len: INTEGER;  

(* If class = String, len holds the string length *)

  s: ARRAY 1900 OF CHAR  

(* If class = String, s holds the string *)

END
;

A rider on a text object to read and parse (scan) it in small pieces

Buffer = POINTER TO BufDesc;

Buffer of a piece of text

The idea is to write a piece of text first into a Buffer, and thereafter insert or append it to a Text. This is done for reasons of efficiency, because the possibly needed rendering of the text, for example on a display, can be done once upon insertion of the buffered piece of text rather than after generating each character.

BufDesc = RECORD   len: INTEGER  
END
;
Writer = RECORD   buf: Buffer;  

(* The Writer's internal buffer *)

  col: INTEGER  

(* Color. Not used. *)

END
;

An obeject that is used to write a piece of text in a Buffer

Переменные

Этот раздел пуст.

Процедуры

PROCEDURE Append (T: Text; B: Buffer);

Appends the contents of buffer B into the end of text T

PROCEDURE ChangeColor (T: Text; beg: INTEGER; end: INTEGER; col: INTEGER);

Changes the color of the piece of T at [bef; end) to col.

Does not work.

PROCEDURE Close (T: Text; name: ARRAY OF CHAR);

Store text T on a storage medium as a file with the given name

PROCEDURE Copy (SB: Buffer; DB: Buffer);

Copies the contents of the source buffer SB to the destination buffer DB

PROCEDURE Delete (T: Text; beg: INTEGER; end: INTEGER; B: Buffer);

Copies a piece of text T from position beg (inclusive) to position end (exclusive) to buffer B and deletes this piece from text T. The previous content of B is deleted.

PROCEDURE GetColor (T: Text; pos: INTEGER; VAR col: INTEGER);

Puts in col the color of a character in T at position pos

PROCEDURE Insert (T: Text; pos: INTEGER; B: Buffer);

Inserts the contents of buffer B into text T at position pos

PROCEDURE Load (VAR R: Files.Rider; T: Text);

Loads text T from file via rider r attached to the file

PROCEDURE Open (T: Text; name: ARRAY OF CHAR);

Initialize Text T.

If name is non-empty, open file with name name and load it in T.

If name is an empty string, create a new empty Text.

PROCEDURE OpenBuf (B: Buffer);

Initialize buffer B as an empty buffer

PROCEDURE OpenReader (VAR R: Reader; T: Text; pos: INTEGER);

Initializes Reader R by setting it to position pos of text T

PROCEDURE OpenScanner (VAR S: Scanner; T: Text; pos: INTEGER);

Initializes Scanner S by setting it to position pos of text T

PROCEDURE OpenWriter (VAR W: Writer);

Initializes Writer W by setting it to position pos of text T

PROCEDURE Pos (VAR R: Reader): INTEGER;

Returns the current position of R in bytes (not characters!).

PROCEDURE Read (VAR R: Reader; VAR ch: CHAR);

Reads a character fro the text attached the reader R and puts it in ch. Reader R is advanced (moved forward) by 1-4 bytes, because the encoding is UTF-8.

PROCEDURE Save (T: Text; beg: INTEGER; end: INTEGER; B: Buffer);

Saves piece of text T from beg (inclusive) to end (exclusive) to buffer B. The previous content of B is deleted.

PROCEDURE Scan (VAR S: Scanner);

Scans the text attached to S and reads whatever is in the text. Stores the scanned value in S. S.class is set to one of the possbile constants

(see above).

The options are: an integer (Int), a real value (Real), a string in quotes (String), a sequence of non-space characters (Name), a single

(otherwise unrecognized) character (Char) or an invalid value (Inval, also means end of text).

The integer result is stored in S.i, real — in S.x, character — in S.c, string — in S.s (the string) and S.len (the length of the string).

The line number in S.line is the line number of the next character that is always held in a S.nextCh.

Call OpenScanner, then Scan, then check the value of S.class.

PROCEDURE SetColor (VAR W: Writer; col: INTEGER);

Sets the color of the Writer.

Does not work.

PROCEDURE Store (VAR W: Files.Rider; T: Text);

Write text T into a file via rider r attached to the file

PROCEDURE Write (VAR W: Writer; ch: CHAR);

Writes character ch into the internal buffer of Writer W

PROCEDURE WriteHex (VAR W: Writer; x: INTEGER);

Writes x as a hexadecimal integer into the internal buffer of Writer W.

PROCEDURE WriteInt (VAR W: Writer; x: INTEGER; n: INTEGER);

Writes integer x into the internal buffer of Writer W.

n means the minimum number of characters to write

(the number gets prefixed with spaces).

PROCEDURE WriteLn (VAR W: Writer);

Writes next line character (or CRLF pair on Windows) into the internal buffer of Writer W

PROCEDURE WriteReal (VAR W: Writer; x: REAL; n: INTEGER);

Writes real number x into the internal buffer of Writer W.

n means the minimum number of characters to write

(the number gets prefixed with spaces).

PROCEDURE WriteRealFix (VAR W: Writer; x: REAL; n: INTEGER; k: INTEGER);

Writes real number x into the internal buffer of Writer W.

n means the minimum number of characters to write

(the number gets prefixed with spaces)

k means the number of digits after a decimal point.

PROCEDURE WriteString (VAR W: Writer; s: ARRAY OF CHAR);

Writes string s into the internal buffer of Writer W