version 1.75, 2015/10/27 15:58:43 |
version 1.76, 2015/11/12 11:05:34 |
|
|
* into a ternary tree. |
* into a ternary tree. |
*/ |
*/ |
|
|
void tty_keys_add1(struct tty_key **, const char *, int); |
void tty_keys_add1(struct tty_key **, const char *, key_code); |
void tty_keys_add(struct tty *, const char *, int); |
void tty_keys_add(struct tty *, const char *, key_code); |
void tty_keys_free1(struct tty_key *); |
void tty_keys_free1(struct tty_key *); |
struct tty_key *tty_keys_find1( |
struct tty_key *tty_keys_find1(struct tty_key *, const char *, size_t, |
struct tty_key *, const char *, size_t, size_t *); |
size_t *); |
struct tty_key *tty_keys_find(struct tty *, const char *, size_t, size_t *); |
struct tty_key *tty_keys_find(struct tty *, const char *, size_t, size_t *); |
void tty_keys_callback(int, short, void *); |
void tty_keys_callback(int, short, void *); |
int tty_keys_mouse(struct tty *, const char *, size_t, size_t *); |
int tty_keys_mouse(struct tty *, const char *, size_t, size_t *); |
|
|
/* Default raw keys. */ |
/* Default raw keys. */ |
struct tty_default_key_raw { |
struct tty_default_key_raw { |
const char *string; |
const char *string; |
int key; |
key_code key; |
}; |
}; |
const struct tty_default_key_raw tty_default_raw_keys[] = { |
const struct tty_default_key_raw tty_default_raw_keys[] = { |
/* |
/* |
|
|
/* Default terminfo(5) keys. */ |
/* Default terminfo(5) keys. */ |
struct tty_default_key_code { |
struct tty_default_key_code { |
enum tty_code_code code; |
enum tty_code_code code; |
int key; |
key_code key; |
}; |
}; |
const struct tty_default_key_code tty_default_code_keys[] = { |
const struct tty_default_key_code tty_default_code_keys[] = { |
/* Function keys. */ |
/* Function keys. */ |
|
|
|
|
/* Add key to tree. */ |
/* Add key to tree. */ |
void |
void |
tty_keys_add(struct tty *tty, const char *s, int key) |
tty_keys_add(struct tty *tty, const char *s, key_code key) |
{ |
{ |
struct tty_key *tk; |
struct tty_key *tk; |
size_t size; |
size_t size; |
|
|
|
|
keystr = key_string_lookup_key(key); |
keystr = key_string_lookup_key(key); |
if ((tk = tty_keys_find(tty, s, strlen(s), &size)) == NULL) { |
if ((tk = tty_keys_find(tty, s, strlen(s), &size)) == NULL) { |
log_debug("new key %s: 0x%x (%s)", s, key, keystr); |
log_debug("new key %s: 0x%llx (%s)", s, key, keystr); |
tty_keys_add1(&tty->key_tree, s, key); |
tty_keys_add1(&tty->key_tree, s, key); |
} else { |
} else { |
log_debug("replacing key %s: 0x%x (%s)", s, key, keystr); |
log_debug("replacing key %s: 0x%llx (%s)", s, key, keystr); |
tk->key = key; |
tk->key = key; |
} |
} |
} |
} |
|
|
/* Add next node to the tree. */ |
/* Add next node to the tree. */ |
void |
void |
tty_keys_add1(struct tty_key **tkp, const char *s, int key) |
tty_keys_add1(struct tty_key **tkp, const char *s, key_code key) |
{ |
{ |
struct tty_key *tk; |
struct tty_key *tk; |
|
|
|
|
* Process at least one key in the buffer and invoke tty->key_callback. Return |
* Process at least one key in the buffer and invoke tty->key_callback. Return |
* 0 if there are no further keys, or 1 if there could be more in the buffer. |
* 0 if there are no further keys, or 1 if there could be more in the buffer. |
*/ |
*/ |
int |
key_code |
tty_keys_next(struct tty *tty) |
tty_keys_next(struct tty *tty) |
{ |
{ |
struct tty_key *tk; |
struct tty_key *tk; |
struct timeval tv; |
struct timeval tv; |
const char *buf; |
const char *buf; |
size_t len, size; |
size_t len, size; |
cc_t bspace; |
cc_t bspace; |
int key, delay, expired = 0; |
int delay, expired = 0; |
|
key_code key; |
|
struct utf8_data utf8data; |
|
u_int i; |
|
|
/* Get key buffer. */ |
/* Get key buffer. */ |
buf = EVBUFFER_DATA(tty->event->input); |
buf = EVBUFFER_DATA(tty->event->input); |
|
|
} |
} |
} |
} |
|
|
|
/* Is this valid UTF-8? */ |
|
if (utf8_open(&utf8data, (u_char)*buf)) { |
|
size = utf8data.size; |
|
if (len < size) { |
|
if (expired) |
|
goto discard_key; |
|
goto partial_key; |
|
} |
|
for (i = 1; i < size; i++) |
|
utf8_append(&utf8data, (u_char)buf[i]); |
|
key = utf8_combine(&utf8data); |
|
log_debug("UTF-8 key %.*s %#llx", (int)size, buf, key); |
|
goto complete_key; |
|
} |
|
|
/* No key found, take first. */ |
/* No key found, take first. */ |
key = (u_char) *buf; |
key = (u_char)*buf; |
size = 1; |
size = 1; |
|
|
/* |
/* |
|
|
return (0); |
return (0); |
|
|
complete_key: |
complete_key: |
log_debug("complete key %.*s %#x", (int) size, buf, key); |
log_debug("complete key %.*s %#llx", (int)size, buf, key); |
|
|
/* Remove data from buffer. */ |
/* Remove data from buffer. */ |
evbuffer_drain(tty->event->input, size); |
evbuffer_drain(tty->event->input, size); |
|
|
return (1); |
return (1); |
|
|
discard_key: |
discard_key: |
log_debug("discard key %.*s %#x", (int) size, buf, key); |
log_debug("discard key %.*s %#llx", (int)size, buf, key); |
|
|
/* Remove data from buffer. */ |
/* Remove data from buffer. */ |
evbuffer_drain(tty->event->input, size); |
evbuffer_drain(tty->event->input, size); |
|
|
utf8_append(&utf8data, buf[*size]); |
utf8_append(&utf8data, buf[*size]); |
value = utf8_combine(&utf8data); |
value = utf8_combine(&utf8data); |
} else |
} else |
value = (u_char) buf[*size]; |
value = (u_char)buf[*size]; |
(*size)++; |
(*size)++; |
} else { |
} else { |
value = (u_char) buf[*size]; |
value = (u_char)buf[*size]; |
(*size)++; |
(*size)++; |
} |
} |
|
|