Skip to content

Commit

Permalink
locale.c: Add a fcn to display LC_ALL
Browse files Browse the repository at this point in the history
This is trivial on a platform that has LC_ALL, but requires extra work
on platforms that don't.
  • Loading branch information
khwilliamson committed May 9, 2021
1 parent 47f5861 commit 4ebd582
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions embed.fnc
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions embed.h
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions locale.c
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions proto.h
Expand Up @@ -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);
Expand Down

0 comments on commit 4ebd582

Please sign in to comment.