Skip to content

Commit

Permalink
locale.c: Refactor Ultrix code
Browse files Browse the repository at this point in the history
Examination shows that this code does nothing unless LC_ALL is defined.
So explicitly test at compile time for that.

Also, two variables don't have to be declared so globally, and by
reducing their scope, by creating a new block we don't have to have
PERL_UNUSED_ARG()s for them
  • Loading branch information
khwilliamson committed Jan 13, 2018
1 parent 42888ca commit 924bb4f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions locale.c
Expand Up @@ -1891,16 +1891,13 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
/* disallow with "" or "0" */
*bad_lang_use_once
&& strNE("0", bad_lang_use_once)))));
bool done = FALSE;
/* setlocale() return vals; not copied so must be looked at immediately */
const char * sl_result[NOMINAL_LC_ALL_INDEX + 1];

/* current locale for given category; should have been copied so aren't
* volatile */
const char * curlocales[NOMINAL_LC_ALL_INDEX + 1];

char * locale_param;

# ifdef WIN32

/* In some systems you can find out the system default locale
Expand Down Expand Up @@ -1982,20 +1979,19 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
assert(NOMINAL_LC_ALL_INDEX == LC_ALL_INDEX);
# endif
# endif /* DEBUGGING */
# ifndef LOCALE_ENVIRON_REQUIRED

PERL_UNUSED_VAR(done);
PERL_UNUSED_VAR(locale_param);

# else
# ifdef LOCALE_ENVIRON_REQUIRED

/*
* Ultrix setlocale(..., "") fails if there are no environment
* variables from which to get a locale name.
*/

# ifdef LC_ALL
# ifndef LC_ALL
# error Ultrix without LC_ALL not implemented
# else

{
bool done = FALSE;
if (lang) {
sl_result[LC_ALL_INDEX] = do_setlocale_c(LC_ALL, setlocale_init);
DEBUG_LOCALE_INIT(LC_ALL, setlocale_init, sl_result[LC_ALL_INDEX]);
Expand All @@ -2005,6 +2001,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
setlocale_failure = TRUE;
}
if (! setlocale_failure) {
const char * locale_param;
for (i = 0; i < LC_ALL_INDEX; i++) {
locale_param = (! done && (lang || PerlEnv_getenv(category_names[i])))
? setlocale_init
Expand All @@ -2016,6 +2013,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
DEBUG_LOCALE_INIT(categories[i], locale_param, sl_result[i]);
}
}
}

# endif /* LC_ALL */
# endif /* LOCALE_ENVIRON_REQUIRED */
Expand Down

0 comments on commit 924bb4f

Please sign in to comment.