[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#160282: cal: Should use the latter Chinese char for day of the week



ha shao wrote:
> On Sun, Sep 15, 2002 at 10:25:23PM +0800, Rex Tsai wrote:
> The problem has been discussed before in this list. Please search
> cal in the archive.

  我看了先前的討論,大概了解問題在那裡。對不起,我先前那封信弄錯,朋友今天提醒
我,其實 Gentoo 的 cal 正常,是因為那是 util-linux-2.11u。不是 bsdmainutils。
我也稍微看過了 bsdmainutils-5.20020211,發現裡面用了 widechar 相關的函式。似乎
跟原本的 bsdmainutils 差別頗大。我稍微 dirty hack 了一下,下面是我的 patch,如
果星期的字串是 DBCS 的話,就不用強迫砍成兩個 Byte。出來的結果會是

     九月 2002
週日 週一 週二 週三 週四 週五 週六
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

LC_ALL=C

   September 2002
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

- patch -
diff -u usr.bin/ncal/ncal.c.orig usr.bin/ncal/ncal.c|more
--- usr.bin/ncal/ncal.c.orig    Mon Sep 16 22:21:05 2002
+++ usr.bin/ncal/ncal.c Mon Sep 16 23:47:01 2002
@@ -783,10 +783,13 @@
                len = mbstowcs(NULL, buf, 0);
                wcs = calloc(len + 1, sizeof(wchar_t));
                mbstowcs(wcs, buf, len);
-               for (j = 0; j < len; j++)
+               if(len == wcswidth(wcs, (size_t)10)) {
+                   for (j = 0; j < len; j++)
                        if (wcswidth(wcs, j + 1) >= 2)
-                               break;
-               wcs[j + 1] = L'\0';
+                           break;
+                   wcs[j+1] = L'\0';
+               }
+
                col = wcswidth(wcs, j + 1);
                len = wcstombs(NULL, wcs, 0);
                wds->names[i] = calloc(len + 2 - col + 1, sizeof(char));
- patch -

  看起來 util-linux 中的 cal 比較適合 Linux 使用,希望 Debian 以後是使用這一
套。我希望能將他修正成日子與星期的排列是對齊的,這樣會美觀許多。

http://www.kernel.org/pub/linux/utils/util-linux/
-- 
-Rex, geek by nature linux by choice




Reply to: