From 878b0f7d1d4c7597140a3f64227c6e247e388d79 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Mon, 12 Apr 2021 15:20:00 -0600 Subject: [PATCH] locale.c: Add a fcn to display LC_ALL This is trivial on a platform that has LC_ALL, but requires extra work on platforms that don't. --- embed.fnc | 1 + embed.h | 1 + locale.c | 30 ++++++++++++++++++++++++++++++ proto.h | 4 ++-- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/embed.fnc b/embed.fnc index 14001230ca43..9d1aa23af74e 100644 --- a/embed.fnc +++ b/embed.fnc @@ -3233,6 +3233,7 @@ SG |bool |sv_derived_from_svpvn |NULLOK SV *sv \ #if defined(PERL_IN_LOCALE_C) # ifdef USE_LOCALE ST |unsigned int|get_category_index|const int category|NULLOK const char * locale +S |const char *|get_LC_ALL_display S |unsigned|get_locale_string_utf8ness_i \ |NULLOK const char * locale \ |const unsigned cat_index \ diff --git a/embed.h b/embed.h index 2d5781aef241..3e2081959e4b 100644 --- a/embed.h +++ b/embed.h @@ -1740,6 +1740,7 @@ # endif # if defined(PERL_IN_LOCALE_C) # if defined(USE_LOCALE) +#define get_LC_ALL_display() S_get_LC_ALL_display(aTHX) #define get_category_index S_get_category_index #define get_locale_string_utf8ness_i(a,b,c,d) S_get_locale_string_utf8ness_i(aTHX_ a,b,c,d) #define is_codeset_name_UTF8 S_is_codeset_name_UTF8 diff --git a/locale.c b/locale.c index 87b3ee144432..e71748b9d88d 100644 --- a/locale.c +++ b/locale.c @@ -1612,6 +1612,36 @@ S_calculate_LC_ALL(pTHX_ const char ** individ_locales) return aggregate_locale; } +STATIC const char * +S_get_LC_ALL_display(pTHX) +{ + +# ifdef LC_ALL + + return querylocale_c(LC_ALL); + +# else + + unsigned int i; + const char * retval; + const char * curlocales[NOMINAL_LC_ALL_INDEX]; + + for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { + curlocales[i] = savepv(querylocale_i(i)); + } + + retval = calculate_LC_ALL(curlocales); + + for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { + Safefree(curlocales[i]); + } + + return retval; + +# endif + +} + STATIC void S_setlocale_failure_panic_i(pTHX_ const unsigned int cat_index, diff --git a/proto.h b/proto.h index 46015b8a75c5..64a2fc4b2824 100644 --- a/proto.h +++ b/proto.h @@ -5184,6 +5184,8 @@ PERL_CALLCONV SV* Perl_hfree_next_entry(pTHX_ HV *hv, STRLEN *indexp); #endif #if defined(PERL_IN_LOCALE_C) # if defined(USE_LOCALE) +STATIC const char * S_get_LC_ALL_display(pTHX); +#define PERL_ARGS_ASSERT_GET_LC_ALL_DISPLAY STATIC unsigned int S_get_category_index(const int category, const char * locale); #define PERL_ARGS_ASSERT_GET_CATEGORY_INDEX STATIC unsigned S_get_locale_string_utf8ness_i(pTHX_ const char * locale, const unsigned cat_index, const char * string, const int known_utf8); @@ -5209,8 +5211,6 @@ STATIC void S_restore_toggled_locale_i(pTHX_ const unsigned cat_index, const cha #define PERL_ARGS_ASSERT_RESTORE_TOGGLED_LOCALE_I STATIC const char * S_save_to_buffer(const char * string, const char **buf, Size_t *buf_size); #define PERL_ARGS_ASSERT_SAVE_TO_BUFFER -STATIC void S_set_numeric_radix(pTHX_ const bool use_locale); -#define PERL_ARGS_ASSERT_SET_NUMERIC_RADIX PERL_STATIC_NO_RET void S_setlocale_failure_panic_i(pTHX_ const unsigned int cat_index, const char * current, const char * failed, const line_t caller_0_line, const line_t caller_1_line) __attribute__noreturn__; #define PERL_ARGS_ASSERT_SETLOCALE_FAILURE_PANIC_I \