=== modified file 'termkey-internal.h' --- termkey-internal.h 2012-03-08 21:15:25 +0000 +++ termkey-internal.h 2012-01-20 17:00:09 +0000 @@ -45,7 +45,6 @@ int waittime; // msec char is_closed; - char is_started; int nkeynames; const char **keynames; === modified file 'termkey.c' --- termkey.c 2012-03-08 21:15:25 +0000 +++ termkey.c 2012-02-13 23:40:42 +0000 @@ -195,7 +195,6 @@ tk->waittime = 50; /* msec */ tk->is_closed = 0; - tk->is_started = 0; tk->nkeynames = 64; tk->keynames = NULL; @@ -271,10 +270,51 @@ goto abort_free_keynames; } + if(tk->fd != -1 && !(tk->flags & TERMKEY_FLAG_NOTERMIOS)) { + struct termios termios; + if(tcgetattr(tk->fd, &termios) == 0) { + tk->restore_termios = termios; + tk->restore_termios_valid = 1; + + termios.c_iflag &= ~(IXON|INLCR|ICRNL); + termios.c_lflag &= ~(ICANON|ECHO); + termios.c_cc[VMIN] = 1; + termios.c_cc[VTIME] = 0; + + if(tk->flags & TERMKEY_FLAG_CTRLC) + /* want no signal keys at all, so just disable ISIG */ + termios.c_lflag &= ~ISIG; + else { + /* Disable Ctrl-\==VQUIT and Ctrl-D==VSUSP but leave Ctrl-C as SIGINT */ + termios.c_cc[VQUIT] = _POSIX_VDISABLE; + termios.c_cc[VSUSP] = _POSIX_VDISABLE; + /* Some OSes have Ctrl-Y==VDSUSP */ +#ifdef VDSUSP + termios.c_cc[VDSUSP] = _POSIX_VDISABLE; +#endif + } + +#ifdef DEBUG + fprintf(stderr, "Setting termios(3) flags\n"); +#endif + tcsetattr(tk->fd, TCSANOW, &termios); + } + } + + struct TermKeyDriverNode *p; + for(p = tk->drivers; p; p = p->next) + if(p->driver->start_driver) + if(!(*p->driver->start_driver)(tk, p->info)) + goto abort_free_drivers; + +#ifdef DEBUG + fprintf(stderr, "Drivers started; termkey instance %p is ready\n", tk); +#endif + return 1; abort_free_drivers: - for(struct TermKeyDriverNode *p = tk->drivers; p; ) { + for(p = tk->drivers; p; ) { (*p->driver->free_driver)(p->info); struct TermKeyDriverNode *next = p->next; free(p); @@ -321,17 +361,12 @@ const char *term = getenv("TERM"); - if(!termkey_init(tk, term)) - goto abort; - - if(!termkey_start(tk)) - goto abort; + if(!termkey_init(tk, term)) { + free(tk); + return NULL; + } return tk; - -abort: - free(tk); - return NULL; } TermKey *termkey_new_abstract(const char *term, int flags) @@ -349,8 +384,6 @@ return NULL; } - termkey_start(tk); - return tk; } @@ -372,67 +405,6 @@ void termkey_destroy(TermKey *tk) { - if(tk->is_started) - termkey_stop(tk); - - termkey_free(tk); -} - -int termkey_start(TermKey *tk) -{ - if(tk->is_started) - return 1; - - if(tk->fd != -1 && !(tk->flags & TERMKEY_FLAG_NOTERMIOS)) { - struct termios termios; - if(tcgetattr(tk->fd, &termios) == 0) { - tk->restore_termios = termios; - tk->restore_termios_valid = 1; - - termios.c_iflag &= ~(IXON|INLCR|ICRNL); - termios.c_lflag &= ~(ICANON|ECHO); - termios.c_cc[VMIN] = 1; - termios.c_cc[VTIME] = 0; - - if(tk->flags & TERMKEY_FLAG_CTRLC) - /* want no signal keys at all, so just disable ISIG */ - termios.c_lflag &= ~ISIG; - else { - /* Disable Ctrl-\==VQUIT and Ctrl-D==VSUSP but leave Ctrl-C as SIGINT */ - termios.c_cc[VQUIT] = _POSIX_VDISABLE; - termios.c_cc[VSUSP] = _POSIX_VDISABLE; - /* Some OSes have Ctrl-Y==VDSUSP */ -#ifdef VDSUSP - termios.c_cc[VDSUSP] = _POSIX_VDISABLE; -#endif - } - -#ifdef DEBUG - fprintf(stderr, "Setting termios(3) flags\n"); -#endif - tcsetattr(tk->fd, TCSANOW, &termios); - } - } - - struct TermKeyDriverNode *p; - for(p = tk->drivers; p; p = p->next) - if(p->driver->start_driver) - if(!(*p->driver->start_driver)(tk, p->info)) - return 0; - -#ifdef DEBUG - fprintf(stderr, "Drivers started; termkey instance %p is ready\n", tk); -#endif - - tk->is_started = 1; - return 1; -} - -int termkey_stop(TermKey *tk) -{ - if(!tk->is_started) - return 1; - struct TermKeyDriverNode *p; for(p = tk->drivers; p; p = p->next) if(p->driver->stop_driver) @@ -441,9 +413,7 @@ if(tk->restore_termios_valid) tcsetattr(tk->fd, TCSANOW, &tk->restore_termios); - tk->is_started = 0; - - return 1; + termkey_free(tk); } int termkey_get_fd(TermKey *tk) === modified file 'termkey.h.in' --- termkey.h.in 2012-03-08 21:15:25 +0000 +++ termkey.h.in 2012-02-13 23:40:42 +0000 @@ -161,9 +161,6 @@ void termkey_free(TermKey *tk); void termkey_destroy(TermKey *tk); -int termkey_start(TermKey *tk); -int termkey_stop(TermKey *tk); - int termkey_get_fd(TermKey *tk); int termkey_get_flags(TermKey *tk);