MagickCore  7.0.7
Convert, Edit, Or Compose Bitmap Images
string.c
Go to the documentation of this file.
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % %
6 % SSSSS TTTTT RRRR IIIII N N GGGG %
7 % SS T R R I NN N G %
8 % SSS T RRRR I N N N G GGG %
9 % SS T R R I N NN G G %
10 % SSSSS T R R IIIII N N GGGG %
11 % %
12 % %
13 % MagickCore String Methods %
14 % %
15 % Software Design %
16 % Cristy %
17 % August 2003 %
18 % %
19 % %
20 % Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
22 % %
23 % You may not use this file except in compliance with the license. You may %
24 % obtain a copy of the license at %
25 % %
26 % https://www.imagemagick.org/script/license.php %
27 % %
28 % unless required by applicable law or agreed to in writing, software %
29 % distributed under the license is distributed on an "as is" basis, %
30 % without warranties or conditions of any kind, either express or implied. %
31 % See the license for the specific language governing permissions and %
32 % limitations under the license. %
33 % %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 */
38 
39 /*
40  include declarations.
41 */
42 #include "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
45 #include "MagickCore/exception.h"
48 #include "MagickCore/list.h"
49 #include "MagickCore/locale_.h"
50 #include "MagickCore/log.h"
51 #include "MagickCore/memory_.h"
54 #include "MagickCore/property.h"
55 #include "MagickCore/resource_.h"
57 #include "MagickCore/string_.h"
60 
61 /*
62  static declarations.
63 */
64 #ifdef __VMS
65 #define asciimap AsciiMap
66 #endif
67 #if !defined(MAGICKCORE_HAVE_STRCASECMP) || !defined(MAGICKCORE_HAVE_STRNCASECMP)
68 static const unsigned char
70  {
71  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
72  0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
73  0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
74  0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
75  0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
76  0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
77  0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
78  0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
79  0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
80  0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
81  0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
82  0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
83  0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
84  0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
85  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
86  0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
87  0xc0, 0xe1, 0xe2, 0xe3, 0xe4, 0xc5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,
88  0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
89  0xf8, 0xf9, 0xfa, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
90  0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
91  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
92  0xfc, 0xfd, 0xfe, 0xff,
93  };
94 #endif
95 
96 /*
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 % %
99 % %
100 % %
101 % A c q u i r e S t r i n g %
102 % %
103 % %
104 % %
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 %
107 % AcquireString() returns an new extented string, containing a clone of the
108 % given string.
109 %
110 % An extended string is the string length, plus an extra MagickPathExtent space
111 % to allow for the string to be actively worked on.
112 %
113 % The returned string shoud be freed using DestoryString().
114 %
115 % The format of the AcquireString method is:
116 %
117 % char *AcquireString(const char *source)
118 %
119 % A description of each parameter follows:
120 %
121 % o source: A character string.
122 %
123 */
124 MagickExport char *AcquireString(const char *source)
125 {
126  char
127  *destination;
128 
129  size_t
130  length;
131 
132  length=0;
133  if (source != (char *) NULL)
134  length+=strlen(source);
135  if (~length < MagickPathExtent)
136  ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
137  destination=(char *) AcquireQuantumMemory(length+MagickPathExtent,
138  sizeof(*destination));
139  if (destination == (char *) NULL)
140  ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
141  *destination='\0';
142  if (source != (char *) NULL)
143  (void) memcpy(destination,source,length*sizeof(*destination));
144  destination[length]='\0';
145  return(destination);
146 }
147 
148 /*
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 % %
151 % %
152 % %
153 % A c q u i r e S t r i n g I n f o %
154 % %
155 % %
156 % %
157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 %
159 % AcquireStringInfo() allocates the StringInfo structure.
160 %
161 % The format of the AcquireStringInfo method is:
162 %
163 % StringInfo *AcquireStringInfo(const size_t length)
164 %
165 % A description of each parameter follows:
166 %
167 % o length: the string length.
168 %
169 */
171 {
172  StringInfo
173  *string_info;
174 
175  string_info=(StringInfo *) AcquireCriticalMemory(sizeof(*string_info));
176  (void) ResetMagickMemory(string_info,0,sizeof(*string_info));
177  string_info->signature=MagickCoreSignature;
178  string_info->length=length;
179  string_info->datum=(unsigned char *) NULL;
180  if (~string_info->length >= (MagickPathExtent-1))
181  string_info->datum=(unsigned char *) AcquireQuantumMemory(
182  string_info->length+MagickPathExtent,sizeof(*string_info->datum));
183  if (string_info->datum == (unsigned char *) NULL)
184  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
185  return(string_info);
186 }
187 
188 /*
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 % %
191 % %
192 % %
193 % B l o b T o S t r i n g I n f o %
194 % %
195 % %
196 % %
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 %
199 % BlobToStringInfo() returns the contents of a blob as a StringInfo structure
200 % with MagickPathExtent extra space.
201 %
202 % The format of the BlobToStringInfo method is:
203 %
204 % StringInfo *BlobToStringInfo(const void *blob,const size_t length)
205 %
206 % A description of each parameter follows:
207 %
208 % o blob: the blob.
209 %
210 % o length: the length of the blob.
211 %
212 */
213 MagickExport StringInfo *BlobToStringInfo(const void *blob,const size_t length)
214 {
215  StringInfo
216  *string_info;
217 
218  string_info=AcquireStringInfo(0);
219  if (~length < MagickPathExtent)
220  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
221  string_info->length=length;
222  if (string_info->datum == (unsigned char *) NULL)
223  string_info->datum=(unsigned char *) AcquireQuantumMemory(length+
224  MagickPathExtent,sizeof(*string_info->datum));
225  else
226  string_info->datum=(unsigned char *) ResizeQuantumMemory(string_info->datum,
227  length+MagickPathExtent,sizeof(*string_info->datum));
228  if (string_info->datum == (unsigned char *) NULL)
229  {
230  string_info=DestroyStringInfo(string_info);
231  return((StringInfo *) NULL);
232  }
233  if (blob != (const void *) NULL)
234  (void) memcpy(string_info->datum,blob,length);
235  return(string_info);
236 }
237 
238 /*
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % %
241 % %
242 % %
243 % C l o n e S t r i n g %
244 % %
245 % %
246 % %
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 %
249 % CloneString() replaces or frees the destination string to make it
250 % a clone of the input string plus MagickPathExtent more space so the string
251 % may be worked on.
252 %
253 % If source is a NULL pointer the destination string will be freed and set to
254 % a NULL pointer. A pointer to the stored in the destination is also returned.
255 %
256 % When finished the non-NULL string should be freed using DestoryString()
257 % or using CloneString() with a NULL pointed for the source.
258 %
259 % The format of the CloneString method is:
260 %
261 % char *CloneString(char **destination,const char *source)
262 %
263 % A description of each parameter follows:
264 %
265 % o destination: A pointer to a character string.
266 %
267 % o source: A character string.
268 %
269 */
270 MagickExport char *CloneString(char **destination,const char *source)
271 {
272  size_t
273  length;
274 
275  assert(destination != (char **) NULL);
276  if (source == (const char *) NULL)
277  {
278  if (*destination != (char *) NULL)
279  *destination=DestroyString(*destination);
280  return(*destination);
281  }
282  if (*destination == (char *) NULL)
283  {
284  *destination=AcquireString(source);
285  return(*destination);
286  }
287  length=strlen(source);
288  if (~length < MagickPathExtent)
289  ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
290  *destination=(char *) ResizeQuantumMemory(*destination,length+
291  MagickPathExtent,sizeof(**destination));
292  if (*destination == (char *) NULL)
293  ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
294  if (length != 0)
295  (void) memcpy(*destination,source,length*sizeof(**destination));
296  (*destination)[length]='\0';
297  return(*destination);
298 }
299 
300 /*
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 % %
303 % %
304 % %
305 % C l o n e S t r i n g I n f o %
306 % %
307 % %
308 % %
309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 %
311 % CloneStringInfo() clones a copy of the StringInfo structure.
312 %
313 % The format of the CloneStringInfo method is:
314 %
315 % StringInfo *CloneStringInfo(const StringInfo *string_info)
316 %
317 % A description of each parameter follows:
318 %
319 % o string_info: the string info.
320 %
321 */
323 {
324  StringInfo
325  *clone_info;
326 
327  assert(string_info != (StringInfo *) NULL);
328  assert(string_info->signature == MagickCoreSignature);
329  clone_info=AcquireStringInfo(string_info->length);
330  if (string_info->length != 0)
331  (void) memcpy(clone_info->datum,string_info->datum,string_info->length+1);
332  return(clone_info);
333 }
334 
335 /*
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % %
338 % %
339 % %
340 % C o m p a r e S t r i n g I n f o %
341 % %
342 % %
343 % %
344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 %
346 % CompareStringInfo() compares the two datums target and source. It returns
347 % an integer less than, equal to, or greater than zero if target is found,
348 % respectively, to be less than, to match, or be greater than source.
349 %
350 % The format of the CompareStringInfo method is:
351 %
352 % int CompareStringInfo(const StringInfo *target,const StringInfo *source)
353 %
354 % A description of each parameter follows:
355 %
356 % o target: the target string.
357 %
358 % o source: the source string.
359 %
360 */
361 
363  const StringInfo *source)
364 {
365  int
366  status;
367 
368  assert(target != (StringInfo *) NULL);
369  assert(target->signature == MagickCoreSignature);
370  assert(source != (StringInfo *) NULL);
371  assert(source->signature == MagickCoreSignature);
372  status=memcmp(target->datum,source->datum,MagickMin(target->length,
373  source->length));
374  if (status != 0)
375  return(status);
376  if (target->length == source->length)
377  return(0);
378  return(target->length < source->length ? -1 : 1);
379 }
380 
381 /*
382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
383 % %
384 % %
385 % %
386 % C o n c a t e n a t e M a g i c k S t r i n g %
387 % %
388 % %
389 % %
390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
391 %
392 % ConcatenateMagickString() concatenates the source string to the destination
393 % string. The destination buffer is always null-terminated even if the
394 % string must be truncated.
395 %
396 % The format of the ConcatenateMagickString method is:
397 %
398 % size_t ConcatenateMagickString(char *destination,const char *source,
399 % const size_t length)
400 %
401 % A description of each parameter follows:
402 %
403 % o destination: the destination string.
404 %
405 % o source: the source string.
406 %
407 % o length: the length of the destination string.
408 %
409 */
410 MagickExport size_t ConcatenateMagickString(char *destination,
411  const char *source,const size_t length)
412 {
413  register char
414  *q;
415 
416  register const char
417  *p;
418 
419  register size_t
420  i;
421 
422  size_t
423  count;
424 
425  assert(destination != (char *) NULL);
426  assert(source != (const char *) NULL);
427  assert(length >= 1);
428  p=source;
429  q=destination;
430  i=length;
431  while ((i-- != 0) && (*q != '\0'))
432  q++;
433  count=(size_t) (q-destination);
434  i=length-count;
435  if (i == 0)
436  return(count+strlen(p));
437  while (*p != '\0')
438  {
439  if (i != 1)
440  {
441  *q++=(*p);
442  i--;
443  }
444  p++;
445  }
446  *q='\0';
447  return(count+(p-source));
448 }
449 
450 /*
451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
452 % %
453 % %
454 % %
455 % C o n c a t e n a t e S t r i n g %
456 % %
457 % %
458 % %
459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
460 %
461 % ConcatenateString() appends a copy of string source, including the
462 % terminating null character, to the end of string destination.
463 %
464 % The format of the ConcatenateString method is:
465 %
466 % MagickBooleanType ConcatenateString(char **destination,
467 % const char *source)
468 %
469 % A description of each parameter follows:
470 %
471 % o destination: A pointer to a character string.
472 %
473 % o source: A character string.
474 %
475 */
477  const char *source)
478 {
479  size_t
480  destination_length,
481  length,
482  source_length;
483 
484  assert(destination != (char **) NULL);
485  if (source == (const char *) NULL)
486  return(MagickTrue);
487  if (*destination == (char *) NULL)
488  {
489  *destination=AcquireString(source);
490  return(MagickTrue);
491  }
492  destination_length=strlen(*destination);
493  source_length=strlen(source);
494  length=destination_length;
495  if (~length < source_length)
496  ThrowFatalException(ResourceLimitFatalError,"UnableToConcatenateString");
497  length+=source_length;
498  if (~length < MagickPathExtent)
499  ThrowFatalException(ResourceLimitFatalError,"UnableToConcatenateString");
500  *destination=(char *) ResizeQuantumMemory(*destination,length+
501  MagickPathExtent,sizeof(**destination));
502  if (*destination == (char *) NULL)
503  ThrowFatalException(ResourceLimitFatalError,"UnableToConcatenateString");
504  if (source_length != 0)
505  (void) memcpy((*destination)+destination_length,source,source_length);
506  (*destination)[length]='\0';
507  return(MagickTrue);
508 }
509 
510 /*
511 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512 % %
513 % %
514 % %
515 % C o n c a t e n a t e S t r i n g I n f o %
516 % %
517 % %
518 % %
519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
520 %
521 % ConcatenateStringInfo() concatenates the source string to the destination
522 % string.
523 %
524 % The format of the ConcatenateStringInfo method is:
525 %
526 % void ConcatenateStringInfo(StringInfo *string_info,
527 % const StringInfo *source)
528 %
529 % A description of each parameter follows:
530 %
531 % o string_info: the string info.
532 %
533 % o source: the source string.
534 %
535 */
537  const StringInfo *source)
538 {
539  size_t
540  length;
541 
542  assert(string_info != (StringInfo *) NULL);
543  assert(string_info->signature == MagickCoreSignature);
544  assert(source != (const StringInfo *) NULL);
545  length=string_info->length;
546  if (~length < source->length)
547  ThrowFatalException(ResourceLimitFatalError,"UnableToConcatenateString");
548  SetStringInfoLength(string_info,length+source->length);
549  (void) memcpy(string_info->datum+length,source->datum,source->length);
550 }
551 
552 /*
553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
554 % %
555 % %
556 % %
557 % C o n f i g u r e F i l e T o S t r i n g I n f o %
558 % %
559 % %
560 % %
561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
562 %
563 % ConfigureFileToStringInfo() returns the contents of a configure file as a
564 % string.
565 %
566 % The format of the ConfigureFileToStringInfo method is:
567 %
568 % StringInfo *ConfigureFileToStringInfo(const char *filename)
569 % ExceptionInfo *exception)
570 %
571 % A description of each parameter follows:
572 %
573 % o filename: the filename.
574 %
575 */
577 {
578  char
579  *string;
580 
581  int
582  file;
583 
585  offset;
586 
587  size_t
588  length;
589 
590  StringInfo
591  *string_info;
592 
593  void
594  *map;
595 
596  assert(filename != (const char *) NULL);
597  file=open_utf8(filename,O_RDONLY | O_BINARY,0);
598  if (file == -1)
599  return((StringInfo *) NULL);
600  offset=(MagickOffsetType) lseek(file,0,SEEK_END);
601  if ((offset < 0) || (offset != (MagickOffsetType) ((ssize_t) offset)))
602  {
603  file=close(file)-1;
604  return((StringInfo *) NULL);
605  }
606  length=(size_t) offset;
607  string=(char *) NULL;
608  if (~length >= (MagickPathExtent-1))
609  string=(char *) AcquireQuantumMemory(length+MagickPathExtent,
610  sizeof(*string));
611  if (string == (char *) NULL)
612  {
613  file=close(file)-1;
614  return((StringInfo *) NULL);
615  }
616  map=MapBlob(file,ReadMode,0,length);
617  if (map != (void *) NULL)
618  {
619  (void) memcpy(string,map,length);
620  (void) UnmapBlob(map,length);
621  }
622  else
623  {
624  register size_t
625  i;
626 
627  ssize_t
628  count;
629 
630  (void) lseek(file,0,SEEK_SET);
631  for (i=0; i < length; i+=count)
632  {
633  count=read(file,string+i,(size_t) MagickMin(length-i,(size_t)
634  SSIZE_MAX));
635  if (count <= 0)
636  {
637  count=0;
638  if (errno != EINTR)
639  break;
640  }
641  }
642  if (i < length)
643  {
644  file=close(file)-1;
645  string=DestroyString(string);
646  return((StringInfo *) NULL);
647  }
648  }
649  string[length]='\0';
650  file=close(file)-1;
651  string_info=AcquireStringInfo(0);
652  string_info->path=ConstantString(filename);
653  string_info->length=length;
654  if (string_info->datum != (unsigned char *) NULL)
655  string_info->datum=(unsigned char *) RelinquishMagickMemory(
656  string_info->datum);
657  string_info->datum=(unsigned char *) string;
658  return(string_info);
659 }
660 
661 /*
662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
663 % %
664 % %
665 % %
666 % C o n s t a n t S t r i n g %
667 % %
668 % %
669 % %
670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
671 %
672 % ConstantString() allocates exactly the needed memory for a string and
673 % copies the source string to that memory location. A NULL string pointer
674 % will allocate an empty string containing just the NUL character.
675 %
676 % When finished the string should be freed using DestoryString()
677 %
678 % The format of the ConstantString method is:
679 %
680 % char *ConstantString(const char *source)
681 %
682 % A description of each parameter follows:
683 %
684 % o source: A character string.
685 %
686 */
687 MagickExport char *ConstantString(const char *source)
688 {
689  char
690  *destination;
691 
692  size_t
693  length;
694 
695  length=0;
696  if (source != (char *) NULL)
697  length+=strlen(source);
698  destination=(char *) NULL;
699  if (~length >= 1UL)
700  destination=(char *) AcquireQuantumMemory(length+1UL,sizeof(*destination));
701  if (destination == (char *) NULL)
702  ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
703  *destination='\0';
704  if (source != (char *) NULL)
705  (void) memcpy(destination,source,length*sizeof(*destination));
706  destination[length]='\0';
707  return(destination);
708 }
709 
710 /*
711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
712 % %
713 % %
714 % %
715 % C o p y M a g i c k S t r i n g %
716 % %
717 % %
718 % %
719 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
720 %
721 % CopyMagickString() copies the source string to the destination string, with
722 % out exceeding the given pre-declared length.
723 %
724 % The destination buffer is always null-terminated even if the string must be
725 % truncated. The return value is the minimum of the source string length or
726 % the length parameter.
727 %
728 % The format of the CopyMagickString method is:
729 %
730 % size_t CopyMagickString(const char *destination,char *source,
731 % const size_t length)
732 %
733 % A description of each parameter follows:
734 %
735 % o destination: the destination string.
736 %
737 % o source: the source string.
738 %
739 % o length: the length of the destination string.
740 %
741 */
742 MagickExport size_t CopyMagickString(char *destination,const char *source,
743  const size_t length)
744 {
745  register char
746  *q;
747 
748  register const char
749  *p;
750 
751  register size_t
752  n;
753 
754  p=source;
755  q=destination;
756  for (n=length; n > 4; n-=4)
757  {
758  *q=(*p++);
759  if (*q == '\0')
760  return((size_t) (p-source-1));
761  q++;
762  *q=(*p++);
763  if (*q == '\0')
764  return((size_t) (p-source-1));
765  q++;
766  *q=(*p++);
767  if (*q == '\0')
768  return((size_t) (p-source-1));
769  q++;
770  *q=(*p++);
771  if (*q == '\0')
772  return((size_t) (p-source-1));
773  q++;
774  }
775  if (n != 0)
776  for (n--; n != 0; n--)
777  {
778  *q=(*p++);
779  if (*q == '\0')
780  return((size_t) (p-source-1));
781  q++;
782  }
783  if (length != 0)
784  *q='\0';
785  return((size_t) (p-source-1));
786 }
787 
788 /*
789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
790 % %
791 % %
792 % %
793 % D e s t r o y S t r i n g %
794 % %
795 % %
796 % %
797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
798 %
799 % DestroyString() destroys memory associated with a string.
800 %
801 % The format of the DestroyString method is:
802 %
803 % char *DestroyString(char *string)
804 %
805 % A description of each parameter follows:
806 %
807 % o string: the string.
808 %
809 */
810 MagickExport char *DestroyString(char *string)
811 {
812  return((char *) RelinquishMagickMemory(string));
813 }
814 
815 /*
816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
817 % %
818 % %
819 % %
820 % D e s t r o y S t r i n g I n f o %
821 % %
822 % %
823 % %
824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
825 %
826 % DestroyStringInfo() destroys memory associated with the StringInfo structure.
827 %
828 % The format of the DestroyStringInfo method is:
829 %
830 % StringInfo *DestroyStringInfo(StringInfo *string_info)
831 %
832 % A description of each parameter follows:
833 %
834 % o string_info: the string info.
835 %
836 */
838 {
839  assert(string_info != (StringInfo *) NULL);
840  assert(string_info->signature == MagickCoreSignature);
841  if (string_info->datum != (unsigned char *) NULL)
842  string_info->datum=(unsigned char *) RelinquishMagickMemory(
843  string_info->datum);
844  if (string_info->path != (char *) NULL)
845  string_info->path=DestroyString(string_info->path);
846  string_info->signature=(~MagickCoreSignature);
847  string_info=(StringInfo *) RelinquishMagickMemory(string_info);
848  return(string_info);
849 }
850 
851 /*
852 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
853 % %
854 % %
855 % %
856 % D e s t r o y S t r i n g L i s t %
857 % %
858 % %
859 % %
860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
861 %
862 % DestroyStringList() zeros memory associated with a string list.
863 %
864 % The format of the DestroyStringList method is:
865 %
866 % char **DestroyStringList(char **list)
867 %
868 % A description of each parameter follows:
869 %
870 % o list: the string list.
871 %
872 */
873 MagickExport char **DestroyStringList(char **list)
874 {
875  register ssize_t
876  i;
877 
878  assert(list != (char **) NULL);
879  for (i=0; list[i] != (char *) NULL; i++)
880  list[i]=DestroyString(list[i]);
881  list=(char **) RelinquishMagickMemory(list);
882  return(list);
883 }
884 
885 /*
886 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
887 % %
888 % %
889 % %
890 % E s c a p e S t r i n g %
891 % %
892 % %
893 % %
894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
895 %
896 % EscapeString() allocates memory for a backslash-escaped version of a
897 % source text string, copies the escaped version of the text to that
898 % memory location while adding backslash characters, and returns the
899 % escaped string.
900 %
901 % The format of the EscapeString method is:
902 %
903 % char *EscapeString(const char *source,const char escape)
904 %
905 % A description of each parameter follows:
906 %
907 % o allocate_string: Method EscapeString returns the escaped string.
908 %
909 % o source: A character string.
910 %
911 % o escape: the quoted string termination character to escape (e.g. '"').
912 %
913 */
914 MagickExport char *EscapeString(const char *source,const char escape)
915 {
916  char
917  *destination;
918 
919  register char
920  *q;
921 
922  register const char
923  *p;
924 
925  size_t
926  length;
927 
928  assert(source != (const char *) NULL);
929  length=0;
930  for (p=source; *p != '\0'; p++)
931  {
932  if ((*p == '\\') || (*p == escape))
933  {
934  if (~length < 1)
935  ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
936  length++;
937  }
938  length++;
939  }
940  destination=(char *) NULL;
941  if (~length >= (MagickPathExtent-1))
942  destination=(char *) AcquireQuantumMemory(length+MagickPathExtent,
943  sizeof(*destination));
944  if (destination == (char *) NULL)
945  ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
946  *destination='\0';
947  q=destination;
948  for (p=source; *p != '\0'; p++)
949  {
950  if ((*p == '\\') || (*p == escape))
951  *q++='\\';
952  *q++=(*p);
953  }
954  *q='\0';
955  return(destination);
956 }
957 
958 /*
959 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
960 % %
961 % %
962 % %
963 % F i l e T o S t r i n g %
964 % %
965 % %
966 % %
967 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
968 %
969 % FileToString() returns the contents of a file as a string.
970 %
971 % The format of the FileToString method is:
972 %
973 % char *FileToString(const char *filename,const size_t extent,
974 % ExceptionInfo *exception)
975 %
976 % A description of each parameter follows:
977 %
978 % o filename: the filename.
979 %
980 % o extent: Maximum length of the string.
981 %
982 % o exception: return any errors or warnings in this structure.
983 %
984 */
985 MagickExport char *FileToString(const char *filename,const size_t extent,
987 {
988  size_t
989  length;
990 
991  assert(filename != (const char *) NULL);
992  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
993  assert(exception != (ExceptionInfo *) NULL);
994  return((char *) FileToBlob(filename,extent,&length,exception));
995 }
996 
997 /*
998 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
999 % %
1000 % %
1001 % %
1002 % F i l e T o S t r i n g I n f o %
1003 % %
1004 % %
1005 % %
1006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1007 %
1008 % FileToStringInfo() returns the contents of a file as a string.
1009 %
1010 % The format of the FileToStringInfo method is:
1011 %
1012 % StringInfo *FileToStringInfo(const char *filename,const size_t extent,
1013 % ExceptionInfo *exception)
1014 %
1015 % A description of each parameter follows:
1016 %
1017 % o filename: the filename.
1018 %
1019 % o extent: Maximum length of the string.
1020 %
1021 % o exception: return any errors or warnings in this structure.
1022 %
1023 */
1025  const size_t extent,ExceptionInfo *exception)
1026 {
1027  StringInfo
1028  *string_info;
1029 
1030  assert(filename != (const char *) NULL);
1031  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
1032  assert(exception != (ExceptionInfo *) NULL);
1033  string_info=AcquireStringInfo(0);
1034  string_info->path=ConstantString(filename);
1035  if (string_info->datum != (unsigned char *) NULL)
1036  string_info->datum=(unsigned char *) RelinquishMagickMemory(
1037  string_info->datum);
1038  string_info->datum=(unsigned char *) FileToBlob(filename,extent,
1039  &string_info->length,exception);
1040  if (string_info->datum == (unsigned char *) NULL)
1041  {
1042  string_info=DestroyStringInfo(string_info);
1043  return((StringInfo *) NULL);
1044  }
1045  return(string_info);
1046 }
1047 
1048 /*
1049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1050 % %
1051 % %
1052 % %
1053 % F o r m a t M a g i c k S i z e %
1054 % %
1055 % %
1056 % %
1057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1058 %
1059 % FormatMagickSize() converts a size to a human readable format, for example,
1060 % 14k, 234m, 2.7g, or 3.0t. Scaling is done by repetitively dividing by
1061 % 1000.
1062 %
1063 % The format of the FormatMagickSize method is:
1064 %
1065 % ssize_t FormatMagickSize(const MagickSizeType size,const char *suffix,
1066 % const size_t length,char *format)
1067 %
1068 % A description of each parameter follows:
1069 %
1070 % o size: convert this size to a human readable format.
1071 %
1072 % o bi: use power of two rather than power of ten.
1073 %
1074 % o suffix: append suffix, typically B or P.
1075 %
1076 % o length: the maximum length of the string.
1077 %
1078 % o format: human readable format.
1079 %
1080 */
1082  const MagickBooleanType bi,const char *suffix,const size_t length,
1083  char *format)
1084 {
1085  char
1086  p[MagickPathExtent],
1087  q[MagickPathExtent];
1088 
1089  const char
1090  **units;
1091 
1092  double
1093  bytes,
1094  extent;
1095 
1096  register ssize_t
1097  i;
1098 
1099  ssize_t
1100  count;
1101 
1102  static const char
1103  *bi_units[] =
1104  {
1105  "", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi", (char *) NULL
1106  },
1107  *traditional_units[] =
1108  {
1109  "", "K", "M", "G", "T", "P", "E", "Z", "Y", (char *) NULL
1110  };
1111 
1112  bytes=1000.0;
1113  units=traditional_units;
1114  if (bi != MagickFalse)
1115  {
1116  bytes=1024.0;
1117  units=bi_units;
1118  }
1119 #if defined(_MSC_VER) && (_MSC_VER == 1200)
1120  extent=(double) ((MagickOffsetType) size);
1121 #else
1122  extent=(double) size;
1123 #endif
1125  extent);
1126  (void) FormatLocaleString(q,MagickPathExtent,"%.20g",extent);
1127  if (strtod(p,(char **) NULL) == strtod(q,(char **) NULL))
1128  {
1129  if (suffix == (const char *) NULL)
1130  count=FormatLocaleString(format,length,"%.20g%s",extent,units[0]);
1131  else
1132  count=FormatLocaleString(format,length,"%.20g%s%s",extent,units[0],
1133  suffix);
1134  return(count);
1135  }
1136  for (i=0; (extent >= bytes) && (units[i+1] != (const char *) NULL); i++)
1137  extent/=bytes;
1138  if (suffix == (const char *) NULL)
1139  count=FormatLocaleString(format,length,"%.*g%s",GetMagickPrecision(),
1140  extent,units[i]);
1141  else
1142  count=FormatLocaleString(format,length,"%.*g%s%s",GetMagickPrecision(),
1143  extent,units[i],suffix);
1144  return(count);
1145 }
1146 
1147 /*
1148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1149 % %
1150 % %
1151 % %
1152 % F o r m a t M a g i c k T i m e %
1153 % %
1154 % %
1155 % %
1156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1157 %
1158 % FormatMagickTime() returns the specified time in the Internet date/time
1159 % format and the length of the timestamp.
1160 %
1161 % The format of the FormatMagickTime method is:
1162 %
1163 % ssize_t FormatMagickTime(const time_t time,const size_t length,
1164 % char *timestamp)
1165 %
1166 % A description of each parameter follows.
1167 %
1168 % o time: the time since the Epoch (00:00:00 UTC, January 1, 1970),
1169 % measured in seconds.
1170 %
1171 % o length: the maximum length of the string.
1172 %
1173 % o timestamp: Return the Internet date/time here.
1174 %
1175 */
1176 MagickExport ssize_t FormatMagickTime(const time_t time,const size_t length,
1177  char *timestamp)
1178 {
1179  ssize_t
1180  count;
1181 
1182  struct tm
1183  gm_time,
1184  local_time;
1185 
1186  time_t
1187  timezone;
1188 
1189  assert(timestamp != (char *) NULL);
1190  (void) ResetMagickMemory(&local_time,0,sizeof(local_time));
1191  (void) ResetMagickMemory(&gm_time,0,sizeof(gm_time));
1192 #if defined(MAGICKCORE_HAVE_LOCALTIME_R)
1193  (void) localtime_r(&time,&local_time);
1194 #else
1195  {
1196  struct tm
1197  *my_time;
1198 
1199  my_time=localtime(&time);
1200  if (my_time != (struct tm *) NULL)
1201  (void) memcpy(&local_time,my_time,sizeof(local_time));
1202  }
1203 #endif
1204 #if defined(MAGICKCORE_HAVE_GMTIME_R)
1205  (void) gmtime_r(&time,&gm_time);
1206 #else
1207  {
1208  struct tm
1209  *my_time;
1210 
1211  my_time=gmtime(&time);
1212  if (my_time != (struct tm *) NULL)
1213  (void) memcpy(&gm_time,my_time,sizeof(gm_time));
1214  }
1215 #endif
1216  timezone=(time_t) ((local_time.tm_min-gm_time.tm_min)/60+
1217  local_time.tm_hour-gm_time.tm_hour+24*((local_time.tm_year-
1218  gm_time.tm_year) != 0 ? (local_time.tm_year-gm_time.tm_year) :
1219  (local_time.tm_yday-gm_time.tm_yday)));
1220  count=FormatLocaleString(timestamp,length,
1221  "%04d-%02d-%02dT%02d:%02d:%02d%+03ld:00",local_time.tm_year+1900,
1222  local_time.tm_mon+1,local_time.tm_mday,local_time.tm_hour,
1223  local_time.tm_min,local_time.tm_sec,(long) timezone);
1224  return(count);
1225 }
1226 
1227 /*
1228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1229 % %
1230 % %
1231 % %
1232 % G e t E n v i r o n m e n t V a l u e %
1233 % %
1234 % %
1235 % %
1236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1237 %
1238 % GetEnvironmentValue() returns the environment string that matches the
1239 % specified name.
1240 %
1241 % The format of the GetEnvironmentValue method is:
1242 %
1243 % char *GetEnvironmentValue(const char *name)
1244 %
1245 % A description of each parameter follows:
1246 %
1247 % o name: the environment name.
1248 %
1249 */
1250 MagickExport char *GetEnvironmentValue(const char *name)
1251 {
1252  const char
1253  *environment;
1254 
1255  environment=getenv(name);
1256  if (environment == (const char *) NULL)
1257  return((char *) NULL);
1258  return(ConstantString(environment));
1259 }
1260 
1261 /*
1262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1263 % %
1264 % %
1265 % %
1266 % G e t S t r i n g I n f o D a t u m %
1267 % %
1268 % %
1269 % %
1270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1271 %
1272 % GetStringInfoDatum() returns the datum associated with the string.
1273 %
1274 % The format of the GetStringInfoDatum method is:
1275 %
1276 % unsigned char *GetStringInfoDatum(const StringInfo *string_info)
1277 %
1278 % A description of each parameter follows:
1279 %
1280 % o string_info: the string info.
1281 %
1282 */
1283 MagickExport unsigned char *GetStringInfoDatum(const StringInfo *string_info)
1284 {
1285  assert(string_info != (StringInfo *) NULL);
1286  assert(string_info->signature == MagickCoreSignature);
1287  return(string_info->datum);
1288 }
1289 
1290 /*
1291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1292 % %
1293 % %
1294 % %
1295 % G e t S t r i n g I n f o L e n g t h %
1296 % %
1297 % %
1298 % %
1299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1300 %
1301 % GetStringInfoLength() returns the string length.
1302 %
1303 % The format of the GetStringInfoLength method is:
1304 %
1305 % size_t GetStringInfoLength(const StringInfo *string_info)
1306 %
1307 % A description of each parameter follows:
1308 %
1309 % o string_info: the string info.
1310 %
1311 */
1312 MagickExport size_t GetStringInfoLength(const StringInfo *string_info)
1313 {
1314  assert(string_info != (StringInfo *) NULL);
1315  assert(string_info->signature == MagickCoreSignature);
1316  return(string_info->length);
1317 }
1318 
1319 /*
1320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1321 % %
1322 % %
1323 % %
1324 % G e t S t r i n g I n f o P a t h %
1325 % %
1326 % %
1327 % %
1328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1329 %
1330 % GetStringInfoPath() returns the path associated with the string.
1331 %
1332 % The format of the GetStringInfoPath method is:
1333 %
1334 % const char *GetStringInfoPath(const StringInfo *string_info)
1335 %
1336 % A description of each parameter follows:
1337 %
1338 % o string_info: the string info.
1339 %
1340 */
1341 MagickExport const char *GetStringInfoPath(const StringInfo *string_info)
1342 {
1343  assert(string_info != (StringInfo *) NULL);
1344  assert(string_info->signature == MagickCoreSignature);
1345  return(string_info->path);
1346 }
1347 
1348 /*
1349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1350 % %
1351 % %
1352 % %
1353 + I n t e r p r e t S i P r e f i x V a l u e %
1354 % %
1355 % %
1356 % %
1357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1358 %
1359 % InterpretSiPrefixValue() converts the initial portion of the string to a
1360 % double representation. It also recognizes SI prefixes (e.g. B, KB, MiB,
1361 % etc.).
1362 %
1363 % The format of the InterpretSiPrefixValue method is:
1364 %
1365 % double InterpretSiPrefixValue(const char *value,char **sentinal)
1366 %
1367 % A description of each parameter follows:
1368 %
1369 % o value: the string value.
1370 %
1371 % o sentinal: if sentinal is not NULL, return a pointer to the character
1372 % after the last character used in the conversion.
1373 %
1374 */
1376  char **magick_restrict sentinal)
1377 {
1378  char
1379  *q;
1380 
1381  double
1382  value;
1383 
1384  value=InterpretLocaleValue(string,&q);
1385  if (q != string)
1386  {
1387  if ((*q >= 'E') && (*q <= 'z'))
1388  {
1389  double
1390  e;
1391 
1392  switch ((int) ((unsigned char) *q))
1393  {
1394  case 'y': e=(-24.0); break;
1395  case 'z': e=(-21.0); break;
1396  case 'a': e=(-18.0); break;
1397  case 'f': e=(-15.0); break;
1398  case 'p': e=(-12.0); break;
1399  case 'n': e=(-9.0); break;
1400  case 'u': e=(-6.0); break;
1401  case 'm': e=(-3.0); break;
1402  case 'c': e=(-2.0); break;
1403  case 'd': e=(-1.0); break;
1404  case 'h': e=2.0; break;
1405  case 'k': e=3.0; break;
1406  case 'K': e=3.0; break;
1407  case 'M': e=6.0; break;
1408  case 'G': e=9.0; break;
1409  case 'T': e=12.0; break;
1410  case 'P': e=15.0; break;
1411  case 'E': e=18.0; break;
1412  case 'Z': e=21.0; break;
1413  case 'Y': e=24.0; break;
1414  default: e=0.0; break;
1415  }
1416  if (e >= MagickEpsilon)
1417  {
1418  if (q[1] == 'i')
1419  {
1420  value*=pow(2.0,e/0.3);
1421  q+=2;
1422  }
1423  else
1424  {
1425  value*=pow(10.0,e);
1426  q++;
1427  }
1428  }
1429  }
1430  if ((*q == 'B') || (*q == 'P'))
1431  q++;
1432  }
1433  if (sentinal != (char **) NULL)
1434  *sentinal=q;
1435  return(value);
1436 }
1437 
1438 /*
1439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1440 % %
1441 % %
1442 % %
1443 % I s S t r i n g T r u e %
1444 % %
1445 % %
1446 % %
1447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1448 %
1449 % IsStringTrue() returns MagickTrue if the value is "true", "on", "yes" or
1450 % "1". Any other string or undefined returns MagickFalse.
1451 %
1452 % Typically this is used to look at strings (options or artifacts) which
1453 % has a default value of "false", when not defined.
1454 %
1455 % The format of the IsStringTrue method is:
1456 %
1457 % MagickBooleanType IsStringTrue(const char *value)
1458 %
1459 % A description of each parameter follows:
1460 %
1461 % o value: Specifies a pointer to a character array.
1462 %
1463 */
1465 {
1466  if (value == (const char *) NULL)
1467  return(MagickFalse);
1468  if (LocaleCompare(value,"true") == 0)
1469  return(MagickTrue);
1470  if (LocaleCompare(value,"on") == 0)
1471  return(MagickTrue);
1472  if (LocaleCompare(value,"yes") == 0)
1473  return(MagickTrue);
1474  if (LocaleCompare(value,"1") == 0)
1475  return(MagickTrue);
1476  return(MagickFalse);
1477 }
1478 
1479 /*
1480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1481 % %
1482 % %
1483 % %
1484 % I s S t r i n g F a l s e %
1485 % %
1486 % %
1487 % %
1488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1489 %
1490 % IsStringFalse() returns MagickTrue if the value is "false", "off", "no" or
1491 % "0". Any other string or undefined returns MagickFalse.
1492 %
1493 % Typically this is used to look at strings (options or artifacts) which
1494 % has a default value of "true", when it has not been defined.
1495 %
1496 % The format of the IsStringFalse method is:
1497 %
1498 % MagickBooleanType IsStringFalse(const char *value)
1499 %
1500 % A description of each parameter follows:
1501 %
1502 % o value: Specifies a pointer to a character array.
1503 %
1504 */
1506 {
1507  if (value == (const char *) NULL)
1508  return(MagickFalse);
1509  if (LocaleCompare(value,"false") == 0)
1510  return(MagickTrue);
1511  if (LocaleCompare(value,"off") == 0)
1512  return(MagickTrue);
1513  if (LocaleCompare(value,"no") == 0)
1514  return(MagickTrue);
1515  if (LocaleCompare(value,"0") == 0)
1516  return(MagickTrue);
1517  return(MagickFalse);
1518 }
1519 
1520 /*
1521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1522 % %
1523 % %
1524 % %
1525 % P r i n t S t r i n g I n f o %
1526 % %
1527 % %
1528 % %
1529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1530 %
1531 % PrintStringInfo() prints the string.
1532 %
1533 % The format of the PrintStringInfo method is:
1534 %
1535 % void PrintStringInfo(FILE *file,const char *id,
1536 % const StringInfo *string_info)
1537 %
1538 % A description of each parameter follows:
1539 %
1540 % o file: the file, typically stdout.
1541 %
1542 % o id: the string id.
1543 %
1544 % o string_info: the string info.
1545 %
1546 */
1547 MagickExport void PrintStringInfo(FILE *file,const char *id,
1548  const StringInfo *string_info)
1549 {
1550  register const char
1551  *p;
1552 
1553  register size_t
1554  i,
1555  j;
1556 
1557  assert(id != (const char *) NULL);
1558  assert(string_info != (StringInfo *) NULL);
1559  assert(string_info->signature == MagickCoreSignature);
1560  p=(char *) string_info->datum;
1561  for (i=0; i < string_info->length; i++)
1562  {
1563  if (((int) ((unsigned char) *p) < 32) &&
1564  (isspace((int) ((unsigned char) *p)) == 0))
1565  break;
1566  p++;
1567  }
1568  (void) FormatLocaleFile(file,"%s(%.20g): ",id,(double) string_info->length);
1569  if (i == string_info->length)
1570  {
1571  for (i=0; i < string_info->length; i++)
1572  (void) fputc(string_info->datum[i],file);
1573  (void) fputc('\n',file);
1574  return;
1575  }
1576  /*
1577  Convert string to a HEX list.
1578  */
1579  p=(char *) string_info->datum;
1580  for (i=0; i < string_info->length; i+=0x14)
1581  {
1582  (void) FormatLocaleFile(file,"0x%08lx: ",(unsigned long) (0x14*i));
1583  for (j=1; j <= MagickMin(string_info->length-i,0x14); j++)
1584  {
1585  (void) FormatLocaleFile(file,"%02lx",(unsigned long) (*(p+j)) & 0xff);
1586  if ((j % 0x04) == 0)
1587  (void) fputc(' ',file);
1588  }
1589  for ( ; j <= 0x14; j++)
1590  {
1591  (void) fputc(' ',file);
1592  (void) fputc(' ',file);
1593  if ((j % 0x04) == 0)
1594  (void) fputc(' ',file);
1595  }
1596  (void) fputc(' ',file);
1597  for (j=1; j <= MagickMin(string_info->length-i,0x14); j++)
1598  {
1599  if (isprint((int) ((unsigned char) *p)) != 0)
1600  (void) fputc(*p,file);
1601  else
1602  (void) fputc('-',file);
1603  p++;
1604  }
1605  (void) fputc('\n',file);
1606  }
1607 }
1608 
1609 /*
1610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1611 % %
1612 % %
1613 % %
1614 % R e s e t S t r i n g I n f o %
1615 % %
1616 % %
1617 % %
1618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1619 %
1620 % ResetStringInfo() reset the string to all null bytes.
1621 %
1622 % The format of the ResetStringInfo method is:
1623 %
1624 % void ResetStringInfo(StringInfo *string_info)
1625 %
1626 % A description of each parameter follows:
1627 %
1628 % o string_info: the string info.
1629 %
1630 */
1632 {
1633  assert(string_info != (StringInfo *) NULL);
1634  assert(string_info->signature == MagickCoreSignature);
1635  (void) ResetMagickMemory(string_info->datum,0,string_info->length);
1636 }
1637 
1638 /*
1639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1640 % %
1641 % %
1642 % %
1643 % S a n t i z e S t r i n g %
1644 % %
1645 % %
1646 % %
1647 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1648 %
1649 % SanitizeString() returns an new string removes all characters except
1650 % letters, digits and !#$%&'*+-=?^_`{|}~@.[].
1651 %
1652 % The returned string shoud be freed using DestoryString().
1653 %
1654 % The format of the SanitizeString method is:
1655 %
1656 % char *SanitizeString(const char *source)
1657 %
1658 % A description of each parameter follows:
1659 %
1660 % o source: A character string.
1661 %
1662 */
1663 MagickExport char *SanitizeString(const char *source)
1664 {
1665  char
1666  *sanitize_source;
1667 
1668  const char
1669  *q;
1670 
1671  register char
1672  *p;
1673 
1674  static char
1675  whitelist[] =
1676  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
1677  "$-_.+!*'(),{}|\\^~[]`\"><#%;/?:@&=";
1678 
1679  sanitize_source=AcquireString(source);
1680  p=sanitize_source;
1681  q=sanitize_source+strlen(sanitize_source);
1682  for (p+=strspn(p,whitelist); p != q; p+=strspn(p,whitelist))
1683  *p='_';
1684  return(sanitize_source);
1685 }
1686 
1687 /*
1688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1689 % %
1690 % %
1691 % %
1692 % S e t S t r i n g I n f o %
1693 % %
1694 % %
1695 % %
1696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1697 %
1698 % SetStringInfo() copies the source string to the destination string.
1699 %
1700 % The format of the SetStringInfo method is:
1701 %
1702 % void SetStringInfo(StringInfo *string_info,const StringInfo *source)
1703 %
1704 % A description of each parameter follows:
1705 %
1706 % o string_info: the string info.
1707 %
1708 % o source: the source string.
1709 %
1710 */
1712  const StringInfo *source)
1713 {
1714  assert(string_info != (StringInfo *) NULL);
1715  assert(string_info->signature == MagickCoreSignature);
1716  assert(source != (StringInfo *) NULL);
1717  assert(source->signature == MagickCoreSignature);
1718  if (string_info->length == 0)
1719  return;
1720  (void) ResetMagickMemory(string_info->datum,0,string_info->length);
1721  (void) memcpy(string_info->datum,source->datum,MagickMin(string_info->length,
1722  source->length));
1723 }
1724 
1725 /*
1726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1727 % %
1728 % %
1729 % %
1730 % S e t S t r i n g I n f o D a t u m %
1731 % %
1732 % %
1733 % %
1734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1735 %
1736 % SetStringInfoDatum() copies bytes from the source string for the length of
1737 % the destination string.
1738 %
1739 % The format of the SetStringInfoDatum method is:
1740 %
1741 % void SetStringInfoDatum(StringInfo *string_info,
1742 % const unsigned char *source)
1743 %
1744 % A description of each parameter follows:
1745 %
1746 % o string_info: the string info.
1747 %
1748 % o source: the source string.
1749 %
1750 */
1752  const unsigned char *source)
1753 {
1754  assert(string_info != (StringInfo *) NULL);
1755  assert(string_info->signature == MagickCoreSignature);
1756  if (string_info->length != 0)
1757  (void) memcpy(string_info->datum,source,string_info->length);
1758 }
1759 
1760 /*
1761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1762 % %
1763 % %
1764 % %
1765 % S e t S t r i n g I n f o L e n g t h %
1766 % %
1767 % %
1768 % %
1769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1770 %
1771 % SetStringInfoLength() set the string length to the specified value.
1772 %
1773 % The format of the SetStringInfoLength method is:
1774 %
1775 % void SetStringInfoLength(StringInfo *string_info,const size_t length)
1776 %
1777 % A description of each parameter follows:
1778 %
1779 % o string_info: the string info.
1780 %
1781 % o length: the string length.
1782 %
1783 */
1785  const size_t length)
1786 {
1787  assert(string_info != (StringInfo *) NULL);
1788  assert(string_info->signature == MagickCoreSignature);
1789  if (string_info->length == length)
1790  return;
1791  if (~length < MagickPathExtent)
1792  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1793  string_info->length=length;
1794  if (string_info->datum == (unsigned char *) NULL)
1795  string_info->datum=(unsigned char *) AcquireQuantumMemory(length+
1796  MagickPathExtent,sizeof(*string_info->datum));
1797  else
1798  string_info->datum=(unsigned char *) ResizeQuantumMemory(string_info->datum,
1799  length+MagickPathExtent,sizeof(*string_info->datum));
1800  if (string_info->datum == (unsigned char *) NULL)
1801  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1802 }
1803 
1804 /*
1805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1806 % %
1807 % %
1808 % %
1809 % S e t S t r i n g I n f o D a t u m %
1810 % %
1811 % %
1812 % %
1813 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1814 %
1815 % SetStringInfoPath() sets the path associated with the string.
1816 %
1817 % The format of the SetStringInfoPath method is:
1818 %
1819 % void SetStringInfoPath(StringInfo *string_info,const char *path)
1820 %
1821 % A description of each parameter follows:
1822 %
1823 % o string_info: the string info.
1824 %
1825 % o path: the path.
1826 %
1827 */
1828 MagickExport void SetStringInfoPath(StringInfo *string_info,const char *path)
1829 {
1830  assert(string_info != (StringInfo *) NULL);
1831  assert(string_info->signature == MagickCoreSignature);
1832  assert(path != (const char *) NULL);
1833  string_info->path=ConstantString(path);
1834 }
1835 
1836 /*
1837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1838 % %
1839 % %
1840 % %
1841 % S p l i t S t r i n g I n f o %
1842 % %
1843 % %
1844 % %
1845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1846 %
1847 % SplitStringInfo() splits a string into two and returns it.
1848 %
1849 % The format of the SplitStringInfo method is:
1850 %
1851 % StringInfo *SplitStringInfo(StringInfo *string_info,const size_t offset)
1852 %
1853 % A description of each parameter follows:
1854 %
1855 % o string_info: the string info.
1856 %
1857 */
1859  const size_t offset)
1860 {
1861  StringInfo
1862  *split_info;
1863 
1864  assert(string_info != (StringInfo *) NULL);
1865  assert(string_info->signature == MagickCoreSignature);
1866  if (offset > string_info->length)
1867  return((StringInfo *) NULL);
1868  split_info=AcquireStringInfo(offset);
1869  SetStringInfo(split_info,string_info);
1870  (void) memmove(string_info->datum,string_info->datum+offset,
1871  string_info->length-offset+MagickPathExtent);
1872  SetStringInfoLength(string_info,string_info->length-offset);
1873  return(split_info);
1874 }
1875 
1876 /*
1877 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1878 % %
1879 % %
1880 % %
1881 % S t r i n g I n f o T o S t r i n g %
1882 % %
1883 % %
1884 % %
1885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1886 %
1887 % StringInfoToString() converts a string info string to a C string.
1888 %
1889 % The format of the StringInfoToString method is:
1890 %
1891 % char *StringInfoToString(const StringInfo *string_info)
1892 %
1893 % A description of each parameter follows:
1894 %
1895 % o string_info: the string.
1896 %
1897 */
1898 MagickExport char *StringInfoToString(const StringInfo *string_info)
1899 {
1900  char
1901  *string;
1902 
1903  size_t
1904  length;
1905 
1906  string=(char *) NULL;
1907  length=string_info->length;
1908  if (~length >= (MagickPathExtent-1))
1909  string=(char *) AcquireQuantumMemory(length+MagickPathExtent,
1910  sizeof(*string));
1911  if (string == (char *) NULL)
1912  return((char *) NULL);
1913  (void) memcpy(string,(char *) string_info->datum,length*sizeof(*string));
1914  string[length]='\0';
1915  return(string);
1916 }
1917 
1918 /*
1919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1920 % %
1921 % %
1922 % %
1923 % S t r i n g I n f o T o H e x S t r i n g %
1924 % %
1925 % %
1926 % %
1927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1928 %
1929 % StringInfoToHexString() converts a string info string to a C string.
1930 %
1931 % The format of the StringInfoToHexString method is:
1932 %
1933 % char *StringInfoToHexString(const StringInfo *string_info)
1934 %
1935 % A description of each parameter follows:
1936 %
1937 % o string_info: the string.
1938 %
1939 */
1941 {
1942  char
1943  *string;
1944 
1945  register const unsigned char
1946  *p;
1947 
1948  register ssize_t
1949  i;
1950 
1951  register unsigned char
1952  *q;
1953 
1954  size_t
1955  length;
1956 
1957  unsigned char
1958  hex_digits[16];
1959 
1960  length=string_info->length;
1961  if (~length < MagickPathExtent)
1962  ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
1963  string=(char *) AcquireQuantumMemory(length+MagickPathExtent,2*
1964  sizeof(*string));
1965  if (string == (char *) NULL)
1966  ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
1967  hex_digits[0]='0';
1968  hex_digits[1]='1';
1969  hex_digits[2]='2';
1970  hex_digits[3]='3';
1971  hex_digits[4]='4';
1972  hex_digits[5]='5';
1973  hex_digits[6]='6';
1974  hex_digits[7]='7';
1975  hex_digits[8]='8';
1976  hex_digits[9]='9';
1977  hex_digits[10]='a';
1978  hex_digits[11]='b';
1979  hex_digits[12]='c';
1980  hex_digits[13]='d';
1981  hex_digits[14]='e';
1982  hex_digits[15]='f';
1983  p=string_info->datum;
1984  q=(unsigned char *) string;
1985  for (i=0; i < (ssize_t) string_info->length; i++)
1986  {
1987  *q++=hex_digits[(*p >> 4) & 0x0f];
1988  *q++=hex_digits[*p & 0x0f];
1989  p++;
1990  }
1991  *q='\0';
1992  return(string);
1993 }
1994 
1995 /*
1996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1997 % %
1998 % %
1999 % %
2000 % S t r i n g T o A r g v %
2001 % %
2002 % %
2003 % %
2004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2005 %
2006 % StringToArgv() converts a text string into command line arguments.
2007 % The 'argv' array of arguments, is returned while the number of arguments
2008 % is returned via the provided integer variable pointer.
2009 %
2010 % Simple 'word' tokenizer, which allows for each word to be optionally
2011 % quoted. However it will not allow use of partial quotes, or escape
2012 % characters.
2013 %
2014 % The format of the StringToArgv method is:
2015 %
2016 % char **StringToArgv(const char *text,int *argc)
2017 %
2018 % A description of each parameter follows:
2019 %
2020 % o argv: Method StringToArgv returns the string list unless an error
2021 % occurs, otherwise NULL.
2022 %
2023 % o text: Specifies the string to segment into a list.
2024 %
2025 % o argc: This integer pointer returns the number of arguments in the
2026 % list.
2027 %
2028 */
2029 MagickExport char **StringToArgv(const char *text,int *argc)
2030 {
2031  char
2032  **argv;
2033 
2034  register const char
2035  *p,
2036  *q;
2037 
2038  register ssize_t
2039  i;
2040 
2041  *argc=0;
2042  if (text == (char *) NULL)
2043  return((char **) NULL);
2044  /*
2045  Determine the number of arguments.
2046  */
2047  for (p=text; *p != '\0'; )
2048  {
2049  while (isspace((int) ((unsigned char) *p)) != 0)
2050  p++;
2051  if (*p == '\0')
2052  break;
2053  (*argc)++;
2054  if (*p == '"')
2055  for (p++; (*p != '"') && (*p != '\0'); p++) ;
2056  if (*p == '\'')
2057  for (p++; (*p != '\'') && (*p != '\0'); p++) ;
2058  while ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '\0'))
2059  p++;
2060  }
2061  (*argc)++;
2062  argv=(char **) AcquireQuantumMemory((size_t) (*argc+1UL),sizeof(*argv));
2063  if (argv == (char **) NULL)
2064  ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
2065  /*
2066  Convert string to an ASCII list.
2067  */
2068  argv[0]=AcquireString("magick");
2069  p=text;
2070  for (i=1; i < (ssize_t) *argc; i++)
2071  {
2072  while (isspace((int) ((unsigned char) *p)) != 0)
2073  p++;
2074  q=p;
2075  if (*q == '"')
2076  {
2077  p++;
2078  for (q++; (*q != '"') && (*q != '\0'); q++) ;
2079  }
2080  else
2081  if (*q == '\'')
2082  {
2083  p++;
2084  for (q++; (*q != '\'') && (*q != '\0'); q++) ;
2085  }
2086  else
2087  while ((isspace((int) ((unsigned char) *q)) == 0) && (*q != '\0'))
2088  q++;
2089  argv[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+MagickPathExtent,
2090  sizeof(**argv));
2091  if (argv[i] == (char *) NULL)
2092  {
2093  for (i--; i >= 0; i--)
2094  argv[i]=DestroyString(argv[i]);
2095  argv=(char **) RelinquishMagickMemory(argv);
2097  "UnableToConvertStringToARGV");
2098  }
2099  (void) memcpy(argv[i],p,(size_t) (q-p));
2100  argv[i][q-p]='\0';
2101  p=q;
2102  while ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '\0'))
2103  p++;
2104  }
2105  argv[i]=(char *) NULL;
2106  return(argv);
2107 }
2108 
2109 /*
2110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2111 % %
2112 % %
2113 % %
2114 % S t r i n g T o A r r a y O f D o u b l e s %
2115 % %
2116 % %
2117 % %
2118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2119 %
2120 % StringToArrayOfDoubles() converts a string of space or comma separated
2121 % numbers into array of floating point numbers (doubles). Any number that
2122 % failes to parse properly will produce a syntax error. As will two commas
2123 % without a number between them. However a final comma at the end will
2124 % not be regarded as an error so as to simplify automatic list generation.
2125 %
2126 % A NULL value is returned on syntax or memory errors.
2127 %
2128 % Use RelinquishMagickMemory() to free returned array when finished.
2129 %
2130 % The format of the StringToArrayOfDoubles method is:
2131 %
2132 % double *StringToArrayOfDoubles(const char *string,size_t *count,
2133 % ExceptionInfo *exception)
2134 %
2135 % A description of each parameter follows:
2136 %
2137 % o string: the string containing the comma/space separated values.
2138 %
2139 % o count: returns number of arguments in returned array
2140 %
2141 % o exception: return any errors or warnings in this structure.
2142 %
2143 */
2144 MagickExport double *StringToArrayOfDoubles(const char *string,ssize_t *count,
2145  ExceptionInfo *exception)
2146 {
2147  char
2148  *q;
2149 
2150  const char
2151  *p;
2152 
2153  double
2154  *array;
2155 
2156  register ssize_t
2157  i;
2158 
2159  /*
2160  Determine count of values, and check syntax.
2161  */
2162  assert(exception != (ExceptionInfo *) NULL);
2163  assert(exception->signature == MagickCoreSignature);
2164  *count=0;
2165  i=0;
2166  p=string;
2167  while (*p != '\0')
2168  {
2169  (void) StringToDouble(p,&q); /* get value - ignores leading space */
2170  if (p == q)
2171  return((double *) NULL); /* no value found */
2172  p=q;
2173  i++; /* increment value count */
2174  while (isspace((int) ((unsigned char) *p)) != 0)
2175  p++; /* skip spaces */
2176  if (*p == ',')
2177  p++; /* skip comma */
2178  while (isspace((int) ((unsigned char) *p)) != 0)
2179  p++; /* and more spaces */
2180  }
2181  /*
2182  Allocate floating point argument list.
2183  */
2184  *count=i;
2185  array=(double *) AcquireQuantumMemory((size_t) i,sizeof(*array));
2186  if (array == (double *) NULL)
2187  {
2188  (void) ThrowMagickException(exception,GetMagickModule(),
2189  ResourceLimitError,"MemoryAllocationFailed","`%s'","");
2190  return((double *) NULL);
2191  }
2192  /*
2193  Fill in the floating point values.
2194  */
2195  i=0;
2196  p=string;
2197  while ((*p != '\0') && (i < *count))
2198  {
2199  array[i++]=StringToDouble(p,&q);
2200  p=q;
2201  while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2202  p++;
2203  }
2204  return(array);
2205 }
2206 
2207 /*
2208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2209 % %
2210 % %
2211 % %
2212 + S t r i n g T o k e n %
2213 % %
2214 % %
2215 % %
2216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2217 %
2218 % StringToken() looks for any one of given delimiters and splits the string
2219 % into two separate strings by replacing the delimiter character found with a
2220 % nul character.
2221 %
2222 % The given string pointer is changed to point to the string following the
2223 % delimiter character found, or NULL. A pointer to the start of the
2224 % string is returned, representing the token before the delimiter.
2225 %
2226 % In may ways this is equivent to the strtok() C library function, but with
2227 % multiple delimiter characters rather than a delimiter string.
2228 %
2229 % The format of the StringToken method is:
2230 %
2231 % char *StringToken(const char *delimiters,char **string)
2232 %
2233 % A description of each parameter follows:
2234 %
2235 % o delimiters: one or more delimiters.
2236 %
2237 % o string: return the first token in the string. If none is found, return
2238 % NULL.
2239 %
2240 */
2241 MagickExport char *StringToken(const char *delimiters,char **string)
2242 {
2243  char
2244  *q;
2245 
2246  register char
2247  *p;
2248 
2249  register const char
2250  *r;
2251 
2252  register int
2253  c,
2254  d;
2255 
2256  p=(*string);
2257  if (p == (char *) NULL)
2258  return((char *) NULL);
2259  q=p;
2260  for ( ; ; )
2261  {
2262  c=(*p++);
2263  r=delimiters;
2264  do
2265  {
2266  d=(*r++);
2267  if (c == d)
2268  {
2269  if (c == '\0')
2270  p=(char *) NULL;
2271  else
2272  p[-1]='\0';
2273  *string=p;
2274  return(q);
2275  }
2276  } while (d != '\0');
2277  }
2278 }
2279 
2280 /*
2281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2282 % %
2283 % %
2284 % %
2285 % S t r i n g T o L i s t %
2286 % %
2287 % %
2288 % %
2289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2290 %
2291 % StringToList() converts a text string into a list by segmenting the text
2292 % string at each carriage return discovered. The list is converted to HEX
2293 % characters if any control characters are discovered within the text string.
2294 %
2295 % The format of the StringToList method is:
2296 %
2297 % char **StringToList(const char *text)
2298 %
2299 % A description of each parameter follows:
2300 %
2301 % o text: Specifies the string to segment into a list.
2302 %
2303 */
2304 MagickExport char **StringToList(const char *text)
2305 {
2306  char
2307  **textlist;
2308 
2309  register const char
2310  *p;
2311 
2312  register ssize_t
2313  i;
2314 
2315  size_t
2316  lines;
2317 
2318  if (text == (char *) NULL)
2319  return((char **) NULL);
2320  for (p=text; *p != '\0'; p++)
2321  if (((int) ((unsigned char) *p) < 32) &&
2322  (isspace((int) ((unsigned char) *p)) == 0))
2323  break;
2324  if (*p == '\0')
2325  {
2326  register const char
2327  *q;
2328 
2329  /*
2330  Convert string to an ASCII list.
2331  */
2332  lines=1;
2333  for (p=text; *p != '\0'; p++)
2334  if (*p == '\n')
2335  lines++;
2336  textlist=(char **) AcquireQuantumMemory((size_t) lines+1UL,
2337  sizeof(*textlist));
2338  if (textlist == (char **) NULL)
2339  ThrowFatalException(ResourceLimitFatalError,"UnableToConvertText");
2340  p=text;
2341  for (i=0; i < (ssize_t) lines; i++)
2342  {
2343  for (q=p; *q != '\0'; q++)
2344  if ((*q == '\r') || (*q == '\n'))
2345  break;
2346  textlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+
2347  MagickPathExtent,sizeof(**textlist));
2348  if (textlist[i] == (char *) NULL)
2349  ThrowFatalException(ResourceLimitFatalError,"UnableToConvertText");
2350  (void) memcpy(textlist[i],p,(size_t) (q-p));
2351  textlist[i][q-p]='\0';
2352  if (*q == '\r')
2353  q++;
2354  p=q+1;
2355  }
2356  }
2357  else
2358  {
2359  char
2360  hex_string[MagickPathExtent];
2361 
2362  register char
2363  *q;
2364 
2365  register ssize_t
2366  j;
2367 
2368  /*
2369  Convert string to a HEX list.
2370  */
2371  lines=(size_t) (strlen(text)/0x14)+1;
2372  textlist=(char **) AcquireQuantumMemory((size_t) lines+1UL,
2373  sizeof(*textlist));
2374  if (textlist == (char **) NULL)
2375  ThrowFatalException(ResourceLimitFatalError,"UnableToConvertText");
2376  p=text;
2377  for (i=0; i < (ssize_t) lines; i++)
2378  {
2379  textlist[i]=(char *) AcquireQuantumMemory(2UL*MagickPathExtent,
2380  sizeof(**textlist));
2381  if (textlist[i] == (char *) NULL)
2382  ThrowFatalException(ResourceLimitFatalError,"UnableToConvertText");
2383  (void) FormatLocaleString(textlist[i],MagickPathExtent,"0x%08lx: ",
2384  (long) (0x14*i));
2385  q=textlist[i]+strlen(textlist[i]);
2386  for (j=1; j <= (ssize_t) MagickMin(strlen(p),0x14); j++)
2387  {
2388  (void) FormatLocaleString(hex_string,MagickPathExtent,"%02x",*(p+j));
2389  (void) CopyMagickString(q,hex_string,MagickPathExtent);
2390  q+=2;
2391  if ((j % 0x04) == 0)
2392  *q++=' ';
2393  }
2394  for ( ; j <= 0x14; j++)
2395  {
2396  *q++=' ';
2397  *q++=' ';
2398  if ((j % 0x04) == 0)
2399  *q++=' ';
2400  }
2401  *q++=' ';
2402  for (j=1; j <= (ssize_t) MagickMin(strlen(p),0x14); j++)
2403  {
2404  if (isprint((int) ((unsigned char) *p)) != 0)
2405  *q++=(*p);
2406  else
2407  *q++='-';
2408  p++;
2409  }
2410  *q='\0';
2411  }
2412  }
2413  textlist[i]=(char *) NULL;
2414  return(textlist);
2415 }
2416 
2417 /*
2418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2419 % %
2420 % %
2421 % %
2422 % S t r i n g T o S t r i n g I n f o %
2423 % %
2424 % %
2425 % %
2426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2427 %
2428 % StringToStringInfo() converts a string to a StringInfo type.
2429 %
2430 % The format of the StringToStringInfo method is:
2431 %
2432 % StringInfo *StringToStringInfo(const char *string)
2433 %
2434 % A description of each parameter follows:
2435 %
2436 % o string: The string.
2437 %
2438 */
2440 {
2441  StringInfo
2442  *string_info;
2443 
2444  assert(string != (const char *) NULL);
2445  string_info=AcquireStringInfo(strlen(string));
2446  SetStringInfoDatum(string_info,(const unsigned char *) string);
2447  return(string_info);
2448 }
2449 
2450 /*
2451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2452 % %
2453 % %
2454 % %
2455 % S t r i p S t r i n g %
2456 % %
2457 % %
2458 % %
2459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2460 %
2461 % StripString() strips any whitespace or quotes from the beginning and end of
2462 % a string of characters.
2463 %
2464 % The format of the StripString method is:
2465 %
2466 % void StripString(char *message)
2467 %
2468 % A description of each parameter follows:
2469 %
2470 % o message: Specifies an array of characters.
2471 %
2472 */
2473 MagickExport void StripString(char *message)
2474 {
2475  register char
2476  *p,
2477  *q;
2478 
2479  size_t
2480  length;
2481 
2482  assert(message != (char *) NULL);
2483  if (*message == '\0')
2484  return;
2485  length=strlen(message);
2486  p=message;
2487  while (isspace((int) ((unsigned char) *p)) != 0)
2488  p++;
2489  if ((*p == '\'') || (*p == '"'))
2490  p++;
2491  q=message+length-1;
2492  while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p))
2493  q--;
2494  if (q > p)
2495  if ((*q == '\'') || (*q == '"'))
2496  q--;
2497  (void) memmove(message,p,(size_t) (q-p+1));
2498  message[q-p+1]='\0';
2499  for (p=message; *p != '\0'; p++)
2500  if (*p == '\n')
2501  *p=' ';
2502 }
2503 
2504 /*
2505 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2506 % %
2507 % %
2508 % %
2509 % S u b s t i t u t e S t r i n g %
2510 % %
2511 % %
2512 % %
2513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2514 %
2515 % SubstituteString() performs string substitution on a string, replacing the
2516 % string with the substituted version. Buffer must be allocated from the heap.
2517 % If the string is matched and status, MagickTrue is returned otherwise
2518 % MagickFalse.
2519 %
2520 % The format of the SubstituteString method is:
2521 %
2522 % MagickBooleanType SubstituteString(char **string,const char *search,
2523 % const char *replace)
2524 %
2525 % A description of each parameter follows:
2526 %
2527 % o string: the string to perform replacements on; replaced with new
2528 % allocation if a replacement is made.
2529 %
2530 % o search: search for this string.
2531 %
2532 % o replace: replace any matches with this string.
2533 %
2534 */
2536  const char *search,const char *replace)
2537 {
2539  status;
2540 
2541  register char
2542  *p;
2543 
2544  size_t
2545  extent,
2546  replace_extent,
2547  search_extent;
2548 
2549  ssize_t
2550  offset;
2551 
2552  status=MagickFalse;
2553  search_extent=0,
2554  replace_extent=0;
2555  for (p=strchr(*string,*search); p != (char *) NULL; p=strchr(p+1,*search))
2556  {
2557  if (search_extent == 0)
2558  search_extent=strlen(search);
2559  if (strncmp(p,search,search_extent) != 0)
2560  continue;
2561  /*
2562  We found a match.
2563  */
2564  status=MagickTrue;
2565  if (replace_extent == 0)
2566  replace_extent=strlen(replace);
2567  if (replace_extent > search_extent)
2568  {
2569  /*
2570  Make room for the replacement string.
2571  */
2572  offset=(ssize_t) (p-(*string));
2573  extent=strlen(*string)+replace_extent-search_extent+1;
2574  *string=(char *) ResizeQuantumMemory(*string,extent+MagickPathExtent,
2575  sizeof(*p));
2576  if (*string == (char *) NULL)
2577  ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
2578  p=(*string)+offset;
2579  }
2580  /*
2581  Replace string.
2582  */
2583  if (search_extent != replace_extent)
2584  (void) CopyMagickMemory(p+replace_extent,p+search_extent,
2585  strlen(p+search_extent)+1);
2586  (void) CopyMagickMemory(p,replace,replace_extent);
2587  p+=replace_extent-1;
2588  }
2589  return(status);
2590 }
#define magick_restrict
Definition: MagickCore.h:41
MagickExport double InterpretSiPrefixValue(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: string.c:1375
MagickExport ssize_t FormatMagickSize(const MagickSizeType size, const MagickBooleanType bi, const char *suffix, const size_t length, char *format)
Definition: string.c:1081
Definition: blob.h:29
MagickExport MagickBooleanType IsStringFalse(const char *value)
Definition: string.c:1505
MagickExport int CompareStringInfo(const StringInfo *target, const StringInfo *source)
Definition: string.c:362
static const unsigned char AsciiMap[]
Definition: string.c:69
MagickExport StringInfo * StringToStringInfo(const char *string)
Definition: string.c:2439
MagickExport void SetStringInfoPath(StringInfo *string_info, const char *path)
Definition: string.c:1828
char * map
Definition: stream.c:84
#define ThrowFatalException(severity, tag)
size_t signature
Definition: exception.h:123
unsigned char * datum
Definition: string_.h:33
MagickExport char * EscapeString(const char *source, const char escape)
Definition: string.c:914
MagickExport size_t ConcatenateMagickString(char *destination, const char *source, const size_t length)
Definition: string.c:410
static double StringToDouble(const char *magick_restrict string, char **magick_restrict sentinal)
MagickExport char * SanitizeString(const char *source)
Definition: string.c:1663
MagickExport void ConcatenateStringInfo(StringInfo *string_info, const StringInfo *source)
Definition: string.c:536
MagickExport ssize_t FormatLocaleString(char *magick_restrict string, const size_t length, const char *magick_restrict format,...)
Definition: locale.c:473
#define MagickEpsilon
Definition: magick-type.h:110
MagickExport void * ResizeQuantumMemory(void *memory, const size_t count, const size_t quantum)
Definition: memory.c:1277
#define O_BINARY
Definition: studio.h:320
MagickExport void StripString(char *message)
Definition: string.c:2473
Definition: log.h:52
MagickExport char * FileToString(const char *filename, const size_t extent, ExceptionInfo *exception)
Definition: string.c:985
ssize_t MagickOffsetType
Definition: magick-type.h:127
#define MagickCoreSignature
MagickExport unsigned char * GetStringInfoDatum(const StringInfo *string_info)
Definition: string.c:1283
MagickExport ssize_t FormatLocaleFile(FILE *file, const char *magick_restrict format,...)
Definition: locale.c:378
MagickBooleanType
Definition: magick-type.h:156
MagickExport char ** StringToList(const char *text)
Definition: string.c:2304
MagickExport char * AcquireString(const char *source)
Definition: string.c:124
MagickExport void * FileToBlob(const char *filename, const size_t extent, size_t *length, ExceptionInfo *exception)
Definition: blob.c:1270
MagickExport void * ResetMagickMemory(void *memory, int byte, const size_t size)
Definition: memory.c:1164
MagickExport StringInfo * FileToStringInfo(const char *filename, const size_t extent, ExceptionInfo *exception)
Definition: string.c:1024
MagickExport StringInfo * DestroyStringInfo(StringInfo *string_info)
Definition: string.c:837
MagickExport void ResetStringInfo(StringInfo *string_info)
Definition: string.c:1631
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:529
MagickExport MagickBooleanType ConcatenateString(char **destination, const char *source)
Definition: string.c:476
MagickExport ssize_t FormatMagickTime(const time_t time, const size_t length, char *timestamp)
Definition: string.c:1176
size_t MagickSizeType
Definition: magick-type.h:128
#define MagickPathExtent
MagickExport void PrintStringInfo(FILE *file, const char *id, const StringInfo *string_info)
Definition: string.c:1547
MagickExport MagickBooleanType IsStringTrue(const char *value)
Definition: string.c:1464
MagickExport MagickBooleanType static void * AcquireCriticalMemory(const size_t size)
MagickExport int GetMagickPrecision(void)
Definition: magick.c:865
MagickExport StringInfo * BlobToStringInfo(const void *blob, const size_t length)
Definition: string.c:213
MagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *tag, const char *format,...)
Definition: exception.c:1058
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1397
static int open_utf8(const char *path, int flags, mode_t mode)
ExceptionInfo * exception
Definition: stream.c:99
MagickExport double * StringToArrayOfDoubles(const char *string, ssize_t *count, ExceptionInfo *exception)
Definition: string.c:2144
MagickExport MagickBooleanType SubstituteString(char **string, const char *search, const char *replace)
Definition: string.c:2535
MagickExport char * GetEnvironmentValue(const char *name)
Definition: string.c:1250
MagickExport StringInfo * ConfigureFileToStringInfo(const char *filename)
Definition: string.c:576
MagickExport size_t CopyMagickString(char *destination, const char *source, const size_t length)
Definition: string.c:742
MagickExport StringInfo * AcquireStringInfo(const size_t length)
Definition: string.c:170
MagickExport int LocaleCompare(const char *p, const char *q)
Definition: locale.c:1409
#define GetMagickModule()
Definition: log.h:28
MagickExport const char * GetStringInfoPath(const StringInfo *string_info)
Definition: string.c:1341
MagickExport char * StringToken(const char *delimiters, char **string)
Definition: string.c:2241
MagickExport void SetStringInfoLength(StringInfo *string_info, const size_t length)
Definition: string.c:1784
MagickExport char * DestroyString(char *string)
Definition: string.c:810
MagickExport char ** DestroyStringList(char **list)
Definition: string.c:873
#define MagickMin(x, y)
Definition: image-private.h:27
char * path
Definition: string_.h:30
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1038
MagickExport MagickBooleanType UnmapBlob(void *, const size_t)
Definition: blob.c:5220
size_t signature
Definition: string_.h:36
MagickExport char * CloneString(char **destination, const char *source)
Definition: string.c:270
size_t length
Definition: string_.h:36
#define MagickExport
MagickExport StringInfo * SplitStringInfo(StringInfo *string_info, const size_t offset)
Definition: string.c:1858
MagickExport char * StringInfoToString(const StringInfo *string_info)
Definition: string.c:1898
MagickExport char * StringInfoToHexString(const StringInfo *string_info)
Definition: string.c:1940
MagickExport char ** StringToArgv(const char *text, int *argc)
Definition: string.c:2029
MagickExport size_t GetStringInfoLength(const StringInfo *string_info)
Definition: string.c:1312
MagickExport char * ConstantString(const char *source)
Definition: string.c:687
MagickExport void * CopyMagickMemory(void *destination, const void *source, const size_t size)
Definition: memory.c:721
MagickExport StringInfo * CloneStringInfo(const StringInfo *string_info)
Definition: string.c:322
MagickExport void SetStringInfoDatum(StringInfo *string_info, const unsigned char *source)
Definition: string.c:1751
MagickExport void * MapBlob(int, const MapMode, const MagickOffsetType, const size_t)
MagickExport void SetStringInfo(StringInfo *string_info, const StringInfo *source)
Definition: string.c:1711
MagickExport double InterpretLocaleValue(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: locale.c:977