bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] nstrftime: allow opt-out of AM/PM adjustment


From: Paul Eggert
Subject: [PATCH] nstrftime: allow opt-out of AM/PM adjustment
Date: Tue, 13 Feb 2024 22:30:13 -0800

For Emacs I would rather avoid bringing in the Gnulib locking code,
since Emacs has its own idea about locks and its main engine is
single-threaded anyway.
Provide a way to use the nstrftime module while avoiding its
recently-added localename dependency, which entails locking code.
(It’s not clear to me that the locking code is needed for nstrftime,
as NetBSD has strftime_z and Solaris locales could be inspected in
some thread-safe way, e.g., by probing strftime month names.
Anyway, all that’s more hassle than I want to put up with right now
for the trivial matter of AM/PM behavior.)
* lib/strftime.c (REQUIRE_GNUISH_STRFTIME_AM_PM):
New macro, which can be overridden by config.h.
(should_remove_ampm, __strftime_internal):
Use it instead of !USE_C_LOCALE when deciding to
implement Gnuish AM/PM behavior.
---
 ChangeLog      | 19 +++++++++++++++++++
 lib/strftime.c | 19 ++++++++++++++++---
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6f43de09f7..2e3959591d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2024-02-13  Paul Eggert  <eggert@cs.ucla.edu>
+
+       nstrftime: allow opt-out of AM/PM adjustment
+       For Emacs I would rather avoid bringing in the Gnulib locking code,
+       since Emacs has its own idea about locks and its main engine is
+       single-threaded anyway.
+       Provide a way to use the nstrftime module while avoiding its
+       recently-added localename dependency, which entails locking code.
+       (It’s not clear to me that the locking code is needed for nstrftime,
+       as NetBSD has strftime_z and Solaris locales could be inspected in
+       some thread-safe way, e.g., by probing strftime month names.
+       Anyway, all that’s more hassle than I want to put up with right now
+       for the trivial matter of AM/PM behavior.)
+       * lib/strftime.c (REQUIRE_GNUISH_STRFTIME_AM_PM):
+       New macro, which can be overridden by config.h.
+       (should_remove_ampm, __strftime_internal):
+       Use it instead of !USE_C_LOCALE when deciding to
+       implement Gnuish AM/PM behavior.
+
 2024-02-13  Bruno Haible  <bruno@clisp.org>
 
        uniwidth/width tests: Update unit test for last commit.
diff --git a/lib/strftime.c b/lib/strftime.c
index b6c0b11e00..c7256c3d35 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -39,6 +39,19 @@
 # include "time-internal.h"
 #endif
 
+/* Whether to require GNU behavior for AM and PM indicators, even on
+   other platforms.  This matters only in non-C locales.
+   The default is to require it; you can override this via
+   AC_DEFINE([REQUIRE_GNUISH_STRFTIME_AM_PM], 1) and if you do that
+   you may be able to omit Gnulib's localename module and its dependencies.  */
+#ifndef REQUIRE_GNUISH_STRFTIME_AM_PM
+# define REQUIRE_GNUISH_STRFTIME_AM_PM true
+#endif
+#if USE_C_LOCALE
+# undef REQUIRE_GNUISH_STRFTIME_AM_PM
+# define REQUIRE_GNUISH_STRFTIME_AM_PM false
+#endif
+
 #if USE_C_LOCALE
 # include "c-ctype.h"
 #else
@@ -83,7 +96,7 @@ extern char *tzname[];
 # include <locale.h>
 #endif
 
-#if (defined __NetBSD__ || defined __sun) && !USE_C_LOCALE
+#if (defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM
 # include <locale.h>
 # include "localename.h"
 #endif
@@ -375,7 +388,7 @@ c_locale (void)
 #endif
 
 
-#if (defined __NetBSD__ || defined __sun) && !USE_C_LOCALE
+#if (defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM
 
 /* Return true if an AM/PM indicator should be removed.  */
 static bool
@@ -1361,7 +1374,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG 
(size_t maxsize)
                           }
                       }
                   }
-#  if !USE_C_LOCALE
+#  if REQUIRE_GNUISH_STRFTIME_AM_PM
                 /* The output of the strftime %p and %r directives contains
                    an AM/PM indicator even for locales where it is not
                    suitable, such as French.  Remove this indicator.  */
-- 
2.43.0




reply via email to

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