#define IN_LIBXSLT
#include "libxslt.h"
#include <string.h>
#include <libxml/xmlmemory.h>
#include <libxml/threads.h>
#include "xsltlocale.h"
#include "xsltutils.h"
#define XSLT_LOCALE_NONE
#define TOUPPER(c) …
#define TOLOWER(c) …
#define ISALPHA(c) …
#define XSLTMAX_ISO639LANGLEN …
#define XSLTMAX_ISO3166CNTRYLEN …
#define XSLTMAX_LANGTAGLEN …
static const xmlChar* xsltDefaultRegion(const xmlChar *localeName);
#ifdef XSLT_LOCALE_WINAPI
xmlRMutexPtr xsltLocaleMutex = NULL;
struct xsltRFC1766Info_s {
xmlChar tag[XSLTMAX_LANGTAGLEN+1];
LCID lcid;
};
typedef struct xsltRFC1766Info_s xsltRFC1766Info;
static int xsltLocaleListSize = 0;
static xsltRFC1766Info *xsltLocaleList = NULL;
static void *
xslt_locale_WINAPI(const xmlChar *languageTag) {
int k;
xsltRFC1766Info *p = xsltLocaleList;
for (k=0; k<xsltLocaleListSize; k++, p++)
if (xmlStrcmp(p->tag, languageTag) == 0)
return(&p->lcid);
return(NULL);
}
static void xsltEnumSupportedLocales(void);
#endif
void
xsltFreeLocales(void) { … }
void *
xsltNewLocale(const xmlChar *languageTag, int lowerFirst ATTRIBUTE_UNUSED) { … }
static const xmlChar*
xsltDefaultRegion(const xmlChar *localeName) { … }
void
xsltFreeLocale(void *locale) { … }
xmlChar *
xsltStrxfrm(void *vlocale, const xmlChar *string)
{ … }
int
xsltLocaleStrcmp(void *locale, const xmlChar *str1, const xmlChar *str2) { … }
#ifdef XSLT_LOCALE_WINAPI
static BOOL CALLBACK
xsltCountSupportedLocales(LPSTR lcid) {
(void) lcid;
++xsltLocaleListSize;
return(TRUE);
}
static BOOL CALLBACK
xsltIterateSupportedLocales(LPSTR lcid) {
static int count = 0;
xmlChar iso639lang [XSLTMAX_ISO639LANGLEN +1];
xmlChar iso3136ctry[XSLTMAX_ISO3166CNTRYLEN+1];
int k, l;
xsltRFC1766Info *p = xsltLocaleList + count;
k = sscanf(lcid, "%lx", (unsigned long*)&p->lcid);
if (k < 1) goto end;
k = GetLocaleInfoA(p->lcid, LOCALE_SISO639LANGNAME,
(char *) iso639lang, sizeof(iso639lang));
if (--k < 1) goto end;
l = GetLocaleInfoA(p->lcid, LOCALE_SISO3166CTRYNAME,
(char *) iso3136ctry, sizeof(iso3136ctry));
if (--l < 1) goto end;
{
xmlChar *q = p->tag;
memcpy(q, iso639lang, k);
q += k;
*q++ = '-';
memcpy(q, iso3136ctry, l);
q += l;
*q = '\0';
}
++count;
end:
return((count < xsltLocaleListSize) ? TRUE : FALSE);
}
static void
xsltEnumSupportedLocales(void) {
xmlRMutexLock(xsltLocaleMutex);
if (xsltLocaleListSize <= 0) {
size_t len;
EnumSystemLocalesA(xsltCountSupportedLocales, LCID_SUPPORTED);
len = xsltLocaleListSize * sizeof(xsltRFC1766Info);
xsltLocaleList = xmlMalloc(len);
memset(xsltLocaleList, 0, len);
EnumSystemLocalesA(xsltIterateSupportedLocales, LCID_SUPPORTED);
}
xmlRMutexUnlock(xsltLocaleMutex);
}
#endif