=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/tty-acs.c,v retrieving revision 1.9 retrieving revision 1.10 diff -c -r1.9 -r1.10 *** src/usr.bin/tmux/tty-acs.c 2020/04/20 13:25:36 1.9 --- src/usr.bin/tmux/tty-acs.c 2020/05/16 16:26:34 1.10 *************** *** 1,4 **** ! /* $OpenBSD: tty-acs.c,v 1.9 2020/04/20 13:25:36 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: tty-acs.c,v 1.10 2020/05/16 16:26:34 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott *************** *** 19,29 **** #include #include #include "tmux.h" - static int tty_acs_cmp(const void *, const void *); - /* Table mapping ACS entries to UTF-8. */ struct tty_acs_entry { u_char key; --- 19,28 ---- #include #include + #include #include "tmux.h" /* Table mapping ACS entries to UTF-8. */ struct tty_acs_entry { u_char key; *************** *** 68,83 **** { '~', "\302\267" } /* bullet */ }; static int tty_acs_cmp(const void *key, const void *value) { const struct tty_acs_entry *entry = value; ! u_char ch; ! ch = *(u_char *) key; ! return (ch - entry->key); } /* Should this terminal use ACS instead of UTF-8 line drawing? */ int tty_acs_needed(struct tty *tty) --- 67,133 ---- { '~', "\302\267" } /* bullet */ }; + /* Table mapping UTF-8 to ACS entries. */ + struct tty_acs_reverse_entry { + const char *string; + u_char key; + }; + static const struct tty_acs_reverse_entry tty_acs_reverse2[] = { + { "\302\267", '~' } + }; + static const struct tty_acs_reverse_entry tty_acs_reverse3[] = { + { "\342\224\200", 'q' }, + { "\342\224\201", 'q' }, + { "\342\224\202", 'x' }, + { "\342\224\203", 'x' }, + { "\342\224\214", 'l' }, + { "\342\224\217", 'k' }, + { "\342\224\220", 'k' }, + { "\342\224\223", 'l' }, + { "\342\224\224", 'm' }, + { "\342\224\227", 'm' }, + { "\342\224\230", 'j' }, + { "\342\224\233", 'j' }, + { "\342\224\234", 't' }, + { "\342\224\243", 't' }, + { "\342\224\244", 'u' }, + { "\342\224\253", 'u' }, + { "\342\224\263", 'w' }, + { "\342\224\264", 'v' }, + { "\342\224\273", 'v' }, + { "\342\224\274", 'n' }, + { "\342\225\213", 'n' }, + { "\342\225\220", 'q' }, + { "\342\225\221", 'x' }, + { "\342\225\224", 'l' }, + { "\342\225\227", 'k' }, + { "\342\225\232", 'm' }, + { "\342\225\235", 'j' }, + { "\342\225\240", 't' }, + { "\342\225\243", 'u' }, + { "\342\225\246", 'w' }, + { "\342\225\251", 'v' }, + { "\342\225\254", 'n' }, + }; + static int tty_acs_cmp(const void *key, const void *value) { const struct tty_acs_entry *entry = value; ! int test = *(u_char *)key; ! return (test - entry->key); } + static int + tty_acs_reverse_cmp(const void *key, const void *value) + { + const struct tty_acs_reverse_entry *entry = value; + const char *test = key; + + return (strcmp(test, entry->string)); + } + /* Should this terminal use ACS instead of UTF-8 line drawing? */ int tty_acs_needed(struct tty *tty) *************** *** 104,114 **** return (1); } ! /* Retrieve ACS to output as a string. */ const char * tty_acs_get(struct tty *tty, u_char ch) { ! struct tty_acs_entry *entry; /* Use the ACS set instead of UTF-8 if needed. */ if (tty_acs_needed(tty)) { --- 154,164 ---- return (1); } ! /* Retrieve ACS to output as UTF-8. */ const char * tty_acs_get(struct tty *tty, u_char ch) { ! const struct tty_acs_entry *entry; /* Use the ACS set instead of UTF-8 if needed. */ if (tty_acs_needed(tty)) { *************** *** 123,126 **** --- 173,197 ---- if (entry == NULL) return (NULL); return (entry->string); + } + + /* Reverse UTF-8 into ACS. */ + int + tty_acs_reverse_get(__unused struct tty *tty, const char *s, size_t slen) + { + const struct tty_acs_reverse_entry *table, *entry; + u_int items; + + if (slen == 2) { + table = tty_acs_reverse2; + items = nitems(tty_acs_reverse2); + } else if (slen == 3) { + table = tty_acs_reverse3; + items = nitems(tty_acs_reverse3); + } else + return (-1); + entry = bsearch(s, table, items, sizeof table[0], tty_acs_reverse_cmp); + if (entry == NULL) + return (-1); + return (entry->key); }