Module Files Reference

Input-output of standard data types from/to a storage media.

  The order of bytes used is Little Endian,
  SInt: 2 bytes, Int: 4 bytes, LInt: 8 bytes
  ORD({0}) = 1,
  FALSE = 0, TRUE = 1
  IEEE Real Format,
  Null-terminated strings,
  compact numbers according to M. Odersky

```.

```

Imports

Platform

Constants

This section is empty.

Types

SBYTE = BYTE;

Signed 8-bit integer, -128..127.

BYTE = UBYTE;

Unsigned 8-bit integer, 0..255.

File = POINTER TO FileDesc;

A file object

Rider = RECORD   res: INTEGER;  

(* Residue (byte count not read) at eof of ReadBytes *)

  eof: BOOLEAN  

(* TRUE when end of file is reached. Should be checked after calling Read procedures. *)

END
;

Rider on a file. Used to read or write data from/to a file. Can be set in a arbitrary place in a file. Automatically moves forward in a file every time it is used for reading or writing.

Variables

This section is empty.

Procedures

PROCEDURE Base (VAR r: Rider): File;

Returns a file object that was connected to rider r with Set.

PROCEDURE ChangeDirectory (VAR path: ARRAY OF CHAR; VAR res: INTEGER);

Sets current working directory to path.

Sets res to 0 on success, non-0 on failure.

PROCEDURE Close (f: File);

Flushes the contents of the file to storage media. The file can still be used after a call to Close.

PROCEDURE Delete (VAR name: ARRAY OF CHAR; VAR res: INTEGER);

Deletes (deregisters) a file with the given name from the storage media.

Sets res to 0 on success, 1 on error.

IMPORTANT! It uses SearchPath to find the specified file.

PROCEDURE GetDate (f: File; VAR t: INTEGER; VAR d: INTEGER);

Puts in t and d the time and date of the file in a special bit format:

  d = YYYYYYYMMMMDDDDD  Y-year  M-month   D-day
  t = HHHHmmmmmmSSSSSS  H-hour  m-minute  S-second

The year bits hold the two last digits of the year


PROCEDURE GetName (f: File; VAR name: ARRAY OF CHAR);

Puts in name the naem of the file f.

PROCEDURE Length (f: File): LONGINT;

Returns the length of the given file in bytes

PROCEDURE New (VAR name: ARRAY OF CHAR): File;

Creates and returns a file object with the given file name.

This procedure is used to create new files or rewrite old files, but New does not delete or rewrite the file if it existed — this is done by Register or Close.

PROCEDURE Old (name: ARRAY OF CHAR): File;

Opens a file with the given file name if it exists. Returns the object representing the file. If the file does not exist, returns NIL.

If you write to a file opened with Old, the changes will be stored in the storage medium only after a call to Register or Close.

PROCEDURE Pos (VAR r: Rider): INTEGER;

Returns position of rider r in the file.

Note that the position is measured in bytes (and not characters, each of which is coded in UTF-8 as 1, 2, 3 or 4 bytes).

Position 0 means the position exactly before the very first byte of the file. Position Length() points at exactly after the last byte.

PROCEDURE Purge (f: File);

Frees the sectors of storage device used by the file

PROCEDURE Read (VAR r: Rider; VAR x: BYTE);

Reads one byte from a file and puts it in x.

The rider r must have been set to a file using Set.

PROCEDURE ReadBool (VAR R: Rider; VAR x: BOOLEAN);

Reads one byte from a file and puts it in x as a BOOLEAN value, where byte value of 0 means FALSE, other values mean TRUE.

The rider r must have been set to a file using Set.

PROCEDURE ReadBytes (VAR r: Rider; VAR x: ARRAY OF BYTE; n: INTEGER);

Reads several bytes from a file and puts it in x. Puts the number of bytes read in n.

The rider r must have been set to a file using Set.

PROCEDURE ReadChar (VAR r: Rider; VAR x: CHAR);

Reads up to four bytes (but at least one byte) from a file, interprets them as a UTF-8-encoded character and puts the decoded character in x

(as 2 bytes in UCS-2 format).

The rider r must have been set to a file using Set.

PROCEDURE ReadInt (VAR R: Rider; VAR x: INTEGER);

Reads four bytes from a file and puts them in x as an INTEGER.

The rider r must have been set to a file using Set.

PROCEDURE ReadLInt (VAR R: Rider; VAR x: INT64);

Reads eight bytes from a file and puts them in x as a LONGINT.

The rider r must have been set to a file using Set.

PROCEDURE ReadLReal (VAR R: Rider; VAR x: REAL);

Reads eight bytes from a file and puts it in x as LONGREAL.

