2f54c7de00
git-svn-id: svn://kolibrios.org@8097 a494cfbc-eb01-0410-851d-a64ba20cac60
77 lines
1.4 KiB
Plaintext
77 lines
1.4 KiB
Plaintext
(*
|
|
BSD 2-Clause License
|
|
|
|
Copyright (c) 2020, Anton Krotov
|
|
All rights reserved.
|
|
*)
|
|
|
|
MODULE Out;
|
|
|
|
IMPORT SYSTEM, Libdl;
|
|
|
|
|
|
VAR
|
|
|
|
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);
|
|
|
|
|
|
PROCEDURE Char* (x: CHAR);
|
|
BEGIN
|
|
printf1(SYSTEM.SADR("%c"), ORD(x))
|
|
END Char;
|
|
|
|
|
|
PROCEDURE String* (s: ARRAY OF CHAR);
|
|
BEGIN
|
|
printf2(SYSTEM.SADR("%.*s"), LENGTH(s), SYSTEM.ADR(s[0]))
|
|
END String;
|
|
|
|
|
|
PROCEDURE Ln*;
|
|
BEGIN
|
|
printf1(SYSTEM.SADR("%s"), SYSTEM.SADR(0AX))
|
|
END Ln;
|
|
|
|
|
|
PROCEDURE Int* (x, width: INTEGER);
|
|
BEGIN
|
|
printf2(SYSTEM.SADR("%*d"), width, x)
|
|
END Int;
|
|
|
|
|
|
PROCEDURE Real* (x: REAL; width: INTEGER);
|
|
BEGIN
|
|
printf3(SYSTEM.SADR("%*.*E"), width, MAX(MIN(width - 8, 15), 1), x)
|
|
END Real;
|
|
|
|
|
|
PROCEDURE FixReal* (x: REAL; width, precision: INTEGER);
|
|
BEGIN
|
|
printf3(SYSTEM.SADR("%*.*f"), width, precision, x)
|
|
END FixReal;
|
|
|
|
|
|
PROCEDURE Open*;
|
|
END Open;
|
|
|
|
|
|
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
|
|
END Out. |