Bug#860926: zh translation for badblocks drifting due to bad column counting

2017-05-29 Thread Theodore Ts'o
tags 860926 +pending
thanks

On Fri, Apr 21, 2017 at 07:30:13PM -0400, Mingye Wang (Arthur2e5) wrote:
> Package: e2fsprogs
> Version: 1.43.4-2
> 
> The current version of e2fsprogs ships a complete Chinese translation. This
> is normally good news, just not quite so with badblocks which miscounts
> columns and gives too few `\b`'s for stepping back.
> 
> The fix is simple and straightforward -- just store the wstring and do some
> wcswidth counting on it.

Many thanks for the bugreport and the suggested fix.  I've just
checked the following into my repository:

>From 0c574883dda4a44eeb4586fd7784373de3d8c030 Mon Sep 17 00:00:00 2001
From: Theodore Ts'o 
Date: Mon, 29 May 2017 20:04:56 -0400
Subject: [PATCH] badblocks: support languages which use multi-column wide
 characters

CJK characters take up two columns for each character; teach badblocks
to take this into account.

Addresses-Debian-Bug: #860926

Signed-off-by: Theodore Ts'o 
Reported-by: "Mingye Wang (Arthur2e5)" 
---
 misc/badblocks.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/misc/badblocks.c b/misc/badblocks.c
index 0c4019a8..e4593918 100644
--- a/misc/badblocks.c
+++ b/misc/badblocks.c
@@ -50,6 +50,9 @@ extern int optind;
 #include 
 #include 
 #include 
+#ifdef HAVE_MBSTOWCS
+#include 
+#endif
 
 #include 
 #include 
@@ -216,6 +219,9 @@ static void print_status(void)
 {
struct timeval time_end;
char diff_buf[32], line_buf[128];
+#ifdef HAVE_MBSTOWCS
+   wchar_t wline_buf[128];
+#endif
int len;
 
gettimeofday(_end, 0);
@@ -229,7 +235,10 @@ static void print_status(void)
   num_write_errors,
   num_corruption_errors);
 #ifdef HAVE_MBSTOWCS
-   len = mbstowcs(NULL, line_buf, sizeof(line_buf));
+   mbstowcs(wline_buf, line_buf, sizeof(line_buf));
+   len = wcswidth(wline_buf, sizeof(line_buf));
+   if (len < 0)
+   len = strlen(line_buf); /* Should never happen... */
 #endif
fputs(line_buf, stderr);
memset(line_buf, '\b', len);
-- 
2.11.0.rc0.7.gbe5a750



Bug#860926: zh translation for badblocks drifting due to bad column counting

2017-04-21 Thread Mingye Wang (Arthur2e5)

Package: e2fsprogs
Version: 1.43.4-2

The current version of e2fsprogs ships a complete Chinese translation. 
This is normally good news, just not quite so with badblocks which 
miscounts columns and gives too few `\b`'s for stepping back.


In zh_CN.po, badblock's status text is translated as:

进度 %6.2f%%,用时 %s。(%d/%d/%d 个错误)

When this goes onto a terminal, however, the user usually ends up 
getting something like:


进度 0.进度 0.进度 0.23%,用时 xx:xx:xx。(0/0/0 个错误)

As mentioned above, this error is caused by badblocks not counting 
columns correctly. Specifically, in misc.badblocks.c:print_status(), the 
number of \b's to use is determined by character counting from mbstowcs. 
Since CJK characters take up two columns onscreen, badblocks ends up 
giving one backspace short for each Chinese character found, and causes 
the screen to drift.


The fix is simple and straightforward -- just store the wstring and do 
some wcswidth counting on it. At the top of the function, declare:


#ifdef HAVE_MBSTOWCS
wchar_t wline_buf[128];
#endif

When it comes to counting columns, do:

#ifdef HAVE_MBSTOWCS
mbstowcs(wline_buf, line_buf, sizeof(line_buf));
len = wcswidth(wline_buf);
#endif

Optionally replace all instances of "len" with "cols", since that is 
what the \b step actually assuming.

--
Cheers,

Arthur2e5



signature.asc
Description: OpenPGP digital signature