1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Improve radix point (decimal point/comma) handling

The GETDECIMAL(x) macro in src/cmd/ksh93/features/locale uses a
global static variable 'lp' to get the localeconv() results.
Several functions in ksh use local variables called 'lp'. It's dumb
luck that this hasn't conflicted yet; it's a bug waiting to happen.
It's also slightly inefficient as it calls localeconv() every time.

In addition there is a redundant 'sh.decomma' flag that is set to 1
if the radix point is a comma, but only once, by sh_init(). It is
not updated if the locale changes. That is not correct.

This commit gets rid of both and implements a new approach instead:
store the radix point in sh.radixpoint at init time in sh_init(),
and in the put_lang() locale discipline function, reinitialise
sh.radixpoint whenever LC_ALL or LC_NUMERIC changes. The rest of
the code can then simply use sh.radixpoint without worry.
This commit is contained in:
Martijn Dekker 2022-06-03 10:29:56 +01:00
parent 6dbde5ec7c
commit f0386a8794
9 changed files with 25 additions and 26 deletions

View file

@ -322,7 +322,7 @@ struct Shell_s
char subshare; /* set when comsub==2 (shared-state ${ ...; } command substitution) */
char toomany; /* set when out of fd's */
char instance; /* in set_instance */
char decomma; /* decimal_point=',' */
char radixpoint; /* current radix point ('.' or ',') */
char redir0; /* redirect of 0 */
char intrace; /* set when trace expands PS4 */
char *readscript; /* set before reading a script */