Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
McDutchie committed Dec 27, 2024
1 parent 5590690 commit a8b2c93
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
10 changes: 0 additions & 10 deletions src/cmd/ksh93/sh/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,10 @@ static void put_cdpath(Namval_t* np,const char *val,int flags,Namfun_t *fp)
}

/* Trap for the LC_* and LANG variables */
extern void astconf_state_data_check(int,char*);
static void put_lang(Namval_t* np,const char *val,int flags,Namfun_t *fp)
{
int type;
char *name = nv_name(np);
astconf_state_data_check(__LINE__,name);
if(name==(LCALLNOD)->nvname)
type = LC_ALL;
else if(name==(LCTYPENOD)->nvname)
Expand All @@ -453,22 +451,16 @@ astconf_state_data_check(__LINE__,name);
#endif
else
type= -1;
astconf_state_data_check(__LINE__,name);
if(type>=0 || type==LC_ALL || type==LC_NUMERIC || type==LC_LANG)
{
char* r;
#ifdef AST_LC_setenv
ast.locale.set |= AST_LC_setenv;
#endif
// https://stackoverflow.com/a/10791845
#define XSTR(x) STR(x)
#define STR(x) #x
#pragma message "The value of setlocale(type,val): " XSTR(setlocale(type,val))
r = setlocale(type,val?val:"");
#ifdef AST_LC_setenv
ast.locale.set ^= AST_LC_setenv;
#endif
astconf_state_data_check(__LINE__,name);
if(!r && val)
{
if(!sh_isstate(SH_INIT) || !sh_isoption(SH_LOGIN_SHELL))
Expand All @@ -477,15 +469,13 @@ astconf_state_data_check(__LINE__,name);
}
}
nv_putv(np, val, flags, fp);
astconf_state_data_check(__LINE__,name);
#if _lib_localeconv
if(type==LC_ALL || type==LC_NUMERIC || type==LC_LANG)
{
struct lconv *lp = localeconv();
char *cp = lp->decimal_point;
/* Multibyte radix points are not (yet?) supported */
sh.radixpoint = strlen(cp)==1 ? *cp : '.';
astconf_state_data_check(__LINE__,name);
}
#endif
}
Expand Down
29 changes: 29 additions & 0 deletions src/lib/libast/comp/setlocale.c
Original file line number Diff line number Diff line change
Expand Up @@ -2577,6 +2577,7 @@ composite(const char* s, int initialize)
* * set (override LC_ALL)
*/

