2f54c7de00
git-svn-id: svn://kolibrios.org@8097 a494cfbc-eb01-0410-851d-a64ba20cac60
107 lines
1.6 KiB
Plaintext
107 lines
1.6 KiB
Plaintext
(*
|
|
BSD 2-Clause License
|
|
|
|
Copyright (c) 2018-2020, Anton Krotov
|
|
All rights reserved.
|
|
*)
|
|
|
|
MODULE WRITER;
|
|
|
|
IMPORT FILES, ERRORS, UTILS;
|
|
|
|
|
|
VAR
|
|
|
|
counter*: INTEGER;
|
|
file: FILES.FILE;
|
|
|
|
|
|
PROCEDURE align* (n, _align: INTEGER): INTEGER;
|
|
BEGIN
|
|
IF n MOD _align # 0 THEN
|
|
INC(n, _align - (n MOD _align))
|
|
END
|
|
|
|
RETURN n
|
|
END align;
|
|
|
|
|
|
PROCEDURE WriteByte* (n: BYTE);
|
|
BEGIN
|
|
IF FILES.WriteByte(file, n) THEN
|
|
INC(counter)
|
|
ELSE
|
|
ERRORS.Error(201)
|
|
END
|
|
END WriteByte;
|
|
|
|
|
|
PROCEDURE Write* (chunk: ARRAY OF BYTE; bytes: INTEGER);
|
|
VAR
|
|
n: INTEGER;
|
|
|
|
BEGIN
|
|
n := FILES.write(file, chunk, bytes);
|
|
IF n # bytes THEN
|
|
ERRORS.Error(201)
|
|
END;
|
|
INC(counter, n)
|
|
END Write;
|
|
|
|
|
|
PROCEDURE Write64LE* (n: INTEGER);
|
|
VAR
|
|
i: INTEGER;
|
|
|
|
BEGIN
|
|
FOR i := 0 TO 7 DO
|
|
WriteByte(UTILS.Byte(n, i))
|
|
END
|
|
END Write64LE;
|
|
|
|
|
|
PROCEDURE Write32LE* (n: INTEGER);
|
|
VAR
|
|
i: INTEGER;
|
|
|
|
BEGIN
|
|
FOR i := 0 TO 3 DO
|
|
WriteByte(UTILS.Byte(n, i))
|
|
END
|
|
END Write32LE;
|
|
|
|
|
|
PROCEDURE Write16LE* (n: INTEGER);
|
|
BEGIN
|
|
WriteByte(UTILS.Byte(n, 0));
|
|
WriteByte(UTILS.Byte(n, 1))
|
|
END Write16LE;
|
|
|
|
|
|
PROCEDURE Padding* (FileAlignment: INTEGER);
|
|
VAR
|
|
i: INTEGER;
|
|
|
|
BEGIN
|
|
i := align(counter, FileAlignment) - counter;
|
|
WHILE i > 0 DO
|
|
WriteByte(0);
|
|
DEC(i)
|
|
END
|
|
END Padding;
|
|
|
|
|
|
PROCEDURE Create* (FileName: ARRAY OF CHAR);
|
|
BEGIN
|
|
counter := 0;
|
|
file := FILES.create(FileName)
|
|
END Create;
|
|
|
|
|
|
PROCEDURE Close*;
|
|
BEGIN
|
|
FILES.close(file)
|
|
END Close;
|
|
|
|
|
|
END WRITER. |