diff --git a/embed.fnc b/embed.fnc index cebd412a2438..2c0886aa93e5 100644 --- a/embed.fnc +++ b/embed.fnc @@ -4337,6 +4337,11 @@ Ri |const char *|mortalized_pv_copy \ |NULLOK const char * const pv S |void |new_LC_ALL |NULLOK const char *unused \ |bool force +void +S |void |output_check_environment_warning \ + |NULLOK const char * const language \ + |NULLOK const char * const lc_all \ + |NULLOK const char * const lang So |void |restore_toggled_locale_i \ |const unsigned cat_index \ |NULLOK const char *original_locale \ diff --git a/embed.h b/embed.h index 5b6e5ef53d9a..c592f5c271b1 100644 --- a/embed.h +++ b/embed.h @@ -1282,6 +1282,7 @@ # define get_category_index_helper(a,b,c) S_get_category_index_helper(aTHX_ a,b,c) # define mortalized_pv_copy(a) S_mortalized_pv_copy(aTHX_ a) # define new_LC_ALL(a,b) S_new_LC_ALL(aTHX_ a,b) +# define output_check_environment_warning(a,b,c) S_output_check_environment_warning(aTHX_ a,b,c) # define save_to_buffer S_save_to_buffer # define setlocale_failure_panic_via_i(a,b,c,d,e,f,g) S_setlocale_failure_panic_via_i(aTHX_ a,b,c,d,e,f,g) # if defined(DEBUGGING) diff --git a/locale.c b/locale.c index 33da571f5910..8e9c04db050a 100644 --- a/locale.c +++ b/locale.c @@ -5916,6 +5916,70 @@ S_give_perl_locale_control(pTHX_ new_LC_ALL(NULL, true); } +STATIC void +S_output_check_environment_warning(pTHX_ const char * const language, + const char * const lc_all, + const char * const lang) +{ + PerlIO_printf(Perl_error_log, + "perl: warning: Please check that your locale settings:\n"); + +# ifdef __GLIBC__ + + PerlIO_printf(Perl_error_log, "\tLANGUAGE = %c%s%c,\n", + language ? '"' : '(', + language ? language : "unset", + language ? '"' : ')'); +# else + PERL_UNUSED_ARG(language); +# endif + + PerlIO_printf(Perl_error_log, "\tLC_ALL = %c%s%c,\n", + lc_all ? '"' : '(', + lc_all ? lc_all : "unset", + lc_all ? '"' : ')'); + +# if defined(USE_ENVIRON_ARRAY) + + { + char **e; + + /* Look through the environment for any variables of the + * form qr/ ^ LC_ [A-Z]+ = /x, except LC_ALL which was + * already handled above. These are assumed to be locale + * settings. Output them and their values. */ + for (e = environ; *e; e++) { + const STRLEN prefix_len = sizeof("LC_") - 1; + STRLEN uppers_len; + + if ( strBEGINs(*e, "LC_") + && ! strBEGINs(*e, "LC_ALL=") + && (uppers_len = strspn(*e + prefix_len, + "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) + && ((*e)[prefix_len + uppers_len] == '=')) + { + PerlIO_printf(Perl_error_log, "\t%.*s = \"%s\",\n", + (int) (prefix_len + uppers_len), *e, + *e + prefix_len + uppers_len + 1); + } + } + } + +# else + + PerlIO_printf(Perl_error_log, + "\t(possibly more locale environment variables)\n"); + +# endif + + PerlIO_printf(Perl_error_log, "\tLANG = %c%s%c\n", + lang ? '"' : '(', + lang ? lang : "unset", + lang ? '"' : ')'); + PerlIO_printf(Perl_error_log, + " are supported and installed on your system.\n"); +} + #endif /* @@ -6358,65 +6422,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn) # endif /* LC_ALL */ - PerlIO_printf(Perl_error_log, - "perl: warning: Please check that your locale settings:\n"); - -# ifdef __GLIBC__ - - PerlIO_printf(Perl_error_log, - "\tLANGUAGE = %c%s%c,\n", - language ? '"' : '(', - language ? language : "unset", - language ? '"' : ')'); -# endif - - PerlIO_printf(Perl_error_log, - "\tLC_ALL = %c%s%c,\n", - lc_all ? '"' : '(', - lc_all ? lc_all : "unset", - lc_all ? '"' : ')'); - -# if defined(USE_ENVIRON_ARRAY) - - { - char **e; - - /* Look through the environment for any variables of the - * form qr/ ^ LC_ [A-Z]+ = /x, except LC_ALL which was - * already handled above. These are assumed to be locale - * settings. Output them and their values. */ - for (e = environ; *e; e++) { - const STRLEN prefix_len = sizeof("LC_") - 1; - STRLEN uppers_len; - - if ( strBEGINs(*e, "LC_") - && ! strBEGINs(*e, "LC_ALL=") - && (uppers_len = strspn(*e + prefix_len, - "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) - && ((*e)[prefix_len + uppers_len] == '=')) - { - PerlIO_printf(Perl_error_log, "\t%.*s = \"%s\",\n", - (int) (prefix_len + uppers_len), *e, - *e + prefix_len + uppers_len + 1); - } - } - } - -# else - - PerlIO_printf(Perl_error_log, - "\t(possibly more locale environment variables)\n"); - -# endif - - PerlIO_printf(Perl_error_log, - "\tLANG = %c%s%c\n", - lang ? '"' : '(', - lang ? lang : "unset", - lang ? '"' : ')'); - - PerlIO_printf(Perl_error_log, - " are supported and installed on your system.\n"); + output_check_environment_warning(language, lc_all, lang); } /* Calculate what fallback locales to try. We have avoided this diff --git a/proto.h b/proto.h index 9050ca287441..94f5356d2541 100644 --- a/proto.h +++ b/proto.h @@ -6983,6 +6983,10 @@ STATIC void S_new_LC_ALL(pTHX_ const char *unused, bool force); # define PERL_ARGS_ASSERT_NEW_LC_ALL +STATIC void +S_output_check_environment_warning(pTHX_ const char * const language, const char * const lc_all, const char * const lang); +# define PERL_ARGS_ASSERT_OUTPUT_CHECK_ENVIRONMENT_WARNING + STATIC void S_restore_toggled_locale_i(pTHX_ const unsigned cat_index, const char *original_locale, const line_t caller_line); # define PERL_ARGS_ASSERT_RESTORE_TOGGLED_LOCALE_I