extern void astconf_state_data_check(int,int,char*);
char*
_ast_setlocale(int category, const char* locale)
{
Expand All @@ -2592,19 +2593,24 @@ _ast_setlocale(int category, const char* locale)
static int initialized;
static const char local[] = "local";

astconf_state_data_check(__LINE__,category,locale);
if ((category = lcindex(category, 0)) < 0)
return NULL;
astconf_state_data_check(__LINE__,category,locale);
if (!locale)
{
/*
* return the current state
*/

compose:
astconf_state_data_check(__LINE__,category,locale);
if (category != AST_LC_ALL && category != AST_LC_LANG)
return (char*)locales[category]->name;
astconf_state_data_check(__LINE__,category,locale);
if (!sp && !(sp = sfstropen()))
return NULL;
astconf_state_data_check(__LINE__,category,locale);
for (i = 1; i < AST_LC_COUNT; i++)
cat[i] = -1;
for (i = 1, k = 0; i < AST_LC_COUNT; i++)
Expand All @@ -2618,6 +2624,7 @@ _ast_setlocale(int category, const char* locale)
}
if (k == 1)
return (char*)locales[1]->name;
astconf_state_data_check(__LINE__,category,locale);
for (i = 1; i < AST_LC_COUNT; i++)
if (cat[i] >= 0 && !(locales[i]->flags & LC_default))
{
Expand All @@ -2631,29 +2638,35 @@ _ast_setlocale(int category, const char* locale)
}
sfprintf(sp, "%s", locales[i]->name);
}
astconf_state_data_check(__LINE__,category,locale);
if (!sfstrtell(sp))
return (char*)locales[0]->name;
astconf_state_data_check(__LINE__,category,locale);
return sfstruse(sp);
}
if (!ast.locale.serial++)
{
stropt(getenv("LC_OPTIONS"), options, sizeof(*options), setopt, NULL);
initialized = 0;
astconf_state_data_check(__LINE__,category,locale);
}
if ((ast.locale.set & (AST_LC_debug|AST_LC_setlocale)) && !(ast.locale.set & AST_LC_internal))
{
header();
sfprintf(sfstderr, "locale user %17s %16s %16s %16s%s%s\n", category == AST_LC_LANG ? "LANG" : lc_categories[category].name, locale && !*locale ? "''" : locale, "", "", initialized ? "" : " initial", (ast.locale.set & AST_LC_setenv) ? " setenv" : "");
astconf_state_data_check(__LINE__,category,locale);
}
if (ast.locale.set & AST_LC_setenv)
{
f = LC_setenv;
p = *locale ? lcmake(locale) : NULL;
astconf_state_data_check(__LINE__,category,locale);
}
else if (*locale)
{
f = LC_setlocale;
p = lcmake(locale);
astconf_state_data_check(__LINE__,category,locale);
}
else if (category == AST_LC_ALL)
{
Expand All @@ -2675,6 +2688,7 @@ _ast_setlocale(int category, const char* locale)
}
else
lang = 0;
astconf_state_data_check(__LINE__,category,locale);
if ((s = getenv("LC_ALL")) && *s)
{
if (u && streq(s, local))
Expand All @@ -2683,6 +2697,7 @@ _ast_setlocale(int category, const char* locale)
}
else
lc_all = 0;
astconf_state_data_check(__LINE__,category,locale);
for (i = 1; i < AST_LC_COUNT; i++)
if (lc_categories[i].flags & LC_setlocale)
/* explicitly set by setlocale() */;
Expand All @@ -2694,18 +2709,22 @@ _ast_setlocale(int category, const char* locale)
}
else
lc_categories[i].prev = 0;
astconf_state_data_check(__LINE__,category,locale);
for (i = 1; i < AST_LC_COUNT; i++)
if (!single(i, lc_all && !(lc_categories[i].flags & LC_setlocale) ? lc_all : lc_categories[i].prev, 0))
{
while (i--)
single(i, NULL, 0);
return NULL;
}
astconf_state_data_check(__LINE__,category,locale);
if (ast.locale.set & AST_LC_debug)
for (i = 1; i < AST_LC_COUNT; i++)
sfprintf(sfstderr, "locale env %17s %16s %16s %16s\n", lc_categories[i].name, locales[i]->name, "", lc_categories[i].prev ? lc_categories[i].prev->name : NULL);
astconf_state_data_check(__LINE__,category,locale);
initialized = 1;
}
astconf_state_data_check(__LINE__,category,locale);
goto compose;
}
else if (category == AST_LC_LANG || !(p = lc_categories[category].prev))
Expand All @@ -2715,6 +2734,7 @@ _ast_setlocale(int category, const char* locale)
}
else
f = 0;
astconf_state_data_check(__LINE__,category,locale);
if (category == AST_LC_LANG)
{
if (lang != p)
Expand All @@ -2726,20 +2746,27 @@ _ast_setlocale(int category, const char* locale)
{
while (i--)
single(i, NULL, 0);
astconf_state_data_check(__LINE__,category,locale);
return NULL;
}
}
}
else if (category != AST_LC_ALL)
{
astconf_state_data_check(__LINE__,category,locale);
if (f || !lc_all)
return single(category, p, f);
astconf_state_data_check(__LINE__,category,locale);
if (p && !(ast.locale.set & AST_LC_internal))
lc_categories[category].prev = p;
astconf_state_data_check(__LINE__,category,locale);
return (char*)locales[category]->name;
}
else if (composite(locale, 0) < 0)
{
astconf_state_data_check(__LINE__,category,locale);
return NULL;
}
else if (lc_all != p)
{
lc_all = p;
Expand All @@ -2748,8 +2775,10 @@ _ast_setlocale(int category, const char* locale)
{
while (i--)
single(i, NULL, 0);
astconf_state_data_check(__LINE__,category,locale);
return NULL;
}
}
astconf_state_data_check(__LINE__,category,locale);
goto compose;
}
6 changes: 4 additions & 2 deletions src/lib/libast/port/astconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,10 @@ astconflist(Sfio_t* sp, const char* path, int flags, const char* pattern)
errno = olderrno;
}

void astconf_state_data_check(int lineno,char *name)
void astconf_state_data_check(int lineno,int cat,char *name)
{
struct stat sb;
if(stat("/tmp/zut",&sb)==0)error(ERROR_warn(0),"[DEBUG] line %d (%s): state.data inited: %d",lineno,name,state.data!=NULL);
static int s = 1;
if(s>0)s=stat("/tmp/zut",&sb);
if(s==0)sfprintf(sfstderr,"[DEBUG] line %d (%d, %s): state.data inited: %d\n",lineno,cat,name,state.data!=NULL);
}

0 comments on commit a8b2c93

Please sign in to comment.