Skip to content

Commit

Permalink
locale.c: Extract code into separate function
Browse files Browse the repository at this point in the history
This is in preparation for it being called from a second location in a
future commit.

Beyond the move, the only changes are to white space, and a
PERL_UNUSED_ARG.
  • Loading branch information
khwilliamson committed May 6, 2023
1 parent 8412a47 commit 200d844
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 59 deletions.
5 changes: 5 additions & 0 deletions embed.fnc
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions embed.h
Expand Up @@ -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)
Expand Down
124 changes: 65 additions & 59 deletions locale.c
Expand Up @@ -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

/*
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 200d844

Please sign in to comment.