diff options
author | Peter Stephenson <p.w.stephenson@ntlworld.com> | 2020-05-05 20:28:31 +0100 |
---|---|---|
committer | Peter Stephenson <p.w.stephenson@ntlworld.com> | 2020-05-05 20:28:31 +0100 |
commit | c486040220e07f2d9fbf45fe6b74f46b669553dc (patch) | |
tree | bb74c9d31facb89fe17b4b10ba3338bb1a08aa65 /Src | |
parent | 455c80e4bbeb10e68f7a0e8d9296097c20c15949 (diff) | |
download | zsh-c486040220e07f2d9fbf45fe6b74f46b669553dc.tar.gz zsh-c486040220e07f2d9fbf45fe6b74f46b669553dc.tar.xz zsh-c486040220e07f2d9fbf45fe6b74f46b669553dc.zip |
45772: Restore locale on parameter scope end.
Check if relevant parameters changes and if so restore system settings.
Diffstat (limited to 'Src')
-rw-r--r-- | Src/params.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Src/params.c b/Src/params.c index 863b32600..122f5da7d 100644 --- a/Src/params.c +++ b/Src/params.c @@ -5569,6 +5569,14 @@ startparamscope(void) locallevel++; } +#ifdef USE_LOCALE +/* + * Flag that one of the special LC_ functions or LANG changed on scope + * end + */ +static int lc_update_needed; +#endif /* USE_LOCALE */ + /* End a parameter scope: delete the parameters local to the scope. */ /**/ @@ -5579,7 +5587,28 @@ endparamscope(void) locallevel--; /* This pops anything from a higher locallevel */ saveandpophiststack(0, HFILE_USE_OPTIONS); +#ifdef USE_LOCALE + lc_update_needed = 0; +#endif scanhashtable(paramtab, 0, 0, 0, scanendscope, 0); +#ifdef USE_LOCALE + if (lc_update_needed) + { + /* Locale changed --- ensure it is restored. */ + char *val; + if ((val = getsparam_u("LC_ALL")) && *val) { + setlocale(LC_ALL, val); + } else { + struct localename *ln; + if ((val = getsparam_u("LANG")) && *val) + setlang(val); + for (ln = lc_names; ln->name; ln++) { + if ((val = getsparam_u(ln->name)) && *val) + setlocale(ln->category, val); + } + } + } +#endif /* USE_LOCALE */ unqueue_signals(); } @@ -5600,6 +5629,11 @@ scanendscope(HashNode hn, UNUSED(int flags)) */ Param tpm = pm->old; +#ifdef USE_LOCALE + if (!strncmp(pm->node.nam, "LC_", 3) || + !strcmp(pm->node.nam, "LANG")) + lc_update_needed = 1; +#endif if (!strcmp(pm->node.nam, "SECONDS")) { setsecondstype(pm, PM_TYPE(tpm->node.flags), PM_TYPE(pm->node.flags)); |