]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/locale.c
(no commit message)
[imagemagick] / MagickCore / locale.c
index 33312702d83ab4ac90d5e4c3bea9a6676ba862e6..866b21db7d59f599792505453b04f573f19f334e 100644 (file)
@@ -59,6 +59,7 @@
 #include "MagickCore/utility.h"
 #include "MagickCore/utility-private.h"
 #include "MagickCore/xml-tree.h"
+#include "MagickCore/xml-tree-private.h"
 \f
 /*
   Define declarations.
@@ -105,8 +106,8 @@ static volatile locale_t
 */
 static MagickBooleanType
   IsLocaleTreeInstantiated(ExceptionInfo *),
-  LoadLocaleCache(const char *,const char *,const char *,const size_t,
-    ExceptionInfo *);
+  LoadLocaleCache(SplayTreeInfo *,const char *,const char *,const char *,
+    const size_t,ExceptionInfo *);
 \f
 #if defined(MAGICKCORE_HAVE_STRTOD_L)
 /*
@@ -188,15 +189,6 @@ static void *DestroyLocaleNode(void *locale_info)
 static SplayTreeInfo *AcquireLocaleSplayTree(const char *filename,
   const char *locale,ExceptionInfo *exception)
 {
-#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
-  return(LoadLocaleCache(LocaleMap,"built-in",locale,0,exception));
-#else
-  const StringInfo
-    *option;
-
-  LinkedListInfo
-    *options;
-
   MagickStatusType
     status;
 
@@ -208,33 +200,43 @@ static SplayTreeInfo *AcquireLocaleSplayTree(const char *filename,
   if (locale_cache == (SplayTreeInfo *) NULL)
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   status=MagickTrue;
-  options=GetLocaleOptions(filename,exception);
-  option=(const StringInfo *) GetNextValueInLinkedList(options);
-  while (option != (const StringInfo *) NULL)
+#if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
   {
-    status&=LoadLocaleCache((const char *) GetStringInfoDatum(option),
-      GetStringInfoPath(option),locale,0,exception);
+    const StringInfo
+      *option;
+
+    LinkedListInfo
+      *options;
+
+    options=GetLocaleOptions(filename,exception);
     option=(const StringInfo *) GetNextValueInLinkedList(options);
-  }
-  options=DestroyLocaleOptions(options);
-  if ((locale_cache == (SplayTreeInfo *) NULL) ||
-      (GetNumberOfNodesInSplayTree(locale_cache) == 0))
+    while (option != (const StringInfo *) NULL)
     {
-      options=GetLocaleOptions("english.xml",exception);
+      status&=LoadLocaleCache(locale_cache,(const char *)
+        GetStringInfoDatum(option),GetStringInfoPath(option),locale,0,
+        exception);
       option=(const StringInfo *) GetNextValueInLinkedList(options);
-      while (option != (const StringInfo *) NULL)
+    }
+    options=DestroyLocaleOptions(options);
+    if (GetNumberOfNodesInSplayTree(locale_cache) == 0)
       {
-        status&=LoadLocaleCache((const char *) GetStringInfoDatum(option),
-          GetStringInfoPath(option),locale,0,exception);
+        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);
       }
-      options=DestroyLocaleOptions(options);
-    }
-  if ((locale_cache == (SplayTreeInfo *) NULL) ||
-      (GetNumberOfNodesInSplayTree(locale_cache) == 0))
-    status&=LoadLocaleCache(LocaleMap,"built-in",locale,0,exception);
-  return(locale_cache);
+  }
 #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)
@@ -911,35 +913,38 @@ MagickExport const char *GetLocaleValue(const LocaleInfo *locale_info)
 */
 static MagickBooleanType IsLocaleTreeInstantiated(ExceptionInfo *exception)
 {
-  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);
+      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_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
 }
 \f
@@ -1091,8 +1096,9 @@ MagickExport MagickBooleanType ListLocaleInfo(FILE *file,
 %
 %  The format of the LoadLocaleCache method is:
 %
-%      MagickBooleanType LoadLocaleCache(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:
 %
@@ -1150,8 +1156,9 @@ static inline size_t MagickMin(const size_t x,const size_t y)
   return(y);
 }
 
-static MagickBooleanType LoadLocaleCache(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],
@@ -1181,13 +1188,6 @@ static MagickBooleanType LoadLocaleCache(const char *xml,const char *filename,
     "Loading locale configure file \"%s\" ...",filename);
   if (xml == (const char *) NULL)
     return(MagickFalse);
-  if (locale_cache == (SplayTreeInfo *) NULL)
-    {
-      locale_cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL,
-        DestroyLocaleNode);
-      if (locale_cache == (SplayTreeInfo *) NULL)
-        return(MagickFalse);
-    }
   status=MagickTrue;
   locale_info=(LocaleInfo *) NULL;
   *tag='\0';
@@ -1268,10 +1268,11 @@ static MagickBooleanType LoadLocaleCache(const char *xml,const char *filename,
                     (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=LoadLocaleCache(xml,path,locale,depth+1,exception);
+                      status&=LoadLocaleCache(locale_cache,xml,path,locale,
+                        depth+1,exception);
                       xml=(char *) RelinquishMagickMemory(xml);
                     }
                 }
@@ -1403,7 +1404,8 @@ static MagickBooleanType LoadLocaleCache(const char *xml,const char *filename,
 */
 MagickPrivate MagickBooleanType LocaleComponentGenesis(void)
 {
-  locale_semaphore=AcquireSemaphoreInfo();
+  if (locale_semaphore == (SemaphoreInfo *) NULL)
+    locale_semaphore=AcquireSemaphoreInfo();
   return(MagickTrue);
 }
 \f