aboutsummaryrefslogtreecommitdiff
path: root/driver-ti.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-09-23 23:40:54 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-09-23 23:40:54 +0100
commitd8f6551972b8f370c712b46cad4fedee6442923f (patch)
tree1791b5ffab6395ead5c89cdaf12b837a8cbd4756 /driver-ti.c
parent0a65f60df137cf1a74de18fefe40b5470d842b77 (diff)
downloadtermo-d8f6551972b8f370c712b46cad4fedee6442923f.tar.gz
termo-d8f6551972b8f370c712b46cad4fedee6442923f.tar.xz
termo-d8f6551972b8f370c712b46cad4fedee6442923f.zip
Neaten logic by loading terminfo strings in a separate function from the constructor
Diffstat (limited to 'driver-ti.c')
-rw-r--r--driver-ti.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/driver-ti.c b/driver-ti.c
index c26e89a..297a723 100644
--- a/driver-ti.c
+++ b/driver-ti.c
@@ -157,24 +157,14 @@ static struct trie_node *compress_trie(struct trie_node *n)
return n;
}
-static void *new_driver(TermKey *tk, const char *term)
+static int load_terminfo(TermKeyTI *ti, const char *term)
{
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)
- return NULL;
-
- 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;
+ return 0;
int 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;
- if(strcmp(strfnames[i] + 4, "mouse") == 0) {
+ if(strcmp(name + 4, "mouse") == 0) {
node = malloc(sizeof(*node));
if(!node)
- goto abort_free_trie;
+ return 0;
node->type = TYPE_MOUSE;
}
@@ -202,7 +192,7 @@ static void *new_driver(TermKey *tk, const char *term)
int mask = 0;
int set = 0;
- if(!funcname2keysym(strfnames[i] + 4, &type, &sym, &mask, &set))
+ if(!funcname2keysym(name + 4, &type, &sym, &mask, &set))
continue;
if(sym == TERMKEY_SYM_NONE)
@@ -214,12 +204,10 @@ static void *new_driver(TermKey *tk, const char *term)
if(node)
if(!insert_seq(ti, value, 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
* instances for multiple different termtypes, and it's different by the
* time we want to use it
@@ -234,6 +222,26 @@ static void *new_driver(TermKey *tk, const char *term)
else
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;
abort_free_trie: