bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changes in nl_langinfo() and strftime() API in glibc


From: Bruno Haible
Subject: Re: Changes in nl_langinfo() and strftime() API in glibc
Date: Wed, 24 Jan 2018 10:03:00 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-104-generic; KDE/5.18.0; x86_64; ; )

Rafal Luzynski wrote:
> Unfortunately,
> I'm afraid it will not even compile without the changes in nl_langinfo()
> because ALTMON_1 and _NL_ABALTMON_1 symbols are undefined.

No, Paul's patch was correct. Paul would never push a commit that does not
compile.

Paul Eggert wrote:
> I don't know the nl_langinfo code as well, though,

Done as follows:


2018-01-24  Bruno Haible  <address@hidden>

        langinfo, nl_langinfo: Add support for alternative month names.
        * m4/langinfo_h.m4 (gl_LANGINFO_H): Define HAVE_LANGINFO_ALTMON.
        * lib/langinfo.in.h (ALTMON_1...ALTMON_12): New macros.
        * lib/nl_langinfo.c (rpl_nl_langinfo): Treat ALTMON_i like MON_i.
        * tests/test-nl_langinfo.c (main): Test ALTMON_*.
        * doc/posix-headers/langinfo.texi: Document support of ALTMON_*.
        * doc/posix-functions/nl_langinfo.texi: Likewise.

diff --git a/doc/posix-functions/nl_langinfo.texi 
b/doc/posix-functions/nl_langinfo.texi
index cd9e523..529b0e9 100644
--- a/doc/posix-functions/nl_langinfo.texi
+++ b/doc/posix-functions/nl_langinfo.texi
@@ -15,6 +15,10 @@ Minix 3.1.8, mingw, MSVC 14, BeOS.
 The constant @code{CODESET} is not supported on some platforms:
 glibc 2.0.6, OpenBSD 3.8.
 @item
+The constants @code{ALTMON_1} to @code{ALTMON_12} are not defined on some
+platforms:
+glibc 2.26 and many others.
address@hidden
 The constants @code{ERA}, @code{ERA_D_FMT}, @code{ERA_D_T_FMT},
 @code{ERA_T_FMT}, @code{ALT_DIGITS} are not supported on some platforms:
 OpenBSD 3.8.
diff --git a/doc/posix-headers/langinfo.texi b/doc/posix-headers/langinfo.texi
index a4d1516..30ae66c 100644
--- a/doc/posix-headers/langinfo.texi
+++ b/doc/posix-headers/langinfo.texi
@@ -14,6 +14,10 @@ Minix 3.1.8, mingw, MSVC 14, BeOS.
 The constant @code{CODESET} is not defined on some platforms:
 glibc 2.0.6, OpenBSD 3.8.
 @item
+The constants @code{ALTMON_1} to @code{ALTMON_12} are not defined on some
+platforms:
+glibc 2.26 and many others.
address@hidden
 The constants @code{ERA}, @code{ERA_D_FMT}, @code{ERA_D_T_FMT},
 @code{ERA_T_FMT}, @code{ALT_DIGITS} are not defined on some platforms:
 OpenBSD 3.8.
diff --git a/lib/langinfo.in.h b/lib/langinfo.in.h
index e51bb57..31ac575 100644
--- a/lib/langinfo.in.h
+++ b/lib/langinfo.in.h
@@ -86,6 +86,18 @@ typedef int nl_item;
 # define MON_10      (MON_1 + 9)
 # define MON_11      (MON_1 + 10)
 # define MON_12      (MON_1 + 11)
+# define ALTMON_1    10200
+# define ALTMON_2    (ALTMON_1 + 1)
+# define ALTMON_3    (ALTMON_1 + 2)
+# define ALTMON_4    (ALTMON_1 + 3)
+# define ALTMON_5    (ALTMON_1 + 4)
+# define ALTMON_6    (ALTMON_1 + 5)
+# define ALTMON_7    (ALTMON_1 + 6)
+# define ALTMON_8    (ALTMON_1 + 7)
+# define ALTMON_9    (ALTMON_1 + 8)
+# define ALTMON_10   (ALTMON_1 + 9)
+# define ALTMON_11   (ALTMON_1 + 10)
+# define ALTMON_12   (ALTMON_1 + 11)
 # define ABMON_1     10035
 # define ABMON_2     (ABMON_1 + 1)
 # define ABMON_3     (ABMON_1 + 2)
