From: "John B. Matthews" <nospam@nospam.invalid>
Subject: Re: Preferred way to do binray I/O on standard input/output stream
Date: Mon, 26 Oct 2009 21:14:38 -0400
Date: 2009-10-26T21:14:38-04:00 [thread overview]
Message-ID: <nospam-6E0089.21143826102009@news.aioe.org> (raw)
In-Reply-To: 0d02cd9f-2cf1-48b6-a10f-6ea84427139d@k4g2000yqb.googlegroups.com
In article
<0d02cd9f-2cf1-48b6-a10f-6ea84427139d@k4g2000yqb.googlegroups.com>,
Hibou57 (Yannick Duchêne) <yannick_duchene@yahoo.fr> wrote:
> On 24 oct, 23:57, "Jeffrey R. Carter" <spam.jrcarter....@spam.acm.org>
> wrote:
> > Package Ada.Text_IO.Text_Streams (ARM A.12.2) allows converting
> > Ada.Text_IO.File_Type to Stream_Access and reading and writing them through
> > the
> > capabilities of streams.
> While this seems to work most of times, I meet a malfunction (data
> not preserved) if the stream ends with a line-feed (a byte whose
> value is 10). When it is, this last byte seems to be dropped from the
> stream, which cause troubles if the binary format is expecting it.
> This occurs only when it exactly ends with this byte, and it is Ok if
> this byte is followed by a byte whose value is 0 (as an example). It
> does not occur when the stream ends with a byte whose value is that
> of the carriage- return (13).
>
> Finally, this does not really turn the stream into a binary stream,
> and some interpretations remain.
I get the same effect. I don't know if it's the shell (bash) or OS (Mac)
doing it. I suspect the former: End_Of_File turns True when a final
linefeed remains to be read; the effect is absent with redirection. I'm
vaguely uneasy using an exception for flow control, but this seems to
copy the data unmolested:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Text_IO.Text_Streams;
procedure Copy is
Stream_Ptr : Text_Streams.Stream_Access;
C : Character;
begin
Stream_Ptr := Text_Streams.Stream(Current_Input);
loop
Character'Read(Stream_Ptr, C);
Put(C);
end loop;
exception
when End_Error => null;
end Copy;
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
next prev parent reply other threads:[~2009-10-27 1:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-24 22:07 Preferred way to do binray I/O on standard input/output stream Hibou57 (Yannick Duchêne)
2009-10-24 22:57 ` Jeffrey R. Carter
2009-10-24 23:22 ` Hibou57 (Yannick Duchêne)
2009-10-27 0:34 ` Hibou57 (Yannick Duchêne)
2009-10-27 1:14 ` John B. Matthews [this message]
2009-10-27 2:36 ` Hibou57 (Yannick Duchêne)
2009-10-27 16:13 ` John B. Matthews
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox