Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Jun 2009 15:34:18 +0000 (UTC)
From:      Hajimu UMEMOTO <ume@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r194964 - stable/7/usr.bin/ncal
Message-ID:  <200906251534.n5PFYIT3055429@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ume
Date: Thu Jun 25 15:34:17 2009
New Revision: 194964
URL: http://svn.freebsd.org/changeset/base/194964

Log:
  MFC 194366, 194447: Fix column width of weekday names for
  multibyte locales.

Modified:
  stable/7/usr.bin/ncal/   (props changed)
  stable/7/usr.bin/ncal/ncal.c

Modified: stable/7/usr.bin/ncal/ncal.c
==============================================================================
--- stable/7/usr.bin/ncal/ncal.c	Thu Jun 25 15:30:25 2009	(r194963)
+++ stable/7/usr.bin/ncal/ncal.c	Thu Jun 25 15:34:17 2009	(r194964)
@@ -417,13 +417,18 @@ printmonth(int y, int m, int jd_flag)
 {
 	struct monthlines month;
 	struct weekdays wds;
-	int i;
+	int i, len;
 
 	mkmonth(y, m - 1, jd_flag, &month);
 	mkweekdays(&wds);
 	printf("    %ls %d\n", month.name, y);
-	for (i = 0; i != 7; i++)
-		wprintf(L"%.2ls%s\n", wds.names[i], month.lines[i]);
+	for (i = 0; i != 7; i++) {
+		len = wcslen(wds.names[i]);
+		if (wcswidth(wds.names[i], len) == len)
+			wprintf(L"%.2ls%s\n", wds.names[i], month.lines[i]);
+		else
+			wprintf(L"%.1ls%s\n", wds.names[i], month.lines[i]);
+	}
 	if (flag_weeks)
 		printf("  %s\n", month.weeks);
 }
@@ -759,7 +764,7 @@ mkmonthb(int y, int m, int jd_flag, stru
 void
 mkweekdays(struct weekdays *wds)
 {
-	int i, len;
+	int i, len, width = 0;
 	struct tm tm;
 	wchar_t buf[20];
 
@@ -768,11 +773,15 @@ mkweekdays(struct weekdays *wds)
 	for (i = 0; i != 7; i++) {
 		tm.tm_wday = (i+1) % 7;
 		wcsftime(buf, sizeof(buf), L"%a", &tm);
-		len = wcslen(buf);
-		if (len > 2)
-			len = 2;
-		wcscpy(wds->names[i], L"   ");
-		wcsncpy(wds->names[i] + 2 - len, buf, len);
+		for (len = 2; len > 0; --len) {
+			if ((width = wcswidth(buf, len)) <= 2)
+				break;
+		}
+		wmemset(wds->names[i], L'\0', 4);
+		if (width == 1)
+			wds->names[i][0] = L' ';
+		wcsncat(wds->names[i], buf, len);
+		wcsncat(wds->names[i], L" ", 1);
 	}
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906251534.n5PFYIT3055429>