=== removed file 't/12strpkey.c' --- t/12strpkey.c 2011-03-31 23:50:51 +0000 +++ t/12strpkey.c 1970-01-01 00:00:00 +0000 @@ -1,90 +0,0 @@ -#include "../termkey.h" -#include "taplib.h" - -int main(int argc, char *argv[]) -{ - TermKey *tk; - TermKeyKey key; - TermKeyResult res; - -#define CLEAR_KEY do { key.type = -1; key.code.number = -1; key.modifiers = -1; key.utf8[0] = 0; } while(0) - - plan_tests(44); - - tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS); - - CLEAR_KEY; - res = termkey_strpkey(tk, "A", &key, 0); - is_int(res, TERMKEY_RES_KEY, "result for unicode/A/0"); - is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/A/0"); - is_int(key.code.number, 'A', "key.code.number for unicode/A/0"); - is_int(key.modifiers, 0, "key.modifiers for unicode/A/0"); - is_str(key.utf8, "A", "key.utf8 for unicode/A/0"); - - CLEAR_KEY; - res = termkey_strpkey(tk, "C-b", &key, 0); - is_int(res, TERMKEY_RES_KEY, "result for unicode/b/CTRL"); - is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL"); - is_int(key.code.number, 'b', "key.code.number for unicode/b/CTRL"); - is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers for unicode/b/CTRL"); - is_str(key.utf8, "b", "key.utf8 for unicode/b/CTRL"); - - CLEAR_KEY; - res = termkey_strpkey(tk, "Ctrl-b", &key, TERMKEY_FORMAT_LONGMOD); - is_int(res, TERMKEY_RES_KEY, "result for unicode/b/CTRL longmod"); - is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL longmod"); - is_int(key.code.number, 'b', "key.code.number for unicode/b/CTRL longmod"); - is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers for unicode/b/CTRL longmod"); - is_str(key.utf8, "b", "key.utf8 for unicode/b/CTRL longmod"); - - CLEAR_KEY; - res = termkey_strpkey(tk, "^B", &key, TERMKEY_FORMAT_CARETCTRL); - is_int(res, TERMKEY_RES_KEY, "result for unicode/b/CTRL caretctrl"); - is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL caretctrl"); - is_int(key.code.number, 'b', "key.code.number for unicode/b/CTRL caretctrl"); - is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers for unicode/b/CTRL caretctrl"); - is_str(key.utf8, "b", "key.utf8 for unicode/b/CTRL caretctrl"); - - CLEAR_KEY; - res = termkey_strpkey(tk, "A-c", &key, 0); - is_int(res, TERMKEY_RES_KEY, "result for unicode/c/ALT"); - is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT"); - is_int(key.code.number, 'c', "key.code.number for unicode/c/ALT"); - is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT"); - is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT"); - - CLEAR_KEY; - res = termkey_strpkey(tk, "Alt-c", &key, TERMKEY_FORMAT_LONGMOD); - is_int(res, TERMKEY_RES_KEY, "result for unicode/c/ALT longmod"); - is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT longmod"); - is_int(key.code.number, 'c', "key.code.number for unicode/c/ALT longmod"); - is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT longmod"); - is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT longmod"); - - CLEAR_KEY; - res = termkey_strpkey(tk, "M-c", &key, TERMKEY_FORMAT_ALTISMETA); - is_int(res, TERMKEY_RES_KEY, "result for unicode/c/ALT altismeta"); - is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta"); - is_int(key.code.number, 'c', "key.code.number for unicode/c/ALT altismeta"); - is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT altismeta"); - is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta"); - - CLEAR_KEY; - res = termkey_strpkey(tk, "Meta-c", &key, TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_LONGMOD); - is_int(res, TERMKEY_RES_KEY, "result for unicode/c/ALT altismeta+longmod"); - is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta+longmod"); - is_int(key.code.number, 'c', "key.code.number for unicode/c/ALT altismeta+longmod"); - is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT altismeta+longmod"); - is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta+longmod"); - - CLEAR_KEY; - res = termkey_strpkey(tk, "Up", &key, 0); - is_int(res, TERMKEY_RES_KEY, "result for sym/Up/0"); - is_int(key.type, TERMKEY_TYPE_KEYSYM, "key.type for sym/Up/0"); - is_int(key.code.sym, TERMKEY_SYM_UP, "key.code.number for sym/Up/0"); - is_int(key.modifiers, 0, "key.modifiers for sym/Up/0"); - - termkey_destroy(tk); - - return exit_status(); -} === modified file 'termkey.c' --- termkey.c 2011-03-31 23:50:51 +0000 +++ termkey.c 2011-03-31 23:26:02 +0000 @@ -429,13 +429,7 @@ unsigned char b0 = bytes[0]; - if(b0 < 0x80) { - // Single byte ASCII - *cp = b0; - *nbytep = 1; - return TERMKEY_RES_KEY; - } - else if(b0 < 0xc0) { + if(b0 < 0xc0) { // Starts with a continuation byte - that's not right *cp = UTF8_INVALID; *nbytep = 1; @@ -1067,67 +1061,3 @@ return pos; } - -TermKeyResult termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyFormat format) -{ - struct modnames *mods = &modnames[!!(format & TERMKEY_FORMAT_LONGMOD) + - !!(format & TERMKEY_FORMAT_ALTISMETA) * 2]; - - key->modifiers = 0; - - if((format & TERMKEY_FORMAT_CARETCTRL) && str[0] == '^' && str[1]) { - TermKeyResult res = termkey_strpkey(tk, str+1, key, format & ~TERMKEY_FORMAT_CARETCTRL); - - if(res != TERMKEY_RES_KEY) - return res; - if(key->type != TERMKEY_TYPE_UNICODE) - return TERMKEY_RES_NONE; - if(key->code.number < '@' || key->code.number > '_') - return TERMKEY_RES_NONE; - if(key->modifiers != 0) - return TERMKEY_RES_NONE; - - if(key->code.number >= 'A' && key->code.number <= 'Z') - key->code.number += 0x20; - key->modifiers = TERMKEY_KEYMOD_CTRL; - fill_utf8(key); - return res; - } - - const char *hyphen; - - while((hyphen = strchr(str, '-'))) { - size_t n = hyphen - str; - - if(n == strlen(mods->alt) && strncmp(mods->alt, str, n) == 0) - key->modifiers |= TERMKEY_KEYMOD_ALT; - else if(n == strlen(mods->ctrl) && strncmp(mods->ctrl, str, n) == 0) - key->modifiers |= TERMKEY_KEYMOD_CTRL; - else if(n == strlen(mods->shift) && strncmp(mods->shift, str, n) == 0) - key->modifiers |= TERMKEY_KEYMOD_SHIFT; - - else - break; - - str = hyphen + 1; - } - - long codepoint; - size_t nbytes; - - if(parse_utf8((unsigned char *)str, strlen(str), &codepoint, &nbytes) == TERMKEY_RES_KEY && - nbytes == strlen(str)) { - key->type = TERMKEY_TYPE_UNICODE; - key->code.number = codepoint; - fill_utf8(key); - } - else if((key->code.sym = termkey_keyname2sym(tk, str)) != TERMKEY_SYM_UNKNOWN) { - key->type = TERMKEY_TYPE_KEYSYM; - } - // TODO: Consider function keys - else { - return TERMKEY_RES_NONE; - } - - return TERMKEY_RES_KEY; -} === modified file 'termkey.h.in' --- termkey.h.in 2011-03-31 23:50:51 +0000 +++ termkey.h.in 2011-03-31 10:08:43 +0000 @@ -189,8 +189,7 @@ #define TERMKEY_FORMAT_VIM (TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_WRAPBRACKET) -size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format); -TermKeyResult termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyFormat format); +size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format); // Old name for termkey_strfkey() size_t termkey_snprint_key(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format);