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 In;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IMPORT SYSTEM;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
CONST
|
2020-05-25 22:48:33 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
MAX_LEN = 1024;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
Done*: BOOLEAN;
|
|
|
|
hConsoleInput: INTEGER;
|
|
|
|
s: ARRAY MAX_LEN + 4 OF CHAR;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE [windows, "msvcrt.dll", ""] sscanf (buf: INTEGER; fmt: INTEGER; adr: INTEGER): INTEGER;
|
|
|
|
PROCEDURE [windows, "kernel32.dll", ""] GetStdHandle (nStdHandle: INTEGER): INTEGER;
|
|
|
|
PROCEDURE [windows, "kernel32.dll", ""] ReadConsoleA (hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, lpReserved: INTEGER);
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE String* (VAR str: ARRAY OF CHAR);
|
|
|
|
VAR
|
|
|
|
count: INTEGER;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
ReadConsoleA(hConsoleInput, SYSTEM.ADR(s[0]), MAX_LEN, SYSTEM.ADR(count), 0);
|
|
|
|
IF (s[count - 1] = 0AX) & (s[count - 2] = 0DX) THEN
|
|
|
|
DEC(count, 2)
|
2020-05-25 22:48:33 +02:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
s[count] := 0X;
|
|
|
|
COPY(s, str);
|
|
|
|
str[LEN(str) - 1] := 0X;
|
|
|
|
Done := TRUE
|
|
|
|
END String;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE Int* (VAR x: INTEGER);
|
2020-05-25 22:48:33 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
String(s);
|
|
|
|
Done := sscanf(SYSTEM.ADR(s[0]), SYSTEM.SADR("%lld"), SYSTEM.ADR(x)) = 1
|
|
|
|
END Int;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|
|
|
|
PROCEDURE Real* (VAR x: REAL);
|
2020-05-25 22:48:33 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
String(s);
|
|
|
|
Done := sscanf(SYSTEM.ADR(s[0]), SYSTEM.SADR("%lf"), SYSTEM.ADR(x)) = 1
|
|
|
|
END Real;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE Char* (VAR x: CHAR);
|
2020-05-25 22:48:33 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
String(s);
|
|
|
|
x := s[0]
|
2020-05-25 22:48:33 +02:00
|
|
|
END Char;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE Ln*;
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
String(s)
|
2020-05-25 22:48:33 +02:00
|
|
|
END Ln;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Open*;
|
|
|
|
BEGIN
|
|
|
|
hConsoleInput := GetStdHandle(-10);
|
|
|
|
Done := TRUE
|
|
|
|
END Open;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
END In.
|