00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "magick/studio.h"
00043 #include "magick/blob.h"
00044 #include "magick/blob-private.h"
00045 #include "magick/exception.h"
00046 #include "magick/exception-private.h"
00047 #include "magick/list.h"
00048 #include "magick/log.h"
00049 #include "magick/memory_.h"
00050 #include "magick/property.h"
00051 #include "magick/resource_.h"
00052 #include "magick/signature-private.h"
00053 #include "magick/string_.h"
00054
00055
00056
00057
00058 #if !defined(MAGICKCORE_HAVE_STRCASECMP) || !defined(MAGICKCORE_HAVE_STRNCASECMP)
00059 static const unsigned char
00060 AsciiMap[] =
00061 {
00062 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
00063 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
00064 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
00065 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
00066 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
00067 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
00068 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
00069 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
00070 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
00071 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
00072 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
00073 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
00074 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
00075 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
00076 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
00077 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
00078 0xc0, 0xe1, 0xe2, 0xe3, 0xe4, 0xc5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,
00079 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
00080 0xf8, 0xf9, 0xfa, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
00081 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
00082 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
00083 0xfc, 0xfd, 0xfe, 0xff,
00084 };
00085 #endif
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 MagickExport char *AcquireString(const char *source)
00111 {
00112 char
00113 *destination;
00114
00115 size_t
00116 length;
00117
00118 length=0;
00119 if (source != (char *) NULL)
00120 length+=strlen(source);
00121 destination=(char *) NULL;
00122 if (~length >= MaxTextExtent)
00123 destination=(char *) AcquireQuantumMemory(length+MaxTextExtent,
00124 sizeof(*destination));
00125 if (destination == (char *) NULL)
00126 ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
00127 *destination='\0';
00128 if (source != (char *) NULL)
00129 (void) CopyMagickString(destination,source,(length+1)*sizeof(*destination));
00130 return(destination);
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 MagickExport StringInfo *AcquireStringInfo(const size_t length)
00156 {
00157 StringInfo
00158 *string_info;
00159
00160 string_info=(StringInfo *) AcquireMagickMemory(sizeof(*string_info));
00161 if (string_info == (StringInfo *) NULL)
00162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
00163 (void) ResetMagickMemory(string_info,0,sizeof(*string_info));
00164 string_info->signature=MagickSignature;
00165 string_info->length=length;
00166 if (string_info->length != 0)
00167 {
00168 string_info->datum=(unsigned char *) NULL;
00169 if (~string_info->length >= MaxTextExtent)
00170 string_info->datum=(unsigned char *) AcquireQuantumMemory(
00171 string_info->length+MaxTextExtent,sizeof(*string_info->datum));
00172 if (string_info->datum == (unsigned char *) NULL)
00173 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
00174 }
00175 return(string_info);
00176 }
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 MagickExport char *CloneString(char **destination,const char *source)
00204 {
00205 size_t
00206 length;
00207
00208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00209 assert(destination != (char **) NULL);
00210 if (source == (const char *) NULL)
00211 {
00212 if (*destination != (char *) NULL)
00213 *destination=DestroyString(*destination);
00214 return(*destination);
00215 }
00216 if (*destination == (char *) NULL)
00217 {
00218 *destination=AcquireString(source);
00219 return(*destination);
00220 }
00221 length=strlen(source);
00222 if (~length < MaxTextExtent)
00223 ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
00224 *destination=(char *) ResizeQuantumMemory(*destination,length+MaxTextExtent,
00225 sizeof(*destination));
00226 if (*destination == (char *) NULL)
00227 ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
00228 (void) CopyMagickString(*destination,source,(length+1)*sizeof(*destination));
00229 return(*destination);
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 MagickExport StringInfo *CloneStringInfo(const StringInfo *string_info)
00255 {
00256 StringInfo
00257 *clone_info;
00258
00259 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00260 assert(string_info != (StringInfo *) NULL);
00261 assert(string_info->signature == MagickSignature);
00262 clone_info=AcquireStringInfo(string_info->length);
00263 if (string_info->length != 0)
00264 (void) CopyMagickMemory(clone_info->datum,string_info->datum,
00265 string_info->length+1);
00266 return(clone_info);
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 static inline size_t MagickMin(const size_t x,const size_t y)
00297 {
00298 if (x < y)
00299 return(x);
00300 return(y);
00301 }
00302
00303 MagickExport int CompareStringInfo(const StringInfo *target,
00304 const StringInfo *source)
00305 {
00306 int
00307 status;
00308
00309 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00310 assert(target != (StringInfo *) NULL);
00311 assert(target->signature == MagickSignature);
00312 assert(source != (StringInfo *) NULL);
00313 assert(source->signature == MagickSignature);
00314 status=memcmp(target->datum,source->datum,MagickMin(target->length,
00315 source->length));
00316 if (status != 0)
00317 return(status);
00318 if (target->length == source->length)
00319 return(0);
00320 return(target->length < source->length ? -1 : 1);
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 MagickExport size_t ConcatenateMagickString(char *destination,
00353 const char *source,const size_t length)
00354 {
00355 register char
00356 *q;
00357
00358 register const char
00359 *p;
00360
00361 register size_t
00362 i;
00363
00364 size_t
00365 count;
00366
00367 assert(destination != (char *) NULL);
00368 assert(source != (const char *) NULL);
00369 assert(length >= 1);
00370 p=source;
00371 q=destination;
00372 i=length;
00373 while ((i-- != 0) && (*q != '\0'))
00374 q++;
00375 count=(size_t) (q-destination);
00376 i=length-count;
00377 if (i == 0)
00378 return(count+strlen(p));
00379 while (*p != '\0')
00380 {
00381 if (i != 1)
00382 {
00383 *q++=(*p);
00384 i--;
00385 }
00386 p++;
00387 }
00388 *q='\0';
00389 return(count+(p-source));
00390 }
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418 MagickExport MagickBooleanType ConcatenateString(char **destination,
00419 const char *source)
00420 {
00421 size_t
00422 length,
00423 source_length;
00424
00425 assert(destination != (char **) NULL);
00426 if (source == (const char *) NULL)
00427 return(MagickTrue);
00428 if (*destination == (char *) NULL)
00429 {
00430 *destination=AcquireString(source);
00431 return(MagickTrue);
00432 }
00433 length=strlen(*destination);
00434 source_length=strlen(source);
00435 if (~length < source_length)
00436 ThrowFatalException(ResourceLimitFatalError,"UnableToConcatenateString");
00437 length+=source_length;
00438 if (~length < MaxTextExtent)
00439 ThrowFatalException(ResourceLimitFatalError,"UnableToConcatenateString");
00440 *destination=(char *) ResizeQuantumMemory(*destination,length+MaxTextExtent,
00441 sizeof(*destination));
00442 if (*destination == (char *) NULL)
00443 ThrowFatalException(ResourceLimitFatalError,"UnableToConcatenateString");
00444 (void) ConcatenateMagickString(*destination,source,(length+1)*
00445 sizeof(*destination));
00446 return(MagickTrue);
00447 }
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 MagickExport void ConcatenateStringInfo(StringInfo *string_info,
00476 const StringInfo *source)
00477 {
00478 size_t
00479 length;
00480
00481 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00482 assert(string_info != (StringInfo *) NULL);
00483 assert(string_info->signature == MagickSignature);
00484 assert(source != (const StringInfo *) NULL);
00485 length=string_info->length;
00486 if (~length < source->length)
00487 ThrowFatalException(ResourceLimitFatalError,"UnableToConcatenateString");
00488 SetStringInfoLength(string_info,length+source->length);
00489 (void) CopyMagickMemory(string_info->datum+length,source->datum,
00490 source->length);
00491 }
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517 MagickExport StringInfo *ConfigureFileToStringInfo(const char *filename)
00518 {
00519 char
00520 *string;
00521
00522 int
00523 file;
00524
00525 MagickOffsetType
00526 offset;
00527
00528 size_t
00529 length;
00530
00531 StringInfo
00532 *string_info;
00533
00534 void
00535 *map;
00536
00537 assert(filename != (const char *) NULL);
00538 file=open(filename,O_RDONLY | O_BINARY);
00539 if (file == -1)
00540 return((StringInfo *) NULL);
00541 offset=(MagickOffsetType) MagickSeek(file,0,SEEK_END);
00542 if ((offset < 0) || (offset != (MagickOffsetType) ((ssize_t) offset)))
00543 {
00544 file=close(file)-1;
00545 return((StringInfo *) NULL);
00546 }
00547 length=(size_t) offset;
00548 string=(char *) NULL;
00549 if (~length > MaxTextExtent)
00550 string=(char *) AcquireQuantumMemory(length+MaxTextExtent,sizeof(*string));
00551 if (string == (char *) NULL)
00552 {
00553 file=close(file)-1;
00554 return((StringInfo *) NULL);
00555 }
00556 map=MapBlob(file,ReadMode,0,length);
00557 if (map != (void *) NULL)
00558 {
00559 (void) CopyMagickMemory(string,map,length);
00560 (void) UnmapBlob(map,length);
00561 }
00562 else
00563 {
00564 register size_t
00565 i;
00566
00567 ssize_t
00568 count;
00569
00570 (void) MagickSeek(file,0,SEEK_SET);
00571 for (i=0; i < length; i+=count)
00572 {
00573 count=read(file,string+i,(size_t) MagickMin(length-i,(size_t)
00574 SSIZE_MAX));
00575 if (count <= 0)
00576 {
00577 count=0;
00578 if (errno != EINTR)
00579 break;
00580 }
00581 }
00582 if (i < length)
00583 {
00584 file=close(file)-1;
00585 string=DestroyString(string);
00586 return((StringInfo *) NULL);
00587 }
00588 }
00589 string[length]='\0';
00590 file=close(file)-1;
00591 string_info=AcquireStringInfo(0);
00592 (void) CopyMagickString(string_info->path,filename,MaxTextExtent);
00593 string_info->length=length;
00594 string_info->datum=(unsigned char *) string;
00595 return(string_info);
00596 }
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622 MagickExport char *ConstantString(const char *source)
00623 {
00624 char
00625 *destination;
00626
00627 size_t
00628 length;
00629
00630 length=0;
00631 if (source != (char *) NULL)
00632 length+=strlen(source);
00633 destination=(char *) NULL;
00634 if (~length >= 1UL)
00635 destination=(char *) AcquireQuantumMemory(length+1UL,sizeof(*destination));
00636 if (destination == (char *) NULL)
00637 ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
00638 *destination='\0';
00639 if (source != (char *) NULL)
00640 (void) CopyMagickString(destination,source,(length+1)*sizeof(*destination));
00641 return(destination);
00642 }
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674 MagickExport size_t CopyMagickString(char *destination,const char *source,
00675 const size_t length)
00676 {
00677 register char
00678 *q;
00679
00680 register const char
00681 *p;
00682
00683 register size_t
00684 n;
00685
00686 p=source;
00687 q=destination;
00688 for (n=length; n > 4; n-=4)
00689 {
00690 *q=(*p++);
00691 if (*q == '\0')
00692 return((size_t) (p-source-1));
00693 q++;
00694 *q=(*p++);
00695 if (*q == '\0')
00696 return((size_t) (p-source-1));
00697 q++;
00698 *q=(*p++);
00699 if (*q == '\0')
00700 return((size_t) (p-source-1));
00701 q++;
00702 *q=(*p++);
00703 if (*q == '\0')
00704 return((size_t) (p-source-1));
00705 q++;
00706 }
00707 if (n != 0)
00708 for (n--; n != 0; n--)
00709 {
00710 *q=(*p++);
00711 if (*q == '\0')
00712 return((size_t) (p-source-1));
00713 q++;
00714 }
00715 if (length != 0)
00716 *q='\0';
00717 return((size_t) (p-source-1));
00718 }
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742 MagickExport char *DestroyString(char *string)
00743 {
00744 return((char *) RelinquishMagickMemory(string));
00745 }
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769 MagickExport StringInfo *DestroyStringInfo(StringInfo *string_info)
00770 {
00771 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00772 assert(string_info != (StringInfo *) NULL);
00773 assert(string_info->signature == MagickSignature);
00774 if (string_info->datum != (unsigned char *) NULL)
00775 string_info->datum=(unsigned char *) RelinquishMagickMemory(
00776 string_info->datum);
00777 string_info->signature=(~MagickSignature);
00778 string_info=(StringInfo *) RelinquishMagickMemory(string_info);
00779 return(string_info);
00780 }
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804 MagickExport char **DestroyStringList(char **list)
00805 {
00806 register long
00807 i;
00808
00809 assert(list != (char **) NULL);
00810 for (i=0; list[i] != (char *) NULL; i++)
00811 list[i]=DestroyString(list[i]);
00812 list=(char **) RelinquishMagickMemory(list);
00813 return(list);
00814 }
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845 MagickExport char *EscapeString(const char *source,const char escape)
00846 {
00847 char
00848 *destination;
00849
00850 register char
00851 *q;
00852
00853 register const char
00854 *p;
00855
00856 size_t
00857 length;
00858
00859 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00860 assert(source != (const char *) NULL);
00861 length=strlen(source);
00862 for (p=source; *p != '\0'; p++)
00863 if ((*p == '\\') || (*p == escape))
00864 {
00865 if (~length < 1)
00866 ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
00867 length++;
00868 }
00869 destination=(char *) NULL;
00870 if (~length >= MaxTextExtent)
00871 destination=(char *) AcquireQuantumMemory(length+MaxTextExtent,
00872 sizeof(*destination));
00873 if (destination == (char *) NULL)
00874 ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
00875 *destination='\0';
00876 if (source != (char *) NULL)
00877 {
00878 q=destination;
00879 for (p=source; *p != '\0'; p++)
00880 {
00881 if ((*p == '\\') || (*p == escape))
00882 *q++='\\';
00883 *q++=(*p);
00884 }
00885 *q='\0';
00886 }
00887 return(destination);
00888 }
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917 MagickExport char *FileToString(const char *filename,const size_t extent,
00918 ExceptionInfo *exception)
00919 {
00920 size_t
00921 length;
00922
00923 assert(filename != (const char *) NULL);
00924 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
00925 assert(exception != (ExceptionInfo *) NULL);
00926 return((char *) FileToBlob(filename,extent,&length,exception));
00927 }
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956 MagickExport StringInfo *FileToStringInfo(const char *filename,
00957 const size_t extent,ExceptionInfo *exception)
00958 {
00959 StringInfo
00960 *string_info;
00961
00962 assert(filename != (const char *) NULL);
00963 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
00964 assert(exception != (ExceptionInfo *) NULL);
00965 string_info=AcquireStringInfo(0);
00966 (void) CopyMagickString(string_info->path,filename,MaxTextExtent);
00967 string_info->datum=FileToBlob(filename,extent,&string_info->length,exception);
00968 if (string_info->datum == (unsigned char *) NULL)
00969 {
00970 string_info=DestroyStringInfo(string_info);
00971 return((StringInfo *) NULL);
00972 }
00973 return(string_info);
00974 }
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002 MagickExport long FormatMagickSize(const MagickSizeType size,char *format)
01003 {
01004 double
01005 length;
01006
01007 long
01008 count;
01009
01010 register long
01011 i,
01012 j;
01013
01014 static const char
01015 *units[] =
01016 {
01017 "b", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", (char *) NULL
01018 };
01019
01020 #if defined(_MSC_VER) && (_MSC_VER == 1200)
01021 length=(double) ((MagickOffsetType) size);
01022 #else
01023 length=(double) size;
01024 #endif
01025 for (i=0; (length >= 1024.0) && (units[i+1] != (const char *) NULL); i++)
01026 length/=1024.0;
01027 for (j=2; j < 12; j++)
01028 {
01029 count=FormatMagickString(format,MaxTextExtent,"%.*g%s",(int) (i+j),length,
01030 units[i]);
01031 if (strchr(format,'+') == (char *) NULL)
01032 break;
01033 }
01034 return(count);
01035 }
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067 MagickExport long FormatMagickStringList(char *string,const size_t length,
01068 const char *format,va_list operands)
01069 {
01070 int
01071 n;
01072
01073 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
01074 n=vsnprintf(string,length,format,operands);
01075 #else
01076 n=vsprintf(string,format,operands);
01077 #endif
01078 if (n < 0)
01079 string[length-1]='\0';
01080 return((long) n);
01081 }
01082
01083 MagickExport long FormatMagickString(char *string,const size_t length,
01084 const char *format,...)
01085 {
01086 long
01087 n;
01088
01089 va_list
01090 operands;
01091
01092 va_start(operands,format);
01093 n=(long) FormatMagickStringList(string,length,format,operands);
01094 va_end(operands);
01095 return(n);
01096 }
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127 MagickExport long FormatMagickTime(const time_t time,const size_t length,
01128 char *timestamp)
01129 {
01130 long
01131 count;
01132
01133 struct tm
01134 gm_time,
01135 local_time;
01136
01137 time_t
01138 timezone;
01139
01140 assert(timestamp != (char *) NULL);
01141 (void) ResetMagickMemory(&local_time,0,sizeof(local_time));
01142 (void) ResetMagickMemory(&gm_time,0,sizeof(gm_time));
01143 #if defined(MAGICKCORE_HAVE_LOCALTIME_R)
01144 (void) localtime_r(&time,&local_time);
01145 #else
01146 {
01147 struct tm
01148 *my_time;
01149
01150 my_time=localtime(&time);
01151 if (my_time != (struct tm *) NULL)
01152 (void) memcpy(&local_time,my_time,sizeof(local_time));
01153 }
01154 #endif
01155 #if defined(MAGICKCORE_HAVE_GMTIME_R)
01156 (void) gmtime_r(&time,&gm_time);
01157 #else
01158 {
01159 struct tm
01160 *my_time;
01161
01162 my_time=gmtime(&time);
01163 if (my_time != (struct tm *) NULL)
01164 (void) memcpy(&gm_time,my_time,sizeof(gm_time));
01165 }
01166 #endif
01167 timezone=(time_t) ((local_time.tm_min-gm_time.tm_min)/60+
01168 local_time.tm_hour-gm_time.tm_hour+24*((local_time.tm_year-
01169 gm_time.tm_year) != 0 ? (local_time.tm_year-gm_time.tm_year) :
01170 (local_time.tm_yday-gm_time.tm_yday)));
01171 count=FormatMagickString(timestamp,length,
01172 "%04d-%02d-%02dT%02d:%02d:%02d%+03ld:00",local_time.tm_year+1900,
01173 local_time.tm_mon+1,local_time.tm_mday,local_time.tm_hour,
01174 local_time.tm_min,local_time.tm_sec,(long) timezone);
01175 return(count);
01176 }
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201 MagickExport char *GetEnvironmentValue(const char *name)
01202 {
01203 const char
01204 *environment;
01205
01206 environment=getenv(name);
01207 if (environment == (const char *) NULL)
01208 return((char *) NULL);
01209 return(ConstantString(environment));
01210 }
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234 MagickExport unsigned char *GetStringInfoDatum(const StringInfo *string_info)
01235 {
01236 assert(string_info != (StringInfo *) NULL);
01237 assert(string_info->signature == MagickSignature);
01238 return(string_info->datum);
01239 }
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263 MagickExport size_t GetStringInfoLength(const StringInfo *string_info)
01264 {
01265 assert(string_info != (StringInfo *) NULL);
01266 assert(string_info->signature == MagickSignature);
01267 return(string_info->length);
01268 }
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292 MagickExport const char *GetStringInfoPath(const StringInfo *string_info)
01293 {
01294 assert(string_info != (StringInfo *) NULL);
01295 assert(string_info->signature == MagickSignature);
01296 return(string_info->path);
01297 }
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328 MagickExport long LocaleCompare(const char *p,const char *q)
01329 {
01330 if ((p == (char *) NULL) && (q == (char *) NULL))
01331 return(0);
01332 if (p == (char *) NULL)
01333 return(-1);
01334 if (q == (char *) NULL)
01335 return(1);
01336 #if defined(MAGICKCORE_HAVE_STRCASECMP)
01337 return((long) strcasecmp(p,q));
01338 #else
01339 {
01340 register int
01341 c,
01342 d,
01343 i;
01344
01345 for (i=0; ; i++)
01346 {
01347 c=(int) p[i];
01348 d=(int) q[i];
01349 if ((c == '\0') || (AsciiMap[c] != AsciiMap[d]))
01350 break;
01351 }
01352 return((long) AsciiMap[c]-AsciiMap[d]);
01353 }
01354 #endif
01355 }
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380 MagickExport void LocaleLower(char *string)
01381 {
01382 register char
01383 *q;
01384
01385 assert(string != (char *) NULL);
01386 for (q=string; *q != '\0'; q++)
01387 *q=(char) tolower((int) *q);
01388 }
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425 MagickExport long LocaleNCompare(const char *p,const char *q,
01426 const size_t length)
01427 {
01428 if (p == (char *) NULL)
01429 return(-1);
01430 if (q == (char *) NULL)
01431 return(1);
01432 #if defined(MAGICKCORE_HAVE_STRNCASECMP)
01433 return((long) strncasecmp(p,q,length));
01434 #else
01435 {
01436 register int
01437 c,
01438 d;
01439
01440 register size_t
01441 n;
01442
01443 for (n=length; n != 0; n--)
01444 {
01445 c=(int) *p;
01446 d=(int) *q;
01447 if (AsciiMap[c] != AsciiMap[d])
01448 return(AsciiMap[c]-AsciiMap[d]);
01449 if (c == '\0')
01450 return(0L);
01451 p++;
01452 q++;
01453 }
01454 return(0L);
01455 }
01456 #endif
01457 }
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482 MagickExport void LocaleUpper(char *string)
01483 {
01484 register char
01485 *q;
01486
01487 assert(string != (char *) NULL);
01488 for (q=string; *q != '\0'; q++)
01489 *q=(char) toupper((int) *q);
01490 }
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519 MagickExport void PrintStringInfo(FILE *file,const char *id,
01520 const StringInfo *string_info)
01521 {
01522 register const char
01523 *p;
01524
01525 register size_t
01526 i,
01527 j;
01528
01529 assert(id != (const char *) NULL);
01530 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",id);
01531 assert(string_info != (StringInfo *) NULL);
01532 assert(string_info->signature == MagickSignature);
01533 p=(char *) string_info->datum;
01534 for (i=0; i < string_info->length; i++)
01535 {
01536 if (((int) ((unsigned char) *p) < 32) &&
01537 (isspace((int) ((unsigned char) *p)) == 0))
01538 break;
01539 p++;
01540 }
01541 if (i == string_info->length)
01542 {
01543 (void) fputs((char *) string_info->datum,file);
01544 (void) fputc('\n',file);
01545 return;
01546 }
01547
01548
01549
01550 p=(char *) string_info->datum;
01551 for (i=0; i < string_info->length; i+=0x14)
01552 {
01553 (void) fprintf(file,"0x%08lx: ",(unsigned long) (0x14*i));
01554 for (j=1; j <= MagickMin(string_info->length-i,0x14); j++)
01555 {
01556 (void) fprintf(file,"%02lx",(unsigned long) (*(p+j)) & 0xff);
01557 if ((j % 0x04) == 0)
01558 (void) fputc(' ',file);
01559 }
01560 for ( ; j <= 0x14; j++)
01561 {
01562 (void) fputc(' ',file);
01563 (void) fputc(' ',file);
01564 if ((j % 0x04) == 0)
01565 (void) fputc(' ',file);
01566 }
01567 (void) fputc(' ',file);
01568 for (j=1; j <= MagickMin(string_info->length-i,0x14); j++)
01569 {
01570 if (isprint((int) ((unsigned char) *p)) != 0)
01571 (void) fputc(*p,file);
01572 else
01573 (void) fputc('-',file);
01574 p++;
01575 }
01576 (void) fputc('\n',file);
01577 }
01578 }
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602 MagickExport void ResetStringInfo(StringInfo *string_info)
01603 {
01604 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
01605 assert(string_info != (StringInfo *) NULL);
01606 assert(string_info->signature == MagickSignature);
01607 (void) ResetMagickMemory(string_info->datum,0,string_info->length);
01608 }
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634 MagickExport void SetStringInfo(StringInfo *string_info,
01635 const StringInfo *source)
01636 {
01637 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
01638 assert(string_info != (StringInfo *) NULL);
01639 assert(string_info->signature == MagickSignature);
01640 assert(source != (StringInfo *) NULL);
01641 assert(source->signature == MagickSignature);
01642 if (string_info->length == 0)
01643 return;
01644 (void) ResetMagickMemory(string_info->datum,0,string_info->length);
01645 (void) CopyMagickMemory(string_info->datum,source->datum,MagickMin(
01646 string_info->length,source->length));
01647 }
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675 MagickExport void SetStringInfoDatum(StringInfo *string_info,
01676 const unsigned char *source)
01677 {
01678 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
01679 assert(string_info != (StringInfo *) NULL);
01680 assert(string_info->signature == MagickSignature);
01681 if (string_info->length != 0)
01682 (void) CopyMagickMemory(string_info->datum,source,string_info->length);
01683 }
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709 MagickExport void SetStringInfoLength(StringInfo *string_info,
01710 const size_t length)
01711 {
01712 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
01713 assert(string_info != (StringInfo *) NULL);
01714 assert(string_info->signature == MagickSignature);
01715 if (~length < MaxTextExtent)
01716 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
01717 string_info->length=length;
01718 if (string_info->datum == (unsigned char *) NULL)
01719 string_info->datum=(unsigned char *) AcquireQuantumMemory(length+
01720 MaxTextExtent,sizeof(*string_info->datum));
01721 else
01722 string_info->datum=(unsigned char *) ResizeQuantumMemory(string_info->datum,
01723 length+MaxTextExtent,sizeof(*string_info->datum));
01724 if (string_info->datum == (unsigned char *) NULL)
01725 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
01726 }
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752 MagickExport void SetStringInfoPath(StringInfo *string_info,const char *path)
01753 {
01754 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
01755 assert(string_info != (StringInfo *) NULL);
01756 assert(string_info->signature == MagickSignature);
01757 assert(path != (const char *) NULL);
01758 (void) CopyMagickString(string_info->path,path,MaxTextExtent);
01759 }
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783 MagickExport StringInfo *SplitStringInfo(StringInfo *string_info,
01784 const size_t offset)
01785 {
01786 StringInfo
01787 *split_info;
01788
01789 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
01790 assert(string_info != (StringInfo *) NULL);
01791 assert(string_info->signature == MagickSignature);
01792 if (offset > string_info->length)
01793 return((StringInfo *) NULL);
01794 split_info=AcquireStringInfo(offset);
01795 SetStringInfo(split_info,string_info);
01796 (void) CopyMagickMemory(string_info->datum,string_info->datum+offset,
01797 string_info->length-offset+MaxTextExtent);
01798 SetStringInfoLength(string_info,string_info->length-offset);
01799 return(split_info);
01800 }
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824 MagickExport char *StringInfoToString(const StringInfo *string_info)
01825 {
01826 char
01827 *string;
01828
01829 size_t
01830 length;
01831
01832 string=(char *) NULL;
01833 length=string_info->length;
01834 if (~length >= MaxTextExtent)
01835 string=(char *) AcquireQuantumMemory(length+MaxTextExtent,sizeof(*string));
01836 if (string != (char *) NULL)
01837 (void) CopyMagickString(string,(char *) string_info->datum,
01838 (length+1)*sizeof(*string));
01839 return(string);
01840 }
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870 MagickExport char **StringToArgv(const char *text,int *argc)
01871 {
01872 char
01873 **argv;
01874
01875 register const char
01876 *p,
01877 *q;
01878
01879 register long
01880 i;
01881
01882 *argc=0;
01883 if (text == (char *) NULL)
01884 return((char **) NULL);
01885
01886
01887
01888 for (p=text; *p != '\0'; )
01889 {
01890 while (isspace((int) ((unsigned char) *p)) != 0)
01891 p++;
01892 (*argc)++;
01893 if (*p == '"')
01894 for (p++; (*p != '"') && (*p != '\0'); p++) ;
01895 if (*p == '\'')
01896 for (p++; (*p != '\'') && (*p != '\0'); p++) ;
01897 while ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '\0'))
01898 p++;
01899 }
01900 (*argc)++;
01901 argv=(char **) AcquireQuantumMemory((size_t) (*argc+1UL),sizeof(*argv));
01902 if (argv == (char **) NULL)
01903 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertStringToARGV");
01904
01905
01906
01907 argv[0]=AcquireString("magick");
01908 p=text;
01909 for (i=1; i < (long) *argc; i++)
01910 {
01911 while (isspace((int) ((unsigned char) *p)) != 0)
01912 p++;
01913 q=p;
01914 if (*q == '"')
01915 {
01916 p++;
01917 for (q++; (*q != '"') && (*q != '\0'); q++) ;
01918 }
01919 else
01920 if (*q == '\'')
01921 {
01922 for (q++; (*q != '\'') && (*q != '\0'); q++) ;
01923 q++;
01924 }
01925 else
01926 while ((isspace((int) ((unsigned char) *q)) == 0) && (*q != '\0'))
01927 q++;
01928 argv[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+MaxTextExtent,
01929 sizeof(**argv));
01930 if (argv[i] == (char *) NULL)
01931 {
01932 for (i--; i >= 0; i--)
01933 argv[i]=DestroyString(argv[i]);
01934 argv=(char **) RelinquishMagickMemory(argv);
01935 ThrowFatalException(ResourceLimitFatalError,
01936 "UnableToConvertStringToARGV");
01937 }
01938 (void) CopyMagickString(argv[i],p,(size_t) (q-p+1));
01939 p=q;
01940 while ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '\0'))
01941 p++;
01942 }
01943 argv[i]=(char *) NULL;
01944 return(argv);
01945 }
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972 MagickExport double StringToDouble(const char *string,const double interval)
01973 {
01974 char
01975 *q;
01976
01977 double
01978 scale,
01979 value;
01980
01981 assert(string != (char *) NULL);
01982 value=strtod(string,&q);
01983 scale=1000.0;
01984 if ((*q != '\0') && (tolower((int) ((unsigned char) *(q+1))) == 'i'))
01985 scale=1024.0;
01986 switch (tolower((int) ((unsigned char) *q)))
01987 {
01988 case '%': value*=pow(scale,0)*interval/100.0; break;
01989 case 'k': value*=pow(scale,1); break;
01990 case 'm': value*=pow(scale,2); break;
01991 case 'g': value*=pow(scale,3); break;
01992 case 't': value*=pow(scale,4); break;
01993 case 'p': value*=pow(scale,5); break;
01994 case 'e': value*=pow(scale,6); break;
01995 case 'z': value*=pow(scale,7); break;
01996 case 'y': value*=pow(scale,8); break;
01997 default: break;
01998 }
01999 return(value);
02000 }
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024 MagickExport char *StringInfoToHexString(const StringInfo *string_info)
02025 {
02026 char
02027 *string;
02028
02029 register const unsigned char
02030 *p;
02031
02032 register long
02033 i;
02034
02035 register unsigned char
02036 *q;
02037
02038 size_t
02039 length;
02040
02041 unsigned char
02042 hex_digits[16];
02043
02044 length=string_info->length;
02045 if (~length < MaxTextExtent)
02046 ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
02047 string=(char *) AcquireQuantumMemory(length+MaxTextExtent,2*sizeof(*string));
02048 if (string == (char *) NULL)
02049 ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
02050 hex_digits[0]='0';
02051 hex_digits[1]='1';
02052 hex_digits[2]='2';
02053 hex_digits[3]='3';
02054 hex_digits[4]='4';
02055 hex_digits[5]='5';
02056 hex_digits[6]='6';
02057 hex_digits[7]='7';
02058 hex_digits[8]='8';
02059 hex_digits[9]='9';
02060 hex_digits[10]='a';
02061 hex_digits[11]='b';
02062 hex_digits[12]='c';
02063 hex_digits[13]='d';
02064 hex_digits[14]='e';
02065 hex_digits[15]='f';
02066 p=string_info->datum;
02067 q=(unsigned char *) string;
02068 for (i=0; i < (long) string_info->length; i++)
02069 {
02070 *q++=hex_digits[(*p >> 4) & 0x0f];
02071 *q++=hex_digits[*p & 0x0f];
02072 p++;
02073 }
02074 *q='\0';
02075 return(string);
02076 }
02077
02078
02079
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103 MagickExport char *StringToken(const char *delimiters,char **string)
02104 {
02105 char
02106 *q;
02107
02108 register char
02109 *p;
02110
02111 register const char
02112 *r;
02113
02114 register int
02115 c,
02116 d;
02117
02118 p=(*string);
02119 if (p == (char *) NULL)
02120 return((char *) NULL);
02121 for (q=p; ; )
02122 {
02123 c=(*p++);
02124 r=delimiters;
02125 do
02126 {
02127 d=(*r++);
02128 if (c == d)
02129 {
02130 if (c == '\0')
02131 p=(char *) NULL;
02132 else
02133 p[-1]='\0';
02134 *string=p;
02135 return(q);
02136 }
02137 } while (d != '\0');
02138 }
02139 }
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168 MagickExport char **StringToList(const char *text)
02169 {
02170 char
02171 **textlist;
02172
02173 register const char
02174 *p;
02175
02176 register long
02177 i;
02178
02179 unsigned long
02180 lines;
02181
02182 if (text == (char *) NULL)
02183 return((char **) NULL);
02184 for (p=text; *p != '\0'; p++)
02185 if (((int) ((unsigned char) *p) < 32) &&
02186 (isspace((int) ((unsigned char) *p)) == 0))
02187 break;
02188 if (*p == '\0')
02189 {
02190 register const char
02191 *q;
02192
02193
02194
02195
02196 lines=1;
02197 for (p=text; *p != '\0'; p++)
02198 if (*p == '\n')
02199 lines++;
02200 textlist=(char **) AcquireQuantumMemory((size_t) lines+1UL,
02201 sizeof(*textlist));
02202 if (textlist == (char **) NULL)
02203 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertText");
02204 p=text;
02205 for (i=0; i < (long) lines; i++)
02206 {
02207 for (q=p; *q != '\0'; q++)
02208 if ((*q == '\r') || (*q == '\n'))
02209 break;
02210 textlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+MaxTextExtent,
02211 sizeof(*textlist));
02212 if (textlist[i] == (char *) NULL)
02213 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertText");
02214 (void) CopyMagickString(textlist[i],p,(size_t) (q-p+1));
02215 if (*q == '\r')
02216 q++;
02217 p=q+1;
02218 }
02219 }
02220 else
02221 {
02222 char
02223 hex_string[MaxTextExtent];
02224
02225 register char
02226 *q;
02227
02228 register long
02229 j;
02230
02231
02232
02233
02234 lines=(unsigned long) (strlen(text)/0x14)+1;
02235 textlist=(char **) AcquireQuantumMemory((size_t) lines+1UL,
02236 sizeof(*textlist));
02237 if (textlist == (char **) NULL)
02238 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertText");
02239 p=text;
02240 for (i=0; i < (long) lines; i++)
02241 {
02242 textlist[i]=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
02243 sizeof(*textlist));
02244 if (textlist[i] == (char *) NULL)
02245 ThrowFatalException(ResourceLimitFatalError,"UnableToConvertText");
02246 (void) FormatMagickString(textlist[i],MaxTextExtent,"0x%08lx: ",0x14*i);
02247 q=textlist[i]+strlen(textlist[i]);
02248 for (j=1; j <= (long) MagickMin(strlen(p),0x14); j++)
02249 {
02250 (void) FormatMagickString(hex_string,MaxTextExtent,"%02x",*(p+j));
02251 (void) CopyMagickString(q,hex_string,MaxTextExtent);
02252 q+=2;
02253 if ((j % 0x04) == 0)
02254 *q++=' ';
02255 }
02256 for ( ; j <= 0x14; j++)
02257 {
02258 *q++=' ';
02259 *q++=' ';
02260 if ((j % 0x04) == 0)
02261 *q++=' ';
02262 }
02263 *q++=' ';
02264 for (j=1; j <= (long) MagickMin(strlen(p),0x14); j++)
02265 {
02266 if (isprint((int) ((unsigned char) *p)) != 0)
02267 *q++=(*p);
02268 else
02269 *q++='-';
02270 p++;
02271 }
02272 *q='\0';
02273 }
02274 }
02275 textlist[i]=(char *) NULL;
02276 return(textlist);
02277 }
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301 MagickExport StringInfo *StringToStringInfo(const char *string)
02302 {
02303 StringInfo
02304 *string_info;
02305
02306 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
02307 assert(string != (const char *) NULL);
02308 string_info=AcquireStringInfo(strlen(string)+1);
02309 SetStringInfoDatum(string_info,(const unsigned char *) string);
02310 return(string_info);
02311 }
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334
02335
02336 MagickExport void StripString(char *message)
02337 {
02338 register char
02339 *p,
02340 *q;
02341
02342 size_t
02343 length;
02344
02345 assert(message != (char *) NULL);
02346 if (*message == '\0')
02347 return;
02348 length=strlen(message);
02349 p=message;
02350 while (isspace((int) ((unsigned char) *p)) != 0)
02351 p++;
02352 if ((*p == '\'') || (*p == '"'))
02353 p++;
02354 q=message+length-1;
02355 while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p))
02356 q--;
02357 if (q > p)
02358 if ((*q == '\'') || (*q == '"'))
02359 q--;
02360 (void) CopyMagickMemory(message,p,(size_t) (q-p+1));
02361 message[q-p+1]='\0';
02362 for (p=message; *p != '\0'; p++)
02363 if (*p == '\n')
02364 *p=' ';
02365 }
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398 MagickExport MagickBooleanType SubstituteString(char **string,
02399 const char *search,const char *replace)
02400 {
02401 MagickBooleanType
02402 status;
02403
02404 register char
02405 *p;
02406
02407 size_t
02408 extent,
02409 replace_extent,
02410 search_extent;
02411
02412 ssize_t
02413 offset;
02414
02415 status=MagickFalse;
02416 search_extent=0,
02417 replace_extent=0;
02418 for (p=strchr(*string,*search); p != (char *) NULL; p=strchr(p+1,*search))
02419 {
02420 if (search_extent == 0)
02421 search_extent=strlen(search);
02422 if (strncmp(p,search,search_extent) != 0)
02423 continue;
02424
02425
02426
02427 status=MagickTrue;
02428 if (replace_extent == 0)
02429 replace_extent=strlen(replace);
02430 if (replace_extent > search_extent)
02431 {
02432
02433
02434
02435 offset=p-(*string);
02436 extent=strlen(*string)+replace_extent-search_extent+1;
02437 *string=(char *) ResizeQuantumMemory(*string,extent+MaxTextExtent,
02438 sizeof(*p));
02439 if (*string == (char *) NULL)
02440 ThrowFatalException(ResourceLimitFatalError,"UnableToAcquireString");
02441 p=(*string)+offset;
02442 }
02443
02444
02445
02446 if (search_extent != replace_extent)
02447 (void) CopyMagickMemory(p+replace_extent,p+search_extent,
02448 strlen(p+search_extent)+1);
02449 (void) CopyMagickMemory(p,replace,replace_extent);
02450 p+=replace_extent-1;
02451 }
02452 return(status);
02453 }