comp.lang.ada
 help / color / mirror / Atom feed
* Re: Trouble w/ End_Error exception in Integer_Text_IO
  1997-06-16  0:00 Trouble w/ End_Error exception in Integer_Text_IO Ha Ha X
@ 1997-06-16  0:00 ` john schneider
  1997-06-18  0:00 ` Nick Roberts
  1 sibling, 0 replies; 5+ messages in thread
From: john schneider @ 1997-06-16  0:00 UTC (permalink / raw)



Ha Ha X wrote:
> 
> I've been having a lot of trouble with an irritating feature of
> Ada.Integer_Text_IO's End_Error exception. When using the Get()
> procedure, if the user enters a manual EOF from the keyboard (^D in
> Unix, or ^Z in DOS), Get() raises End_Error. This is, I suppose,
> intended to prevent people from reading past EOF in a text file. Fine.
> 
> However, when I am getting input from user with Integer_Text_IO, I
> want to just clear that EOF off the input stream, put an error
> message, and loop back for new input.  Unfortunately, End_Error does
> not clear EOF off the stream. Furthermore, Skip_Line's defined
> behavior is to raise End_Error if you attempt to skip EOF.
> 
> The net result is that when a user hits ^Z by accident, I am forced to
> bomb out of the program with an exception. I've searched in the AARM
> for a solution, to no avail. This problem extends to virtually every
> input procedure in Ada.Text_IO.
> 
> So, in short, my question is: how can EOF be cleared off the standard
> input stream? I'm using GNAT 3.05 for MS-DOS, if that's any help.
> 
> Thanks in advance.
> 
> ~k.lee
> kql6708@is.nyu.edu
-- 

There are probably more elegant solutions, but you might try
closing and re-openinng the input stream.  It's a little clumsy,
but if you're really reading user keystrokes (not data piped from
another program) you shouldn't lose more than the remainder of
the current input line -- which the user messed up with EOF, anyway!


John Schneider
j-schneider@ti.com

The opinions are mine, but you are welcome to share them.




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

* Trouble w/ End_Error exception in Integer_Text_IO
@ 1997-06-16  0:00 Ha Ha X
  1997-06-16  0:00 ` john schneider
  1997-06-18  0:00 ` Nick Roberts
  0 siblings, 2 replies; 5+ messages in thread
From: Ha Ha X @ 1997-06-16  0:00 UTC (permalink / raw)



I've been having a lot of trouble with an irritating feature of
Ada.Integer_Text_IO's End_Error exception. When using the Get()
procedure, if the user enters a manual EOF from the keyboard (^D in
Unix, or ^Z in DOS), Get() raises End_Error. This is, I suppose,
intended to prevent people from reading past EOF in a text file. Fine.

However, when I am getting input from user with Integer_Text_IO, I
want to just clear that EOF off the input stream, put an error
message, and loop back for new input.  Unfortunately, End_Error does
not clear EOF off the stream. Furthermore, Skip_Line's defined
behavior is to raise End_Error if you attempt to skip EOF.

The net result is that when a user hits ^Z by accident, I am forced to
bomb out of the program with an exception. I've searched in the AARM
for a solution, to no avail. This problem extends to virtually every
input procedure in Ada.Text_IO.

So, in short, my question is: how can EOF be cleared off the standard
input stream? I'm using GNAT 3.05 for MS-DOS, if that's any help.

Thanks in advance.

~k.lee
kql6708@is.nyu.edu






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

* Re: Trouble w/ End_Error exception in Integer_Text_IO
  1997-06-16  0:00 Trouble w/ End_Error exception in Integer_Text_IO Ha Ha X
  1997-06-16  0:00 ` john schneider
@ 1997-06-18  0:00 ` Nick Roberts
  1997-06-20  0:00   ` Do-While Jones
  1997-06-21  0:00   ` Robert Dewar
  1 sibling, 2 replies; 5+ messages in thread
From: Nick Roberts @ 1997-06-18  0:00 UTC (permalink / raw)





Ha Ha X <kql6708@is.nyu.edu> wrote in article
<33a4a1c5.2804336@netnews.worldnet.att.net>...
> I've been having a lot of trouble with an irritating feature of
> Ada.Integer_Text_IO's End_Error exception. When using the Get()
> procedure, if the user enters a manual EOF from the keyboard (^D in
> Unix, or ^Z in DOS), Get() raises End_Error. This is, I suppose,
> intended to prevent people from reading past EOF in a text file. Fine.
[...]

A possible solution is to use Get_Immediate instead of Get, and write a
little procedure which accumulates characters into a string and then uses
the integer version of Get on the string. Line buffering still works under
GNAT for DOS (because it doesn't disable DOS' line buffering (which it
should!)), but, of course, it may not under other environments or Adas.

What Adas for DOS should all offer is an open option (via the Form
parameter) which disables EOF character detection for a text input stream
(other kinds of EOF detection unaffected), and this should be the default
for standard input (there is no tradition of using ^Z to terminate user
input under DOS, as there is (using ^D) under UNIX).

Such an option isn't workable for UNIX (I think) because the kernel
converts the ^D into a 'hard' EOF (read returns 0). There could always be
an option to ignore EOF altogether (but never as a default).

Perhaps a better solution is to simply accept that ^Z or ^D raises an
exception, and to handle that exception as a way for the user to forcefully
terminate the program (or similar). Or you could just tell your users not
to press ^Z!

Nick.





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

* Re: Trouble w/ End_Error exception in Integer_Text_IO
  1997-06-18  0:00 ` Nick Roberts
@ 1997-06-20  0:00   ` Do-While Jones
  1997-06-21  0:00   ` Robert Dewar
  1 sibling, 0 replies; 5+ messages in thread
From: Do-While Jones @ 1997-06-20  0:00 UTC (permalink / raw)



In article <01bc7c33$c23a2ca0$LocalHost@xhv46.dial.pipex.com>,
Nick Roberts <Nick.Roberts@dial.pipex.com> wrote:
>
>
>Ha Ha X <kql6708@is.nyu.edu> wrote in article
><33a4a1c5.2804336@netnews.worldnet.att.net>...
>> I've been having a lot of trouble with an irritating feature of
>> Ada.Integer_Text_IO's End_Error exception. When using the Get()
>> procedure, if the user enters a manual EOF from the keyboard (^D in
>> Unix, or ^Z in DOS), Get() raises End_Error. This is, I suppose,
>> intended to prevent people from reading past EOF in a text file. Fine.
>[...]
>

This brings back memories of the Seventh National Ada Conference, 14-16
March, 1989.  What I said then, when I presented the paper "How to Live
With TEXT_IO", is still true today. 

The basic problem is that people aren't files.  Files never make a mistake
and then try to fix it by pressing the rubout key.  Files don't want to
move the cursor.  Files don't want to "press any key to continue."  Files
don't enter a real number when the program is expecting an integer as
often as people do.  TEXT_IO is a good file interface that can be used as
a simple user interface.

If you are writing a serious program that involves significant user input,
you should not be using TEXT_IO, or any of its 1995 variants. 

Ten years ago I wrote several user interfaces (VIRTUAL_TERMINAL,
SCROLL_TERMINAL, and FORM_TERMINAL) which are described in Ada in Action
(which you can download from the Ada Home Page).  Now that I do lots of
real-time interactive 2-D graphic programming (built entirely in Ada on
top of primitive bit-mapped graphics), I use a KEYBOARD package, a TEXT
window package, and DIALOG_BOX, MENU, CHECKLIST, etc. for user IO.  I use
TEXT_IO for reading and writing configuration files only.

TEXT_IO is an adequate user interface for throw-away programs.  I use it
for some of my module test routines.  But I never use it for programs that
customers will use.

TEXT_IO is certainly appropriate for beginner programs in a first-semester
programming course.  Just accept it for what it is--a simple, universal
user interface without much capability.  Use Get_Line to read entire lines
and process them yourself.

If you are doing any serious programming that involves a user interface,
use the AONIX GUI-builder tool, or CLAW, or some sort of windows/motif
interface, or write your own user-interface that does exactly what you
want, just like I did.  Don't try to make a silk purse out of TEXT_IO. 

Do-While Jones

            +--------------------------------+
            |    Know                 Ada    |
            |        [Ada's Portrait]        |
            |    Will              Travel    |
            | wire do_while@ridgecrest.ca.us |
            +--------------------------------+

                                       





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

* Re: Trouble w/ End_Error exception in Integer_Text_IO
  1997-06-18  0:00 ` Nick Roberts
  1997-06-20  0:00   ` Do-While Jones
@ 1997-06-21  0:00   ` Robert Dewar
  1 sibling, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1997-06-21  0:00 UTC (permalink / raw)



Nick Roberts said

<<Such an option isn't workable for UNIX (I think) because the kernel
converts the ^D into a 'hard' EOF (read returns 0). There could always be
an option to ignore EOF altogether (but never as a default).
>>


A program can certainly put stdin into raw mode if that is what it wants.





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

end of thread, other threads:[~1997-06-21  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-06-16  0:00 Trouble w/ End_Error exception in Integer_Text_IO Ha Ha X
1997-06-16  0:00 ` john schneider
1997-06-18  0:00 ` Nick Roberts
1997-06-20  0:00   ` Do-While Jones
1997-06-21  0:00   ` Robert Dewar

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