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:
parent
6dbde5ec7c
commit
f0386a8794
9 changed files with 25 additions and 26 deletions
|
|
@ -428,6 +428,17 @@ static void put_cdpath(register Namval_t* np,const char *val,int flags,Namfun_t
|
|||
sh.cdpathlist = (void*)path_addpath((Pathcomp_t*)sh.cdpathlist,val,PATH_CDPATH);
|
||||
}
|
||||
|
||||
static void init_radixpoint(void)
|
||||
{
|
||||
#if _hdr_locale && _lib_localeconv
|
||||
struct lconv *lp;
|
||||
if((lp = localeconv()) && lp->decimal_point && *lp->decimal_point)
|
||||
sh.radixpoint = *lp->decimal_point;
|
||||
else
|
||||
#endif
|
||||
sh.radixpoint = '.';
|
||||
}
|
||||
|
||||
#ifdef _hdr_locale
|
||||
/* Trap for the LC_* and LANG variables */
|
||||
static void put_lang(Namval_t* np,const char *val,int flags,Namfun_t *fp)
|
||||
|
|
@ -474,6 +485,8 @@ static void put_cdpath(register Namval_t* np,const char *val,int flags,Namfun_t
|
|||
}
|
||||
}
|
||||
nv_putv(np, val, flags, fp);
|
||||
if(type==LC_ALL || type==LC_NUMERIC)
|
||||
init_radixpoint();
|
||||
if(CC_NATIVE!=CC_ASCII && (type==LC_ALL || type==LC_LANG || type==LC_CTYPE))
|
||||
{
|
||||
if(sh_lexstates[ST_BEGIN]!=sh_lexrstates[ST_BEGIN])
|
||||
|
|
@ -1454,8 +1467,7 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
|
|||
}
|
||||
if(beenhere==1)
|
||||
{
|
||||
struct lconv* lc;
|
||||
sh.decomma = (lc=localeconv()) && lc->decimal_point && *lc->decimal_point==',';
|
||||
init_radixpoint();
|
||||
beenhere = 2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue