[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gnucap-devel] Flushing the output buffer after writing to stdout?
From: |
al davis |
Subject: |
Re: [Gnucap-devel] Flushing the output buffer after writing to stdout? |
Date: |
Sun, 16 Apr 2006 23:14:59 -0400 |
User-agent: |
KMail/1.8.3 |
On Sunday 16 April 2006 16:22, Stuart Brorson wrote:
> I'd like to talk to gnucap via a pipe opened from another process. In
> particular, I am using the "popen2" facility from Python. So
> far, my efforts in this direction have failed. I suspect that one of
> my problems is that the IO buffers aren't being flushed
> after gnucap outputs a bunch of text to the stdout.
The buffers are automatically flushed on every \n, \r, \b.
> I have looked through the gnucap code to try to explicitly stick calls
> to flush at the critical places where IO occurs. However, I am
> completely flummoxed by how gnucap does IO. I have discovered the IO
> class as well as the OMSTREAM class, but can't figure out how these
> inherit from cout, which is the only thing I know about C++ IO. I
> also don't know the difference between IO and OMSTREAM, or what they
> are trying to accomplish.
The use of OMSTREAM is sort of like any stream, but it is a multiple stream.
Think of it as a set of streams. Writing once writes to all of them.
This part of the code was written many years ago, before C++ I/O was stable,
so it is built around the old C "FILE*". Even now, it does some things that
the usual C++ streams don't, such as floating point numbers with letters
representing multipliers, better control of formatting, including support for
devices and files with limited line length. The files included in a single
OMSTREAM are not necessarily formatted the same. Still, writing once does
them all.
Basically, you open a C style FILE*, then attach it.
If you look inside, you will see that the C++ streams do this too.
>
> Questions:
>
> 1. Within gnucap, which statement actually writes something to the
> stdout?
Usually "fputc", but please don't use it directly.
> 2. How do I explicitly tell stdout to flush? Has this fcn been built
> into the relevant classes yet?
Writing \n, \r, or \b. Doing it as part of a string has the desired effect.
If you want to flush in the middle of a line, write a blank then backspace.
Since it uses the standard C I/O, which links stdin and stdout, reading from
stdin flushes stdout.
> 3. Ummm, can somebody please give me the 30 second overview of what
> IO and OMSTREAM classes are for, and how one should use them?
ALL output uses OMSTREAM.
The IO class should really be a namespace. It is a class only because there
was no such thing as namespace when I wrote that part. It exists for the
purpose of minimizing clutter in the global namespace. Actually, it probably
should be more like a regular class, a container for all IO stuff. That way
there could be more than one.