@@ -138,6 +150,22 @@ typedef int nl_item;
 #  define GNULIB_defined_T_FMT_AMPM 1
 # endif
 
+# if address@hidden@
+#  define ALTMON_1    10200
+#  define ALTMON_2    (ALTMON_1 + 1)
+#  define ALTMON_3    (ALTMON_1 + 2)
+#  define ALTMON_4    (ALTMON_1 + 3)
+#  define ALTMON_5    (ALTMON_1 + 4)
+#  define ALTMON_6    (ALTMON_1 + 5)
+#  define ALTMON_7    (ALTMON_1 + 6)
+#  define ALTMON_8    (ALTMON_1 + 7)
+#  define ALTMON_9    (ALTMON_1 + 8)
+#  define ALTMON_10   (ALTMON_1 + 9)
+#  define ALTMON_11   (ALTMON_1 + 10)
+#  define ALTMON_12   (ALTMON_1 + 11)
+#  define GNULIB_defined_ALTMON 1
+# endif
+
 # if address@hidden@
 #  define ERA         10047
 #  define ERA_D_FMT   10048
diff --git a/lib/nl_langinfo.c b/lib/nl_langinfo.c
index 725ccf6..b93f7be 100644
--- a/lib/nl_langinfo.c
+++ b/lib/nl_langinfo.c
@@ -100,6 +100,24 @@ rpl_nl_langinfo (nl_item item)
     case T_FMT_AMPM:
       return (char *) "%I:%M:%S %p";
 # endif
+# if GNULIB_defined_ALTMON
+    case ALTMON_1:
+    case ALTMON_2:
+    case ALTMON_3:
+    case ALTMON_4:
+    case ALTMON_5:
+    case ALTMON_6:
+    case ALTMON_7:
+    case ALTMON_8:
+    case ALTMON_9:
+    case ALTMON_10:
+    case ALTMON_11:
+    case ALTMON_12:
+      /* We don't ship the appropriate localizations with gnulib.  Therefore,
+         treat ALTMON_i like MON_i.  */
+      item = item - ALTMON_1 + MON_1;
+      break;
+# endif
 # if GNULIB_defined_ERA
     case ERA:
       /* The format is not standardized.  In glibc it is a sequence of strings
@@ -228,28 +246,49 @@ nl_langinfo (nl_item item)
           return (char *) abdays[item - ABDAY_1];
         return nlbuf;
       }
-    case MON_1:
-    case MON_2:
-    case MON_3:
-    case MON_4:
-    case MON_5:
-    case MON_6:
-    case MON_7:
-    case MON_8:
-    case MON_9:
-    case MON_10:
-    case MON_11:
-    case MON_12:
-      {
-        static char const months[][sizeof "September"] = {
-          "January", "February", "March", "April", "May", "June", "July",
-          "September", "October", "November", "December"
-        };
+    {
+      static char const months[][sizeof "September"] = {
+        "January", "February", "March", "April", "May", "June", "July",
+        "September", "October", "November", "December"
+      };
+      case MON_1:
+      case MON_2:
+      case MON_3:
+      case MON_4:
+      case MON_5:
+      case MON_6:
+      case MON_7:
+      case MON_8:
+      case MON_9:
+      case MON_10:
+      case MON_11:
+      case MON_12:
         tmm.tm_mon = item - MON_1;
         if (!strftime (nlbuf, sizeof nlbuf, "%B", &tmm))
           return (char *) months[item - MON_1];
         return nlbuf;
-      }
+      case ALTMON_1:
+      case ALTMON_2:
+      case ALTMON_3:
+      case ALTMON_4:
+      case ALTMON_5:
+      case ALTMON_6:
+      case ALTMON_7:
+      case ALTMON_8:
+      case ALTMON_9:
+      case ALTMON_10:
+      case ALTMON_11:
+      case ALTMON_12:
+        tmm.tm_mon = item - ALTMON_1;
+        /* The platforms without nl_langinfo() don't support strftime with %OB.
+           We don't even need to try.  */
+        #if 0
+        if (!strftime (nlbuf, sizeof nlbuf, "%OB", &tmm))
+        #endif
+          if (!strftime (nlbuf, sizeof nlbuf, "%B", &tmm))
+            return (char *) months[item - ALTMON_1];
+        return nlbuf;
+    }
     case ABMON_1:
     case ABMON_2:
     case ABMON_3:
