about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-01-29 02:54:27 +0000
committerUlrich Drepper <drepper@redhat.com>2000-01-29 02:54:27 +0000
commit4295702fe36902ad82587748b918d828ce62c446 (patch)
tree538686004e11cb2af80a3be1e1fc5b95f859b4ff
parent8217ddf5c6137488b6ea5b244f74c7668b800f83 (diff)
downloadglibc-4295702fe36902ad82587748b918d828ce62c446.tar.gz
glibc-4295702fe36902ad82587748b918d828ce62c446.tar.xz
glibc-4295702fe36902ad82587748b918d828ce62c446.zip
Update.
2000-01-28  Ulrich Drepper  <drepper@cygnus.com>

	* locale/C-monetary.c: Add initializers for new fields.
	* locale/C-numeric.c: Likewise.
	* locale/Makefile (distribute): Add indigits.h, indigitswc.h,
	outdigits.h, and outdigitswc.h.
	* locale/langinfo.h: Add _NL_MONETARY_DECIMAL_POINT_WC,
	_NL_MONETARY_THOUSANDS_SEP_WC, _NL_NUMERIC_DECIMAL_POINT_WC,
	and _NL_NUMERIC_THOUSANDS_SEP_WC.
	* locale/indigits.h: New file.
	* locale/indigitswc.h: New file.
	* locale/outdigits.h: New file.
	* locale/outdigitswc.h: New file.
	* locale/programs/ld-monetary.c: Write out decimal point and
	thousands separator info in wide character form.
	* locale/programs/ld-numeric.c: Likewise.
	* stdio-common/Makefile (routines): Add _i18n_itoa and _i18n_itowa.
	(distribute): Add _i18n_itoa.h and _i18n_itowa.h.
	* stdio-common/_i18n_itoa.c: New file.
	* stdio-common/_i18n_itoa.h: New file.
	* stdio-common/_i18n_itowa.c: New file.
	* stdio-common/_i18n_itowa.h: New file.
	* stdio-common/printf-parse.h: Parse 'I' flag.
	* stdio-common/printf.h (struct printf_info): Add i18n field.
	* stdio-common/vfprintf.c: Implement 'I' flag to print using locales'
	outdigits.
-rw-r--r--ChangeLog27
-rw-r--r--locale/Makefile1
-rw-r--r--locale/indigits.h98
-rw-r--r--locale/indigitswc.h88
-rw-r--r--locale/langinfo.h6
-rw-r--r--locale/outdigits.h45
-rw-r--r--locale/outdigitswc.h35
-rw-r--r--locale/programs/ld-monetary.c58
-rw-r--r--locale/programs/ld-numeric.c47
-rw-r--r--stdio-common/Makefile7
-rw-r--r--stdio-common/_i18n_itoa.c266
-rw-r--r--stdio-common/_i18n_itoa.h41
-rw-r--r--stdio-common/_i18n_itowa.c267
-rw-r--r--stdio-common/_i18n_itowa.h41
-rw-r--r--stdio-common/printf-parse.h7
-rw-r--r--stdio-common/printf.h3
-rw-r--r--stdio-common/vfprintf.c131
17 files changed, 1105 insertions, 63 deletions
diff --git a/ChangeLog b/ChangeLog
index ee3d17b273..a77bf71d39 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2000-01-28  Ulrich Drepper  <drepper@cygnus.com>
+
+	* locale/C-monetary.c: Add initializers for new fields.
+	* locale/C-numeric.c: Likewise.
+	* locale/Makefile (distribute): Add indigits.h, indigitswc.h,
+	outdigits.h, and outdigitswc.h.
+	* locale/langinfo.h: Add _NL_MONETARY_DECIMAL_POINT_WC,
+	_NL_MONETARY_THOUSANDS_SEP_WC, _NL_NUMERIC_DECIMAL_POINT_WC,
+	and _NL_NUMERIC_THOUSANDS_SEP_WC.
+	* locale/indigits.h: New file.
+	* locale/indigitswc.h: New file.
+	* locale/outdigits.h: New file.
+	* locale/outdigitswc.h: New file.
+	* locale/programs/ld-monetary.c: Write out decimal point and
+	thousands separator info in wide character form.
+	* locale/programs/ld-numeric.c: Likewise.
+	* stdio-common/Makefile (routines): Add _i18n_itoa and _i18n_itowa.
+	(distribute): Add _i18n_itoa.h and _i18n_itowa.h.
+	* stdio-common/_i18n_itoa.c: New file.
+	* stdio-common/_i18n_itoa.h: New file.
+	* stdio-common/_i18n_itowa.c: New file.
+	* stdio-common/_i18n_itowa.h: New file.
+	* stdio-common/printf-parse.h: Parse 'I' flag.
+	* stdio-common/printf.h (struct printf_info): Add i18n field.
+	* stdio-common/vfprintf.c: Implement 'I' flag to print using locales'
+	outdigits.
+
 2000-01-27  Geoff Keating  <geoffk@cygnus.com>
 
 	* csu/Makefile ($(objpfx)version-info.h): Don't use echo -n
diff --git a/locale/Makefile b/locale/Makefile
index 71bd457dce..bc49c90636 100644
--- a/locale/Makefile
+++ b/locale/Makefile
@@ -24,6 +24,7 @@ subdir	:= locale
 headers		= locale.h langinfo.h xlocale.h
 distribute	= localeinfo.h categories.def iso-639.def iso-3166.def \
 		  iso-4217.def weight.h strlen-hash.h elem-hash.h \
+		  indigits.h indigitswc.h outdigits.h outdigitswc.h \
 		  $(addprefix programs/, \
 			      locale.c localedef.c \
 			      $(localedef-modules:=.c) $(locale-modules:=.c) \
diff --git a/locale/indigits.h b/locale/indigits.h
new file mode 100644
index 0000000000..a5289cec06
--- /dev/null
+++ b/locale/indigits.h
@@ -0,0 +1,98 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.org>, 2000.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <assert.h>
+#include <langinfo.h>
+#include <string.h>
+
+/* Look up the value of the next multibyte character and return its numerical
+   value if it is one of the digits known in the locale.  If *DECIDED is
+   -1 this means it is not yet decided which form it is and we have to
+   search through all available digits.  Otherwise we know which script
+   the digits are from.  */
+static inline int
+indigit_value (const char **s, size_t *len, int *decided)
+{
+  int from_level;
+  int to_level;
+  const char *mbdigits[10];
+  int n;
+
+  if (*decided != -1)
+    from_level = to_level = *decided;
+  else
+    {
+      from_level = 0;
+      to_level = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_INDIGITS_MB_LEN) - 1;
+      assert (from_level <= to_level);
+    }
+
+  /* In this round we get the pointer to the digit strings and also perform
+     the first round of comparisons.  */
+  for (n = 0; n < 10; ++n)
+    {
+      size_t dlen;
+
+      /* Get the string for the digits with value N.  */
+      mbdigits[n] = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_MB + n);
+      dlen = strlen (mbdigits[n]);
+
+      if (dlen <= len && memcmp (*s, mbdigits[n], dlen) == 0)
+	{
+	  /* Found it.  */
+	  *s += dlen;
+	  len -= dlen;
+	  if (*decided == -1)
+	    *decided = 0;
+	  return n;
+	}
+
+      /* Advance the pointer to the next string.  */
+      mbdigits[n] += dlen + 1;
+    }
+
+  /* Now perform the remaining tests.  */
+  while (++from_level <= to_level)
+    {
+      /* Search all ten digits of this level.  */
+      for (n = 0; n < 10; ++n)
+	{
+	  size_t dlen = strlen (mbdigits[n]);
+
+	  if (dlen <= len && memcmp (*s, mbdigits[n], dlen) == 0)
+	    {
+	      /* Found it.  */
+	      *s += dlen;
+	      len -= dlen;
+	      if (*decided == -1)
+		*decided = from_level;
+	      return n;
+	    }
+
+	  /* Advance the pointer to the next string.  */
+	  mbdigits[n] += dlen + 1;
+	}
+
+      /* Next level.  */
+      ++from_level;
+    }
+
+  /* If we reach this point no matching digit was found.  */
+  return -1;
+}
diff --git a/locale/indigitswc.h b/locale/indigitswc.h
new file mode 100644
index 0000000000..8afbb7ea17
--- /dev/null
+++ b/locale/indigitswc.h
@@ -0,0 +1,88 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.org>, 2000.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <assert.h>
+#include <langinfo.h>
+
+/* Look up the value of the next multibyte character and return its numerical
+   value if it is one of the digits known in the locale.  If *DECIDED is
+   -1 this means it is not yet decided which form it is and we have to
+   search through all available digits.  Otherwise we know which script
+   the digits are from.  */
+static inline int
+indigitwc_value (wchar_t wc, int *decided)
+{
+  int from_level;
+  int to_level;
+  const wchar_t *wcdigits[10];
+  int n;
+
+  if (*decided != -1)
+    from_level = to_level = *decided;
+  else
+    {
+      from_level = 0;
+      to_level = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_INDIGITS_WC_LEN) - 1;
+      assert (from_level <= to_level);
+    }
+
+  /* In this round we get the pointer to the digit strings and also perform
+     the first round of comparisons.  */
+  for (n = 0; n < 10; ++n)
+    {
+      /* Get the string for the digits with value N.  */
+      wcdigits[n] = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_WC + n);
+
+      if (wc == wcdigits[n])
+	{
+	  /* Found it.  */
+	  if (*decided == -1)
+	    *decided = 0;
+	  return n;
+	}
+
+      /* Advance the pointer to the next string.  */
+      ++wcdigits[n];
+    }
+
+  /* Now perform the remaining tests.  */
+  while (++from_level <= to_level)
+    {
+      /* Search all ten digits of this level.  */
+      for (n = 0; n < 10; ++n)
+	{
+	  if (wc == wcdigits[n])
+	    {
+	      /* Found it.  */
+	      if (*decided == -1)
+		*decided = from_level;
+	      return n;
+	    }
+
+	  /* Advance the pointer to the next string.  */
+	  ++wcdigits[n];
+	}
+
+      /* Next level.  */
+      ++from_level;
+    }
+
+  /* If we reach this point no matching digit was found.  */
+  return -1;
+}
diff --git a/locale/langinfo.h b/locale/langinfo.h
index 69341223cb..9ae6c8160c 100644
--- a/locale/langinfo.h
+++ b/locale/langinfo.h
@@ -1,5 +1,5 @@
 /* Access to locale-dependent parameters.
-   Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -381,6 +381,8 @@ enum
   _NL_MONETARY_DUO_VALID_FROM,
   _NL_MONETARY_DUO_VALID_TO,
   _NL_MONETARY_CONVERSION_RATE,
+  _NL_MONETARY_DECIMAL_POINT_WC,
+  _NL_MONETARY_THOUSANDS_SEP_WC,
   _NL_NUM_LC_MONETARY,
 
   /* LC_NUMERIC category: formatting of numbers.
@@ -399,6 +401,8 @@ enum
 #endif
   GROUPING,
 #define GROUPING		GROUPING
+  _NL_NUMERIC_DECIMAL_POINT_WC,
+  _NL_NUMERIC_THOUSANDS_SEP_WC,
   _NL_NUM_LC_NUMERIC,
 
   YESEXPR = _NL_ITEM (LC_MESSAGES, 0), /* Regex matching ``yes'' input.  */
diff --git a/locale/outdigits.h b/locale/outdigits.h
new file mode 100644
index 0000000000..413dfe465e
--- /dev/null
+++ b/locale/outdigits.h
@@ -0,0 +1,45 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.org>, 2000.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <assert.h>
+#include <langinfo.h>
+#include <string.h>
+#include "../locale/localeinfo.h"
+
+/* Look up the value of the next multibyte character and return its numerical
+   value if it is one of the digits known in the locale.  If *DECIDED is
+   -1 this means it is not yet decided which form it is and we have to
+   search through all available digits.  Otherwise we know which script
+   the digits are from.  */
+static inline char *
+outdigit_value (char *s, int n)
+{
+  const char *outdigit;
+  size_t dlen;
+
+  assert (0 <= n && n <= 9);
+  outdigit = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_OUTDIGIT0_MB + n);
+  dlen = strlen (outdigit);
+
+  s -= dlen;
+  while (dlen-- > 0)
+    s[dlen] = outdigit[dlen];
+
+  return s;
+}
diff --git a/locale/outdigitswc.h b/locale/outdigitswc.h
new file mode 100644
index 0000000000..5ff8e1b63d
--- /dev/null
+++ b/locale/outdigitswc.h
@@ -0,0 +1,35 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.org>, 2000.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <assert.h>
+#include <langinfo.h>
+#include "../locale/localeinfo.h"
+
+/* Look up the value of the next multibyte character and return its numerical
+   value if it is one of the digits known in the locale.  If *DECIDED is
+   -1 this means it is not yet decided which form it is and we have to
+   search through all available digits.  Otherwise we know which script
+   the digits are from.  */
+static inline wchar_t
+outdigitwc_value (int n)
+{
+  assert (0 <= n && n <= 9);
+
+  return _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_OUTDIGIT0_WC + n);
+}
diff --git a/locale/programs/ld-monetary.c b/locale/programs/ld-monetary.c
index 6a7655817c..2b2ac63397 100644
--- a/locale/programs/ld-monetary.c
+++ b/locale/programs/ld-monetary.c
@@ -43,6 +43,8 @@ struct locale_monetary_t
   const char *currency_symbol;
   const char *mon_decimal_point;
   const char *mon_thousands_sep;
+  uint32_t mon_decimal_point_wc;
+  uint32_t mon_thousands_sep_wc;
   char *mon_grouping;
   size_t mon_grouping_len;
   const char *positive_sign;
@@ -150,7 +152,7 @@ monetary_startup (struct linereader *lr, struct localedef_t *locale,
   if (lr != NULL)
     {
       lr->translate_strings = 1;
-      lr->return_widestr = 0;
+      lr->return_widestr = 1;
     }
 }
 
