Date: Thu, 24 Oct 2013 21:24:32 -0400 From: David Chisnall <theraven@FreeBSD.org> To: sbruno@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: <3656E3A3-F76E-42F4-BCFC-8B0F49FF5DA9@FreeBSD.org> In-Reply-To: <1382663626.2498.4.camel@localhost> References: <1382327452.2610.5.camel@localhost> <1382399026.7749.3.camel@localhost> <0744E30D-89EF-4340-A7DC-968AC27F302B@FreeBSD.org> <1382663626.2498.4.camel@localhost>
index | next in thread | previous in thread | raw e-mail
On 24 Oct 2013, at 21:13, Sean Bruno <sean_bruno@yahoo.com> wrote:
> 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:
>>
>>> Heh, Matthew suggested the obvious in private mail, it seems that this
>>> would be better "spelled" as "isalpha" :-)
>>
>> This looks wrong. The behaviour of isalpha() depends on the current locale. You probably want isalpha_l(), with the "C" locale.
>>
>> 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
> ===================================================================
> --- 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"
>
> @@ -275,13 +276,15 @@
> for (int i = 0; i < _argument_count; i++)
> {
> const char *arg = _argument_vector[i];
> + locale_t loc;
>
> + loc = newlocale(LC_ALL_MASK, "C", 0);
> /* Escape arg if it contains shell metacharacters. */
> if (*arg == '-')
> {
> putchar (*arg);
> arg++;
> - if (*arg >= 'A' && *arg <= 'Z' || *arg >= 'a' && *arg <= 'z')
> + if (isalpha_l(*arg, loc))
> {
> putchar (*arg);
> arg++;
> @@ -293,7 +296,7 @@
> putchar (*arg);
> arg++;
> }
> - while (*arg >= 'A' && *arg <= 'Z' || *arg >= 'a' && *arg
> <= 'z' || *arg == '-');
> + while (isalpha_l(*arg, loc) || *arg == '-');
> if (*arg == '=')
> {
> 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
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3656E3A3-F76E-42F4-BCFC-8B0F49FF5DA9>
