From e71a9154126c7ee853b9a657678de40d475279eb Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 12 Nov 2015 22:04:37 +0000 Subject: [PATCH] Rename overly-long utf8data to ud throughout. --- input-keys.c | 10 ++--- key-string.c | 20 ++++----- screen-write.c | 38 ++++++++--------- tty-keys.c | 20 ++++----- utf8.c | 114 ++++++++++++++++++++++++------------------------- 5 files changed, 101 insertions(+), 101 deletions(-) diff --git a/input-keys.c b/input-keys.c index a761a088..3938c185 100644 --- a/input-keys.c +++ b/input-keys.c @@ -144,7 +144,7 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m) size_t dlen; char *out; key_code justkey; - struct utf8_data utf8data; + struct utf8_data ud; log_debug("writing key 0x%llx (%s) to %%%u", key, key_string_lookup_key(key), wp->id); @@ -164,16 +164,16 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m) if (key != KEYC_NONE && justkey < 0x7f) { if (key & KEYC_ESCAPE) bufferevent_write(wp->event, "\033", 1); - utf8data.data[0] = justkey; - bufferevent_write(wp->event, &utf8data.data[0], 1); + ud.data[0] = justkey; + bufferevent_write(wp->event, &ud.data[0], 1); return; } if (key != KEYC_NONE && justkey > 0x7f && justkey < KEYC_BASE) { - if (utf8_split(justkey, &utf8data) != 0) + if (utf8_split(justkey, &ud) != 0) return; if (key & KEYC_ESCAPE) bufferevent_write(wp->event, "\033", 1); - bufferevent_write(wp->event, utf8data.data, utf8data.size); + bufferevent_write(wp->event, ud.data, ud.size); return; } diff --git a/key-string.c b/key-string.c index 4285e129..c2230218 100644 --- a/key-string.c +++ b/key-string.c @@ -146,7 +146,7 @@ key_string_lookup_string(const char *string) u_short u; int size; key_code modifiers; - struct utf8_data utf8data; + struct utf8_data ud; u_int i; /* Is this a hexadecimal value? */ @@ -173,12 +173,12 @@ key_string_lookup_string(const char *string) return (KEYC_NONE); } else { /* Try as a UTF-8 key. */ - if (utf8_open(&utf8data, (u_char)*string)) { - if (strlen(string) != utf8data.size) + if (utf8_open(&ud, (u_char)*string)) { + if (strlen(string) != ud.size) return (KEYC_NONE); - for (i = 1; i < utf8data.size; i++) - utf8_append(&utf8data, (u_char)string[i]); - key = utf8_combine(&utf8data); + for (i = 1; i < ud.size; i++) + utf8_append(&ud, (u_char)string[i]); + key = utf8_combine(&ud); return (key | modifiers); } @@ -213,7 +213,7 @@ key_string_lookup_key(key_code key) static char out[24]; char tmp[8]; u_int i; - struct utf8_data utf8data; + struct utf8_data ud; *out = '\0'; @@ -253,9 +253,9 @@ key_string_lookup_key(key_code key) /* 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'; + if (utf8_split(key, &ud) == 0) { + memcpy(out, ud.data, ud.size); + out[ud.size] = '\0'; return (out); } } diff --git a/screen-write.c b/screen-write.c index 6286d21f..4bf3ec72 100644 --- a/screen-write.c +++ b/screen-write.c @@ -112,7 +112,7 @@ screen_write_strlen(const char *fmt, ...) { va_list ap; char *msg; - struct utf8_data utf8data; + struct utf8_data ud; u_char *ptr; size_t left, size = 0; @@ -122,17 +122,17 @@ screen_write_strlen(const char *fmt, ...) ptr = msg; while (*ptr != '\0') { - if (*ptr > 0x7f && utf8_open(&utf8data, *ptr)) { + if (*ptr > 0x7f && utf8_open(&ud, *ptr)) { ptr++; left = strlen(ptr); - if (left < utf8data.size - 1) + if (left < ud.size - 1) break; - while (utf8_append(&utf8data, *ptr)) + while (utf8_append(&ud, *ptr)) ptr++; ptr++; - size += utf8data.width; + size += ud.width; } else { if (*ptr > 0x1f && *ptr < 0x7f) 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) { char *msg; - struct utf8_data utf8data; + struct utf8_data ud; u_char *ptr; size_t left, size = 0; @@ -181,27 +181,27 @@ screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen, ptr = msg; while (*ptr != '\0') { - if (*ptr > 0x7f && utf8_open(&utf8data, *ptr)) { + if (*ptr > 0x7f && utf8_open(&ud, *ptr)) { ptr++; left = strlen(ptr); - if (left < utf8data.size - 1) + if (left < ud.size - 1) break; - while (utf8_append(&utf8data, *ptr)) + while (utf8_append(&ud, *ptr)) ptr++; ptr++; if (maxlen > 0 && - size + utf8data.width > (size_t) maxlen) { + size + ud.width > (size_t) maxlen) { while (size < (size_t) maxlen) { screen_write_putc(ctx, gc, ' '); size++; } break; } - size += utf8data.width; + size += ud.width; - grid_cell_set(gc, &utf8data); + grid_cell_set(gc, &ud); screen_write_cell(ctx, gc); } else { 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 lgc; - struct utf8_data utf8data; + struct utf8_data ud; va_list ap; char *msg; u_char *ptr, *last; @@ -254,27 +254,27 @@ screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen, continue; } - if (*ptr > 0x7f && utf8_open(&utf8data, *ptr)) { + if (*ptr > 0x7f && utf8_open(&ud, *ptr)) { ptr++; left = strlen(ptr); - if (left < utf8data.size - 1) + if (left < ud.size - 1) break; - while (utf8_append(&utf8data, *ptr)) + while (utf8_append(&ud, *ptr)) ptr++; ptr++; if (maxlen > 0 && - size + utf8data.width > (size_t) maxlen) { + size + ud.width > (size_t) maxlen) { while (size < (size_t) maxlen) { screen_write_putc(ctx, gc, ' '); size++; } break; } - size += utf8data.width; + size += ud.width; - grid_cell_set(&lgc, &utf8data); + grid_cell_set(&lgc, &ud); screen_write_cell(ctx, &lgc); } else { if (maxlen > 0 && size + 1 > (size_t) maxlen) diff --git a/tty-keys.c b/tty-keys.c index 31adf0f0..6a64ef15 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -474,7 +474,7 @@ tty_keys_next(struct tty *tty) cc_t bspace; int delay, expired = 0; key_code key; - struct utf8_data utf8data; + struct utf8_data ud; u_int i; /* Get key buffer. */ @@ -539,16 +539,16 @@ first_key: } /* Is this valid UTF-8? */ - if (utf8_open(&utf8data, (u_char)*buf)) { - size = utf8data.size; + if (utf8_open(&ud, (u_char)*buf)) { + size = ud.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); + utf8_append(&ud, (u_char)buf[i]); + key = utf8_combine(&ud); log_debug("UTF-8 key %.*s %#llx", (int)size, buf, key); goto complete_key; } @@ -650,7 +650,7 @@ int tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size) { struct mouse_event *m = &tty->mouse; - struct utf8_data utf8data; + struct utf8_data ud; u_int i, value, x, y, b, sgr_b; 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); if (tty->mode & MODE_MOUSE_UTF8) { - if (utf8_open(&utf8data, buf[*size])) { - if (utf8data.size != 2) + if (utf8_open(&ud, buf[*size])) { + if (ud.size != 2) return (-1); (*size)++; if (len <= *size) return (1); - utf8_append(&utf8data, buf[*size]); - value = utf8_combine(&utf8data); + utf8_append(&ud, buf[*size]); + value = utf8_combine(&ud); } else value = (u_char)buf[*size]; (*size)++; diff --git a/utf8.c b/utf8.c index db738020..82471c66 100644 --- a/utf8.c +++ b/utf8.c @@ -350,12 +350,12 @@ static void utf8_build(void); /* Set a single character. */ void -utf8_set(struct utf8_data *utf8data, u_char ch) +utf8_set(struct utf8_data *ud, u_char ch) { - *utf8data->data = ch; - utf8data->size = 1; + *ud->data = ch; + ud->size = 1; - utf8data->width = 1; + ud->width = 1; } /* @@ -368,18 +368,18 @@ utf8_set(struct utf8_data *utf8data, u_char ch) * Returns 1 if more UTF-8 to come, 0 if not UTF-8. */ 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) - utf8data->size = 2; + ud->size = 2; else if (ch >= 0xe0 && ch <= 0xef) - utf8data->size = 3; + ud->size = 3; else if (ch >= 0xf0 && ch <= 0xf4) - utf8data->size = 4; + ud->size = 4; else return (0); - utf8_append(utf8data, ch); + utf8_append(ud, ch); return (1); } @@ -389,20 +389,20 @@ utf8_open(struct utf8_data *utf8data, u_char ch) * Returns 1 if more UTF-8 data to come, 0 if finished. */ 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! */ - if (utf8data->have >= utf8data->size) + if (ud->have >= ud->size) fatalx("UTF-8 character overflow"); - if (utf8data->size > sizeof utf8data->data) + if (ud->size > sizeof ud->data) fatalx("UTF-8 character size too large"); - utf8data->data[utf8data->have++] = ch; - if (utf8data->have != utf8data->size) + ud->data[ud->have++] = ch; + if (ud->have != ud->size) return (1); - utf8data->width = utf8_width(utf8_combine(utf8data)); + ud->width = utf8_width(utf8_combine(ud)); return (0); } @@ -451,29 +451,29 @@ utf8_width(u_int uc) /* Combine UTF-8 into 32-bit Unicode. */ u_int -utf8_combine(const struct utf8_data *utf8data) +utf8_combine(const struct utf8_data *ud) { u_int value; value = 0xff; - switch (utf8data->size) { + switch (ud->size) { case 1: - value = utf8data->data[0]; + value = ud->data[0]; break; case 2: - value = utf8data->data[1] & 0x3f; - value |= (utf8data->data[0] & 0x1f) << 6; + value = ud->data[1] & 0x3f; + value |= (ud->data[0] & 0x1f) << 6; break; case 3: - value = utf8data->data[2] & 0x3f; - value |= (utf8data->data[1] & 0x3f) << 6; - value |= (utf8data->data[0] & 0xf) << 12; + value = ud->data[2] & 0x3f; + value |= (ud->data[1] & 0x3f) << 6; + value |= (ud->data[0] & 0xf) << 12; break; case 4: - value = utf8data->data[3] & 0x3f; - value |= (utf8data->data[2] & 0x3f) << 6; - value |= (utf8data->data[1] & 0x3f) << 12; - value |= (utf8data->data[0] & 0x7) << 18; + value = ud->data[3] & 0x3f; + value |= (ud->data[2] & 0x3f) << 6; + value |= (ud->data[1] & 0x3f) << 12; + value |= (ud->data[0] & 0x7) << 18; break; } return (value); @@ -481,29 +481,29 @@ utf8_combine(const struct utf8_data *utf8data) /* Split 32-bit Unicode into UTF-8. */ int -utf8_split(u_int uc, struct utf8_data *utf8data) +utf8_split(u_int uc, struct utf8_data *ud) { if (uc < 0x7f) { - utf8data->size = 1; - utf8data->data[0] = uc; + ud->size = 1; + ud->data[0] = uc; } else if (uc < 0x7ff) { - utf8data->size = 2; - utf8data->data[0] = 0xc0 | ((uc >> 6) & 0x1f); - utf8data->data[1] = 0x80 | (uc & 0x3f); + ud->size = 2; + ud->data[0] = 0xc0 | ((uc >> 6) & 0x1f); + ud->data[1] = 0x80 | (uc & 0x3f); } else if (uc < 0xffff) { - utf8data->size = 3; - utf8data->data[0] = 0xe0 | ((uc >> 12) & 0xf); - utf8data->data[1] = 0x80 | ((uc >> 6) & 0x3f); - utf8data->data[2] = 0x80 | (uc & 0x3f); + ud->size = 3; + ud->data[0] = 0xe0 | ((uc >> 12) & 0xf); + ud->data[1] = 0x80 | ((uc >> 6) & 0x3f); + ud->data[2] = 0x80 | (uc & 0x3f); } else if (uc < 0x1fffff) { - utf8data->size = 4; - utf8data->data[0] = 0xf0 | ((uc >> 18) & 0x7); - utf8data->data[1] = 0x80 | ((uc >> 12) & 0x3f); - utf8data->data[2] = 0x80 | ((uc >> 6) & 0x3f); - utf8data->data[3] = 0x80 | (uc & 0x3f); + ud->size = 4; + ud->data[0] = 0xf0 | ((uc >> 18) & 0x7); + ud->data[1] = 0x80 | ((uc >> 12) & 0x3f); + ud->data[2] = 0x80 | ((uc >> 6) & 0x3f); + ud->data[3] = 0x80 | (uc & 0x3f); } else return (-1); - utf8data->width = utf8_width(uc); + ud->width = utf8_width(uc); return (0); } @@ -528,7 +528,7 @@ utf8_split2(u_int uc, u_char *ptr) int utf8_strvis(char *dst, const char *src, size_t len, int flag) { - struct utf8_data utf8data; + struct utf8_data ud; const char *start, *end; int more; size_t i; @@ -537,18 +537,18 @@ utf8_strvis(char *dst, const char *src, size_t len, int flag) end = src + len; while (src < end) { - if (utf8_open(&utf8data, *src)) { + if (utf8_open(&ud, *src)) { more = 1; while (++src < end && more) - more = utf8_append(&utf8data, *src); + more = utf8_append(&ud, *src); if (!more) { /* UTF-8 character finished. */ - for (i = 0; i < utf8data.size; i++) - *dst++ = utf8data.data[i]; + for (i = 0; i < ud.size; i++) + *dst++ = ud.data[i]; continue; - } else if (utf8data.have > 0) { + } else if (ud.have > 0) { /* Not a complete UTF-8 character. */ - src -= utf8data.have; + src -= ud.have; } } if (src < end - 1) @@ -573,7 +573,7 @@ utf8_sanitize(const char *src) char *dst; size_t n; int more; - struct utf8_data utf8data; + struct utf8_data ud; u_int i; dst = NULL; @@ -581,18 +581,18 @@ utf8_sanitize(const char *src) n = 0; while (*src != '\0') { dst = xreallocarray(dst, n + 1, sizeof *dst); - if (utf8_open(&utf8data, *src)) { + if (utf8_open(&ud, *src)) { more = 1; while (*++src != '\0' && more) - more = utf8_append(&utf8data, *src); + more = utf8_append(&ud, *src); if (!more) { - dst = xreallocarray(dst, n + utf8data.width, + dst = xreallocarray(dst, n + ud.width, sizeof *dst); - for (i = 0; i < utf8data.width; i++) + for (i = 0; i < ud.width; i++) dst[n++] = '_'; continue; } - src -= utf8data.have; + src -= ud.have; } if (*src > 0x1f && *src < 0x7f) dst[n] = *src;