]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/locale.c
Update web pages
[imagemagick] / MagickCore / locale.c
index 3e87b1ef104c31c6355d4ec27a8f3909403e571c..a9e9adefd115e3ca7e0bbf29c4c2f842dfaffb19 100644 (file)
 %                      MagickCore Image Locale Methods                        %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 July 2003                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
 #include "MagickCore/exception.h"
 #include "MagickCore/exception-private.h"
 #include "MagickCore/hashmap.h"
+#include "MagickCore/image-private.h"
 #include "MagickCore/locale_.h"
+#include "MagickCore/locale-private.h"
 #include "MagickCore/log.h"
 #include "MagickCore/memory_.h"
+#include "MagickCore/nt-base-private.h"
 #include "MagickCore/semaphore.h"
 #include "MagickCore/splay-tree.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
 #include "MagickCore/token.h"
 #include "MagickCore/utility.h"
+#include "MagickCore/utility-private.h"
 #include "MagickCore/xml-tree.h"
+#include "MagickCore/xml-tree-private.h"
 \f
 /*
   Define declarations.
 */
+#if defined(MAGICKCORE_HAVE_NEWLOCALE) || defined(MAGICKCORE_WINDOWS_SUPPORT)
+#  define MAGICKCORE_LOCALE_SUPPORT
+#endif
 #define LocaleFilename  "locale.xml"
 #define MaxRecursionDepth  200
 \f
-/*
-  Typedef declarations.
-*/
-#if defined(__CYGWIN__)
-typedef struct _locale_t *locale_t;
-#endif
-\f
 /*
   Static declarations.
 */
@@ -88,24 +90,22 @@ static SemaphoreInfo
   *locale_semaphore = (SemaphoreInfo *) NULL;
 
 static SplayTreeInfo
-  *locale_list = (SplayTreeInfo *) NULL;
+  *locale_cache = (SplayTreeInfo *) NULL;
 
-#if defined(MAGICKCORE_HAVE_STRTOD_L)
+#if defined(MAGICKCORE_LOCALE_SUPPORT)
 static volatile locale_t
   c_locale = (locale_t) NULL;
 #endif
-
-static volatile MagickBooleanType
-  instantiate_locale = MagickFalse;
 \f
 /*
   Forward declarations.
 */
 static MagickBooleanType
-  InitializeLocaleList(ExceptionInfo *),
-  LoadLocaleLists(const char *,const char *,ExceptionInfo *);
+  IsLocaleTreeInstantiated(ExceptionInfo *),
+  LoadLocaleCache(SplayTreeInfo *,const char *,const char *,const char *,
+    const size_t,ExceptionInfo *);
 \f
-#if defined(MAGICKCORE_HAVE_STRTOD_L)
+#if defined(MAGICKCORE_LOCALE_SUPPORT)
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -138,7 +138,104 @@ static locale_t AcquireCLocale(void)
 }
 #endif
 \f
-#if defined(MAGICKCORE_HAVE_STRTOD_L)
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%  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_LOCALE_SUPPORT)
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -234,13 +331,13 @@ MagickExport LinkedListInfo *DestroyLocaleOptions(LinkedListInfo *messages)
 %
 */
 
