65#if defined(WIZARDSTOOLKIT_HAVE_NEWLOCALE) || defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
66# define WIZARDSTOOLKIT_LOCALE_SUPPORT
68#define LocaleFilename "locale.xml"
69#define MaxRecursionDepth 200
76 "<?xml version=\"1.0\"?>"
78 " <locale name=\"C\">"
80 " <Message name=\"\">"
92#if defined(WIZARDSTOOLKIT_LOCALE_SUPPORT)
93static volatile locale_t
94 c_locale = (locale_t) NULL;
105#if defined(WIZARDSTOOLKIT_LOCALE_SUPPORT)
125static locale_t AcquireCLocale(
void)
127#if defined(WIZARDSTOOLKIT_HAVE_NEWLOCALE)
128 if (c_locale == (locale_t) NULL)
129 c_locale=newlocale(LC_ALL_MASK,
"C",(locale_t) 0);
130#elif defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !defined(__MINGW32__)
131 if (c_locale == (locale_t) NULL)
132 c_locale=_create_locale(LC_ALL,
"C");
173 if (p->
path != (
char *) NULL)
175 if (p->
tag != (
char *) NULL)
177 if (p->
message != (
char *) NULL)
196#if !defined(WIZARDSTOOLKIT_ZERO_CONFIGURATION_SUPPORT)
235#if defined(WIZARDSTOOLKIT_LOCALE_SUPPORT)
255static void DestroyCLocale(
void)
257 if (c_locale != (locale_t) NULL)
258 freelocale(c_locale);
259 c_locale=(locale_t) NULL;
332#if defined(WIZARDSTOOLKIT_LOCALE_SUPPORT) && defined(WIZARDSTOOLKIT_HAVE_VFPRINTF_L)
337 locale=AcquireCLocale();
338 if (locale == (locale_t) NULL)
339 n=(ssize_t) vfprintf(file,format,operands);
341#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
342 n=(ssize_t) vfprintf_l(file,format,locale,operands);
344 n=(ssize_t) vfprintf_l(file,locale,format,operands);
348#if defined(WIZARDSTOOLKIT_LOCALE_SUPPORT) && defined(WIZARDSTOOLKIT_HAVE_USELOCALE)
354 locale=AcquireCLocale();
355 if (locale == (locale_t) NULL)
356 n=(ssize_t) vfprintf(file,format,operands);
359 previous_locale=uselocale(locale);
360 n=(ssize_t) vfprintf(file,format,operands);
361 uselocale(previous_locale);
365 n=(ssize_t) vfprintf(file,format,operands);
379 va_start(operands,format);
417 const char *format,va_list operands)
422#if defined(WIZARDSTOOLKIT_LOCALE_SUPPORT) && defined(WIZARDSTOOLKIT_HAVE_VSNPRINTF_L)
427 locale=AcquireCLocale();
428 if (locale == (locale_t) NULL)
429 n=(ssize_t) vsnprintf(
string,length,format,operands);
431#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
432 n=(ssize_t) vsnprintf_l(
string,length,format,locale,operands);
434 n=(ssize_t) vsnprintf_l(
string,length,locale,format,operands);
437#elif defined(WIZARDSTOOLKIT_HAVE_VSNPRINTF)
438#if defined(WIZARDSTOOLKIT_LOCALE_SUPPORT) && defined(WIZARDSTOOLKIT_HAVE_USELOCALE)
444 locale=AcquireCLocale();
445 if (locale == (locale_t) NULL)
446 n=(ssize_t) vsnprintf(
string,length,format,operands);
449 previous_locale=uselocale(locale);
450 n=(ssize_t) vsnprintf(
string,length,format,operands);
451 uselocale(previous_locale);
455 n=(ssize_t) vsnprintf(
string,length,format,operands);
458 n=(ssize_t) vsprintf(
string,format,operands);
461 string[length-1]=
'\0';
466 const char *format,...)
474 va_start(operands,format);
516 if ((tag == (
const char *) NULL) || (
LocaleCompare(tag,
"*") == 0))
558#if defined(__cplusplus) || defined(c_plusplus)
575#if defined(__cplusplus) || defined(c_plusplus)
594 assert(pattern != (
char *) NULL);
596 assert(number_messages != (
size_t *) NULL);
621 *number_messages=(size_t) i;
655#if defined(__cplusplus) || defined(c_plusplus)
670#if defined(__cplusplus) || defined(c_plusplus)
689 assert(pattern != (
char *) NULL);
691 assert(number_messages != (
size_t *) NULL);
695 return((
char **) NULL);
698 if (messages == (
char **) NULL)
699 return((
char **) NULL);
711 messages[i]=(
char *) NULL;
712 *number_messages=(size_t) i;
750 if ((tag == (
const char *) NULL) || (*tag ==
'\0'))
803 assert(filename != (
const char *) NULL);
816 while (element != (
const char *) NULL)
821 "Searching for locale file: \"%s\"",path);
829#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
834 blob=(
char *) NTResourceToBlob(filename);
835 if (blob != (
char *) NULL)
840 blob=(
char *) RelinquishMagickMemory(blob);
918 locale=(
char *) NULL;
919 p=setlocale(LC_CTYPE,(
const char *) NULL);
920 if (p != (
const char *) NULL)
922 if (locale == (
char *) NULL)
924 if (locale == (
char *) NULL)
926 if (locale == (
char *) NULL)
928 if (locale == (
char *) NULL)
930 if (locale == (
char *) NULL)
977 if ((*
string ==
'0') && ((
string[1] | 0x20)==
'x'))
978 value=(double) strtoul(
string,&q,16);
981#if defined(WIZARDSTOOLKIT_LOCALE_SUPPORT) && defined(WIZARDSTOOLKIT_HAVE_STRTOD_L)
985 locale=AcquireCLocale();
986 if (locale == (locale_t) NULL)
987 value=strtod(
string,&q);
989 value=strtod_l(
string,&q,locale);
991 value=strtod(
string,&q);
994 if (sentinal != (
char **) NULL)
1038 if (file == (
const FILE *) NULL)
1042 if (locale_info == (
const LocaleInfo **) NULL)
1044 path=(
const char *) NULL;
1045 for (i=0; i < (ssize_t) number_messages; i++)
1049 if ((path == (
const char *) NULL) ||
1052 if (locale_info[i]->path != (
char *) NULL)
1056 "-------------------------------------------------"
1057 "------------------------------\n");
1059 path=locale_info[i]->
path;
1061 if (locale_info[i]->message != (
char *) NULL)
1065 (void) fflush(file);
1113 p=path+strlen(path)-1;
1116 for (count=0; (count < (ssize_t) components) && (p > path); p--)
1122 if (count < (ssize_t) components)
1128 const char *reason,
const char *description)
1132 if (reason == (
char *) NULL)
1135 if (description != (
char *) NULL)
1138 (void) fflush(stderr);
1143 const char *xml,
const char *filename,
const char *locale,
const size_t depth,
1174 "Loading locale configure file \"%s\" ...",filename);
1175 if (xml == (
const char *) NULL)
1185 for (q=(
char *) xml; *q !=
'\0'; )
1202 while (isspace((
int) ((
unsigned char) *q)) != 0)
1215 while (isspace((
int) ((
unsigned char) *q)) != 0)
1225 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
1260 if (xml != (
char *) NULL)
1276 while ((*token !=
'>') && (*q !=
'\0'))
1301 while ((*token !=
'>') && (*q !=
'\0'))
1314 for (p=(
char *) q; (*q !=
'<') && (*q !=
'\0'); q++) ;
1315 while (isspace((
int) ((
unsigned char) *p)) != 0)
1318 while ((isspace((
int) ((
unsigned char) *q)) != 0) && (q > p))
1324 "memory allocation failed `%s'");
1325 (void) memset(locale_info,0,
sizeof(*locale_info));
1333 "memory allocation failed `%s'");
1345 if (*keyword ==
'<')
1350 if (*(keyword+1) ==
'?')
1352 if (*(keyword+1) ==
'/')
1359 token[strlen(token)-1]=
'\0';
1396#if defined(WIZARDSTOOLKIT_LOCALE_SUPPORT)
1397 (void) AcquireCLocale();
1427#if defined(WIZARDSTOOLKIT_LOCALE_SUPPORT)
WizardExport const char * GetClientName(void)
#define ThrowFatalException(severity, tag)
WizardExport ExceptionInfo * AcquireExceptionInfo(void)
WizardExport ExceptionInfo * DestroyExceptionInfo(ExceptionInfo *exception)
WizardExport WizardBooleanType ThrowWizardException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *format,...)
WizardExport FatalErrorHandler SetFatalErrorHandler(FatalErrorHandler handler)
void(* FatalErrorHandler)(const ExceptionType, const char *, const char *)
WizardExport void ResetLinkedListIterator(LinkedListInfo *list_info)
WizardExport WizardBooleanType AppendValueToLinkedList(LinkedListInfo *list_info, const void *value)
WizardExport LinkedListInfo * NewLinkedList(const size_t capacity)
WizardExport void * GetNextValueInLinkedList(LinkedListInfo *list_info)
WizardExport LinkedListInfo * DestroyLinkedList(LinkedListInfo *list_info, void *(*relinquish_value)(void *))
static WizardBooleanType LoadLocaleCache(SplayTreeInfo *, const char *, const char *, const char *, const size_t, ExceptionInfo *)
static WizardBooleanType IsLocaleTreeInstantiated(ExceptionInfo *)
WizardExport char ** GetLocaleList(const char *pattern, size_t *number_messages, ExceptionInfo *exception)
static void * DestroyLocaleNode(void *locale_info)
static void * DestroyOptions(void *message)
static SplayTreeInfo * AcquireLocaleSplayTree(const char *filename, const char *locale, ExceptionInfo *exception)
WizardExport ssize_t FormatLocaleFile(FILE *file, const char *format,...)
static void ChopLocaleComponents(char *path, const size_t components)
WizardExport ssize_t FormatLocaleStringList(char *string, const size_t length, const char *format, va_list operands)
WizardExport const LocaleInfo * GetLocaleInfo_(const char *tag, ExceptionInfo *exception)
static void LocaleFatalErrorHandler(const ExceptionType wizard_unused(severity), const char *reason, const char *description)
WizardExport ssize_t FormatLocaleFileList(FILE *file, const char *format, va_list operands)
WizardExport LinkedListInfo * DestroyLocaleOptions(LinkedListInfo *messages)
static int LocaleTagCompare(const void *x, const void *y)
static SplayTreeInfo * locale_cache
WizardExport double InterpretLocaleValue(const char *string, char **sentinal)
WizardExport ssize_t FormatLocaleString(char *string, const size_t length, const char *format,...)
WizardExport const char * GetLocaleMessage(const char *tag)
static int LocaleInfoCompare(const void *x, const void *y)
WizardExport WizardBooleanType ListLocaleInfo(FILE *file, ExceptionInfo *exception)
WizardExport WizardBooleanType LocaleComponentGenesis(void)
WizardExport const char * GetLocaleValue(const LocaleInfo *locale_info)
WizardExport const LocaleInfo ** GetLocaleInfoList(const char *pattern, size_t *number_messages, ExceptionInfo *exception)
WizardExport void LocaleComponentTerminus(void)
static SemaphoreInfo * locale_semaphore
WizardExport LinkedListInfo * GetLocaleOptions(const char *filename, ExceptionInfo *exception)
static const char * LocaleMap
#define WizardLocaleExtent
WizardBooleanType LogWizardEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
#define GetWizardModule()
WizardExport void * AcquireWizardMemory(const size_t size)
WizardExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
WizardExport void * RelinquishWizardMemory(void *memory)
#define wizard_unreferenced(x)
WizardExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
WizardExport SemaphoreInfo * AcquireSemaphoreInfo(void)
WizardExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info)
WizardExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
WizardExport void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info)
WizardExport const void * GetValueFromSplayTree(SplayTreeInfo *splay_tree, const void *key)
WizardExport const void * GetNextValueInSplayTree(SplayTreeInfo *splay_tree)
WizardExport void ResetSplayTreeIterator(SplayTreeInfo *splay_tree)
WizardExport int CompareSplayTreeString(const void *target, const void *source)
WizardExport size_t GetNumberOfNodesInSplayTree(const SplayTreeInfo *splay_tree)
WizardExport SplayTreeInfo * DestroySplayTree(SplayTreeInfo *splay_tree)
WizardExport WizardBooleanType AddValueToSplayTree(SplayTreeInfo *splay_tree, const void *key, const void *value)
WizardExport SplayTreeInfo * NewSplayTree(int(*compare)(const void *, const void *), void *(*relinquish_key)(void *), void *(*relinquish_value)(void *))
WizardExport void SetStringInfoLength(StringInfo *string_info, const size_t length)
WizardExport int LocaleNCompare(const char *p, const char *q, const size_t length)
WizardExport char * DestroyString(char *string)
WizardExport int LocaleCompare(const char *p, const char *q)
WizardExport void SetStringInfoPath(StringInfo *string_info, const char *path)
WizardExport char * ConstantString(const char *source)
WizardExport size_t ConcatenateWizardString(char *destination, const char *source, const size_t length)
WizardExport StringInfo * AcquireStringInfo(const size_t length)
WizardExport StringInfo * ConfigureFileToStringInfo(const char *filename)
WizardExport char * AcquireString(const char *source)
WizardExport void SetStringInfoDatum(StringInfo *string_info, const unsigned char *source)
WizardExport unsigned char * GetStringInfoDatum(const StringInfo *string_info)
WizardExport char * GetEnvironmentValue(const char *name)
WizardExport size_t CopyWizardString(char *destination, const char *source, const size_t length)
WizardExport const char * GetStringInfoPath(const StringInfo *string_info)
WizardExport StringInfo * DestroyStringInfo(StringInfo *string_info)
WizardBooleanType stealth
#define DirectorySeparator
WizardExport WizardBooleanType GlobExpression(const char *expression, const char *pattern, const WizardBooleanType case_insensitive)
WizardExport void GetNextToken(const char *start, const char **end, const size_t extent, char *token)
WizardExport void GetPathComponent(const char *path, PathType type, char *component)
unsigned int WizardStatusType
WizardPrivate char * FileToXML(const char *, const size_t)