From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7345 invoked from network); 20 Nov 1999 20:18:20 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 20 Nov 1999 20:18:20 -0000 Received: (qmail 26994 invoked by alias); 20 Nov 1999 20:18:15 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8693 Received: (qmail 26987 invoked from network); 20 Nov 1999 20:18:15 -0000 Date: Sat, 20 Nov 1999 15:18:07 -0500 From: Clint Adams To: zsh-workers@sunsite.auc.dk Subject: PATCH: math and locale Message-ID: <19991120151807.A22546@dman.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Mutt/1.0i This alleviates the decimal point problem by making it locale-independent. This reverses the previous fix which introduced new problems. --- Src/math.c 1999/11/10 19:13:33 1.1.1.19 +++ Src/math.c 1999/11/20 20:07:47 @@ -184,20 +184,12 @@ static int zzlex(void) { - char decimal = '.', thousands = ','; - int cct = 0; #ifdef USE_LOCALE - struct lconv *lc; + char *prev_locale; #endif - + int cct = 0; yyval.type = MN_INTEGER; -#ifdef USE_LOCALE - lc = localeconv(); - decimal = *(lc->decimal_point); - thousands = *(lc->thousands_sep); -#endif - for (;; cct = 0) switch (*ptr++) { case '+': @@ -335,9 +327,7 @@ case ':': return COLON; case ',': - case '.': - if (*(ptr-1) == thousands) return COMMA; - else break; + return COMMA; case '\0': ptr--; return EOI; @@ -362,15 +352,22 @@ } /* Fall through! */ default: - if (idigit(*--ptr) || *ptr == decimal) { + if (idigit(*--ptr) || *ptr == '.') { char *nptr; for (nptr = ptr; idigit(*nptr); nptr++); - if (*nptr == decimal || *nptr == 'e' || *nptr == 'E') { + if (*nptr == '.' || *nptr == 'e' || *nptr == 'E') { /* it's a float */ yyval.type = MN_FLOAT; +#ifdef USE_LOCALE + prev_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "POSIX"); +#endif yyval.u.d = strtod(ptr, &nptr); - if (ptr == nptr || *nptr == decimal ) { +#ifdef USE_LOCALE + setlocale(LC_NUMERIC, prev_locale); +#endif + if (ptr == nptr || *nptr == '.' ) { zerr("bad floating point constant", NULL, 0); return EOI; }