The rider r must have been set to a file using Set.

PROCEDURE ReadLine (VAR R: Rider; VAR x: ARRAY OF SHORTCHAR);

Reads bytes from a file until the first 0X, 0AX or 0DX byte, puts all in x (except the last byte).

The rider r must have been set to a file using Set.

PROCEDURE ReadNum (VAR R: Rider; VAR x: INTEGER);

Reads one or more bytes from a file to decode a compact number

(according to M. Odersky), puts the number read in x.

The rider r must have been set to a file using Set.

PROCEDURE ReadReal (VAR R: Rider; VAR x: SHORTREAL);

Reads four bytes from a file and puts it in x as REAL.

The rider r must have been set to a file using Set.

PROCEDURE ReadSInt (VAR R: Rider; VAR x: SHORTINT);

Reads two bytes from a file and puts them in x as a SHORTINT.

The rider r must have been set to a file using Set.

PROCEDURE ReadSet (VAR R: Rider; VAR x: SET);

Reads four bytes from a file and puts it in x as a SET.

The rider r must have been set to a file using Set.

PROCEDURE ReadShortChar (VAR r: Rider; VAR x: SHORTCHAR);

Reads one byte from a file and puts it in x as a short (ASCII) character.

The rider r must have been set to a file using Set.

PROCEDURE ReadShortString (VAR R: Rider; VAR x: ARRAY OF SHORTCHAR);

Reads bytes from a file until the first zero byte, puts all in x.

The rider r must have been set to a file using Set.

PROCEDURE ReadString (VAR R: Rider; VAR x: ARRAY OF CHAR);

Reads a file character by character until the first 0X, puts all in x.

The rider r must have been set to a file using Set.

PROCEDURE Register (f: File);

Registers and saves a file on the storage media.

Call Register when you are finished writing a file. Register can be called several times and anywhere in between.

PROCEDURE Rename (VAR old: ARRAY OF CHAR; VAR new: ARRAY OF CHAR; VAR res: INTEGER);

Renames a file with the name old to new.

Sets res to 0 on success, non-0 on error.

res = 2 means file not found.

IMPORTANT! It uses SearchPath to find the specified file.

PROCEDURE Set (VAR r: Rider; f: File; pos: LONGINT);

Sets rider r at position pos of the file f.

Use this procedure after successfully opening a file with Old or New.

Note that the position is measured in bytes (and not characters, each of which is coded in UTF-8 as 1, 2, 3 or 4 bytes). Position 0 means the position exactly before the very first byte of the file. Position Length() points at exactly after the last byte.

PROCEDURE SetSearchPath (VAR path: ARRAY OF CHAR);

Sets a search path for Old, New, Delete, Rename etc.

PROCEDURE Truncate (F: File; pos: INTEGER);

Truncates a file at position pos. The file length will be equal to pos.

PROCEDURE Write (VAR r: Rider; x: BYTE);

Writes a single byte x to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteBool (VAR R: Rider; x: BOOLEAN);

Writes BOOLEAN x as one byte to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteBytes (VAR r: Rider; VAR x: ARRAY OF BYTE; n: INTEGER);

Writes n bytes from array x to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media. Записывает в файл n байт из массива x.

Бегунок r должен быть установлен на файл с помощью Set.

Файл не записывается на носитель сразу.

PROCEDURE WriteChar (VAR R: Rider; c: CHAR);

Writes character x as UTF-8 to a file (1 to 4 bytes).

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteInt (VAR R: Rider; x: INTEGER);

Writes INTEGER x as four bytes to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteLInt (VAR R: Rider; x: INT64);

Writes LONGINT x as eight bytes to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteLReal (VAR R: Rider; x: REAL);

Writes LONGREAL x as eight bytes to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteNum (VAR R: Rider; x: INTEGER);

Writes INTEGER x as one or more bytes to a file in a compact number format (according to M. Odersky).

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteReal (VAR R: Rider; x: SHORTREAL);

Writes REAL x as four bytes to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteSInt (VAR R: Rider; x: SHORTINT);

Writes SHORTINT x as two bytes to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteSet (VAR R: Rider; x: SET);

Writes SET x as four bytes to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteShortChar (VAR R: Rider; x: SHORTCHAR);

Writes short (1-byte) character x to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteShortString (VAR R: Rider; VAR x: ARRAY OF SHORTCHAR);

Writes string x consising of a 1-byte characters to a file.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.

PROCEDURE WriteString (VAR R: Rider; VAR x: ARRAY OF CHAR);

Writes string x to a file in UTF-8 format.

The rider r must have been set to a file using Set.

The file is not immediately written on a storage media.