docs/53454: wrong sample code in manpage of wcwidth(3)

Kuang-che Wu kcwu at kcwu.homeip.net
Wed Jun 18 18:50:17 UTC 2003


>Number:         53454
>Category:       docs
>Synopsis:       wrong sample code in manpage of wcwidth(3)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-doc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun 18 11:50:15 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Kuang-che Wu
>Release:        FreeBSD 5.1-BETA i386
>Organization:
>Environment:
System: FreeBSD kcwu.homeip.net 5.1-BETA FreeBSD 5.1-BETA #2: Wed May 7 16:00:34 CST 2003 root at kcwu.homeip.net:/files/usr.obj/usr/src/sys/DESKTOP i386


	
>Description:
	The sample code produces 19 column positions wide 
	in first line, and 20 in rest lines.
	
	
>How-To-Repeat:
$ echo 123456789012345678901234567890123456789012345678901234567890 | ./w
1234567890123456789
01234567890123456789
01234567890123456789
0
	
>Fix:
           while ((ch = getwchar()) != WEOF) {
                   if ((w = wcwidth(ch)) > 0)
                           column += w;
-                  if (column >= 20) {
+                  if (column > 20) {
                           putwchar(L'\n');
-                          column = 0;
+                          column = w;
                   }
                   putwchar(ch);
                   if (ch == L'\n')
                           column = 0;
           }


	Maybe you would like to fix it some other way.
	


>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-doc mailing list