ioctl() and termios for "canonical" read
Well, this app is giving me quite a headache :(
I need to have a program read a char at a time and then process it, using read(). Therefore, I'll have to set the terminal to canonical mode (correct?), using ioctl() along with termios' flags. What I just can't get is what flag to use and wich values to set (I've already read ALL the man page...). My best bet is using the c_lflag and manipulating it's ICANON value. Can somebody point out a good solution for this problem? Some sample code would be usefull, I'm not very skilled...
Thanx in advance!
PS: I can't use getchar :rolleyes:
Here's how to, if anyone ever needs it
struct termios oldT, newT;
ioctl(0,TCGETS,&oldT); /*get current mode
newT.c_lflag &= ~ECHO; /* echo off */
newT.c_lflag &= ~ICANON; /*one char @ a time*/
ioctl(0,TCSETS,&newT); /* set new terminal mode */
read(0,&c,1); /*read 1 char @ a time from stdin*/
ioctl(0,TCSETS,&oldT); /* restore previous terminal mode */
Detailed info on: http://www.unidata.ucar.edu/cgi-bin/man-cgi?termio+7