From: Gautier on
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).

> 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.
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...
Well, I think I'll switch to a binary format...
______________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!
From: Dmitry A. Kazakov on
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
From: Gautier on
Dmitry A. Kazakov:

> Yes, but will that be ASCII-encoded? And it has somehow invent lines and
> pages.

Sure, it is indeed a zip-archived text file that I intend to read through
UnZip.Streams.

Meanwhile (#ada irc...) there seems to be a nice solution:

http://jesselang.com/software/streams_text_io/

....
>> 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.)

No problem with that - there is already a framework in that package (for other
files) that sends things byte-per-byte in a deterministic endianess; floats are
split/merged with certain a Float_portable_binary_transfer package.

Thanks for the help!
______________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!