----boundary-LibPST-iamunique-493914876_-_-
Content-type: text/plain
Hello!
> So, just in case someone has the urge to write an I/O module, does anyone
> know anything about what is involved?
It is very easy.
PROCEDURE WriteStdErr* (IN str: ARRAY OF SHORTCHAR);
VAR
stderr: WinApi.HANDLE;
res: INTEGER;
BEGIN
stderr := WinApi.GetStdHandle(WinApi.STD_ERROR_HANDLE);
IF stderr # 0 THEN
res := WinApi.CharToOemA(str, str);
res := WinApi.WriteFile(stderr, S.ADR(str), LEN(str$), res, NIL);
END
END WriteStdErr;
A little more sophisticated version.
PROCEDURE WriteStdErr* (IN str: ARRAY OF CHAR);
VAR
stderr: WinApi.HANDLE;
sstr: ARRAY 256 OF SHORTCHAR;
res, strLen: INTEGER;
BEGIN
strLen := LEN(str$);
ASSERT(strLen < LEN(sstr), 20);
stderr := WinApi.GetStdHandle(WinApi.STD_ERROR_HANDLE);
IF stderr # 0 THEN
IF WinApi.GetFileType(stderr) = WinApi.FILE_TYPE_CHAR THEN
res := WinApi.WriteConsoleW(stderr, SYSTEM.ADR(str), strLen, res, 0)
ELSE
res := WinApi.WideCharToMultiByte(WinApi.GetConsoleOutputCP(), {},
str, strLen, sstr, LEN(sstr)-1, NIL, NIL);
res := WinApi.WriteFile(stderr, SYSTEM.ADR(sstr), LEN(sstr$), res, NIL)
END
END
END WriteStdErr;
The latter version is Unicode-aware and it properly handles the output
redirection to a file/pipe.
Use similar approach for retrieving and reading/writing
WinApi.STD_INPUT_HANDLE and WinApi.STD_OUTPUT_HANDLE.
If stderr # 0, then the code is most likely being run from a console
executable (GUI applications may have a valid stdout handle, I don't
know about stdin).
I have patched Kernel.FatalError and Kernel.DefaultTrapViewer to perform
console output instead of calling WinApi.MessageBox if the stderr is
available. This makes the Kernel a little more console-friendly. ; )
It ain't hard to make a console I/O module. If it's not there, then
maybe there was no demand for it yet.
---=====---
Alexander
--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy
----boundary-LibPST-iamunique-493914876_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTFcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIEhlbGxvIVxwYXINClxwYXINCj4gU28sIGp1c3Qg
aW4gY2FzZSBzb21lb25lIGhhcyB0aGUgdXJnZSB0byB3cml0ZSBhbiBJL08gbW9kdWxlLCBkb2Vz
IGFueW9uZVxwYXINCj4ga25vdyBhbnl0aGluZyBhYm91dCB3aGF0IGlzIGludm9sdmVkP1xwYXIN
ClxwYXINCiAgSXQgaXMgdmVyeSBlYXN5LlxwYXINClxwYXINClBST0NFRFVSRSBXcml0ZVN0ZEVy
ciogKElOIHN0cjogQVJSQVkgT0YgU0hPUlRDSEFSKTtccGFyDQogIFZBUlxwYXINCiAgICBzdGRl
cnI6IFdpbkFwaS5IQU5ETEU7XHBhcg0KICAgIHJlczogSU5URUdFUjtccGFyDQpCRUdJTlxwYXIN
CiAgc3RkZXJyIDo9IFdpbkFwaS5HZXRTdGRIYW5kbGUoV2luQXBpLlNURF9FUlJPUl9IQU5ETEUp
O1xwYXINCiAgSUYgc3RkZXJyICMgMCBUSEVOXHBhcg0KICAgIHJlcyA6PSBXaW5BcGkuQ2hhclRv
T2VtQShzdHIsIHN0cik7XHBhcg0KICAgIHJlcyA6PSBXaW5BcGkuV3JpdGVGaWxlKHN0ZGVyciwg
Uy5BRFIoc3RyKSwg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