diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-02-16 13:54:30 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-02-16 13:54:30 +0000 |
commit | 1aca2b0fc16540e64ac8edfd35b3cfd02b418d78 (patch) | |
tree | f3947cffa865d6825f1d64a027010b829f2e6182 /libquadmath/printf | |
parent | 582d616d1621d35ef00539d65c30c35cff96ee3b (diff) | |
download | gcc-1aca2b0fc16540e64ac8edfd35b3cfd02b418d78.tar.gz |
* printf/quadmath-printf.c: Also check __GLIBC__ when checking
whether workarounds for printf hook handling should be added.
* configure.ac: Check for locale.h too.
(USE_LOCALE_SUPPORT): Remove check.
(USE_NL_LANGINFO, USE_NL_LANGINFO_WC, USE_LOCALECONV): New checks.
(USE_I18_NUMBER_H): Check also for _NL_CTYPE_MB_CUR_MAX.
* printf/printf_fphex.c (__quadmath_printf_fphex): Use nl_langinfo
or localeconv for narrow version and nl_langinfo if USE_NL_LANGINFO_WC
for wide version.
* printf/quadmath-printf.h: Include locale.h if HAVE_LOCALE_H.
* printf/printf_fp.c (USE_I18N_NUMBER_H): Don't define to 0.
(__quadmath_printf_fp): Use nl_langinfo or localeconv for narrow
version and nl_langinfo if USE_NL_LANGINFO_WC for wide version.
Guard nl_langinfo (_NL_CTYPE_MB_CUR_MAX) use with
USE_I18N_NUMBER_H #ifdef.
* configure: Regenerated.
* config.h.in: Regenerated.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170211 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libquadmath/printf')
-rw-r--r-- | libquadmath/printf/printf_fp.c | 105 | ||||
-rw-r--r-- | libquadmath/printf/printf_fphex.c | 35 | ||||
-rw-r--r-- | libquadmath/printf/quadmath-printf.c | 2 | ||||
-rw-r--r-- | libquadmath/printf/quadmath-printf.h | 3 |
4 files changed, 115 insertions, 30 deletions
diff --git a/libquadmath/printf/printf_fp.c b/libquadmath/printf/printf_fp.c index 4d0bf18ce48..4a63be9f8a3 100644 --- a/libquadmath/printf/printf_fp.c +++ b/libquadmath/printf/printf_fp.c @@ -37,8 +37,6 @@ #ifdef USE_I18N_NUMBER_H #include "_i18n_number.h" -#else -#define USE_I18N_NUMBER_H 0 #endif @@ -227,30 +225,48 @@ __quadmath_printf_fp (struct __quadmath_printf_file *fp, } /* Figure out the decimal point character. */ -#ifdef USE_LOCALE_SUPPORT +#ifdef USE_NL_LANGINFO if (info->extra == 0) - { - decimal = nl_langinfo (DECIMAL_POINT); - decimalwc = nl_langinfo_wc (_NL_NUMERIC_DECIMAL_POINT_WC); - } + decimal = nl_langinfo (DECIMAL_POINT); else { decimal = nl_langinfo (MON_DECIMAL_POINT); if (*decimal == '\0') decimal = nl_langinfo (DECIMAL_POINT); + } + /* The decimal point character must never be zero. */ + assert (*decimal != '\0'); +#elif defined USE_LOCALECONV + const struct lconv *lc = localeconv (); + if (info->extra == 0) + decimal = lc->decimal_point; + else + { + decimal = lc->mon_decimal_point; + if (decimal == NULL || *decimal == '\0') + decimal = lc->decimal_point; + } + if (decimal == NULL || *decimal == '\0') + decimal = "."; +#else + decimal = "."; +#endif +#ifdef USE_NL_LANGINFO_WC + if (info->extra == 0) + decimalwc = nl_langinfo_wc (_NL_NUMERIC_DECIMAL_POINT_WC); + else + { decimalwc = nl_langinfo_wc (_NL_MONETARY_DECIMAL_POINT_WC); if (decimalwc == L_('\0')) decimalwc = nl_langinfo_wc (_NL_NUMERIC_DECIMAL_POINT_WC); } - /* The decimal point character must not be zero. */ - assert (*decimal != '\0'); + /* The decimal point character must never be zero. */ assert (decimalwc != L_('\0')); #else - decimal = "."; decimalwc = L_('.'); #endif -#ifdef USE_LOCALE_SUPPORT +#if defined USE_NL_LANGINFO && defined USE_NL_LANGINFO_WC if (info->group) { if (info->extra == 0) @@ -269,6 +285,9 @@ __quadmath_printf_fp (struct __quadmath_printf_file *fp, thousands_sepwc = nl_langinfo_wc (_NL_NUMERIC_THOUSANDS_SEP_WC); else thousands_sepwc = nl_langinfo_wc (_NL_MONETARY_THOUSANDS_SEP_WC); + + if (thousands_sepwc == L_('\0')) + grouping = NULL; } else { @@ -276,22 +295,66 @@ __quadmath_printf_fp (struct __quadmath_printf_file *fp, thousands_sep = nl_langinfo (THOUSANDS_SEP); else thousands_sep = nl_langinfo (MON_THOUSANDS_SEP); + if (*thousands_sep == '\0') + grouping = NULL; } + } + } + else +#elif defined USE_NL_LANGINFO + if (info->group && !wide) + { + if (info->extra == 0) + grouping = nl_langinfo (GROUPING); + else + grouping = nl_langinfo (MON_GROUPING); + + if (*grouping <= 0 || *grouping == CHAR_MAX) + grouping = NULL; + else + { + /* Figure out the thousands separator character. */ + if (info->extra == 0) + thousands_sep = nl_langinfo (THOUSANDS_SEP); + else + thousands_sep = nl_langinfo (MON_THOUSANDS_SEP); + + if (*thousands_sep == '\0') + grouping = NULL; + } + } + else +#elif defined USE_LOCALECONV + if (info->group && !wide) + { + if (info->extra == 0) + grouping = lc->grouping; + else + grouping = lc->mon_grouping; + + if (grouping == NULL || *grouping <= 0 || *grouping == CHAR_MAX) + grouping = NULL; + else + { + /* Figure out the thousands separator character. */ + if (info->extra == 0) + thousands_sep = lc->thousands_sep; + else + thousands_sep = lc->mon_thousands_sep; - if ((wide && thousands_sepwc == L_('\0')) - || (! wide && *thousands_sep == '\0')) + if (thousands_sep == NULL || *thousands_sep == '\0') grouping = NULL; - else if (thousands_sepwc == L_('\0')) - /* If we are printing multibyte characters and there is a - multibyte representation for the thousands separator, - we must ensure the wide character thousands separator - is available, even if it is fake. */ - thousands_sepwc = (wchar_t) 0xfffffffe; } } else #endif grouping = NULL; + if (grouping != NULL && !wide) + /* If we are printing multibyte characters and there is a + multibyte representation for the thousands separator, + we must ensure the wide character thousands separator + is available, even if it is fake. */ + thousands_sepwc = (wchar_t) 0xfffffffe; /* Fetch the argument value. */ { @@ -1095,8 +1158,8 @@ __quadmath_printf_fp (struct __quadmath_printf_file *fp, size_t decimal_len; size_t thousands_sep_len; wchar_t *copywc; -#ifdef USE_LOCALE_SUPPORT - size_t factor = ((info->i18n && USE_I18N_NUMBER_H) +#ifdef USE_I18N_NUMBER_H + size_t factor = (info->i18n ? nl_langinfo_wc (_NL_CTYPE_MB_CUR_MAX) : 1); #else diff --git a/libquadmath/printf/printf_fphex.c b/libquadmath/printf/printf_fphex.c index 44900f49cc5..941e93307e0 100644 --- a/libquadmath/printf/printf_fphex.c +++ b/libquadmath/printf/printf_fphex.c @@ -117,25 +117,44 @@ __quadmath_printf_fphex (struct __quadmath_printf_file *fp, int wide = info->wide; /* Figure out the decimal point character. */ -#ifdef USE_LOCALE_SUPPORT +#ifdef USE_NL_LANGINFO if (info->extra == 0) - { - decimal = nl_langinfo (DECIMAL_POINT); - decimalwc = nl_langinfo_wc (_NL_NUMERIC_DECIMAL_POINT_WC); - } + decimal = nl_langinfo (DECIMAL_POINT); else { decimal = nl_langinfo (MON_DECIMAL_POINT); if (*decimal == '\0') decimal = nl_langinfo (DECIMAL_POINT); + } + /* The decimal point character must never be zero. */ + assert (*decimal != '\0'); +#elif defined USE_LOCALECONV + const struct lconv *lc = localeconv (); + if (info->extra == 0) + decimal = lc->decimal_point; + else + { + decimal = lc->mon_decimal_point; + if (decimal == NULL || *decimal == '\0') + decimal = lc->decimal_point; + } + if (decimal == NULL || *decimal == '\0') + decimal = "."; +#else + decimal = "."; +#endif +#ifdef USE_NL_LANGINFO_WC + if (info->extra == 0) + decimalwc = nl_langinfo_wc (_NL_NUMERIC_DECIMAL_POINT_WC); + else + { decimalwc = nl_langinfo_wc (_NL_MONETARY_DECIMAL_POINT_WC); - if (decimalwc == L'\0') + if (decimalwc == L_('\0')) decimalwc = nl_langinfo_wc (_NL_NUMERIC_DECIMAL_POINT_WC); } /* The decimal point character must never be zero. */ - assert (*decimal != '\0' && decimalwc != L'\0'); + assert (decimalwc != L_('\0')); #else - decimal = "."; decimalwc = L_('.'); #endif diff --git a/libquadmath/printf/quadmath-printf.c b/libquadmath/printf/quadmath-printf.c index 4f5305edee4..750dc246fcc 100644 --- a/libquadmath/printf/quadmath-printf.c +++ b/libquadmath/printf/quadmath-printf.c @@ -292,7 +292,7 @@ flt128_ais (const struct printf_info *info, size_t n __attribute__ ((unused)), size[0] = sizeof (__float128); return 1; } -#if __GLIBC_MINOR__ <= 13 +#if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 13) /* Workaround bug in glibc printf hook handling. */ size[0] = -1; switch (info->spec) diff --git a/libquadmath/printf/quadmath-printf.h b/libquadmath/printf/quadmath-printf.h index 796df200027..05fed7aaf07 100644 --- a/libquadmath/printf/quadmath-printf.h +++ b/libquadmath/printf/quadmath-printf.h @@ -38,6 +38,9 @@ Boston, MA 02110-1301, USA. */ #ifdef HAVE_PRINTF_HOOKS #include <printf.h> #endif +#ifdef HAVE_LOCALE_H +#include <locale.h> +#endif #include "quadmath-imp.h" #include "gmp-impl.h" |