Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Oct 2013 21:13:46 -0400
From:      Sean Bruno <sean_bruno@yahoo.com>
To:        David Chisnall <theraven@FreeBSD.org>
Cc:        Matthew Fleming <mdf@FreeBSD.org>, "freebsd-current@freebsd.org" <freebsd-current@FreeBSD.org>
Subject:   Re: gperf/src/options.cc -- quiesce clang warnings -Wlogical-op-parentheses
Message-ID:  <1382663626.2498.4.camel@localhost>
In-Reply-To: <0744E30D-89EF-4340-A7DC-968AC27F302B@FreeBSD.org>
References:  <1382327452.2610.5.camel@localhost> <1382399026.7749.3.camel@localhost> <0744E30D-89EF-4340-A7DC-968AC27F302B@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--=-v5MEAmV5OoPcecnCReXG
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

On Tue, 2013-10-22 at 09:47 +0100, David Chisnall wrote:
> On 22 Oct 2013, at 00:43, Sean Bruno <sean_bruno@yahoo.com> 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 loca=
le.  You probably want isalpha_l(), with the "C" locale.
>=20
> David

Took me a bit of wrangling to figure out what the proper implementation
of isalpha_l() and friends.

How about this then?

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 <string.h> /* declares strcmp() */
 #include <ctype.h>  /* declares isdigit() */
 #include <limits.h> /* defines CHAR_MAX */
+#include <xlocale.h>/* 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' && *a=
rg
<=3D 'z' || *arg =3D=3D '-');
+              while (isalpha_l(*arg, loc) || *arg =3D=3D '-');
               if (*arg =3D=3D '=3D')
                 {
                   putchar (*arg);


--=-v5MEAmV5OoPcecnCReXG
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (FreeBSD)

iQEcBAABAgAGBQJSacXJAAoJEBkJRdwI6BaH3J0IAIjo4bRhQqx5hL9hyH4McJNI
aPtA/f4kzZy0hh0qheunt+6JLROP7HgpcKq3Kji9BRnY/6XnDCprT8//iAciD6Zx
0EXM4TtyzZgjCebkhr3UH6w19js+T6hJfAqm6G/IYjtDjCp4rmHQM+dqg8xMMHwX
xocKSFu0NtwzMhSP2IKfv6GWbiPaLQJ4QZxEdoIYMUpZQEl4kv0TuBiPUDFRaIs3
3BMEz9PUNr9gAWSYZNTWaoCtb1s2MyTTchOkztaHKW+vB2TncNRPyfxNldCQVp7k
2RHnxUTQhKGeCnvtPuBoy+k27KUmc7HLU6E/bvYZNwPqT8vYrRaj2D+G0Tcbkaw=
=T2jz
-----END PGP SIGNATURE-----

--=-v5MEAmV5OoPcecnCReXG--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1382663626.2498.4.camel>