]> granicus.if.org Git - php/commitdiff
- Cleaned up some of the locale mess:
authorDerick Rethans <derick@php.net>
Mon, 15 Nov 2004 13:40:31 +0000 (13:40 +0000)
committerDerick Rethans <derick@php.net>
Mon, 15 Nov 2004 13:40:31 +0000 (13:40 +0000)
  * all internal use of sprintf, snprintf and the like will always
    use the . as thousands seperator (if php.h is included only!).
  * echo, printf() and sprintf() always render locale-aware
  * added the %F modifier for non-locale aware rendering for floats

NEWS
configure.in
ext/standard/formatted_print.c
ext/standard/var_unserializer.c
main/php.h
main/php_sprintf.c
main/snprintf.c
main/snprintf.h

diff --git a/NEWS b/NEWS
index 4ca49c8fa19bbc077802e8b85244deb75d23f008..1deb1a5eefa2332f3e403b4bfc610c44ba608a8d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PHP 4                                                                      NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2004, Version 4.3.10
+- Added the %F modifier to *printf to render a non-locale-aware representation
+  of a float with the . as decimal seperator. (Derick)
 - Fixed a bug in addslashes() handling of the '\0' character. (Ilia)
 - Backported Marcus' foreach() speedup patch from PHP 5.x. (Derick)
 - Fixed potential problems with unserializing invalid serialize data. (Marcus)
index d51e4df2122fe2c7ebd895b44f1fa28ed228270f..b7495f0f2f1b278e02a150f1b05c4a856cb81ac3 100644 (file)
@@ -570,8 +570,8 @@ fi
 AC_REPLACE_FUNCS(strlcat strlcpy getopt)
 AC_FUNC_UTIME_NULL
 AC_FUNC_ALLOCA
-PHP_AC_BROKEN_SPRINTF
-PHP_AC_BROKEN_SNPRINTF
+dnl PHP_AC_BROKEN_SPRINTF
+dnl PHP_AC_BROKEN_SNPRINTF
 PHP_DECLARED_TIMEZONE
 PHP_TIME_R_TYPE
 PHP_READDIR_R_TYPE
index 9a5affe0596f0ee4817f421ff20faef0067568c7..4a7d86d7c4c5e30e2680f2081b6fad4b34747ed4 100644 (file)
@@ -303,13 +303,14 @@ php_sprintf_appenddouble(char **buffer, int *pos,
        char *cvt;
        register int i = 0, j = 0;
        int sign, decpt, cvt_len;
+       char decimal_point = '.';
 #ifdef HAVE_LOCALE_H
        struct lconv lc;
-       char decimal_point;
+       char locale_decimal_point;
        localeconv_r(&lc);
-       decimal_point = (lc.decimal_point)[0];
+       locale_decimal_point = (lc.decimal_point)[0];
 #else
-       char decimal_point = '.';
+       char locale_decimal_point = '.';
 #endif
 
        PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n",
@@ -343,12 +344,12 @@ php_sprintf_appenddouble(char **buffer, int *pos,
                numbuf[i++] = '+';
        }
 
-       if (fmt == 'f') {
+       if (fmt == 'f' || fmt == 'F') {
                if (decpt <= 0) {
                        numbuf[i++] = '0';
                        if (precision > 0) {
                                int k = precision;
-                               numbuf[i++] = decimal_point;
+                               numbuf[i++] = fmt == 'F' ? decimal_point : locale_decimal_point;
                                while ((decpt++ < 0) && k--) {
                                        numbuf[i++] = '0';
                                }
@@ -358,7 +359,7 @@ php_sprintf_appenddouble(char **buffer, int *pos,
                                numbuf[i++] = j < cvt_len ? cvt[j++] : '0';
                        }
                        if (precision > 0) {
-                               numbuf[i++] = decimal_point;
+                               numbuf[i++] = fmt == 'F' ? decimal_point : locale_decimal_point;
                                while (precision-- > 0) {
                                        numbuf[i++] = j < cvt_len ? cvt[j++] : '0';
                                }
@@ -472,7 +473,8 @@ php_sprintf_getnumber(char *buffer, int *pos)
  *  "b"   integer argument is printed as binary
  *  "c"   integer argument is printed as a single character
  *  "d"   argument is an integer
- *  "f"   the argument is a float
+ *  "f"   the argument is a float, the decimal separator is locale-aware
+ *  "F"   the argument is a float, but the decimal separator is always "."
  *  "o"   integer argument is printed as octal
  *  "s"   argument is a string
  *  "x"   integer argument is printed as lowercase hexadecimal
@@ -672,6 +674,7 @@ php_formatted_print(int ht, int *len, int use_array TSRMLS_DC)
 
                                case 'e':
                                case 'f':
+                               case 'F':
                                        /* XXX not done */
                                        convert_to_double(tmp);
                                        php_sprintf_appenddouble(&result, &outpos, &size,
index 65165b9bd28c29fe02625ecc89818513aa6a66f5..46b79bdc6b1b86e334930a2c116cfe9a7c239f8e 100644 (file)
@@ -1,5 +1,5 @@
-/* Generated by re2c 0.9.4 on Fri Sep 24 23:45:23 2004 */
-#line 1 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
+/* Generated by re2c 0.5 on Thu Nov  4 01:10:35 2004 */
+#line 1 "/dat/dev/php/php-4.3dev/ext/standard/var_unserializer.re"
 /*
    +----------------------------------------------------------------------+
    | PHP Version 4                                                        |
@@ -111,7 +111,7 @@ PHPAPI void var_destroy(php_unserialize_data_t *var_hashx)
 #define YYMARKER marker
 
 
-#line 118 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
+#line 118
 
 
 
@@ -296,8 +296,6 @@ PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER)
 
        
        
-
-#line 7 "<stdout>"
 {
        YYCTYPE yych;
        unsigned int yyaccept;
@@ -375,7 +373,7 @@ yy0:
                                goto yy15;
                        } else {
                                if(yych <= '}') goto yy13;
-                               if(yych <= 0xBF)        goto yy15;
+                               if(yych <= '\277')      goto yy15;
                                goto yy2;
                        }
                }
@@ -389,9 +387,8 @@ yy3:        yyaccept = 0;
        if(yych == ':') goto yy80;
        goto yy4;
 yy4:
-#line 511 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{ return 0; }
-#line 101 "<stdout>"
+#line 511
+       { return 0; }
 yy5:   yych = *++YYCURSOR;
        if(yych == ';') goto yy78;
        goto yy4;
@@ -423,16 +420,15 @@ yy12:     yyaccept = 0;
        yych = *(YYMARKER = ++YYCURSOR);
        if(yych == ':') goto yy16;
        goto yy4;
-yy13:  ++YYCURSOR;
+yy13:  yych = *++YYCURSOR;
        goto yy14;
 yy14:
-#line 505 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 505
+       {
        /* this is the case where we have less data than planned */
        php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unexpected end of serialized data");
        return 0; /* not sure if it should be 0 or 1 here? */
 }
-#line 142 "<stdout>"
 yy15:  yych = *++YYCURSOR;
        goto yy4;
 yy16:  yych = *++YYCURSOR;
@@ -452,11 +448,11 @@ yy19:     if(yybm[0+yych] & 128)  goto yy18;
 yy20:  yych = *++YYCURSOR;
        if(yych != '"') goto yy2;
        goto yy21;
-yy21:  ++YYCURSOR;
+yy21:  yych = *++YYCURSOR;
        goto yy22;
 yy22:
-#line 424 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 424
+       {
        size_t len, len2, maxlen;
        int elements;
        char *class_name;
@@ -536,7 +532,6 @@ yy22:
 
        return object_common2(UNSERIALIZE_PASSTHRU, elements);
 }
-#line 247 "<stdout>"
 yy23:  yych = *++YYCURSOR;
        if(yych <= ','){
                if(yych != '+') goto yy2;
@@ -562,18 +557,17 @@ yy26:     if(yych <= '/') goto yy2;
 yy27:  yych = *++YYCURSOR;
        if(yych != '"') goto yy2;
        goto yy28;
-yy28:  ++YYCURSOR;
+yy28:  yych = *++YYCURSOR;
        goto yy29;
 yy29:
-#line 416 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 416
+       {
 
        INIT_PZVAL(*rval);
        
        return object_common2(UNSERIALIZE_PASSTHRU,
                        object_common1(UNSERIALIZE_PASSTHRU, ZEND_STANDARD_CLASS_DEF_PTR));
 }
-#line 285 "<stdout>"
 yy30:  yych = *++YYCURSOR;
        if(yych == '+') goto yy31;
        if(yych <= '/') goto yy2;
@@ -594,11 +588,11 @@ yy33:     if(yych <= '/') goto yy2;
 yy34:  yych = *++YYCURSOR;
        if(yych != '{') goto yy2;
        goto yy35;
-yy35:  ++YYCURSOR;
+yy35:  yych = *++YYCURSOR;
        goto yy36;
 yy36:
-#line 398 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 398
+       {
        int elements = parse_iv(start + 2);
 
        *p = YYCURSOR;
@@ -615,7 +609,6 @@ yy36:
 
        return finish_nested_data(UNSERIALIZE_PASSTHRU);
 }
-#line 328 "<stdout>"
 yy37:  yych = *++YYCURSOR;
        if(yych == '+') goto yy38;
        if(yych <= '/') goto yy2;
@@ -636,11 +629,11 @@ yy40:     if(yych <= '/') goto yy2;
 yy41:  yych = *++YYCURSOR;
        if(yych != '"') goto yy2;
        goto yy42;
-yy42:  ++YYCURSOR;
+yy42:  yych = *++YYCURSOR;
        goto yy43;
 yy43:
-#line 370 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 370
+       {
        size_t len, maxlen;
        char *str;
 
@@ -667,7 +660,6 @@ yy43:
        ZVAL_STRINGL(*rval, str, len, 1);
        return 1;
 }
-#line 381 "<stdout>"
 yy44:  yych = *++YYCURSOR;
        if(yych <= '/'){
                if(yych <= ','){
@@ -753,17 +745,16 @@ yy53:     if(yych <= ';'){
                        goto yy2;
                }
        }
-yy54:  ++YYCURSOR;
+yy54:  yych = *++YYCURSOR;
        goto yy55;
 yy55:
-#line 363 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 363
+       {
        *p = YYCURSOR;
        INIT_PZVAL(*rval);
        ZVAL_DOUBLE(*rval, atof(start + 2));
        return 1;
 }
-#line 479 "<stdout>"
 yy56:  yych = *++YYCURSOR;
        if(yych <= ','){
                if(yych != '+') goto yy2;
@@ -820,11 +811,11 @@ yy63:     yych = *++YYCURSOR;
 yy64:  yych = *++YYCURSOR;
        if(yych != ';') goto yy2;
        goto yy65;
-yy65:  ++YYCURSOR;
+yy65:  yych = *++YYCURSOR;
        goto yy66;
 yy66:
-#line 346 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 346
+       {
        *p = YYCURSOR;
        INIT_PZVAL(*rval);
 #if defined(HAVE_ATOF_ACCEPTS_NAN) && defined(HAVE_ATOF_ACCEPTS_INF)
@@ -840,7 +831,6 @@ yy66:
 #endif
        return 1;
 }
-#line 558 "<stdout>"
 yy67:  yych = *++YYCURSOR;
        if(yych == 'N') goto yy64;
        goto yy2;
@@ -866,17 +856,16 @@ yy71:     if(yych <= '/') goto yy2;
        if(yych <= '9') goto yy70;
        if(yych != ';') goto yy2;
        goto yy72;
-yy72:  ++YYCURSOR;
+yy72:  yych = *++YYCURSOR;
        goto yy73;
 yy73:
-#line 339 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 339
+       {
        *p = YYCURSOR;
        INIT_PZVAL(*rval);
        ZVAL_LONG(*rval, parse_iv(start + 2));
        return 1;
 }
-#line 595 "<stdout>"
 yy74:  yych = *++YYCURSOR;
        if(yych <= '/') goto yy2;
        if(yych >= '2') goto yy2;
@@ -884,28 +873,26 @@ yy74:     yych = *++YYCURSOR;
 yy75:  yych = *++YYCURSOR;
        if(yych != ';') goto yy2;
        goto yy76;
-yy76:  ++YYCURSOR;
+yy76:  yych = *++YYCURSOR;
        goto yy77;
 yy77:
-#line 332 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 332
+       {
        *p = YYCURSOR;
        INIT_PZVAL(*rval);
        ZVAL_BOOL(*rval, parse_iv(start + 2));
        return 1;
 }
-#line 613 "<stdout>"
-yy78:  ++YYCURSOR;
+yy78:  yych = *++YYCURSOR;
        goto yy79;
 yy79:
-#line 325 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 325
+       {
        *p = YYCURSOR;
        INIT_PZVAL(*rval);
        ZVAL_NULL(*rval);
        return 1;
 }
-#line 624 "<stdout>"
 yy80:  yych = *++YYCURSOR;
        if(yych <= ','){
                if(yych != '+') goto yy2;
@@ -928,11 +915,11 @@ yy83:     if(yych <= '/') goto yy2;
        if(yych <= '9') goto yy82;
        if(yych != ';') goto yy2;
        goto yy84;
-yy84:  ++YYCURSOR;
+yy84:  yych = *++YYCURSOR;
        goto yy85;
 yy85:
-#line 304 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
-{
+#line 304
+       {
        int id;
 
        *p = YYCURSOR;
@@ -952,9 +939,8 @@ yy85:
        
        return 1;
 }
-#line 672 "<stdout>"
 }
-#line 513 "/usr/src/PHP_4_3_0/ext/standard/var_unserializer.re"
+#line 513
 
 
        return 0;
index caa59712af50ebc67d7b14c5004d79f24a9f6903..1ea18721e241ce35687d348e5d94b7de00833633 100644 (file)
 
 #include "zend_API.h"
 
-#if PHP_BROKEN_SPRINTF
 #undef sprintf
 #define sprintf php_sprintf
-#endif
 
 /* PHP's DEBUG value must match Zend's ZEND_DEBUG value */
 #undef PHP_DEBUG
@@ -230,9 +228,7 @@ char *strerror(int);
 #define PHP_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_MALLOC
 #define PHP_ATTRIBUTE_FORMAT ZEND_ATTRIBUTE_FORMAT
 
-#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) || PHP_BROKEN_SPRINTF || PHP_BROKEN_SNPRINTF || PHP_BROKEN_VSNPRINTF
 #include "snprintf.h"
-#endif
 #include "spprintf.h"
 
 #define EXEC_INPUT_BUF 4096
index 6f252c8e4851dc09d22d54a393105289bc4e6753..9db5c0de680d63a0830161932b9f60dac09c9b93 100644 (file)
@@ -22,8 +22,6 @@
 #include <stdarg.h>
 #include "php_config.h"
 
-#if PHP_BROKEN_SPRINTF
-
 int
 php_sprintf (char*s, const char* format, ...)
 {
@@ -39,8 +37,6 @@ php_sprintf (char*s, const char* format, ...)
   return strlen (s);
 }
 
-#endif /* PHP_BROKEN_SPRINTF */
-
 /*
  * Local variables:
  * tab-width: 4
index b9383c57da318cce1f33dd1f8adfe8c52b11f091..177ef4635684ce5bd0264491953453d6ad6f5a6a 100644 (file)
@@ -462,8 +462,6 @@ ap_php_gcvt(double number, int ndigit, char *buf, boolean_e altform)
        return (buf);
 }
 
-#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) || PHP_BROKEN_SNPRINTF || PHP_BROKEN_VSNPRINTF
-
 /*
  * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions
  *
@@ -988,8 +986,6 @@ int ap_php_vsnprintf(char *buf, size_t len, const char *format, va_list ap)
        return (cc);
 }
 
-#endif                                                 /* HAVE_SNPRINTF */
-
 /*
  * Local variables:
  * tab-width: 4
index ff92a80a6bdf8d11001bf19ecd16dbc2c0d16e1e..75ddb7968bb72f92c610224371cdaa1e783cfcc3 100644 (file)
@@ -62,20 +62,14 @@ Example:
 #ifndef SNPRINTF_H
 #define SNPRINTF_H
 
-#if !defined(HAVE_SNPRINTF) || PHP_BROKEN_SNPRINTF
 int ap_php_snprintf(char *, size_t, const char *, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
 #define snprintf ap_php_snprintf
-#endif
 
-#if !defined(HAVE_VSNPRINTF) || PHP_BROKEN_VSNPRINTF
 int ap_php_vsnprintf(char *, size_t, const char *, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0);
 #define vsnprintf ap_php_vsnprintf
-#endif
 
-#if PHP_BROKEN_SPRINTF
 int php_sprintf (char* s, const char* format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
 #define sprintf php_sprintf
-#endif
 
 typedef enum {
        NO = 0, YES = 1