svn commit: r189804 - head/usr.bin/ncal
Christoph Mallon
christoph.mallon at gmx.de
Sun Mar 15 02:12:46 PDT 2009
Hi David!
David Schultz schrieb:
> Author: das
> Date: Sat Mar 14 18:55:51 2009
> New Revision: 189804
> URL: http://svn.freebsd.org/changeset/base/189804
>
> Log:
> Multibyte character support for cal(1).
>
> PR: 131578
>
> Modified:
> head/usr.bin/ncal/ncal.1
> head/usr.bin/ncal/ncal.c
>
[...]
> Modified: head/usr.bin/ncal/ncal.c
> ==============================================================================
> --- head/usr.bin/ncal/ncal.c Sat Mar 14 18:24:15 2009 (r189803)
> +++ head/usr.bin/ncal/ncal.c Sat Mar 14 18:55:51 2009 (r189804)
[...]
> @@ -532,17 +537,17 @@ printyearb(int y, int jd_flag)
> printf("%s\n\n", center(t, s, mw * mpl + mpl));
>
> for (j = 0; j != 12; j += mpl) {
> - printf("%-*s ", mw, center(s, year[j].name, mw));
> + printf("%-*ls ", mw, wcenter(ws, year[j].name, mw));
> if (mpl == 2)
> - printf("%s\n", center(s, year[j + 1].name, mw));
> + printf("%ls\n", wcenter(ws, year[j + 1].name, mw));
> else
> - printf("%-*s %s\n", mw,
> - center(s, year[j + 1].name, mw),
> - center(t, year[j + 2].name, mw));
> + printf("%-*ls %ls\n", mw,
> + wcenter(ws, year[j + 1].name, mw),
> + wcenter(wt, year[j + 2].name, mw));
>
> if (mpl == 2)
> - printf(" %s %s %s %s %s %s %s "
> - " %s %s %s %s %s %s %.2s\n",
> + wprintf(L" %ls %ls %ls %ls %ls %ls %ls "
> + " %ls %ls %ls %ls %ls %ls %.2ls\n",
> wds.names[6], wds.names[0], wds.names[1],
> wds.names[2], wds.names[3], wds.names[4],
> wds.names[5],
[...]
Your changes to ncal are invalid. You are mixing byte and wide output
functions, which access the same stream (here printf() and wprintf()).
This is not allowed according to C99 §17.9.2:5:
"Byte input/output functions shall not be applied to a wide-oriented
stream and wide character input/output functions shall not be applied to
a byte-oriented stream. [...]"
(The first access of a stream with a byte/wide oriented function makes
it byte/wide oriented)
With FreeBSD's current implementation of output functions this
accidently works, but you should not rely on this. For example with
glibc's implementation it fails.
Attached is a patch, which changes all wprintf()s back to printf().
Christoph
-------------- next part --------------
Index: ncal.c
===================================================================
--- ncal.c (Revision 189845)
+++ ncal.c (Arbeitskopie)
@@ -443,15 +443,15 @@
mw = jd_flag ? MONTH_WIDTH_B_J : MONTH_WIDTH_B;
swprintf(s, MAX_WIDTH, L"%ls %d", month.name, y);
- wprintf(L"%ls\n", wcenter(t, s, mw));
+ printf("%ls\n", wcenter(t, s, mw));
if (jd_flag)
- wprintf(L" %ls %ls %ls %ls %ls %ls %.2ls\n",
+ printf(" %ls %ls %ls %ls %ls %ls %.2ls\n",
wds.names[6], wds.names[0],
wds.names[1], wds.names[2], wds.names[3],
wds.names[4], wds.names[5]);
else
- wprintf(L"%ls%ls%ls%ls%ls%ls%.2ls\n", wds.names[6],
+ printf("%ls%ls%ls%ls%ls%ls%.2ls\n", wds.names[6],
wds.names[0], wds.names[1], wds.names[2], wds.names[3],
wds.names[4], wds.names[5]);
@@ -546,7 +546,7 @@
wcenter(wt, year[j + 2].name, mw));
if (mpl == 2)
- wprintf(L" %ls %ls %ls %ls %ls %ls %ls "
+ printf(" %ls %ls %ls %ls %ls %ls %ls "
" %ls %ls %ls %ls %ls %ls %.2ls\n",
wds.names[6], wds.names[0], wds.names[1],
wds.names[2], wds.names[3], wds.names[4],
@@ -555,7 +555,7 @@
wds.names[2], wds.names[3], wds.names[4],
wds.names[5]);
else
- wprintf(L"%ls%ls%ls%ls%ls%ls%ls "
+ printf("%ls%ls%ls%ls%ls%ls%ls "
"%ls%ls%ls%ls%ls%ls%ls "
"%ls%ls%ls%ls%ls%ls%.2ls\n",
wds.names[6], wds.names[0], wds.names[1],
More information about the svn-src-all
mailing list