Date: Wed, 25 Nov 2015 04:31:21 +0300 From: Andrey Chernov <ache@freebsd.org> To: Baptiste Daroussin <bapt@freebsd.org> Cc: Ed Schouten <ed@nuxi.nl>, Jilles Tjoelker <jilles@stack.nl>, "Sergey V. Dyatko" <sergey.dyatko@gmail.com>, FreeBSD Current <freebsd-current@freebsd.org> Subject: Re: /bin/ls formatting broken for non-C(?) locales Message-ID: <56550F69.8050609@freebsd.org> In-Reply-To: <20151125001513.GC70014@ivaldir.etoilebsd.net> References: <20151120110556.6e20a71f@laptop.minsk.domain> <20151120104253.GA21071@ivaldir.etoilebsd.net> <20151120110212.GB21071@ivaldir.etoilebsd.net> <20151120122352.GA5751@stack.nl> <20151121003541.GF21071@ivaldir.etoilebsd.net> <CABh_MK=cz-zB7krcnKjhqfW9VnwjSmuaZ9%2BAETQiLy3AsHq_vw@mail.gmail.com> <5650DACA.2090501@freebsd.org> <20151125001513.GC70014@ivaldir.etoilebsd.net>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --rsjnjilm5pXJGv0DVaTQ018kLjpJi7Rc1 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 25.11.2015 3:15, Baptiste Daroussin wrote: > On Sat, Nov 21, 2015 at 11:57:46PM +0300, Andrey Chernov wrote: >> On 21.11.2015 15:18, Ed Schouten wrote: >>> Hi Baptiste, >>> >>> I suppose you should use the wcswidth() function somewhere to compute= >>> the visible width of the month name. Some characters may be >>> double-width, others may have no effective width at all. >>> >> >> I agree. Checking error return of wide chars functions with some >> fallback will be good too. >=20 > I have updated the code https://reviews.freebsd.org/D4239 >=20 > Tested by modifying some locales to add double width and zero width uni= code in > the locales >=20 > Also added the error checking for the return of wide chars functions. F= or now I > haven't added fallback, suggestions welcome if needed. 1) For just 1 char in wcswidth(&wab_months[i][j], 1); it is better to use another function wcwidth(wab_months[i][j]); 2) By fallback I mean something which not stops ls working with incorrect for some reason locale, like setting max_width_month to MAX_ABMON_WIDTH on error return (from mbstowcs/wcwidth/wcswidth/wcswidth) and exit from populate_abbreviated_month(). 3) wcwidth/wcswidth may return -1 too, it needs to be checked too. 4) The whole processing looks overcomplicated and not effective. What about this instead? for (i =3D 0; i < 12; i++) { count wcswidth() of each month and store it in wab_months_width[]. count max_width_month. } for (i =3D 0; i < 12; i++) { if ((n =3D max_width_month - wab_months_width[i]) > 0) call wcscat(wab_months[i], L" ") n times. } 5) If there is no %b is strftime() format, there is no sense to spend CPU cycles on from populate_abbreviated_month(), so it should be called only once inside ls_strftime() on first %b instead of calling it in printtime() for all cases. --=20 http://ache.vniz.net/ --rsjnjilm5pXJGv0DVaTQ018kLjpJi7Rc1 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBCAAGBQJWVQ9pAAoJEKUckv0MjfbKbK8H/24o0qAR0rM1dN1dQxNKiFEw /yhQkUBnhmOoPMu0RU5O5g6t5iU4UZWpJ7b0A/fdjRe/kAHU9ml0lcM4KMYKNOIn aajWfYSFz7evukPP6+dJO9iBOU1elXUHQKJR7/xm8CiGBqxryKuMjq47BxnT+pxA aHAgKtT6i0chWYEJJ0/ApWr9wvD8d8TWG5SQtN2e78LTiQybZUQldAjfBz96/5y4 +P0fWFYZcfsVJ6B5M5aIZOUGGLK1c3I1fRkjE64L7fFfOmk5OUH8+kbFjsT6IHGs 3342hoOzIuaxmy5I/nghJTrJeAFhg3lx2YJ4VFNzpHcUC8hBxgILkgybP6ty5Vc= =A+4q -----END PGP SIGNATURE----- --rsjnjilm5pXJGv0DVaTQ018kLjpJi7Rc1--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?56550F69.8050609>