From owner-freebsd-arch Sat Nov 3 6:40:18 2001 Delivered-To: freebsd-arch@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id 1847D37B416 for ; Sat, 3 Nov 2001 06:40:14 -0800 (PST) Received: from hades.hell.gr (patr530-a154.otenet.gr [212.205.215.154]) by mailsrv.otenet.gr (8.11.5/8.11.5) with ESMTP id fA3Ee5221032; Sat, 3 Nov 2001 16:40:05 +0200 (EET) Received: (from charon@localhost) by hades.hell.gr (8.11.6/8.11.6) id fA3EZFs09110; Sat, 3 Nov 2001 14:35:15 GMT (envelope-from charon@labs.gr) Date: Sat, 3 Nov 2001 14:35:15 +0000 From: Giorgos Keramidas To: Peter Pentchev Cc: Dag-Erling Smorgrav , Joe Abley , arch@FreeBSD.ORG Subject: Re: POSIX character class support for 1Tawk Message-ID: <20011103143515.D4464@hades.hell.gr> References: <20011102233831.L25226@buffoon.automagic.org> <20011103012226.Q25226@buffoon.automagic.org> <20011103145608.B76275@straylight.oblivion.bg> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20011103145608.B76275@straylight.oblivion.bg> User-Agent: Mutt/1.3.22.1i Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sat, Nov 03, 2001 at 02:56:08PM +0200, Peter Pentchev wrote: > On Sat, Nov 03, 2001 at 07:23:59AM +0100, Dag-Erling Smorgrav wrote: > > Joe Abley writes: > > > Our isalpha() and friends are locale-sensitive, I think. > > > > Only if the caller has previously called setlocale(). > > So what's the problem in calling setlocale(LC_ALL, "") > early in main() or something, as so many other utilities in > our base system already do? Unfortunately enough, it's not that simple. You'd have to check for all the possible LC_xxx environment variables. The small program below shows what can happen if you use setlocale() with NULL instead of the correct value. #include #include #include #include #include #define GREEK_ALPHA 0xe1 int main (void) { char *lc; setlocale(LC_ALL, NULL); printf("Using NULL: %s\n", isalpha(GREEK_ALPHA) ? "true" : "false"); if ((lc = getenv("LC_ALL")) == NULL) { fprintf(stderr, "LC_ALL is not defined\n"); exit(1); } setlocale(LC_ALL, lc); printf("Using getenv(): %s\n", isalpha(GREEK_ALPHA) ? "true" : "false"); return 0; } Which gives the output shown below: $ cc -Wall -o blah blah.c $ ./blah Using NULL: false LC_ALL is not defined $ env LC_LANG=el_GR LC_ALL=el_GR.ISO8859-7 ./blah Using NULL: false Using getenv(): true In the second case, of having the proper locale setup in the environment, only when getenv() is used to retrieve the proper value for setlocale() the GREEK_ALPHA character is recognized from isalpha() :/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message