#include "MagickCore/utility.h"
#include "MagickCore/utility-private.h"
#include "MagickCore/xml-tree.h"
+#include "MagickCore/xml-tree-private.h"
\f
/*
Define declarations.
*locale_semaphore = (SemaphoreInfo *) NULL;
static SplayTreeInfo
- *locale_list = (SplayTreeInfo *) NULL;
+ *locale_cache = (SplayTreeInfo *) NULL;
#if defined(MAGICKCORE_HAVE_STRTOD_L)
static volatile locale_t
*/
static MagickBooleanType
IsLocaleTreeInstantiated(ExceptionInfo *),
- LoadLocaleLists(const char *,const char *,ExceptionInfo *);
+ LoadLocaleCache(SplayTreeInfo *,const char *,const char *,const char *,
+ const size_t,ExceptionInfo *);
\f
#if defined(MAGICKCORE_HAVE_STRTOD_L)
/*
}
#endif
\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% A c q u i r e L o c a l e S p l a y T r e e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% AcquireLocaleSplayTree() caches one or more locale configurations which
+% provides a mapping between locale attributes and a locale tag.
+%
+% The format of the AcquireLocaleSplayTree method is:
+%
+% SplayTreeInfo *AcquireLocaleSplayTree(const char *filename,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o filename: the font file tag.
+%
+% o locale: the actual locale.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+
+static void *DestroyLocaleNode(void *locale_info)
+{
+ register LocaleInfo
+ *p;
+
+ p=(LocaleInfo *) locale_info;
+ if (p->path != (char *) NULL)
+ p->path=DestroyString(p->path);
+ if (p->tag != (char *) NULL)
+ p->tag=DestroyString(p->tag);
+ if (p->message != (char *) NULL)
+ p->message=DestroyString(p->message);
+ return(RelinquishMagickMemory(p));
+}
+
+static SplayTreeInfo *AcquireLocaleSplayTree(const char *filename,
+ const char *locale,ExceptionInfo *exception)
+{
+ MagickStatusType
+ status;
+
+ SplayTreeInfo
+ *locale_cache;
+
+ locale_cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL,
+ DestroyLocaleNode);
+ if (locale_cache == (SplayTreeInfo *) NULL)
+ ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+ status=MagickTrue;
+#if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
+ {
+ const StringInfo
+ *option;
+
+ LinkedListInfo
+ *options;
+
+ options=GetLocaleOptions(filename,exception);
+ option=(const StringInfo *) GetNextValueInLinkedList(options);
+ while (option != (const StringInfo *) NULL)
+ {
+ status&=LoadLocaleCache(locale_cache,(const char *)
+ GetStringInfoDatum(option),GetStringInfoPath(option),locale,0,
+ exception);
+ option=(const StringInfo *) GetNextValueInLinkedList(options);
+ }
+ options=DestroyLocaleOptions(options);
+ if (GetNumberOfNodesInSplayTree(locale_cache) == 0)
+ {
+ options=GetLocaleOptions("english.xml",exception);
+ option=(const StringInfo *) GetNextValueInLinkedList(options);
+ while (option != (const StringInfo *) NULL)
+ {
+ status&=LoadLocaleCache(locale_cache,(const char *)
+ GetStringInfoDatum(option),GetStringInfoPath(option),locale,0,
+ exception);
+ option=(const StringInfo *) GetNextValueInLinkedList(options);
+ }
+ options=DestroyLocaleOptions(options);
+ }
+ }
+#endif
+ if (GetNumberOfNodesInSplayTree(locale_cache) == 0)
+ status&=LoadLocaleCache(locale_cache,LocaleMap,"built-in",locale,0,
+ exception);
+ return(locale_cache);
+}
+\f
#if defined(MAGICKCORE_HAVE_STRTOD_L)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
LockSemaphoreInfo(locale_semaphore);
if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0))
{
- ResetSplayTreeIterator(locale_list);
- locale_info=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
+ ResetSplayTreeIterator(locale_cache);
+ locale_info=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache);
UnlockSemaphoreInfo(locale_semaphore);
return(locale_info);
}
- locale_info=(const LocaleInfo *) GetValueFromSplayTree(locale_list,tag);
+ locale_info=(const LocaleInfo *) GetValueFromSplayTree(locale_cache,tag);
UnlockSemaphoreInfo(locale_semaphore);
return(locale_info);
}
if (p == (const LocaleInfo *) NULL)
return((const LocaleInfo **) NULL);
messages=(const LocaleInfo **) AcquireQuantumMemory((size_t)
- GetNumberOfNodesInSplayTree(locale_list)+1UL,sizeof(*messages));
+ GetNumberOfNodesInSplayTree(locale_cache)+1UL,sizeof(*messages));
if (messages == (const LocaleInfo **) NULL)
return((const LocaleInfo **) NULL);
/*
Generate locale list.
*/
LockSemaphoreInfo(locale_semaphore);
- ResetSplayTreeIterator(locale_list);
- p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
+ ResetSplayTreeIterator(locale_cache);
+ p=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache);
for (i=0; p != (const LocaleInfo *) NULL; )
{
if ((p->stealth == MagickFalse) &&
(GlobExpression(p->tag,pattern,MagickTrue) != MagickFalse))
messages[i++]=p;
- p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
+ p=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache);
}
UnlockSemaphoreInfo(locale_semaphore);
qsort((void *) messages,(size_t) i,sizeof(*messages),LocaleInfoCompare);
if (p == (const LocaleInfo *) NULL)
return((char **) NULL);
messages=(char **) AcquireQuantumMemory((size_t)
- GetNumberOfNodesInSplayTree(locale_list)+1UL,sizeof(*messages));
+ GetNumberOfNodesInSplayTree(locale_cache)+1UL,sizeof(*messages));
if (messages == (char **) NULL)
return((char **) NULL);
LockSemaphoreInfo(locale_semaphore);
- p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
+ p=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache);
for (i=0; p != (const LocaleInfo *) NULL; )
{
if ((p->stealth == MagickFalse) &&
(GlobExpression(p->tag,pattern,MagickTrue) != MagickFalse))
messages[i++]=ConstantString(p->tag);
- p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
+ p=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache);
}
UnlockSemaphoreInfo(locale_semaphore);
qsort((void *) messages,(size_t) i,sizeof(*messages),LocaleTagCompare);
*/
static MagickBooleanType IsLocaleTreeInstantiated(ExceptionInfo *exception)
{
- if (locale_semaphore == (SemaphoreInfo *) NULL)
- ActivateSemaphoreInfo(&locale_semaphore);
- LockSemaphoreInfo(locale_semaphore);
- if (locale_list == (SplayTreeInfo *) NULL)
+ if (locale_cache == (SplayTreeInfo *) NULL)
{
- char
- *locale;
-
- register const char
- *p;
-
- locale=(char *) NULL;
- p=setlocale(LC_CTYPE,(const char *) NULL);
- if (p != (const char *) NULL)
- locale=ConstantString(p);
- if (locale == (char *) NULL)
- locale=GetEnvironmentValue("LC_ALL");
- if (locale == (char *) NULL)
- locale=GetEnvironmentValue("LC_MESSAGES");
- if (locale == (char *) NULL)
- locale=GetEnvironmentValue("LC_CTYPE");
- if (locale == (char *) NULL)
- locale=GetEnvironmentValue("LANG");
- if (locale == (char *) NULL)
- locale=ConstantString("C");
- (void) LoadLocaleLists(LocaleFilename,locale,exception);
- locale=DestroyString(locale);
+ if (locale_semaphore == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&locale_semaphore);
+ LockSemaphoreInfo(locale_semaphore);
+ if (locale_cache == (SplayTreeInfo *) NULL)
+ {
+ char
+ *locale;
+
+ register const char
+ *p;
+
+ locale=(char *) NULL;
+ p=setlocale(LC_CTYPE,(const char *) NULL);
+ if (p != (const char *) NULL)
+ locale=ConstantString(p);
+ if (locale == (char *) NULL)
+ locale=GetEnvironmentValue("LC_ALL");
+ if (locale == (char *) NULL)
+ locale=GetEnvironmentValue("LC_MESSAGES");
+ if (locale == (char *) NULL)
+ locale=GetEnvironmentValue("LC_CTYPE");
+ if (locale == (char *) NULL)
+ locale=GetEnvironmentValue("LANG");
+ if (locale == (char *) NULL)
+ locale=ConstantString("C");
+ locale_cache=AcquireLocaleSplayTree(LocaleFilename,locale,exception);
+ locale=DestroyString(locale);
+ }
+ UnlockSemaphoreInfo(locale_semaphore);
}
- UnlockSemaphoreInfo(locale_semaphore);
- return(locale_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
+ return(locale_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
}
\f
/*
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% LoadLocaleList() loads the locale configuration file which provides a mapping
+% LoadLocaleCache() loads the locale configurations which provides a mapping
% between locale attributes and a locale name.
%
-% The format of the LoadLocaleList method is:
+% The format of the LoadLocaleCache method is:
%
-% MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
-% const size_t depth,ExceptionInfo *exception)
+% MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
+% const char *xml,const char *filename,const size_t depth,
+% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
*path='\0';
}
-static void *DestroyLocaleNode(void *locale_info)
-{
- register LocaleInfo
- *p;
-
- p=(LocaleInfo *) locale_info;
- if (p->path != (char *) NULL)
- p->path=DestroyString(p->path);
- if (p->tag != (char *) NULL)
- p->tag=DestroyString(p->tag);
- if (p->message != (char *) NULL)
- p->message=DestroyString(p->message);
- return(RelinquishMagickMemory(p));
-}
-
static void LocaleFatalErrorHandler(
const ExceptionType magick_unused(severity),
const char *reason,const char *description)
return(y);
}
-static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
- const char *locale,const size_t depth,ExceptionInfo *exception)
+static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
+ const char *xml,const char *filename,const char *locale,const size_t depth,
+ ExceptionInfo *exception)
{
char
keyword[MaxTextExtent],
"Loading locale configure file \"%s\" ...",filename);
if (xml == (const char *) NULL)
return(MagickFalse);
- if (locale_list == (SplayTreeInfo *) NULL)
- {
- locale_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL,
- DestroyLocaleNode);
- if (locale_list == (SplayTreeInfo *) NULL)
- return(MagickFalse);
- }
status=MagickTrue;
locale_info=(LocaleInfo *) NULL;
*tag='\0';
(void) CopyMagickString(path,token,MaxTextExtent);
else
(void) ConcatenateMagickString(path,token,MaxTextExtent);
- xml=FileToString(path,~0UL,exception);
+ xml=FileToXML(path,~0UL);
if (xml != (char *) NULL)
{
- status=LoadLocaleList(xml,path,locale,depth+1,exception);
+ status&=LoadLocaleCache(locale_cache,xml,path,locale,
+ depth+1,exception);
xml=(char *) RelinquishMagickMemory(xml);
}
}
locale_info->tag=ConstantString(tag);
locale_info->message=ConstantString(message);
locale_info->signature=MagickSignature;
- status=AddValueToSplayTree(locale_list,locale_info->tag,locale_info);
+ status=AddValueToSplayTree(locale_cache,locale_info->tag,locale_info);
if (status == MagickFalse)
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",
% %
% %
% %
-% L o a d L o c a l e L i s t s %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% LoadLocaleList() loads one or more locale configuration file which
-% provides a mapping between locale attributes and a locale tag.
-%
-% The format of the LoadLocaleLists method is:
-%
-% MagickBooleanType LoadLocaleLists(const char *filename,
-% ExceptionInfo *exception)
-%
-% A description of each parameter follows:
-%
-% o filename: the font file tag.
-%
-% o locale: the actual locale.
-%
-% o exception: return any errors or warnings in this structure.
-%
-*/
-static MagickBooleanType LoadLocaleLists(const char *filename,
- const char *locale,ExceptionInfo *exception)
-{
-#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
- return(LoadLocaleList(LocaleMap,"built-in",locale,0,exception));
-#else
- const StringInfo
- *option;
-
- LinkedListInfo
- *options;
-
- MagickStatusType
- status;
-
- status=MagickFalse;
- options=GetLocaleOptions(filename,exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- while (option != (const StringInfo *) NULL)
- {
- status&=LoadLocaleList((const char *) GetStringInfoDatum(option),
- GetStringInfoPath(option),locale,0,exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- }
- options=DestroyLocaleOptions(options);
- if ((locale_list == (SplayTreeInfo *) NULL) ||
- (GetNumberOfNodesInSplayTree(locale_list) == 0))
- {
- options=GetLocaleOptions("english.xml",exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- while (option != (const StringInfo *) NULL)
- {
- status&=LoadLocaleList((const char *) GetStringInfoDatum(option),
- GetStringInfoPath(option),locale,0,exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- }
- options=DestroyLocaleOptions(options);
- }
- if ((locale_list == (SplayTreeInfo *) NULL) ||
- (GetNumberOfNodesInSplayTree(locale_list) == 0))
- status&=LoadLocaleList(LocaleMap,"built-in",locale,0,exception);
- return(status != 0 ? MagickTrue : MagickFalse);
-#endif
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
+ L o c a l e C o m p o n e n t G e n e s i s %
% %
% %
*/
MagickPrivate MagickBooleanType LocaleComponentGenesis(void)
{
- locale_semaphore=AcquireSemaphoreInfo();
+ if (locale_semaphore == (SemaphoreInfo *) NULL)
+ locale_semaphore=AcquireSemaphoreInfo();
return(MagickTrue);
}
\f
if (locale_semaphore == (SemaphoreInfo *) NULL)
ActivateSemaphoreInfo(&locale_semaphore);
LockSemaphoreInfo(locale_semaphore);
- if (locale_list != (SplayTreeInfo *) NULL)
- locale_list=DestroySplayTree(locale_list);
+ if (locale_cache != (SplayTreeInfo *) NULL)
+ locale_cache=DestroySplayTree(locale_cache);
#if defined(MAGICKCORE_HAVE_STRTOD_L)
DestroyCLocale();
#endif