Mail Archives: djgpp/1997/04/10/11:00:33
Doug Eleveld wrote:
>
> Hello Everyone,
>
> I' know how to redirect stderr to a file and such, but what I'd like
> to do is have my program process all the text that would normally
> go to stderr (or stdout or from stdin) and display it in a window
> in graphics mode. Do I have to take over a FILE* and then redirect to
> that FILE*? Is there a more sensible way? Does anyone do this kind of
> stuff with DJGPP?
Two solutions come to my mind, one is to write code using the
File System Extensions in DJGPP, close stderr and reopen it
with a filename like "/dev/stderr_80x40" and your FSE catches
it. The big advantage is, that you'll just have to handle
characters, no sprintf() required.
The advantage is you can catch stdout by the same way, so there
is no difference between printf() and fprintf(stdout)
int (*printfunc)(char *,..);
#ifdef TEXTMODE
printfunc = printf;
#else
printfunc = myprintf
#endif
/*
** This should go before the above
*/
int myprintf(char *fmt,...){
char buf[2048]; /* Beware: This can corrupt your stack when printing
** Lines longer than 2048 characters. Any idea how to
** catch that?
*/
va_args v=va_start(fmt);
int retval;
retval = vsprintf(buf,fmt,v);
va_end(v);
/* parse buf and display it the way you need it */
...
return retval;
}
int main(){
printfunc("This goes to %s\n", "wherever");
}
THIS_IS_NOT_TESTED! (It probably won't even compile, but I hope you get
the idea)
--
Ciao
Tom
*************************************************************
* Thomas Demmer *
* Lehrstuhl fuer Stroemungsmechanik *
* Ruhr-Uni-Bochum *
* Universitaetsstr. 150 *
* D-44780 Bochum *
* Tel: +49 234 700 6434 *
* Fax: +49 234 709 4162 *
* http://www.lstm.ruhr-uni-bochum.de/~demmer *
*************************************************************
- Raw text -