@@ -248,6 +250,8 @@ not correspond to a valid name in ISO 4217"),
 %s: value for field `%s' must not be the empty string"),
 	     "LC_MONETARY", "mon_decimal_point");
     }
+  if (monetary->mon_decimal_point_wc == L'\0')
+    monetary->mon_decimal_point_wc = L'.';
 
   if (monetary->mon_grouping_len == 0)
     {
@@ -575,6 +579,16 @@ monetary_output (struct localedef_t *locale, struct charmap_t *charmap,
   iov[cnt].iov_len = 8;
   ++cnt;
 
+  idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;
+  iov[cnt].iov_base = (void *) &monetary->mon_decimal_point_wc;
+  iov[cnt].iov_len = sizeof (uint32_t);
+  ++cnt;
+
+  idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;
+  iov[cnt].iov_base = (void *) &monetary->mon_thousands_sep_wc;
+  iov[cnt].iov_len = sizeof (uint32_t);
+  ++cnt;
+
   assert (cnt == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_MONETARY));
 
   write_locale_data (output_path, "LC_MONETARY",
@@ -666,13 +680,51 @@ monetary_read (struct linereader *ldfile, struct localedef_t *result,
 
 	  STR_ELEM (int_curr_symbol);
 	  STR_ELEM (currency_symbol);
-	  STR_ELEM (mon_decimal_point);
-	  STR_ELEM (mon_thousands_sep);
 	  STR_ELEM (positive_sign);
 	  STR_ELEM (negative_sign);
 	  STR_ELEM (duo_int_curr_symbol);
 	  STR_ELEM (duo_currency_symbol);
 
+#define STR_ELEM_WC(cat) \
+	case tok_##cat:							      \
+	  /* Ignore the rest of the line if we don't need the input of	      \
+	     this line.  */						      \
+	  if (ignore_content)						      \
+	    {								      \
+	      lr_ignore_rest (ldfile, 0);				      \
+	      break;							      \
+	    }								      \
+									      \
+	  now = lr_token (ldfile, charmap, NULL);			      \
+	  if (now->tok != tok_string)					      \
+	    goto err_label;						      \
+	  if (monetary->cat != NULL)					      \
+	    lr_error (ldfile, _("\
+%s: field `%s' declared more than once"), "LC_MONETARY", #cat);		      \
+	  else if (!ignore_content && now->val.str.startmb == NULL)	      \
+	    {								      \
+	      lr_error (ldfile, _("\
+%s: unknown character in field `%s'"), "LC_MONETARY", #cat);		      \
+	      monetary->cat = "";					      \
+	      monetary->cat##_wc = L'\0';				      \
+	    }								      \
+	  else if (now->val.str.startwc != NULL && now->val.str.lenwc > 1)    \
+	    {								      \
+	      lr_error (ldfile, _("\
+%s: value for field `%s' must be a single character"), "LC_MONETARY", #cat);  \
+	    }								      \
+	  else if (!ignore_content)					      \
+	    {								      \
+	      monetary->cat = now->val.str.startmb;			      \
+									      \
+	      if (now->val.str.startwc != NULL)				      \
+		monetary->cat##_wc = *now->val.str.startwc;		      \
+	    }								      \
+	  break
+
+	  STR_ELEM_WC (mon_decimal_point);
+	  STR_ELEM_WC (mon_thousands_sep);
+
 #define INT_ELEM(cat) \
 	case tok_##cat:							      \
 	  /* Ignore the rest of the line if we don't need the input of	      \
diff --git a/locale/programs/ld-numeric.c b/locale/programs/ld-numeric.c
index e61db91e8b..d7cec903a8 100644
--- a/locale/programs/ld-numeric.c
+++ b/locale/programs/ld-numeric.c
@@ -40,6 +40,8 @@ struct locale_numeric_t
   const char *thousands_sep;
   char *grouping;
   size_t grouping_len;
+  uint32_t decimal_point_wc;
+  uint32_t thousands_sep_wc;
 };
 
 
@@ -49,19 +51,15 @@ numeric_startup (struct linereader *lr, struct localedef_t *locale,
 {
   if (!ignore_content)
     {
-      struct locale_numeric_t *numeric;
-
-      locale->categories[LC_NUMERIC].numeric = numeric =
-	(struct locale_numeric_t *) xcalloc (1, sizeof (*numeric));
-
-      numeric->grouping = NULL;
-      numeric->grouping_len = 0;
+      locale->categories[LC_NUMERIC].numeric =
+	(struct locale_numeric_t *) xcalloc (1,
+					     sizeof (struct locale_numeric_t));
     }
 
   if (lr != NULL)
     {
       lr->translate_strings = 1;
-      lr->return_widestr = 0;
+      lr->return_widestr = 1;
     }
 }
 
@@ -106,12 +104,14 @@ numeric_finish (struct localedef_t *locale, struct charmap_t *charmap)
 	}
     }
 
-#define TEST_ELEM(cat)							      \
+#define TEST_ELEM(cat, default)						      \
   if (numeric->cat == NULL && ! be_quiet && ! nothing)			      \
-    error (0, 0, _("%s: field `%s' not defined"), "LC_NUMERIC", #cat)
+    error (0, 0, _("%s: field `%s' not defined"), "LC_NUMERIC", #cat);	      \
+  if (numeric->cat##_wc == L'\0')					      \
+    numeric->cat##_wc = default
 
-  TEST_ELEM (decimal_point);
-  TEST_ELEM (thousands_sep);
+  TEST_ELEM (decimal_point, L'.');
+  TEST_ELEM (thousands_sep, L'\0');
 
   /* The decimal point must not be empty.  This is not said explicitly
      in POSIX but ANSI C (ISO/IEC 9899) says in 4.4.2.1 it has to be
@@ -169,6 +169,16 @@ numeric_output (struct localedef_t *locale, struct charmap_t *charmap,
   iov[cnt].iov_base = numeric->grouping;
   iov[cnt].iov_len = numeric->grouping_len;
 
+  idx[cnt - 2] = iov[0].iov_len + iov[1].iov_len;
+  iov[cnt].iov_base = (void *) &numeric->decimal_point_wc;
+  iov[cnt].iov_len = sizeof (uint32_t);
+  ++cnt;
+
+  idx[cnt - 2] = idx[cnt - 3] + iov[cnt - 1].iov_len;
+  iov[cnt].iov_base = (void *) &numeric->thousands_sep_wc;
+  iov[cnt].iov_len = sizeof (uint32_t);;
+  ++cnt;
+
   assert (cnt + 1 == 2 + _NL_ITEM_INDEX (_NL_NUM_LC_NUMERIC));
 
   write_locale_data (output_path, "LC_NUMERIC",
@@ -246,9 +256,20 @@ numeric_read (struct linereader *ldfile, struct localedef_t *result,
 	      lr_error (ldfile, _("\
 %s: unknown character in field `%s'"), "LC_NUMERIC", #cat);		      \
 	      numeric->cat = "";					      \
+	      numeric->cat##_wc = L'\0';				      \
+	    }								      \
+	  else if (now->val.str.startwc != NULL && now->val.str.lenwc > 1)    \
+	    {								      \
+	      lr_error (ldfile, _("\
+%s: value for field `%s' must be a single character"), "LC_NUMERIC", #cat);   \
 	    }								      \
 	  else if (!ignore_content)					      \
-	    numeric->cat = now->val.str.startmb;			      \
+	    {								      \
+	      numeric->cat = now->val.str.startmb;			      \
+									      \
+	      if (now->val.str.startwc != NULL)				      \
+		numeric->cat##_wc = *now->val.str.startwc;		      \
+	    }								      \
 	  break
 
 	  STR_ELEM (decimal_point);
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index cf12dc7704..d2f51888e4 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
+# Copyright (C) 1991-1999, 2000 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -25,7 +25,7 @@ headers	:= printf.h
 
 routines	:=							      \
 	ctermid cuserid							      \
-	_itoa _itowa itoa-digits itowa-digits				      \
+	_itoa _itowa _i18n_itoa _i18n_itowa itoa-digits itowa-digits	      \
 	vfprintf vprintf printf_fp reg-printf printf-prs printf_fphex	      \
 	printf_size fprintf printf snprintf sprintf asprintf dprintf	      \
 	vfscanf 							      \
@@ -45,7 +45,8 @@ endif
 install-others := $(inst_includedir)/bits/stdio_lim.h
 
 aux	:= errlist siglist
-distribute := _itoa.h _itowa.h printf-parse.h stdio_lim.h.in
+distribute := _itoa.h _itowa.h _i18n_itoa.h _i18n_itowa.h \
+	      printf-parse.h stdio_lim.h.in
 
 tests := tst-printf tstscanf test_rdwr test-popen tstgetln test-fseek \
 	 temptest tst-fileno test-fwrite tst-ungetc tst-ferror \
diff --git a/stdio-common/_i18n_itoa.c b/stdio-common/_i18n_itoa.c
new file mode 100644
index 0000000000..55a7b28ec2
--- /dev/null
+++ b/stdio-common/_i18n_itoa.c
@@ -0,0 +1,266 @@
+/* Internal function for converting integers to string using locale
+   specific digits.
+   Copyright (C) 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <gmp-mparam.h>
+#include <stdlib/gmp.h>
+#include <stdlib/gmp-impl.h>
+#include <stdlib/longlong.h>
+
+#include "_i18n_itoa.h"
+
+
+/* Canonize environment.  For some architectures not all values might
+   be defined in the GMP header files.  */
+#ifndef UMUL_TIME
+# define UMUL_TIME 1
+#endif
+#ifndef UDIV_TIME
+# define UDIV_TIME 3
+#endif
+
+/* Control memory layout.  */
+#ifdef PACK
+# undef PACK
+# define PACK __attribute__ ((packed))
+#else
+# define PACK
+#endif
+
+
+/* Declare local types.  */
+struct base_table_t
+{
+#if (UDIV_TIME > 2 * UMUL_TIME)
+  mp_limb_t base_multiplier;
+#endif
+  char flag;
+  char post_shift;
+#if BITS_PER_MP_LIMB == 32
+  struct
+    {
+      char normalization_steps;
+      char ndigits;
+      mp_limb_t base PACK;
+#if UDIV_TIME > 2 * UMUL_TIME
+      mp_limb_t base_ninv PACK;
+#endif
+    } big;
+#endif
+};
+
+
+/* Variable in other file.  */
+extern const struct base_table_t _itoa_base_table[];
+
+
+char *
+_i18n_itoa (value, buflim)
+     unsigned long long int value;
+     char *buflim;
+{
+  const struct base_table_t *brec = &_itoa_base_table[8];
+
+#if BITS_PER_MP_LIMB == 64
+  mp_limb_t base_multiplier = brec->base_multiplier;
+  if (brec->flag)    while (value != 0)
+      {
+	mp_limb_t quo, rem, x, dummy;
+
+	umul_ppmm (x, dummy, value, base_multiplier);
+	quo = (x + ((value - x) >> 1)) >> (brec->post_shift - 1);
+	rem = value - quo * 10;
+	buflim = outdigit_value (buflim, rem);
+	value = quo;
+      }
+  else
+    while (value != 0)
+      {
+	mp_limb_t quo, rem, x, dummy;
+
+	umul_ppmm (x, dummy, value, base_multiplier);
+	quo = x >> brec->post_shift;
+	rem = value - quo * 10;
+	buflim = outdigit_value (buflim, rem);
+	value = quo;
+      }
+#endif
+#if BITS_PER_MP_LIMB == 32
+  mp_limb_t t[3];
+  int n;
+
+  /* First convert x0 to 1-3 words in base s->big.base.
+     Optimize for frequent cases of 32 bit numbers.  */
+  if ((mp_limb_t) (value >> 32) >= 1)
+    {
+#if UDIV_TIME > 2 * UMUL_TIME || UDIV_NEEDS_NORMALIZATION
+      int big_normalization_steps = brec->big.normalization_steps;
+      mp_limb_t big_base_norm
+	= brec->big.base << big_normalization_steps;
+#endif
+      if ((mp_limb_t) (value >> 32) >= brec->big.base)
+	{
+	  mp_limb_t x1hi, x1lo, r;
+	  /* If you want to optimize this, take advantage of
+	     that the quotient in the first udiv_qrnnd will
+	     always be very small.  It might be faster just to
+	     subtract in a tight loop.  */
+
+#if UDIV_TIME > 2 * UMUL_TIME
+	  mp_limb_t x, xh, xl;
+
+	  if (big_normalization_steps == 0)
+	    xh = 0;
+	  else
+	    xh = (mp_limb_t) (value >> (64 - big_normalization_steps));
+	  xl = (mp_limb_t) (value >> (32 - big_normalization_steps));
+	  udiv_qrnnd_preinv (x1hi, r, xh, xl, big_base_norm,
+			     brec->big.base_ninv);
+
+	  xl = ((mp_limb_t) value) << big_normalization_steps;
+	  udiv_qrnnd_preinv (x1lo, x, r, xl, big_base_norm,
+			     brec->big.base_ninv);
+	  t[2] = x >> big_normalization_steps;
+
+	  if (big_normalization_steps == 0)
+	    xh = x1hi;
+	  else
+	    xh = ((x1hi << big_normalization_steps)
+		  | (x1lo >> (32 - big_normalization_steps)));
+	  xl = x1lo << big_normalization_steps;
+	  udiv_qrnnd_preinv (t[0], x, xh, xl, big_base_norm,
+			     brec->big.base_ninv);
+	  t[1] = x >> big_normalization_steps;
+#elif UDIV_NEEDS_NORMALIZATION
+	  mp_limb_t x, xh, xl;
+
+	  if (big_normalization_steps == 0)
+	    xh = 0;
+	  else
+	    xh = (mp_limb_t) (value >> 64 - big_normalization_steps);
+	  xl = (mp_limb_t) (value >> 32 - big_normalization_steps);
+	  udiv_qrnnd (x1hi, r, xh, xl, big_base_norm);
+
+	  xl = ((mp_limb_t) value) << big_normalization_steps;
+	  udiv_qrnnd (x1lo, x, r, xl, big_base_norm);
+	  t[2] = x >> big_normalization_steps;
+
+	  if (big_normalization_steps == 0)
+	    xh = x1hi;
+	  else
+	    xh = ((x1hi << big_normalization_steps)
+		  | (x1lo >> 32 - big_normalization_steps));
+	  xl = x1lo << big_normalization_steps;
+	  udiv_qrnnd (t[0], x, xh, xl, big_base_norm);
+	  t[1] = x >> big_normalization_steps;
+#else
+	  udiv_qrnnd (x1hi, r, 0, (mp_limb_t) (value >> 32),
+		      brec->big.base);
+	  udiv_qrnnd (x1lo, t[2], r, (mp_limb_t) value, brec->big.base);
+	  udiv_qrnnd (t[0], t[1], x1hi, x1lo, brec->big.base);
+#endif
+	  n = 3;
+	}
+      else
+	{
+#if (UDIV_TIME > 2 * UMUL_TIME)
+	  mp_limb_t x;
+
+	  value <<= brec->big.normalization_steps;
+	  udiv_qrnnd_preinv (t[0], x, (mp_limb_t) (value >> 32),
+			     (mp_limb_t) value, big_base_norm,
+			     brec->big.base_ninv);
+	  t[1] = x >> brec->big.normalization_steps;
+#elif UDIV_NEEDS_NORMALIZATION
+	  mp_limb_t x;
+
+	  value <<= big_normalization_steps;
+	  udiv_qrnnd (t[0], x, (mp_limb_t) (value >> 32),
+		      (mp_limb_t) value, big_base_norm);
+	  t[1] = x >> big_normalization_steps;
+#else
+	  udiv_qrnnd (t[0], t[1], (mp_limb_t) (value >> 32),
+		      (mp_limb_t) value, brec->big.base);
+#endif
+	  n = 2;
+	}
+    }
+  else
+    {
+      t[0] = value;
+      n = 1;
+    }
+
+  /* Convert the 1-3 words in t[], word by word, to ASCII.  */
+  do
+    {
+      mp_limb_t ti = t[--n];
+      int ndig_for_this_limb = 0;
+
+#if UDIV_TIME > 2 * UMUL_TIME
+      mp_limb_t base_multiplier = brec->base_multiplier;
+      if (brec->flag)
+	while (ti != 0)
+	  {
+	    mp_limb_t quo, rem, x, dummy;
+
+	    umul_ppmm (x, dummy, ti, base_multiplier);
+	    quo = (x + ((ti - x) >> 1)) >> (brec->post_shift - 1);
+	    rem = ti - quo * 10;
+	    buflim = outdigit_value (buflim, rem);
+	    ti = quo;
+	    ++ndig_for_this_limb;
+	  }      else
+	while (ti != 0)
+	  {
+	    mp_limb_t quo, rem, x, dummy;
+
+	    umul_ppmm (x, dummy, ti, base_multiplier);
+	    quo = x >> brec->post_shift;
+	    rem = ti - quo * 10;
+	    buflim = outdigit_value (buflim, rem);
+	    ti = quo;
+	    ++ndig_for_this_limb;
+	  }
+#else
+      while (ti != 0)
+	{
+	  mp_limb_t quo, rem;
+
+	  quo = ti / 10;
+	  rem = ti % 10;
+	  buflim = outdigit_value (buflim, rem);
+	  ti = quo;
+	  ++ndig_for_this_limb;
+	}
+#endif
+      /* If this wasn't the most significant word, pad with zeros.  */
+      if (n != 0)
+	while (ndig_for_this_limb < brec->big.ndigits)
+	  {
+	    *--buflim = '0';
+	    ++ndig_for_this_limb;
+	  }
+    }
+  while (n != 0);
+#endif
+
+  return buflim;
+}
diff --git a/stdio-common/_i18n_itoa.h b/stdio-common/_i18n_itoa.h
new file mode 100644
index 0000000000..5662cd91f3
--- /dev/null
+++ b/stdio-common/_i18n_itoa.h
@@ -0,0 +1,41 @@
+/* Internal function for converting integers to string using locale
+   specific digits.
+   Copyright (C) 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#ifndef _I18N_ITOA_H
+#define _I18N_ITOA_H
+#include <sys/cdefs.h>
+
+#include "../locale/outdigits.h"
+
+
+extern char *_i18n_itoa (unsigned long long int value, char *buflim);
+
+static inline char *
+_i18n_itoa_word (unsigned long int value, char *buflim)
+{
+  do
+    buflim = outdigit_value (buflim, value % 10);
+  while ((value /= 10) != 0);					      \
+
+  return buflim;
+}
+
+#endif	/* _i18n_itoa.h */
diff --git a/stdio-common/_i18n_itowa.c b/stdio-common/_i18n_itowa.c
new file mode 100644
index 0000000000..357f8a383b
--- /dev/null
+++ b/stdio-common/_i18n_itowa.c
@@ -0,0 +1,267 @@
+/* Internal function for converting integers to string using locale
+   specific digits.
+   Copyright (C) 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <gmp-mparam.h>
+#include <stdlib/gmp.h>
+#include <stdlib/gmp-impl.h>
+#include <stdlib/longlong.h>
+
+#include "_i18n_itowa.h"
+
+
+/* Canonize environment.  For some architectures not all values might
+   be defined in the GMP header files.  */
+#ifndef UMUL_TIME
+# define UMUL_TIME 1
+#endif
+#ifndef UDIV_TIME
+# define UDIV_TIME 3
+#endif
+
+/* Control memory layout.  */
+#ifdef PACK
+# undef PACK
+# define PACK __attribute__ ((packed))
+#else
+# define PACK
+#endif
+
+
+/* Declare local types.  */
+struct base_table_t
+{
+#if (UDIV_TIME > 2 * UMUL_TIME)
+  mp_limb_t base_multiplier;
+#endif
+  char flag;
+  char post_shift;
+#if BITS_PER_MP_LIMB == 32
+  struct
+    {
+      char normalization_steps;
+      char ndigits;
+      mp_limb_t base PACK;
+#if UDIV_TIME > 2 * UMUL_TIME
+      mp_limb_t base_ninv PACK;
+#endif
+    } big;
+#endif
+};
+
+
+/* Variable in other file.  */
+extern const struct base_table_t _itoa_base_table[];
+
+
+wchar_t *
+_i18n_itowa (value, buflim)
+     unsigned long long int value;
+     wchar_t *buflim;
+{
+  const struct base_table_t *brec = &_itoa_base_table[8];
+
+#if BITS_PER_MP_LIMB == 64
+  mp_limb_t base_multiplier = brec->base_multiplier;
+  if (brec->flag)    while (value != 0)
+      {
+	mp_limb_t quo, rem, x, dummy;
+
+	umul_ppmm (x, dummy, value, base_multiplier);
+	quo = (x + ((value - x) >> 1)) >> (brec->post_shift - 1);
+	rem = value - quo * 10;
+	*--buflim = outdigitwc_value (rem);
+	value = quo;
+      }
+  else
+    while (value != 0)
+      {
+	mp_limb_t quo, rem, x, dummy;
+
+	umul_ppmm (x, dummy, value, base_multiplier);
+	quo = x >> brec->post_shift;
+	rem = value - quo * 10;
+	*--buflim = outdigitwc_value (rem);
+	value = quo;
+      }
+#endif
+#if BITS_PER_MP_LIMB == 32
+  mp_limb_t t[3];
+  int n;
+
+  /* First convert x0 to 1-3 words in base s->big.base.
+     Optimize for frequent cases of 32 bit numbers.  */
+  if ((mp_limb_t) (value >> 32) >= 1)
+    {
+#if UDIV_TIME > 2 * UMUL_TIME || UDIV_NEEDS_NORMALIZATION
+      int big_normalization_steps = brec->big.normalization_steps;
+      mp_limb_t big_base_norm
+	= brec->big.base << big_normalization_steps;
+#endif
+      if ((mp_limb_t) (value >> 32) >= brec->big.base)
+	{
+	  mp_limb_t x1hi, x1lo, r;
+	  /* If you want to optimize this, take advantage of
+	     that the quotient in the first udiv_qrnnd will
+	     always be very small.  It might be faster just to
+	     subtract in a tight loop.  */
+
+#if UDIV_TIME > 2 * UMUL_TIME
+	  mp_limb_t x, xh, xl;
+
+	  if (big_normalization_steps == 0)
+	    xh = 0;
+	  else
+	    xh = (mp_limb_t) (value >> (64 - big_normalization_steps));
+	  xl = (mp_limb_t) (value >> (32 - big_normalization_steps));
+	  udiv_qrnnd_preinv (x1hi, r, xh, xl, big_base_norm,
+			     brec->big.base_ninv);
+
+	  xl = ((mp_limb_t) value) << big_normalization_steps;
+	  udiv_qrnnd_preinv (x1lo, x, r, xl, big_base_norm,
+			     brec->big.base_ninv);
+	  t[2] = x >> big_normalization_steps;
+
+	  if (big_normalization_steps == 0)
+	    xh = x1hi;
+	  else
+	    xh = ((x1hi << big_normalization_steps)
+		  | (x1lo >> (32 - big_normalization_steps)));
+	  xl = x1lo << big_normalization_steps;
+	  udiv_qrnnd_preinv (t[0], x, xh, xl, big_base_norm,
+			     brec->big.base_ninv);
+	  t[1] = x >> big_normalization_steps;
+#elif UDIV_NEEDS_NORMALIZATION
+	  mp_limb_t x, xh, xl;
+
+	  if (big_normalization_steps == 0)
+	    xh = 0;
+	  else
+	    xh = (mp_limb_t) (value >> 64 - big_normalization_steps);
+	  xl = (mp_limb_t) (value >> 32 - big_normalization_steps);
+	  udiv_qrnnd (x1hi, r, xh, xl, big_base_norm);
+
+	  xl = ((mp_limb_t) value) << big_normalization_steps;
+	  udiv_qrnnd (x1lo, x, r, xl, big_base_norm);
+	  t[2] = x >> big_normalization_steps;
+
+	  if (big_normalization_steps == 0)
+	    xh = x1hi;
+	  else
+	    xh = ((x1hi << big_normalization_steps)
+		  | (x1lo >> 32 - big_normalization_steps));
+	  xl = x1lo << big_normalization_steps;
+	  udiv_qrnnd (t[0], x, xh, xl, big_base_norm);
+	  t[1] = x >> big_normalization_steps;
+#else
+	  udiv_qrnnd (x1hi, r, 0, (mp_limb_t) (value >> 32),
+		      brec->big.base);
+	  udiv_qrnnd (x1lo, t[2], r, (mp_limb_t) value, brec->big.base);
+	  udiv_qrnnd (t[0], t[1], x1hi, x1lo, brec->big.base);
+#endif
+	  n = 3;
+	}
+      else
+	{
+#if (UDIV_TIME > 2 * UMUL_TIME)
+	  mp_limb_t x;
+
+	  value <<= brec->big.normalization_steps;
+	  udiv_qrnnd_preinv (t[0], x, (mp_limb_t) (value >> 32),
+			     (mp_limb_t) value, big_base_norm,
+			     brec->big.base_ninv);
+	  t[1] = x >> brec->big.normalization_steps;
+#elif UDIV_NEEDS_NORMALIZATION
+	  mp_limb_t x;
+
+	  value <<= big_normalization_steps;
+	  udiv_qrnnd (t[0], x, (mp_limb_t) (value >> 32),
+		      (mp_limb_t) value, big_base_norm);
+	  t[1] = x >> big_normalization_steps;
+#else
+	  udiv_qrnnd (t[0], t[1], (mp_limb_t) (value >> 32),
+		      (mp_limb_t) value, brec->big.base);
+#endif
+	  n = 2;
+	}
+    }
+  else
+    {
+      t[0] = value;
+      n = 1;
+    }
+
+  /* Convert the 1-3 words in t[], word by word, to ASCII.  */
+  do
+    {
+      mp_limb_t ti = t[--n];
+      int ndig_for_this_limb = 0;
+
+#if UDIV_TIME > 2 * UMUL_TIME
+      mp_limb_t base_multiplier = brec->base_multiplier;
+      if (brec->flag)
+	while (ti != 0)
+	  {
+	    mp_limb_t quo, rem, x, dummy;
+
+	    umul_ppmm (x, dummy, ti, base_multiplier);
+	    quo = (x + ((ti - x) >> 1)) >> (brec->post_shift - 1);
+	    rem = ti - quo * 10;
+	    *--buflim = outdigitwc_value (rem);
+	    ti = quo;
+	    ++ndig_for_this_limb;
+	  }
+      else
+	while (ti != 0)
+	  {
+	    mp_limb_t quo, rem, x, dummy;
+
+	    umul_ppmm (x, dummy, ti, base_multiplier);
+	    quo = x >> brec->post_shift;
+	    rem = ti - quo * 10;
+	    *--buflim = outdigitwc_value (rem);
+	    ti = quo;
+	    ++ndig_for_this_limb;
+	  }
+#else
+      while (ti != 0)
+	{
+	  mp_limb_t quo, rem;
+
+	  quo = ti / 10;
+	  rem = ti % 10;
+	  *--buflim = outdigitwc_value (rem);
+	  ti = quo;
+	  ++ndig_for_this_limb;
+	}
+#endif
+      /* If this wasn't the most significant word, pad with zeros.  */
+      if (n != 0)
+	while (ndig_for_this_limb < brec->big.ndigits)
+	  {
+	    *--buflim = '0';
+	    ++ndig_for_this_limb;
+	  }
+    }
+  while (n != 0);
+#endif
+
+  return buflim;
+}
diff --git a/stdio-common/_i18n_itowa.h b/stdio-common/_i18n_itowa.h
new file mode 100644
index 0000000000..f4b091e5f6
--- /dev/null
+++ b/stdio-common/_i18n_itowa.h
@@ -0,0 +1,41 @@
+/* Internal function for converting integers to string using locale
+   specific digits.
+   Copyright (C) 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#ifndef _I18N_ITOWA_H
+#define _I18N_ITOWA_H
+#include <sys/cdefs.h>
+
+#include "../locale/outdigitswc.h"
+
+
+extern wchar_t *_i18n_itowa (unsigned long long int value, wchar_t *buflim);
+
+static inline wchar_t *
+_i18n_itowa_word (unsigned long int value, wchar_t *buflim)
+{
+  do
+    *--buflim = outdigitwc_value (value % 10);
+  while ((value /= 10) != 0);					      \
+
+  return buflim;
+}
+
+#endif	/* _i18n_itoa.h */
diff --git a/stdio-common/printf-parse.h b/stdio-common/printf-parse.h
index a8cb0345c3..64ecbe023f 100644
--- a/stdio-common/printf-parse.h
+++ b/stdio-common/printf-parse.h
@@ -1,5 +1,5 @@
 /* Internal header for parsing printf format strings.
-   Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
    This file is part of th GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -201,6 +201,11 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
 	   indicates any.  */
 	spec->info.group = 1;
 	break;
+      case L_('I'):
+	/* Use the internationalized form of the output.  Currently
+	   means to use the `outdigits' of the current locale.  */
+	spec->info.i18n = 1;
+	break;
       }
   if (spec->info.left)
     spec->info.pad = ' ';
diff --git a/stdio-common/printf.h b/stdio-common/printf.h
index 755f652ec2..c24a6fa454 100644
--- a/stdio-common/printf.h
+++ b/stdio-common/printf.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,95,96,97,98,99 Free Software Foundation, Inc.
+/* Copyright (C) 1991-1993, 1995-1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -46,6 +46,7 @@ struct printf_info
   unsigned int extra:1;		/* For special use.  */
   unsigned int is_char:1;	/* hh flag.  */
   unsigned int wide:1;		/* Nonzero for wide character streams.  */
+  unsigned int i18n:1;		/* I flag.  */
   wchar_t pad;			/* Padding character.  */
 };
 
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index d4145a7279..9d8785bf21 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
+/* Copyright (C) 1991-1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -27,6 +27,7 @@
 #include <bits/libc-lock.h>
 #include <sys/param.h>
 #include "_itoa.h"
+#include "_i18n_itoa.h"
 #include <locale/localeinfo.h>
 
 /* This code is shared between the standard stdio implementation found
@@ -80,6 +81,7 @@
 			  return -1
 # else
 # include "_itowa.h"
+# include "_i18n_itowa.h"
 
 #  define vfprintf	_IO_vfwprintf
 #  define CHAR_T	wchar_t
@@ -98,6 +100,9 @@
 
 #  define _itoa(Val, Buf, Base, Case) _itowa (Val, Buf, Base, Case)
 #  define _itoa_word(Val, Buf, Base, Case) _itowa_word (Val, Buf, Base, Case)
+#  define _i18n_itoa(Val, Buf, Base, Case) _i18n_itowa (Val, Buf, Base, Case)
+#  define _i18n_itoa_word(Val, Buf, Base, Case) \
+  _i18n_itowa_word (Val, Buf, Base, Case)
 #  undef EOF
 #  define EOF WEOF
 # endif
@@ -213,8 +218,13 @@ static int printf_unknown __P ((FILE *, const struct printf_info *,
 				const void *const *));
 
 /* Group digits of number string.  */
