[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nmh-workers] Feedback: remove LOCALE ifdefs?

From: paul vixie
Subject: Re: [Nmh-workers] Feedback: remove LOCALE ifdefs?
Date: Sun, 27 May 2012 06:57:32 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1

On 5/26/2012 9:24 PM, Ken Hornstein wrote:
>> just say isascii(x) && isspace(x). this is actually necessary for any
>> test nowadays. if you're not using wchar_t and <wchar.h> then you have
>> to guard against false matches by non-ascii upper-register characters.
> Hm, looking at things more closely ... you're right, of course!  Actually,
> even though I made cpstripped() multibyte safe, I wonder if sprinkling
> isascii in there might work for 1.5 ...

this put me in mind of bind8. the code below i think i wrote in 1993.
clearly i could have used isascii() but my feeling at the time was that
network data should be measured in absolute terms whereas ctype seemed
relative (to the local charset). this all comes from dns not having a
well defined presentation layer. but if you wanted to change m_getfld()
to say (x == 0x20 || x == 0x0a || x == 0x09) instead of isspace() then
you would likely not break much. (unless you're on a system where
getchar() is inserting 0x0d after every actual 0x0a it finds in the
stream, in which case all bets are off.)

in e-mail headers, a space is what rfc822 says it is, not what POSIX
says it is.

anyway here's some old ugly code that shows how we did it in dns.
imagine me sitting in a cave gnawing on a dinosaur bone.

 * Note the conspicuous absence of ctype macros in these definitions.  On
 * non-ASCII hosts, we can't depend on string literals or ctype macros to
 * tell us anything about network-format data.  The rest of the BIND system
 * is not careful about this, but for some reason, we're doing it right
#define PERIOD 0x2e
#define hyphenchar(c) ((c) == 0x2d)
#define bslashchar(c) ((c) == 0x5c)
#define periodchar(c) ((c) == PERIOD)
#define asterchar(c) ((c) == 0x2a)
#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
                   || ((c) >= 0x61 && (c) <= 0x7a))
#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)

#define borderchar(c) (alphachar(c) || digitchar(c))
#define middlechar(c) (borderchar(c) || hyphenchar(c))
#define domainchar(c) ((c) > 0x20 && (c) < 0x7f)

res_hnok(const char *dn) {
        int pch = PERIOD, ch = *dn++;

        while (ch != '\0') {
                int nch = *dn++;

                if (periodchar(ch)) {
                } else if (periodchar(pch)) {
                        if (!borderchar(ch))
                                return (0);
                } else if (periodchar(nch) || nch == '\0') {
                        if (!borderchar(ch))
                                return (0);
                } else {
                        if (!middlechar(ch))
                                return (0);
                pch = ch, ch = nch;
        return (1);

"I suspect I'm not known as a font of optimism." (VJS, 2012)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]