diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2008-10-08 01:52:53 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2008-10-08 01:52:53 +0100 |
commit | 9f7d84ba814eedb19075c7c476ee60327a771eef (patch) | |
tree | e4a1e5185bfd100f3a11dcf09290ebb13c83db84 /termkey.c | |
parent | a80c10e90f5213b681fa32a52198ec81f454adac (diff) | |
download | termo-9f7d84ba814eedb19075c7c476ee60327a771eef.tar.gz termo-9f7d84ba814eedb19075c7c476ee60327a771eef.tar.xz termo-9f7d84ba814eedb19075c7c476ee60327a771eef.zip |
Register keynames using a more extensible internal array; easier to add new ones
Diffstat (limited to 'termkey.c')
-rw-r--r-- | termkey.c | 30 |
1 files changed, 21 insertions, 9 deletions
@@ -21,6 +21,20 @@ static termkey_result getkey_simple(termkey_t *tk, termkey_key *key); static termkey_keysym register_c0(termkey_t *tk, termkey_keysym sym, unsigned char ctrl, const char *name); static termkey_keysym register_c0_full(termkey_t *tk, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char ctrl, const char *name); +static struct { + termkey_keysym sym; + const char *name; +} keynames[] = { + { TERMKEY_SYM_NONE, "NONE" }, + { TERMKEY_SYM_BACKSPACE, "Backspace" }, + { TERMKEY_SYM_TAB, "Tab" }, + { TERMKEY_SYM_ENTER, "Enter" }, + { TERMKEY_SYM_ESCAPE, "Escape" }, + { TERMKEY_SYM_SPACE, "Space" }, + { TERMKEY_SYM_DEL, "DEL" }, + { 0, NULL }, +}; + termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime) { termkey_t *tk = malloc(sizeof(*tk)); @@ -79,10 +93,13 @@ termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime) tk->method.emit_codepoint = &emit_codepoint; tk->method.getkey_simple = &getkey_simple; - register_c0(tk, TERMKEY_SYM_BACKSPACE, 0x08, "Backspace"); - register_c0(tk, TERMKEY_SYM_TAB, 0x09, "Tab"); - register_c0(tk, TERMKEY_SYM_ENTER, 0x0d, "Enter"); - register_c0(tk, TERMKEY_SYM_ESCAPE, 0x1b, "Escape"); + for(i = 0; keynames[i].name; i++) + termkey_register_keyname(tk, keynames[i].sym, keynames[i].name); + + register_c0(tk, TERMKEY_SYM_BACKSPACE, 0x08, NULL); + register_c0(tk, TERMKEY_SYM_TAB, 0x09, NULL); + register_c0(tk, TERMKEY_SYM_ENTER, 0x0d, NULL); + register_c0(tk, TERMKEY_SYM_ESCAPE, 0x1b, NULL); for(i = 0; drivers[i]; i++) { void *driver_info = (*drivers[i]->new_driver)(tk); @@ -99,11 +116,6 @@ termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime) return NULL; } - // Special built-in names - termkey_register_keyname(tk, TERMKEY_SYM_NONE, "NONE"); - termkey_register_keyname(tk, TERMKEY_SYM_SPACE, "Space"); - termkey_register_keyname(tk, TERMKEY_SYM_DEL, "DEL"); - if(!(flags & TERMKEY_FLAG_NOTERMIOS)) { struct termios termios; if(tcgetattr(fd, &termios) == 0) { |