+#ifdef COMPILE_WPRINTF
 static CHAR_T *group_number __P ((CHAR_T *, CHAR_T *, const char *, wchar_t))
      internal_function;
+#else
+static CHAR_T *group_number __P ((CHAR_T *, CHAR_T *, const char *,
+				  const char *)) internal_function;
+#endif
 
 
 /* The function itself.  */
@@ -222,7 +232,11 @@ int
 vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 {
   /* The character used as thousands separator.  */
+#ifdef COMPILE_WPRINTF
   wchar_t thousands_sep;
+#else
+  const char *thousands_sep;
+#endif
 
   /* The string describing the size of groups of digits.  */
   const char *grouping;
@@ -254,6 +268,10 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
   /* Count number of specifiers we already processed.  */
   int nspecs_done;
 
+  /* This flag is set by the 'I' modifier and selects the use of the
+     `outdigits' as determined by the current locale.  */
+  int use_outdigits;
+
   /* For the %m format we may need the current `errno' value.  */
   int save_errno = errno;
 
@@ -273,7 +291,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 	       0,            0,            0,            0,
 	       0, /* 'A' */ 26,            0, /* 'C' */ 25,
 	       0, /* 'E' */ 19,            0, /* 'G' */ 19,
-	       0,            0,            0,            0,
+	       0, /* 'I' */ 29,            0,            0,
     /* 'L' */ 12,            0,            0,            0,
 	       0,            0,            0, /* 'S' */ 21,
 	       0,            0,            0,            0,
@@ -321,7 +339,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 
 #define STEP0_3_TABLE							      \
     /* Step 0: at the beginning.  */					      \
-    static JUMP_TABLE_TYPE step0_jumps[29] =				      \
+    static JUMP_TABLE_TYPE step0_jumps[30] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (flag_space),		/* for ' ' */				      \
@@ -352,9 +370,10 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_floathex),	/* for 'A', 'a' */			      \
       REF (mod_ptrdiff_t),      /* for 't' */				      \
       REF (mod_intmax_t),       /* for 'j' */				      \
