=== modified file 'demo.c' --- demo.c 2008-02-23 20:26:04 +0000 +++ demo.c 2008-02-23 20:07:48 +0000 @@ -1,10 +1,24 @@ #include #include +#include #include #include "termkey.h" int main(int argc, char *argv[]) { + struct termios termios; + + if(tcgetattr(0, &termios)) { + perror("ioctl(TCIOGETS)"); + exit(1); + } + + int old_lflag = termios.c_lflag; + termios.c_iflag &= ~(IXON|INLCR|ICRNL); + termios.c_lflag &= ~(ICANON|ECHO|ISIG); + + tcsetattr(0, TCSANOW, &termios); + termkey_t *tk = termkey_new(0, 0); termkey_result ret; @@ -30,5 +44,8 @@ break; } - termkey_destroy(tk); + termios.c_lflag = old_lflag; + tcsetattr(0, TCSANOW, &termios); + + termkey_free(tk); } === modified file 'termkey.c' --- termkey.c 2008-02-23 20:26:04 +0000 +++ termkey.c 2008-02-23 20:07:48 +0000 @@ -4,7 +4,6 @@ #include #include #include -#include #include @@ -22,9 +21,6 @@ size_t buffcount; // NUMBER of entires valid in buffer size_t buffsize; // Total malloc'ed size - struct termios restore_termios; - char restore_termios_valid; - int waittime; // msec char is_closed; @@ -82,8 +78,6 @@ tk->buffcount = 0; tk->buffsize = buffsize; - tk->restore_termios_valid = 0; - tk->waittime = waittime; tk->is_closed = 0; @@ -187,19 +181,6 @@ termkey_register_csifunc(tk, TERMKEY_SYM_F19, 33, "F19"); termkey_register_csifunc(tk, TERMKEY_SYM_F20, 34, "F20"); - if(!(flags & TERMKEY_FLAG_NOTERMIOS)) { - struct termios termios; - if(tcgetattr(fd, &termios) == 0) { - tk->restore_termios = termios; - tk->restore_termios_valid = 1; - - termios.c_iflag &= ~(IXON|INLCR|ICRNL); - termios.c_lflag &= ~(ICANON|ECHO|ISIG); - - tcsetattr(fd, TCSANOW, &termios); - } - } - return tk; } @@ -217,14 +198,6 @@ free(tk); } -void termkey_destroy(termkey_t *tk) -{ - if(tk->restore_termios_valid) - tcsetattr(tk->fd, TCSANOW, &tk->restore_termios); - - termkey_free(tk); -} - void termkey_setwaittime(termkey_t *tk, int msec) { tk->waittime = msec; === modified file 'termkey.h' --- termkey.h 2008-02-23 20:26:04 +0000 +++ termkey.h 2008-02-23 19:22:28 +0000 @@ -115,12 +115,10 @@ TERMKEY_FLAG_CONVERTKP = 0x02, // Convert KP codes to regular keypresses TERMKEY_FLAG_RAW = 0x04, // Input is raw bytes, not UTF-8 TERMKEY_FLAG_UTF8 = 0x08, // Input is definitely UTF-8 - TERMKEY_FLAG_NOTERMIOS = 0x10, // Do not make initial termios calls on construction }; termkey_t *termkey_new(int fd, int flags); void termkey_free(termkey_t *tk); -void termkey_destroy(termkey_t *tk); void termkey_setwaittime(termkey_t *tk, int msec); int termkey_getwaittime(termkey_t *tk);