#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
struct tty_acs_entry {
u_char key;
const char *string;
};
static const struct tty_acs_entry tty_acs_table[] = {
{ '+', "\342\206\222" },
{ ',', "\342\206\220" },
{ '-', "\342\206\221" },
{ '.', "\342\206\223" },
{ '0', "\342\226\256" },
{ '`', "\342\227\206" },
{ 'a', "\342\226\222" },
{ 'b', "\342\220\211" },
{ 'c', "\342\220\214" },
{ 'd', "\342\220\215" },
{ 'e', "\342\220\212" },
{ 'f', "\302\260" },
{ 'g', "\302\261" },
{ 'h', "\342\220\244" },
{ 'i', "\342\220\213" },
{ 'j', "\342\224\230" },
{ 'k', "\342\224\220" },
{ 'l', "\342\224\214" },
{ 'm', "\342\224\224" },
{ 'n', "\342\224\274" },
{ 'o', "\342\216\272" },
{ 'p', "\342\216\273" },
{ 'q', "\342\224\200" },
{ 'r', "\342\216\274" },
{ 's', "\342\216\275" },
{ 't', "\342\224\234" },
{ 'u', "\342\224\244" },
{ 'v', "\342\224\264" },
{ 'w', "\342\224\254" },
{ 'x', "\342\224\202" },
{ 'y', "\342\211\244" },
{ 'z', "\342\211\245" },
{ '{', "\317\200" },
{ '|', "\342\211\240" },
{ '}', "\302\243" },
{ '~', "\302\267" }
};
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 const struct utf8_data tty_acs_double_borders_list[] = {
{ "", 0, 0, 0 },
{ "\342\225\221", 0, 3, 1 },
{ "\342\225\220", 0, 3, 1 },
{ "\342\225\224", 0, 3, 1 },
{ "\342\225\227", 0, 3, 1 },
{ "\342\225\232", 0, 3, 1 },
{ "\342\225\235", 0, 3, 1 },
{ "\342\225\246", 0, 3, 1 },
{ "\342\225\251", 0, 3, 1 },
{ "\342\225\240", 0, 3, 1 },
{ "\342\225\243", 0, 3, 1 },
{ "\342\225\254", 0, 3, 1 },
{ "\302\267", 0, 2, 1 }
};
static const struct utf8_data tty_acs_heavy_borders_list[] = {
{ "", 0, 0, 0 },
{ "\342\224\203", 0, 3, 1 },
{ "\342\224\201", 0, 3, 1 },
{ "\342\224\217", 0, 3, 1 },
{ "\342\224\223", 0, 3, 1 },
{ "\342\224\227", 0, 3, 1 },
{ "\342\224\233", 0, 3, 1 },
{ "\342\224\263", 0, 3, 1 },
{ "\342\224\273", 0, 3, 1 },
{ "\342\224\243", 0, 3, 1 },
{ "\342\224\253", 0, 3, 1 },
{ "\342\225\213", 0, 3, 1 },
{ "\302\267", 0, 2, 1 }
};
static const struct utf8_data tty_acs_rounded_borders_list[] = {
{ "", 0, 0, 0 },
{ "\342\224\202", 0, 3, 1 },
{ "\342\224\200", 0, 3, 1 },
{ "\342\225\255", 0, 3, 1 },
{ "\342\225\256", 0, 3, 1 },
{ "\342\225\260", 0, 3, 1 },
{ "\342\225\257", 0, 3, 1 },
{ "\342\224\263", 0, 3, 1 },
{ "\342\224\273", 0, 3, 1 },
{ "\342\224\234", 0, 3, 1 },
{ "\342\224\244", 0, 3, 1 },
{ "\342\225\213", 0, 3, 1 },
{ "\302\267", 0, 2, 1 }
};
const struct utf8_data *
tty_acs_double_borders(int cell_type)
{
return (&tty_acs_double_borders_list[cell_type]);
}
const struct utf8_data *
tty_acs_heavy_borders(int cell_type)
{
return (&tty_acs_heavy_borders_list[cell_type]);
}
const struct utf8_data *
tty_acs_rounded_borders(int cell_type)
{
return (&tty_acs_rounded_borders_list[cell_type]);
}
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));
}
int
tty_acs_needed(struct tty *tty)
{
if (tty == NULL)
return (0);
if (tty_term_has(tty->term, TTYC_U8) &&
tty_term_number(tty->term, TTYC_U8) == 0)
return (1);
if (tty->client->flags & CLIENT_UTF8)
return (0);
return (1);
}
const char *
tty_acs_get(struct tty *tty, u_char ch)
{
const struct tty_acs_entry *entry;
if (tty_acs_needed(tty)) {
if (tty->term->acs[ch][0] == '\0')
return (NULL);
return (&tty->term->acs[ch][0]);
}
entry = bsearch(&ch, tty_acs_table, nitems(tty_acs_table),
sizeof tty_acs_table[0], tty_acs_cmp);
if (entry == NULL)
return (NULL);
return (entry->string);
}
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);
}