On Mon, 31 Mar 2008 21:17:10 +0200, Gautier wrote:
> Dmitry A. Kazakov:
>> But a stream has no defined formatting and is unrelated to ASCII.
>
> Still, you can read the stream through Character'Read(s,c).
Yes, but will that be ASCII-encoded? And it has somehow invent lines and
pages.
>> Then the idea of parsing stream looks problematic. If you have in the
stream a
>> sequence " + -", what Get should do after discovering '-'?
>
> Exactly the same behaviour as when parsing an ill-formatted text.
Ah, yes. I cannot find the place in ARM, but it seems that Text_IO would
swallow syntactically incorrect input before propagating Data_Error.
> Reading a text file (or supposedly so) indirectly via a stream and
Stream_IO
> would have the same result that via Ada.Text_IO.
>
>> Anyway, it is quite simple to do. You can do
>>
>> type Formatted_Stream (Source : access Root_Stream_Type'Class) is
>> tagged limited private;
>> function Get (Stream : access Formatted_Stream) return Integer;
>> ...
>>
>> The implementation of Formatted_Stream will use Source for all its I/O.
So
>> you could hang it on any existing stream.
>
> Fine, seems I need to rewrite a Text_IO for streams. I hoped for a
ready-made
> solution...
But Text_IO also defines all Get procedures on String. So if you knew
where
line ends are in your stream you could cache the current line in
Formatted_Stream and then simply route all its Gets to Ada.Text_IO Gets.
> Well, I think I'll switch to a binary format...
I would do that too. Also I would override 'Read and 'Write in order to
make it platform-independent. (Stream_Element should be replaced by
octets.)
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


|