Skip to content

Commit

Permalink
45772: Restore locale on parameter scope end.
Browse files Browse the repository at this point in the history
Check if relevant parameters changes and if so restore system settings.
  • Loading branch information
Peter Stephenson committed May 5, 2020
1 parent 455c80e commit c486040
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2020-05-05 Peter Stephenson <p.w.stephenson@ntlworld.com>

* 45772: Src/params.c: Upon restoring locale variables, restore
the corresponding system settings.

2020-05-23 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>

* unposted: Src/Builtins/rlimits.c: add a comment about how to
Expand Down
34 changes: 34 additions & 0 deletions Src/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

/**/
Expand All @@ -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();
}

Expand All @@ -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));
Expand Down

0 comments on commit c486040

Please sign in to comment.