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,5afe598156615c8b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!j44g2000cwa.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Get_Line problem (GNAT bug?) Date: 6 Dec 2006 10:06:25 -0800 Organization: http://groups.google.com Message-ID: <1165428385.365155.179960@j44g2000cwa.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1165428391 23905 127.0.0.1 (6 Dec 2006 18:06:31 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 6 Dec 2006 18:06:31 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: j44g2000cwa.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:7825 Date: 2006-12-06T10:06:25-08:00 List-Id: 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