From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,cbf5e026169c215b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!fdn.fr!gegeweb.org!aioe.org!nospam From: "John B. Matthews" Newsgroups: comp.lang.ada Subject: Re: Preferred way to do binray I/O on standard input/output stream Date: Mon, 26 Oct 2009 21:14:38 -0400 Organization: The Wasteland Message-ID: References: <8ec042f2-5308-4a7c-8f48-a6b72ec8feba@p9g2000vbl.googlegroups.com> <0d02cd9f-2cf1-48b6-a10f-6ea84427139d@k4g2000yqb.googlegroups.com> NNTP-Posting-Host: LQJtZWzu+iKlBROuDg+IUg.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.0 Cancel-Lock: sha1:JsNNHMuzPkzG59vgu7IJa+Jc+Ig= User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: g2news2.google.com comp.lang.ada:8805 Date: 2009-10-26T21:14:38-04:00 List-Id: In article <0d02cd9f-2cf1-48b6-a10f-6ea84427139d@k4g2000yqb.googlegroups.com>, Hibou57 (Yannick DuchĂȘne) wrote: > On 24 oct, 23:57, "Jeffrey R. Carter" > 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