This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] [PATCH] Support ABALTMON_* constants


This provides the ABALTMON_* constants in langinfo.h, conditionalized on
__USE_GNU, and updates uses of _NL_ABALTMON_* accordingly.
Documentation is updated, as well as the NEWS entry.

This patch is based on Rafal's alternate month name patchset.

I understand this probably won't go in at this point, but I still wrote
it like it was going to, in case we did want to provide the ABALTMON
constants at the same time as ALTMON.  The patch seems straightforward,
but aside from passing a build and not introducing new testsuite
failures, I'm not sure what else I can test right now.

Rical
From e5c64212810bf4d84769fa70e4b0959e0e9714b6 Mon Sep 17 00:00:00 2001
From: Rical Jasan <ricaljasan@deathguild.net>
Date: Sat, 20 Jan 2018 02:23:32 -0800
Subject: [PATCH] Support ABALTMON_* constants.

ABALTMON is a natural addition to the MON, ABMON, and ALTMON constants
used for formatting month names.  The functionality for abbreviated
alternative months names is already implemented, but the corresponding
constants weren't defined.  This commit adds them as a GNU extension.

	* NEWS: Update recommended nl_langinfo constants for
	abbreviated alternative month names.
	* locale/categories.def (LC_TIME): Change _NL_ABALTMON_1 to
	ABALTMON_1.
	* locale/langinfo.h [__USE_GNU] (ABALTMON_1, ABALTMON_2,
	ABALTMON_3, ABALTMON_4, ABALTMON_5, ABALTMON_6, ABALTMON_7,
	ABALTMON_8, ABALTMON_9, ABALTMON_10, ABALTMON_11,
	ABALTMON_12): New macros.
	* locale/nl_langinfo_l.c (__nl_langinfo_noaltmon_l): Convert
	use of _NL_ABALTMON_1 to ABALTMON_1.
	* manual/locale.texi (nl_langinfo): Document the new
	ABALTMON_* constants.
	* time/strftime_l.c: Remove unnecessary define of ABALTMON_1.
	* time/strptime_l.c (ab_alt_month_name): Convert use of
	_NL_ABALTMON_1 to ABALTMON_1.
	(__strptime_internal): Likewise.
---
 NEWS                   |  2 +-
 locale/categories.def  |  2 +-
 locale/langinfo.h      | 14 ++++++++++++++
 locale/nl_langinfo_l.c |  6 +++---
 manual/locale.texi     | 24 ++++++++++++++++++++----
 time/strftime_l.c      |  1 -
 time/strptime_l.c      |  6 +++---
 7 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/NEWS b/NEWS
index dd8b7956b2..243fa499bb 100644
--- a/NEWS
+++ b/NEWS
@@ -82,7 +82,7 @@ Major new features:
   name---standalone or complete, abbreviated or full.  In a call to
   nl_langinfo, the query constants MON_1..12 and ABMON_1..12 return
   the strings used by "%B" and "%b", respectively.  New query
-  constants ALTMON_1..12 and _NL_ABALTMON_1..12 return the strings
+  constants ALTMON_1..12 and ABALTMON_1..12 return the strings
   used by "%OB" and "%Ob", respectively.
 
   In a locale definition file, use "alt_mon" and "ab_alt_mon" to
diff --git a/locale/categories.def b/locale/categories.def
index 56c5f88f6e..9476e02672 100644
--- a/locale/categories.def
+++ b/locale/categories.def
@@ -251,7 +251,7 @@ DEFINE_CATEGORY
   DEFINE_ELEMENT (_NL_TIME_CODESET,	    "time-codeset",	   std, string)
   DEFINE_ELEMENT (ALTMON_1,        "alt_mon",         opt, stringarray,  12, 12)
   DEFINE_ELEMENT (_NL_WALTMON_1,   "wide-alt_mon",    opt, wstringarray, 12, 12)
-  DEFINE_ELEMENT (_NL_ABALTMON_1,  "ab_alt_mon",      opt, stringarray,  12, 12)
+  DEFINE_ELEMENT (ABALTMON_1,      "ab_alt_mon",      opt, stringarray,  12, 12)
   DEFINE_ELEMENT (_NL_WABALTMON_1, "wide-ab_alt_mon", opt, wstringarray, 12, 12)
   ), NO_POSTLOAD)
 
diff --git a/locale/langinfo.h b/locale/langinfo.h
index a50cc9b568..d221e074ae 100644
--- a/locale/langinfo.h
+++ b/locale/langinfo.h
@@ -293,6 +293,20 @@ enum
   _NL_ABALTMON_10,
   _NL_ABALTMON_11,
   _NL_ABALTMON_12,
+#ifdef __USE_GNU
+# define ABALTMON_1		_NL_ABALTMON_1
+# define ABALTMON_2		_NL_ABALTMON_2
+# define ABALTMON_3		_NL_ABALTMON_3
+# define ABALTMON_4		_NL_ABALTMON_4
+# define ABALTMON_5		_NL_ABALTMON_5
+# define ABALTMON_6		_NL_ABALTMON_6
+# define ABALTMON_7		_NL_ABALTMON_7
+# define ABALTMON_8		_NL_ABALTMON_8
+# define ABALTMON_9		_NL_ABALTMON_9
+# define ABALTMON_10		_NL_ABALTMON_10
+# define ABALTMON_11		_NL_ABALTMON_11
+# define ABALTMON_12		_NL_ABALTMON_12
+#endif
 
   /* Abbreviated month names, in the grammatical form used when the month
      is named by itself.  */