+      REF (flag_i18n),	        /* for 'I' */				      \
     };									      \
     /* Step 1: after processing width.  */				      \
-    static JUMP_TABLE_TYPE step1_jumps[29] =				      \
+    static JUMP_TABLE_TYPE step1_jumps[30] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (form_unknown),	/* for ' ' */				      \
@@ -384,10 +403,11 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_wcharacter),	/* for 'C' */				      \
       REF (form_floathex),	/* for 'A', 'a' */			      \
       REF (mod_ptrdiff_t),      /* for 't' */				      \
-      REF (mod_intmax_t)        /* for 'j' */				      \
+      REF (mod_intmax_t),       /* for 'j' */				      \
+      REF (flag_i18n)	        /* for 'I' */				      \
     };									      \
     /* Step 2: after processing precision.  */				      \
-    static JUMP_TABLE_TYPE step2_jumps[29] =				      \
+    static JUMP_TABLE_TYPE step2_jumps[30] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (form_unknown),	/* for ' ' */				      \
@@ -417,10 +437,11 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_wcharacter),	/* for 'C' */				      \
       REF (form_floathex),	/* for 'A', 'a' */			      \
       REF (mod_ptrdiff_t),      /* for 't' */				      \
-      REF (mod_intmax_t)        /* for 'j' */				      \
+      REF (mod_intmax_t),       /* for 'j' */				      \
+      REF (flag_i18n)	        /* for 'I' */				      \
     };									      \
     /* Step 3a: after processing first 'h' modifier.  */		      \
