comp.lang.ada
 help / color / mirror / Atom feed
From: jason@comp.lancs.ac.uk (Mr.J.P.Kitchen)
Subject: Non line-buffered input
Date: 3 Dec 90 11:27:16 GMT	[thread overview]
Message-ID: <1115@dcl-vitus.comp.lancs.ac.uk> (raw)

Arne - I lost your Email address - but I'm posting here because it should
have more general interest.

>> 
>> Newsgroups: comp.lang.ada
>> Organization: Department of Computing at Lancaster University, UK.
>> 
>> Text_io is line buffered. The only way around this is to write your own
>> single character I/O routines in another language (e.g. 'C') and pragma
>> interface it to your Ada programs.
>>
 
>That sounds like a practicable solution.  The problem is, I don't know
>anything about pragma.  Could you possibly tell me how touse it ??


It depends on what system you're using and (unfortunately) which Ada compiler.
On our system which is running under UNIX version xxx and using the York Ada
Compiler, a sample program may be as follows:-


package MY_IO is
   pragma LIBNAME("get_charac");
   function GET_CHARAC return CHARACTER;
end MY_IO;

with MY_IO, TEXT_IO;
use TEXT_IO, MY_IO;
procedure TEST is
   CH: CHARACTER;
begin
   loop
      PUT("Press a key (don't press return after it): ");
      CH:= GET_CHARAC;
      NEW_LINE; PUT("The key was "); PUT(CH); NEW_LINE(2);
   end loop;
end TEST;


Note: the PRAGMA LIBNAME would be replaced by PRAGMA INTERFACE(C,GET_CHARAC)
      in most versions of Ada.

You will also need a 'C' program along the following lines in another file:-

#include <stdio.h>
char get_charac()
{
	char ch;
	system("stty cbreak"); /* half cooked mode */
	ch=getc(stdin);
	system("stty -cbreak"); /* back to normal */
	return ch;
}


To compile this with the York Ada compiler, I used the following command:-

       Ac -M test.A get_charac.c

-M tells the compiler that a main unit is being submitted.


Hope this is useful to you.

--Jason

             reply	other threads:[~1990-12-03 11:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-12-03 11:27 Mr.J.P.Kitchen [this message]
1990-12-14  0:46 ` Non line-buffered input William McIver Jr.
replies disabled

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