diff options
author | 2025-04-26 11:21:25 +0200 | |
---|---|---|
committer | 2025-04-26 11:21:25 +0200 | |
commit | e42e607aefc4132d508a0e5724b5d0975d0a53e8 (patch) | |
tree | 94816b5d70f719995111d8d108ec08604ebc292d /drivers/tty/vt | |
parent | Revert "vt: properly support zero-width Unicode code points" (diff) | |
download | wireguard-linux-e42e607aefc4132d508a0e5724b5d0975d0a53e8.tar.xz wireguard-linux-e42e607aefc4132d508a0e5724b5d0975d0a53e8.zip |
Revert "vt: move unicode processing to a separate file"
This reverts commit 2acaf27cd7f4f32bfe8bf7335690618e2417e744.
A new version of the series was submitted, so it's easier to revert the
old one and add the new one due to the changes invovled.
Cc: Nicolas Pitre <nico@fluxnic.net>
Cc: Jiri Slaby <jirislaby@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/vt')
-rw-r--r-- | drivers/tty/vt/Makefile | 3 | ||||
-rw-r--r-- | drivers/tty/vt/ucs_width.c | 45 | ||||
-rw-r--r-- | drivers/tty/vt/vt.c | 40 |
3 files changed, 40 insertions, 48 deletions
diff --git a/drivers/tty/vt/Makefile b/drivers/tty/vt/Makefile index bee69277bbc3..2c8ce8b592ed 100644 --- a/drivers/tty/vt/Makefile +++ b/drivers/tty/vt/Makefile @@ -7,8 +7,7 @@ FONTMAPFILE = cp437.uni obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o \ selection.o keyboard.o \ vt.o defkeymap.o -obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o \ - ucs_width.o +obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o # Files generated that shall be removed upon make clean clean-files := consolemap_deftbl.c defkeymap.c diff --git a/drivers/tty/vt/ucs_width.c b/drivers/tty/vt/ucs_width.c deleted file mode 100644 index 5f0bde30a1fb..000000000000 --- a/drivers/tty/vt/ucs_width.c +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -#include <linux/types.h> -#include <linux/array_size.h> -#include <linux/bsearch.h> -#include <linux/consolemap.h> - -/* ucs_is_double_width() is based on the wcwidth() implementation by - * Markus Kuhn -- 2007-05-26 (Unicode 5.0) - * Latest version: https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c - */ - -struct interval { - uint32_t first; - uint32_t last; -}; - -static int ucs_cmp(const void *key, const void *elt) -{ - uint32_t cp = *(uint32_t *)key; - struct interval e = *(struct interval *) elt; - - if (cp > e.last) - return 1; - else if (cp < e.first) - return -1; - return 0; -} - -static const struct interval double_width[] = { - { 0x1100, 0x115F }, { 0x2329, 0x232A }, { 0x2E80, 0x303E }, - { 0x3040, 0xA4CF }, { 0xAC00, 0xD7A3 }, { 0xF900, 0xFAFF }, - { 0xFE10, 0xFE19 }, { 0xFE30, 0xFE6F }, { 0xFF00, 0xFF60 }, - { 0xFFE0, 0xFFE6 }, { 0x20000, 0x2FFFD }, { 0x30000, 0x3FFFD } -}; - -bool ucs_is_double_width(uint32_t cp) -{ - if (cp < double_width[0].first || - cp > double_width[ARRAY_SIZE(double_width) - 1].last) - return false; - - return bsearch(&cp, double_width, ARRAY_SIZE(double_width), - sizeof(struct interval), ucs_cmp) != NULL; -} diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index bcb508bc15ab..b5f3c8a818ed 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -104,6 +104,7 @@ #include <linux/uaccess.h> #include <linux/kdb.h> #include <linux/ctype.h> +#include <linux/bsearch.h> #include <linux/gcd.h> #define MAX_NR_CON_DRIVER 16 @@ -2711,6 +2712,43 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c) } } +/* is_double_width() is based on the wcwidth() implementation by + * Markus Kuhn -- 2007-05-26 (Unicode 5.0) + * Latest version: https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c + */ +struct interval { + uint32_t first; + uint32_t last; +}; + +static int ucs_cmp(const void *key, const void *elt) +{ + uint32_t ucs = *(uint32_t *)key; + struct interval e = *(struct interval *) elt; + + if (ucs > e.last) + return 1; + else if (ucs < e.first) + return -1; + return 0; +} + +static int is_double_width(uint32_t ucs) +{ + static const struct interval double_width[] = { + { 0x1100, 0x115F }, { 0x2329, 0x232A }, { 0x2E80, 0x303E }, + { 0x3040, 0xA4CF }, { 0xAC00, 0xD7A3 }, { 0xF900, 0xFAFF }, + { 0xFE10, 0xFE19 }, { 0xFE30, 0xFE6F }, { 0xFF00, 0xFF60 }, + { 0xFFE0, 0xFFE6 }, { 0x20000, 0x2FFFD }, { 0x30000, 0x3FFFD } + }; + if (ucs < double_width[0].first || + ucs > double_width[ARRAY_SIZE(double_width) - 1].last) + return 0; + + return bsearch(&ucs, double_width, ARRAY_SIZE(double_width), + sizeof(struct interval), ucs_cmp) != NULL; +} + struct vc_draw_region { unsigned long from, to; int x; @@ -2915,7 +2953,7 @@ static int vc_con_write_normal(struct vc_data *vc, int tc, int c, bool inverse = false; if (vc->vc_utf && !vc->vc_disp_ctrl) { - if (ucs_is_double_width(c)) + if (is_double_width(c)) width = 2; } |