aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-04-01 13:26:54 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-04-01 13:26:54 +0100
commitdbb13defb7ab00b1f4e801f3daab7dd1a3744ac0 (patch)
tree4d7bd461bcc48380b3c353ac7b7cec2ed22d313b /termkey.c
parent6adb2324f5568c3045e97c1712a1bc6e3f9220cc (diff)
downloadtermo-dbb13defb7ab00b1f4e801f3daab7dd1a3744ac0.tar.gz
termo-dbb13defb7ab00b1f4e801f3daab7dd1a3744ac0.tar.xz
termo-dbb13defb7ab00b1f4e801f3daab7dd1a3744ac0.zip
Provide a termkey_lookup_keyname that can do partial buffer parsing
Diffstat (limited to 'termkey.c')
-rw-r--r--termkey.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/termkey.c b/termkey.c
index 302d81f..0503326 100644
--- a/termkey.c
+++ b/termkey.c
@@ -914,18 +914,30 @@ const char *termkey_get_keyname(TermKey *tk, TermKeySym sym)
return "UNKNOWN";
}
-TermKeySym termkey_keyname2sym(TermKey *tk, const char *keyname)
+char *termkey_lookup_keyname(TermKey *tk, const char *str, TermKeySym *sym)
{
/* We store an array, so we can't do better than a linear search. Doesn't
* matter because user won't be calling this too often */
- TermKeySym sym;
+ for(*sym = 0; *sym < tk->nkeynames; (*sym)++) {
+ const char *thiskey = tk->keynames[*sym];
+ if(!thiskey)
+ continue;
+ size_t len = strlen(thiskey);
+ if(strncmp(str, thiskey, len) == 0)
+ return (char *)str + len;
+ }
- for(sym = 0; sym < tk->nkeynames; sym++)
- if(tk->keynames[sym] && strcmp(keyname, tk->keynames[sym]) == 0)
- return sym;
+ return NULL;
+}
- return TERMKEY_SYM_UNKNOWN;
+TermKeySym termkey_keyname2sym(TermKey *tk, const char *keyname)
+{
+ TermKeySym sym;
+ char *endp = termkey_lookup_keyname(tk, keyname, &sym);
+ if(!endp || endp[0])
+ return TERMKEY_SYM_UNKNOWN;
+ return sym;
}
static TermKeySym register_c0(TermKey *tk, TermKeySym sym, unsigned char ctrl, const char *name)