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: 103376,b5cd7bf26d091c6f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Mon, 06 Jun 2011 13:16:03 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Reading the while standard input into a String References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4decb6f4$0$6627$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 06 Jun 2011 13:16:04 CEST NNTP-Posting-Host: 03d5d509.newsspool2.arcor-online.net X-Trace: DXC=LVY^RA_2K[6LNKYb?b>076A9EHlD;3Yc24Fo<]lROoR18kF:Lh>_cHTX3j=k2Y=PGPi On 05.06.11 18:20, Natasha Kerensikova wrote: > Hello, > > I have encountered what was a very easily solved problem in C: dump the > whole contents of the standard input into some place in memory, in order > to process it afterwards. To use something like C's fread(1), I'd do the same in Ada with Streams and Storage_Element_Array. Like fread, which has void* arguments, the Ada equivalent will read storage elements (bytes, likely octets). Very likely, the storage elements can be converted to Character without check, i.e. using an instance of Unchecked_Conversion, or simple the 'Address attribute. So no copying is involved at this stage. When processing Input character by character, no I/O is performed. I define an index for the characters in the storage area so filled: declare Buffer : Storage_Element_Array (...); Input : String (Buffer'Range); pragma Import (Ada, Input); for Input'Address use Buffer'Address; Last : Natural; -- index of last octed Pos : Positive; -- points to current character begin -- have standard input flow into Buffer from a text stream -- ... for Pos in Input'First .. Last loop Process (Input (Pos)); pos := pos + 1; end loop; end;