]> granicus.if.org Git - imagemagick/blobdiff - magick/locale.c
(no commit message)
[imagemagick] / magick / locale.c
index cf800d643655d48dc0c337f90f3d64d2b4c5ad54..b131ec44dd45595c931e59aa50bafa1237edc5fa 100644 (file)
 #define LocaleFilename  "locale.xml"
 #define MaxRecursionDepth  200
 \f
+/*
+  Typedef declarations.
+*/
+#if defined(__CYGWIN__)
+typedef struct _locale_t *locale_t;
+#endif
+\f
 /*
   Static declarations.
 */
@@ -83,11 +90,13 @@ static SemaphoreInfo
 static SplayTreeInfo
   *locale_list = (SplayTreeInfo *) NULL;
 
-static volatile MagickBooleanType
-  instantiate_locale = MagickFalse;
-
+#if defined(MAGICKCORE_HAVE_STRTOD_L)
 static volatile locale_t
   c_locale = (locale_t) NULL;
+#endif
+
+static volatile MagickBooleanType
+  instantiate_locale = MagickFalse;
 \f
 /*
   Forward declarations.
@@ -96,6 +105,7 @@ static MagickBooleanType
   InitializeLocaleList(ExceptionInfo *),
   LoadLocaleLists(const char *,const char *,ExceptionInfo *);
 \f
+#if defined(MAGICKCORE_HAVE_STRTOD_L)
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -126,7 +136,9 @@ static locale_t AcquireCLocale(void)
 #endif
   return(c_locale);
 }
+#endif
 \f
+#if defined(MAGICKCORE_HAVE_STRTOD_L)
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -157,6 +169,7 @@ static void DestroyCLocale(void)
 #endif
   c_locale=(locale_t) NULL;
 }
+#endif
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -221,22 +234,26 @@ MagickExport LinkedListInfo *DestroyLocaleOptions(LinkedListInfo *messages)
 %
 */
 
-MagickExport ssize_t FormatLocaleFileList(FILE *file,const char *format,
-  va_list operands)
+MagickExport ssize_t FormatLocaleFileList(FILE *file,
+  const char *restrict format,va_list operands)
 {
-  int
+  ssize_t
     n;
 
-#if defined(MAGICKCORE_HAVE_FPRINTF_L)
+#if defined(MAGICKCORE_HAVE_VFPRINTF_L)
   {
     locale_t
       locale;
 
     locale=AcquireCLocale();
     if (locale == (locale_t) NULL)
-      n=fprintf(file,format,operands);
+      n=(ssize_t) vfprintf(file,format,operands);
     else
-      n=fprintf_l(file,format,locale,operands);
+#if defined(MAGICKCORE_WINDOWS_SUPPORT)
+      n=(ssize_t) vfprintf_l(file,format,locale,operands);
+#else
+      n=(ssize_t) vfprintf_l(file,locale,format,operands);
+#endif
   }
 #else
 #if defined(MAGICKCORE_HAVE_USELOCALE)
@@ -247,22 +264,23 @@ MagickExport ssize_t FormatLocaleFileList(FILE *file,const char *format,
 
     locale=AcquireCLocale();
     if (locale == (locale_t) NULL)
-      n=fprintf(file,format,operands);
+      n=(ssize_t) vfprintf(file,format,operands);
     else
       {
         previous_locale=uselocale(locale);
-        n=fprintf(file,format,operands);
+        n=(ssize_t) vfprintf(file,format,operands);
         uselocale(previous_locale);
       }
   }
 #else
-  n=fprintf(file,format,operands);
+  n=(ssize_t) vfprintf(file,format,operands);
 #endif
 #endif
-  return((ssize_t) n);
+  return(n);
 }
 
-MagickExport ssize_t FormatLocaleFile(FILE *file,const char *format,...)
+MagickExport ssize_t FormatLocaleFile(FILE *file,const char *restrict format,
+  ...)
 {
   ssize_t
     n;
@@ -271,7 +289,7 @@ MagickExport ssize_t FormatLocaleFile(FILE *file,const char *format,...)
     operands;
 
   va_start(operands,format);
-  n=(ssize_t) FormatLocaleFileList(file,format,operands);
+  n=FormatLocaleFileList(file,format,operands);
   va_end(operands);
   return(n);
 }
@@ -307,14 +325,27 @@ MagickExport ssize_t FormatLocaleFile(FILE *file,const char *format,...)
 %
 */
 