diff --git a/locale/nl_langinfo_l.c b/locale/nl_langinfo_l.c
index 4ec6ce6f0d..15254b745b 100644
--- a/locale/nl_langinfo_l.c
+++ b/locale/nl_langinfo_l.c
@@ -82,7 +82,7 @@ __nl_langinfo_noaltmon_l (nl_item item, locale_t l)
 {
   if ((item >= ALTMON_1 && item <= ALTMON_12)
       || (item >= _NL_WALTMON_1 && item <= _NL_WALTMON_12)
-      || (item >= _NL_ABALTMON_1 && item <= _NL_ABALTMON_12)
+      || (item >= ABALTMON_1 && item <= ABALTMON_12)
       || (item >= _NL_WABALTMON_1 && item <= _NL_WABALTMON_12))
     /* Pretend it's a bogus index for this category: bogus item.  */
     return (char *) "";
@@ -98,8 +98,8 @@ __nl_langinfo_noaltmon_l (nl_item item, locale_t l)
     }
   else if (item >= ABMON_1 && item <= ABMON_12)
     {
-      /* _NL_ABALTMON... item contains what ABMON_... item contained before.  */
-      return __nl_langinfo_l (item + _NL_ABALTMON_1 - ABMON_1, l);
+      /* ABALTMON... item contains what ABMON_... item contained before.  */
+      return __nl_langinfo_l (item + ABALTMON_1 - ABMON_1, l);
     }
   else if (item >= _NL_WABMON_1 && item <= _NL_WABMON_12)
     {
diff --git a/manual/locale.texi b/manual/locale.texi
index 19b1cfc421..db77e54516 100644
--- a/manual/locale.texi
+++ b/manual/locale.texi
@@ -974,11 +974,27 @@ use these month names for the conversion specifier @code{%OB}
 Note that not all languages need two different forms of the month names,
 so the strings returned for @code{MON_@dots{}} and @code{ALTMON_@dots{}}
 may or may not be the same, depending on the locale.
+@item ABALTMON_1
+@itemx ABALTMON_2
+@itemx ABALTMON_3
+@itemx ABALTMON_4
+@itemx ABALTMON_5
+@itemx ABALTMON_6
+@itemx ABALTMON_7
+@itemx ABALTMON_8
+@itemx ABALTMON_9
+@itemx ABALTMON_10
+@itemx ABALTMON_11
+@itemx ABALTMON_12
+Similar to @code{ALTMON_1}, etc.,@: but here the month names are abbreviated.
+The @code{strftime} functions use these month names for the conversion
+specifiers @code{%Ob} and @code{%Oh} (@pxref{Formatting Calendar Time}).
 
-@strong{NB:} @code{ABALTMON_@dots{}} constants corresponding to the @code{%Ob}
-conversion specifier are not currently provided, but are expected to be in a
-future release.  In the meantime, it is possible to use
-@code{_NL_ABALTMON_@dots{}}.
+Note that not all languages need two different forms of the month names,
+so the strings returned for @code{ABMON_@dots{}} and @code{ABALTMON_@dots{}}
+may or may not be the same, depending on the locale.
+
+These constants are a GNU extension.
 @item AM_STR
 @itemx PM_STR
 The return values are strings which can be used in the representation of time
diff --git a/time/strftime_l.c b/time/strftime_l.c
index 85305b4652..93f0996a11 100644
--- a/time/strftime_l.c
+++ b/time/strftime_l.c
@@ -108,7 +108,6 @@ extern char *tzname[];
 # define UCHAR_T unsigned char
 # define L_(Str) Str
 # define NLW(Sym) Sym
-# define ABALTMON_1 _NL_ABALTMON_1
 
 # if !defined STDC_HEADERS && !defined HAVE_MEMCPY
 #  define MEMCPY(d, s, n) bcopy ((s), (d), (n))
diff --git a/time/strptime_l.c b/time/strptime_l.c
index cd901c2606..42c8af4f3d 100644
--- a/time/strptime_l.c
+++ b/time/strptime_l.c
@@ -127,7 +127,7 @@ extern const struct __locale_data _nl_C_LC_TIME attribute_hidden;
 # define alt_month_name \
   (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ALTMON_1)].string)
 # define ab_alt_month_name \
-  (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (_NL_ABALTMON_1)].string)
+  (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABALTMON_1)].string)
 # define HERE_D_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_T_FMT)].string)
 # define HERE_D_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_FMT)].string)
 # define HERE_AM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (AM_STR)].string)
@@ -440,14 +440,14 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tmp,
 			decided_longest = loc;
 		    }
 		  trp = rp;
-		  if (match_string (_NL_CURRENT (LC_TIME, _NL_ABALTMON_1 + cnt),
+		  if (match_string (_NL_CURRENT (LC_TIME, ABALTMON_1 + cnt),
 				    trp)
 		      && trp > rp_longest)
 		    {
 		      rp_longest = trp;
 		      cnt_longest = cnt;
 		      if (s.decided == not
-			  && strcmp (_NL_CURRENT (LC_TIME, _NL_ABALTMON_1 + cnt),
+			  && strcmp (_NL_CURRENT (LC_TIME, ABALTMON_1 + cnt),
 				     alt_month_name[cnt]))
 			decided_longest = loc;
 		    }
-- 
2.14.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]