forked from KolibriOS/kolibrios
2f54c7de00
git-svn-id: svn://kolibrios.org@8097 a494cfbc-eb01-0410-851d-a64ba20cac60
87 lines
1.6 KiB
Plaintext
87 lines
1.6 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, x: INTEGER);
|
|
|
|
|
|
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("%*lld"), width, x)
|
|
END Int;
|
|
|
|
|
|
PROCEDURE intval (x: REAL): INTEGER;
|
|
VAR
|
|
i: INTEGER;
|
|
|
|
BEGIN
|
|
SYSTEM.GET(SYSTEM.ADR(x), i)
|
|
RETURN i
|
|
END intval;
|
|
|
|
|
|
PROCEDURE Real* (x: REAL; width: INTEGER);
|
|
BEGIN
|
|
printf3(SYSTEM.SADR("%*.*E"), width, MAX(MIN(width - 8, 15), 1), intval(x))
|
|
END Real;
|
|
|
|
|
|
PROCEDURE FixReal* (x: REAL; width, precision: INTEGER);
|
|
BEGIN
|
|
printf3(SYSTEM.SADR("%*.*f"), width, precision, intval(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. |