Patch for printf's "%If"

Hamed Malek hamed@bamdad.org
Thu Dec 18 11:26:00 GMT 2003


Attached is a patch for "%If" (and other similar) format strings to work
with printf and other such functions. This is required for Persian and
other locales which use localized digits (outdigit).  Currently, the 'I'
prefix works for decimal integers, which should be extended to decimal
floats.

I appreciate the patch being included. I consider the patch public domain. 
But please tell me if I need to sign a copyright assignment to FSF.

Hamed Malek
-------------- next part --------------
--- glibc/stdio-common/printf_fp.c.pIf	2003-12-04 14:51:16.000000000 +0330
+++ glibc/stdio-common/printf_fp.c	2003-12-04 15:10:38.000000000 +0330
@@ -43,6 +43,18 @@
 #include <stdlib.h>
 #include <wchar.h>
 
+#ifdef USE_IN_LIBIO
+# ifndef COMPILE_WPRINTF
+#  define CHAR_T        char
+# else
+#  define CHAR_T        wchar_t
+# endif
+#else
+# define CHAR_T         char
+#endif
+
+#include "_i18n_number.h"
+
 #ifndef NDEBUG
 # define NDEBUG			/* Undefine this for debugging assertions.  */
 #endif
@@ -1129,6 +1141,19 @@
 	}
 
       tmpptr = buffer;
+      if (info->i18n)
+        {
+          #ifdef USE_IN_LIBIO
+          # ifndef COMPILE_WPRINTF
+            tmpptr = _i18n_number_rewrite (tmpptr, cp);
+          # else
+            wstartp = _i18n_number_rewrite (wstartp, wcp);
+          # endif
+          #else
+            tmpptr = _i18n_number_rewrite (tmpptr, cp); 
+          #endif      
+        }
+
       PRINT (tmpptr, wstartp, wide ? wcp - wstartp : cp - tmpptr);
 
       /* Free the memory if necessary.  */
--- glibc/stdio-common/vfprintf.c.pIf	2003-12-04 14:51:16.000000000 +0330
+++ glibc/stdio-common/vfprintf.c	2003-12-04 15:34:18.000000000 +0330
@@ -817,6 +817,7 @@
 					.group = group,			      \
 					.pad = pad,			      \
 					.extra = 0,			      \
+					.i18n = use_outdigits,		      \
 					.wide = sizeof (CHAR_T) != 1 };	      \
 									      \
 	    if (is_long_double)						      \


More information about the Libc-alpha mailing list