-    static JUMP_TABLE_TYPE step3a_jumps[29] =				      \
+    static JUMP_TABLE_TYPE step3a_jumps[30] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (form_unknown),	/* for ' ' */				      \
@@ -450,10 +471,11 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_unknown),	/* for 'C' */				      \
       REF (form_unknown),	/* for 'A', 'a' */			      \
       REF (form_unknown),       /* for 't' */				      \
-      REF (form_unknown)        /* for 'j' */				      \
+      REF (form_unknown),       /* for 'j' */				      \
+      REF (form_unknown)        /* for 'I' */				      \
     };									      \
     /* Step 3b: after processing first 'l' modifier.  */		      \
-    static JUMP_TABLE_TYPE step3b_jumps[29] =				      \
+    static JUMP_TABLE_TYPE step3b_jumps[30] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (form_unknown),	/* for ' ' */				      \
@@ -483,12 +505,13 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_wcharacter),	/* for 'C' */				      \
       REF (form_floathex),	/* for 'A', 'a' */			      \
       REF (form_unknown),       /* for 't' */				      \
-      REF (form_unknown)        /* for 'j' */				      \
+      REF (form_unknown),       /* for 'j' */				      \
+      REF (form_unknown)        /* for 'I' */				      \
     }
 
 #define STEP4_TABLE							      \
     /* Step 4: processing format specifier.  */				      \
