Changeset 32
- Timestamp:
- Feb 6, 2001, 7:21:38 PM (25 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/helpers/xstring.h
r23 r32 153 153 typedef XSTRFINDREPLACEC *PXSTRFINDREPLACEC; 154 154 155 // V0.9.9 (2001-01-29) [lafaix]: constants added 156 #define CRLF2LF TRUE 157 #define LF2CRLF FALSE 158 155 159 VOID XWPENTRY xstrConvertLineFormat(PXSTRING pxstr, BOOL fToCFormat); 156 160 typedef VOID XWPENTRY XSTRCONVERTLINEFORMAT(PXSTRING pxstr, BOOL fToCFormat); -
trunk/src/helpers/except.c
r31 r32 435 435 *(pulStackWord+1)); 436 436 pulStackWord = (PULONG)*(pulStackWord); 437 438 if (pulStackWord == 0) 439 fprintf(file, "\n pulStackWord == 0"); 440 else if (pulStackWord >= (PULONG)ptib->tib_pstacklimit) 441 fprintf(file, "\n pulStackWord >= (PULONG)ptib->tib_pstacklimit"); 437 442 } // end while 438 443 } … … 736 741 737 742 if (ptib != 0) 743 { 738 744 excDumpStackFrames(file, ptib, pContextRec); 745 } 739 746 } 740 747 } -
trunk/src/helpers/xstring.c
r23 r32 390 390 *@@changed V0.9.6 (2000-11-01) [umoeller]: rewritten 391 391 *@@changed V0.9.7 (2001-01-15) [umoeller]: added ulSourceLength 392 *@@changed V0.9.9 (2001-01-28) [lafaix]: fixed memory leak and NULL source behavior 392 393 */ 393 394 … … 402 403 if (pcszSource) 403 404 { 405 // source specified: 404 406 if (ulSourceLength == 0) 407 // but not length: 405 408 ulSourceLength = strlen(pcszSource); 406 407 if (ulSourceLength) 409 } 410 else 411 ulSourceLength = 0; 412 413 if (ulSourceLength) 414 { 415 // we do have a source string: 416 ULONG cbNeeded = ulSourceLength + 1; 417 if (cbNeeded > pxstr->cbAllocated) 408 418 { 409 // we do have a source string: 410 ULONG cbNeeded = ulSourceLength + 1; 411 if (cbNeeded > pxstr->cbAllocated) 412 { 413 // we need more memory than we have previously 414 // allocated: 415 pxstr->cbAllocated = cbNeeded; 416 pxstr->psz = (PSZ)malloc(cbNeeded); 417 } 418 // else: we have enough memory 419 420 // strcpy(pxstr->psz, pcszSource); 421 memcpy(pxstr->psz, 422 pcszSource, 423 ulSourceLength); 424 *(pxstr->psz + ulSourceLength) = 0; 419 // we need more memory than we have previously 420 // allocated: 421 if (pxstr->psz) 422 free(pxstr->psz); // V0.9.9 (2001-01-28) [lafaix] 423 pxstr->cbAllocated = cbNeeded; 424 pxstr->psz = (PSZ)malloc(cbNeeded); 425 425 } 426 else 427 { 428 // no source specified or source is empty: 429 if (pxstr->cbAllocated) 430 // we did have a string: set to empty, 431 // but leave allocated memory intact 432 *(pxstr->psz) = 0; 433 // else: pxstr->psz is still NULL 434 } 435 436 // in all cases, set new length 437 pxstr->ulLength = ulSourceLength; 426 // else: we have enough memory 427 428 // strcpy(pxstr->psz, pcszSource); 429 memcpy(pxstr->psz, 430 pcszSource, 431 ulSourceLength + 1); // V0.9.9 (2001-01-31) [umoeller] 438 432 } 433 else 434 { 435 // no source specified or source is empty: 436 if (pxstr->cbAllocated) 437 // we did have a string: set to empty, 438 // but leave allocated memory intact 439 *(pxstr->psz) = 0; 440 // else 441 // we had no string previously: in that case 442 // psz and ulLength and cbAllocated are all still NULL 443 } 444 445 // in all cases, set new length 446 pxstr->ulLength = ulSourceLength; 439 447 } 440 448 … … 627 635 /* 628 636 *@@ xstrrpl: 629 * replaces c SearchLen characters in pxstr, starting630 * at the position ul Start, with the string637 * replaces cReplLen characters in pxstr, starting 638 * at the position ulFirstReplPos, with the string 631 639 * in pxstrReplaceWith. 632 640 * … … 657 665 * 658 666 *@@added V0.9.7 (2001-01-15) [umoeller] 667 *@@changed V0.9.9 (2001-01-29) [lafaix]: fixed unnecessary allocation when pxstr was big enough 659 668 */ 660 669 … … 733 742 // we have enough memory left, 734 743 // we can just overwrite in the middle... 735 736 PSZ pszAfterFoundBackup = 0; 744 // fixed V0.9.9 (2001-01-29) [lafaix] 745 737 746 // calc length of string after "found" 738 747 ULONG cTailLength = pxstr->ulLength - ulFirstReplOfs - cReplLen; 739 748 740 // if "replace" is longer than "found", 741 // make a backup of the stuff after "found", 742 // or this would get overwritten 743 if (cReplaceLen > cReplLen) 744 { 745 pszAfterFoundBackup = (PSZ)malloc(cTailLength + 1); 746 memcpy(pszAfterFoundBackup, 747 pFound + cReplLen, 748 cTailLength + 1); 749 } 749 // first, we move the end to its new location (memmove 750 // handles overlap if needed) 751 memmove(pFound + cReplaceLen, 752 pFound + cReplLen, 753 cTailLength + 1); // including null terminator 750 754 751 755 // now overwrite "found" in the middle 752 756 if (cReplaceLen) 753 757 { 754 memcpy(p xstr->psz + ulFirstReplOfs,758 memcpy(pFound, 755 759 pstrReplaceWith->psz, 756 760 cReplaceLen); // no null terminator 757 761 } 758 762 759 // now append tail (stuff after "found") again... 760 if (pszAfterFoundBackup) 761 { 762 // we made a backup above: 763 memcpy(pxstr->psz + ulFirstReplOfs + cReplaceLen, 764 pszAfterFoundBackup, 765 cTailLength + 1); 766 free(pszAfterFoundBackup); 767 // done! 768 } 769 else 770 // no backup: 771 if (cReplaceLen < cReplLen) 772 // "replace" is shorter than "found: 773 memcpy(pxstr->psz + ulFirstReplOfs + cReplaceLen, 774 pFound + cReplLen, 775 cTailLength + 1); 776 // else (cReplaceLen == cReplLen): 777 // we can leave the tail as it is 778 763 // that's it; adjust the string length now 779 764 pxstr->ulLength = cbNeeded - 1; 780 765 } … … 871 856 * (and pxstr was therefore not changed). 872 857 * 873 * This starts the search at *pulOf fset. If874 * (*pulOf fset== 0), this starts from the beginning858 * This starts the search at *pulOfs. If 859 * (*pulOfs == 0), this starts from the beginning 875 860 * of pxstr. 876 861 * 877 * If the string was found, *pulOf fsetwill be set to the862 * If the string was found, *pulOfs will be set to the 878 863 * first character after the new replacement string. This 879 864 * allows you to call this func again with the same strings … … 1007 992 * converts between line formats. 1008 993 * 1009 * If (fToCFormat == TRUE), all \r\n pairs are replaced994 * If (fToCFormat == CRLF2LF), all \r\n pairs are replaced 1010 995 * with \n chars (UNIX or C format). 1011 996 * 1012 * Reversely, if (fToCFormat == FALSE), all \n chars997 * Reversely, if (fToCFormat == LF2CRLF), all \n chars 1013 998 * are converted to \r\n pairs (DOS and OS/2 formats). 1014 999 * No check is made whether this has already been done. … … 1018 1003 1019 1004 VOID xstrConvertLineFormat(PXSTRING pxstr, 1020 BOOL fToCFormat) // in: if TRUE, to C format; if FALSE, to OS/2 format.1005 BOOL fToCFormat) // in: if CRLF2LF, to C format; if LF2CRLF, to OS/2 format. 1021 1006 { 1022 1007 XSTRING strFind,
Note:
See TracChangeset
for help on using the changeset viewer.