compiler/bootstrap/windows-88/Console.c
David C W Brown da88496c5f Tidy (#41)
* Deduplicate common constants into OPM and do some source format tidying.

* Fix postpush buildall script to force checkout of updated buildall.

* Show enlistment branch in makefiles

* Support non-printables in string literals and tidy case alignment and constant literals.

* Common code for MIN and MAX of integer types.

* Common code for SInt/Int/LInt in ConstOp parameter preparation.

* Common code for SInt/Int/LInt in Op parameter preparation.

* Refactor SetIntType to work with byte size directly. Prepare to revert my incorrect VAL changes.

* Original meaning of VAL restored. Many library files disabled until use of VAL in 64 bits fixed.

* Make Reals.Mod independent of INTEGER size and add reals tests.

* Implement fraction, IsInfinity and IsNaN in oocLowReal.Mod.

* OPB little simplifications and ShorterSize/LongerSize functions.

* Add test for alignment computability

* Replace alignment constants with calculated alignment.

* typ.size aware OPV.Convert

* Add SYSTEM_INT64 and make tests name independent.

* Remove SYSTEM.H includes (string.h and stdint.h).

* Replace uses of uintptr_t and size_t with SYSTEM_ADDRESS.

* Sad hack to make FreeBSD and OpenBSD happy with memcpy declaration.

* Detect 64 bit on FreeBSD, and size_t defined on OpenBSD.

* %zd not supportd by mingw, cast strnlen return to int.

* Add debug for intermittent failure only on OpenBSD.

* Add textTexts as a confidence test and tidy up a couple of other tests.

* Update binary test process.
2016-08-25 14:41:00 +01:00

151 lines
2.7 KiB
C

/* voc 1.95 [2016/08/23] for gcc LP64 on cygwin xtspkaSfF */
#define LARGE
#include "SYSTEM.h"
#include "Platform.h"
static CHAR Console_line[128];
static INTEGER Console_pos;
export void Console_Bool (BOOLEAN b);
export void Console_Char (CHAR ch);
export void Console_Flush (void);
export void Console_Hex (LONGINT i);
export void Console_Int (LONGINT i, LONGINT n);
export void Console_Ln (void);
export void Console_Read (CHAR *ch);
export void Console_ReadLine (CHAR *line, LONGINT line__len);
export void Console_String (CHAR *s, LONGINT s__len);
void Console_Flush (void)
{
INTEGER error;
error = Platform_Write(Platform_StdOut, (LONGINT)(SYSTEM_ADDRESS)Console_line, Console_pos);
Console_pos = 0;
}
void Console_Char (CHAR ch)
{
if (Console_pos == 128) {
Console_Flush();
}
Console_line[__X(Console_pos, ((LONGINT)(128)))] = ch;
Console_pos += 1;
if (ch == 0x0a) {
Console_Flush();
}
}
void Console_String (CHAR *s, LONGINT s__len)
{
INTEGER i;
__DUP(s, s__len, CHAR);
i = 0;
while (s[__X(i, s__len)] != 0x00) {
Console_Char(s[__X(i, s__len)]);
i += 1;
}
__DEL(s);
}
void Console_Int (LONGINT i, LONGINT n)
{
CHAR s[32];
LONGINT i1, k;
if (i == __LSHL(1, 63, LONGINT)) {
__MOVE("8085774586302733229", s, 20);
k = 19;
} else {
i1 = __ABS(i);
s[0] = (CHAR)(__MOD(i1, 10) + 48);
i1 = __DIV(i1, 10);
k = 1;
while (i1 > 0) {
s[__X(k, ((LONGINT)(32)))] = (CHAR)(__MOD(i1, 10) + 48);
i1 = __DIV(i1, 10);
k += 1;
}
}
if (i < 0) {
s[__X(k, ((LONGINT)(32)))] = '-';
k += 1;
}
while (n > k) {
Console_Char(' ');
n -= 1;
}
while (k > 0) {
k -= 1;
Console_Char(s[__X(k, ((LONGINT)(32)))]);
}
}
void Console_Ln (void)
{
Console_Char(0x0a);
}
void Console_Bool (BOOLEAN b)
{
if (b) {
Console_String((CHAR*)"TRUE", (LONGINT)5);
} else {
Console_String((CHAR*)"FALSE", (LONGINT)6);
}
}
void Console_Hex (LONGINT i)
{
LONGINT k, n;
k = -28;
while (k <= 0) {
n = __MASK(__ASH(i, k), -16);
if (n <= 9) {
Console_Char((CHAR)(48 + n));
} else {
Console_Char((CHAR)(55 + n));
}
k += 4;
}
}
void Console_Read (CHAR *ch)
{
LONGINT n;
INTEGER error;
Console_Flush();
error = Platform_ReadBuf(Platform_StdIn, (void*)&*ch, ((LONGINT)(1)), &n);
if (n != 1) {
*ch = 0x00;
}
}
void Console_ReadLine (CHAR *line, LONGINT line__len)
{
LONGINT i;
CHAR ch;
Console_Flush();
i = 0;
Console_Read(&ch);
while ((((i < line__len - 1 && ch != 0x0a)) && ch != 0x00)) {
line[__X(i, line__len)] = ch;
i += 1;
Console_Read(&ch);
}
line[__X(i, line__len)] = 0x00;
}
export void *Console__init(void)
{
__DEFMOD;
__MODULE_IMPORT(Platform);
__REGMOD("Console", 0);
__REGCMD("Flush", Console_Flush);
__REGCMD("Ln", Console_Ln);
/* BEGIN */
Console_pos = 0;
__ENDMOD;
}