reading process Input() without blocking -> corrected, probelm was unrelated memory management
So I made a cool text editor that can display unix UTF-8 outputs like a unix shell should, called EmojiGear, and I was telling myself, wouldn't it be super extra cool If I could use "pipe redirection" to display a UTF8 command content from pipe redirection, and use a command like:
wget -O - http://wttr.in | EmojiGear
... (wget is available for OS3 on aminet in ADE package, wttr.in is a site that return a ANSI-art weather report for your location , -O - is the option to have the page on output rather than on a file.) My approach so far is simple:
{
BPTR inpt=Input();
if(inpt)
{
char tempinput[128];
LONG tidone;
tidone = Read(inpt,tempinput,127);
tempinput[tidone]= 0;
if(tidone>0) {
SetGdAttrs(app->textEditorObj, UTED_InsertText, (ULONG)tempinput, TAG_END);
}
}
}
... it almost works, I can get the 10 first lines then it would block and crash... Of course "Read(Input())" would wait for ever if there is no input... Is there a way to make so we read() only when we know there's actual data, so we're non blocking all other features.
I mean just upon that code I have a: Wait( ThisWindowMessageBit|CTRL_C|otherWindowMessageBit|AnythingThatWouldNeedTheAppToWakeUp)
This would be super cool if I could have a waiting bit for precisely the process input in a DOS meaning, so I could receive PIPE data redirection.
Online Status
Got it working ! I'm not sure Read(Input()) block at all ... but well also now I test with (input && !IsInteractive(input)) before Read() and looks ok. I also had to manage not-breakig the long utf8 chars, could have made problem. Happy I am: "Vive le PIPE".