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