-MagickExport ssize_t FormatLocaleFileList(FILE *file,
+MagickPrivate ssize_t FormatLocaleFileList(FILE *file,
   const char *restrict format,va_list operands)
 {
   ssize_t
     n;
 
-#if defined(MAGICKCORE_HAVE_VFPRINTF_L)
+#if defined(MAGICKCORE_LOCALE_SUPPORT) && defined(MAGICKCORE_HAVE_VFPRINTF_L)
   {
     locale_t
       locale;
@@ -256,7 +353,7 @@ MagickExport ssize_t FormatLocaleFileList(FILE *file,
 #endif
   }
 #else
-#if defined(MAGICKCORE_HAVE_USELOCALE)
+#if defined(MAGICKCORE_LOCALE_SUPPORT) && defined(MAGICKCORE_HAVE_USELOCALE)
   {
     locale_t
       locale,
@@ -325,13 +422,13 @@ MagickExport ssize_t FormatLocaleFile(FILE *file,const char *restrict format,
 %
 */
 
-MagickExport ssize_t FormatLocaleStringList(char *restrict string,
+MagickPrivate ssize_t FormatLocaleStringList(char *restrict string,
   const size_t length,const char *restrict format,va_list operands)
 {
   ssize_t
     n;
 
-#if defined(MAGICKCORE_HAVE_VSNPRINTF_L)
+#if defined(MAGICKCORE_LOCALE_SUPPORT) && defined(MAGICKCORE_HAVE_VSNPRINTF_L)
   {
     locale_t
       locale;
@@ -347,7 +444,7 @@ MagickExport ssize_t FormatLocaleStringList(char *restrict string,
 #endif
   }
 #elif defined(MAGICKCORE_HAVE_VSNPRINTF)
-#if defined(MAGICKCORE_HAVE_USELOCALE)
+#if defined(MAGICKCORE_LOCALE_SUPPORT) && defined(MAGICKCORE_HAVE_USELOCALE)
   {
     locale_t
       locale,
@@ -418,20 +515,23 @@ MagickExport ssize_t FormatLocaleString(char *restrict string,
 MagickExport const LocaleInfo *GetLocaleInfo_(const char *tag,
   ExceptionInfo *exception)
 {
+  const LocaleInfo
+    *locale_info;
+
   assert(exception != (ExceptionInfo *) NULL);
-  if ((locale_list == (SplayTreeInfo *) NULL) ||
-      (instantiate_locale == MagickFalse))
-    if (InitializeLocaleList(exception) == MagickFalse)
-      return((const LocaleInfo *) NULL);
-  if ((locale_list == (SplayTreeInfo *) NULL) ||
-      (GetNumberOfNodesInSplayTree(locale_list) == 0))
+  if (IsLocaleTreeInstantiated(exception) == MagickFalse)
     return((const LocaleInfo *) NULL);
+  LockSemaphoreInfo(locale_semaphore);
   if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0))
     {
-      ResetSplayTreeIterator(locale_list);
-      return((const LocaleInfo *) GetNextValueInSplayTree(locale_list));
+      ResetSplayTreeIterator(locale_cache);
+      locale_info=(const LocaleInfo *) GetNextValueInSplayTree(locale_cache);
+      UnlockSemaphoreInfo(locale_semaphore);
+      return(locale_info);
     }
-  return((const LocaleInfo *) GetValueFromSplayTree(locale_list,tag));
+  locale_info=(const LocaleInfo *) GetValueFromSplayTree(locale_cache,tag);
+  UnlockSemaphoreInfo(locale_semaphore);
+  return(locale_info);
 }
 \f
 /*
@@ -508,21 +608,21 @@ MagickExport const LocaleInfo **GetLocaleInfoList(const char *pattern,
   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);
@@ -580,8 +680,8 @@ static int LocaleTagCompare(const void *x,const void *y)
 }
 #endif
 
-MagickExport char **GetLocaleList(const char *pattern,
-  size_t *number_messages,ExceptionInfo *exception)
+MagickExport char **GetLocaleList(const char *pattern,size_t *number_messages,
+  ExceptionInfo *exception)
 {
   char
     **messages;
@@ -603,17 +703,17 @@ MagickExport char **GetLocaleList(const char *pattern,
   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);
@@ -648,7 +748,7 @@ MagickExport char **GetLocaleList(const char *pattern,
 MagickExport const char *GetLocaleMessage(const char *tag)
 {
   char
-    name[MaxTextExtent];
+    name[MagickLocaleExtent];
 
   const LocaleInfo
     *locale_info;
@@ -659,7 +759,7 @@ MagickExport const char *GetLocaleMessage(const char *tag)
   if ((tag == (const char *) NULL) || (*tag == '\0'))
     return(tag);
   exception=AcquireExceptionInfo();
-  (void) FormatLocaleString(name,MaxTextExtent,"%s/",tag);
+  (void) FormatLocaleString(name,MagickLocaleExtent,"%s/",tag);
   locale_info=GetLocaleInfo_(name,exception);
   exception=DestroyExceptionInfo(exception);
   if (locale_info != (const LocaleInfo *) NULL)
@@ -697,7 +797,7 @@ MagickExport LinkedListInfo *GetLocaleOptions(const char *filename,
   ExceptionInfo *exception)
 {
   char
-    path[MaxTextExtent];
+    path[MagickPathExtent];
 
   const char
     *element;
@@ -712,7 +812,7 @@ MagickExport LinkedListInfo *GetLocaleOptions(const char *filename,
   assert(filename != (const char *) NULL);
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
   assert(exception != (ExceptionInfo *) NULL);
-  (void) CopyMagickString(path,filename,MaxTextExtent);
+  (void) CopyMagickString(path,filename,MagickPathExtent);
   /*
     Load XML from configuration files to linked-list.
   */
@@ -724,7 +824,8 @@ MagickExport LinkedListInfo *GetLocaleOptions(const char *filename,
       element=(const char *) GetNextValueInLinkedList(paths);
       while (element != (const char *) NULL)
       {
-        (void) FormatLocaleString(path,MaxTextExtent,"%s%s",element,filename);
+        (void) FormatLocaleString(path,MagickPathExtent,"%s%s",element,
+          filename);
         (void) LogMagickEvent(LocaleEvent,GetMagickModule(),
           "Searching for locale file: \"%s\"",path);
         xml=ConfigureFileToStringInfo(path);
@@ -742,9 +843,12 @@ MagickExport LinkedListInfo *GetLocaleOptions(const char *filename,
     blob=(char *) NTResourceToBlob(filename);
     if (blob != (char *) NULL)
       {
-        xml=StringToStringInfo(blob);
+        xml=AcquireStringInfo(0);
+        SetStringInfoLength(xml,strlen(blob)+1);
+        SetStringInfoDatum(xml,(const unsigned char *) blob);
+        blob=(char *) RelinquishMagickMemory(blob);
+        SetStringInfoPath(xml,filename);
         (void) AppendValueToLinkedList(messages,xml);
-        blob=DestroyString(blob);
       }
   }
 #endif
@@ -778,7 +882,7 @@ MagickExport const char *GetLocaleValue(const LocaleInfo *locale_info)
 {
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(locale_info != (LocaleInfo *) NULL);
-  assert(locale_info->signature == MagickSignature);
+  assert(locale_info->signature == MagickCoreSignature);
   return(locale_info->message);
 }
 \f
@@ -787,33 +891,32 @@ MagickExport const char *GetLocaleValue(const LocaleInfo *locale_info)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   I n i t i a l i z e L o c a l e L i s t                                   %
++   I s L o c a l e T r e e I n s t a n t i a t e d                           %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  InitializeLocaleList() initializes the locale list.
+%  IsLocaleTreeInstantiated() determines if the locale tree is instantiated.
+%  If not, it instantiates the tree and returns it.
 %
-%  The format of the InitializeLocaleList method is:
+%  The format of the IsLocaleInstantiated method is:
 %
-%      MagickBooleanType InitializeLocaleList(ExceptionInfo *exception)
+%      MagickBooleanType IsLocaleTreeInstantiated(ExceptionInfo *exception)
 %
 %  A description of each parameter follows.
 %
 %    o exception: return any errors or warnings in this structure.
 %
 */
-static MagickBooleanType InitializeLocaleList(ExceptionInfo *exception)
+static MagickBooleanType IsLocaleTreeInstantiated(ExceptionInfo *exception)
 {
-  if ((locale_list == (SplayTreeInfo *) NULL) &&
-      (instantiate_locale == MagickFalse))
+  if (locale_cache == (SplayTreeInfo *) NULL)
     {
       if (locale_semaphore == (SemaphoreInfo *) NULL)
-        AcquireSemaphoreInfo(&locale_semaphore);
+        ActivateSemaphoreInfo(&locale_semaphore);
       LockSemaphoreInfo(locale_semaphore);
-      if ((locale_list == (SplayTreeInfo *) NULL) &&
-          (instantiate_locale == MagickFalse))
+      if (locale_cache == (SplayTreeInfo *) NULL)
         {
           char
             *locale;
@@ -835,13 +938,12 @@ static MagickBooleanType InitializeLocaleList(ExceptionInfo *exception)
             locale=GetEnvironmentValue("LANG");
           if (locale == (char *) NULL)
             locale=ConstantString("C");
-          (void) LoadLocaleLists(LocaleFilename,locale,exception);
+          locale_cache=AcquireLocaleSplayTree(LocaleFilename,locale,exception);
           locale=DestroyString(locale);
-          instantiate_locale=MagickTrue;
         }
       UnlockSemaphoreInfo(locale_semaphore);
     }
-  return(locale_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
+  return(locale_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
 }
 \f
 /*
@@ -876,23 +978,31 @@ static MagickBooleanType InitializeLocaleList(ExceptionInfo *exception)
 MagickExport double InterpretLocaleValue(const char *restrict string,
   char **restrict sentinal)
 {
+  char
+    *q;
+
   double
     value;
 
-#if defined(MAGICKCORE_HAVE_STRTOD_L)
-  {
-    locale_t
-      locale;
-
-    locale=AcquireCLocale();
-    if (locale == (locale_t) NULL)
-      value=strtod(string,sentinal);
-    else
-      value=strtod_l(string,sentinal,locale);
-  }
+  if ((*string == '0') && ((string[1] | 0x20)=='x'))
+    value=(double) strtoul(string,&q,16);
+  else
+    {
+#if defined(MAGICKCORE_LOCALE_SUPPORT) && defined(MAGICKCORE_HAVE_STRTOD_L)
+      locale_t
+        locale;
+
+      locale=AcquireCLocale();
+      if (locale == (locale_t) NULL)
+        value=strtod(string,&q);
+      else
+        value=strtod_l(string,&q,locale);
 #else
-  value=strtod(string,sentinal);
+      value=strtod(string,&q);
 #endif
+    }
+  if (sentinal != (char **) NULL)
+    *sentinal=q;
   return(value);
 }
 \f
@@ -979,13 +1089,14 @@ MagickExport MagickBooleanType ListLocaleInfo(FILE *file,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  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:
 %
@@ -1022,21 +1133,6 @@ static void ChopLocaleComponents(char *path,const size_t components)
     *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)
@@ -1051,14 +1147,14 @@ static void LocaleFatalErrorHandler(
   exit(1);
 }
 
-
-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],
-    message[MaxTextExtent],
-    tag[MaxTextExtent],
+    keyword[MagickLocaleExtent],
+    message[MagickLocaleExtent],
+    tag[MagickLocaleExtent],
     *token;
 
   const char
@@ -1070,7 +1166,7 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
   LocaleInfo
     *locale_info;
 
-  MagickBooleanType
+  MagickStatusType
     status;
 
   register char
@@ -1083,13 +1179,6 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
     "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';
@@ -1105,7 +1194,7 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
     GetMagickToken(q,&q,token);
     if (*token == '\0')
       break;
-    (void) CopyMagickString(keyword,token,MaxTextExtent);
+    (void) CopyMagickString(keyword,token,MagickLocaleExtent);
     if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
       {
         /*
@@ -1139,7 +1228,7 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
         */
         while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
         {
-          (void) CopyMagickString(keyword,token,MaxTextExtent);
+          (void) CopyMagickString(keyword,token,MagickLocaleExtent);
           GetMagickToken(q,&q,token);
           if (*token != '=')
             continue;
@@ -1158,22 +1247,23 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
               else
                 {
                   char
-                    path[MaxTextExtent],
+                    path[MagickPathExtent],
                     *xml;
 
                   *path='\0';
                   GetPathComponent(filename,HeadPath,path);
                   if (*path != '\0')
                     (void) ConcatenateMagickString(path,DirectorySeparator,
-                      MaxTextExtent);
+                      MagickPathExtent);
                   if (*token == *DirectorySeparator)
-                    (void) CopyMagickString(path,token,MaxTextExtent);
+                    (void) CopyMagickString(path,token,MagickPathExtent);
                   else
-                    (void) ConcatenateMagickString(path,token,MaxTextExtent);
-                  xml=FileToString(path,~0,exception);
+                    (void) ConcatenateMagickString(path,token,MagickPathExtent);
+                  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);
                     }
                 }
@@ -1188,7 +1278,7 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
         */
         while ((*token != '>') && (*q != '\0'))
         {
-          (void) CopyMagickString(keyword,token,MaxTextExtent);
+          (void) CopyMagickString(keyword,token,MagickLocaleExtent);
           GetMagickToken(q,&q,token);
           if (*token != '=')
             continue;
@@ -1199,7 +1289,7 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
     if (LocaleCompare(keyword,"</locale>") == 0)
       {
         ChopLocaleComponents(tag,1);
-        (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
+        (void) ConcatenateMagickString(tag,"/",MagickLocaleExtent);
         continue;
       }
     if (LocaleCompare(keyword,"<localemap>") == 0)
@@ -1213,15 +1303,15 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
         */
         while ((*token != '>') && (*q != '\0'))
         {
-          (void) CopyMagickString(keyword,token,MaxTextExtent);
+          (void) CopyMagickString(keyword,token,MagickLocaleExtent);
           GetMagickToken(q,&q,token);
           if (*token != '=')
             continue;
           GetMagickToken(q,&q,token);
           if (LocaleCompare(keyword,"name") == 0)
             {
-              (void) ConcatenateMagickString(tag,token,MaxTextExtent);
-              (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
+              (void) ConcatenateMagickString(tag,token,MagickLocaleExtent);
+              (void) ConcatenateMagickString(tag,"/",MagickLocaleExtent);
             }
         }
         for (p=(char *) q; (*q != '<') && (*q != '\0'); q++) ;
@@ -1230,7 +1320,8 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
         q--;
         while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p))
           q--;
-        (void) CopyMagickString(message,p,(size_t) (q-p+2));
+        (void) CopyMagickString(message,p,MagickMin((size_t) (q-p+2),
+          MagickLocaleExtent));
         locale_info=(LocaleInfo *) AcquireMagickMemory(sizeof(*locale_info));
         if (locale_info == (LocaleInfo *) NULL)
           ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
@@ -1238,21 +1329,21 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
         locale_info->path=ConstantString(filename);
         locale_info->tag=ConstantString(tag);
         locale_info->message=ConstantString(message);
-        locale_info->signature=MagickSignature;
-        status=AddValueToSplayTree(locale_list,locale_info->tag,locale_info);
+        locale_info->signature=MagickCoreSignature;
+        status=AddValueToSplayTree(locale_cache,locale_info->tag,locale_info);
         if (status == MagickFalse)
           (void) ThrowMagickException(exception,GetMagickModule(),
             ResourceLimitError,"MemoryAllocationFailed","`%s'",
             locale_info->tag);
-        (void) ConcatenateMagickString(tag,message,MaxTextExtent);
-        (void) ConcatenateMagickString(tag,"\n",MaxTextExtent);
+        (void) ConcatenateMagickString(tag,message,MagickLocaleExtent);
+        (void) ConcatenateMagickString(tag,"\n",MagickLocaleExtent);
         q++;
         continue;
       }
     if (LocaleCompare(keyword,"</message>") == 0)
       {
         ChopLocaleComponents(tag,2);
-        (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
+        (void) ConcatenateMagickString(tag,"/",MagickLocaleExtent);
         continue;
       }
     if (*keyword == '<')
@@ -1266,13 +1357,13 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
           {
             ChopLocaleComponents(tag,1);
             if (*tag != '\0')
-              (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
+              (void) ConcatenateMagickString(tag,"/",MagickLocaleExtent);
             continue;
           }
         token[strlen(token)-1]='\0';
-        (void) CopyMagickString(token,token+1,MaxTextExtent);
-        (void) ConcatenateMagickString(tag,token,MaxTextExtent);
-        (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
+        (void) CopyMagickString(token,token+1,MagickLocaleExtent);
+        (void) ConcatenateMagickString(tag,token,MagickLocaleExtent);
+        (void) ConcatenateMagickString(tag,"/",MagickLocaleExtent);
         continue;
       }
     GetMagickToken(q,(const char **) NULL,token);
@@ -1281,80 +1372,7 @@ static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
   }
   token=(char *) RelinquishMagickMemory(token);
   (void) SetFatalErrorHandler(fatal_handler);
-  return(status);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%  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_EMBEDDABLE_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
 /*
@@ -1375,9 +1393,10 @@ static MagickBooleanType LoadLocaleLists(const char *filename,
 %      MagickBooleanType LocaleComponentGenesis(void)
 %
 */
-MagickExport MagickBooleanType LocaleComponentGenesis(void)
+MagickPrivate MagickBooleanType LocaleComponentGenesis(void)
 {
-  AcquireSemaphoreInfo(&locale_semaphore);
+  if (locale_semaphore == (SemaphoreInfo *) NULL)
+    locale_semaphore=AcquireSemaphoreInfo();
   return(MagickTrue);
 }
 \f
@@ -1399,15 +1418,16 @@ MagickExport MagickBooleanType LocaleComponentGenesis(void)
 %      LocaleComponentTerminus(void)
 %
 */
-MagickExport void LocaleComponentTerminus(void)
+MagickPrivate void LocaleComponentTerminus(void)
 {
   if (locale_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&locale_semaphore);
+    ActivateSemaphoreInfo(&locale_semaphore);
   LockSemaphoreInfo(locale_semaphore);
-#if defined(MAGICKCORE_HAVE_STRTOD_L)
+  if (locale_cache != (SplayTreeInfo *) NULL)
+    locale_cache=DestroySplayTree(locale_cache);
+#if defined(MAGICKCORE_LOCALE_SUPPORT)
   DestroyCLocale();
 #endif
-  instantiate_locale=MagickFalse;
   UnlockSemaphoreInfo(locale_semaphore);
-  DestroySemaphoreInfo(&locale_semaphore);
+  RelinquishSemaphoreInfo(&locale_semaphore);
 }