=== modified file 't/10keyname.c' --- t/10keyname.c 2011-04-01 12:26:54 +0000 +++ t/10keyname.c 2011-03-31 12:51:21 +0000 @@ -5,9 +5,8 @@ { TermKey *tk; TermKeySym sym; - char *end; - plan_tests(10); + plan_tests(3); tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS); @@ -17,19 +16,6 @@ sym = termkey_keyname2sym(tk, "SomeUnknownKey"); is_int(sym, TERMKEY_SYM_UNKNOWN, "keyname2sym SomeUnknownKey"); - end = termkey_lookup_keyname(tk, "Up", &sym); - ok(!!end, "termkey_get_keyname Up returns non-NULL"); - is_str(end, "", "termkey_get_keyname Up return points at endofstring"); - is_int(sym, TERMKEY_SYM_UP, "termkey_get_keyname Up yields Up symbol"); - - end = termkey_lookup_keyname(tk, "DownMore", &sym); - ok(!!end, "termkey_get_keyname DownMore returns non-NULL"); - is_str(end, "More", "termkey_get_keyname DownMore return points at More"); - is_int(sym, TERMKEY_SYM_DOWN, "termkey_get_keyname DownMore yields Down symbol"); - - end = termkey_lookup_keyname(tk, "SomeUnknownKey", &sym); - ok(!end, "termkey_get_keyname SomeUnknownKey returns NULL"); - is_str(termkey_get_keyname(tk, TERMKEY_SYM_SPACE), "Space", "get_keyname SPACE"); termkey_destroy(tk); === modified file 'termkey.c' --- termkey.c 2011-04-01 12:26:54 +0000 +++ termkey.c 2011-04-01 09:48:15 +0000 @@ -914,30 +914,18 @@ return "UNKNOWN"; } -char *termkey_lookup_keyname(TermKey *tk, const char *str, TermKeySym *sym) +TermKeySym termkey_keyname2sym(TermKey *tk, const char *keyname) { /* 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 */ - 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; - } - - return NULL; -} - -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; + + for(sym = 0; sym < tk->nkeynames; sym++) + if(tk->keynames[sym] && strcmp(keyname, tk->keynames[sym]) == 0) + return sym; + + return TERMKEY_SYM_UNKNOWN; } static TermKeySym register_c0(TermKey *tk, TermKeySym sym, unsigned char ctrl, const char *name) === modified file 'termkey.h.in' --- termkey.h.in 2011-04-01 12:26:54 +0000 +++ termkey.h.in 2011-03-31 23:50:51 +0000 @@ -171,12 +171,11 @@ TermKeySym termkey_register_keyname(TermKey *tk, TermKeySym sym, const char *name); const char *termkey_get_keyname(TermKey *tk, TermKeySym sym); -char *termkey_lookup_keyname(TermKey *tk, const char *str, TermKeySym *sym); + +TermKeyResult termkey_interpret_mouse(TermKey *tk, TermKeyKey *key, TermKeyMouseEvent *event, int *button, int *line, int *col); TermKeySym termkey_keyname2sym(TermKey *tk, const char *keyname); -TermKeyResult termkey_interpret_mouse(TermKey *tk, TermKeyKey *key, TermKeyMouseEvent *event, int *button, int *line, int *col); - typedef enum { TERMKEY_FORMAT_LONGMOD = 1 << 0, // Shift-... instead of S-... TERMKEY_FORMAT_CARETCTRL = 1 << 1, // ^X instead of C-X === modified file 'termkey_get_keyname.3' --- termkey_get_keyname.3 2011-04-01 12:26:54 +0000 +++ termkey_get_keyname.3 2011-03-31 14:42:32 +0000 @@ -17,6 +17,5 @@ .BR termkey_new (3), .BR termkey_getkey (3), .BR termkey_waitkey (3), -.BR termkey_lookup_keyname (3), .BR termkey_keyname2sym (3), .BR termkey_strfkey (3) === modified file 'termkey_keyname2sym.3' --- termkey_keyname2sym.3 2011-04-01 12:26:54 +0000 +++ termkey_keyname2sym.3 2011-04-01 10:11:50 +0000 @@ -10,13 +10,13 @@ .sp Link with \fI-ltermkey\fP. .SH DESCRIPTION -\fBtermkey_keyname2sym\fP looks up the symbolic key value represented by the given string name. This is a case-sensitive comparison. If the given name is not found, \fBTERMKEY_SYM_UNKNOWN\fP is returned instead. This function is the inverse of \fBtermkey_get_keyname\fP(3), and is a more specific form of \fBtermkey_lookup_keyname\fP(3) which only recognises names as complete strings. +\fBtermkey_keyname2sym\fP looks up the symbolic key value represented by the given string name. This is a case-sensitive comparison. If the given name is not found, \fBTERMKEY_SYM_UNKNOWN\fP is returned instead. This function is the inverse of \fBtermkey_get_keyname\fP(3). .PP Because the key names are stored in an array indexed by the symbol number, this function has to perform a linear search of the names. Use of this function should be restricted to converting key names into symbolic values during a program's initialisation, so that efficient comparisons can be done while it is running. .SH "RETURN VALUE" -\fBtermkey_keyname2sym\fP() returns a symbolic key constant, or \fBTERMKEY_SYM_UNKNOWN\fP. +\fBtermkey_get_key\fP() returns a pointer to a string. .SH "SEE ALSO" .BR termkey_new (3), .BR termkey_get_keyname (3), -.BR termkey_lookup_keyname (3), +.BR termkey_strfkey (3), .BR termkey_strpkey (3) === removed file 'termkey_lookup_keyname.3' --- termkey_lookup_keyname.3 2011-04-01 12:26:54 +0000 +++ termkey_lookup_keyname.3 1970-01-01 00:00:00 +0000 @@ -1,23 +0,0 @@ -.TH TERMKEY_LOOKUP_KEYNAME 3 -.SH NAME -termkey_lookup_keyname \- look up a symbolic key value for a string name -.SH SYNOPSIS -.nf -.B #include -.sp -.BI "char *termkey_lookup_keyname(TermKey *" tk ", const char *" keyname ", -.BI " TermKeySym *" sym "); -.fi -.sp -Link with \fI-ltermkey\fP. -.SH DESCRIPTION -\fBtermkey_lookup_keyname\fP looks up the symbolic key value represented by the given string name. This is a case-sensitive comparison. The symbolic value is written to the variable addressed by \fIsym\fP. This function is a more general form of \fBtermkey_keyname2sym\fP(3) because it can recognise a symbolic key name within a longer string, returning a pointer to the remainder of the input after the key name. -.PP -Because the key names are stored in an array indexed by the symbol number, this function has to perform a linear search of the names. Use of this function should be restricted to converting key names into symbolic values during a program's initialisation, so that efficient comparisons can be done while it is running. -.SH "RETURN VALUE" -\fBtermkey_lookup_keyname\fP() returns a pointer to the first character after a recognised name, or \fBNULL\fP if the string does not begin with the name of a recognised symbolic key. -.SH "SEE ALSO" -.BR termkey_new (3), -.BR termkey_get_keyname (3), -.BR termkey_keyname2sym (3), -.BR termkey_strpkey (3)