comp.lang.ada
 help / color / mirror / Atom feed
From: "Adam Beneschan" <adam@irvine.com>
Subject: Re: Get_Line problem (GNAT bug?)
Date: 6 Dec 2006 10:06:25 -0800
Date: 2006-12-06T10:06:25-08:00	[thread overview]
Message-ID: <1165428385.365155.179960@j44g2000cwa.googlegroups.com> (raw)
In-Reply-To: el6jss$268$1@cernne03.cern.ch

Maciej Sobczak wrote:
> Hi,
>
> Consider:
>
> with Ada.Text_IO;
>
> procedure Hello is
>     use Ada.Text_IO;
>
>     Input_Line : String(1..100);
>     Last_Index : Integer range 0..100;
> begin
>     loop
>        Put("What's your name? ");
>        exit when End_Of_File;
>        Get_Line(Input_Line, Last_Index);
>        if Last_Index >= Input_Line'First then
>           Put("Hi, ");
>           Put(Input_Line(1..Last_Index));
>           New_Line;
>        else
>           Put("You have funny empty name.");
>           New_Line;
>        end if;
>     end loop;
> end Hello;
>
> (please focus on the Get_Line problem here)
>
> It should be obvious what the program does, except that the behaviour in
> the case of empty input line is a bit strange.
> Below, in the right-hand column I describe what keys were pressed:
>
> $ ./hello
> What's your name? Maciek                -- M a c i e k ENTER
> Hi, Maciek
> What's your name?                       -- ENTER
>                                          -- ENTER
> You have funny empty name.
> What's your name?                       -- ENTER
> You have funny empty name.
> What's your name?                       -- EOF
> $
>
> As you see, the first ENTER was somehow "swollowed", creating an empty
> line in the console (that's the echo of what user typed), but still
> blocking in Get_Line. All subsequent ENTERs seem to be handled
> correctly, which means that Get_Line returns with Last_Index <
> Input_Line'First.
>
> I was already suggested that it might be a GNAT feature. If yes, it
> seems to be persistent, because I see it with two different versions.
>
> Of course, I expect that empty lines are handled uniformly.
>
> Any thoughts?

It has something to do with the End_Of_File call.  I got the same
behavior that you did, but when I commented out the line "exit when
End_Of_File;" [and used another method to determine when to exit the
loop---specifically, I exited when the input was equal to "quit"], I
did not get that behavior.  Note that when "standard input" is a
terminal or the equivalent, the End_Of_File call has to perform an
input operation because it has to wait for the user to press control-D
(on Unix-like systems) before End_Of_File knows what to return.  It may
be that that isn't being handled quite correctly.

I also found that if I took out "exit when End_Of_File" and added an
exception handler for End_Error, the erroneous behavior didn't occur.

                              -- Adam




  reply	other threads:[~2006-12-06 18:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-06 14:25 Get_Line problem (GNAT bug?) Maciej Sobczak
2006-12-06 18:06 ` Adam Beneschan [this message]
2006-12-06 20:34 ` Gautier
2006-12-06 21:47 ` Dmitry A. Kazakov
2006-12-06 23:40   ` Adam Beneschan
2006-12-07  0:02     ` Björn Persson
2006-12-07  1:09       ` Adam Beneschan
2006-12-07  1:28         ` Björn Persson
2006-12-07  5:00         ` Jeffrey R. Carter
2006-12-07  8:26   ` Maciej Sobczak
2006-12-07  9:21     ` Jean-Pierre Rosen
2006-12-07 13:35       ` Ludovic Brenta
2006-12-07 22:23       ` Robert A Duff
2006-12-07 10:22     ` Dmitry A. Kazakov
2006-12-07 14:51       ` Maciej Sobczak
2006-12-07 16:29         ` Dmitry A. Kazakov
2006-12-08  8:22           ` Maciej Sobczak
2006-12-07 22:50       ` Robert A Duff
2006-12-08  0:13         ` Randy Brukardt
2006-12-08  4:04         ` Larry Kilgallen
2006-12-08  9:11         ` Dmitry A. Kazakov
2006-12-07  9:14   ` Jean-Pierre Rosen
2006-12-07  3:34 ` Steve
2006-12-07 17:42   ` Adam Beneschan
2006-12-07 22:35     ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox