]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/locale.c
Update web pages
[imagemagick] / MagickCore / locale.c
index 02626ea6f35680592b06090e9491abe9276fe3f0..a9e9adefd115e3ca7e0bbf29c4c2f842dfaffb19 100644 (file)
@@ -17,7 +17,7 @@
 %                                 July 2003                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2014 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  %
@@ -46,6 +46,7 @@
 #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"
 /*
   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.
 */
@@ -96,7 +92,7 @@ static SemaphoreInfo
 static SplayTreeInfo
   *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
@@ -109,7 +105,7 @@ static MagickBooleanType
   LoadLocaleCache(SplayTreeInfo *,const char *,const char *,const char *,
     const size_t,ExceptionInfo *);
 \f
-#if defined(MAGICKCORE_HAVE_STRTOD_L)
+#if defined(MAGICKCORE_LOCALE_SUPPORT)
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -239,7 +235,7 @@ static SplayTreeInfo *AcquireLocaleSplayTree(const char *filename,
   return(locale_cache);
 }
 \f
-#if defined(MAGICKCORE_HAVE_STRTOD_L)
+#if defined(MAGICKCORE_LOCALE_SUPPORT)
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -341,7 +337,7 @@ MagickPrivate ssize_t FormatLocaleFileList(FILE *file,
   ssize_t
     n;
 
-#if defined(MAGICKCORE_HAVE_VFPRINTF_L)
+#if defined(MAGICKCORE_LOCALE_SUPPORT) && defined(MAGICKCORE_HAVE_VFPRINTF_L)
   {
     locale_t
       locale;
@@ -357,7 +353,7 @@ MagickPrivate ssize_t FormatLocaleFileList(FILE *file,
 #endif
   }
 #else
-#if defined(MAGICKCORE_HAVE_USELOCALE)
+#if defined(MAGICKCORE_LOCALE_SUPPORT) && defined(MAGICKCORE_HAVE_USELOCALE)
   {
     locale_t
       locale,
@@ -432,7 +428,7 @@ MagickPrivate ssize_t FormatLocaleStringList(char *restrict string,
   ssize_t
     n;
 
-#if defined(MAGICKCORE_HAVE_VSNPRINTF_L)
+#if defined(MAGICKCORE_LOCALE_SUPPORT) && defined(MAGICKCORE_HAVE_VSNPRINTF_L)
   {
     locale_t
       locale;
@@ -448,7 +444,7 @@ MagickPrivate 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,
@@ -684,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;
@@ -752,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;
@@ -763,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)
@@ -801,7 +797,7 @@ MagickExport LinkedListInfo *GetLocaleOptions(const char *filename,
   ExceptionInfo *exception)
 {
   char
-    path[MaxTextExtent];
+    path[MagickPathExtent];
 
   const char
     *element;
@@ -816,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.
   */
@@ -828,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);
@@ -848,7 +845,8 @@ MagickExport LinkedListInfo *GetLocaleOptions(const char *filename,
       {
         xml=AcquireStringInfo(0);
         SetStringInfoLength(xml,strlen(blob)+1);
-        SetStringInfoDatum(xml,(unsigned char *) blob);
+        SetStringInfoDatum(xml,(const unsigned char *) blob);
+        blob=(char *) RelinquishMagickMemory(blob);
         SetStringInfoPath(xml,filename);
         (void) AppendValueToLinkedList(messages,xml);
       }
@@ -884,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
@@ -990,7 +988,7 @@ MagickExport double InterpretLocaleValue(const char *restrict string,
     value=(double) strtoul(string,&q,16);
   else
     {
-#if defined(MAGICKCORE_HAVE_STRTOD_L)
+#if defined(MAGICKCORE_LOCALE_SUPPORT) && defined(MAGICKCORE_HAVE_STRTOD_L)
       locale_t
         locale;
 
@@ -1149,21 +1147,14 @@ static void LocaleFatalErrorHandler(
   exit(1);
 }
 
-static inline size_t MagickMin(const size_t x,const size_t y)
-{
-  if (x < y)
-    return(x);
-  return(y);
-}
-
 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
@@ -1175,7 +1166,7 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
   LocaleInfo
     *locale_info;
 
-  MagickBooleanType
+  MagickStatusType
     status;
 
   register char
@@ -1203,7 +1194,7 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
     GetMagickToken(q,&q,token);
     if (*token == '\0')
       break;
-    (void) CopyMagickString(keyword,token,MaxTextExtent);
+    (void) CopyMagickString(keyword,token,MagickLocaleExtent);
     if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
       {
         /*
@@ -1237,7 +1228,7 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
         */
         while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
         {
-          (void) CopyMagickString(keyword,token,MaxTextExtent);
+          (void) CopyMagickString(keyword,token,MagickLocaleExtent);
           GetMagickToken(q,&q,token);
           if (*token != '=')
             continue;
@@ -1256,18 +1247,18 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
               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);
+                    (void) ConcatenateMagickString(path,token,MagickPathExtent);
                   xml=FileToXML(path,~0UL);
                   if (xml != (char *) NULL)
                     {
@@ -1287,7 +1278,7 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
         */
         while ((*token != '>') && (*q != '\0'))
         {
-          (void) CopyMagickString(keyword,token,MaxTextExtent);
+          (void) CopyMagickString(keyword,token,MagickLocaleExtent);
           GetMagickToken(q,&q,token);
           if (*token != '=')
             continue;
@@ -1298,7 +1289,7 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
     if (LocaleCompare(keyword,"</locale>") == 0)
       {
         ChopLocaleComponents(tag,1);
-        (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
+        (void) ConcatenateMagickString(tag,"/",MagickLocaleExtent);
         continue;
       }
     if (LocaleCompare(keyword,"<localemap>") == 0)
@@ -1312,15 +1303,15 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
         */
         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++) ;
@@ -1330,7 +1321,7 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
         while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p))
           q--;
         (void) CopyMagickString(message,p,MagickMin((size_t) (q-p+2),
-          MaxTextExtent));
+          MagickLocaleExtent));
         locale_info=(LocaleInfo *) AcquireMagickMemory(sizeof(*locale_info));
         if (locale_info == (LocaleInfo *) NULL)
           ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
@@ -1338,21 +1329,21 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
         locale_info->path=ConstantString(filename);
         locale_info->tag=ConstantString(tag);
         locale_info->message=ConstantString(message);
-        locale_info->signature=MagickSignature;
+        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 == '<')
@@ -1366,13 +1357,13 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
           {
             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);
@@ -1381,7 +1372,7 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
   }
   token=(char *) RelinquishMagickMemory(token);
   (void) SetFatalErrorHandler(fatal_handler);
-  return(status);
+  return(status != 0 ? MagickTrue : MagickFalse);
 }
 \f
 /*
@@ -1404,7 +1395,8 @@ static MagickBooleanType LoadLocaleCache(SplayTreeInfo *locale_cache,
 */
 MagickPrivate MagickBooleanType LocaleComponentGenesis(void)
 {
-  locale_semaphore=AcquireSemaphoreInfo();
+  if (locale_semaphore == (SemaphoreInfo *) NULL)
+    locale_semaphore=AcquireSemaphoreInfo();
   return(MagickTrue);
 }
 \f
@@ -1433,7 +1425,7 @@ MagickPrivate void LocaleComponentTerminus(void)
   LockSemaphoreInfo(locale_semaphore);
   if (locale_cache != (SplayTreeInfo *) NULL)
     locale_cache=DestroySplayTree(locale_cache);
-#if defined(MAGICKCORE_HAVE_STRTOD_L)
+#if defined(MAGICKCORE_LOCALE_SUPPORT)
   DestroyCLocale();
 #endif
   UnlockSemaphoreInfo(locale_semaphore);