Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: math and locale
- X-seq: zsh-workers 8693
- From: Clint Adams <schizo@xxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: math and locale
- Date: Sat, 20 Nov 1999 15:18:07 -0500
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
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;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author