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