mfeldman@seas.gwu.edu (Michael Feldman) (04/04/91)
Recently someone posted a nice portable (Unix-oriented) solution to the problem of getting a single character from the keyboard in the presence of tasks. As I recall, there was a brief C program interfaced to Ada, and a task which polled for input. Can somebody re-post this? Mike Feldman --------------------------------------------------------------------------- Prof. Michael Feldman Department of Electrical Engineering and Computer Science The George Washington University Washington, DC 20052 U.S.A. phone 202-994-5253 fax 202-994-5296 email mfeldman@seas.gwu.edu ---------------------------------------------------------------------------
g_harrison@vger.nsu.edu (George C. Harrison, Norfolk State University) (04/04/91)
In article <2986@sparko.gwu.edu>, mfeldman@seas.gwu.edu (Michael Feldman) writes: > Recently someone posted a nice portable (Unix-oriented) solution to > the problem of getting a single character from the keyboard in the > presence of tasks. As I recall, there was a brief C program interfaced > to Ada, and a task which polled for input. Can somebody re-post this? > > Mike Feldman > --------------------------------------------------------------------------- > Prof. Michael Feldman > Department of Electrical Engineering and Computer Science > The George Washington University > Washington, DC 20052 U.S.A. > > phone 202-994-5253 > fax 202-994-5296 > email mfeldman@seas.gwu.edu > --------------------------------------------------------------------------- This is not EXACTLY what you may want but... From John Herro's ADA-TUTR: -- UNIX.ADA Ver. 1.21 18-FEB-1989 -- Copyright 1988-1989 John J. Herro -- Software Innovations Technology -- 1083 Mandarin Drive NE, Palm Bay, FL 32905-4706 (407)951-0233 -- -- Compile this before compiling ADA_TUTR.ADA on a UNIX based system. You must -- also compile ONECHAR.C with a C compiler before linking. See first page of -- ADA_TUTR.ADA for more details. -- package body CUSTOM_IO is etc.... procedure GET(CHAR : out CHARACTER) is function ONECHAR return CHARACTER; pragma INTERFACE (C, ONECHAR); begin CHAR := ONECHAR; end GET; /* Complements of Dave Hill of Salt Lake City...... for more see ADA-TUTR by John Herro */ #include <stdio.h> #include <termio.h> char onechar() { static struct termio newsets, oldsets; char c; ioctl(fileno(stdin), TCGETA, &newsets); ioctl(fileno(stdin), TCGETA, &oldsets); /* used by cooked */ newsets.c_cc[4] = '\001'; newsets.c_cc[5] = '\0'; newsets.c_lflag &= ~ (ICANON); ioctl(fileno(stdin), TCSETAF, &newsets); c = getchar(); ioctl(fileno(stdin), TCSETAF, &oldsets); return (c); } -- George C. Harrison ----------------------- ----- Professor of Computer Science ----------------------- ----- Norfolk State University ----------------------- ----- 2401 Corprew Avenue, Norfolk, Virginia 23504 ----------------------- ----- INTERNET: g_harrison@vger.nsu.edu ---------------------------------
mfeldman@seas.gwu.edu (Michael Feldman) (04/06/91)
In article <807.27fb097d@vger.nsu.edu> g_harrison@vger.nsu.edu (George C. Harrison, Norfolk State University) writes: > >This is not EXACTLY what you may want but... > >From John Herro's ADA-TUTR: > ... code deleted I have this. I thought I remembered seeing a tasking example built on top of this, in which the input task polls for input so the entire Unix process doesn't hang waiting for a keystroke. The AdaTutor example is fine, as far as it goes, in a sequential program, but it ain't enough for a tasking program... Mike Feldman