42#include "MagickCore/studio.h"
43#include "MagickCore/blob.h"
44#include "MagickCore/blob-private.h"
45#include "MagickCore/exception.h"
46#include "MagickCore/exception-private.h"
47#include "MagickCore/image-private.h"
48#include "MagickCore/list.h"
49#include "MagickCore/locale_.h"
50#include "MagickCore/log.h"
51#include "MagickCore/memory_.h"
52#include "MagickCore/memory-private.h"
53#include "MagickCore/nt-base-private.h"
54#include "MagickCore/property.h"
55#include "MagickCore/policy.h"
56#include "MagickCore/resource_.h"
57#include "MagickCore/resource-private.h"
58#include "MagickCore/signature-private.h"
59#include "MagickCore/string_.h"
60#include "MagickCore/string-private.h"
61#include "MagickCore/utility-private.h"
66#define CharsPerLine 0x14
96MagickExport
char *AcquireString(
const char *source)
105 if (source != (
char *) NULL)
106 length+=strlen(source);
107 if (~length < MagickPathExtent)
108 ThrowFatalException(ResourceLimitFatalError,
"UnableToAcquireString");
109 destination=(
char *) AcquireQuantumMemory(length+MagickPathExtent,
110 sizeof(*destination));
111 if (destination == (
char *) NULL)
112 ThrowFatalException(ResourceLimitFatalError,
"UnableToAcquireString");
113 if (source != (
char *) NULL)
114 (void) memcpy(destination,source,length*
sizeof(*destination));
115 destination[length]=
'\0';
142static StringInfo *AcquireStringInfoContainer(
void)
147 string_info=(
StringInfo *) AcquireCriticalMemory(
sizeof(*string_info));
148 (void) memset(string_info,0,
sizeof(*string_info));
149 string_info->signature=MagickCoreSignature;
153MagickExport
StringInfo *AcquireStringInfo(
const size_t length)
158 string_info=AcquireStringInfoContainer();
159 string_info->length=length;
160 if (~string_info->length >= (MagickPathExtent-1))
161 string_info->datum=(
unsigned char *) AcquireQuantumMemory(
162 string_info->length+MagickPathExtent,
sizeof(*string_info->datum));
163 if (string_info->datum == (
unsigned char *) NULL)
164 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
165 (void) memset(string_info->datum,0,(length+MagickPathExtent)*
166 sizeof(*string_info->datum));
195MagickExport
StringInfo *BlobToStringInfo(
const void *blob,
const size_t length)
200 if (~length < MagickPathExtent)
201 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
202 string_info=AcquireStringInfoContainer();
203 string_info->length=length;
204 string_info->datum=(
unsigned char *) AcquireQuantumMemory(length+
205 MagickPathExtent,
sizeof(*string_info->datum));
206 if (string_info->datum == (
unsigned char *) NULL)
208 string_info=DestroyStringInfo(string_info);
211 if (blob != (
const void *) NULL)
212 (void) memcpy(string_info->datum,blob,length);
214 (
void) memset(string_info->datum,0,length*
sizeof(*string_info->datum));
215 (void) memset(string_info->datum+length,0,MagickPathExtent*
216 sizeof(*string_info->datum));
252MagickExport
char *CloneString(
char **destination,
const char *source)
257 assert(destination != (
char **) NULL);
258 if (source == (
const char *) NULL)
260 if (*destination != (
char *) NULL)
261 *destination=DestroyString(*destination);
262 return(*destination);
264 if (*destination == (
char *) NULL)
266 *destination=AcquireString(source);
267 return(*destination);
269 length=strlen(source);
270 if (~length < MagickPathExtent)
271 ThrowFatalException(ResourceLimitFatalError,
"UnableToAcquireString");
272 *destination=(
char *) ResizeQuantumMemory(*destination,length+
273 MagickPathExtent,
sizeof(**destination));
274 if (*destination == (
char *) NULL)
275 ThrowFatalException(ResourceLimitFatalError,
"UnableToAcquireString");
277 (void) memcpy(*destination,source,length*
sizeof(**destination));
278 (*destination)[length]=
'\0';
279 return(*destination);
310 assert(string_info->signature == MagickCoreSignature);
311 clone_info=AcquireStringInfo(string_info->length);
312 (void) CloneString(&clone_info->path,string_info->path);
313 (void) CloneString(&clone_info->name,string_info->name);
314 if (string_info->length != 0)
315 (void) memcpy(clone_info->datum,string_info->datum,string_info->length+1);
346MagickExport
int CompareStringInfo(
const StringInfo *target,
353 assert(target->signature == MagickCoreSignature);
355 assert(source->signature == MagickCoreSignature);
356 status=memcmp(target->datum,source->datum,MagickMin(target->length,
360 if (target->length == source->length)
362 return(target->length < source->length ? -1 : 1);
394MagickExport
size_t ConcatenateMagickString(
char *magick_restrict destination,
395 const char *magick_restrict source,
const size_t length)
407 assert(destination != (
char *) NULL);
408 assert(source != (
const char *) NULL);
413 while ((i-- != 0) && (*q !=
'\0'))
415 count=(size_t) (q-destination);
418 return(count+strlen(p));
429 return(count+(
size_t) (p-source));
458MagickExport MagickBooleanType ConcatenateString(
459 char **magick_restrict destination,
const char *magick_restrict source)
466 assert(destination != (
char **) NULL);
467 if (source == (
const char *) NULL)
469 if (*destination == (
char *) NULL)
471 *destination=AcquireString(source);
474 destination_length=strlen(*destination);
475 source_length=strlen(source);
476 length=destination_length;
477 if (~length < source_length)
478 ThrowFatalException(ResourceLimitFatalError,
"UnableToConcatenateString");
479 length+=source_length;
480 if (~length < MagickPathExtent)
481 ThrowFatalException(ResourceLimitFatalError,
"UnableToConcatenateString");
482 *destination=(
char *) ResizeQuantumMemory(*destination,
483 OverAllocateMemory(length+MagickPathExtent),
sizeof(**destination));
484 if (*destination == (
char *) NULL)
485 ThrowFatalException(ResourceLimitFatalError,
"UnableToConcatenateString");
486 if (source_length != 0)
487 (void) memcpy((*destination)+destination_length,source,source_length);
488 (*destination)[length]=
'\0';
518MagickExport
void ConcatenateStringInfo(
StringInfo *string_info,
525 assert(string_info->signature == MagickCoreSignature);
527 length=string_info->length;
528 if (~length < source->length)
529 ThrowFatalException(ResourceLimitFatalError,
"UnableToConcatenateString");
530 length+=source->length;
531 if (~length < MagickPathExtent)
532 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
533 if (string_info->datum == (
unsigned char *) NULL)
534 string_info->datum=(
unsigned char *) AcquireQuantumMemory(length+
535 MagickPathExtent,
sizeof(*string_info->datum));
537 string_info->datum=(
unsigned char *) ResizeQuantumMemory(
538 string_info->datum,OverAllocateMemory(length+MagickPathExtent),
539 sizeof(*string_info->datum));
540 if (string_info->datum == (
unsigned char *) NULL)
541 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
542 (void) memcpy(string_info->datum+string_info->length,source->datum,
544 string_info->length=length;
571MagickExport
StringInfo *ConfigureFileToStringInfo(
const char *filename)
591 assert(filename != (
const char *) NULL);
592 file=open_utf8(filename,O_RDONLY | O_BINARY,0);
595 offset=(MagickOffsetType) lseek(file,0,SEEK_END);
596 if ((offset < 0) || (offset != (MagickOffsetType) ((ssize_t) offset)))
601 length=(size_t) offset;
602 string=(
char *) NULL;
603 if (~length >= (MagickPathExtent-1))
604 string=(
char *) AcquireQuantumMemory(length+MagickPathExtent,
606 if (
string == (
char *) NULL)
611 map=MapBlob(file,ReadMode,0,length);
612 if (map != (
void *) NULL)
614 (void) memcpy(
string,map,length);
615 (void) UnmapBlob(map,length);
625 (void) lseek(file,0,SEEK_SET);
626 for (i=0; i < length; i+=(size_t) count)
628 count=read(file,
string+i,(
size_t) MagickMin(length-i,(
size_t)
629 MagickMaxBufferExtent));
640 string=DestroyString(
string);
646 string_info=AcquireStringInfoContainer();
647 string_info->path=ConstantString(filename);
648 string_info->length=length;
649 string_info->datum=(
unsigned char *)
string;
679MagickExport
char *ConstantString(
const char *source)
688 if (source != (
char *) NULL)
689 length+=strlen(source);
690 destination=(
char *) NULL;
692 destination=(
char *) AcquireQuantumMemory(length+1UL,
sizeof(*destination));
693 if (destination == (
char *) NULL)
694 ThrowFatalException(ResourceLimitFatalError,
"UnableToAcquireString");
695 if (source != (
char *) NULL)
696 (void) memcpy(destination,source,length*
sizeof(*destination));
697 destination[length]=
'\0';
732MagickExport
size_t CopyMagickString(
char *magick_restrict destination,
733 const char *magick_restrict source,
const size_t length)
746 for (n=length; n > 4; n-=4)
748 if (((*q++)=(*p++)) ==
'\0')
749 return((
size_t) (p-source-1));
750 if (((*q++)=(*p++)) ==
'\0')
751 return((
size_t) (p-source-1));
752 if (((*q++)=(*p++)) ==
'\0')
753 return((
size_t) (p-source-1));
754 if (((*q++)=(*p++)) ==
'\0')
755 return((
size_t) (p-source-1));
760 if (((*q++)=(*p++)) ==
'\0')
761 return((
size_t) (p-source-1));
764 return((
size_t) (p-source));
789MagickExport
char *DestroyString(
char *
string)
791 return((
char *) RelinquishMagickMemory(
string));
819 assert(string_info->signature == MagickCoreSignature);
820 if (string_info->datum != (
unsigned char *) NULL)
821 string_info->datum=(
unsigned char *) RelinquishMagickMemory(
823 if (string_info->name != (
char *) NULL)
824 string_info->name=DestroyString(string_info->name);
825 if (string_info->path != (
char *) NULL)
826 string_info->path=DestroyString(string_info->path);
827 string_info->signature=(~MagickCoreSignature);
828 string_info=(
StringInfo *) RelinquishMagickMemory(string_info);
854MagickExport
char **DestroyStringList(
char **list)
859 assert(list != (
char **) NULL);
860 for (i=0; list[i] != (
char *) NULL; i++)
861 list[i]=DestroyString(list[i]);
862 list=(
char **) RelinquishMagickMemory(list);
895MagickExport
char *EscapeString(
const char *source,
const char escape)
909 assert(source != (
const char *) NULL);
911 for (p=source; *p !=
'\0'; p++)
913 if ((*p ==
'\\') || (*p == escape))
916 ThrowFatalException(ResourceLimitFatalError,
"UnableToEscapeString");
921 destination=(
char *) NULL;
922 if (~length >= (MagickPathExtent-1))
923 destination=(
char *) AcquireQuantumMemory(length+MagickPathExtent,
924 sizeof(*destination));
925 if (destination == (
char *) NULL)
926 ThrowFatalException(ResourceLimitFatalError,
"UnableToEscapeString");
929 for (p=source; *p !=
'\0'; p++)
931 if ((*p ==
'\\') || (*p == escape))
966MagickExport
char *FileToString(
const char *filename,
const size_t extent,
975 assert(filename != (
const char *) NULL);
977 if (IsEventLogging() != MagickFalse)
978 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
980 if ((*filename ==
'@') && (strlen(filename) > 1))
985 status=IsRightsAuthorized(PathPolicyDomain,ReadPolicyRights,filename);
986 if (status == MagickFalse)
989 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
990 "NotAuthorized",
"`%s'",filename);
991 return((
char *) NULL);
995 return((
char *) FileToBlob(p,extent,&length,exception));
1025MagickExport
StringInfo *FileToStringInfo(
const char *filename,
1031 assert(filename != (
const char *) NULL);
1033 if (IsEventLogging() != MagickFalse)
1034 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
1035 string_info=AcquireStringInfoContainer();
1036 string_info->path=ConstantString(filename);
1037 string_info->datum=(
unsigned char *) FileToBlob(filename,extent,
1038 &string_info->length,exception);
1039 if (string_info->datum == (
unsigned char *) NULL)
1041 string_info=DestroyStringInfo(string_info);
1044 return(string_info);
1080MagickExport ssize_t FormatMagickSize(
const MagickSizeType size,
1081 const MagickBooleanType bi,
const char *suffix,
const size_t length,
1100 "",
"Ki",
"Mi",
"Gi",
"Ti",
"Pi",
"Ei",
"Zi",
"Yi",
"Ri",
"Qi", (
char *) NULL
1102 *traditional_units[] =
1104 "",
"K",
"M",
"G",
"T",
"P",
"E",
"Z",
"Y",
"R",
"Q", (
char *) NULL
1108 units=traditional_units;
1109 if (bi != MagickFalse)
1114 extent=(double) size;
1115 (void) FormatLocaleString(format,MagickFormatExtent,
"%.*g",
1116 GetMagickPrecision(),extent);
1117 if (strstr(format,
"e+") == (
char *) NULL)
1119 if (suffix == (
const char *) NULL)
1120 count=FormatLocaleString(format,length,
"%.20g%s",extent,units[0]);
1122 count=FormatLocaleString(format,length,
"%.20g%s%s",extent,units[0],
1126 for (i=0; (extent >= bytes) && (units[i+1] != (
const char *) NULL); i++)
1128 if (suffix == (
const char *) NULL)
1129 count=FormatLocaleString(format,length,
"%.*g%s",GetMagickPrecision(),
1132 count=FormatLocaleString(format,length,
"%.*g%s%s",GetMagickPrecision(),
1133 extent,units[i],suffix);
1160MagickExport
char *GetEnvironmentValue(
const char *name)
1162#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1163 return(NTGetEnvironmentValue(name));
1168 environment=getenv(name);
1169 if (environment == (
const char *) NULL)
1170 return((
char *) NULL);
1171 return(ConstantString(environment));
1197MagickExport
unsigned char *GetStringInfoDatum(
const StringInfo *string_info)
1200 assert(string_info->signature == MagickCoreSignature);
1201 return(string_info->datum);
1226MagickExport
size_t GetStringInfoLength(
const StringInfo *string_info)
1229 assert(string_info->signature == MagickCoreSignature);
1230 return(string_info->length);
1255MagickExport
const char *GetStringInfoName(
const StringInfo *string_info)
1258 assert(string_info->signature == MagickCoreSignature);
1259 return(string_info->name);
1284MagickExport
const char *GetStringInfoPath(
const StringInfo *string_info)
1287 assert(string_info->signature == MagickCoreSignature);
1288 return(string_info->path);
1318MagickExport
double InterpretSiPrefixValue(
const char *magick_restrict
string,
1319 char **magick_restrict sentinel)
1327 value=InterpretLocaleValue(
string,&q);
1330 if ((*q >=
'E') && (*q <=
'z'))
1335 switch ((
int) ((
unsigned char) *q))
1337 case 'q': e=(-30.0);
break;
1338 case 'r': e=(-27.0);
break;
1339 case 'y': e=(-24.0);
break;
1340 case 'z': e=(-21.0);
break;
1341 case 'a': e=(-18.0);
break;
1342 case 'f': e=(-15.0);
break;
1343 case 'p': e=(-12.0);
break;
1344 case 'n': e=(-9.0);
break;
1345 case 'u': e=(-6.0);
break;
1346 case 'm': e=(-3.0);
break;
1347 case 'c': e=(-2.0);
break;
1348 case 'd': e=(-1.0);
break;
1349 case 'h': e=2.0;
break;
1350 case 'k': e=3.0;
break;
1351 case 'K': e=3.0;
break;
1352 case 'M': e=6.0;
break;
1353 case 'G': e=9.0;
break;
1354 case 'T': e=12.0;
break;
1355 case 'P': e=15.0;
break;
1356 case 'E': e=18.0;
break;
1357 case 'Z': e=21.0;
break;
1358 case 'Y': e=24.0;
break;
1359 case 'R': e=27.0;
break;
1360 case 'Q': e=30.0;
break;
1361 default: e=0.0;
break;
1363 if (e >= MagickEpsilon)
1367 value*=pow(2.0,e/0.3);
1377 if ((*q ==
'B') || (*q ==
'P'))
1380 if (sentinel != (
char **) NULL)
1411MagickExport MagickBooleanType IsStringTrue(
const char *value)
1413 if (value == (
const char *) NULL)
1414 return(MagickFalse);
1415 if (LocaleCompare(value,
"true") == 0)
1417 if (LocaleCompare(value,
"on") == 0)
1419 if (LocaleCompare(value,
"yes") == 0)
1421 if (LocaleCompare(value,
"1") == 0)
1423 return(MagickFalse);
1452MagickExport MagickBooleanType IsStringFalse(
const char *value)
1454 if (value == (
const char *) NULL)
1455 return(MagickFalse);
1456 if (LocaleCompare(value,
"false") == 0)
1458 if (LocaleCompare(value,
"off") == 0)
1460 if (LocaleCompare(value,
"no") == 0)
1462 if (LocaleCompare(value,
"0") == 0)
1464 return(MagickFalse);
1494MagickExport
void PrintStringInfo(FILE *file,
const char *
id,
1504 assert(
id != (
const char *) NULL);
1506 assert(string_info->signature == MagickCoreSignature);
1507 p=(
char *) string_info->datum;
1508 for (i=0; i < string_info->length; i++)
1510 if (((
int) ((
unsigned char) *p) < 32) &&
1511 (isspace((
int) ((
unsigned char) *p)) == 0))
1515 (void) FormatLocaleFile(file,
"%s(%.20g):\n",
id,(
double) string_info->length);
1516 if (i == string_info->length)
1518 for (i=0; i < string_info->length; i++)
1519 (
void) fputc(string_info->datum[i],file);
1520 (void) fputc(
'\n',file);
1526 p=(
char *) string_info->datum;
1527 for (i=0; i < string_info->length; i+=CharsPerLine)
1529 (void) FormatLocaleFile(file,
"0x%08lx: ",(
unsigned long) (CharsPerLine*i));
1530 for (j=1; j <= MagickMin(string_info->length-i,CharsPerLine); j++)
1532 (void) FormatLocaleFile(file,
"%02lx",(
unsigned long) (*(p+j)) & 0xff);
1533 if ((j % 0x04) == 0)
1534 (void) fputc(
' ',file);
1536 for ( ; j <= CharsPerLine; j++)
1538 (void) fputc(
' ',file);
1539 (void) fputc(
' ',file);
1540 if ((j % 0x04) == 0)
1541 (void) fputc(
' ',file);
1543 (void) fputc(
' ',file);
1544 for (j=1; j <= MagickMin(string_info->length-i,CharsPerLine); j++)
1546 if (isprint((
int) ((
unsigned char) *p)) != 0)
1547 (void) fputc(*p,file);
1549 (
void) fputc(
'-',file);
1552 (void) fputc(
'\n',file);
1578MagickExport
void ResetStringInfo(
StringInfo *string_info)
1581 assert(string_info->signature == MagickCoreSignature);
1582 (void) memset(string_info->datum,0,string_info->length);
1610MagickExport
char *SanitizeString(
const char *source)
1623 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
1624 "$-_.+!*'(),{}|\\^~[]`\"><#%;/?:@&=";
1626 sanitize_source=AcquireString(source);
1628 q=sanitize_source+strlen(sanitize_source);
1629 for (p+=strspn(p,allowlist); p != q; p+=strspn(p,allowlist))
1631 return(sanitize_source);
1658MagickExport
void SetStringInfo(
StringInfo *string_info,
1662 assert(string_info->signature == MagickCoreSignature);
1664 assert(source->signature == MagickCoreSignature);
1665 if (string_info->length == 0)
1667 (void) memset(string_info->datum,0,string_info->length);
1668 (void) memcpy(string_info->datum,source->datum,MagickMin(string_info->length,
1698MagickExport
void SetStringInfoDatum(
StringInfo *string_info,
1699 const unsigned char *source)
1702 assert(string_info->signature == MagickCoreSignature);
1703 if (string_info->length != 0)
1704 (void) memcpy(string_info->datum,source,string_info->length);
1731MagickExport
void SetStringInfoLength(
StringInfo *string_info,
1732 const size_t length)
1735 assert(string_info->signature == MagickCoreSignature);
1736 if (string_info->length == length)
1738 if (~length < MagickPathExtent)
1739 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
1740 string_info->length=length;
1741 if (string_info->datum == (
unsigned char *) NULL)
1742 string_info->datum=(
unsigned char *) AcquireQuantumMemory(length+
1743 MagickPathExtent,
sizeof(*string_info->datum));
1745 string_info->datum=(
unsigned char *) ResizeQuantumMemory(string_info->datum,
1746 length+MagickPathExtent,
sizeof(*string_info->datum));
1747 if (string_info->datum == (
unsigned char *) NULL)
1748 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
1775MagickExport
void SetStringInfoName(
StringInfo *string_info,
const char *name)
1778 assert(string_info->signature == MagickCoreSignature);
1779 assert(name != (
const char *) NULL);
1780 string_info->name=ConstantString(name);
1807MagickExport
void SetStringInfoPath(
StringInfo *string_info,
const char *path)
1810 assert(string_info->signature == MagickCoreSignature);
1811 assert(path != (
const char *) NULL);
1812 string_info->path=ConstantString(path);
1838 const size_t offset)
1844 assert(string_info->signature == MagickCoreSignature);
1845 if (offset > string_info->length)
1847 split_info=AcquireStringInfo(offset);
1848 SetStringInfo(split_info,string_info);
1849 (void) memmove(string_info->datum,string_info->datum+offset,
1850 string_info->length-offset+MagickPathExtent);
1851 SetStringInfoLength(string_info,string_info->length-offset);
1877MagickExport
char *StringInfoToDigest(
const StringInfo *signature)
1885 signature_info=AcquireSignatureInfo();
1886 UpdateSignature(signature_info,signature);
1887 FinalizeSignature(signature_info);
1888 digest=StringInfoToHexString(GetSignatureDigest(signature_info));
1889 signature_info=DestroySignatureInfo(signature_info);
1915MagickExport
char *StringInfoToHexString(
const StringInfo *string_info)
1935 length=string_info->length;
1936 if (~length < MagickPathExtent)
1937 ThrowFatalException(ResourceLimitFatalError,
"UnableToAcquireString");
1938 string=(
char *) AcquireQuantumMemory(length+MagickPathExtent,2*
1940 if (
string == (
char *) NULL)
1941 ThrowFatalException(ResourceLimitFatalError,
"UnableToAcquireString");
1958 p=string_info->datum;
1959 q=(
unsigned char *)
string;
1960 for (i=0; i < (ssize_t) string_info->length; i++)
1962 *q++=hex_digits[(*p >> 4) & 0x0f];
1963 *q++=hex_digits[*p & 0x0f];
1992MagickExport
char *StringInfoToString(
const StringInfo *string_info)
2000 string=(
char *) NULL;
2001 length=string_info->length;
2002 if (~length >= (MagickPathExtent-1))
2003 string=(
char *) AcquireQuantumMemory(length+MagickPathExtent,
2005 if (
string == (
char *) NULL)
2006 return((
char *) NULL);
2007 (void) memcpy(
string,(
char *) string_info->datum,length*
sizeof(*
string));
2008 string[length]=
'\0';
2046MagickExport
char **StringToArgv(
const char *text,
int *argc)
2059 if (text == (
char *) NULL)
2060 return((
char **) NULL);
2064 for (p=text; *p !=
'\0'; )
2066 while (isspace((
int) ((
unsigned char) *p)) != 0)
2072 for (p++; (*p !=
'"') && (*p !=
'\0'); p++) ;
2074 for (p++; (*p !=
'\'') && (*p !=
'\0'); p++) ;
2075 while ((isspace((
int) ((
unsigned char) *p)) == 0) && (*p !=
'\0'))
2079 argv=(
char **) AcquireQuantumMemory((
size_t) *argc+1UL,
sizeof(*argv));
2080 if (argv == (
char **) NULL)
2081 ThrowFatalException(ResourceLimitFatalError,
"UnableToConvertStringToARGV");
2085 argv[0]=AcquireString(
"magick");
2087 for (i=1; i < (ssize_t) *argc; i++)
2089 while (isspace((
int) ((
unsigned char) *p)) != 0)
2095 for (q++; (*q !=
'"') && (*q !=
'\0'); q++) ;
2101 for (q++; (*q !=
'\'') && (*q !=
'\0'); q++) ;
2104 while ((isspace((
int) ((
unsigned char) *q)) == 0) && (*q !=
'\0'))
2106 argv[i]=(
char *) AcquireQuantumMemory((
size_t) (q-p)+MagickPathExtent,
2108 if (argv[i] == (
char *) NULL)
2110 for (i--; i >= 0; i--)
2111 argv[i]=DestroyString(argv[i]);
2112 argv=(
char **) RelinquishMagickMemory(argv);
2113 ThrowFatalException(ResourceLimitFatalError,
2114 "UnableToConvertStringToARGV");
2116 (void) memcpy(argv[i],p,(
size_t) (q-p));
2119 while ((isspace((
int) ((
unsigned char) *p)) == 0) && (*p !=
'\0'))
2122 argv[i]=(
char *) NULL;
2161MagickExport
double *StringToArrayOfDoubles(
const char *
string,ssize_t *count,
2180 assert(exception->signature == MagickCoreSignature);
2182 if (
string == (
char *) NULL)
2183 return((
double *) NULL);
2188 (void) StringToDouble(p,&q);
2190 return((
double *) NULL);
2193 while (isspace((
int) ((
unsigned char) *p)) != 0)
2197 while (isspace((
int) ((
unsigned char) *p)) != 0)
2204 array=(
double *) AcquireQuantumMemory((
size_t) i,
sizeof(*array));
2205 if (array == (
double *) NULL)
2207 (void) ThrowMagickException(exception,GetMagickModule(),
2208 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
2209 return((
double *) NULL);
2216 while ((*p !=
'\0') && (i < *count))
2218 array[i++]=StringToDouble(p,&q);
2220 while ((isspace((
int) ((
unsigned char) *p)) != 0) || (*p ==
','))
2260MagickExport
char *StringToken(
const char *delimiters,
char **
string)
2276 if (p == (
char *) NULL)
2277 return((
char *) NULL);
2295 }
while (d !=
'\0');
2323MagickExport
char **StringToList(
const char *text)
2325 return(StringToStrings(text,(
size_t *) NULL));
2354MagickExport
char **StringToStrings(
const char *text,
size_t *count)
2368 if (text == (
char *) NULL)
2370 if (count != (
size_t *) NULL)
2372 return((
char **) NULL);
2374 for (p=text; *p !=
'\0'; p++)
2375 if (((
int) ((
unsigned char) *p) < 32) &&
2376 (isspace((
int) ((
unsigned char) *p)) == 0))
2387 for (p=text; *p !=
'\0'; p++)
2390 textlist=(
char **) AcquireQuantumMemory((
size_t) lines+1UL,
2392 if (textlist == (
char **) NULL)
2393 ThrowFatalException(ResourceLimitFatalError,
"UnableToConvertText");
2395 for (i=0; i < (ssize_t) lines; i++)
2397 for (q=p; *q !=
'\0'; q++)
2398 if ((*q ==
'\r') || (*q ==
'\n'))
2400 textlist[i]=(
char *) AcquireQuantumMemory((
size_t) (q-p)+1,
2401 sizeof(**textlist));
2402 if (textlist[i] == (
char *) NULL)
2403 ThrowFatalException(ResourceLimitFatalError,
"UnableToConvertText");
2404 (void) memcpy(textlist[i],p,(
size_t) (q-p));
2405 textlist[i][q-p]=
'\0';
2414 hex_string[MagickPathExtent];
2425 lines=(size_t) (strlen(text)/CharsPerLine)+1;
2426 textlist=(
char **) AcquireQuantumMemory((
size_t) lines+1UL,
2428 if (textlist == (
char **) NULL)
2429 ThrowFatalException(ResourceLimitFatalError,
"UnableToConvertText");
2431 for (i=0; i < (ssize_t) lines; i++)
2436 textlist[i]=(
char *) AcquireQuantumMemory(2UL*MagickPathExtent,
2437 sizeof(**textlist));
2438 if (textlist[i] == (
char *) NULL)
2439 ThrowFatalException(ResourceLimitFatalError,
"UnableToConvertText");
2440 (void) FormatLocaleString(textlist[i],MagickPathExtent,
"0x%08lx: ",
2441 (
long) (CharsPerLine*i));
2442 q=textlist[i]+strlen(textlist[i]);
2444 for (j=1; j <= (ssize_t) MagickMin(length,CharsPerLine); j++)
2446 (void) FormatLocaleString(hex_string,MagickPathExtent,
"%02x",*(p+j));
2447 (void) CopyMagickString(q,hex_string,MagickPathExtent);
2449 if ((j % 0x04) == 0)
2452 for ( ; j <= CharsPerLine; j++)
2456 if ((j % 0x04) == 0)
2460 for (j=1; j <= (ssize_t) MagickMin(length,CharsPerLine); j++)
2462 if (isprint((
int) ((
unsigned char) *p)) != 0)
2469 textlist[i]=(
char *) ResizeQuantumMemory(textlist[i],(
size_t) (q-
2470 textlist[i]+1),
sizeof(**textlist));
2471 if (textlist[i] == (
char *) NULL)
2472 ThrowFatalException(ResourceLimitFatalError,
"UnableToConvertText");
2475 if (count != (
size_t *) NULL)
2477 textlist[i]=(
char *) NULL;
2503MagickExport
StringInfo *StringToStringInfo(
const char *
string)
2508 assert(
string != (
const char *) NULL);
2509 string_info=AcquireStringInfo(strlen(
string));
2510 SetStringInfoDatum(string_info,(
const unsigned char *)
string);
2511 return(string_info);
2538MagickExport
void StripString(
char *message)
2540 (void) StripMagickString(message);
2543MagickExport
size_t StripMagickString(
char *message)
2552 assert(message != (
char *) NULL);
2553 if (*message ==
'\0')
2555 length=strlen(message);
2559 while (isspace((
int) ((
unsigned char) *p)) != 0)
2561 if ((*p ==
'\'') || (*p ==
'"'))
2564 while ((isspace((
int) ((
unsigned char) *q)) != 0) && (q > p))
2567 if ((*q ==
'\'') || (*q ==
'"'))
2569 (void) memmove(message,p,(
size_t) (q-p+1));
2570 message[q-p+1]=
'\0';
2571 for (p=message; *p !=
'\0'; p++)
2574 return((
size_t) (q-p+1));
2608MagickExport MagickBooleanType SubstituteString(
char **
string,
2609 const char *search,
const char *replace)
2628 for (p=strchr(*
string,*search); p != (
char *) NULL; p=strchr(p+1,*search))
2630 if (search_extent == 0)
2631 search_extent=strlen(search);
2632 if (strncmp(p,search,search_extent) != 0)
2638 if (replace_extent == 0)
2639 replace_extent=strlen(replace);
2640 if (replace_extent > search_extent)
2645 offset=(ssize_t) (p-(*
string));
2646 extent=strlen(*
string)+replace_extent-search_extent+1;
2647 *
string=(
char *) ResizeQuantumMemory(*
string,
2648 OverAllocateMemory(extent+MagickPathExtent),
sizeof(*p));
2649 if (*
string == (
char *) NULL)
2650 ThrowFatalException(ResourceLimitFatalError,
"UnableToAcquireString");
2656 if (search_extent != replace_extent)
2657 (void) memmove(p+replace_extent,p+search_extent,
2658 strlen(p+search_extent)+1);
2659 (void) memcpy(p,replace,replace_extent);
2660 p+=replace_extent-1;