Package: screen
Version: 4.0.3-9
Severity: normal

When I run screen on CJK locale, that shows me the broken
terminal layout on aptitude say. getting rid of the patch or
using wcswidth(3) instead of the own code in utf8_isdouble()
fixes that issue. I'm running with the attached patch for a
while though, that looks good to me.

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.24-1-686 (SMP w/1 CPU core)
Locale: LANG=ja_JP.UTF-8, LC_CTYPE=ja_JP.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages screen depends on:
ii  libc6                     2.7-10         GNU C Library: Shared libraries
ii  libncursesw5              5.6+20080419-2 Shared libraries for terminal hand
ii  libpam0g                  0.99.7.1-6     Pluggable Authentication Modules l

screen recommends no packages.

-- debconf information:
  screen/old_upgrade_prompt: false
#! /bin/sh /usr/share/dpatch/dpatch-run
## 40cjk_eastasian.dpatch by Yi-Hsuan Hsin <[EMAIL PROTECTED]>
##
## DP: Fix display of characters with ambiguous width depending on the
## DP: user's display locale. See upstream #16666.

@DPATCH@
diff -urNad screen-4.0.3~/ansi.c screen-4.0.3/ansi.c
--- screen-4.0.3~/ansi.c        2007-12-03 16:56:26.000000000 +0900
+++ screen-4.0.3/ansi.c 2007-12-03 16:56:27.000000000 +0900
@@ -681,7 +681,7 @@
              curr->w_rend.font = 0;
            }
 #  ifdef DW_CHARS
-         if (curr->w_encoding == UTF8 && c >= 0x1100 && utf8_isdouble(c))
+         if (curr->w_encoding == UTF8 && utf8_isdouble(c))
            curr->w_mbcs = 0xff;
 #  endif
          if (curr->w_encoding == UTF8 && c >= 0x0300 && utf8_iscomb(c))
diff -urNad screen-4.0.3~/comm.c screen-4.0.3/comm.c
--- screen-4.0.3~/comm.c        2007-12-03 16:56:26.000000000 +0900
+++ screen-4.0.3/comm.c 2007-12-03 16:56:27.000000000 +0900
@@ -112,6 +112,9 @@
 #endif
   { "charset",          NEED_FORE|ARGS_1 },
   { "chdir",           ARGS_01 },
+#ifdef DW_CHARS
+  { "cjkwidth",                ARGS_01 },
+#endif
   { "clear",           NEED_FORE|ARGS_0 },
   { "colon",           NEED_LAYER|ARGS_01 },
   { "command",         NEED_DISPLAY|ARGS_02 },
diff -urNad screen-4.0.3~/encoding.c screen-4.0.3/encoding.c
--- screen-4.0.3~/encoding.c    2007-12-03 16:56:26.000000000 +0900
+++ screen-4.0.3/encoding.c     2007-12-03 17:14:03.000000000 +0900
@@ -22,6 +22,7 @@
  */

 #include <sys/types.h>
+#include <wchar.h>

 #include "config.h"
 #include "screen.h"
@@ -35,6 +37,10 @@

 extern char *screenencodings;

+#ifdef DW_CHARS
+extern int cjkwidth;
+#endif
+
 static int  encmatch __P((char *, char *));
 # ifdef UTF8
 static int   recode_char __P((int, int, int));
@@ -845,22 +851,39 @@
 }

 #ifdef DW_CHARS
