#include #include #include #include static struct termio back; static void KeyInit() { struct termio term = back; /* Disable linebuffer and echoing */ term.c_lflag &= ~(ICANON|ECHO); /* Disable signals generated by ^C, ^Z and ^] (int,stop,quit) *term.c_lflag &= ~(ISIG); */ /* Disable special handling of ^S and ^Q *term.c_iflag &= ~(IXON); */ term.c_cc[VMIN] = 1; /* 0=no block, 1=do block */ ioctl(0, TCSETA, &term); /* Another way to make nonblocking: * fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); */ } static void Resume(int c) { c=c; KeyInit(); } int main(void) { /* Make this signal handler so that suspending and */ /* resuming the program does not break the terminal */ ioctl(0, TCGETA, &back); signal(SIGCONT, Resume); KeyInit(); printf("q lopettaa.\n"); for(;;) { int c = getchar(); if(c == EOF)break; printf("Nappi: '%c'\n", c); if(c == 'q')break; } ioctl(0, TCSETA, &back); return 0; }