Rearrange struct __locale_t pointers into an array
This allows looping through the structs and buffers. Also rearrange definitions to follow order of LC_xxx values. Signed-off by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
1498c79db8
commit
53f84bb5ac
|
@ -77,16 +77,16 @@ __ctype_load_locale (struct __locale_t *locale, const char *name,
|
|||
return -1;
|
||||
memcpy (ctp, &ct, sizeof *ctp);
|
||||
}
|
||||
locale->ctype = ret == 0 ? &_C_ctype_locale : ctp;
|
||||
if (locale->ctype_buf)
|
||||
free (locale->ctype_buf);
|
||||
locale->ctype_buf = bufp;
|
||||
locale->lc_cat[LC_CTYPE].ptr = ret == 0 ? &_C_ctype_locale : ctp;
|
||||
if (locale->lc_cat[LC_CTYPE].buf)
|
||||
free (locale->lc_cat[LC_CTYPE].buf);
|
||||
locale->lc_cat[LC_CTYPE].buf = bufp;
|
||||
ret = 0;
|
||||
}
|
||||
#elif !defined (__HAVE_LOCALE_INFO_EXTENDED__)
|
||||
ret = 0;
|
||||
if (!strcmp (name, "C"))
|
||||
locale->ctype = NULL;
|
||||
locale->lc_cat[LC_CTYPE].ptr = NULL;
|
||||
else
|
||||
{
|
||||
if (locale == __get_global_locale ())
|
||||
|
@ -100,9 +100,10 @@ __ctype_load_locale (struct __locale_t *locale, const char *name,
|
|||
mbc[0] = mb_cur_max;
|
||||
mbc[1] = '\0';
|
||||
_ctype_locale.mb_cur_max = mbc;
|
||||
if (locale->ctype_buf && locale->ctype_buf != _ctype_locale_buf)
|
||||
free (locale->ctype_buf);
|
||||
locale->ctype_buf = bufp;
|
||||
if (locale->lc_cat[LC_CTYPE].buf
|
||||
&& locale->lc_cat[LC_CTYPE].buf != _ctype_locale_buf)
|
||||
free (locale->lc_cat[LC_CTYPE].buf);
|
||||
locale->lc_cat[LC_CTYPE].buf = bufp;
|
||||
}
|
||||
else
|
||||
ret = -1;
|
||||
|
|
|
@ -87,10 +87,10 @@ __messages_load_locale (struct __locale_t *locale, const char *name,
|
|||
return -1;
|
||||
memcpy (mep, &me, sizeof *mep);
|
||||
}
|
||||
locale->messages = ret == 0 ? &_C_messages_locale : mep;
|
||||
if (locale->messages_buf)
|
||||
free (locale->messages_buf);
|
||||
locale->messages_buf = bufp;
|
||||
locale->lc_cat[LC_MESSAGES].ptr = ret == 0 ? &_C_messages_locale : mep;
|
||||
if (locale->lc_cat[LC_MESSAGES].buf)
|
||||
free (locale->lc_cat[LC_MESSAGES].buf);
|
||||
locale->lc_cat[LC_MESSAGES].buf = bufp;
|
||||
ret = 0;
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -115,10 +115,10 @@ __monetary_load_locale (struct __locale_t *locale, const char *name ,
|
|||
return -1;
|
||||
memcpy (mop, &mo, sizeof *mop);
|
||||
}
|
||||
locale->monetary = ret == 0 ? &_C_monetary_locale : mop;
|
||||
if (locale->monetary_buf)
|
||||
free (locale->monetary_buf);
|
||||
locale->monetary_buf = bufp;
|
||||
locale->lc_cat[LC_MONETARY].ptr = ret == 0 ? &_C_monetary_locale : mop;
|
||||
if (locale->lc_cat[LC_MONETARY].buf)
|
||||
free (locale->lc_cat[LC_MONETARY].buf);
|
||||
locale->lc_cat[LC_MONETARY].buf = bufp;
|
||||
ret = 0;
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -77,10 +77,10 @@ __numeric_load_locale (struct __locale_t *locale, const char *name ,
|
|||
return -1;
|
||||
memcpy (nmp, &nm, sizeof *nmp);
|
||||
}
|
||||
locale->numeric = ret == 0 ? &_C_numeric_locale : nmp;
|
||||
if (locale->numeric_buf)
|
||||
free (locale->numeric_buf);
|
||||
locale->numeric_buf = bufp;
|
||||
locale->lc_cat[LC_NUMERIC].ptr = ret == 0 ? &_C_numeric_locale : nmp;
|
||||
if (locale->lc_cat[LC_NUMERIC].buf)
|
||||
free (locale->lc_cat[LC_NUMERIC].buf);
|
||||
locale->lc_cat[LC_NUMERIC].buf = bufp;
|
||||
ret = 0;
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -243,20 +243,19 @@ struct __locale_t __global_locale =
|
|||
"ASCII",
|
||||
"ASCII",
|
||||
#else
|
||||
&_C_ctype_locale,
|
||||
NULL,
|
||||
&_C_monetary_locale,
|
||||
NULL,
|
||||
&_C_numeric_locale,
|
||||
NULL,
|
||||
&_C_time_locale,
|
||||
NULL,
|
||||
&_C_messages_locale,
|
||||
NULL,
|
||||
{
|
||||
{ NULL, NULL }, /* LC_ALL */
|
||||
#ifdef __CYGWIN__
|
||||
&_C_collate_locale,
|
||||
NULL,
|
||||
{ &_C_collate_locale, NULL }, /* LC_COLLATE */
|
||||
#else
|
||||
{ NULL, NULL }, /* LC_COLLATE */
|
||||
#endif
|
||||
{ &_C_ctype_locale, NULL }, /* LC_CTYPE */
|
||||
{ &_C_monetary_locale, NULL }, /* LC_MONETARY */
|
||||
{ &_C_numeric_locale, NULL }, /* LC_NUMERIC */
|
||||
{ &_C_time_locale, NULL }, /* LC_TIME */
|
||||
{ &_C_messages_locale, NULL }, /* LC_MESSAGES */
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -276,9 +275,6 @@ _DEFUN(_setlocale_r, (p, category, locale),
|
|||
int category _AND
|
||||
_CONST char *locale)
|
||||
{
|
||||
static char new_categories[_LC_LAST][ENCODING_LEN + 1];
|
||||
static char saved_categories[_LC_LAST][ENCODING_LEN + 1];
|
||||
|
||||
#ifndef _MB_CAPABLE
|
||||
if (locale)
|
||||
{
|
||||
|
@ -288,6 +284,8 @@ _DEFUN(_setlocale_r, (p, category, locale),
|
|||
}
|
||||
return "C";
|
||||
#else /* !_MB_CAPABLE */
|
||||
static char new_categories[_LC_LAST][ENCODING_LEN + 1];
|
||||
static char saved_categories[_LC_LAST][ENCODING_LEN + 1];
|
||||
int i, j, len, saverr;
|
||||
const char *env, *r;
|
||||
|
||||
|
@ -438,9 +436,6 @@ currentlocale ()
|
|||
}
|
||||
return (global_locale_string);
|
||||
}
|
||||
#endif /* _MB_CAPABLE */
|
||||
|
||||
#ifdef _MB_CAPABLE
|
||||
|
||||
extern void __set_ctype (struct __locale_t *, const char *charset);
|
||||
|
||||
|
@ -483,7 +478,7 @@ loadlocale (struct __locale_t *loc, int category, const char *new_locale)
|
|||
|
||||
restart:
|
||||
if (!locale)
|
||||
locale = new_locale;
|
||||
locale = (char *) new_locale;
|
||||
else if (locale != tmp_locale)
|
||||
{
|
||||
locale = __set_locale_from_locale_alias (locale, tmp_locale);
|
||||
|
|
|
@ -43,6 +43,18 @@ __BEGIN_DECLS
|
|||
#define CATEGORY_LEN 11
|
||||
#define _LC_LAST 7
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
typedef __uint32_t LCID;
|
||||
|
||||
struct lc_collate_T
|
||||
{
|
||||
LCID lcid;
|
||||
int (*mbtowc) (struct _reent *, wchar_t *, const char *, size_t, mbstate_t *);
|
||||
char codeset[ENCODING_LEN + 1];
|
||||
};
|
||||
extern const struct lc_collate_T _C_collate_locale;
|
||||
#endif
|
||||
|
||||
struct lc_ctype_T {
|
||||
const char *codeset; /* codeset for mbtowc conversion */
|
||||
const char *mb_cur_max;
|
||||
|
@ -153,47 +165,27 @@ struct lc_messages_T {
|
|||
};
|
||||
extern const struct lc_messages_T _C_messages_locale;
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
typedef __uint32_t LCID;
|
||||
|
||||
struct lc_collate_T
|
||||
struct __lc_cats
|
||||
{
|
||||
LCID lcid;
|
||||
int (*mbtowc) (struct _reent *, wchar_t *, const char *, size_t, mbstate_t *);
|
||||
char codeset[ENCODING_LEN + 1];
|
||||
const void *ptr;
|
||||
char *buf;
|
||||
};
|
||||
extern const struct lc_collate_T _C_collate_locale;
|
||||
#endif
|
||||
|
||||
struct __locale_t
|
||||
{
|
||||
char categories[_LC_LAST][ENCODING_LEN + 1];
|
||||
int (*wctomb) (struct _reent *, char *, wchar_t,
|
||||
mbstate_t *);
|
||||
int (*mbtowc) (struct _reent *, wchar_t *,
|
||||
const char *, size_t, mbstate_t *);
|
||||
int cjk_lang;
|
||||
char *ctype_ptr; /* Unused in __global_locale */
|
||||
char categories[_LC_LAST][ENCODING_LEN + 1];
|
||||
int (*wctomb) (struct _reent *, char *, wchar_t,
|
||||
mbstate_t *);
|
||||
int (*mbtowc) (struct _reent *, wchar_t *,
|
||||
const char *, size_t, mbstate_t *);
|
||||
int cjk_lang;
|
||||
char *ctype_ptr; /* Unused in __global_locale */
|
||||
#ifndef __HAVE_LOCALE_INFO__
|
||||
char mb_cur_max[2];
|
||||
char ctype_codeset[ENCODING_LEN + 1];
|
||||
char message_codeset[ENCODING_LEN + 1];
|
||||
char mb_cur_max[2];
|
||||
char ctype_codeset[ENCODING_LEN + 1];
|
||||
char message_codeset[ENCODING_LEN + 1];
|
||||
#else
|
||||
const struct lc_ctype_T *ctype;
|
||||
char *ctype_buf;
|
||||
const struct lc_monetary_T *monetary;
|
||||
char *monetary_buf;
|
||||
const struct lc_numeric_T *numeric;
|
||||
char *numeric_buf;
|
||||
const struct lc_time_T *time;
|
||||
char *time_buf;
|
||||
const struct lc_messages_T *messages;
|
||||
char *messages_buf;
|
||||
#ifdef __CYGWIN__
|
||||
const struct lc_collate_T *collate;
|
||||
char *collate_buf;
|
||||
#endif
|
||||
/* Append more categories here. */
|
||||
struct __lc_cats lc_cat[_LC_LAST];
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -224,44 +216,44 @@ __get_current_locale ()
|
|||
return _REENT->_locale ?: &__global_locale;
|
||||
}
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
_ELIDABLE_INLINE const struct lc_collate_T *
|
||||
__get_current_collate_locale (void)
|
||||
{
|
||||
return (const struct lc_collate_T *) __get_current_locale ()->lc_cat[LC_COLLATE].ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
_ELIDABLE_INLINE const struct lc_ctype_T *
|
||||
__get_current_ctype_locale (void)
|
||||
{
|
||||
return __get_current_locale ()->ctype;
|
||||
return (const struct lc_ctype_T *) __get_current_locale ()->lc_cat[LC_CTYPE].ptr;
|
||||
}
|
||||
|
||||
_ELIDABLE_INLINE const struct lc_monetary_T *
|
||||
__get_current_monetary_locale (void)
|
||||
{
|
||||
return __get_current_locale ()->monetary;
|
||||
}
|
||||
|
||||
_ELIDABLE_INLINE const struct lc_time_T *
|
||||
__get_current_time_locale (void)
|
||||
{
|
||||
return __get_current_locale ()->time;
|
||||
return (const struct lc_monetary_T *) __get_current_locale ()->lc_cat[LC_MONETARY].ptr;
|
||||
}
|
||||
|
||||
_ELIDABLE_INLINE const struct lc_numeric_T *
|
||||
__get_current_numeric_locale (void)
|
||||
{
|
||||
return __get_current_locale ()->numeric;
|
||||
return (const struct lc_numeric_T *) __get_current_locale ()->lc_cat[LC_NUMERIC].ptr;
|
||||
}
|
||||
|
||||
_ELIDABLE_INLINE const struct lc_time_T *
|
||||
__get_current_time_locale (void)
|
||||
{
|
||||
return (const struct lc_time_T *) __get_current_locale ()->lc_cat[LC_TIME].ptr;
|
||||
}
|
||||
|
||||
_ELIDABLE_INLINE const struct lc_messages_T *
|
||||
__get_current_messages_locale (void)
|
||||
{
|
||||
return __get_current_locale ()->messages;
|
||||
return (const struct lc_messages_T *) __get_current_locale ()->lc_cat[LC_MESSAGES].ptr;
|
||||
}
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
_ELIDABLE_INLINE const struct lc_collate_T *
|
||||
__get_current_collate_locale (void)
|
||||
{
|
||||
return __get_current_locale ()->collate;
|
||||
}
|
||||
#endif
|
||||
|
||||
_ELIDABLE_INLINE const char *
|
||||
__locale_charset (void)
|
||||
{
|
||||
|
|
|
@ -177,10 +177,10 @@ __time_load_locale (struct __locale_t *locale, const char *name,
|
|||
return -1;
|
||||
memcpy (tip, &ti, sizeof *tip);
|
||||
}
|
||||
locale->time = ret == 0 ? &_C_time_locale : tip;
|
||||
if (locale->time_buf)
|
||||
free (locale->time_buf);
|
||||
locale->time_buf = bufp;
|
||||
locale->lc_cat[LC_TIME].ptr = ret == 0 ? &_C_time_locale : tip;
|
||||
if (locale->lc_cat[LC_TIME].buf)
|
||||
free (locale->lc_cat[LC_TIME].buf);
|
||||
locale->lc_cat[LC_TIME].buf = bufp;
|
||||
ret = 0;
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -1074,7 +1074,7 @@ __collate_load_locale (struct __locale_t *locale, const char *name,
|
|||
void *f_mbtowc, const char *charset)
|
||||
{
|
||||
const struct lc_collate_T *ccop;
|
||||
char *buf = NULL;
|
||||
char *bufp = NULL;
|
||||
|
||||
LCID lcid = __get_lcid_from_locale (name);
|
||||
if (lcid == (LCID) -1)
|
||||
|
@ -1082,23 +1082,23 @@ __collate_load_locale (struct __locale_t *locale, const char *name,
|
|||
if (!lcid)
|
||||
{
|
||||
ccop = &_C_collate_locale;
|
||||
buf = NULL;
|
||||
bufp = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = (char *) calloc (1, sizeof (struct lc_collate_T));
|
||||
if (!buf)
|
||||
bufp = (char *) calloc (1, sizeof (struct lc_collate_T));
|
||||
if (!bufp)
|
||||
return -1;
|
||||
struct lc_collate_T *cop = (struct lc_collate_T *) buf;
|
||||
struct lc_collate_T *cop = (struct lc_collate_T *) bufp;
|
||||
cop->lcid = lcid;
|
||||
cop->mbtowc = (mbtowc_p) f_mbtowc;
|
||||
stpcpy (cop->codeset, charset);
|
||||
ccop = (const struct lc_collate_T *) cop;
|
||||
}
|
||||
locale->collate = ccop;
|
||||
if (locale->collate_buf)
|
||||
free (locale->collate_buf);
|
||||
locale->collate_buf = buf;
|
||||
locale->lc_cat[LC_COLLATE].ptr = ccop;
|
||||
if (locale->lc_cat[LC_COLLATE].buf)
|
||||
free (locale->lc_cat[LC_COLLATE].buf);
|
||||
locale->lc_cat[LC_COLLATE].buf = bufp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue