comp.lang.ada
 help / color / mirror / Atom feed
* is there a getch() for ada95??
@ 1996-12-30  0:00 Michael Rizzo
  1996-12-31  0:00 ` Tarjei T. Jensen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Michael Rizzo @ 1996-12-30  0:00 UTC (permalink / raw)



Hello.
   I'm working on a small appliacation with ada95... First experience
with
the language.. And I'm trying to create a small package to handle
console
i/o.. Is there a package that does this already.. Something like conio.h
for C?    Is there a function that can read charater input from the
keyboard without echo, and without having to press the CR after the
charater... I'm trying to design some screen controls that will use the
arrow keys and the function keys...
   If this package doesn't exist is it possible to include conio.h into
my
ada95 progam?
    Any info will be greatly appreciated and very helpful..
                                       mike rizzo




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

* Re: is there a getch() for ada95??
  1996-12-30  0:00 is there a getch() for ada95?? Michael Rizzo
  1996-12-31  0:00 ` Tarjei T. Jensen
@ 1996-12-31  0:00 ` Jerry van Dijk
  1997-01-12  0:00 ` is there a getch() for ada95?? [LONG] tconiam
  2 siblings, 0 replies; 4+ messages in thread
From: Jerry van Dijk @ 1996-12-31  0:00 UTC (permalink / raw)



Micheal,

> And I'm trying to create a small package to handle
> console i/o.

Unfortunately, that is difficult to answer without knowing which
compiler/operating
system you are using.

If, for example, you are using GNAT on DOS (which I suspect) the answer
is that
there are several posibilities for console I/O.

In general though, if you are using GNAT, you can call the C library
function
getch() from Ada, like in:

	with Ada.Text_IO; use Ada.Text_IO;

	procedure Test is

		function getch return Integer;
		pragma Import (C, getch);

	begin

		Put ("Press a key: ");
		Put_Line ("You pressed a key with scancode" & Integer'Image(getch));

	end Test;

with the best wishes for the new year!
Jerry.





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

* Re: is there a getch() for ada95??
  1996-12-30  0:00 is there a getch() for ada95?? Michael Rizzo
@ 1996-12-31  0:00 ` Tarjei T. Jensen
  1996-12-31  0:00 ` Jerry van Dijk
  1997-01-12  0:00 ` is there a getch() for ada95?? [LONG] tconiam
  2 siblings, 0 replies; 4+ messages in thread
From: Tarjei T. Jensen @ 1996-12-31  0:00 UTC (permalink / raw)



Michael Rizzo wrote:
> 
> Hello.
> Is there a package that does this already.. Something like conio.h
> for C?    Is there a function that can read charater input from the
> keyboard without echo, and without having to press the CR after the
> charater... I'm trying to design some screen controls that will use the
> arrow keys and the function keys...
>    If this package doesn't exist is it possible to include conio.h into
> my
> ada95 progam?

I haven't read the specifications, but you might find it worthwhile to
read up on the procedure get_immediate. If you don't have a paper copy
of the Ada 95 Reference Manual then there is the online version (e.g.
from http://www.adahome.com). Paper copies are also available. If you
are using an Ada 95 compiler under Unix or GNAT with Gcc then you can
always include any getch() or getc() function from C as shown in annex B
of the Ada 95 Reference Manual. Just be sure to include the function and
not the macro version of the function.

If you are not particulary comfortable with Ada yet there is a few books
that you may find useful. These are John Barnes "Programming in Ada 95",
Norman Cohen "Ada as a 2.nd language" (2.nd edition) and Alan Burns &
Andy Wellings "Concurrency in Ada". The latter is probably best seen as
an add-on to either of the two former books.

Greetings,

-- 
// Tarjei T. Jensen 
//    tarjei@online.no || voice +47 51 62 85 58
//   Support you local rescue centre: GET LOST!




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

* Re: is there a getch() for ada95?? [LONG]
  1996-12-30  0:00 is there a getch() for ada95?? Michael Rizzo
  1996-12-31  0:00 ` Tarjei T. Jensen
  1996-12-31  0:00 ` Jerry van Dijk
@ 1997-01-12  0:00 ` tconiam
  2 siblings, 0 replies; 4+ messages in thread
From: tconiam @ 1997-01-12  0:00 UTC (permalink / raw)



You want to use the package Ada.Text_IO.  You probably want to get a copy
of the Language Reference Manual (LRM) also. [see http://www.adahome.com/
]

I think you are looking for the procedure Get_Immediate.

Excerpt from the LRM:
---------- cut here ----------

A.10.7 Input-Output of Characters and Strings

                              Static Semantics

1   For an item of type Character the following procedures are provided:


2   procedure Get(File : in File_Type; Item : out Character);
    procedure Get(Item : out Character);

        3   After skipping any line terminators and any page terminators,
        reads the next character from the specified input file and returns
        the value of this character in the out parameter Item.
        4   The exception End_Error is propagated if an attempt is made to
        skip a file terminator.


5   procedure Put(File : in File_Type; Item : in Character);
    procedure Put(Item : in Character);

        6   If the line length of the specified output file is bounded
(that
        is, does not have the conventional value zero), and the current
        column number exceeds it, has the effect of calling New_Line with
a
        spacing of one.  Then, or otherwise, outputs the given character
to
        the file.


7   procedure Look_Ahead (File        : in  File_Type;
                          Item        : out Character;
                          End_Of_Line : out Boolean);
    procedure Look_Ahead (Item        : out Character;
                          End_Of_Line : out Boolean);

        8   Mode_Error is propagated if the mode of the file is not
In_File.
        Sets End_Of_Line to True if at end of line, including if at end of
        page or at end of file; in each of these cases the value of Item
is
        not specified.  Otherwise End_Of_Line is set to False and Item is
set
        to the the next character (without consuming it) from the file.


9   procedure Get_Immediate(File : in  File_Type;
                            Item : out Character);
    procedure Get_Immediate(Item : out Character);

        10   Reads the next character, either control or graphic, from the
        specified File or the default input file.  Mode_Error is
propagated
        if the mode of the file is not In_File.  End_Error is propagated
if
        at the end of the file.  The current column, line and page numbers
        for the file are not affected.


11  procedure Get_Immediate(File      : in  File_Type;
                            Item      : out Character;
                            Available : out Boolean);
    procedure Get_Immediate(Item      : out Character;
                            Available : out Boolean);

        12   If a character, either control or graphic, is available from
the
        specified File or the default input file, then the character is
read;
        Available is True and Item contains the value of this character. 
If
        a character is not available, then Available is False and the
value
        of Item is not specified.  Mode_Error is propagated if the mode of
        the file is not In_File.  End_Error is propagated if at the end of
        the file.  The current column, line and page numbers for the file
are
        not affected.
        13   For an item of type String the following procedures are
        provided:


14  procedure Get(File : in File_Type; Item : out String);
    procedure Get(Item : out String);

        15   Determines the length of the given string and attempts that
        number of Get operations for successive characters of the string
(in
        particular, no operation is performed if the string is null).


16  procedure Put(File : in File_Type; Item : in String);
    procedure Put(Item : in String);

        17   Determines the length of the given string and attempts that
        number of Put operations for successive characters of the string
(in
        particular, no operation is performed if the string is null).


18  procedure Get_Line(File : in File_Type; Item : out String; Last : out
Natur\
al);
    procedure Get_Line(Item : out String;   Last : out Natural);

        19   Reads successive characters from the specified input file and
        assigns them to successive characters of the specified string.
        Reading stops if the end of the string is met.  Reading also stops
if
        the end of the line is met before meeting the end of the string;
in
        this case Skip_Line is (in effect) called with a spacing of 1. 
The
        values of characters not assigned are not specified.
        20   If characters are read, returns in Last the index value such
        that Item(Last) is the last character assigned (the index of the
        first character assigned is Item'First).  If no characters are
read,
        returns in Last an index value that is one less than Item'First. 
The
        exception End_Error is propagated if an attempt is made to skip a
        file terminator.


21  procedure Put_Line(File : in File_Type; Item : in String);
    procedure Put_Line(Item : in String);

        22   Calls the procedure Put for the given string, and then the
        procedure New_Line with a spacing of one.


                            Implementation Advice

23   The Get_Immediate procedures should be implemented with unbuffered
input.  For a device such as a keyboard, input should be ``available'' if
a
key has already been typed, whereas for a disk file, input should always
be
available except at end of file.  For a file associated with a
keyboard-like
device, any line-editing features of the underlying operating system
should
be disabled during the execution of Get_Immediate.


     NOTES
24   (26) Get_Immediate can be used to read a single key from the keyboard
     ``immediately''; that is, without waiting for an end of line.  In a
call
     of Get_Immediate without the parameter Available, the caller will
wait
     until a character is available.

25   (27) In a literal string parameter of Put, the enclosing string
bracket
     characters are not output.  Each doubled string bracket character in
the
     enclosed string is output as a single string bracket character, as a
     consequence of the rule for string literals (see 2.6).

26   (28) A string read by Get or written by Put can extend over several
     lines.  An implementation is allowed to assume that certain external
     files do not contain page terminators, in which case Get_Line and
Skip_
     Line can return as soon as a line terminator is read.




-------------------------------------------------------------------------
Todd Coniam       tconiam@aol.com
Ada 95 - The international standard in OO languages
-------------------------------------------------------------------------
Check: http://lglwww.epfl.ch/Ada/     Free compiler: http://www.gnat.com/





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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-30  0:00 is there a getch() for ada95?? Michael Rizzo
1996-12-31  0:00 ` Tarjei T. Jensen
1996-12-31  0:00 ` Jerry van Dijk
1997-01-12  0:00 ` is there a getch() for ada95?? [LONG] tconiam

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