17d77551cSTim J. Robbins.\" Copyright (c) 2002 Tim J. Robbins 27d77551cSTim J. Robbins.\" All rights reserved. 37d77551cSTim J. Robbins.\" 47d77551cSTim J. Robbins.\" Redistribution and use in source and binary forms, with or without 57d77551cSTim J. Robbins.\" modification, are permitted provided that the following conditions 67d77551cSTim J. Robbins.\" are met: 77d77551cSTim J. Robbins.\" 1. Redistributions of source code must retain the above copyright 87d77551cSTim J. Robbins.\" notice, this list of conditions and the following disclaimer. 97d77551cSTim J. Robbins.\" 2. Redistributions in binary form must reproduce the above copyright 107d77551cSTim J. Robbins.\" notice, this list of conditions and the following disclaimer in the 117d77551cSTim J. Robbins.\" documentation and/or other materials provided with the distribution. 127d77551cSTim J. Robbins.\" 137d77551cSTim J. Robbins.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 147d77551cSTim J. Robbins.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 157d77551cSTim J. Robbins.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 167d77551cSTim J. Robbins.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 177d77551cSTim J. Robbins.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 187d77551cSTim J. Robbins.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 197d77551cSTim J. Robbins.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 207d77551cSTim J. Robbins.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 217d77551cSTim J. Robbins.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 227d77551cSTim J. Robbins.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 237d77551cSTim J. Robbins.\" SUCH DAMAGE. 247d77551cSTim J. Robbins.\" 25daa79084STom Rhodes.Dd August 17, 2004 267d77551cSTim J. Robbins.Dt WCWIDTH 3 277d77551cSTim J. Robbins.Os 287d77551cSTim J. Robbins.Sh NAME 297d77551cSTim J. Robbins.Nm wcwidth 307d77551cSTim J. Robbins.Nd "number of column positions of a wide-character code" 317d77551cSTim J. Robbins.Sh LIBRARY 327d77551cSTim J. Robbins.Lb libc 337d77551cSTim J. Robbins.Sh SYNOPSIS 347d77551cSTim J. Robbins.In wchar.h 357d77551cSTim J. Robbins.Ft int 367d77551cSTim J. Robbins.Fn wcwidth "wchar_t wc" 377d77551cSTim J. Robbins.Sh DESCRIPTION 387d77551cSTim J. RobbinsThe 397d77551cSTim J. Robbins.Fn wcwidth 407d77551cSTim J. Robbinsfunction determines the number of column positions required to 417d77551cSTim J. Robbinsdisplay the wide character 427d77551cSTim J. Robbins.Fa wc . 437d77551cSTim J. Robbins.Sh RETURN VALUES 447d77551cSTim J. RobbinsThe 457d77551cSTim J. Robbins.Fn wcwidth 467d77551cSTim J. Robbinsfunction returns 0 if the 477d77551cSTim J. Robbins.Fa wc 487d77551cSTim J. Robbinsargument is a null wide character (L'\e0'), 49279062faSRuslan Ermilov\-1 if 507d77551cSTim J. Robbins.Fa wc 517d77551cSTim J. Robbinsis not printable, 527d77551cSTim J. Robbinsotherwise it returns the number of column positions the 537d77551cSTim J. Robbinscharacter occupies. 54f2a67ef1STim J. Robbins.Sh EXAMPLES 55f2a67ef1STim J. RobbinsThis code fragment reads text from standard input and 56f2a67ef1STim J. Robbinsbreaks lines that are more than 20 column positions wide, 57f2a67ef1STim J. Robbinssimilar to the 58f2a67ef1STim J. Robbins.Xr fold 1 59f2a67ef1STim J. Robbinsutility: 60f2a67ef1STim J. Robbins.Bd -literal -offset indent 61f2a67ef1STim J. Robbinswint_t ch; 62f2a67ef1STim J. Robbinsint column, w; 63f2a67ef1STim J. Robbins 64f2a67ef1STim J. Robbinscolumn = 0; 65f2a67ef1STim J. Robbinswhile ((ch = getwchar()) != WEOF) { 665349fd7fSTim J. Robbins w = wcwidth(ch); 675349fd7fSTim J. Robbins if (w > 0 && column + w >= 20) { 68279062faSRuslan Ermilov putwchar(L'\en'); 691bdc6fddSTom Rhodes column = 0; 70f2a67ef1STim J. Robbins } 71f2a67ef1STim J. Robbins putwchar(ch); 72279062faSRuslan Ermilov if (ch == L'\en') 73f2a67ef1STim J. Robbins column = 0; 745349fd7fSTim J. Robbins else if (w > 0) 755349fd7fSTim J. Robbins column += w; 76f2a67ef1STim J. Robbins} 77f2a67ef1STim J. Robbins.Ed 787d77551cSTim J. Robbins.Sh SEE ALSO 797d77551cSTim J. Robbins.Xr iswprint 3 , 807d77551cSTim J. Robbins.Xr wcswidth 3 817d77551cSTim J. Robbins.Sh STANDARDS 827d77551cSTim J. RobbinsThe 837d77551cSTim J. Robbins.Fn wcwidth 847d77551cSTim J. Robbinsfunction conforms to 857d77551cSTim J. Robbins.St -p1003.1-2001 . 86