]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/string.c
(no commit message)
[imagemagick] / MagickCore / string.c
index 948ed1db540d1e73851160de4e653586009287bf..31023be8916bf1825211e22e69b2d5f3b7d9425b 100644 (file)
 %                        MagickCore String Methods                            %
 %                                                                             %
 %                             Software Design                                 %
-%                               John Cristy                                   %
+%                                  Cristy                                     %
 %                               August 2003                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 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  %
@@ -61,7 +61,7 @@
 */
 #if !defined(MAGICKCORE_HAVE_STRCASECMP) || !defined(MAGICKCORE_HAVE_STRNCASECMP)
 static const unsigned char
-  asciimap[] =
+  AsciiMap[] =
   {
     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
     0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -267,7 +267,6 @@ MagickExport char *CloneString(char **destination,const char *source)
   size_t
     length;
 
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(destination != (char **) NULL);
   if (source == (const char *) NULL)
     {
@@ -320,7 +319,6 @@ MagickExport StringInfo *CloneStringInfo(const StringInfo *string_info)
   StringInfo
     *clone_info;
 
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(string_info != (StringInfo *) NULL);
   assert(string_info->signature == MagickSignature);
   clone_info=AcquireStringInfo(string_info->length);
@@ -369,7 +367,6 @@ MagickExport int CompareStringInfo(const StringInfo *target,
   int
     status;
 
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(target != (StringInfo *) NULL);
   assert(target->signature == MagickSignature);
   assert(source != (StringInfo *) NULL);
@@ -544,7 +541,6 @@ MagickExport void ConcatenateStringInfo(StringInfo *string_info,
   size_t
     length;
 
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(string_info != (StringInfo *) NULL);
   assert(string_info->signature == MagickSignature);
   assert(source != (const StringInfo *) NULL);
@@ -840,7 +836,6 @@ MagickExport char *DestroyString(char *string)
 */
 MagickExport StringInfo *DestroyStringInfo(StringInfo *string_info)
 {
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(string_info != (StringInfo *) NULL);
   assert(string_info->signature == MagickSignature);
   if (string_info->datum != (unsigned char *) NULL)
@@ -928,7 +923,6 @@ MagickExport char *EscapeString(const char *source,const char escape)
   size_t
     length;
 
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(source != (const char *) NULL);
   length=strlen(source);
   for (p=source; *p != '\0'; p++)
@@ -1114,6 +1108,7 @@ MagickExport ssize_t FormatMagickSize(const MagickSizeType size,
 #endif
   for (i=0; (length >= bytes) && (units[i+1] != (const char *) NULL); i++)
     length/=bytes;
+  count=0;
   for (j=2; j < 12; j++)
   {
     count=FormatLocaleString(format,MaxTextExtent,"%.*g%sB",(int) (i+j),length,
@@ -1734,7 +1729,6 @@ MagickExport void PrintStringInfo(FILE *file,const char *id,
     j;
 
   assert(id != (const char *) NULL);
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
   assert(string_info != (StringInfo *) NULL);
   assert(string_info->signature == MagickSignature);
   p=(char *) string_info->datum;
@@ -1745,9 +1739,11 @@ MagickExport void PrintStringInfo(FILE *file,const char *id,
       break;
     p++;
   }
+  (void) FormatLocaleFile(file,"%s(%.20g): ",id,(double) string_info->length);
   if (i == string_info->length)
     {
-      (void) fputs((char *) string_info->datum,file);
+      for (i=0; i < string_info->length; i++)
+        (void) fputc(string_info->datum[i],file);
       (void) fputc('\n',file);
       return;
     }
@@ -1808,7 +1804,6 @@ MagickExport void PrintStringInfo(FILE *file,const char *id,
 */
 MagickExport void ResetStringInfo(StringInfo *string_info)
 {
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(string_info != (StringInfo *) NULL);
   assert(string_info->signature == MagickSignature);
   (void) ResetMagickMemory(string_info->datum,0,string_info->length);
@@ -1841,7 +1836,6 @@ MagickExport void ResetStringInfo(StringInfo *string_info)
 MagickExport void SetStringInfo(StringInfo *string_info,
   const StringInfo *source)
 {
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(string_info != (StringInfo *) NULL);
   assert(string_info->signature == MagickSignature);
   assert(source != (StringInfo *) NULL);
@@ -1882,7 +1876,6 @@ MagickExport void SetStringInfo(StringInfo *string_info,
 MagickExport void SetStringInfoDatum(StringInfo *string_info,
   const unsigned char *source)
 {
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(string_info != (StringInfo *) NULL);
   assert(string_info->signature == MagickSignature);
   if (string_info->length != 0)
@@ -1916,7 +1909,6 @@ MagickExport void SetStringInfoDatum(StringInfo *string_info,
 MagickExport void SetStringInfoLength(StringInfo *string_info,
   const size_t length)
 {
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(string_info != (StringInfo *) NULL);
   assert(string_info->signature == MagickSignature);
   if (~length < MaxTextExtent)
@@ -1958,7 +1950,6 @@ MagickExport void SetStringInfoLength(StringInfo *string_info,
 */
 MagickExport void SetStringInfoPath(StringInfo *string_info,const char *path)
 {
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(string_info != (StringInfo *) NULL);
   assert(string_info->signature == MagickSignature);
   assert(path != (const char *) NULL);
@@ -1993,7 +1984,6 @@ MagickExport StringInfo *SplitStringInfo(StringInfo *string_info,
   StringInfo
     *split_info;
 
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(string_info != (StringInfo *) NULL);
   assert(string_info->signature == MagickSignature);
   if (offset > string_info->length)
@@ -2248,7 +2238,7 @@ MagickExport char **StringToArgv(const char *text,int *argc)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  StringToArrayOfDoubles() converts a string of space or comma seperated
+%  StringToArrayOfDoubles() converts a string of space or comma separated
 %  numbers into array of floating point numbers (doubles). Any number that
 %  failes to parse properly will produce a syntax error. As will two commas
 %  without a  number between them.  However a final comma at the end will
@@ -2260,66 +2250,77 @@ MagickExport char **StringToArgv(const char *text,int *argc)
 %
 %  The format of the StringToArrayOfDoubles method is:
 %
-%     double *StringToArrayOfDoubles(const char *string,
-%          size_t *count, ExceptionInfo *exception)
+%     double *StringToArrayOfDoubles(const char *string,size_t *count)
 %
 %  A description of each parameter follows:
 %
-%    o string: the string containing the comma/space seperated values.
+%    o string: the string containing the comma/space separated values.
 %
 %    o count: returns number of arguments in returned array
 %
-%    o exception: return 'memory failure' exceptions
+%    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport double *StringToArrayOfDoubles(const char *string,
-     ssize_t *count, ExceptionInfo *exception)
+MagickExport double *StringToArrayOfDoubles(const char *string,ssize_t *count,
+  ExceptionInfo *exception)
 {
-  const char
-    *p;
-
   char
     *q;
 
+  const char
+    *p;
+
   double
     *array;
 
   register ssize_t
     i;
 
-  /* Determine count of values, and check syntax */
+  /*
+    Determine count of values, and check syntax.
+  */
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickSignature);
   *count=0;
-  p=string;
   i=0;
-  while( *p != '\0' )
+  p=string;
+  while (*p != '\0')
   {
-    (void) StringToDouble(p, &q);       /* get value - ignores leading space */
-    if (p == q) return((double *)NULL); /* no value found */
-    p=q; i++;                           /* inc value count */
-    while ( isspace((int)*p) ) p++;     /* skip spaces */
-    if ( *p == ',' )           p++;     /* skip comma */
-    while ( isspace((int)*p) ) p++;     /* and more spaces */
+    (void) StringToDouble(p,&q);  /* get value - ignores leading space */
+    if (p == q)
+      return((double *) NULL);  /* no value found */
+    p=q;
+    i++;  /* increment value count */
+    while (isspace((int) ((unsigned char) *p)) != 0)
+      p++;  /* skip spaces */
+    if (*p == ',')
+      p++;  /* skip comma */
+    while (isspace((int) ((unsigned char) *p)) != 0)
+      p++;  /* and more spaces */
   }
-
-  /* Allocate floating point argument list */
+  /*
+    Allocate floating point argument list.
+  */
   *count=i;
-  array=(double *) AcquireQuantumMemory(i,sizeof(*array));
-  if (array == (double *) NULL) {
-    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
-    (void) ThrowMagickException(exception,GetMagickModule(),
-         ResourceLimitFatalError,"MemoryAllocationFailed"," ");
-    return((double *)NULL);
-  }
-
-  /* Fill in the floating point values */
-  p=string;
+  array=(double *) AcquireQuantumMemory((size_t) i,sizeof(*array));
+  if (array == (double *) NULL)
+    {
+      (void) ThrowMagickException(exception,GetMagickModule(),
+        ResourceLimitError,"MemoryAllocationFailed","`%s'","");
+      return((double *) NULL);
+    }
+  /*
+    Fill in the floating point values.
+  */
   i=0;
-  while( *p != '\0' && i < *count ) {
+  p=string;
+  while ((*p != '\0') && (i < *count))
+  {
     array[i++]=StringToDouble(p,&q);
     p=q;
-    while ( isspace((int)*p) || *p == ',' ) p++;
+    while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
+      p++;
   }
-
   return(array);
 }
 \f
@@ -2560,7 +2561,6 @@ MagickExport StringInfo *StringToStringInfo(const char *string)
   StringInfo
     *string_info;
 
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(string != (const char *) NULL);
   string_info=AcquireStringInfo(strlen(string));
   SetStringInfoDatum(string_info,(const unsigned char *) string);