Support a list of potential backend drivers

This commit is contained in:
Paul LeoNerd Evans 2008-10-07 03:17:06 +01:00
parent d7358c43af
commit 8b7c2b5d4f
1 changed files with 17 additions and 2 deletions

View File

@ -8,6 +8,11 @@
#include <stdio.h> #include <stdio.h>
static struct termkey_driver *drivers[] = {
&termkey_driver_csi,
NULL,
};
termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime) termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime)
{ {
termkey_t *tk = malloc(sizeof(*tk)); termkey_t *tk = malloc(sizeof(*tk));
@ -59,9 +64,19 @@ termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime)
for(i = 0; i < tk->nkeynames; i++) for(i = 0; i < tk->nkeynames; i++)
tk->keynames[i] = NULL; tk->keynames[i] = NULL;
tk->driver = termkey_driver_csi; for(i = 0; drivers[i]; i++) {
void *driver_info = (*drivers[i]->new_driver)(tk);
if(!driver_info)
continue;
tk->driver_info = (*tk->driver.new_driver)(tk); tk->driver = *(drivers[i]);
tk->driver_info = driver_info;
}
if(!tk->driver_info) {
fprintf(stderr, "Unable to find a terminal driver\n");
return NULL;
}
// Special built-in names // Special built-in names
termkey_register_keyname(tk, TERMKEY_SYM_NONE, "NONE"); termkey_register_keyname(tk, TERMKEY_SYM_NONE, "NONE");