Neaten logic by loading terminfo strings in a separate function from the constructor
This commit is contained in:
parent
0a65f60df1
commit
d8f6551972
44
driver-ti.c
44
driver-ti.c
|
@ -157,24 +157,14 @@ static struct trie_node *compress_trie(struct trie_node *n)
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *new_driver(TermKey *tk, const char *term)
|
static int load_terminfo(TermKeyTI *ti, const char *term)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* Have to cast away the const. But it's OK - we know terminfo won't really
|
/* Have to cast away the const. But it's OK - we know terminfo won't really
|
||||||
* modify term */
|
* modify term */
|
||||||
if(setupterm((char*)term, 1, &err) != OK)
|
if(setupterm((char*)term, 1, &err) != OK)
|
||||||
return NULL;
|
return 0;
|
||||||
|
|
||||||
TermKeyTI *ti = malloc(sizeof *ti);
|
|
||||||
if(!ti)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
ti->tk = tk;
|
|
||||||
|
|
||||||
ti->root = new_node_arr(0, 0xff);
|
|
||||||
if(!ti->root)
|
|
||||||
goto abort_free_ti;
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; strfnames[i]; i++) {
|
for(i = 0; strfnames[i]; i++) {
|
||||||
|
@ -189,10 +179,10 @@ static void *new_driver(TermKey *tk, const char *term)
|
||||||
|
|
||||||
struct trie_node *node = NULL;
|
struct trie_node *node = NULL;
|
||||||
|
|
||||||
if(strcmp(strfnames[i] + 4, "mouse") == 0) {
|
if(strcmp(name + 4, "mouse") == 0) {
|
||||||
node = malloc(sizeof(*node));
|
node = malloc(sizeof(*node));
|
||||||
if(!node)
|
if(!node)
|
||||||
goto abort_free_trie;
|
return 0;
|
||||||
|
|
||||||
node->type = TYPE_MOUSE;
|
node->type = TYPE_MOUSE;
|
||||||
}
|
}
|
||||||
|
@ -202,7 +192,7 @@ static void *new_driver(TermKey *tk, const char *term)
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
int set = 0;
|
int set = 0;
|
||||||
|
|
||||||
if(!funcname2keysym(strfnames[i] + 4, &type, &sym, &mask, &set))
|
if(!funcname2keysym(name + 4, &type, &sym, &mask, &set))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(sym == TERMKEY_SYM_NONE)
|
if(sym == TERMKEY_SYM_NONE)
|
||||||
|
@ -214,12 +204,10 @@ static void *new_driver(TermKey *tk, const char *term)
|
||||||
if(node)
|
if(node)
|
||||||
if(!insert_seq(ti, value, node)) {
|
if(!insert_seq(ti, value, node)) {
|
||||||
free(node);
|
free(node);
|
||||||
goto abort_free_trie;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ti->root = compress_trie(ti->root);
|
|
||||||
|
|
||||||
/* Take copies of these terminfo strings, in case we build multiple termkey
|
/* Take copies of these terminfo strings, in case we build multiple termkey
|
||||||
* instances for multiple different termtypes, and it's different by the
|
* instances for multiple different termtypes, and it's different by the
|
||||||
* time we want to use it
|
* time we want to use it
|
||||||
|
@ -234,6 +222,26 @@ static void *new_driver(TermKey *tk, const char *term)
|
||||||
else
|
else
|
||||||
ti->stop_string = NULL;
|
ti->stop_string = NULL;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *new_driver(TermKey *tk, const char *term)
|
||||||
|
{
|
||||||
|
TermKeyTI *ti = malloc(sizeof *ti);
|
||||||
|
if(!ti)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ti->tk = tk;
|
||||||
|
|
||||||
|
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;
|
return ti;
|
||||||
|
|
||||||
abort_free_trie:
|
abort_free_trie:
|
||||||
|
|
Loading…
Reference in New Issue