-    static JUMP_TABLE_TYPE step4_jumps[29] =				      \
+    static JUMP_TABLE_TYPE step4_jumps[30] =				      \
     {									      \
       REF (form_unknown),						      \
       REF (form_unknown),	/* for ' ' */				      \
@@ -518,7 +541,8 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       REF (form_wcharacter),	/* for 'C' */				      \
       REF (form_floathex),	/* for 'A', 'a' */			      \
       REF (form_unknown),       /* for 't' */				      \
-      REF (form_unknown)        /* for 'j' */				      \
+      REF (form_unknown),       /* for 'j' */				      \
+      REF (form_unknown)        /* for 'I' */				      \
     }
 
 
@@ -624,8 +648,11 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 	  else								      \
 	    {								      \
 	      /* Put the number in WORK.  */				      \
-	      string = _itoa (number.longlong, workend + 1, base,	      \
-			      spec == L_('X'));				      \
+	      if (use_outdigits && base == 10)				      \
+	        string = _i18n_itoa (number.longlong, workend + 1);	      \
+	      else							      \
+	        string = _itoa (number.longlong, workend + 1, base,	      \
+			        spec == L_('X'));			      \
 	      string -= 1;						      \
 	      if (group && grouping)					      \
 		string = group_number (string, workend, grouping,	      \
@@ -678,8 +705,11 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 	  else								      \
 	    {								      \
 	      /* Put the number in WORK.  */				      \
-	      string = _itoa_word (number.word, workend + 1, base,	      \
-				   spec == L_('X'));			      \
+	      if (use_outdigits && base == 10)				      \
+	        string = _i18n_itoa_word (number.word, workend + 1);	      \
+	      else							      \
+	        string = _itoa_word (number.word, workend + 1, base,	      \
+				     spec == L_('X'));			      \
 	      string -= 1;						      \
 	      if (group && grouping)					      \
 		string = group_number (string, workend, grouping,	      \
@@ -1302,26 +1332,31 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
     LABEL (flag_quote):
       group = 1;
 
-      /* XXX Completely wrong.  Use wctob.  */
       if (grouping == (const char *) -1)
 	{
-	  mbstate_t mbstate;
-
-	  /* Figure out the thousands separator character.  */
-	  memset (&mbstate, '\0', sizeof (mbstate));
-	  if (__mbrtowc (&thousands_sep,
-			 _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP),
-			 strlen (_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP)),
-			 &mbstate) <= 0)
-	    thousands_sep = (wchar_t)
-	      *_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
+#ifdef COMPILE_WPRINTF
+	  thousands_sep = _NL_CURRENT_WORD (LC_NUMERIC,
+					    _NL_NUMERIC_THOUSANDS_SEP_WC);
+#else
+	  thousands_sep = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
+#endif
+
 	  grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
 	  if (*grouping == '\0' || *grouping == CHAR_MAX
-	      || thousands_sep == L'\0')
+#ifdef COMPILE_WPRINTF
+	      || thousands_sep == L'\0'
+#else
+	      || *thousands_sep == '\0'
+#endif
+	      )
 	    grouping = NULL;
 	}
       JUMP (*++f, step0_jumps);
 
+    LABEL (flag_i18n):
+      use_outdigits = 1;
+      break;
+
       /* Get width from argument.  */
     LABEL (width_asterics):
       {
@@ -1492,18 +1527,15 @@ do_positional:
 
     if (grouping == (const char *) -1)
       {
-	mbstate_t mbstate;
-
-	/* Figure out the thousands separator character.  */
-	memset (&mbstate, '\0', sizeof (mbstate));
-	if (__mbrtowc (&thousands_sep,
-		       _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP),
-		       strlen (_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP)),
-		       &mbstate) <= 0)
-	  thousands_sep = (wchar_t) *_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
+#ifdef COMPILE_WPRINTF
+	thousands_sep = _NL_CURRENT_WORD (LC_NUMERIC,
+					  _NL_NUMERIC_THOUSANDS_SEP_WC);
+#else
+	thousands_sep = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
+#endif
+
 	grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
-	if (*grouping == '\0' || *grouping == CHAR_MAX
-	    || thousands_sep == L'\0')
+	if (*grouping == '\0' || *grouping == CHAR_MAX)
 	  grouping = NULL;
       }
 
