mirror of
https://github.com/tmux/tmux.git
synced 2024-11-18 10:28:54 +00:00
Merge branch 'obsd-master'
This commit is contained in:
commit
a7027ed8e5
10
input-keys.c
10
input-keys.c
@ -143,7 +143,7 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
|
|||||||
size_t dlen;
|
size_t dlen;
|
||||||
char *out;
|
char *out;
|
||||||
key_code justkey;
|
key_code justkey;
|
||||||
struct utf8_data utf8data;
|
struct utf8_data ud;
|
||||||
|
|
||||||
log_debug("writing key 0x%llx (%s) to %%%u", key,
|
log_debug("writing key 0x%llx (%s) to %%%u", key,
|
||||||
key_string_lookup_key(key), wp->id);
|
key_string_lookup_key(key), wp->id);
|
||||||
@ -163,16 +163,16 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
|
|||||||
if (key != KEYC_NONE && justkey < 0x7f) {
|
if (key != KEYC_NONE && justkey < 0x7f) {
|
||||||
if (key & KEYC_ESCAPE)
|
if (key & KEYC_ESCAPE)
|
||||||
bufferevent_write(wp->event, "\033", 1);
|
bufferevent_write(wp->event, "\033", 1);
|
||||||
utf8data.data[0] = justkey;
|
ud.data[0] = justkey;
|
||||||
bufferevent_write(wp->event, &utf8data.data[0], 1);
|
bufferevent_write(wp->event, &ud.data[0], 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (key != KEYC_NONE && justkey > 0x7f && justkey < KEYC_BASE) {
|
if (key != KEYC_NONE && justkey > 0x7f && justkey < KEYC_BASE) {
|
||||||
if (utf8_split(justkey, &utf8data) != 0)
|
if (utf8_split(justkey, &ud) != 0)
|
||||||
return;
|
return;
|
||||||
if (key & KEYC_ESCAPE)
|
if (key & KEYC_ESCAPE)
|
||||||
bufferevent_write(wp->event, "\033", 1);
|
bufferevent_write(wp->event, "\033", 1);
|
||||||
bufferevent_write(wp->event, utf8data.data, utf8data.size);
|
bufferevent_write(wp->event, ud.data, ud.size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
key-string.c
20
key-string.c
@ -146,7 +146,7 @@ key_string_lookup_string(const char *string)
|
|||||||
u_short u;
|
u_short u;
|
||||||
int size;
|
int size;
|
||||||
key_code modifiers;
|
key_code modifiers;
|
||||||
struct utf8_data utf8data;
|
struct utf8_data ud;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
/* Is this a hexadecimal value? */
|
/* Is this a hexadecimal value? */
|
||||||
@ -173,12 +173,12 @@ key_string_lookup_string(const char *string)
|
|||||||
return (KEYC_NONE);
|
return (KEYC_NONE);
|
||||||
} else {
|
} else {
|
||||||
/* Try as a UTF-8 key. */
|
/* Try as a UTF-8 key. */
|
||||||
if (utf8_open(&utf8data, (u_char)*string)) {
|
if (utf8_open(&ud, (u_char)*string)) {
|
||||||
if (strlen(string) != utf8data.size)
|
if (strlen(string) != ud.size)
|
||||||
return (KEYC_NONE);
|
return (KEYC_NONE);
|
||||||
for (i = 1; i < utf8data.size; i++)
|
for (i = 1; i < ud.size; i++)
|
||||||
utf8_append(&utf8data, (u_char)string[i]);
|
utf8_append(&ud, (u_char)string[i]);
|
||||||
key = utf8_combine(&utf8data);
|
key = utf8_combine(&ud);
|
||||||
return (key | modifiers);
|
return (key | modifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +213,7 @@ key_string_lookup_key(key_code key)
|
|||||||
static char out[24];
|
static char out[24];
|
||||||
char tmp[8];
|
char tmp[8];
|
||||||
u_int i;
|
u_int i;
|
||||||
struct utf8_data utf8data;
|
struct utf8_data ud;
|
||||||
|
|
||||||
*out = '\0';
|
*out = '\0';
|
||||||
|
|
||||||
@ -253,9 +253,9 @@ key_string_lookup_key(key_code key)
|
|||||||
|
|
||||||
/* Is this a UTF-8 key? */
|
/* Is this a UTF-8 key? */
|
||||||
if (key > 127 && key < KEYC_BASE) {
|
if (key > 127 && key < KEYC_BASE) {
|
||||||
if (utf8_split(key, &utf8data) == 0) {
|
if (utf8_split(key, &ud) == 0) {
|
||||||
memcpy(out, utf8data.data, utf8data.size);
|
memcpy(out, ud.data, ud.size);
|
||||||
out[utf8data.size] = '\0';
|
out[ud.size] = '\0';
|
||||||
return (out);
|
return (out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ screen_write_strlen(const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char *msg;
|
char *msg;
|
||||||
struct utf8_data utf8data;
|
struct utf8_data ud;
|
||||||
u_char *ptr;
|
u_char *ptr;
|
||||||
size_t left, size = 0;
|
size_t left, size = 0;
|
||||||
|
|
||||||
@ -122,17 +122,17 @@ screen_write_strlen(const char *fmt, ...)
|
|||||||
|
|
||||||
ptr = msg;
|
ptr = msg;
|
||||||
while (*ptr != '\0') {
|
while (*ptr != '\0') {
|
||||||
if (*ptr > 0x7f && utf8_open(&utf8data, *ptr)) {
|
if (*ptr > 0x7f && utf8_open(&ud, *ptr)) {
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
left = strlen(ptr);
|
left = strlen(ptr);
|
||||||
if (left < utf8data.size - 1)
|
if (left < ud.size - 1)
|
||||||
break;
|
break;
|
||||||
while (utf8_append(&utf8data, *ptr))
|
while (utf8_append(&ud, *ptr))
|
||||||
ptr++;
|
ptr++;
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
size += utf8data.width;
|
size += ud.width;
|
||||||
} else {
|
} else {
|
||||||
if (*ptr > 0x1f && *ptr < 0x7f)
|
if (*ptr > 0x1f && *ptr < 0x7f)
|
||||||
size++;
|
size++;
|
||||||
@ -173,7 +173,7 @@ screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
|
|||||||
struct grid_cell *gc, const char *fmt, va_list ap)
|
struct grid_cell *gc, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
char *msg;
|
char *msg;
|
||||||
struct utf8_data utf8data;
|
struct utf8_data ud;
|
||||||
u_char *ptr;
|
u_char *ptr;
|
||||||
size_t left, size = 0;
|
size_t left, size = 0;
|
||||||
|
|
||||||
@ -181,27 +181,27 @@ screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
|
|||||||
|
|
||||||
ptr = msg;
|
ptr = msg;
|
||||||
while (*ptr != '\0') {
|
while (*ptr != '\0') {
|
||||||
if (*ptr > 0x7f && utf8_open(&utf8data, *ptr)) {
|
if (*ptr > 0x7f && utf8_open(&ud, *ptr)) {
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
left = strlen(ptr);
|
left = strlen(ptr);
|
||||||
if (left < utf8data.size - 1)
|
if (left < ud.size - 1)
|
||||||
break;
|
break;
|
||||||
while (utf8_append(&utf8data, *ptr))
|
while (utf8_append(&ud, *ptr))
|
||||||
ptr++;
|
ptr++;
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
if (maxlen > 0 &&
|
if (maxlen > 0 &&
|
||||||
size + utf8data.width > (size_t) maxlen) {
|
size + ud.width > (size_t) maxlen) {
|
||||||
while (size < (size_t) maxlen) {
|
while (size < (size_t) maxlen) {
|
||||||
screen_write_putc(ctx, gc, ' ');
|
screen_write_putc(ctx, gc, ' ');
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
size += utf8data.width;
|
size += ud.width;
|
||||||
|
|
||||||
grid_cell_set(gc, &utf8data);
|
grid_cell_set(gc, &ud);
|
||||||
screen_write_cell(ctx, gc);
|
screen_write_cell(ctx, gc);
|
||||||
} else {
|
} else {
|
||||||
if (maxlen > 0 && size + 1 > (size_t) maxlen)
|
if (maxlen > 0 && size + 1 > (size_t) maxlen)
|
||||||
@ -226,7 +226,7 @@ screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
|
|||||||
struct grid_cell *gc, const char *fmt, ...)
|
struct grid_cell *gc, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
struct grid_cell lgc;
|
struct grid_cell lgc;
|
||||||
struct utf8_data utf8data;
|
struct utf8_data ud;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char *msg;
|
char *msg;
|
||||||
u_char *ptr, *last;
|
u_char *ptr, *last;
|
||||||
@ -254,27 +254,27 @@ screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ptr > 0x7f && utf8_open(&utf8data, *ptr)) {
|
if (*ptr > 0x7f && utf8_open(&ud, *ptr)) {
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
left = strlen(ptr);
|
left = strlen(ptr);
|
||||||
if (left < utf8data.size - 1)
|
if (left < ud.size - 1)
|
||||||
break;
|
break;
|
||||||
while (utf8_append(&utf8data, *ptr))
|
while (utf8_append(&ud, *ptr))
|
||||||
ptr++;
|
ptr++;
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
if (maxlen > 0 &&
|
if (maxlen > 0 &&
|
||||||
size + utf8data.width > (size_t) maxlen) {
|
size + ud.width > (size_t) maxlen) {
|
||||||
while (size < (size_t) maxlen) {
|
while (size < (size_t) maxlen) {
|
||||||
screen_write_putc(ctx, gc, ' ');
|
screen_write_putc(ctx, gc, ' ');
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
size += utf8data.width;
|
size += ud.width;
|
||||||
|
|
||||||
grid_cell_set(&lgc, &utf8data);
|
grid_cell_set(&lgc, &ud);
|
||||||
screen_write_cell(ctx, &lgc);
|
screen_write_cell(ctx, &lgc);
|
||||||
} else {
|
} else {
|
||||||
if (maxlen > 0 && size + 1 > (size_t) maxlen)
|
if (maxlen > 0 && size + 1 > (size_t) maxlen)
|
||||||
|
20
tty-keys.c
20
tty-keys.c
@ -474,7 +474,7 @@ tty_keys_next(struct tty *tty)
|
|||||||
cc_t bspace;
|
cc_t bspace;
|
||||||
int delay, expired = 0;
|
int delay, expired = 0;
|
||||||
key_code key;
|
key_code key;
|
||||||
struct utf8_data utf8data;
|
struct utf8_data ud;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
/* Get key buffer. */
|
/* Get key buffer. */
|
||||||
@ -539,16 +539,16 @@ first_key:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Is this valid UTF-8? */
|
/* Is this valid UTF-8? */
|
||||||
if (utf8_open(&utf8data, (u_char)*buf)) {
|
if (utf8_open(&ud, (u_char)*buf)) {
|
||||||
size = utf8data.size;
|
size = ud.size;
|
||||||
if (len < size) {
|
if (len < size) {
|
||||||
if (expired)
|
if (expired)
|
||||||
goto discard_key;
|
goto discard_key;
|
||||||
goto partial_key;
|
goto partial_key;
|
||||||
}
|
}
|
||||||
for (i = 1; i < size; i++)
|
for (i = 1; i < size; i++)
|
||||||
utf8_append(&utf8data, (u_char)buf[i]);
|
utf8_append(&ud, (u_char)buf[i]);
|
||||||
key = utf8_combine(&utf8data);
|
key = utf8_combine(&ud);
|
||||||
log_debug("UTF-8 key %.*s %#llx", (int)size, buf, key);
|
log_debug("UTF-8 key %.*s %#llx", (int)size, buf, key);
|
||||||
goto complete_key;
|
goto complete_key;
|
||||||
}
|
}
|
||||||
@ -650,7 +650,7 @@ int
|
|||||||
tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
|
tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
|
||||||
{
|
{
|
||||||
struct mouse_event *m = &tty->mouse;
|
struct mouse_event *m = &tty->mouse;
|
||||||
struct utf8_data utf8data;
|
struct utf8_data ud;
|
||||||
u_int i, value, x, y, b, sgr_b;
|
u_int i, value, x, y, b, sgr_b;
|
||||||
u_char sgr_type, c;
|
u_char sgr_type, c;
|
||||||
|
|
||||||
@ -693,14 +693,14 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
|
|||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
if (tty->mode & MODE_MOUSE_UTF8) {
|
if (tty->mode & MODE_MOUSE_UTF8) {
|
||||||
if (utf8_open(&utf8data, buf[*size])) {
|
if (utf8_open(&ud, buf[*size])) {
|
||||||
if (utf8data.size != 2)
|
if (ud.size != 2)
|
||||||
return (-1);
|
return (-1);
|
||||||
(*size)++;
|
(*size)++;
|
||||||
if (len <= *size)
|
if (len <= *size)
|
||||||
return (1);
|
return (1);
|
||||||
utf8_append(&utf8data, buf[*size]);
|
utf8_append(&ud, buf[*size]);
|
||||||
value = utf8_combine(&utf8data);
|
value = utf8_combine(&ud);
|
||||||
} else
|
} else
|
||||||
value = (u_char)buf[*size];
|
value = (u_char)buf[*size];
|
||||||
(*size)++;
|
(*size)++;
|
||||||
|
114
utf8.c
114
utf8.c
@ -349,12 +349,12 @@ static void utf8_build(void);
|
|||||||
|
|
||||||
/* Set a single character. */
|
/* Set a single character. */
|
||||||
void
|
void
|
||||||
utf8_set(struct utf8_data *utf8data, u_char ch)
|
utf8_set(struct utf8_data *ud, u_char ch)
|
||||||
{
|
{
|
||||||
*utf8data->data = ch;
|
*ud->data = ch;
|
||||||
utf8data->size = 1;
|
ud->size = 1;
|
||||||
|
|
||||||
utf8data->width = 1;
|
ud->width = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -367,18 +367,18 @@ utf8_set(struct utf8_data *utf8data, u_char ch)
|
|||||||
* Returns 1 if more UTF-8 to come, 0 if not UTF-8.
|
* Returns 1 if more UTF-8 to come, 0 if not UTF-8.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
utf8_open(struct utf8_data *utf8data, u_char ch)
|
utf8_open(struct utf8_data *ud, u_char ch)
|
||||||
{
|
{
|
||||||
memset(utf8data, 0, sizeof *utf8data);
|
memset(ud, 0, sizeof *ud);
|
||||||
if (ch >= 0xc2 && ch <= 0xdf)
|
if (ch >= 0xc2 && ch <= 0xdf)
|
||||||
utf8data->size = 2;
|
ud->size = 2;
|
||||||
else if (ch >= 0xe0 && ch <= 0xef)
|
else if (ch >= 0xe0 && ch <= 0xef)
|
||||||
utf8data->size = 3;
|
ud->size = 3;
|
||||||
else if (ch >= 0xf0 && ch <= 0xf4)
|
else if (ch >= 0xf0 && ch <= 0xf4)
|
||||||
utf8data->size = 4;
|
ud->size = 4;
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
utf8_append(utf8data, ch);
|
utf8_append(ud, ch);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,20 +388,20 @@ utf8_open(struct utf8_data *utf8data, u_char ch)
|
|||||||
* Returns 1 if more UTF-8 data to come, 0 if finished.
|
* Returns 1 if more UTF-8 data to come, 0 if finished.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
utf8_append(struct utf8_data *utf8data, u_char ch)
|
utf8_append(struct utf8_data *ud, u_char ch)
|
||||||
{
|
{
|
||||||
/* XXX this should do validity checks too! */
|
/* XXX this should do validity checks too! */
|
||||||
|
|
||||||
if (utf8data->have >= utf8data->size)
|
if (ud->have >= ud->size)
|
||||||
fatalx("UTF-8 character overflow");
|
fatalx("UTF-8 character overflow");
|
||||||
if (utf8data->size > sizeof utf8data->data)
|
if (ud->size > sizeof ud->data)
|
||||||
fatalx("UTF-8 character size too large");
|
fatalx("UTF-8 character size too large");
|
||||||
|
|
||||||
utf8data->data[utf8data->have++] = ch;
|
ud->data[ud->have++] = ch;
|
||||||
if (utf8data->have != utf8data->size)
|
if (ud->have != ud->size)
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
utf8data->width = utf8_width(utf8_combine(utf8data));
|
ud->width = utf8_width(utf8_combine(ud));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,29 +450,29 @@ utf8_width(u_int uc)
|
|||||||
|
|
||||||
/* Combine UTF-8 into 32-bit Unicode. */
|
/* Combine UTF-8 into 32-bit Unicode. */
|
||||||
u_int
|
u_int
|
||||||
utf8_combine(const struct utf8_data *utf8data)
|
utf8_combine(const struct utf8_data *ud)
|
||||||
{
|
{
|
||||||
u_int value;
|
u_int value;
|
||||||
|
|
||||||
value = 0xff;
|
value = 0xff;
|
||||||
switch (utf8data->size) {
|
switch (ud->size) {
|
||||||
case 1:
|
case 1:
|
||||||
value = utf8data->data[0];
|
value = ud->data[0];
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
value = utf8data->data[1] & 0x3f;
|
value = ud->data[1] & 0x3f;
|
||||||
value |= (utf8data->data[0] & 0x1f) << 6;
|
value |= (ud->data[0] & 0x1f) << 6;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
value = utf8data->data[2] & 0x3f;
|
value = ud->data[2] & 0x3f;
|
||||||
value |= (utf8data->data[1] & 0x3f) << 6;
|
value |= (ud->data[1] & 0x3f) << 6;
|
||||||
value |= (utf8data->data[0] & 0xf) << 12;
|
value |= (ud->data[0] & 0xf) << 12;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
value = utf8data->data[3] & 0x3f;
|
value = ud->data[3] & 0x3f;
|
||||||
value |= (utf8data->data[2] & 0x3f) << 6;
|
value |= (ud->data[2] & 0x3f) << 6;
|
||||||
value |= (utf8data->data[1] & 0x3f) << 12;
|
value |= (ud->data[1] & 0x3f) << 12;
|
||||||
value |= (utf8data->data[0] & 0x7) << 18;
|
value |= (ud->data[0] & 0x7) << 18;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return (value);
|
return (value);
|
||||||
@ -480,29 +480,29 @@ utf8_combine(const struct utf8_data *utf8data)
|
|||||||
|
|
||||||
/* Split 32-bit Unicode into UTF-8. */
|
/* Split 32-bit Unicode into UTF-8. */
|
||||||
int
|
int
|
||||||
utf8_split(u_int uc, struct utf8_data *utf8data)
|
utf8_split(u_int uc, struct utf8_data *ud)
|
||||||
{
|
{
|
||||||
if (uc < 0x7f) {
|
if (uc < 0x7f) {
|
||||||
utf8data->size = 1;
|
ud->size = 1;
|
||||||
utf8data->data[0] = uc;
|
ud->data[0] = uc;
|
||||||
} else if (uc < 0x7ff) {
|
} else if (uc < 0x7ff) {
|
||||||
utf8data->size = 2;
|
ud->size = 2;
|
||||||
utf8data->data[0] = 0xc0 | ((uc >> 6) & 0x1f);
|
ud->data[0] = 0xc0 | ((uc >> 6) & 0x1f);
|
||||||
utf8data->data[1] = 0x80 | (uc & 0x3f);
|
ud->data[1] = 0x80 | (uc & 0x3f);
|
||||||
} else if (uc < 0xffff) {
|
} else if (uc < 0xffff) {
|
||||||
utf8data->size = 3;
|
ud->size = 3;
|
||||||
utf8data->data[0] = 0xe0 | ((uc >> 12) & 0xf);
|
ud->data[0] = 0xe0 | ((uc >> 12) & 0xf);
|
||||||
utf8data->data[1] = 0x80 | ((uc >> 6) & 0x3f);
|
ud->data[1] = 0x80 | ((uc >> 6) & 0x3f);
|
||||||
utf8data->data[2] = 0x80 | (uc & 0x3f);
|
ud->data[2] = 0x80 | (uc & 0x3f);
|
||||||
} else if (uc < 0x1fffff) {
|
} else if (uc < 0x1fffff) {
|
||||||
utf8data->size = 4;
|
ud->size = 4;
|
||||||
utf8data->data[0] = 0xf0 | ((uc >> 18) & 0x7);
|
ud->data[0] = 0xf0 | ((uc >> 18) & 0x7);
|
||||||
utf8data->data[1] = 0x80 | ((uc >> 12) & 0x3f);
|
ud->data[1] = 0x80 | ((uc >> 12) & 0x3f);
|
||||||
utf8data->data[2] = 0x80 | ((uc >> 6) & 0x3f);
|
ud->data[2] = 0x80 | ((uc >> 6) & 0x3f);
|
||||||
utf8data->data[3] = 0x80 | (uc & 0x3f);
|
ud->data[3] = 0x80 | (uc & 0x3f);
|
||||||
} else
|
} else
|
||||||
return (-1);
|
return (-1);
|
||||||
utf8data->width = utf8_width(uc);
|
ud->width = utf8_width(uc);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +527,7 @@ utf8_split2(u_int uc, u_char *ptr)
|
|||||||
int
|
int
|
||||||
utf8_strvis(char *dst, const char *src, size_t len, int flag)
|
utf8_strvis(char *dst, const char *src, size_t len, int flag)
|
||||||
{
|
{
|
||||||
struct utf8_data utf8data;
|
struct utf8_data ud;
|
||||||
const char *start, *end;
|
const char *start, *end;
|
||||||
int more;
|
int more;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -536,18 +536,18 @@ utf8_strvis(char *dst, const char *src, size_t len, int flag)
|
|||||||
end = src + len;
|
end = src + len;
|
||||||
|
|
||||||
while (src < end) {
|
while (src < end) {
|
||||||
if (utf8_open(&utf8data, *src)) {
|
if (utf8_open(&ud, *src)) {
|
||||||
more = 1;
|
more = 1;
|
||||||
while (++src < end && more)
|
while (++src < end && more)
|
||||||
more = utf8_append(&utf8data, *src);
|
more = utf8_append(&ud, *src);
|
||||||
if (!more) {
|
if (!more) {
|
||||||
/* UTF-8 character finished. */
|
/* UTF-8 character finished. */
|
||||||
for (i = 0; i < utf8data.size; i++)
|
for (i = 0; i < ud.size; i++)
|
||||||
*dst++ = utf8data.data[i];
|
*dst++ = ud.data[i];
|
||||||
continue;
|
continue;
|
||||||
} else if (utf8data.have > 0) {
|
} else if (ud.have > 0) {
|
||||||
/* Not a complete UTF-8 character. */
|
/* Not a complete UTF-8 character. */
|
||||||
src -= utf8data.have;
|
src -= ud.have;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (src < end - 1)
|
if (src < end - 1)
|
||||||
@ -572,7 +572,7 @@ utf8_sanitize(const char *src)
|
|||||||
char *dst;
|
char *dst;
|
||||||
size_t n;
|
size_t n;
|
||||||
int more;
|
int more;
|
||||||
struct utf8_data utf8data;
|
struct utf8_data ud;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
dst = NULL;
|
dst = NULL;
|
||||||
@ -580,18 +580,18 @@ utf8_sanitize(const char *src)
|
|||||||
n = 0;
|
n = 0;
|
||||||
while (*src != '\0') {
|
while (*src != '\0') {
|
||||||
dst = xreallocarray(dst, n + 1, sizeof *dst);
|
dst = xreallocarray(dst, n + 1, sizeof *dst);
|
||||||
if (utf8_open(&utf8data, *src)) {
|
if (utf8_open(&ud, *src)) {
|
||||||
more = 1;
|
more = 1;
|
||||||
while (*++src != '\0' && more)
|
while (*++src != '\0' && more)
|
||||||
more = utf8_append(&utf8data, *src);
|
more = utf8_append(&ud, *src);
|
||||||
if (!more) {
|
if (!more) {
|
||||||
dst = xreallocarray(dst, n + utf8data.width,
|
dst = xreallocarray(dst, n + ud.width,
|
||||||
sizeof *dst);
|
sizeof *dst);
|
||||||
for (i = 0; i < utf8data.width; i++)
|
for (i = 0; i < ud.width; i++)
|
||||||
dst[n++] = '_';
|
dst[n++] = '_';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
src -= utf8data.have;
|
src -= ud.have;
|
||||||
}
|
}
|
||||||
if (*src > 0x1f && *src < 0x7f)
|
if (*src > 0x1f && *src < 0x7f)
|
||||||
dst[n] = *src;
|
dst[n] = *src;
|
||||||
|
Loading…
Reference in New Issue
Block a user