From owner-freebsd-current@FreeBSD.ORG Fri Oct 25 01:24:41 2013 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 4EACEA7B; Fri, 25 Oct 2013 01:24:41 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from theravensnest.org (theraven.freebsd.your.org [216.14.102.27]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 022632DBE; Fri, 25 Oct 2013 01:24:40 +0000 (UTC) Received: from [10.60.213.211] (173-13-112-142-NewEngland.hfc.comcastbusiness.net [173.13.112.142]) (authenticated bits=0) by theravensnest.org (8.14.5/8.14.5) with ESMTP id r9P1OcsK060406 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Fri, 25 Oct 2013 01:24:39 GMT (envelope-from theraven@FreeBSD.org) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Subject: Re: gperf/src/options.cc -- quiesce clang warnings -Wlogical-op-parentheses From: David Chisnall In-Reply-To: <1382663626.2498.4.camel@localhost> Date: Thu, 24 Oct 2013 21:24:32 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: <3656E3A3-F76E-42F4-BCFC-8B0F49FF5DA9@FreeBSD.org> References: <1382327452.2610.5.camel@localhost> <1382399026.7749.3.camel@localhost> <0744E30D-89EF-4340-A7DC-968AC27F302B@FreeBSD.org> <1382663626.2498.4.camel@localhost> To: sbruno@FreeBSD.org X-Mailer: Apple Mail (2.1508) Cc: Matthew Fleming , "freebsd-current@freebsd.org" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 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: Fri, 25 Oct 2013 01:24:41 -0000 On 24 Oct 2013, at 21:13, Sean Bruno wrote: > On Tue, 2013-10-22 at 09:47 +0100, David Chisnall wrote: >> On 22 Oct 2013, at 00:43, Sean Bruno wrote: >>=20 >>> Heh, Matthew suggested the obvious in private mail, it seems that = this >>> would be better "spelled" as "isalpha" :-) >>=20 >> This looks wrong. The behaviour of isalpha() depends on the current = locale. You probably want isalpha_l(), with the "C" locale. >>=20 >> David >=20 > Took me a bit of wrangling to figure out what the proper = implementation > of isalpha_l() and friends. >=20 > How about this then? >=20 > Index: options.cc > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- options.cc (revision 257083) > +++ options.cc (working copy) > @@ -28,6 +28,7 @@ > #include /* declares strcmp() */ > #include /* declares isdigit() */ > #include /* defines CHAR_MAX */ > +#include /* support for newlocale() */ > #include "getopt.h" > #include "version.h" >=20 > @@ -275,13 +276,15 @@ > for (int i =3D 0; i < _argument_count; i++) > { > const char *arg =3D _argument_vector[i]; > + locale_t loc;=09 >=20 > + loc =3D newlocale(LC_ALL_MASK, "C", 0); > /* Escape arg if it contains shell metacharacters. */ > if (*arg =3D=3D '-') > { > putchar (*arg); > arg++; > - if (*arg >=3D 'A' && *arg <=3D 'Z' || *arg >=3D 'a' && *arg = <=3D 'z') > + if (isalpha_l(*arg, loc)) > { > putchar (*arg); > arg++; > @@ -293,7 +296,7 @@ > putchar (*arg); > arg++; > } > - while (*arg >=3D 'A' && *arg <=3D 'Z' || *arg >=3D 'a' = && *arg > <=3D 'z' || *arg =3D=3D '-'); > + while (isalpha_l(*arg, loc) || *arg =3D=3D '-'); > if (*arg =3D=3D '=3D') > { > putchar (*arg); Don't forget the freelocale() at the end. This seems like a very slow way of doing what was very fast in the = original code though. I'm not entirely sure what you're aiming to gain = in this refactoring. David