@@ -1781,6 +1813,8 @@ printf_unknown (FILE *s, const struct printf_info *info,
     outchar (L_('-'));
   if (info->pad == L_('0'))
     outchar (L_('0'));
+  if (info->i18n)
+    outchar (L_('I'));
 
   if (info->width != 0)
     {
@@ -1809,10 +1843,18 @@ printf_unknown (FILE *s, const struct printf_info *info,
 static CHAR_T *
 internal_function
 group_number (CHAR_T *w, CHAR_T *rear_ptr, const char *grouping,
-	      wchar_t thousands_sep)
+#ifdef COMPILE_WPRINTF
+	      wchar_t thousands_sep
+#else
+	      const char *thousands_sep
+#endif
+	      )
 {
   int len;
   CHAR_T *src, *s;
+#ifndef COMPILE_WPRINTF
+  int tlen = strlen (thousands_sep);
+#endif
 
   /* We treat all negative values like CHAR_MAX.  */
 
@@ -1836,7 +1878,14 @@ group_number (CHAR_T *w, CHAR_T *rear_ptr, const char *grouping,
       if (--len == 0 && s >= src)
 	{
 	  /* A new group begins.  */
+#ifdef COMPILE_WPRINTF
 	  *w-- = thousands_sep;
+#else
+	  int cnt = tlen;
+	  do
+	    *w-- = thousands_sep[--cnt];
+	  while (cnt > 0);
+#endif
 
 	  len = *grouping++;
 	  if (*grouping == '\0')