+struct interval {
+  int first;
+  int last;
+};
+
+/* auxiliary function for binary search in interval table */
+static int bisearch(int ucs, const struct interval *table, int max) {
+  int min = 0;
+  int mid;
+
+  if (ucs < table[0].first || ucs > table[max].last)
+    return 0;
+  while (max >= min) {
+    mid = (min + max) / 2;
+    if (ucs > table[mid].last)
+      min = mid + 1;
+    else if (ucs < table[mid].first)
+      max = mid - 1;
+    else
+      return 1;
+  }
+
+  return 0;
+}
+
 int
 utf8_isdouble(c)
 int c;
 {
-  return
-    (c >= 0x1100 &&
-     (c <= 0x115f ||                    /* Hangul Jamo init. consonants */
-      (c >= 0x2e80 && c <= 0xa4cf && (c & ~0x0011) != 0x300a &&
-       c != 0x303f) ||                  /* CJK ... Yi */
-      (c >= 0xac00 && c <= 0xd7a3) || /* Hangul Syllables */
-      (c >= 0xdf00 && c <= 0xdfff) || /* dw combining sequence */
-      (c >= 0xf900 && c <= 0xfaff) || /* CJK Compatibility Ideographs */
-      (c >= 0xfe30 && c <= 0xfe6f) || /* CJK Compatibility Forms */
-      (c >= 0xff00 && c <= 0xff5f) || /* Fullwidth Forms */
-      (c >= 0xffe0 && c <= 0xffe6) ||
-      (c >= 0x20000 && c <= 0x2ffff)));
+  /* convert Unicode to UCS-4 */
+  wchar_t w = c;
+
+  return wcswidth(&w, 1) > 1;
 }
 #endif

diff -urNad screen-4.0.3~/process.c screen-4.0.3/process.c
--- screen-4.0.3~/process.c     2007-12-03 16:56:26.000000000 +0900
+++ screen-4.0.3/process.c      2007-12-03 16:56:27.000000000 +0900
@@ -103,6 +103,9 @@
 #ifdef UTF8
 extern char *screenencodings;
 #endif
+#ifdef DW_CHARS
+extern int cjkwidth;
+#endif

 static int  CheckArgNum __P((int, char **));
 static void ClearAction __P((struct action *));
@@ -3826,6 +3829,15 @@
            Msg(0, "idle off");
        }
       break;
+#ifdef DW_CHARS
+    case RC_CJKWIDTH:
+      if(ParseSwitch(act, &cjkwidth) == 0)
+      {
+        if(msgok)
+          Msg(0, "Treat ambiguous width characters as %s width", cjkwidth ? 
"full" : "half");
+      }
+      break;
+#endif
     default:
 #ifdef HAVE_BRAILLE
       /* key == -2: input from braille keybord, msgok always 0 */
diff -urNad screen-4.0.3~/screen.c screen-4.0.3/screen.c
--- screen-4.0.3~/screen.c      2007-12-03 16:56:26.000000000 +0900
+++ screen-4.0.3/screen.c       2007-12-03 16:56:27.000000000 +0900
@@ -221,6 +221,10 @@
 char *screenencodings;
 #endif

+#ifdef DW_CHARS
+int cjkwidth;
+#endif
+
 #ifdef NETHACK
 int nethackflag = 0;
 #endif
@@ -468,6 +472,9 @@
   InitBuiltinTabs();
   screenencodings = SaveStr(SCREENENCODINGS);
 #endif
+#ifdef DW_CHARS
+  cjkwidth = 0;
+#endif
   nwin = nwin_undef;
   nwin_options = nwin_undef;
   strcpy(screenterm, "screen");
@@ -764,6 +771,19 @@
       debug1("environment says encoding=%d\n", nwin_options.encoding);
 #endif
     }
+# ifdef DW_CHARS
+  {
+    char *s;
+    if((s = getenv("LC_ALL")) || (s = getenv("LC_CTYPE")) ||
+       (s = getenv("LANG")))
+    {
+      if(!strncmp(s, "zh_", 3) || !strncmp(s, "ja_", 3) || !strncmp(s, "ko_", 
3))
+      {
+        cjkwidth = 1;
+      }
+    }
+  }
+#endif
 #endif
   if (SockMatch && strlen(SockMatch) >= MAXSTR)
     Panic(0, "Ridiculously long socketname - try again.");

Attachment: pgpifQQamrGUH.pgp
Description: PGP signature

Reply via email to