-MagickExport ssize_t FormatLocaleStringList(char *string,const size_t length,
-  const char *format,va_list operands)
+MagickExport ssize_t FormatLocaleStringList(char *restrict string,
+  const size_t length,const char *restrict format,va_list operands)
 {
-  int
+  ssize_t
     n;
 
 #if defined(MAGICKCORE_HAVE_VSNPRINTF_L)
-  n=vsnprintf_l(string,length,format,(locale_t) NULL,operands);
+  {
+    locale_t
+      locale;
+
+    locale=AcquireCLocale();
+    if (locale == (locale_t) NULL)
+      n=(ssize_t) vsnprintf(string,length,format,operands);
+    else
+#if defined(MAGICKCORE_WINDOWS_SUPPORT)
+      n=(ssize_t) vsnprintf_l(string,length,format,locale,operands);
+#else
+      n=(ssize_t) vsnprintf_l(string,length,locale,format,operands);
+#endif
+  }
 #elif defined(MAGICKCORE_HAVE_VSNPRINTF)
 #if defined(MAGICKCORE_HAVE_USELOCALE)
   {
@@ -324,27 +355,27 @@ MagickExport ssize_t FormatLocaleStringList(char *string,const size_t length,
 
     locale=AcquireCLocale();
     if (locale == (locale_t) NULL)
-      n=vsnprintf(string,length,format,operands);
+      n=(ssize_t) vsnprintf(string,length,format,operands);
     else
       {
         previous_locale=uselocale(locale);
-        n=vsnprintf(string,length,format,operands);
+        n=(ssize_t) vsnprintf(string,length,format,operands);
         uselocale(previous_locale);
       }
   }
 #else
-  n=vsnprintf(string,length,format,operands);
+  n=(ssize_t) vsnprintf(string,length,format,operands);
 #endif
 #else
-  n=vsprintf(string,format,operands);
+  n=(ssize_t) vsprintf(string,format,operands);
 #endif
   if (n < 0)
     string[length-1]='\0';
-  return((ssize_t) n);
+  return(n);
 }
 
-MagickExport ssize_t FormatLocaleString(char *string,const size_t length,
-  const char *format,...)
+MagickExport ssize_t FormatLocaleString(char *restrict string,
+  const size_t length,const char *restrict format,...)
 {
   ssize_t
     n;
@@ -353,7 +384,7 @@ MagickExport ssize_t FormatLocaleString(char *string,const size_t length,
     operands;
 
   va_start(operands,format);
-  n=(ssize_t) FormatLocaleStringList(string,length,format,operands);
+  n=FormatLocaleStringList(string,length,format,operands);
   va_end(operands);
   return(n);
 }
@@ -818,6 +849,58 @@ static MagickBooleanType InitializeLocaleList(ExceptionInfo *exception)
 %                                                                             %
 %                                                                             %
 %                                                                             %
++   I n t e r p r e t L o c a l e V a l u e                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  InterpretLocaleValue() interprets the string as a floating point number in
+%  the "C" locale and returns its value as a double. If sentinal is not a null
+%  pointer, the method also sets the value pointed by sentinal to point to the
+%  first character after the number.
+%
+%  The format of the InterpretLocaleValue method is:
+%
+%      double InterpretLocaleValue(const char *value,char **sentinal)
+%
+%  A description of each parameter follows:
+%
+%    o value: the string value.
+%
+%    o sentinal:  if sentinal is not NULL, a pointer to the character after the
+%      last character used in the conversion is stored in the location
+%      referenced by sentinal.
+%
+*/
+MagickExport double InterpretLocaleValue(const char *restrict string,
+  char **restrict sentinal)
+{
+  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);
+  }
+#else
+  value=strtod(string,sentinal);
+#endif
+  return(value);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %  L i s t L o c a l e I n f o                                                %
 %                                                                             %
 %                                                                             %
@@ -1321,59 +1404,10 @@ MagickExport void LocaleComponentTerminus(void)
   if (locale_semaphore == (SemaphoreInfo *) NULL)
     AcquireSemaphoreInfo(&locale_semaphore);
   LockSemaphoreInfo(locale_semaphore);
+#if defined(MAGICKCORE_HAVE_STRTOD_L)
   DestroyCLocale();
+#endif
   instantiate_locale=MagickFalse;
   UnlockSemaphoreInfo(locale_semaphore);
   DestroySemaphoreInfo(&locale_semaphore);
 }
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-+   L o c a l e T o D o u b l e                                               %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  LocaleToDouble() interprets the string as a floating point number in the
-%  "C" locale and returns its value as a double. If sentinal is not a null
-%  pointer, the method also sets the value pointed by sentinal to point to the
-%  first character after the number.
-%
-%  The format of the LocaleToDouble method is:
-%
-%      double LocaleToDouble(const char *value,char **sentinal)
-%
-%  A description of each parameter follows:
-%
-%    o value: the string value.
-%
-%    o sentinal:  if sentinal is not NULL, a pointer to the character after the
-%      last character used in the conversion is stored in the location
-%      referenced by sentinal.
-%
-*/
-MagickExport double LocaleToDouble(const char *string,char **sentinal)
-{
-  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);
-  }
-#else
-  value=strtod(string,sentinal);
-#endif
-  return(value);
-}