=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/key-string.c,v retrieving revision 1.27 retrieving revision 1.28 diff -c -r1.27 -r1.28 *** src/usr.bin/tmux/key-string.c 2015/10/26 22:03:04 1.27 --- src/usr.bin/tmux/key-string.c 2015/11/12 11:05:34 1.28 *************** *** 1,4 **** ! /* $OpenBSD: key-string.c,v 1.27 2015/10/26 22:03:04 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: key-string.c,v 1.28 2015/11/12 11:05:34 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 22,33 **** #include "tmux.h" ! int key_string_search_table(const char *); ! int key_string_get_modifiers(const char **); const struct { const char *string; ! int key; } key_string_table[] = { /* Function keys. */ { "F1", KEYC_F1 }, --- 22,33 ---- #include "tmux.h" ! key_code key_string_search_table(const char *); ! key_code key_string_get_modifiers(const char **); const struct { const char *string; ! key_code key; } key_string_table[] = { /* Function keys. */ { "F1", KEYC_F1 }, *************** *** 98,104 **** }; /* Find key string in table. */ ! int key_string_search_table(const char *string) { u_int i; --- 98,104 ---- }; /* Find key string in table. */ ! key_code key_string_search_table(const char *string) { u_int i; *************** *** 111,120 **** } /* Find modifiers. */ ! int key_string_get_modifiers(const char **string) { ! int modifiers; modifiers = 0; while (((*string)[0] != '\0') && (*string)[1] == '-') { --- 111,120 ---- } /* Find modifiers. */ ! key_code key_string_get_modifiers(const char **string) { ! key_code modifiers; modifiers = 0; while (((*string)[0] != '\0') && (*string)[1] == '-') { *************** *** 138,150 **** } /* Lookup a string and convert to a key value. */ ! int key_string_lookup_string(const char *string) { static const char *other = "!#()+,-.0123456789:;<=>?'\r\t"; ! int key, modifiers; u_short u; int size; /* Is this a hexadecimal value? */ if (string[0] == '0' && string[1] == 'x') { --- 138,153 ---- } /* Lookup a string and convert to a key value. */ ! key_code key_string_lookup_string(const char *string) { static const char *other = "!#()+,-.0123456789:;<=>?'\r\t"; ! key_code key; u_short u; int size; + key_code modifiers; + struct utf8_data utf8data; + u_int i; /* Is this a hexadecimal value? */ if (string[0] == '0' && string[1] == 'x') { *************** *** 164,174 **** return (KEYC_NONE); /* Is this a standard ASCII key? */ ! if (string[1] == '\0') { ! key = (u_char) string[0]; ! if (key < 32 || key == 127 || key > 255) return (KEYC_NONE); } else { /* Otherwise look the key up in the table. */ key = key_string_search_table(string); if (key == KEYC_NONE) --- 167,187 ---- return (KEYC_NONE); /* Is this a standard ASCII key? */ ! if (string[1] == '\0' && (u_char)string[0] <= 127) { ! key = (u_char)string[0]; ! if (key < 32 || key == 127) return (KEYC_NONE); } else { + /* Try as a UTF-8 key. */ + if (utf8_open(&utf8data, (u_char)*string)) { + if (strlen(string) != utf8data.size) + return (KEYC_NONE); + for (i = 1; i < utf8data.size; i++) + utf8_append(&utf8data, (u_char)string[i]); + key = utf8_combine(&utf8data); + return (key | modifiers); + } + /* Otherwise look the key up in the table. */ key = key_string_search_table(string); if (key == KEYC_NONE) *************** *** 195,205 **** /* Convert a key code into string format, with prefix if necessary. */ const char * ! key_string_lookup_key(int key) { ! static char out[24]; ! char tmp[8]; ! u_int i; *out = '\0'; --- 208,219 ---- /* Convert a key code into string format, with prefix if necessary. */ const char * ! key_string_lookup_key(key_code key) { ! static char out[24]; ! char tmp[8]; ! u_int i; ! struct utf8_data utf8data; *out = '\0'; *************** *** 237,259 **** return (out); } /* Invalid keys are errors. */ if (key == 127 || key > 255) { ! snprintf(out, sizeof out, "", key); return (out); } /* Check for standard or control key. */ ! if (key >= 0 && key <= 32) { if (key == 0 || key > 26) ! xsnprintf(tmp, sizeof tmp, "C-%c", 64 + key); else ! xsnprintf(tmp, sizeof tmp, "C-%c", 96 + key); } else if (key >= 32 && key <= 126) { tmp[0] = key; tmp[1] = '\0'; } else if (key >= 128) ! xsnprintf(tmp, sizeof tmp, "\\%o", key); strlcat(out, tmp, sizeof out); return (out); --- 251,282 ---- return (out); } + /* Is this a UTF-8 key? */ + if (key > 127 && key < KEYC_BASE) { + if (utf8_split(key, &utf8data) == 0) { + memcpy(out, utf8data.data, utf8data.size); + out[utf8data.size] = '\0'; + return (out); + } + } + /* Invalid keys are errors. */ if (key == 127 || key > 255) { ! snprintf(out, sizeof out, "", key); return (out); } /* Check for standard or control key. */ ! if (key <= 32) { if (key == 0 || key > 26) ! xsnprintf(tmp, sizeof tmp, "C-%c", (int)(64 + key)); else ! xsnprintf(tmp, sizeof tmp, "C-%c", (int)(96 + key)); } else if (key >= 32 && key <= 126) { tmp[0] = key; tmp[1] = '\0'; } else if (key >= 128) ! xsnprintf(tmp, sizeof tmp, "\\%llo", key); strlcat(out, tmp, sizeof out); return (out);