From owner-freebsd-current@freebsd.org Wed Nov 25 01:32:00 2015 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 94D32A375B6 for ; Wed, 25 Nov 2015 01:32:00 +0000 (UTC) (envelope-from mailing-machine@vniz.net) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 17FF2152B for ; Wed, 25 Nov 2015 01:31:59 +0000 (UTC) (envelope-from mailing-machine@vniz.net) Received: by lffu14 with SMTP id u14so43166290lff.1 for ; Tue, 24 Nov 2015 17:31:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type; bh=RmSKIeXQgbr8IQmnm1EXbZKKGtSPotxHL7/6Z3bMEkM=; b=NV9oMTyLxuOf8oitawsrmlfp0YrrNpfxhj+JAOLE/1XhIKOZ3+Dvg8nUhYvPu1C66P lUtXQLW0xbzrmDIEQVcSFz/ymOjGR386oV46vumIlBDk0pksVyyEFAEuO1TMfgoCvGbC O0Z8keEqZruoI3vsQstLWTwxyIpfPCi/fGsKEp4gvonErOMKjVcz3ZVGSity26ZE5PHk qqmDrbkVc6IpPBM0zRK5P5AGRFQ6ZGORbNQo/OXsD9cpvn5AhPYHPj+VXejWrjbZ4Zic 9lmmL5WPX4Ufovo8VQHoORIlW4yyGN6c9rFAgpFqKP/1BFHASdKxnHa57L3/5fS/psMj F03Q== X-Gm-Message-State: ALoCoQkCLVPXXvfxaUj+/3gViXpdfQHlIWjQ5yZi0C02iFs/qBes4FG09BqUp9g6hPtnKc+0407B X-Received: by 10.25.166.15 with SMTP id p15mr12372885lfe.128.1448415111597; Tue, 24 Nov 2015 17:31:51 -0800 (PST) Received: from ?IPv6:2001:470:1f0b:1925:ca60:ff:fecc:e1a5? (ext-hermes.eyot.ru. [2001:470:1f0b:1925:ca60:ff:fecc:e1a5]) by smtp.gmail.com with ESMTPSA id m70sm3019005lfb.17.2015.11.24.17.31.50 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 24 Nov 2015 17:31:50 -0800 (PST) Subject: Re: /bin/ls formatting broken for non-C(?) locales To: Baptiste Daroussin 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> <5650DACA.2090501@freebsd.org> <20151125001513.GC70014@ivaldir.etoilebsd.net> Cc: Ed Schouten , Jilles Tjoelker , "Sergey V. Dyatko" , FreeBSD Current From: Andrey Chernov X-Enigmail-Draft-Status: N1110 Message-ID: <56550F69.8050609@freebsd.org> Date: Wed, 25 Nov 2015 04:31:21 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <20151125001513.GC70014@ivaldir.etoilebsd.net> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="rsjnjilm5pXJGv0DVaTQ018kLjpJi7Rc1" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2015 01:32:00 -0000 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--