comp.lang.ada
 help / color / mirror / Atom feed
* Possible gnat and ObjectAda bugs?
@ 2000-11-25  0:00 David C. Hoos, Sr.
  2000-11-26  0:00 ` Preben Randhol
  2000-11-27  0:00 ` Randy Brukardt
  0 siblings, 2 replies; 3+ messages in thread
From: David C. Hoos, Sr. @ 2000-11-25  0:00 UTC (permalink / raw)


The code at the end of this message produces strange results with GNAT
3.13p,
and even more bizarre results with ObjectAda 7.1:

What is strange is that when Standard Input is from the keyboard, the
program
does not enter the loop until the enter key has been pressed.

Is this a bug, or am I missing something here?

with Ada.Text_IO;
procedure Echo
is
   C : Character;
begin
   while not Ada.Text_IO.End_Of_File (Ada.Text_IO.Current_Input)
   loop
      Ada.Text_IO.Put_Line
        (Ada.Text_IO.Standard_Error,
         "Waiting for character...");
      Ada.Text_IO.Get_Immediate (C);
      Ada.Text_IO.Put_Line
        (Ada.Text_IO.Standard_Error,
         "Got character at position" &
         Integer'Image (Character'Pos (C)));
      Ada.Text_IO.Put (Ada.Text_IO.Current_Output, C);
   end loop;
end Echo;







^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Possible gnat and ObjectAda bugs?
  2000-11-25  0:00 Possible gnat and ObjectAda bugs? David C. Hoos, Sr.
@ 2000-11-26  0:00 ` Preben Randhol
  2000-11-27  0:00 ` Randy Brukardt
  1 sibling, 0 replies; 3+ messages in thread
From: Preben Randhol @ 2000-11-26  0:00 UTC (permalink / raw)


On Sat, 25 Nov 2000 08:23:05 -0600, David C. Hoos, Sr. wrote:
>The code at the end of this message produces strange results with GNAT
>3.13p,
>and even more bizarre results with ObjectAda 7.1:
>
>What is strange is that when Standard Input is from the keyboard, the
>program
>does not enter the loop until the enter key has been pressed.
>
>Is this a bug, or am I missing something here?

Looks like Ada.Text_IO.Current_Input expects input that are terminated
by a new_line. Though your code would raise an exception if one hit \x04
(EOF) from the keyboard. I think I would have done something like this:


with Ada.Text_IO;
with Ada.IO_Exceptions;
procedure Echo
is
   C : Character;
begin
  loop
    begin
      Ada.Text_IO.Put_Line
        (Ada.Text_IO.Standard_Error,
         "Waiting for character...");
      Ada.Text_IO.Get_Immediate (C);

      Ada.Text_IO.Put_Line
      (Ada.Text_IO.Standard_Error,
       "Got character at position" &
       Integer'Image (Character'Pos (C)));
      Ada.Text_IO.Put (Ada.Text_IO.Current_Output, C);
    exception
      when Ada.Io_Exceptions.End_Error =>
        Ada.Text_IO.Put_Line
          (Ada.Text_IO.Standard_Error,
            "Ending...");
      exit;
    end;
   end loop;
end Echo;

-- 
Preben Randhol ---------------- http://www.pvv.org/~randhol/ --
iMy favorite editor is Emacs!<ESC>bcwVim<ESC>
                                         -- vim best-editor.txt




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Possible gnat and ObjectAda bugs?
  2000-11-25  0:00 Possible gnat and ObjectAda bugs? David C. Hoos, Sr.
  2000-11-26  0:00 ` Preben Randhol
@ 2000-11-27  0:00 ` Randy Brukardt
  1 sibling, 0 replies; 3+ messages in thread
From: Randy Brukardt @ 2000-11-27  0:00 UTC (permalink / raw)


David C. Hoos, Sr. wrote in message
<9VPT5.39609$A2.8013565@newsrump.sjc.telocity.net>...
>The code at the end of this message produces strange results with GNAT
>3.13p, and even more bizarre results with ObjectAda 7.1:
>
>What is strange is that when Standard Input is from the keyboard, the
>program does not enter the loop until the enter key has been pressed.
>
>Is this a bug, or am I missing something here?

You're missing something. A correct implementation of End_of_File has to
look past a line terminator and page terminator to check for a file
terminator. This means it has to read from the input. Presumably, the
implementations you tried did that in "cooked" mode, meaning that you
have to enter an entire line before the program gets any of it. (This is
the way that Janus/Ada works.) However, your code shows that you are
trying to use Get_Immediate, which reads in raw mode (keys are
immediately returned to the program). But that won't happen, because
End_of_File has already done the read in "cooked" mode.

Certainly, you should never use any of the End_of_xxx functions with
Get_Immediate. Moreover (because of the lookahead), I'd recommend never
using them when you want to read from the keyboard (even in "cooked"
mode). Indeed, my personal style is to never use them at all, because
they are pretty complex, and thus slow the program down a bit. The check
for End_Error is always done in Text_IO whether you handle it or not, so
that is essentially free. So the only cost is for the End_Error handler;
I recommend putting it outside the loop (so it isn't entered and left
many times), but otherwise its function isn't critical (it only is
executed once per file).

                Randy.







^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-11-27  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-25  0:00 Possible gnat and ObjectAda bugs? David C. Hoos, Sr.
2000-11-26  0:00 ` Preben Randhol
2000-11-27  0:00 ` Randy Brukardt

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