2020-05-25 22:48:33 +02:00
|
|
|
(*
|
2020-10-13 09:58:51 +02:00
|
|
|
BSD 2-Clause License
|
2020-05-25 22:48:33 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
Copyright (c) 2020, Anton Krotov
|
|
|
|
All rights reserved.
|
2020-05-25 22:48:33 +02:00
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE Out;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IMPORT SYSTEM, Libdl;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
VAR
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
printf1: PROCEDURE [linux] (fmt: INTEGER; x: INTEGER);
|
|
|
|
printf2: PROCEDURE [linux] (fmt: INTEGER; width, x: INTEGER);
|
|
|
|
printf3: PROCEDURE [linux] (fmt: INTEGER; width, precision: INTEGER; x: REAL);
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE Char* (x: CHAR);
|
2020-05-25 22:48:33 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
printf1(SYSTEM.SADR("%c"), ORD(x))
|
2020-05-25 22:48:33 +02:00
|
|
|
END Char;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE String* (s: ARRAY OF CHAR);
|
2020-05-25 22:48:33 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
printf2(SYSTEM.SADR("%.*s"), LENGTH(s), SYSTEM.ADR(s[0]))
|
2020-05-25 22:48:33 +02:00
|
|
|
END String;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Ln*;
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
printf1(SYSTEM.SADR("%s"), SYSTEM.SADR(0AX))
|
2020-05-25 22:48:33 +02:00
|
|
|
END Ln;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|
|
|
|
PROCEDURE Int* (x, width: INTEGER);
|
2020-05-25 22:48:33 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
printf2(SYSTEM.SADR("%*d"), width, x)
|
|
|
|
END Int;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE Real* (x: REAL; width: INTEGER);
|
2020-05-25 22:48:33 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
printf3(SYSTEM.SADR("%*.*E"), width, MAX(MIN(width - 8, 15), 1), x)
|
2020-05-25 22:48:33 +02:00
|
|
|
END Real;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|
|
|
|
PROCEDURE FixReal* (x: REAL; width, precision: INTEGER);
|
2020-05-25 22:48:33 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
printf3(SYSTEM.SADR("%*.*f"), width, precision, x)
|
2020-05-25 22:48:33 +02:00
|
|
|
END FixReal;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE Open*;
|
|
|
|
END Open;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|
|
|
|
PROCEDURE init;
|
|
|
|
VAR
|
|
|
|
libc, printf: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
libc := Libdl.open("libc.so.6", Libdl.LAZY);
|
|
|
|
ASSERT(libc # 0);
|
|
|
|
printf := Libdl.sym(libc, "printf");
|
|
|
|
ASSERT(printf # 0);
|
|
|
|
SYSTEM.PUT(SYSTEM.ADR(printf1), printf);
|
|
|
|
SYSTEM.PUT(SYSTEM.ADR(printf2), printf);
|
|
|
|
SYSTEM.PUT(SYSTEM.ADR(printf3), printf);
|
|
|
|
END init;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
init
|
2020-05-25 22:48:33 +02:00
|
|
|
END Out.
|