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,FREEMAIL_FROM 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,ASCII Path: g2news2.google.com!postnews.google.com!w19g2000yqk.googlegroups.com!not-for-mail From: =?ISO-8859-1?Q?Hibou57_=28Yannick_Duch=EAne=29?= Newsgroups: comp.lang.ada Subject: Re: Preferred way to do binray I/O on standard input/output stream Date: Mon, 26 Oct 2009 19:36:49 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <8ec042f2-5308-4a7c-8f48-a6b72ec8feba@p9g2000vbl.googlegroups.com> <0d02cd9f-2cf1-48b6-a10f-6ea84427139d@k4g2000yqb.googlegroups.com> NNTP-Posting-Host: 86.75.149.43 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1256611009 6383 127.0.0.1 (27 Oct 2009 02:36:49 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 27 Oct 2009 02:36:49 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w19g2000yqk.googlegroups.com; posting-host=86.75.149.43; posting-account=vrfdLAoAAAAauX_3XwyXEwXCWN3A1l8D User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; fr),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8806 Date: 2009-10-26T19:36:49-07:00 List-Id: On 27 oct, 02:14, "John B. Matthews" wrote: > with Ada.Text_IO; use Ada.Text_IO; > with Ada.Text_IO.Text_Streams; > > procedure Copy is > =A0 =A0Stream_Ptr : Text_Streams.Stream_Access; > =A0 =A0C : Character; > begin > =A0 =A0Stream_Ptr :=3D Text_Streams.Stream(Current_Input); > =A0 =A0loop > =A0 =A0 =A0 Character'Read(Stream_Ptr, C); > =A0 =A0 =A0 Put(C); > =A0 =A0end loop; > exception > =A0 =A0when End_Error =3D> null; > end Copy; > > -- > John B. Matthews > trashgod at gmail dot com > The trouble with this, is that this force a look-ahead : an item must be read to know if an item is available, and this can lead into numerous logical traps (I prefer to keep distinct the action of reading and testing availability of data). May be this is finally really better to re-create a type to stand for the standard input as binary, but what I do not like with this way, is the possible lack of knowledge of some platforms, which is required for implementations (For me, it will be OK for Windows, BSD, Linux, but not the others... although in the mean time, I'm not sure I will ever need it for other platforms).