1*4882a593SmuzhiyunFrom f0a4ffb3f6b9128e4c77ec1ff509077feb330298 Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Jeffy Chen <jeffy.chen@rock-chips.com>
3*4882a593SmuzhiyunDate: Fri, 9 Dec 2022 11:15:45 +0800
4*4882a593SmuzhiyunSubject: [PATCH 7/8] Support bypassing Unicode when printing
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunEnabled by default.
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunBased on:
9*4882a593Smuzhiyunhttps://blog.csdn.net/wavemcu/article/details/7202908
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunTested on RK3588 EVB:
12*4882a593Smuzhiyun1/ Disable CONFIG_UNICODE_SUPPORT
13*4882a593Smuzhiyun2/ Check busybox ls could display chinese characters
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunSigned-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
16*4882a593Smuzhiyun---
17*4882a593Smuzhiyun libbb/Config.src         |  6 ++++++
18*4882a593Smuzhiyun libbb/printable_string.c |  6 +++++-
19*4882a593Smuzhiyun libbb/unicode.c          | 10 +++++++++-
20*4882a593Smuzhiyun 3 files changed, 20 insertions(+), 2 deletions(-)
21*4882a593Smuzhiyun
22*4882a593Smuzhiyundiff --git a/libbb/Config.src b/libbb/Config.src
23*4882a593Smuzhiyunindex b980f19..8b833c9 100644
24*4882a593Smuzhiyun--- a/libbb/Config.src
25*4882a593Smuzhiyun+++ b/libbb/Config.src
26*4882a593Smuzhiyun@@ -264,6 +264,12 @@ config UNICODE_SUPPORT
27*4882a593Smuzhiyun 	Probably by the time when busybox will be fully Unicode-clean,
28*4882a593Smuzhiyun 	other encodings will be mainly of historic interest.
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun+config UNICODE_BYPASS
31*4882a593Smuzhiyun+	bool "Bypass Unicode when printing"
32*4882a593Smuzhiyun+	default y
33*4882a593Smuzhiyun+	help
34*4882a593Smuzhiyun+	This makes various applets bypass Unicode when printing.
35*4882a593Smuzhiyun+
36*4882a593Smuzhiyun config UNICODE_USING_LOCALE
37*4882a593Smuzhiyun 	bool "Use libc routines for Unicode (else uses internal ones)"
38*4882a593Smuzhiyun 	default n
39*4882a593Smuzhiyundiff --git a/libbb/printable_string.c b/libbb/printable_string.c
40*4882a593Smuzhiyunindex a814fd0..3473192 100644
41*4882a593Smuzhiyun--- a/libbb/printable_string.c
42*4882a593Smuzhiyun+++ b/libbb/printable_string.c
43*4882a593Smuzhiyun@@ -42,8 +42,12 @@ const char* FAST_FUNC printable_string2(uni_stat_t *stats, const char *str)
44*4882a593Smuzhiyun 			unsigned char c = *d;
45*4882a593Smuzhiyun 			if (c == '\0')
46*4882a593Smuzhiyun 				break;
47*4882a593Smuzhiyun-			if (c < ' ' || c >= 0x7f)
48*4882a593Smuzhiyun+			if (c < ' ')
49*4882a593Smuzhiyun 				*d = '?';
50*4882a593Smuzhiyun+#if !ENABLE_UNICODE_BYPASS
51*4882a593Smuzhiyun+			if (c >= 0x7f)
52*4882a593Smuzhiyun+				*d = '?';
53*4882a593Smuzhiyun+#endif
54*4882a593Smuzhiyun 			d++;
55*4882a593Smuzhiyun 		}
56*4882a593Smuzhiyun 		if (stats) {
57*4882a593Smuzhiyundiff --git a/libbb/unicode.c b/libbb/unicode.c
58*4882a593Smuzhiyunindex e98cbbf..2f9d0d3 100644
59*4882a593Smuzhiyun--- a/libbb/unicode.c
60*4882a593Smuzhiyun+++ b/libbb/unicode.c
61*4882a593Smuzhiyun@@ -1027,7 +1027,11 @@ static char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char
62*4882a593Smuzhiyun 					while ((int)--width >= 0);
63*4882a593Smuzhiyun 					break;
64*4882a593Smuzhiyun 				}
65*4882a593Smuzhiyun+#if !ENABLE_UNICODE_BYPASS
66*4882a593Smuzhiyun 				*d++ = (c >= ' ' && c < 0x7f) ? c : '?';
67*4882a593Smuzhiyun+#else
68*4882a593Smuzhiyun+				*d++ = (c >= ' ') ? c : '?';
69*4882a593Smuzhiyun+#endif
70*4882a593Smuzhiyun 				src++;
71*4882a593Smuzhiyun 			}
72*4882a593Smuzhiyun 			*d = '\0';
73*4882a593Smuzhiyun@@ -1035,8 +1039,12 @@ static char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char
74*4882a593Smuzhiyun 			d = dst = xstrndup(src, width);
75*4882a593Smuzhiyun 			while (*d) {
76*4882a593Smuzhiyun 				unsigned char c = *d;
77*4882a593Smuzhiyun-				if (c < ' ' || c >= 0x7f)
78*4882a593Smuzhiyun+				if (c < ' ')
79*4882a593Smuzhiyun 					*d = '?';
80*4882a593Smuzhiyun+#if !ENABLE_UNICODE_BYPASS
81*4882a593Smuzhiyun+				if (c >= 0x7f)
82*4882a593Smuzhiyun+					*d = '?';
83*4882a593Smuzhiyun+#endif
84*4882a593Smuzhiyun 				d++;
85*4882a593Smuzhiyun 			}
86*4882a593Smuzhiyun 		}
87*4882a593Smuzhiyun--
88*4882a593Smuzhiyun2.20.1
89*4882a593Smuzhiyun
90