# HG changeset patch # User Bruno Haible # Date 1516784537 -3600 # Node ID c67645792a3d965883f357efb2dab3d9871fe8c5 # Parent a188a4c517c4e7fa38c0ee6e957a9cf9be46b964 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 -r a188a4c517c4 -r c67645792a3d ChangeLog --- a/ChangeLog Tue Jan 23 00:42:04 2018 -0800 +++ b/ChangeLog Wed Jan 24 10:02:17 2018 +0100 @@ -1,3 +1,13 @@ +2018-01-24 Bruno Haible + + 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. + 2018-01-23 Paul Eggert Merge strftime.c changes from glibc diff -r a188a4c517c4 -r c67645792a3d doc/posix-functions/nl_langinfo.texi --- a/doc/posix-functions/nl_langinfo.texi Tue Jan 23 00:42:04 2018 -0800 +++ b/doc/posix-functions/nl_langinfo.texi Wed Jan 24 10:02:17 2018 +0100 @@ -15,6 +15,10 @@ 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. +@item 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 -r a188a4c517c4 -r c67645792a3d doc/posix-headers/langinfo.texi --- a/doc/posix-headers/langinfo.texi Tue Jan 23 00:42:04 2018 -0800 +++ b/doc/posix-headers/langinfo.texi Wed Jan 24 10:02:17 2018 +0100 @@ -14,6 +14,10 @@ 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. +@item 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 -r a188a4c517c4 -r c67645792a3d lib/langinfo.in.h --- a/lib/langinfo.in.h Tue Jan 23 00:42:04 2018 -0800 +++ b/lib/langinfo.in.h Wed Jan 24 10:02:17 2018 +0100 @@ -86,6 +86,18 @@ # 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 @@ # define GNULIB_defined_T_FMT_AMPM 1 # endif +# if !@HAVE_LANGINFO_ALTMON@ +# 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 !@HAVE_LANGINFO_ERA@ # define ERA 10047 # define ERA_D_FMT 10048 diff -r a188a4c517c4 -r c67645792a3d lib/nl_langinfo.c --- a/lib/nl_langinfo.c Tue Jan 23 00:42:04 2018 -0800 +++ b/lib/nl_langinfo.c Wed Jan 24 10:02:17 2018 +0100 @@ -100,6 +100,24 @@ 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 @@ 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 -r a188a4c517c4 -r c67645792a3d m4/langinfo_h.m4 --- a/m4/langinfo_h.m4 Tue Jan 23 00:42:04 2018 -0800 +++ b/m4/langinfo_h.m4 Wed Jan 24 10:02:17 2018 +0100 @@ -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 @@ dnl Determine whether 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 @@ HAVE_LANGINFO_H=1 dnl Determine what 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 @@ 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 +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 @@ 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 -r a188a4c517c4 -r c67645792a3d tests/test-nl_langinfo.c --- a/tests/test-nl_langinfo.c Tue Jan 23 00:42:04 2018 -0800 +++ b/tests/test-nl_langinfo.c Wed Jan 24 10:02:17 2018 +0100 @@ -92,6 +92,32 @@ 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);