zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: math i18n
@ 1999-11-10 17:11 Clint Adams
  1999-11-10 17:31 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Clint Adams @ 1999-11-10 17:11 UTC (permalink / raw)
  To: zsh-workers

% export LC_ALL=pl_PL

% typeset -F a; ((a=1.1))
zsh: bad floating point constant

% ((a=1,1)) ; echo $a
1,0000000000

% LANG=C; ((a=1.1)) ; echo $a
1.1000000000

You can't make a floating point assignment if your locale's
decimal point is a comma.

The problem here is that strtod is using the locale yet zsh is
ignoring it.

This patch fixes the problem basically by allowing locale
to switch the meanings of '.' and ','.  Because I'm an
ignorant American, I have no idea what this breaks.

--- Src/math.c	1999/11/10 08:23:22	1.1.1.18
+++ Src/math.c	1999/11/10 17:03:30
@@ -184,9 +184,20 @@
 static int
 zzlex(void)
 {
+    char decimal = '.', thousands = ',';
     int cct = 0;
+#ifdef USE_LOCALE
+    struct lconv *lc;
+#endif
 
     yyval.type = MN_INTEGER;
+
+#ifdef USE_LOCALE
+    lc = localeconv();
+    decimal = *(lc->decimal_point);
+    thousands = *(lc->thousands_sep);
+#endif
+
     for (;; cct = 0)
 	switch (*ptr++) {
 	case '+':
@@ -324,7 +335,9 @@
 	case ':':
 	    return COLON;
 	case ',':
-	    return COMMA;
+	case '.':
+	    if (*(ptr-1) == thousands) return COMMA;
+	    else break;
 	case '\0':
 	    ptr--;
 	    return EOI;
@@ -349,15 +362,15 @@
 	    }
 	/* Fall through! */
 	default:
-	    if (idigit(*--ptr) || *ptr == '.') {
+	    if (idigit(*--ptr) || *ptr == decimal) {
 		char *nptr;
 		for (nptr = ptr; idigit(*nptr); nptr++);
 
-		if (*nptr == '.' || *nptr == 'e' || *nptr == 'E') {
+		if (*nptr == decimal || *nptr == 'e' || *nptr == 'E') {
 		    /* it's a float */
 		    yyval.type = MN_FLOAT;
 		    yyval.u.d = strtod(ptr, &nptr);
-		    if (ptr == nptr || *nptr == '.') {
+		    if (ptr == nptr || *nptr == decimal ) {
 			zerr("bad floating point constant", NULL, 0);
 			return EOI;
 		    }


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: math i18n
  1999-11-10 17:11 PATCH: math i18n Clint Adams
@ 1999-11-10 17:31 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1999-11-10 17:31 UTC (permalink / raw)
  To: Clint Adams, zsh-workers

On Nov 10, 12:11pm, Clint Adams wrote:
} Subject: PATCH: math i18n
}
} This patch fixes the problem basically by allowing locale
} to switch the meanings of '.' and ','.  Because I'm an
} ignorant American, I have no idea what this breaks.

It breaks the comma operator, which is the C-style sequential expression
evaluation operator.  That is,

	$((a=1,2))

should mean "assign 1 to `a' and return the value 2" and not "assign 1.2
to `a'".

I recommend that we either don't use strtod(), or find a way to force it
to use the C locale, rather than mess around with the shell syntax.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-11-10 17:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-10 17:11 PATCH: math i18n Clint Adams
1999-11-10 17:31 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).