X-Git-Url: https://pd.if.org/git/?p=pdclib.old;a=blobdiff_plain;f=internals%2F_PDCLIB_locale.h;h=e99d9ca1ac85710cf51ce8576ba8d65972708c91;hp=bed89b561a39903a0ea335b1be7401359d87d5d4;hb=ed01ab8d9fcc47f6a4089ef72a73ef7a084d1ed3;hpb=fd89f130aedf49fbdb3e4f5a24c9cedb56eea22e diff --git a/internals/_PDCLIB_locale.h b/internals/_PDCLIB_locale.h index bed89b5..e99d9ca 100644 --- a/internals/_PDCLIB_locale.h +++ b/internals/_PDCLIB_locale.h @@ -1,12 +1,81 @@ #ifndef __PDCLIB_LOCALE_H #define __PDCLIB_LOCALE_H __PDCLIB_LOCALE_H +#include <_PDCLIB_int.h> #include +#include +#include -#define _PDCLIB_threadlocale() (uselocale(NULL)) +#define _PDCLIB_LOCALE_METHOD_TSS 't' +#define _PDCLIB_LOCALE_METHOD_THREAD_LOCAL 'T' + +#if !defined(_PDCLIB_LOCALE_METHOD) + #error _PDCLIB_LOCALE_METHOD undefined: don't know where I'm storing the thread locale +#elif _PDCLIB_LOCALE_METHOD == _PDCLIB_LOCALE_METHOD_TSS + extern tss_t _PDCLIB_locale_tss; + static inline locale_t _PDCLIB_threadlocale( void ) + { + locale_t l = tss_get(_PDCLIB_locale_tss); + if(l == NULL) + l = &_PDCLIB_global_locale; + return l; + } + + static inline void _PDCLIB_setthreadlocale( locale_t l ) + { + if(tss_set(_PDCLIB_locale_tss, l) != thrd_success) + abort(); + } +#elif _PDCLIB_LOCALE_METHOD == _PDCLIB_LOCALE_METHOD_THREAD_LOCAL + extern thread_local locale_t _PDCLIB_locale_tls; + #define _PDCLIB_threadlocale() (_PDCLIB_locale_tls || &_PDCLIB_global_locale) + static inline locale_t _PDCLIB_threadlocale( void ) + { + locale_t l = _PDCLIB_locale_tls; + if(l == NULL) + l = &_PDCLIB_global_locale; + return l; + } + + static inline void _PDCLIB_setthreadlocale( locale_t l ) + { + _PDCLIB_locale_tls = l; + } +#else + #error Locale TSS method unspecified +#endif + +/* -------------------------------------------------------------------------- */ +/* lookup tables */ +/* -------------------------------------------------------------------------- */ + +#define _PDCLIB_CTYPE_ALPHA 1 +#define _PDCLIB_CTYPE_BLANK 2 +#define _PDCLIB_CTYPE_CNTRL 4 +#define _PDCLIB_CTYPE_GRAPH 8 +#define _PDCLIB_CTYPE_PUNCT 16 +#define _PDCLIB_CTYPE_SPACE 32 +#define _PDCLIB_CTYPE_LOWER 64 +#define _PDCLIB_CTYPE_UPPER 128 +#define _PDCLIB_CTYPE_DIGIT 256 +#define _PDCLIB_CTYPE_XDIGT 512 + +typedef struct _PDCLIB_ctype +{ + _PDCLIB_uint16_t flags; + unsigned char upper; + unsigned char lower; + unsigned char collation; +} _PDCLIB_ctype_t; struct _PDCLIB_locale { - struct _PDCLIB_charcodec *_Codec; + _PDCLIB_charcodec_t _Codec; struct lconv _Conv; + + /* ctype */ + _PDCLIB_ctype_t *_CType; + + /* perror/strerror */ + char *_ErrnoStr[_PDCLIB_ERRNO_MAX]; }; #endif