From: "robin" <robin51@dodo.mapson.com.au>
Subject: Re: Reading the while standard input into a String
Date: Mon, 6 Jun 2011 11:49:40 +1000
Date: 2011-06-06T11:49:40+10:00 [thread overview]
Message-ID: <4dec323f$0$12378$c30e37c6@exi-reader.telstra.net> (raw)
In-Reply-To: slrniunb6n.i18.lithiumcat@sigil.instinctive.eu
"Natasha Kerensikova" <lithiumcat@gmail.com> wrote in message news:slrniunb6n.i18.lithiumcat@sigil.instinctive.eu...
| 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.
It's also trivial in PL/I:
do forever;
allocate line;
get edit (line) (L);
end;
or read each line into an array element or whatever.
| I was quite unhappy with the preprocessing performed by Ada.Text_IO, so
| I went on using the text stream interface. However I still read
| character by character into a temporary buffer, and it feels ugly. Here
| is the code:
|
| with Ada.Strings.Unbounded;
| with Ada.Text_IO.Text_Streams;
|
| Source : Ada.Text_IO.Text_Streams.Stream_Access
| := Ada.Text_IO.Text_Streams.Stream (Ada.Text_IO.Standard_Input);
|
| procedure Read_Chunk (To : out String; Last : out Natural) is
| begin
| Last := To'First - 1;
| for J in To'Range loop
| Character'Read (Source, To (J));
| Last := J;
| end loop;
| exception
| when Ada.Text_IO.End_Error => Null;
| end Read_Chunk;
|
|
| procedure The_Program is
| -- some tuff
| Input : Ada.Strings.Unbounded.Unbounded_String;
| begin
| declare
| Chunk : String (1 .. 256);
| Last : Natural;
| begin
| loop
| Read_Chunk (Chunk, Last);
| Ada.Strings.Unbounded.Append (Input, Chunk (1 .. Last));
| exit when Last < Chunk'Last;
| end loop;
| end;
|
| -- Process Input or To_String (Input);
| end The_Program;
|
| Is there a better/smarter/less ugly way to achieve the same result?
next prev parent reply other threads:[~2011-06-06 1:49 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-05 16:20 Reading the while standard input into a String Natasha Kerensikova
2011-06-06 1:49 ` robin [this message]
2011-06-06 7:18 ` Dmitry A. Kazakov
2011-06-06 10:46 ` Natasha Kerensikova
2011-06-06 12:05 ` Dmitry A. Kazakov
2011-06-06 16:55 ` Jeffrey Carter
2011-06-06 17:42 ` Pascal Obry
2011-06-06 17:43 ` Pascal Obry
2011-06-06 18:31 ` Dmitry A. Kazakov
2011-06-06 8:09 ` stefan-lucks
2011-06-06 8:33 ` Ludovic Brenta
2011-06-06 10:08 ` Natasha Kerensikova
2011-06-06 10:27 ` Ludovic Brenta
2011-06-06 10:31 ` Ludovic Brenta
2011-06-06 12:07 ` Natasha Kerensikova
2011-06-06 15:18 ` Maciej Sobczak
2011-06-06 18:18 ` Dmitry A. Kazakov
2011-06-06 18:36 ` Maciej Sobczak
2011-06-06 18:53 ` Dmitry A. Kazakov
2011-06-06 19:10 ` J-P. Rosen
2011-06-06 19:46 ` Dmitry A. Kazakov
2011-06-06 23:37 ` Shark8
2011-06-07 3:00 ` Randy Brukardt
2011-06-07 7:25 ` Dmitry A. Kazakov
2011-06-07 7:32 ` Maciej Sobczak
2011-06-07 8:51 ` Dmitry A. Kazakov
2011-06-07 3:10 ` Randy Brukardt
2011-06-06 19:06 ` J-P. Rosen
2011-06-06 19:52 ` Dmitry A. Kazakov
2011-06-07 3:15 ` Randy Brukardt
2011-06-06 22:14 ` Robert A Duff
2011-06-06 9:46 ` Georg Bauhaus
2011-06-06 11:16 ` Georg Bauhaus
2011-06-06 12:11 ` Dmitry A. Kazakov
2011-06-06 13:32 ` Georg Bauhaus
2011-06-06 14:06 ` Dmitry A. Kazakov
2011-06-06 14:14 ` Georg Bauhaus
2011-06-07 3:19 ` Randy Brukardt
2011-06-06 18:14 ` John B. Matthews
2011-06-07 10:23 ` Martin
2011-06-07 16:57 ` John B. Matthews
2011-06-07 17:22 ` Robert A Duff
2011-06-07 17:55 ` John B. Matthews
2011-06-08 0:26 ` Robert A Duff
2011-06-08 7:38 ` Egil Høvik
2011-06-08 9:27 ` Martin
2011-06-08 12:04 ` Egil Høvik
2011-06-08 18:09 ` Niklas Holsti
2011-06-09 0:46 ` Randy Brukardt
2011-06-10 8:22 ` Martin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox