From 1a1713a4c7c1e62425165c7ee82e6cf9efff5500 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Mon, 15 Nov 2004 13:41:41 +0000 Subject: [PATCH] - MF4.3: Cleaned up some of the locale mess: * 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 | 2 ++ configure.in | 4 ++-- ext/standard/formatted_print.c | 14 ++++++++------ main/php.h | 4 ---- main/php_sprintf.c | 4 ---- main/snprintf.c | 4 ---- main/snprintf.h | 6 ------ 7 files changed, 12 insertions(+), 26 deletions(-) diff --git a/NEWS b/NEWS index 1f881f232e..8de4c36ecb 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2004, PHP 5.0.3 +- Added the %F modifier to *printf to render a non-locale-aware representation + of a float with the . as decimal seperator. (Derick) - Fixed error handling in mysqli_multi_query. (Georg) - Fixed a problem with SPL iterators aggregating the innner iterator. (Marcus) - Extended the functionality of is_subclass_of() to accept either a class name diff --git a/configure.in b/configure.in index e008038f81..52f529ae24 100644 --- a/configure.in +++ b/configure.in @@ -587,8 +587,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 diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index e35946fa10..75cf0205d8 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -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'; } @@ -697,6 +698,7 @@ php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC case 'e': case 'f': + case 'F': /* XXX not done */ convert_to_double(tmp); php_sprintf_appenddouble(&result, &outpos, &size, diff --git a/main/php.h b/main/php.h index 2871db6be4..2e3957f5a1 100644 --- a/main/php.h +++ b/main/php.h @@ -37,10 +37,8 @@ #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 @@ -236,9 +234,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 diff --git a/main/php_sprintf.c b/main/php_sprintf.c index f7daab2952..b0589c20a2 100644 --- a/main/php_sprintf.c +++ b/main/php_sprintf.c @@ -26,8 +26,6 @@ #include "php_config.h" #endif -#if PHP_BROKEN_SPRINTF - int php_sprintf (char*s, const char* format, ...) { @@ -43,8 +41,6 @@ php_sprintf (char*s, const char* format, ...) return strlen (s); } -#endif /* PHP_BROKEN_SPRINTF */ - /* * Local variables: * tab-width: 4 diff --git a/main/snprintf.c b/main/snprintf.c index fa0e7f1e88..e0804b07d7 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -466,8 +466,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 * @@ -1157,8 +1155,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 diff --git a/main/snprintf.h b/main/snprintf.h index 76b7b6a6ca..a6d98793b2 100644 --- a/main/snprintf.h +++ b/main/snprintf.h @@ -64,20 +64,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 -- 2.50.1