=== modified file 'driver-ti.c' --- driver-ti.c 2016-11-30 18:17:07 +0000 +++ driver-ti.c 2016-09-27 22:18:20 +0000 @@ -51,12 +51,6 @@ typedef struct { TermKey *tk; -#ifdef HAVE_UNIBILIUM - unibi_term *unibi; /* only valid until first 'start' call */ -#else - char *term; /* only valid until first 'start' call */ -#endif - struct trie_node *root; char *start_string; @@ -169,27 +163,23 @@ return n; } -static int load_terminfo(TermKeyTI *ti) +static int load_terminfo(TermKeyTI *ti, const char *term) { int i; #ifdef HAVE_UNIBILIUM - unibi_term *unibi = ti->unibi; + unibi_term *unibi = unibi_from_term(term); + if(!unibi) + return 0; #else - { - int err; + int err; - /* Have to cast away the const. But it's OK - we know terminfo won't really - * modify term */ - if(setupterm((char*)ti->term, 1, &err) != OK) - return 0; - } + /* Have to cast away the const. But it's OK - we know terminfo won't really + * modify term */ + if(setupterm((char*)term, 1, &err) != OK) + return 0; #endif - ti->root = new_node_arr(0, 0xff); - if(!ti->root) - return 0; - #ifdef HAVE_UNIBILIUM for(i = unibi_string_begin_+1; i < unibi_string_end_; i++) #else @@ -268,12 +258,8 @@ #ifdef HAVE_UNIBILIUM unibi_destroy(unibi); -#else - free(ti->term); #endif - ti->root = compress_trie(ti->root); - return 1; } @@ -284,28 +270,22 @@ return NULL; ti->tk = tk; - ti->root = NULL; - -#ifdef HAVE_UNIBILIUM - ti->unibi = unibi_from_term(term); - if(!ti->unibi) - goto abort_free; -#else - { - int err; - - /* Have to cast away the const. But it's OK - we know terminfo won't really - * modify term */ - if(setupterm((char*)term, 1, &err) != OK) - goto abort_free; - - ti->term = strdup(term); - } -#endif + + ti->root = new_node_arr(0, 0xff); + if(!ti->root) + goto abort_free_ti; + + if(!load_terminfo(ti, term)) + goto abort_free_trie; + + ti->root = compress_trie(ti->root); return ti; -abort_free: +abort_free_trie: + free_trie(ti->root); + +abort_free_ti: free(ti); return NULL; @@ -315,14 +295,9 @@ { TermKeyTI *ti = info; struct stat statbuf; - char *start_string; + char *start_string = ti->start_string; size_t len; - if(!ti->root) - load_terminfo(ti); - - start_string = ti->start_string; - if(tk->fd == -1 || !start_string) return 1;