diff --git a/m4/langinfo_h.m4 b/m4/langinfo_h.m4
index 9ae375c..de077c3 100644
--- a/m4/langinfo_h.m4
+++ b/m4/langinfo_h.m4
@@ -1,4 +1,4 @@
-# langinfo_h.m4 serial 7
+# langinfo_h.m4 serial 8
 dnl Copyright (C) 2009-2018 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -17,6 +17,7 @@ AC_DEFUN([gl_LANGINFO_H],
   dnl Determine whether <langinfo.h> exists. It is missing on mingw and BeOS.
   HAVE_LANGINFO_CODESET=0
   HAVE_LANGINFO_T_FMT_AMPM=0
+  HAVE_LANGINFO_ALTMON=0
   HAVE_LANGINFO_ERA=0
   HAVE_LANGINFO_YESEXPR=0
   AC_CHECK_HEADERS_ONCE([langinfo.h])
@@ -24,6 +25,7 @@ AC_DEFUN([gl_LANGINFO_H],
     HAVE_LANGINFO_H=1
     dnl Determine what <langinfo.h> defines. CODESET and ERA etc. are missing
     dnl on OpenBSD 3.8. T_FMT_AMPM and YESEXPR, NOEXPR are missing on IRIX 5.3.
+    dnl ALTMON_* are missing on glibc 2.26 and many other systems.
     AC_CACHE_CHECK([whether langinfo.h defines CODESET],
       [gl_cv_header_langinfo_codeset],
       [AC_COMPILE_IFELSE(
@@ -48,6 +50,18 @@ int a = T_FMT_AMPM;
     if test $gl_cv_header_langinfo_t_fmt_ampm = yes; then
       HAVE_LANGINFO_T_FMT_AMPM=1
     fi
+    AC_CACHE_CHECK([whether langinfo.h defines ALTMON_1],
+      [gl_cv_header_langinfo_altmon],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM([[#include <langinfo.h>
+int a = ALTMON_1;
+]])],
+         [gl_cv_header_langinfo_altmon=yes],
+         [gl_cv_header_langinfo_altmon=no])
+      ])
+    if test $gl_cv_header_langinfo_altmon = yes; then
+      HAVE_LANGINFO_ALTMON=1
+    fi
     AC_CACHE_CHECK([whether langinfo.h defines ERA],
       [gl_cv_header_langinfo_era],
       [AC_COMPILE_IFELSE(
@@ -78,6 +92,7 @@ int a = YESEXPR;
   AC_SUBST([HAVE_LANGINFO_H])
   AC_SUBST([HAVE_LANGINFO_CODESET])
   AC_SUBST([HAVE_LANGINFO_T_FMT_AMPM])
+  AC_SUBST([HAVE_LANGINFO_ALTMON])
   AC_SUBST([HAVE_LANGINFO_ERA])
   AC_SUBST([HAVE_LANGINFO_YESEXPR])
 
diff --git a/tests/test-nl_langinfo.c b/tests/test-nl_langinfo.c
index 8ad9df1..a13fb71 100644
--- a/tests/test-nl_langinfo.c
+++ b/tests/test-nl_langinfo.c
@@ -92,6 +92,32 @@ main (int argc, char *argv[])
   ASSERT (strlen (nl_langinfo (MON_10)) > 0);
   ASSERT (strlen (nl_langinfo (MON_11)) > 0);
   ASSERT (strlen (nl_langinfo (MON_12)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_1)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_2)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_3)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_4)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_5)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_6)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_7)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_8)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_9)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_10)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_11)) > 0);
+  ASSERT (strlen (nl_langinfo (ALTMON_12)) > 0);
+  /* In the tested locales, alternate month names and month names ought to be
+     the same.  */
+  ASSERT (strcmp (nl_langinfo (ALTMON_1), nl_langinfo (MON_1)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_2), nl_langinfo (MON_2)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_3), nl_langinfo (MON_3)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_4), nl_langinfo (MON_4)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_5), nl_langinfo (MON_5)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_6), nl_langinfo (MON_6)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_7), nl_langinfo (MON_7)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_8), nl_langinfo (MON_8)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_9), nl_langinfo (MON_9)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_10), nl_langinfo (MON_10)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_11), nl_langinfo (MON_11)) == 0);
+  ASSERT (strcmp (nl_langinfo (ALTMON_12), nl_langinfo (MON_12)) == 0);
   ASSERT (strlen (nl_langinfo (ABMON_1)) > 0);
   ASSERT (strlen (nl_langinfo (ABMON_2)) > 0);
   ASSERT (strlen (nl_langinfo (ABMON_3)) > 0);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]