Changeset 13
- Timestamp:
- Nov 23, 2000, 7:36:41 PM (25 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/helpers/memdebug.h
r7 r13 41 41 extern PFNCBMEMDLOG G_pMemdLogFunc; 42 42 43 /* ****************************************************************** 44 * 45 * Private declarations 46 * 47 ********************************************************************/ 48 49 #ifdef MEMDEBUG_PRIVATE 50 51 BOOL memdLock(VOID); 52 53 VOID memdUnlock(VOID); 54 55 /* 56 *@@ HEAPITEM: 57 * informational structure created for each 58 * malloc() call by memdMalloc. These are stored 59 * in a global linked list (G_pHeapItemsRoot). 60 * 61 * We cannot use the linklist.c functions for 62 * managing the linked list because these use 63 * malloc in turn, which would lead to infinite 64 * loops. 65 * 66 *@@added V0.9.3 (2000-04-11) [umoeller] 67 */ 68 69 typedef struct _HEAPITEM 70 { 71 struct _HEAPITEM *pNext; // next item in linked list or NULL if last 72 73 void *pAfterMagic; // memory pointer returned by memdMalloc; 74 // this points to after the magic string 75 unsigned long ulSize; // requested size (without magic head and tail) 76 77 const char *pcszSourceFile; // as passed to memdMalloc 78 unsigned long ulLine; // as passed to memdMalloc 79 const char *pcszFunction; // as passed to memdMalloc 80 81 DATETIME dtAllocated; // system date/time at time of memdMalloc call 82 83 ULONG ulTID; // thread ID that memdMalloc was running on 84 85 BOOL fFreed; // TRUE only after item has been freed by memdFree 86 } HEAPITEM, *PHEAPITEM; 87 88 extern PHEAPITEM G_pHeapItemsRoot; 89 extern ULONG G_ulItemsReleased; 90 extern ULONG G_ulBytesReleased; 91 92 #endif // MEMDEBUG_PRIVATE 93 94 /* ****************************************************************** 95 * 96 * Publics 97 * 98 ********************************************************************/ 99 43 100 void* memdMalloc(size_t stSize, 44 101 const char *pcszSourceFile, … … 57 114 const char *pcszFunction); 58 115 116 void* memdRealloc(void *p, 117 size_t stSize, 118 const char *pcszSourceFile, 119 unsigned long ulLine, 120 const char *pcszFunction); 121 59 122 unsigned long memdReleaseFreed(void); 60 123 … … 64 127 #define malloc(ul) memdMalloc(ul, __FILE__, __LINE__, __FUNCTION__) 65 128 #define calloc(n, size) memdCalloc(n, size, __FILE__, __LINE__, __FUNCTION__) 129 #define realloc(p, ul) memdRealloc(p, ul, __FILE__, __LINE__, __FUNCTION__) 66 130 #define free(p) memdFree(p, __FILE__, __LINE__, __FUNCTION__) 67 131 … … 79 143 #ifdef PM_INCLUDED 80 144 /******************************************************************** 81 * *82 * XFolder debugging helpers *83 * *145 * 146 * XFolder debugging helpers 147 * 84 148 ********************************************************************/ 85 149 … … 94 158 95 159 /* ****************************************************************** 96 * *97 * Heap debugging window *98 * *160 * 161 * Heap debugging window 162 * 99 163 ********************************************************************/ 100 164 -
trunk/include/helpers/stringh.h
r12 r13 64 64 65 65 ULONG strhrpl(PSZ *ppszBuf, 66 ULONGulOfs,66 PULONG pulOfs, 67 67 const char *pcszSearch, 68 const char *pcszReplace, 69 PULONG pulAfterOfs); 68 const char *pcszReplace); 70 69 71 70 ULONG strhWords(PSZ psz); … … 74 73 75 74 PSZ strhThousandsDouble(PSZ pszTarget, double dbl, CHAR cThousands); 75 76 PSZ strhVariableDouble(PSZ pszTarget, double dbl, PSZ pszUnits, 77 CHAR cThousands); 76 78 77 79 VOID strhFileDate(PSZ pszBuf, … … 102 104 PSZ *ppszEnd); 103 105 106 BOOL strhIsWord(const char *pcszBuf, 107 const char *p, 108 ULONG cbSearch, 109 const char *pcszBeginChars, 110 const char *pcszEndChars); 111 104 112 PSZ strhFindWord(const char *pszBuf, 105 113 const char *pszSearch, … … 192 200 ********************************************************************/ 193 201 194 char* strhfind (const char *string, 195 const char *pattern, 196 BOOL repeat_find); 197 198 char* strhfind_r (const char *string, 199 const char *pattern); 200 201 char* strhfind_rb (const char *string, 202 const char *pattern, 203 size_t *shift, 204 BOOL *repeat_find); 205 206 void* strhmemfind (const void *block, 207 size_t block_size, 208 const void *pattern, 209 size_t pattern_size, 210 BOOL repeat_find); 211 212 void* strhmemfind_r (const void *block, 213 size_t block_size, 214 const void *pattern, 215 size_t pattern_size); 216 217 void* strhmemfind_rb (const void *in_block, 218 size_t block_size, 219 const void *in_pattern, 220 size_t pattern_size, 221 size_t *shift, 222 BOOL *repeat_find); 202 void* strhmemfind(const void *in_block, 203 size_t block_size, 204 const void *in_pattern, 205 size_t pattern_size, 206 size_t *shift, 207 BOOL *repeat_find); 223 208 224 209 char* strhtxtfind (const char *string, -
trunk/include/helpers/tree.h
r7 r13 1 2 /* 3 *@@sourcefile tree.h: 4 * header file for tree.c (red-black balanced binary trees). 5 * See remarks there. 6 */ 7 8 /* 9 * Written: 97/11/18 Jonathan Schultz <jonathan@imatix.com> 10 * Revised: 98/12/08 Jonathan Schultz <jonathan@imatix.com> 11 * 12 * Copyright (C) 1991-99 iMatix Corporation. 13 * Copyright (C) 2000 Ulrich Mller. 14 * This file is part of the XWorkplace source package. 15 * XWorkplace is free software; you can redistribute it and/or modify 16 * it under the terms of the GNU General Public License as published 17 * by the Free Software Foundation, in version 2 as it comes in the 18 * "COPYING" file of the XWorkplace main distribution. 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 */ 24 25 1 26 /* ----------------------------------------------------------------<Prolog>- 2 27 Name: sfltree.h … … 52 77 *@@ TREE: 53 78 * tree node. 79 * 80 * To use the tree functions, all your structures 81 * must have a TREE structure as their first member. 82 * 83 * Example: 84 * 85 + typedef struct _MYTREENODE 86 + { 87 + TREE tree; 88 + char acMyData[1000]; 89 + } MYTREENODE, *PMYTREENODE; 90 * 91 * See tree.c for an introduction to the tree functions. 54 92 */ 55 93 … … 61 99 unsigned long id; 62 100 TREE_COLOUR colour; 63 } TREE ;101 } TREE, *PTREE; 64 102 65 103 // The tree algorithm needs to know how to sort the data. -
trunk/include/helpers/xstring.h
r12 r13 79 79 #define xstrIsString(psz) ( (psz != 0) && (*(psz) != 0) ) 80 80 81 PSZ xstrFindWord(const XSTRING *pxstr, 82 ULONG ulOfs, 83 const XSTRING *pstrFind, 84 size_t *pShiftTable, 85 PBOOL pfRepeatFind, 86 const char *pcszBeginChars, 87 const char *pcszEndChars); 88 81 89 ULONG xstrrpl(PXSTRING pxstr, 82 ULONGulOfs,90 PULONG pulOfs, 83 91 const XSTRING *pstrSearch, 84 92 const XSTRING *pstrReplace, 85 PULONG pulAfterOfs); 93 size_t *pShiftTable, 94 PBOOL pfRepeatFind); 86 95 87 96 ULONG xstrcrpl(PXSTRING pxstr, 88 ULONGulOfs,97 PULONG pulOfs, 89 98 const char *pcszSearch, 90 const char *pcszReplace, 91 PULONG pulAfterOfs); 99 const char *pcszReplace); 92 100 #endif 93 101 -
trunk/readme.txt
r7 r13 143 143 headers. 144 144 145 Note that all the helpers C code includes their own include 146 files this way. As a result, the XWPHelpers "include" 147 directory must be in your include path, or this won't 148 compile. 149 150 Besides, the helpers C code expects a file called "setup.h" 151 in your include path somewhere. This is included by all 152 the C files so you can (re)define certain macros there. 145 153 146 154 -
trunk/src/helpers/cctl_progbar.c
r8 r13 140 140 { 141 141 // make string 142 sprintf(szPercent, "% d%%", ((100 * pData->ulNow) / pData->ulMax) );142 sprintf(szPercent, "%lu %%", ((100 * pData->ulNow) / pData->ulMax) ); 143 143 144 144 // calculate string space -
trunk/src/helpers/debug.c
r8 r13 700 700 NrPublic = pubfunc_ofs = pxdi->sspub32.offset; 701 701 read_types = TRUE; 702 sprintf(pxdi->szNrPub, "%s %s (%s, seg %04X : ofs %08X\n", 702 sprintf(pxdi->szNrPub, 703 "%s %s (%s, seg %04lX : ofs %08lX\n", 703 704 (pxdi->sspub32.type == 1) ? " Abs" : " ", 704 705 ename, 705 706 ModName, // () 706 pxdi->sspub32.segment,707 (ULONG)pxdi->sspub32.segment, 707 708 pxdi->sspub32.offset 708 709 ); … … 1177 1178 sprintf(pszBuf, "%f", *(double*)varptr); 1178 1179 else if (type == 10) 1179 sprintf(pszBuf, "%f", *(long double*)varptr);1180 sprintf(pszBuf, "%f", (double)(*(long double*)varptr)); 1180 1181 else if (type == 16) 1181 1182 sprintf(pszBuf, "%s", *(char*)varptr ? "TRUE" : "FALSE"); … … 1187 1188 sprintf(pszBuf, "%c", *(char*)varptr); 1188 1189 else if (type == 21) 1189 sprintf(pszBuf, "% lc", *(short*)varptr);1190 sprintf(pszBuf, "%hd", (*(short*)varptr)); 1190 1191 else if (type == 22) 1191 sprintf(pszBuf, "%l c", *(long*)varptr);1192 sprintf(pszBuf, "%ld", *(long*)varptr); 1192 1193 else if (type == 23) 1193 1194 sprintf(pszBuf, "void"); 1194 1195 else if (type >= 32) 1195 1196 { 1196 sprintf(pszBuf, "0x%p", *(ULONG *) varptr);1197 sprintf(pszBuf, "0x%p", (void*)(*(ULONG*)varptr)); 1197 1198 if (Attr & PAG_FREE) 1198 1199 { … … 1247 1248 one_userdef[pos].type_index - 0x80); 1248 1249 1249 fprintf(LogFile, " %- 6d %- 20.20s %- 33.33s %s (user)\n", 1250 fprintf(LogFile, 1251 " %- 6ld %- 20.20s %- 33.33s %s (user)\n", 1250 1252 autovar_def[var_no].stack_offset, // stack offset 1251 1253 autovar_def[var_no].name, // identifier … … 1295 1297 sszVar, 1296 1298 32); 1297 fprintf(LogFile, " %- 6 d %- 20.20s %- 33.33s %s (ptr1)\n",1299 fprintf(LogFile, " %- 6ld %- 20.20s %- 33.33s %s (ptr1)\n", 1298 1300 autovar_def[var_no].stack_offset, 1299 1301 autovar_def[var_no].name, … … 1319 1321 sszVar, 1320 1322 32); 1321 fprintf(LogFile, " %- 6 d %- 20.20s %- 33.33s %s (ptr2)\n",1323 fprintf(LogFile, " %- 6ld %- 20.20s %- 33.33s %s (ptr2)\n", 1322 1324 autovar_def[var_no].stack_offset, 1323 1325 autovar_def[var_no].name, … … 1335 1337 sszVar, 1336 1338 32); 1337 fprintf(LogFile, " %- 6 d %- 20.20s %- 33.33s %s (ptr3)\n",1339 fprintf(LogFile, " %- 6ld %- 20.20s %- 33.33s %s (ptr3)\n", 1338 1340 autovar_def[var_no].stack_offset, 1339 1341 autovar_def[var_no].name, … … 1372 1374 { 1373 1375 AutoVarsFound = TRUE; 1374 fprintf(LogFile, " List of auto variables at EBP %p in %s:\n", stackofs, func_name); 1376 fprintf(LogFile, " List of auto variables at EBP %p in %s:\n", 1377 (PVOID)stackofs, 1378 func_name); 1375 1379 fprintf(LogFile, " Offset Name Type Value \n"); 1376 1380 fprintf(LogFile, " ÄÄÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n"); … … 1388 1392 autovar_def[n].type_idx - 0x80); 1389 1393 1390 fprintf(LogFile, " %- 6 d %- 20.20s %- 33.33s %s (simple)\n",1394 fprintf(LogFile, " %- 6ld %- 20.20s %- 33.33s %s (simple)\n", 1391 1395 autovar_def[n].stack_offset, 1392 1396 autovar_def[n].name, … … 1400 1404 if (!search_pointers(LogFile, stackofs, n)) 1401 1405 { 1402 fprintf(LogFile, " %- 6 d %-20.20s 0x%X (unknown)\n",1406 fprintf(LogFile, " %- 6ld %-20.20s 0x%X (unknown)\n", 1403 1407 autovar_def[n].stack_offset, 1404 1408 autovar_def[n].name, … … 1506 1510 { 1507 1511 // symbol found 1508 fprintf(LogFile, "between %s + 0x% X ", Buffer, TrapOffset - LastVal);1509 fprintf(LogFile, "(ppLineDef: 0x%lX) ",1512 fprintf(LogFile, "between %s + 0x%lX ", Buffer, TrapOffset - LastVal); 1513 /* fprintf(LogFile, "(ppLineDef: 0x%lX) ", 1510 1514 LINEDEFOFFSET(SegDef) 1511 ); 1515 ); */ 1512 1516 fprintf(LogFile, "\n"); 1513 1517 } … … 1522 1526 // symbol found, as above 1523 1527 fprintf(LogFile, " " 1524 "and %s - 0x% X ", Buffer, LastVal - TrapOffset);1528 "and %s - 0x%lX ", Buffer, LastVal - TrapOffset); 1525 1529 fprintf(LogFile, "\n"); 1526 1530 break; … … 1534 1538 if (SymDef16.wSymVal > TrapOffset) 1535 1539 { 1536 fprintf(LogFile, "between %s + % X\n",1540 fprintf(LogFile, "between %s + %lX\n", 1537 1541 Buffer, 1538 1542 TrapOffset - LastVal); … … 1545 1549 { 1546 1550 fprintf(LogFile, " " 1547 "and %s - % X\n",1551 "and %s - %lX\n", 1548 1552 Buffer, 1549 1553 LastVal - TrapOffset); … … 1681 1685 else if (arc != 0) 1682 1686 fprintf(LogFile, 1683 "Error % dreading symbol file %s\n",1687 "Error %lu reading symbol file %s\n", 1684 1688 arc, 1685 1689 szSymName); … … 1743 1747 if (rc != NO_ERROR) 1744 1748 { 1745 fprintf(LogFile, "Invalid EBP %8.8 p (DosQueryMem returned %d)\n",Ebp, rc);1749 fprintf(LogFile, "Invalid EBP %8.8lX (DosQueryMem returned %lu)\n", (ULONG)Ebp, rc); 1746 1750 break; 1747 1751 } 1748 1752 if (!(Attr & PAG_COMMIT)) 1749 1753 { 1750 fprintf(LogFile, "Invalid EBP %8.8 p (not committed)\n",Ebp);1754 fprintf(LogFile, "Invalid EBP %8.8lX (not committed)\n", (ULONG)Ebp); 1751 1755 break; 1752 1756 } 1753 1757 if (Size < 10) 1754 1758 { 1755 fprintf(LogFile, "Invalid EBP %8.8 p (mem block size < 10)\n",Ebp);1759 fprintf(LogFile, "Invalid EBP %8.8lX (mem block size < 10)\n", (ULONG)Ebp); 1756 1760 break; 1757 1761 } … … 1853 1857 fprintf(LogFile, " Trap -> "); 1854 1858 else 1855 fprintf(LogFile, " %8.8 p ",Ebp);1859 fprintf(LogFile, " %8.8lX ", (ULONG)Ebp); 1856 1860 1857 1861 // "Address" column 1858 1862 if (f32bit) 1859 fprintf(LogFile, ":%8.8 p ",RetAddr);1863 fprintf(LogFile, ":%8.8lX ", (ULONG)RetAddr); 1860 1864 else 1861 1865 fprintf(LogFile, "%04.04X:%04.04X ", Cs, Ip); … … 1874 1878 if (rc != NO_ERROR || !(Attr & PAG_COMMIT)) 1875 1879 { 1876 fprintf(LogFile, "Invalid RetAddr: %8.8 p\n",RetAddr);1880 fprintf(LogFile, "Invalid RetAddr: %8.8lX\n", (ULONG)RetAddr); 1877 1881 break; // avoid infinite loops 1878 1882 } … … 1895 1899 1896 1900 // print module and object 1897 fprintf(LogFile, "%-8s %04 X ", szName, ObjNum + 1);1901 fprintf(LogFile, "%-8s %04lX ", szName, ObjNum + 1); 1898 1902 1899 1903 if (strlen(Name) > 3) … … 1907 1911 else 1908 1912 fprintf(LogFile, 1909 "DosQueryModFromEIP failed, returned % d\n",1913 "DosQueryModFromEIP failed, returned %lu\n", 1910 1914 rc); 1911 1915 } … … 1949 1953 if ((rc != NO_ERROR) || (Size < 4)) 1950 1954 { 1951 fprintf(LogFile, "... lost stack chain - invalid EBP: %8.8 p\n",Ebp);1955 fprintf(LogFile, "... lost stack chain - invalid EBP: %8.8lX\n", (ULONG)Ebp); 1952 1956 break; 1953 1957 } -
trunk/src/helpers/dosh.c
r8 r13 464 464 | OPEN_SHARE_DENYNONE, 465 465 NULL); 466 467 // _Pmpf((__FUNCTION__ ": DosOpen(OPEN_FLAGS_DASD) returned %d", arc)); 466 468 467 469 switch (arc) … … 1070 1072 do 1071 1073 { 1072 sprintf(szCount, ".%03 d", ulCount);1074 sprintf(szCount, ".%03lu", ulCount); 1073 1075 strcpy(pszLastDot, szCount); 1074 1076 ulCount++; -
trunk/src/helpers/except.c
r8 r13 299 299 ulOffset = 0; 300 300 fprintf(file, 301 " %-8s: %08 X ",301 " %-8s: %08lX ", 302 302 pszDescription, 303 303 ulAddress); … … 312 312 // error: 313 313 fprintf(file, 314 " %-8s:% d Error: DosQueryModFromEIP returned %d\n",314 " %-8s:%lu Error: DosQueryModFromEIP returned %lu\n", 315 315 szMod1, 316 316 ulObject, … … 322 322 323 323 fprintf(file, 324 " %-8s:% d",324 " %-8s:%lu ", 325 325 szMod1, 326 326 ulObject); … … 393 393 ) 394 394 { 395 fprintf(file, "\n %08 X: ",pulStackWord);395 fprintf(file, "\n %08lX: ", (ULONG)pulStackWord); 396 396 fprintf(file, "Page inaccessible"); 397 397 pulStackWord += 0x1000; … … 400 400 } 401 401 402 sprintf(szAddress, "%08 X",403 pulStackWord);402 sprintf(szAddress, "%08lX", 403 (ULONG)pulStackWord); 404 404 excPrintStackFrame(file, 405 405 szAddress, … … 416 416 * This calls excPrintStackFrame for each stack frame. 417 417 * 418 * If DEBUG_EXCPT_STACKDUMP is #define'd, this also dumps419 * the stack completely, which isn't that useful.420 *421 418 *@@changed V0.9.0 [umoeller]: added support for application hook 422 419 *@@changed V0.9.0 (99-11-02) [umoeller]: added TID to dump 423 420 *@@changed V0.9.2 (2000-03-10) [umoeller]: now using excPrintStackFrame 424 421 *@@changed V0.9.3 (2000-05-03) [umoeller]: fixed crashes 422 *@@changed V0.9.6 (2000-11-06) [umoeller]: added more register dumps 425 423 */ 426 424 … … 475 473 // generic exception info 476 474 fprintf(file, 477 "\n%s:\n Exception type: %08 X\n Address: %08X\n Params: ",475 "\n%s:\n Exception type: %08lX\n Address: %08lX\n Params: ", 478 476 pszHandlerName, 479 477 pReportRec->ExceptionNum, 480 pReportRec->ExceptionAddress);478 (ULONG)pReportRec->ExceptionAddress); 481 479 for (ul = 0; ul < pReportRec->cParameters; ul++) 482 480 { 483 fprintf(file, "%08 X ",481 fprintf(file, "%08lX ", 484 482 pReportRec->ExceptionInfo[ul]); 485 483 } … … 494 492 fprintf(file, "\nAccess violation: "); 495 493 if (pReportRec->ExceptionInfo[0] & XCPT_READ_ACCESS) 496 fprintf(file, "Invalid read access from 0x%04 X:%08X.\n",494 fprintf(file, "Invalid read access from 0x%04lX:%08lX.\n", 497 495 pContextRec->ctx_SegDs, pReportRec->ExceptionInfo[1]); 498 496 else if (pReportRec->ExceptionInfo[0] & XCPT_WRITE_ACCESS) 499 fprintf(file, "Invalid write access to 0x%04 X:%08X.\n",497 fprintf(file, "Invalid write access to 0x%04lX:%08lX.\n", 500 498 pContextRec->ctx_SegDs, pReportRec->ExceptionInfo[1]); 501 499 else if (pReportRec->ExceptionInfo[0] & XCPT_SPACE_ACCESS) 502 fprintf(file, "Invalid space access at 0x%04 X.\n",500 fprintf(file, "Invalid space access at 0x%04lX.\n", 503 501 pReportRec->ExceptionInfo[1]); 504 502 else if (pReportRec->ExceptionInfo[0] & XCPT_LIMIT_ACCESS) 505 503 fprintf(file, "Invalid limit access occurred.\n"); 506 504 else if (pReportRec->ExceptionInfo[0] == XCPT_UNKNOWN_ACCESS) 507 fprintf(file, "unknown at 0x%04 X:%08X\n",505 fprintf(file, "unknown at 0x%04lX:%08lX\n", 508 506 pContextRec->ctx_SegDs, pReportRec->ExceptionInfo[1]); 509 507 fprintf(file, … … 586 584 "\n Process module: 0x%lX (%s)" 587 585 "\n Trapping module: 0x%lX (%s)" 588 "\n Object: % d\n",586 "\n Object: %lu\n", 589 587 ppib->pib_ulpid, 590 588 hMod1, szMod1, … … 594 592 fprintf(file, 595 593 "\nTrapping thread information:" 596 "\n Thread ID: 0x%lX (% d)"594 "\n Thread ID: 0x%lX (%lu)" 597 595 "\n Priority: 0x%lX\n", 598 596 ptib->tib_ptib2->tib2_ultid, ptib->tib_ptib2->tib2_ultid, … … 618 616 if (pContextRec->ContextFlags & CONTEXT_INTEGER) 619 617 { 618 // DS the following 4 added V0.9.6 (2000-11-06) [umoeller] 619 fprintf(file, "\n DS = %08lX ", pContextRec->ctx_SegDs); 620 excDescribePage(file, pContextRec->ctx_SegDs); 621 // ES 622 fprintf(file, "\n ES = %08lX ", pContextRec->ctx_SegEs); 623 excDescribePage(file, pContextRec->ctx_SegEs); 624 // FS 625 fprintf(file, "\n FS = %08lX ", pContextRec->ctx_SegFs); 626 excDescribePage(file, pContextRec->ctx_SegFs); 627 // GS 628 fprintf(file, "\n GS = %08lX ", pContextRec->ctx_SegGs); 629 excDescribePage(file, pContextRec->ctx_SegGs); 630 620 631 // EAX 621 fprintf(file, "\n EAX = %08 X ", pContextRec->ctx_RegEax);632 fprintf(file, "\n EAX = %08lX ", pContextRec->ctx_RegEax); 622 633 excDescribePage(file, pContextRec->ctx_RegEax); 623 634 // EBX 624 fprintf(file, "\n EBX = %08 X ", pContextRec->ctx_RegEbx);635 fprintf(file, "\n EBX = %08lX ", pContextRec->ctx_RegEbx); 625 636 excDescribePage(file, pContextRec->ctx_RegEbx); 626 637 // ECX 627 fprintf(file, "\n ECX = %08 X ", pContextRec->ctx_RegEcx);638 fprintf(file, "\n ECX = %08lX ", pContextRec->ctx_RegEcx); 628 639 excDescribePage(file, pContextRec->ctx_RegEcx); 629 640 // EDX 630 fprintf(file, "\n EDX = %08 X ", pContextRec->ctx_RegEdx);641 fprintf(file, "\n EDX = %08lX ", pContextRec->ctx_RegEdx); 631 642 excDescribePage(file, pContextRec->ctx_RegEdx); 632 643 // ESI 633 fprintf(file, "\n ESI = %08 X ", pContextRec->ctx_RegEsi);644 fprintf(file, "\n ESI = %08lX ", pContextRec->ctx_RegEsi); 634 645 excDescribePage(file, pContextRec->ctx_RegEsi); 635 646 // EDI 636 fprintf(file, "\n EDI = %08 X ", pContextRec->ctx_RegEdi);647 fprintf(file, "\n EDI = %08lX ", pContextRec->ctx_RegEdi); 637 648 excDescribePage(file, pContextRec->ctx_RegEdi); 638 649 fprintf(file, "\n"); … … 646 657 // *** instruction 647 658 648 fprintf(file, "Instruction pointer (where exception occured):\n CS:EIP = %04 X:%08X ",659 fprintf(file, "Instruction pointer (where exception occured):\n CS:EIP = %04lX:%08lX ", 649 660 pContextRec->ctx_SegCs, 650 661 pContextRec->ctx_RegEip); … … 653 664 // *** CPU flags 654 665 655 fprintf(file, "\n FLG = %08X", pContextRec->ctx_EFlags);666 fprintf(file, "\n EFLAGS = %08lX", pContextRec->ctx_EFlags); 656 667 657 668 /* … … 660 671 */ 661 672 662 fprintf(file, "\nStack:\n Base: %08X\n Limit: %08X", 663 (ptib ? ptib->tib_pstack : 0), 664 (ptib ? ptib->tib_pstacklimit :0)); 665 fprintf(file, "\n SS:ESP = %04X:%08X ", 666 pContextRec->ctx_SegSs, pContextRec->ctx_RegEsp); 673 fprintf(file, "\nStack:\n Base: %08lX\n Limit: %08lX", 674 (ULONG)(ptib ? ptib->tib_pstack : 0), 675 (ULONG)(ptib ? ptib->tib_pstacklimit : 0)); 676 fprintf(file, "\n SS:ESP = %04lX:%08lX ", 677 pContextRec->ctx_SegSs, 678 pContextRec->ctx_RegEsp); 667 679 excDescribePage(file, pContextRec->ctx_RegEsp); 668 680 669 fprintf(file, "\n EBP = %08 X ", pContextRec->ctx_RegEbp);681 fprintf(file, "\n EBP = %08lX ", pContextRec->ctx_RegEbp); 670 682 excDescribePage(file, pContextRec->ctx_RegEbp); 671 683 -
trunk/src/helpers/gpih.c
r8 r13 384 384 { 385 385 // _Pmpf(("Found font PP: %s", pszFontFound)); 386 sscanf(pszFontNameSize, "% d", pulSize);386 sscanf(pszFontNameSize, "%lu", pulSize); 387 387 *ppszFaceName = pcDot + 1; 388 388 brc = TRUE; … … 932 932 { 933 933 // _Pmpf(("Found font PP: %s", pszFontFound)); 934 sscanf(pszFontFound, "% d", &ulFontSize);934 sscanf(pszFontFound, "%lu", &ulFontSize); 935 935 if (plSize) 936 936 *plSize = ulFontSize; -
trunk/src/helpers/helpers_post.in
r9 r13 114 114 $(OUTPUTDIR)\memdebug.obj: $(@B).c $(HLPINC)\$(@B).h \ 115 115 $(PROJECTINC)\setup.h \ 116 $(HLPINC)\except.h $(HLPINC)\stringh.h 117 118 $(OUTPUTDIR)\memdebug_win.obj: $(@B).c $(HLPINC)\memdebug.h \ 119 $(PROJECTINC)\setup.h \ 116 120 $(HLPINC)\cnrh.h $(HLPINC)\except.h $(HLPINC)\stringh.h $(HLPINC)\winh.h 117 121 -
trunk/src/helpers/helpers_pre.in
r10 r13 40 40 41 41 PLAINCOBJS = \ 42 43 44 42 $(OUTPUTDIR)\linklist.obj \ 43 $(OUTPUTDIR)\tree.obj \ 44 $(OUTPUTDIR)\xml.obj \ 45 45 46 46 CPOBJS = $(PLAINCOBJS) \ 47 $(OUTPUTDIR)\datetime.obj \ 48 $(OUTPUTDIR)\debug.obj \ 49 $(OUTPUTDIR)\dosh.obj \ 50 $(OUTPUTDIR)\dosh2.obj \ 51 $(OUTPUTDIR)\eah.obj \ 52 $(OUTPUTDIR)\except.obj \ 53 $(OUTPUTDIR)\level.obj \ 54 $(OUTPUTDIR)\procstat.obj \ 55 $(OUTPUTDIR)\prfh.obj \ 56 $(OUTPUTDIR)\prfh2.obj \ 57 $(OUTPUTDIR)\resh.obj \ 58 $(OUTPUTDIR)\stringh.obj \ 59 $(OUTPUTDIR)\syssound.obj \ 60 $(OUTPUTDIR)\threads.obj \ 61 $(OUTPUTDIR)\tmsgfile.obj \ 62 $(OUTPUTDIR)\wphandle.obj \ 63 $(OUTPUTDIR)\xprf.obj \ 64 $(OUTPUTDIR)\xprf2.obj \ 65 $(OUTPUTDIR)\xstring.obj 47 $(OUTPUTDIR)\datetime.obj \ 48 $(OUTPUTDIR)\debug.obj \ 49 $(OUTPUTDIR)\dosh.obj \ 50 $(OUTPUTDIR)\dosh2.obj \ 51 $(OUTPUTDIR)\eah.obj \ 52 $(OUTPUTDIR)\except.obj \ 53 $(OUTPUTDIR)\level.obj \ 54 $(OUTPUTDIR)\procstat.obj \ 55 $(OUTPUTDIR)\prfh.obj \ 56 $(OUTPUTDIR)\prfh2.obj \ 57 $(OUTPUTDIR)\resh.obj \ 58 $(OUTPUTDIR)\stringh.obj \ 59 $(OUTPUTDIR)\syssound.obj \ 60 $(OUTPUTDIR)\tmsgfile.obj \ 61 $(OUTPUTDIR)\wphandle.obj \ 62 $(OUTPUTDIR)\xprf.obj \ 63 $(OUTPUTDIR)\xprf2.obj \ 64 $(OUTPUTDIR)\xstring.obj 66 65 67 66 OBJS = $(CPOBJS) \ 68 $(OUTPUTDIR)\animate.obj \ 69 $(OUTPUTDIR)\cctl_chart.obj \ 70 $(OUTPUTDIR)\cctl_checkcnr.obj \ 71 $(OUTPUTDIR)\cctl_progbar.obj \ 72 $(OUTPUTDIR)\cctl_splitwin.obj \ 73 $(OUTPUTDIR)\cctl_tooltip.obj \ 74 $(OUTPUTDIR)\comctl.obj \ 75 $(OUTPUTDIR)\cnrh.obj \ 76 $(OUTPUTDIR)\gpih.obj \ 77 $(OUTPUTDIR)\memdebug.obj \ 78 $(OUTPUTDIR)\shapewin.obj \ 79 $(OUTPUTDIR)\textview.obj \ 80 $(OUTPUTDIR)\textv_html.obj \ 81 $(OUTPUTDIR)\winh.obj 67 $(OUTPUTDIR)\animate.obj \ 68 $(OUTPUTDIR)\cctl_chart.obj \ 69 $(OUTPUTDIR)\cctl_checkcnr.obj \ 70 $(OUTPUTDIR)\cctl_progbar.obj \ 71 $(OUTPUTDIR)\cctl_splitwin.obj \ 72 $(OUTPUTDIR)\cctl_tooltip.obj \ 73 $(OUTPUTDIR)\comctl.obj \ 74 $(OUTPUTDIR)\cnrh.obj \ 75 $(OUTPUTDIR)\gpih.obj \ 76 $(OUTPUTDIR)\memdebug.obj \ 77 $(OUTPUTDIR)\memdebug_win.obj \ 78 $(OUTPUTDIR)\shapewin.obj \ 79 $(OUTPUTDIR)\threads.obj \ 80 $(OUTPUTDIR)\textview.obj \ 81 $(OUTPUTDIR)\textv_html.obj \ 82 $(OUTPUTDIR)\winh.obj 82 83 83 84 # helpers include path -
trunk/src/helpers/makefile
r9 r13 136 136 # The exclamation point ( ! ) preceding the LIB command causes NMAKE 137 137 # to execute the LIB command once for each dependent file in the list. 138 138 139 $(OUTPUTDIR)\helpers.lib: $(OBJS) 139 140 !ifdef EMX 140 !emxomfar cr $ (OUTPUTDIR)\helpers.lib$?141 !emxomfar cr $* $? 141 142 !else 142 !ilib /nol /nob $(OUTPUTDIR)\helpers.lib -+$?; 143 !ilib /nol /nob $* -+$?; 144 !endif 145 146 # same thing for cp.lib 147 $(OUTPUTDIR)\cp.lib: $(CPOBJS) 148 !ifdef EMX 149 !emxomfar cr $* $? 150 !else 151 !ilib /nol /nob $* -+$?; 152 !endif 153 154 # same thing for plainc.lib 155 $(OUTPUTDIR)\plainc.lib: $(PLAINCOBJS) 156 !ifdef EMX 157 !emxomfar cr $* $? 158 !else 159 !ilib /nol /nob $* -+$?; 143 160 !endif 144 161 -
trunk/src/helpers/memdebug.c
r8 r13 1 1 2 2 /* 3 * memdebug.c: 4 * memory debugging helpers. Memory debugging is enabled 5 * if the __XWPMEMDEBUG__ #define is set in setup.h. 3 *@@sourcefile memdebug.c: 4 * memory debugging helpers. 6 5 * 7 6 * Several things are in here which might turn out to … … 12 11 * -- Sophisticated heap debugging functions, which 13 12 * automatically replace malloc() and free() etc. 14 * when XWorkplace is compiled with debug code. 13 * If the __XWPMEMDEBUG__ #define is set before including 14 * memdebug.h, all those standard library calls 15 * are remapped to use the functions in this file 16 * instead. 17 * 18 * At present, malloc(), calloc(), realloc(), strdup() 19 * and free() are supported. 20 * 15 21 * These log every memory allocation made and log 16 22 * much more data compared to the VAC++ memory … … 28 34 * function. 29 35 * 30 * At present, malloc(), calloc(), strdup() and free()31 * are supported. If you invoke free() on a memory block32 * allocated by a function other than the above, you'll33 * get a runtime error.34 *35 36 * These debug functions have been added with V0.9.3 36 37 * and should now be compiler-independent. 37 38 * 38 * -- A PM heap debugging window which shows the statuzs 39 * V0.9.6 added realloc() support and fixed a few bugs. 40 * 41 * -- A PM heap debugging window which shows the status 39 42 * of the heap logging list. See memdCreateMemDebugWindow 40 * for details. 41 * 42 * To enable memory debugging, do the following: 43 * (memdebug_win.c) for details. 44 * 45 * To enable memory debugging, do the following in each (!) 46 * of your code modules: 43 47 * 44 48 * 1) Include at least <stdlib.h> and <string.h>. … … 53 57 * That's all. XWorkplace's setup.h does this automatically 54 58 * if XWorkplace is compiled with debug code. 59 * 60 * A couple of WARNINGS: 61 * 62 * 1) Memory debugging can greatly slow down the system 63 * after a while. When free() is invoked, the memory 64 * that was allocated is freed, but not the memory 65 * log entry (the HEAPITEM) to allow tracing what was 66 * freed. As a result, the linked list of memory items 67 * keeps growing longer, and free() becomes terribly 68 * slow after a while because it must traverse the 69 * entire list for each free() call. Use memdReleaseFreed 70 * from time to time. 71 * 72 * 2) The replacement functions in this file allocate 73 * extra memory for the magic strings. For example, if 74 * you call malloc(100), more than 100 bytes get allocated 75 * to allow for storing the magic strings to detect 76 * memory overwrites. Two magic strings are allocated, 77 * one before the actual buffer, and one behind it. 78 * 79 * As a result, YOU MUST NOT confuse the replacement 80 * memory functions with the original ones. If you 81 * use malloc() in one source file and free() the 82 * buffer in another one where debug memory has not 83 * been enabled, you'll get crashes. 84 * 85 * As a rule of thumb, enable memory debugging for all 86 * your source files or for none. And make sure everything 87 * is recompiled when you change your mind. 55 88 * 56 89 *@@added V0.9.1 (2000-02-12) [umoeller] … … 80 113 #define INCL_DOSERRORS 81 114 82 #define INCL_WINWINDOWMGR83 #define INCL_WINFRAMEMGR84 #define INCL_WINCOUNTRY85 #define INCL_WINSYS86 #define INCL_WINMENUS87 #define INCL_WINSTDCNR88 115 #include <os2.h> 89 116 90 117 #include <stdio.h> 91 118 #include <string.h> 92 // #include <malloc.h>93 119 #include <setjmp.h> 94 120 95 #define DONT_REPLACE_MALLOC // we need the "real" malloc in this file 121 #define DONT_REPLACE_MALLOC // never do debug memory for this 122 #define MEMDEBUG_PRIVATE 96 123 #include "setup.h" 97 124 98 125 #ifdef __XWPMEMDEBUG__ 99 126 100 #include "helpers\cnrh.h"101 127 #include "helpers\except.h" 102 //#include "helpers\memdebug.h" // included by setup.h already128 #include "helpers\memdebug.h" // included by setup.h already 103 129 #include "helpers\stringh.h" 104 #include "helpers\winh.h"105 130 106 131 /* … … 120 145 #define MEMBLOCKMAGIC_TAIL "\250\210&%/dfjsk%#,dlhf\223" 121 146 122 /*123 *@@ HEAPITEM:124 * informational structure created for each125 * malloc() call by memdMalloc. These are stored126 * in a global linked list (G_pHeapItemsRoot).127 *128 * We cannot use the linklist.c functions for129 * managing the linked list because these use130 * malloc in turn, which would lead to infinite131 * loops.132 *133 *@@added V0.9.3 (2000-04-11) [umoeller]134 */135 136 typedef struct _HEAPITEM137 {138 struct _HEAPITEM *pNext; // next item in linked list or NULL if last139 140 void *pAfterMagic; // memory pointer returned by memdMalloc;141 // this points to after the magic string142 unsigned long ulSize; // size of *pData143 144 const char *pcszSourceFile; // as passed to memdMalloc145 unsigned long ulLine; // as passed to memdMalloc146 const char *pcszFunction; // as passed to memdMalloc147 148 DATETIME dtAllocated; // system date/time at time of memdMalloc call149 150 ULONG ulTID; // thread ID that memdMalloc was running on151 152 BOOL fFreed; // TRUE only after item has been freed by memdFree153 } HEAPITEM, *PHEAPITEM;154 155 147 HMTX G_hmtxMallocList = NULLHANDLE; 156 148 157 PHEAPITEM G_pHeapItemsRoot = NULL, 158 G_pHeapItemsLast = NULL; 159 160 PSZ G_pszMemCnrTitle = NULL; 149 extern PHEAPITEM G_pHeapItemsRoot = NULL; 150 PHEAPITEM G_pHeapItemsLast = NULL; 161 151 162 152 PFNCBMEMDLOG G_pMemdLogFunc = NULL; 163 153 164 ULONG G_ulItemsReleased = 0, 165 154 extern ULONG G_ulItemsReleased = 0; 155 extern ULONG G_ulBytesReleased = 0; 166 156 167 157 /* ****************************************************************** … … 189 179 arc = DosCreateMutexSem(NULL, 190 180 &G_hmtxMallocList, 191 0, 192 FALSE);193 194 arc = DosRequestMutexSem(G_hmtxMallocList,195 SEM_INDEFINITE_WAIT);181 0, // unshared 182 TRUE); // request now! 183 else 184 arc = DosRequestMutexSem(G_hmtxMallocList, 185 SEM_INDEFINITE_WAIT); 196 186 197 187 return (arc == NO_ERROR); … … 435 425 pHeapItem->fFreed = TRUE; 436 426 437 /* lstRemoveNode(&G_llHeapItems,438 pNode); */439 427 fFound = TRUE; 440 428 break; 441 } 429 } // if (!pHeapItem->fFreed) 442 430 443 431 pHeapItem = pHeapItem->pNext; … … 452 440 CHAR szMsg[1000]; 453 441 sprintf(szMsg, 454 "free() failed. Calledfrom %s (%s, line %d) for object 0x%lX.",442 "free() called with invalid object from %s (%s, line %d) for object 0x%lX.", 455 443 pcszFunction, 456 444 pcszSourceFile, … … 459 447 G_pMemdLogFunc(szMsg); 460 448 } 449 } 450 451 /* 452 *@@ memdRealloc: 453 * wrapper function for realloc(). See memdMalloc for 454 * details. 455 * 456 *@@added V0.9.6 (2000-11-12) [umoeller] 457 */ 458 459 void* memdRealloc(void *p, 460 size_t stSize, 461 const char *pcszSourceFile, // in: source file name 462 unsigned long ulLine, // in: source line 463 const char *pcszFunction) // in: function name 464 { 465 void *prc = NULL; 466 BOOL fFound = FALSE; 467 468 if (memdLock()) 469 { 470 PHEAPITEM pHeapItem = G_pHeapItemsRoot; 471 472 // search the list with the pointer which was 473 // really returned by the original malloc(), 474 // that is, the byte before the magic string 475 void *pBeforeMagic = ((PBYTE)p) - sizeof(MEMBLOCKMAGIC_HEAD); 476 477 while (pHeapItem) 478 { 479 if (pHeapItem->pAfterMagic == p) 480 // the same address may be allocated and freed 481 // several times, so if this address has been 482 // freed, search on 483 if (!pHeapItem->fFreed) 484 { 485 // found: 486 PVOID pObjNew = 0; 487 ULONG ulError = 0; 488 ULONG cbCopy = 0; 489 PTIB ptib; 490 PPIB ppib; 491 492 // check magic string 493 if (memcmp(pBeforeMagic, 494 MEMBLOCKMAGIC_HEAD, 495 sizeof(MEMBLOCKMAGIC_HEAD)) 496 != 0) 497 ulError = 1; 498 else if (memcmp(((PBYTE)pHeapItem->pAfterMagic) + pHeapItem->ulSize, 499 MEMBLOCKMAGIC_TAIL, 500 sizeof(MEMBLOCKMAGIC_TAIL)) 501 != 0) 502 ulError = 2; 503 504 if (ulError) 505 { 506 // magic block has been overwritten: 507 if (G_pMemdLogFunc) 508 { 509 CHAR szMsg[1000]; 510 sprintf(szMsg, 511 "Magic string %s memory block at 0x%lX has been overwritten.\n" 512 "This was detected by the realloc() call at %s (%s, line %d).\n" 513 "The block was allocated by %s (%s, line %d).", 514 (ulError == 1) ? "before" : "after", 515 p, 516 pcszFunction, 517 pcszSourceFile, 518 ulLine, // free 519 pHeapItem->pcszFunction, 520 pHeapItem->pcszSourceFile, 521 pHeapItem->ulLine); 522 G_pMemdLogFunc(szMsg); 523 } 524 } 525 526 // now reallocate! 527 pObjNew = malloc(stSize // new size 528 + sizeof(MEMBLOCKMAGIC_HEAD) 529 + sizeof(MEMBLOCKMAGIC_TAIL)); 530 531 // store "front" magic string 532 memcpy(pObjNew, 533 MEMBLOCKMAGIC_HEAD, 534 sizeof(MEMBLOCKMAGIC_HEAD)); 535 // return address: first byte after "front" magic string 536 prc = ((PBYTE)pObjNew) + sizeof(MEMBLOCKMAGIC_HEAD); 537 538 // bytes to copy: the smaller of the old and the new size 539 cbCopy = pHeapItem->ulSize; 540 if (stSize < pHeapItem->ulSize) 541 cbCopy = stSize; 542 543 // copy buffer from old memory object 544 memcpy(prc, // after "front" magic 545 pHeapItem->pAfterMagic, 546 cbCopy); 547 548 // store "tail" magic string to block which 549 // will be returned plus the size which was requested 550 memcpy(((PBYTE)prc) + stSize, 551 MEMBLOCKMAGIC_TAIL, 552 sizeof(MEMBLOCKMAGIC_TAIL)); 553 554 // free the old buffer 555 free(pBeforeMagic); 556 557 // update the HEAPITEM 558 pHeapItem->pAfterMagic = prc; // new pointer! 559 pHeapItem->ulSize = stSize; // new size! 560 pHeapItem->pcszSourceFile = pcszSourceFile; 561 pHeapItem->ulLine = ulLine; 562 pHeapItem->pcszFunction = pcszFunction; 563 564 // update date, time, TID 565 DosGetDateTime(&pHeapItem->dtAllocated); 566 pHeapItem->ulTID = 0; 567 if (DosGetInfoBlocks(&ptib, &ppib) == NO_ERROR) 568 if (ptib) 569 if (ptib->tib_ptib2) 570 pHeapItem->ulTID = ptib->tib_ptib2->tib2_ultid; 571 572 fFound = TRUE; 573 break; 574 } // if (!pHeapItem->fFreed) 575 576 pHeapItem = pHeapItem->pNext; 577 } 578 579 memdUnlock(); 580 } 581 582 if (!fFound) 583 if (G_pMemdLogFunc) 584 { 585 CHAR szMsg[1000]; 586 sprintf(szMsg, 587 "realloc() called with invalid object from %s (%s, line %d) for object 0x%lX.", 588 pcszFunction, 589 pcszSourceFile, 590 ulLine, 591 p); 592 G_pMemdLogFunc(szMsg); 593 } 594 595 return (prc); 461 596 } 462 597 … … 485 620 while (pHeapItem) 486 621 { 622 // store next first, because we can change the "next" pointer 487 623 PHEAPITEM pNext = pHeapItem->pNext; // can be NULL 624 488 625 if (pHeapItem->fFreed) 489 626 { 490 // item freed:627 // item was freed: 491 628 if (pPrevious == NULL) 492 629 // head of list: … … 499 636 ulItemsReleased++; 500 637 ulBytesReleased += pHeapItem->ulSize; 638 639 if (pHeapItem == G_pHeapItemsLast) 640 // reset "last item" cache 641 G_pHeapItemsLast = NULL; 501 642 502 643 free(pHeapItem); … … 550 691 #endif 551 692 552 /* ******************************************************************553 * *554 * Heap debugging window *555 * *556 ********************************************************************/557 558 /*559 *@@ MEMRECORD:560 *561 *@@added V0.9.1 (99-12-04) [umoeller]562 */563 564 typedef struct _MEMRECORD565 {566 RECORDCORE recc;567 568 ULONG ulIndex;569 570 CDATE cdateAllocated;571 CTIME ctimeAllocated;572 573 PSZ pszFreed;574 575 ULONG ulTID;576 577 PSZ pszFunction; // points to szFunction578 CHAR szFunction[400];579 580 PSZ pszSource; // points to szSource581 CHAR szSource[CCHMAXPATH];582 583 ULONG ulLine;584 585 PSZ pszAddress; // points to szAddress586 CHAR szAddress[20];587 588 ULONG ulSize;589 590 } MEMRECORD, *PMEMRECORD;591 592 /* ULONG ulHeapItemsCount1,593 ulHeapItemsCount2;594 ULONG ulTotalAllocated,595 ulTotalFreed;596 PMEMRECORD pMemRecordThis = NULL;597 PSZ pszMemCnrTitle = NULL; */598 599 #if 0600 /*601 *@@ fncbMemHeapWalkCount:602 * callback func for _heap_walk function used for603 * fnwpMemDebug.604 *605 *@@added V0.9.1 (99-12-04) [umoeller]606 */607 608 int fncbMemHeapWalkCount(const void *pObject,609 size_t Size,610 int useflag,611 int status,612 const char *filename,613 size_t line)614 {615 // skip all the items which seem to be616 // internal to the runtime617 if ((filename) || (useflag == _FREEENTRY))618 {619 ulHeapItemsCount1++;620 if (useflag == _FREEENTRY)621 ulTotalFreed += Size;622 else623 ulTotalAllocated += Size;624 }625 return (0);626 }627 628 /*629 *@@ fncbMemHeapWalkFill:630 * callback func for _heap_walk function used for631 * fnwpMemDebug.632 *633 *@@added V0.9.1 (99-12-04) [umoeller]634 */635 636 int fncbMemHeapWalkFill(const void *pObject,637 size_t Size,638 int useflag,639 int status,640 const char *filename,641 size_t line)642 {643 // skip all the items which seem to be644 // internal to the runtime645 if ((filename) || (useflag == _FREEENTRY))646 {647 ulHeapItemsCount2++;648 if ((pMemRecordThis) && (ulHeapItemsCount2 < ulHeapItemsCount1))649 {650 pMemRecordThis->ulIndex = ulHeapItemsCount2 - 1;651 652 pMemRecordThis->pObject = pObject;653 pMemRecordThis->useflag = useflag;654 pMemRecordThis->status = status;655 pMemRecordThis->filename = filename;656 657 pMemRecordThis->pszAddress = pMemRecordThis->szAddress;658 659 pMemRecordThis->ulSize = Size;660 661 pMemRecordThis->pszSource = pMemRecordThis->szSource;662 663 pMemRecordThis->ulLine = line;664 665 pMemRecordThis = (PMEMRECORD)pMemRecordThis->recc.preccNextRecord;666 }667 else668 return (1); // stop669 }670 671 return (0);672 }673 674 /*675 *@@ memdCreateRecordsVAC:676 *677 *@@added V0.9.3 (2000-04-10) [umoeller]678 */679 680 VOID memdCreateRecordsVAC(HWND hwndCnr)681 {682 // count heap items683 ulHeapItemsCount1 = 0;684 ulTotalFreed = 0;685 ulTotalAllocated = 0;686 _heap_walk(fncbMemHeapWalkCount);687 688 pMemRecordFirst = (PMEMRECORD)cnrhAllocRecords(hwndCnr,689 sizeof(MEMRECORD),690 ulHeapItemsCount1);691 if (pMemRecordFirst)692 {693 ulHeapItemsCount2 = 0;694 pMemRecordThis = pMemRecordFirst;695 _heap_walk(fncbMemHeapWalkFill);696 697 // the following doesn't work while _heap_walk is running698 pMemRecordThis = pMemRecordFirst;699 while (pMemRecordThis)700 {701 switch (pMemRecordThis->useflag)702 {703 case _USEDENTRY: pMemRecordThis->pszUseFlag = "Used"; break;704 case _FREEENTRY: pMemRecordThis->pszUseFlag = "Freed"; break;705 }706 707 switch (pMemRecordThis->status)708 {709 case _HEAPBADBEGIN: pMemRecordThis->pszStatus = "heap bad begin"; break;710 case _HEAPBADNODE: pMemRecordThis->pszStatus = "heap bad node"; break;711 case _HEAPEMPTY: pMemRecordThis->pszStatus = "heap empty"; break;712 case _HEAPOK: pMemRecordThis->pszStatus = "OK"; break;713 }714 715 sprintf(pMemRecordThis->szAddress, "0x%lX", pMemRecordThis->pObject);716 strcpy(pMemRecordThis->szSource,717 (pMemRecordThis->filename)718 ? pMemRecordThis->filename719 : "?");720 721 pMemRecordThis = (PMEMRECORD)pMemRecordThis->recc.preccNextRecord;722 }723 724 cnrhInsertRecords(hwndCnr,725 NULL, // parent726 (PRECORDCORE)pMemRecordFirst,727 TRUE,728 NULL,729 CRA_RECORDREADONLY,730 ulHeapItemsCount2);731 }732 }733 734 #endif735 736 /*737 *@@ memdCreateRecords:738 *739 *@@added V0.9.3 (2000-04-10) [umoeller]740 */741 742 VOID memdCreateRecords(HWND hwndCnr,743 PULONG pulTotalItems,744 PULONG pulAllocatedItems,745 PULONG pulFreedItems,746 PULONG pulTotalBytes,747 PULONG pulAllocatedBytes,748 PULONG pulFreedBytes)749 {750 // count heap items751 ULONG ulHeapItemsCount1 = 0;752 PMEMRECORD pMemRecordFirst;753 754 if (memdLock())755 {756 // PLISTNODE pNode = lstQueryFirstNode(&G_llHeapItems);757 PHEAPITEM pHeapItem = G_pHeapItemsRoot;758 759 *pulTotalItems = 0;760 *pulAllocatedItems = 0;761 *pulFreedItems = 0;762 763 *pulTotalBytes = 0;764 *pulAllocatedBytes = 0;765 *pulFreedBytes = 0;766 767 while (pHeapItem)768 {769 ulHeapItemsCount1++;770 if (pHeapItem->fFreed)771 {772 (*pulFreedItems)++;773 (*pulFreedBytes) += pHeapItem->ulSize;774 }775 else776 {777 (*pulAllocatedItems)++;778 (*pulAllocatedBytes) += pHeapItem->ulSize;779 }780 781 (*pulTotalBytes) += pHeapItem->ulSize;782 783 pHeapItem = pHeapItem->pNext;784 }785 786 *pulTotalItems = ulHeapItemsCount1;787 788 pMemRecordFirst = (PMEMRECORD)cnrhAllocRecords(hwndCnr,789 sizeof(MEMRECORD),790 ulHeapItemsCount1);791 if (pMemRecordFirst)792 {793 ULONG ulHeapItemsCount2 = 0;794 PMEMRECORD pMemRecordThis = pMemRecordFirst;795 pHeapItem = G_pHeapItemsRoot;796 // PLISTNODE pMemNode = lstQueryFirstNode(&G_llHeapItems);797 798 while ((pMemRecordThis) && (pHeapItem))799 {800 // PHEAPITEM pHeapItem = (PHEAPITEM)pMemNode->pItemData;801 802 pMemRecordThis->ulIndex = ulHeapItemsCount2++;803 804 cnrhDateTimeDos2Win(&pHeapItem->dtAllocated,805 &pMemRecordThis->cdateAllocated,806 &pMemRecordThis->ctimeAllocated);807 808 if (pHeapItem->fFreed)809 pMemRecordThis->pszFreed = "yes";810 811 pMemRecordThis->ulTID = pHeapItem->ulTID;812 813 strcpy(pMemRecordThis->szSource, pHeapItem->pcszSourceFile);814 pMemRecordThis->pszSource = pMemRecordThis->szSource;815 816 pMemRecordThis->ulLine = pHeapItem->ulLine;817 818 strcpy(pMemRecordThis->szFunction, pHeapItem->pcszFunction);819 pMemRecordThis->pszFunction = pMemRecordThis->szFunction;820 821 sprintf(pMemRecordThis->szAddress, "0x%lX", pHeapItem->pAfterMagic);822 pMemRecordThis->pszAddress = pMemRecordThis->szAddress;823 824 pMemRecordThis->ulSize = pHeapItem->ulSize;825 826 827 /* switch (pMemRecordThis->useflag)828 {829 case _USEDENTRY: pMemRecordThis->pszUseFlag = "Used"; break;830 case _FREEENTRY: pMemRecordThis->pszUseFlag = "Freed"; break;831 }832 833 switch (pMemRecordThis->status)834 {835 case _HEAPBADBEGIN: pMemRecordThis->pszStatus = "heap bad begin"; break;836 case _HEAPBADNODE: pMemRecordThis->pszStatus = "heap bad node"; break;837 case _HEAPEMPTY: pMemRecordThis->pszStatus = "heap empty"; break;838 case _HEAPOK: pMemRecordThis->pszStatus = "OK"; break;839 }840 841 sprintf(pMemRecordThis->szAddress, "0x%lX", pMemRecordThis->pObject);842 strcpy(pMemRecordThis->szSource,843 (pMemRecordThis->filename)844 ? pMemRecordThis->filename845 : "?"); */846 847 pMemRecordThis = (PMEMRECORD)pMemRecordThis->recc.preccNextRecord;848 pHeapItem = pHeapItem->pNext;849 }850 851 cnrhInsertRecords(hwndCnr,852 NULL, // parent853 (PRECORDCORE)pMemRecordFirst,854 TRUE,855 NULL,856 CRA_RECORDREADONLY,857 ulHeapItemsCount2);858 }859 860 memdUnlock();861 }862 }863 864 /*865 *@@ mnu_fnCompareIndex:866 *867 *@@added V0.9.1 (99-12-03) [umoeller]868 */869 870 SHORT EXPENTRY mnu_fnCompareIndex(PMEMRECORD pmrc1, PMEMRECORD pmrc2, PVOID pStorage)871 {872 // HAB habDesktop = WinQueryAnchorBlock(HWND_DESKTOP);873 pStorage = pStorage; // to keep the compiler happy874 if ((pmrc1) && (pmrc2))875 if (pmrc1->ulIndex < pmrc2->ulIndex)876 return (-1);877 else if (pmrc1->ulIndex > pmrc2->ulIndex)878 return (1);879 880 return (0);881 }882 883 /*884 *@@ mnu_fnCompareSourceFile:885 *886 *@@added V0.9.1 (99-12-03) [umoeller]887 */888 889 SHORT EXPENTRY mnu_fnCompareSourceFile(PMEMRECORD pmrc1, PMEMRECORD pmrc2, PVOID pStorage)890 {891 HAB habDesktop = WinQueryAnchorBlock(HWND_DESKTOP);892 pStorage = pStorage; // to keep the compiler happy893 if ((pmrc1) && (pmrc2))894 switch (WinCompareStrings(habDesktop, 0, 0,895 pmrc1->szSource,896 pmrc2->szSource,897 0))898 {899 case WCS_LT: return (-1);900 case WCS_GT: return (1);901 default: // equal902 if (pmrc1->ulLine < pmrc2->ulLine)903 return (-1);904 else if (pmrc1->ulLine > pmrc2->ulLine)905 return (1);906 907 }908 909 return (0);910 }911 912 #define ID_MEMCNR 1000913 914 /*915 *@@ memd_fnwpMemDebug:916 * client window proc for the heap debugger window917 * accessible from the Desktop context menu if918 * __XWPMEMDEBUG__ is defined. Otherwise, this is not919 * compiled.920 *921 * Usage: this is a regular PM client window procedure922 * to be used with WinRegisterClass and WinCreateStdWindow.923 * See dtpMenuItemSelected, which uses this.924 *925 * This creates a container with all the memory objects926 * with the size of the client area in turn.927 *928 *@@added V0.9.1 (99-12-04) [umoeller]929 */930 931 932 MRESULT EXPENTRY memd_fnwpMemDebug(HWND hwndClient, ULONG msg, MPARAM mp1, MPARAM mp2)933 {934 MRESULT mrc = 0;935 936 switch (msg)937 {938 case WM_CREATE:939 {940 TRY_LOUD(excpt1, NULL)941 {942 // PCREATESTRUCT pcs = (PCREATESTRUCT)mp2;943 HWND hwndCnr;944 hwndCnr = WinCreateWindow(hwndClient, // parent945 WC_CONTAINER,946 "",947 WS_VISIBLE | CCS_MINIICONS | CCS_READONLY | CCS_SINGLESEL,948 0, 0, 0, 0,949 hwndClient, // owner950 HWND_TOP,951 ID_MEMCNR,952 NULL, NULL);953 if (hwndCnr)954 {955 XFIELDINFO xfi[11];956 PFIELDINFO pfi = NULL;957 PMEMRECORD pMemRecordFirst;958 int i = 0;959 960 ULONG ulTotalItems = 0,961 ulAllocatedItems = 0,962 ulFreedItems = 0;963 ULONG ulTotalBytes = 0,964 ulAllocatedBytes = 0,965 ulFreedBytes = 0;966 967 // set up cnr details view968 xfi[i].ulFieldOffset = FIELDOFFSET(MEMRECORD, ulIndex);969 xfi[i].pszColumnTitle = "No.";970 xfi[i].ulDataType = CFA_ULONG;971 xfi[i++].ulOrientation = CFA_RIGHT;972 973 xfi[i].ulFieldOffset = FIELDOFFSET(MEMRECORD, cdateAllocated);974 xfi[i].pszColumnTitle = "Date";975 xfi[i].ulDataType = CFA_DATE;976 xfi[i++].ulOrientation = CFA_LEFT;977 978 xfi[i].ulFieldOffset = FIELDOFFSET(MEMRECORD, ctimeAllocated);979 xfi[i].pszColumnTitle = "Time";980 xfi[i].ulDataType = CFA_TIME;981 xfi[i++].ulOrientation = CFA_LEFT;982 983 xfi[i].ulFieldOffset = FIELDOFFSET(MEMRECORD, pszFreed);984 xfi[i].pszColumnTitle = "Freed";985 xfi[i].ulDataType = CFA_STRING;986 xfi[i++].ulOrientation = CFA_CENTER;987 988 xfi[i].ulFieldOffset = FIELDOFFSET(MEMRECORD, ulTID);989 xfi[i].pszColumnTitle = "TID";990 xfi[i].ulDataType = CFA_ULONG;991 xfi[i++].ulOrientation = CFA_RIGHT;992 993 xfi[i].ulFieldOffset = FIELDOFFSET(MEMRECORD, pszFunction);994 xfi[i].pszColumnTitle = "Function";995 xfi[i].ulDataType = CFA_STRING;996 xfi[i++].ulOrientation = CFA_LEFT;997 998 xfi[i].ulFieldOffset = FIELDOFFSET(MEMRECORD, pszSource);999 xfi[i].pszColumnTitle = "Source";1000 xfi[i].ulDataType = CFA_STRING;1001 xfi[i++].ulOrientation = CFA_LEFT;1002 1003 xfi[i].ulFieldOffset = FIELDOFFSET(MEMRECORD, ulLine);1004 xfi[i].pszColumnTitle = "Line";1005 xfi[i].ulDataType = CFA_ULONG;1006 xfi[i++].ulOrientation = CFA_RIGHT;1007 1008 xfi[i].ulFieldOffset = FIELDOFFSET(MEMRECORD, ulSize);1009 xfi[i].pszColumnTitle = "Size";1010 xfi[i].ulDataType = CFA_ULONG;1011 xfi[i++].ulOrientation = CFA_RIGHT;1012 1013 xfi[i].ulFieldOffset = FIELDOFFSET(MEMRECORD, pszAddress);1014 xfi[i].pszColumnTitle = "Address";1015 xfi[i].ulDataType = CFA_STRING;1016 xfi[i++].ulOrientation = CFA_LEFT;1017 1018 pfi = cnrhSetFieldInfos(hwndCnr,1019 &xfi[0],1020 i, // array item count1021 TRUE, // no draw lines1022 3); // return column1023 1024 {1025 PSZ pszFont = "9.WarpSans";1026 WinSetPresParam(hwndCnr,1027 PP_FONTNAMESIZE,1028 strlen(pszFont),1029 pszFont);1030 }1031 1032 memdCreateRecords(hwndCnr,1033 &ulTotalItems,1034 &ulAllocatedItems,1035 &ulFreedItems,1036 &ulTotalBytes,1037 &ulAllocatedBytes,1038 &ulFreedBytes);1039 1040 BEGIN_CNRINFO()1041 {1042 CHAR szCnrTitle[1000];1043 CHAR szTotalItems[100],1044 szAllocatedItems[100],1045 szFreedItems[100],1046 szReleasedItems[100];1047 CHAR szTotalBytes[100],1048 szAllocatedBytes[100],1049 szFreedBytes[100],1050 szReleasedBytes[100];1051 sprintf(szCnrTitle,1052 "Total logs in use: %s items = %s bytes\n"1053 " Total in use: %s items = %s bytes\n"1054 " Total freed: %s items = %s bytes\n"1055 "Total logs released: %s items = %s bytes",1056 strhThousandsDouble(szTotalItems,1057 ulTotalItems,1058 '.'),1059 strhThousandsDouble(szTotalBytes,1060 ulTotalBytes,1061 '.'),1062 strhThousandsDouble(szAllocatedItems,1063 ulAllocatedItems,1064 '.'),1065 strhThousandsDouble(szAllocatedBytes,1066 ulAllocatedBytes,1067 '.'),1068 strhThousandsDouble(szFreedItems,1069 ulFreedItems,1070 '.'),1071 strhThousandsDouble(szFreedBytes,1072 ulFreedBytes,1073 '.'),1074 strhThousandsDouble(szReleasedItems,1075 G_ulItemsReleased,1076 '.'),1077 strhThousandsDouble(szReleasedBytes,1078 G_ulBytesReleased,1079 '.'));1080 G_pszMemCnrTitle = strdup(szCnrTitle);1081 cnrhSetTitle(G_pszMemCnrTitle);1082 cnrhSetView(CV_DETAIL | CV_MINI | CA_DETAILSVIEWTITLES1083 | CA_DRAWICON1084 | CA_CONTAINERTITLE | CA_TITLEREADONLY1085 | CA_TITLESEPARATOR | CA_TITLELEFT);1086 cnrhSetSplitBarAfter(pfi);1087 cnrhSetSplitBarPos(250);1088 } END_CNRINFO(hwndCnr);1089 1090 WinSetFocus(HWND_DESKTOP, hwndCnr);1091 }1092 }1093 CATCH(excpt1) {} END_CATCH();1094 1095 mrc = WinDefWindowProc(hwndClient, msg, mp1, mp2);1096 break; }1097 1098 case WM_WINDOWPOSCHANGED:1099 {1100 PSWP pswp = (PSWP)mp1;1101 mrc = WinDefWindowProc(hwndClient, msg, mp1, mp2);1102 if (pswp->fl & SWP_SIZE)1103 {1104 WinSetWindowPos(WinWindowFromID(hwndClient, ID_MEMCNR), // cnr1105 HWND_TOP,1106 0, 0, pswp->cx, pswp->cy,1107 SWP_SIZE | SWP_MOVE | SWP_SHOW);1108 }1109 break; }1110 1111 case WM_CONTROL:1112 {1113 USHORT usItemID = SHORT1FROMMP(mp1),1114 usNotifyCode = SHORT2FROMMP(mp1);1115 if (usItemID == ID_MEMCNR) // cnr1116 {1117 switch (usNotifyCode)1118 {1119 case CN_CONTEXTMENU:1120 {1121 PMEMRECORD precc = (PMEMRECORD)mp2;1122 if (precc == NULL)1123 {1124 // whitespace1125 HWND hwndMenu = WinCreateMenu(HWND_DESKTOP,1126 NULL); // no menu template1127 winhInsertMenuItem(hwndMenu,1128 MIT_END,1129 1001,1130 "Sort by index",1131 MIS_TEXT, 0);1132 winhInsertMenuItem(hwndMenu,1133 MIT_END,1134 1002,1135 "Sort by source file",1136 MIS_TEXT, 0);1137 cnrhShowContextMenu(WinWindowFromID(hwndClient, ID_MEMCNR),1138 NULL, // record1139 hwndMenu,1140 hwndClient);1141 }1142 }1143 }1144 }1145 break; }1146 1147 case WM_COMMAND:1148 switch (SHORT1FROMMP(mp1))1149 {1150 case 1001: // sort by index1151 WinSendMsg(WinWindowFromID(hwndClient, ID_MEMCNR),1152 CM_SORTRECORD,1153 (MPARAM)mnu_fnCompareIndex,1154 0);1155 break;1156 1157 case 1002: // sort by source file1158 WinSendMsg(WinWindowFromID(hwndClient, ID_MEMCNR),1159 CM_SORTRECORD,1160 (MPARAM)mnu_fnCompareSourceFile,1161 0);1162 break;1163 }1164 break;1165 1166 case WM_CLOSE:1167 WinDestroyWindow(WinWindowFromID(hwndClient, ID_MEMCNR));1168 WinDestroyWindow(WinQueryWindow(hwndClient, QW_PARENT));1169 free(G_pszMemCnrTitle);1170 G_pszMemCnrTitle = NULL;1171 break;1172 1173 default:1174 mrc = WinDefWindowProc(hwndClient, msg, mp1, mp2);1175 }1176 1177 return (mrc);1178 }1179 1180 /*1181 *@@ memdCreateMemDebugWindow:1182 * creates a heap debugging window which1183 * is a standard frame with a container,1184 * listing all heap objects ever allocated.1185 *1186 * The client of this standard frame is in1187 * memd_fnwpMemDebug.1188 *1189 * This thing lists all calls to malloc()1190 * which were ever made, including the1191 * source file and source line number which1192 * made the call. Extreeeemely useful for1193 * detecting memory leaks.1194 *1195 * This only works if the memory functions1196 * have been replaced with the debug versions1197 * in this file.1198 */1199 1200 VOID memdCreateMemDebugWindow(VOID)1201 {1202 ULONG flStyle = FCF_TITLEBAR | FCF_SYSMENU | FCF_HIDEMAX1203 | FCF_SIZEBORDER | FCF_SHELLPOSITION1204 | FCF_NOBYTEALIGN | FCF_TASKLIST;1205 if (WinRegisterClass(WinQueryAnchorBlock(HWND_DESKTOP),1206 "XWPMemDebug",1207 memd_fnwpMemDebug, 0L, 0))1208 {1209 HWND hwndClient;1210 HWND hwndMemFrame = WinCreateStdWindow(HWND_DESKTOP,1211 0L,1212 &flStyle,1213 "XWPMemDebug",1214 "Allocated XWorkplace Memory Objects",1215 0L,1216 NULLHANDLE, // resource1217 0,1218 &hwndClient);1219 if (hwndMemFrame)1220 {1221 WinSetWindowPos(hwndMemFrame,1222 HWND_TOP,1223 0, 0, 0, 0,1224 SWP_ZORDER | SWP_SHOW | SWP_ACTIVATE);1225 }1226 }1227 }1228 1229 693 #else 1230 694 void memdDummy(void) -
trunk/src/helpers/prfh.c
r8 r13 263 263 { 264 264 CHAR szColor[30]; 265 LONG r, g, b;265 ULONG r, g, b; 266 266 PrfQueryProfileString( 267 267 HINI_USER, … … 271 271 szColor, 272 272 sizeof(szColor)-1); 273 sscanf(szColor, "% d %d %d", &r, &g, &b);274 return ( r*0x10000 + g*0x100 + b);273 sscanf(szColor, "%lu %lu %lu ", &r, &g, &b); 274 return (LONG)(r*0x10000 + g*0x100 + b); 275 275 } 276 276 … … 468 468 if (PrfQueryProfile(hab, &Profiles)) 469 469 { 470 _Pmpf(("Old user profile: %s", Profiles.pszUserName));470 // _Pmpf(("Old user profile: %s", Profiles.pszUserName)); 471 471 472 472 // change INIs -
trunk/src/helpers/prfh2.c
r12 r13 98 98 if (fLog) 99 99 { 100 fprintf(fLog, " Error occured: %s\n Return code: %s (% d)\n",100 fprintf(fLog, " Error occured: %s\n Return code: %s (%lu)\n", 101 101 pszErrorString, 102 102 (ulrc == MBID_ABORT) ? "MBID_ABORT" … … 179 179 "hiniOld 0x%lX, pszOld %s, pfnwpCallback 0x%lX, " 180 180 "hwnd 0x%lX, msg 0x%lX, ulCount 0x%lX, ulMax 0x%lX\n", 181 hOld, pszOld, fncbUpdate, hwnd, msg, ulCount, ulMax); 181 hOld, 182 pszOld, 183 (ULONG)fncbUpdate, 184 hwnd, 185 msg, 186 ulCount, 187 ulMax); 182 188 fflush(fLog); 183 189 } … … 500 506 arc2 = doshSetPathAttr(szSysBackup, FILE_NORMAL); 501 507 if (fLog) 502 fprintf(fLog, " rc2: % d\n", arc2);508 fprintf(fLog, " rc2: %lu\n", arc2); 503 509 504 510 // delete OS2SYS.BAK … … 509 515 arc2 = DosDelete(szSysBackup); 510 516 if (fLog) 511 fprintf(fLog, " rc2: % d\n", arc2);517 fprintf(fLog, " rc2: %lu\n", arc2); 512 518 513 519 // attrib -r -s -h -a OS2SYS.INI … … 518 524 arc2 = doshSetPathAttr(Profiles.pszSysName, FILE_NORMAL); 519 525 if (fLog) 520 fprintf(fLog, " rc2: % d\n", arc2);526 fprintf(fLog, " rc2: %lu\n", arc2); 521 527 522 528 // move OS2SYS.INI OS2SYS.BAK … … 526 532 arc = DosMove(Profiles.pszSysName, szSysBackup); 527 533 if (fLog) 528 fprintf(fLog, " rc: % d\n", arc);534 fprintf(fLog, " rc: %lu\n", arc); 529 535 530 536 if (arc) … … 539 545 arc = DosMove(szSysNew, Profiles.pszSysName); 540 546 if (fLog) 541 fprintf(fLog, " rc: % d\n", arc);547 fprintf(fLog, " rc: %lu\n", arc); 542 548 if (arc) 543 549 ulErrorOccured = prfhINIError(MB_ABORTRETRYIGNORE, fLog, fncbError, "Error moving newly created profile to system profile."); … … 566 572 arc2 = doshSetPathAttr(szUserBackup, FILE_NORMAL); 567 573 if (fLog) 568 fprintf(fLog, " rc2: % d\n", arc2);574 fprintf(fLog, " rc2: %lu\n", arc2); 569 575 570 576 // delete OS2.BAK … … 575 581 arc2 = DosDelete(szUserBackup); 576 582 if (fLog) 577 fprintf(fLog, " rc2: % d\n", arc2);583 fprintf(fLog, " rc2: %lu\n", arc2); 578 584 579 585 // attrib -r -s -h -a OS2.INI … … 583 589 arc2 = doshSetPathAttr(Profiles.pszUserName, FILE_NORMAL); 584 590 if (fLog) 585 fprintf(fLog, " rc2: % d\n", arc2);591 fprintf(fLog, " rc2: %lu\n", arc2); 586 592 587 593 // move OS2.INI OS2.BAK … … 591 597 arc = DosMove(Profiles.pszUserName, szUserBackup); 592 598 if (fLog) 593 fprintf(fLog, " rc: % d\n", arc);599 fprintf(fLog, " rc: %lu\n", arc); 594 600 595 601 if (arc) … … 606 612 arc = DosMove(szUserNew, Profiles.pszUserName); 607 613 if (fLog) 608 fprintf(fLog, " rc: % d\n", arc);614 fprintf(fLog, " rc: %lu\n", arc); 609 615 610 616 if (arc) -
trunk/src/helpers/procstat.c
r8 r13 593 593 USHORT usSemID) // in: as in QPROCESS32.pausSem16 594 594 { 595 PQSEM32STRUC32 pSemThis = pInfo->pSem32Data;595 // PQSEM32STRUC32 pSemThis = pInfo->pSem32Data; 596 596 597 597 /* while (pSemThis) -
trunk/src/helpers/stringh.c
r12 r13 3 3 *@@sourcefile stringh.c: 4 4 * contains string/text helper functions. These are good for 5 * parsing/splitting strings and other stuff used throughout XWorkplace. 5 * parsing/splitting strings and other stuff used throughout 6 * XWorkplace. 7 * 8 * Note that these functions are really a bunch of very mixed 9 * up string helpers, which you may or may not find helpful. 10 * If you're looking for string functions with memory 11 * management, look at xstring.c instead. 6 12 * 7 13 * Usage: All OS/2 programs. … … 180 186 * this creates a new PSZ containing the string 181 187 * from pBegin to pEnd, excluding the pEnd character. 182 * The new string is null-terminated. 188 * The new string is null-terminated. The caller 189 * must free() the new string after use. 183 190 * 184 191 * Example: … … 424 431 * be free()'able. 425 432 * 426 * Use of this wrapper is not recommended because427 * it is considerably slower than xstrrpl.433 * Repetitive use of this wrapper is not recommended 434 * because it is considerably slower than xstrrpl. 428 435 * 429 436 *@@added V0.9.6 (2000-11-01) [umoeller] … … 431 438 432 439 ULONG strhrpl(PSZ *ppszBuf, // in/out: string 433 ULONG ulOfs, // in: where to begin search (0 = start)434 const char *pcszSearch, // in: search string; cannot be NULL435 const char *pcsz Replace, // in: replacementstring; cannot be NULL436 PULONG pulAfterOfs) // out: offset where found (ptr can be NULL)440 PULONG pulOfs, // in: where to begin search (0 = start); 441 // out: ofs of first char after replacement string 442 const char *pcszSearch, // in: search string; cannot be NULL 443 const char *pcszReplace) // in: replacement string; cannot be NULL 437 444 { 438 445 ULONG ulrc = 0; … … 440 447 xstrFind, 441 448 xstrReplace; 449 size_t ShiftTable[256]; 450 BOOL fRepeat = FALSE; 442 451 xstrInit(&xstrBuf, 0); 443 452 xstrset(&xstrBuf, *ppszBuf); … … 447 456 xstrset(&xstrReplace, (PSZ)pcszReplace); 448 457 449 if (ulrc = xstrrpl(&xstrBuf, ulOfs, &xstrFind, &xstrReplace, pulAfterOfs)) 458 if ((ulrc = xstrrpl(&xstrBuf, 459 pulOfs, 460 &xstrFind, 461 &xstrReplace, 462 ShiftTable, 463 &fRepeat))) 450 464 // replaced: 451 465 *ppszBuf = xstrBuf.psz; … … 482 496 * converts a ULONG into a decimal string, while 483 497 * inserting thousands separators into it. Specify 484 * the separator char in cThousands. 498 * the separator character in cThousands. 499 * 485 500 * Returns pszTarget so you can use it directly 486 501 * with sprintf and the "%s" flag. 502 * 487 503 * For cThousands, you should use the data in 488 504 * OS2.INI ("PM_National" application), which is 489 505 * always set according to the "Country" object. 506 * You can use prfhQueryCountrySettings to 507 * retrieve this setting. 508 * 490 509 * Use strhThousandsDouble for "double" values. 491 510 */ … … 497 516 USHORT ust, uss, usc; 498 517 CHAR szTemp[40]; 499 sprintf(szTemp, "% d", ul);518 sprintf(szTemp, "%lu", ul); 500 519 501 520 ust = 0; … … 548 567 549 568 /* 569 *@@ strhVariableDouble: 570 * like strhThousandsULong, but for a "double" value, and 571 * with a variable number of decimal places depending on the 572 * size of the quantity. 573 * 574 *@@added V0.9.6 (2000-11-12) [pr] 575 */ 576 577 PSZ strhVariableDouble(PSZ pszTarget, 578 double dbl, 579 PSZ pszUnits, 580 CHAR cThousands) 581 { 582 if (dbl < 100.0) 583 sprintf(pszTarget, "%.2f%s", dbl, pszUnits); 584 else 585 if (dbl < 1000.0) 586 sprintf(pszTarget, "%.1f%s", dbl, pszUnits); 587 else 588 strcat(strhThousandsDouble(pszTarget, dbl, cThousands), 589 pszUnits); 590 591 return(pszTarget); 592 } 593 594 /* 550 595 *@@ strhFileDate: 551 596 * converts file date data to a string (to pszBuf). … … 566 611 * cDateSep is used as a date separator (e.g. '.'). 567 612 * This can be queried using: 568 + 613 + prfhQueryProfileChar(HINI_USER, "PM_National", "sDate", '/'); 569 614 * 570 615 * Alternatively, you can query all the country settings 571 * at once using prfhQueryCountrySettings (prfh.c , new with V0.9.0).616 * at once using prfhQueryCountrySettings (prfh.c). 572 617 * 573 618 *@@changed (99-11-07) [umoeller]: now calling strhDateTime … … 611 656 * 612 657 * Alternatively, you can query all the country settings 613 * at once using prfhQueryCountrySettings (prfh.c , new with V0.9.0).658 * at once using prfhQueryCountrySettings (prfh.c). 614 659 * 615 660 *@@changed 99-03-15 fixed 12-hour crash … … 637 682 /* 638 683 *@@ strhDateTime: 639 * converts Control Program eDATETIME info640 * to two strings. See strhFileDate and strhFileTime684 * converts Control Program DATETIME info 685 * into two strings. See strhFileDate and strhFileTime 641 686 * for more detailed parameter descriptions. 642 687 * … … 821 866 822 867 /* 868 *@@ strhIsWord: 869 * returns TRUE if p points to a "word" 870 * in pcszBuf. 871 * 872 * p is considered a word if the character _before_ 873 * it is in pcszBeginChars and the char _after_ 874 * it (i.e. *(p+cbSearch)) is in pcszEndChars. 875 * 876 *@@added V0.9.6 (2000-11-12) [umoeller] 877 */ 878 879 BOOL strhIsWord(const char *pcszBuf, 880 const char *p, // in: start of word 881 ULONG cbSearch, // in: length of word 882 const char *pcszBeginChars, // suggestion: "\x0d\x0a ()/\\-,." 883 const char *pcszEndChars) // suggestion: "\x0d\x0a ()/\\-,.:;" 884 { 885 BOOL fEndOK = FALSE; 886 887 // check previous char 888 if ( (p == pcszBuf) 889 || (strchr(pcszBeginChars, *(p-1))) 890 ) 891 { 892 // OK, valid begin char: 893 // check end char 894 CHAR cNextChar = *(p + cbSearch); 895 if (cNextChar == 0) 896 fEndOK = TRUE; 897 else 898 { 899 char *pc = strchr(pcszEndChars, cNextChar); 900 if (pc) 901 // OK, is end char: avoid doubles of that char, 902 // but allow spaces 903 if ( (cNextChar+1 != *pc) 904 || (cNextChar+1 == ' ') 905 || (cNextChar+1 == 0) 906 ) 907 fEndOK = TRUE; 908 } 909 } 910 911 return (fEndOK); 912 } 913 914 /* 823 915 *@@ strhFindWord: 824 916 * searches for pszSearch in pszBuf, which is … … 836 928 * 837 929 * The algorithm here uses strstr to find pszSearch in pszBuf 838 * and performs additional "is-word" checks for each item found. 839 * With VAC++ 3.0, this is still much faster than searching 840 * words first and then comparing each word with pszSearch. 841 * I've tried it that way too, and that took nearly double as 842 * long. Apparently, the VAC++ runtime library uses some 843 * optimized search algorithm here, so we better use that one. 930 * and performs additional "is-word" checks for each item found 931 * (by calling strhIsWord). 932 * 933 * Note that this function is fairly slow compared to xstrFindWord. 844 934 * 845 935 *@@added V0.9.0 (99-11-08) [umoeller] … … 859 949 { 860 950 const char *p = pszBuf; 861 862 /* // go thru all characters863 while (*p)864 {865 // check if current character is either the866 // very first or a "begin word" character867 if ( (p == pszBuf)868 || (strchr(pcszBeginChars, *p) == 0)869 )870 {871 // yes: go for next872 if (*(++p))873 {874 // compare with search string875 if (strcmp(p, pszSearch) == 0)876 {877 // is the same:878 // check if still in buffer879 if (p < pszBuf + cbBuf)880 {881 CHAR cAfterEndOfWord = *(p + cbSearch);882 if (cAfterEndOfWord == 0)883 {884 // end of string:885 // that's ok886 pszReturn = (PSZ)p;887 break;888 }889 else890 {891 // check if in "end of word" list892 char *pc2 = strchr(pcszEndChars, cAfterEndOfWord);893 if (pc2)894 // OK, is end char: avoid doubles of that char,895 // but allow spaces896 if ( (cAfterEndOfWord+1 != *pc2)897 || (cAfterEndOfWord+1 == ' ')898 || (cAfterEndOfWord+1 == 0)899 )900 {901 // end of string:902 // that's ok903 pszReturn = (PSZ)p;904 break;905 }906 }907 }908 }909 }910 else911 // end of string:912 break;913 }914 915 ++p;916 } // end while917 */918 951 919 952 do // while p … … 925 958 // check if that's a word 926 959 927 // check previous char 928 if ( (p == pszBuf) 929 || (strchr(pcszBeginChars, *(p-1))) 930 ) 960 if (strhIsWord(pszBuf, 961 p, 962 cbSearch, 963 pcszBeginChars, 964 pcszEndChars)) 931 965 { 932 // OK, valid begin char: 933 BOOL fEndOK = FALSE; 934 // check end char 935 CHAR cNextChar = *(p + cbSearch); 936 if (cNextChar == 0) 937 fEndOK = TRUE; 938 else 939 { 940 char *pc = strchr(pcszEndChars, cNextChar); 941 if (pc) 942 // OK, is end char: avoid doubles of that char, 943 // but allow spaces 944 if ( (cNextChar+1 != *pc) 945 || (cNextChar+1 == ' ') 946 || (cNextChar+1 == 0) 947 ) 948 fEndOK = TRUE; 949 } 950 951 if (fEndOK) 952 { 953 // valid end char: 954 pszReturn = (PSZ)p; 955 break; 956 } 966 // valid end char: 967 pszReturn = (PSZ)p; 968 break; 957 969 } 970 958 971 p += cbSearch; 959 972 } … … 1186 1199 if (pEOL) 1187 1200 { 1188 XSTRING strBuf, 1189 strFind, 1190 strReplace; 1201 XSTRING strBuf; 1202 ULONG ulOfs = 0; 1191 1203 1192 1204 PSZ pszOldCopy = (PSZ)malloc(cbOldParam+1); … … 1196 1208 xstrInit(&strBuf, 0); 1197 1209 xstrset(&strBuf, *ppszBuf); // this must not be freed! 1198 xstrInit(&strFind, 0);1210 /* xstrInit(&strFind, 0); 1199 1211 xstrset(&strFind, pszOldCopy); // this must not be freed! 1200 1212 xstrInit(&strReplace, 0); 1201 1213 xstrset(&strReplace, pszNewParam); // this must not be freed! 1214 */ 1202 1215 1203 1216 // check for upper case desired? … … 1206 1219 strupr(pszNewParam); 1207 1220 1208 xstr rpl(&strBuf, 0, &strFind, &strReplace, NULL);1221 xstrcrpl(&strBuf, &ulOfs, pszOldCopy, pszNewParam); 1209 1222 1210 1223 free(pszOldCopy); … … 1373 1386 PSZ pParam; 1374 1387 if ((pParam = strhFindAttribValue(pszSearchIn, pszTag))) 1375 sscanf(pParam, "% d", pl);1388 sscanf(pParam, "%ld", pl); 1376 1389 1377 1390 return (pParam); … … 1799 1812 pszLine += ulIndent; 1800 1813 } 1801 pszLine += sprintf(pszLine, "%02lX ", *pbCurrent);1814 pszLine += sprintf(pszLine, "%02lX ", (ULONG)*pbCurrent); 1802 1815 1803 1816 if ( (*pbCurrent > 31) && (*pbCurrent < 127) ) … … 1869 1882 1870 1883 /* 1871 * @@skip_comp_os2:1884 * skip_comp_os2: 1872 1885 * Return a pointer to the next component of the path SRC, for OS/2 1873 1886 * and DOS styles. When the end of the string is reached, a pointer … … 2467 2480 2468 2481 /* 2469 *@@ strhfind: 2470 * searches for a pattern in a string using the Boyer-Moore- 2471 * Horspool-Sunday algorithm. The string and pattern are null-terminated 2472 * strings. Returns a pointer to the pattern if found within the string, 2473 * or NULL if the pattern was not found. If you repeatedly scan for the 2474 * same pattern, use the repeat_find argument. If this is TRUE, the 2475 * function does not re-parse the pattern. You must of course call the 2476 * function with repeat_find equal to FALSE the first time. This function 2477 * is meant to handle character data, and is most effective when you work 2478 * with large strings. To search binary data use strhmemfind(). Will not work 2479 * on multibyte characters. 2480 * 2481 * Examples: 2482 + char *result; 2482 *@@ strhmemfind: 2483 * searches for a pattern in a block of memory using the 2484 * Boyer-Moore-Horspool-Sunday algorithm. 2485 * 2486 * The block and pattern may contain any values; you must 2487 * explicitly provide their lengths. If you search for strings, 2488 * use strlen() on the buffers. 2489 * 2490 * Returns a pointer to the pattern if found within the block, 2491 * or NULL if the pattern was not found. 2492 * 2493 * This algorithm needs a "shift table" to cache data for the 2494 * search pattern. This table can be reused when performing 2495 * several searches with the same pattern. 2496 * 2497 * "shift" must point to an array big enough to hold 256 (8**2) 2498 * "size_t" values. 2499 * 2500 * If (*repeat_find == FALSE), the shift table is initialized. 2501 * So on the first search with a given pattern, *repeat_find 2502 * should be FALSE. This function sets it to TRUE after the 2503 * shift table is initialised, allowing the initialisation 2504 * phase to be skipped on subsequent searches. 2505 * 2506 * This function is most effective when repeated searches are 2507 * made for the same pattern in one or more large buffers. 2508 * 2509 * Example: 2510 * 2511 + PSZ pszHaystack = "This is a sample string.", 2512 + pszNeedle = "string"; 2513 + size_t shift[256]; 2514 + BOOL fRepeat = FALSE; 2483 2515 + 2484 + result = strhfind ("abracadabra", "cad", FALSE); 2485 + if (result) 2486 + puts (result); 2487 + 2516 + PSZ pFound = strhmemfind(pszHaystack, 2517 + strlen(pszHaystack), // block size 2518 + pszNeedle, 2519 + strlen(pszNeedle), // pattern size 2520 + shift, 2521 + &fRepeat); 2522 * 2488 2523 * Taken from the "Standard Function Library", file sflfind.c. 2489 2524 * Copyright: Copyright (c) 1991-99 iMatix Corporation. 2490 * Slightly modified .2525 * Slightly modified by umoeller. 2491 2526 * 2492 2527 *@@added V0.9.3 (2000-05-08) [umoeller] 2493 2528 */ 2494 2529 2495 char* strhfind (const char *string, // String containing data 2496 const char *pattern, // Pattern to search for 2497 BOOL repeat_find) // Same pattern as last time 2498 { 2499 static size_t 2500 searchbuf [256]; // Fixed search buffer 2501 2502 ASSERT (string); // Expect non-NULL pointers, but 2503 ASSERT (pattern); // fall through if not debugging 2504 2505 return (char *) strhmemfind_rb (string, strlen (string), 2506 pattern, strlen (pattern), 2507 searchbuf, &repeat_find); 2508 } 2509 2510 /* 2511 *@@ strhfind_r: 2512 * searches for a pattern in a string using the Boyer-Moore- 2513 * Horspool-Sunday algorithm. The string and pattern are null-terminated 2514 * strings. Returns a pointer to the pattern if found within the string, 2515 * or NULL if the pattern was not found. This function is meant to handle 2516 * character data, and is most effective when you work with large strings. 2517 * To search binary data use strhmemfind(). Will not work on multibyte 2518 * characters. Reentrant. 2519 * 2520 * Examples: 2521 + char *result; 2522 + 2523 + result = strhfind_r ("abracadabra", "cad"); 2524 + if (result) 2525 + puts (result); 2526 * 2527 * Taken from the "Standard Function Library", file sflfind.c. 2528 * Copyright: Copyright (c) 1991-99 iMatix Corporation. 2529 * Slightly modified. 2530 * 2531 *@@added V0.9.3 (2000-05-08) [umoeller] 2532 */ 2533 2534 char* strhfind_r (const char *string, // String containing data 2535 const char *pattern) // Pattern to search for 2536 { 2537 size_t 2538 searchbuf [256]; // One-time search buffer 2539 BOOL 2540 secondtime = FALSE; // Search buffer init needed 2541 2542 ASSERT (string); // Expect non-NULL pointers, but 2543 ASSERT (pattern); // fall through if not debugging 2544 2545 return (char *) strhmemfind_rb (string, strlen (string), 2546 pattern, strlen (pattern), 2547 searchbuf, &secondtime); 2548 } 2549 2550 /* 2551 *@@ strhfind_rb: 2552 * searches for a pattern in a string using the Boyer-Moore- 2553 * Horspool-Sunday algorithm. The string and pattern are null-terminated 2554 * strings. Returns a pointer to the pattern if found within the string, 2555 * or NULL if the pattern was not found. Supports more efficient repeat 2556 * searches (for the same pattern), through a supplied search buffer. The 2557 * search buffer must be long enough to contain 256 (2**8) size_t entries. 2558 * On the first call repeat_find must be set to FALSE. After the search 2559 * buffer has been initialised, repeat_find will be set to TRUE by the 2560 * function, avoiding the search buffer initialisation on later calls. 2561 * 2562 * This function is most effective when repeated searches are made for 2563 * the same pattern in one or more strings. This function is meant to 2564 * handle character data, and is most effective when you work with 2565 * large strings. To search binary data use strhmemfind(). Will not work 2566 * on multibyte characters. Reentrant. 2567 * 2568 * Examples: 2569 + char *result; 2570 + BOOL repeat_search = FALSE; 2571 + size_t searchbuf[256]; 2572 + 2573 + result = strhfind_rb ("abracadabra", "cad", searchbuf, &repeat_search); 2574 + if (result) 2575 + { 2576 + puts (result); 2577 + result = strhfind_rb ("cad/cam", "cad", searchbuf, &repeat_search); 2578 + if (result) 2579 + puts (result); 2580 + } 2581 * 2582 * Taken from the "Standard Function Library", file sflfind.c. 2583 * Copyright: Copyright (c) 1991-99 iMatix Corporation. 2584 * Slightly modified. 2585 * 2586 *@@added V0.9.3 (2000-05-08) [umoeller] 2587 */ 2588 2589 char* strhfind_rb (const char *string, // String containing data 2590 const char *pattern, // Pattern to search for 2591 size_t *shift, // Working buffer between searches 2592 BOOL *repeat_find) // Flag for first/later search 2593 { 2594 ASSERT (string); // Expect non-NULL pointers, but 2595 ASSERT (pattern); // fall through if not debugging 2596 ASSERT (shift); 2597 ASSERT (repeat_find); 2598 2599 return (char *) strhmemfind_rb (string, strlen (string), 2600 pattern, strlen (pattern), 2601 shift, repeat_find); 2602 } 2603 2604 /* 2605 *@@ strhmemfind: 2606 * searches for a pattern in a block of memory using the Boyer- 2607 * Moore-Horspool-Sunday algorithm. The block and pattern may contain any 2608 * values; you must explicitly provide their lengths. Returns a pointer to 2609 * the pattern if found within the block, or NULL if the pattern was not 2610 * found. If you repeatedly scan for the same pattern, use the repeat_find 2611 * argument. If this is TRUE, the function does not re-parse the pattern. 2612 * This function is meant to handle binary data. If you need to search 2613 * strings, use the strhfind_r or strhfind_rb() functions. Non-Reentrant. 2614 * 2615 * Taken from the "Standard Function Library", file sflfind.c. 2616 * Copyright: Copyright (c) 1991-99 iMatix Corporation. 2617 * Slightly modified. 2618 * 2619 *@@added V0.9.3 (2000-05-08) [umoeller] 2620 */ 2621 2622 void* strhmemfind (const void *block, // Block containing data 2623 size_t block_size, // Size of block in bytes 2624 const void *pattern, // Pattern to search for 2625 size_t pattern_size, // Size of pattern block 2626 BOOL repeat_find) // Same pattern as last time 2627 { 2628 static size_t 2629 searchbuf [256]; // Static shared search buffer 2630 2631 ASSERT (block); // Expect non-NULL pointers, but 2632 ASSERT (pattern); // full through if not debugging 2633 2634 return strhmemfind_rb (block, block_size, pattern, pattern_size, 2635 searchbuf, &repeat_find); 2636 } 2637 2638 /* 2639 *@@ strhmemfind_r: 2640 * searches for a pattern in a block of memory using the Boyer- 2641 * Moore-Horspool-Sunday algorithm. The block and pattern may contain any 2642 * values; you must explicitly provide their lengths. Returns a pointer to 2643 * the pattern if found within the block, or NULL if the pattern was not 2644 * found. 2645 * 2646 * This function is meant to handle binary data, for a single search for 2647 * a given pattern. If you need to search strings, use the strhfind_r() 2648 * or strhfind_rb() functions. If you want to do efficient repeated searches 2649 * for one pattern, use strhmemfind_rb(). Reentrant. 2650 * 2651 * Taken from the "Standard Function Library", file sflfind.c. 2652 * Copyright: Copyright (c) 1991-99 iMatix Corporation. 2653 * Slightly modified. 2654 * 2655 *@@added V0.9.3 (2000-05-08) [umoeller] 2656 */ 2657 2658 void* strhmemfind_r (const void *block, // Block containing data 2659 size_t block_size, // Size of block in bytes 2660 const void *pattern, // Pattern to search for 2661 size_t pattern_size) // Size of pattern block 2662 { 2663 size_t 2664 searchbuf [256]; // One-time search buffer 2665 BOOL 2666 secondtime = FALSE; 2667 2668 ASSERT (block); // Expect non-NULL pointers, but 2669 ASSERT (pattern); // full through if not debugging 2670 2671 return strhmemfind_rb (block, block_size, pattern, pattern_size, 2672 searchbuf, &secondtime); 2673 } 2674 2675 /* 2676 *@@ strhmemfind_rb: 2677 * searches for a pattern in a block of memory using the Boyer- 2678 * Moore-Horspool-Sunday algorithm. The block and pattern may contain any 2679 * values; you must explicitly provide their lengths. Returns a pointer to 2680 * the pattern if found within the block, or NULL if the pattern was not 2681 * found. On the first search with a given pattern, *repeat_find should 2682 * be FALSE. It will be set to TRUE after the shift table is initialised, 2683 * allowing the initialisation phase to be skipped on subsequent searches. 2684 * shift must point to an array big enough to hold 256 (8**2) size_t values. 2685 * 2686 * This function is meant to handle binary data, for repeated searches 2687 * for the same pattern. If you need to search strings, use the 2688 * strhfind_r() or strhfind_rb() functions. If you wish to search for a 2689 * pattern only once consider using strhmemfind_r(). Reentrant. 2690 * 2691 * Taken from the "Standard Function Library", file sflfind.c. 2692 * Copyright: Copyright (c) 1991-99 iMatix Corporation. 2693 * Slightly modified. 2694 * 2695 *@@added V0.9.3 (2000-05-08) [umoeller] 2696 */ 2697 2698 void* strhmemfind_rb (const void *in_block, // Block containing data 2699 size_t block_size, // Size of block in bytes 2700 const void *in_pattern, // Pattern to search for 2701 size_t pattern_size, // Size of pattern block 2702 size_t *shift, // Shift table (search buffer) 2703 BOOL *repeat_find) // TRUE: search buffer already init 2704 { 2705 size_t 2706 byte_nbr, // Distance through block 2707 match_size; // Size of matched part 2530 void* strhmemfind(const void *in_block, // in: block containing data 2531 size_t block_size, // in: size of block in bytes 2532 const void *in_pattern, // in: pattern to search for 2533 size_t pattern_size, // in: size of pattern block 2534 size_t *shift, // in/out: shift table (search buffer) 2535 BOOL *repeat_find) // in/out: if TRUE, *shift is already initialized 2536 { 2537 size_t byte_nbr, // Distance through block 2538 match_size; // Size of matched part 2708 2539 const unsigned char 2709 *match_base = NULL, // Base of match of pattern2710 *match_ptr = NULL, // Point within current match2711 *limit = NULL; // Last potiental match point2540 *match_base = NULL, // Base of match of pattern 2541 *match_ptr = NULL, // Point within current match 2542 *limit = NULL; // Last potiental match point 2712 2543 const unsigned char 2713 *block = (unsigned char *) in_block, // Concrete pointer to block data2714 *pattern = (unsigned char *) in_pattern; // Concrete pointer to search value2715 2716 ASSERT (block); // Expect non-NULL pointers, but2717 ASSERT (pattern); // fail gracefully if not debugging2718 ASSERT (shift); // NULL repeat_find => is false2719 if (block == NULL || pattern == NULL || shift == NULL)2544 *block = (unsigned char *) in_block, // Concrete pointer to block data 2545 *pattern = (unsigned char *) in_pattern; // Concrete pointer to search value 2546 2547 if ( (block == NULL) 2548 || (pattern == NULL) 2549 || (shift == NULL) 2550 ) 2720 2551 return (NULL); 2721 2552 … … 2736 2567 2737 2568 if (!repeat_find || !*repeat_find) 2738 { 2739 for (byte_nbr = 0; byte_nbr < 256; byte_nbr++) 2740 shift [byte_nbr] = pattern_size + 1; 2741 for (byte_nbr = 0; byte_nbr < pattern_size; byte_nbr++) 2742 shift [(unsigned char) pattern [byte_nbr]] = pattern_size - byte_nbr; 2569 { 2570 for (byte_nbr = 0; 2571 byte_nbr < 256; 2572 byte_nbr++) 2573 shift[byte_nbr] = pattern_size + 1; 2574 for (byte_nbr = 0; 2575 byte_nbr < pattern_size; 2576 byte_nbr++) 2577 shift[(unsigned char)pattern[byte_nbr]] = pattern_size - byte_nbr; 2743 2578 2744 2579 if (repeat_find) 2745 2580 *repeat_find = TRUE; 2746 2581 } 2747 2582 2748 2583 // Search for the block, each time jumping up by the amount … … 2754 2589 for (match_base = block; 2755 2590 match_base < limit; 2756 match_base += shift 2757 2591 match_base += shift[*(match_base + pattern_size)]) 2592 { 2758 2593 match_ptr = match_base; 2759 2594 match_size = 0; 2760 2595 2761 2596 // Compare pattern until it all matches, or we find a difference 2762 while (*match_ptr++ == pattern 2763 2597 while (*match_ptr++ == pattern[match_size++]) 2598 { 2764 2599 ASSERT (match_size <= pattern_size && 2765 2600 match_ptr == (match_base + match_size)); 2766 2601 2767 // 2602 // If we found a match, return the start address 2768 2603 if (match_size >= pattern_size) 2769 return ((void*)(match_base));2770 2771 2772 2604 return ((void*)(match_base)); 2605 2606 } 2607 } 2773 2608 return (NULL); // Found nothing 2774 2609 } -
trunk/src/helpers/syssound.c
r8 r13 153 153 { 154 154 // individual volume settings per sound 155 sscanf(p1, "% d", pulVolume);155 sscanf(p1, "%lu", pulVolume); 156 156 ulrc++; 157 157 } … … 290 290 "100", 291 291 szData2, sizeof(szData2)); 292 sscanf(szData2, "% d", pulVolume);292 sscanf(szData2, "%lu", pulVolume); 293 293 } 294 294 … … 332 332 CHAR szData[1000]; 333 333 // format: soundfile#description#volume 334 sprintf(szData, "%s#%s#% d", pszFile, pszDescr, ulVolume);334 sprintf(szData, "%s#%s#%lu", pszFile, pszDescr, ulVolume); 335 335 brc = PrfWriteProfileString(hiniMMPM, 336 336 MMINIKEY_SYSSOUNDS, szKey, … … 475 475 ulKeyLen = strlen(szFile)+1; // go beyond null byte 476 476 ulKeyLen += sprintf(szFile+ulKeyLen, 477 "% d",477 "%lu", 478 478 ulVolume) + 1; 479 479 // and write to OS2SYS.INI … … 608 608 // copy it 609 609 sscanf(pSchemeSoundData + cbSchemeSoundFile, 610 "% d",610 "%lu", 611 611 &ulVolume); 612 612 613 613 // and write data to MMPM.INI 614 614 // format: soundfile#description#volume 615 sprintf(szData, "%s#%s#% d", szFile, szDescription, ulVolume);615 sprintf(szData, "%s#%s#%lu", szFile, szDescription, ulVolume); 616 616 if (PrfWriteProfileString(hiniMMPM, 617 617 MMINIKEY_SYSSOUNDS, // "MMPM2_AlarmSounds" -
trunk/src/helpers/textv_html.c
r11 r13 175 175 176 176 VOID AppendChar(PCOPYTARGET pct, // in/out: formatting buffer 177 CHARc)177 unsigned char c) 178 178 { 179 179 // calculate ofs where to store next char … … 685 685 pct->ulListLevel - 1); 686 686 if (pListDesc) 687 { 687 688 if (pListDesc->ulListType == 1) 688 689 // is ordered list: 689 sprintf(szMarker, "% d.", (pListDesc->ulItem)++);690 sprintf(szMarker, "%lu.", (pListDesc->ulItem)++); 690 691 else if (pListDesc->ulListType == 0) 691 692 // is unordered list: 692 693 // set bullet type according to unordered nesting 693 694 szMarker[2] = pct->ulUnorderedListLevel; 695 } 694 696 } 695 697 … … 864 866 if (pct->fInLink) 865 867 { 866 sprintf(szAnchor, "%04 lX", pct->usAnchorIndex);868 sprintf(szAnchor, "%04hX", pct->usAnchorIndex); 867 869 AppendString(pct, 868 870 TXVESC_LINK); … … 933 935 case 'd': // ADDRESS 934 936 if (stricmp(p2, "DRESS") == 0) 937 { 935 938 if (!fEndOfTag) 936 939 return TagI; 937 940 else 938 941 return TagXI; 942 } 939 943 } 940 944 break; … … 976 980 case 'o': 977 981 if (stricmp(p2, "DE") == 0) 982 { 978 983 if (!fEndOfTag) 979 984 return TagCODE; 980 985 else 981 986 return TagXCODE; 987 } 982 988 break; 983 989 } … … 998 1004 if (*p2 == 'R') 999 1005 if (*(pCheck + 3) == 0) 1006 { 1000 1007 if (!fEndOfTag) 1001 1008 return TagUL; 1002 1009 else 1003 1010 return TagXUL; 1011 } 1004 1012 break; 1005 1013 … … 1007 1015 case 'l': // DL 1008 1016 if (*p2 == 0) 1017 { 1009 1018 if (!fEndOfTag) 1010 1019 return TagDL; 1011 1020 else 1012 1021 return TagXDL; 1022 } 1013 1023 break; 1014 1024 … … 1025 1035 if ( (c1 == 'M') || (c1 == 'm') ) // EM 1026 1036 if (*p2 == 0) 1037 { 1027 1038 if (!fEndOfTag) 1028 1039 return TagI; 1029 1040 else 1030 1041 return TagXI; 1042 } 1031 1043 break; 1032 1044 … … 1073 1085 case 'i': 1074 1086 if (c1 == 0) 1087 { 1075 1088 if (!fEndOfTag) 1076 1089 return TagI; 1077 1090 else 1078 1091 return TagXI; 1092 } 1079 1093 break; 1080 1094 … … 1089 1103 case 'm': 1090 1104 if (stricmp(p2, "NU") == 0) 1105 { 1091 1106 if (!fEndOfTag) 1092 1107 return TagUL; 1093 1108 else 1094 1109 return TagXUL; 1110 } 1095 1111 break; 1096 1112 … … 1099 1115 if ((c1 == 'L') || (c1 == 'l')) 1100 1116 if (*p2 == 0) 1117 { 1101 1118 if (!fEndOfTag) 1102 1119 return TagOL; 1103 1120 else 1104 1121 return TagXOL; 1122 } 1105 1123 break; 1106 1124 … … 1118 1136 if ((*p2 == 'E') || (*p2 == 'e')) 1119 1137 if (*(pCheck + 3) == 0) 1138 { 1120 1139 if (!fEndOfTag) 1121 1140 return TagPRE; 1122 1141 else 1123 1142 return TagXPRE; 1143 } 1124 1144 break; 1125 1145 } … … 1133 1153 case 't': // STRONG 1134 1154 if (stricmp(p2, "RONG") == 0) 1155 { 1135 1156 if (!fEndOfTag) 1136 1157 return TagB; 1137 1158 else 1138 1159 return TagXB; 1160 } 1139 1161 else if (stricmp(p2, "RIKE") == 0) 1162 { 1140 1163 if (!fEndOfTag) 1141 1164 return TagSTRIKE; 1142 1165 else 1143 1166 return TagXSTRIKE; 1167 } 1144 1168 break; 1145 1169 … … 1147 1171 case 'a': 1148 1172 if (stricmp(p2, "MP") == 0) 1173 { 1149 1174 if (!fEndOfTag) 1150 1175 return TagCODE; 1151 1176 else 1152 1177 return TagXCODE; 1178 } 1153 1179 break; 1154 1180 } … … 1174 1200 case 't': 1175 1201 if (*p2 == 0) 1202 { 1176 1203 if (!fEndOfTag) 1177 1204 return TagCODE; 1178 1205 else 1179 1206 return TagXCODE; 1207 } 1180 1208 break; 1181 1209 } … … 1195 1223 case 'l': 1196 1224 if (*p2 == 0) 1225 { 1197 1226 if (!fEndOfTag) 1198 1227 return TagUL; 1199 1228 else 1200 1229 return TagXUL; 1230 } 1201 1231 break; 1202 1232 } … … 1393 1423 */ 1394 1424 1395 CHARConvertEscape(PSZ pszTag)1425 unsigned char ConvertEscape(PSZ pszTag) 1396 1426 { 1397 1427 CHAR c0, c1; -
trunk/src/helpers/textview.c
r12 r13 1311 1311 pWordThis->pvRectangle = (PVOID)pRect; 1312 1312 lstAppendItem(&pRect->llWords, pWordThis); 1313 // ### memory leak right here!!! 1313 1314 ulWordsInThisRect++; 1314 1315 -
trunk/src/helpers/tmsgfile.c
r8 r13 724 724 725 725 // determine entry 726 sprintf(szEntry, "%s % u %u" NEWLINE,726 sprintf(szEntry, "%s %lu %lu" NEWLINE, 727 727 pCurrentNameStart, 728 728 ulCurrentMessagePos, -
trunk/src/helpers/tree.c
r11 r13 15 15 * This has been taken from the Standard Function Library (SFL) 16 16 * by iMatix Corporation and changed to user the "id" member for 17 * tree sorting/comparison. 17 * tree sorting/comparison. This implementation is released 18 * under the GPL. 18 19 * 19 20 * <B>Using binary trees</B> 21 * 22 * You can use any structure as elements in a tree, provided 23 * that the first member in the structure is a TREE structure 24 * (i.e. it has the left, right, parent, id, and colour members). 25 * The tree functions don't care what follows. 26 * 27 * So the implementation here is slightly different from the 28 * linked lists in linklist.c, because the LISTNODE structs 29 * only have pointers to the data. By contrast, the TREE structs 30 * are expected to contain the data themselves. See treeInsertID() 31 * for a sample. 20 32 * 21 33 * Each TREE node does not only contain data, but also an … … 55 67 * Differences compared to linklist.c: 56 68 * 69 * -- Trees are considerably slower when inserting and removing 70 * nodes because the tree has to be rebalanced every time 71 * a node changes. By contrast, trees are much faster finding 72 * nodes because the tree is always sorted. 73 * 74 * -- You must always supply a comparison function to allow the 75 * tree functions to sort the tree. 76 * 57 77 * -- As opposed to a LISTNODE, the TREE structure (which 58 * represents a tree node) does not contain a data pointer. 59 * Instead, all tree nodes are assumed to contain the 60 * data themselves. As a result, you must define your 61 * own structures which start with a TREE structure. 62 * 63 * See treeInsertID() for samples. 64 * 65 * -- You must supply a comparison function to allow the 66 * tree functions to sort the tree. 78 * represents a tree node) does not contain a data pointer, 79 * as said above. 67 80 * 68 81 *@@added V0.9.5 (2000-09-29) [umoeller] … … 838 851 * and will receive the "pUser" parameter, which you can use 839 852 * as a data pointer to some structure for whatever you like. 840 */ 841 842 void treeTraverse(TREE *tree, 843 TREE_PROCESS *process, 844 void *pUser, 845 int method) 853 * 854 * "method" specifies in which order the nodes are traversed. 855 * This can be: 856 * 857 * -- 1: current node first, then left node, then right node. 858 * -- 2: left node first, then right node, then current node. 859 * -- other: left node first, then current node, then right node. 860 */ 861 862 void treeTraverse(TREE *tree, // in: root of tree 863 TREE_PROCESS *process, // in: callback for each node 864 void *pUser, // in: user param for callback 865 int method) // in: traversal mode 846 866 { 847 867 if ((!tree) -
trunk/src/helpers/winh.c
r12 r13 2979 2979 if (pszText) 2980 2980 { 2981 if (strhrpl(&pszText, 0, pszSearch, pszReplaceWith, 0) > 0) 2981 ULONG ulOfs = 0; 2982 if (strhrpl(&pszText, &ulOfs, pszSearch, pszReplaceWith) > 0) 2982 2983 { 2983 2984 WinSetWindowText(hwnd, pszText); -
trunk/src/helpers/xml.c
r12 r13 240 240 PSZ xmlTokenize(const char *pcszXML) 241 241 { 242 return (0); 242 243 } 243 244 -
trunk/src/helpers/xstring.c
r12 r13 51 51 * 3) If you need the char* pointer (e.g. for a call 52 52 * to another function), use XSTRING.psz. However, 53 * you should NEVER modify the psz pointer yourself 54 * because then these functions will get into trouble. 53 * you should ONLY modify the psz pointer yourself 54 * if the other XSTRING members are updated accordingly. 55 * You may, for example, change single characters 56 * in the psz buffer. By contrast, if you change the 57 * length of the string, you must update XSTRING.ulLength. 58 * Otherwise these functions will get into trouble. 55 59 * 56 60 * Also, you should never assume that the "psz" 57 61 * pointer has not changed after you have called 58 62 * one of the xstr* functions because these can 59 * always reallocate the buffer if needed. 63 * always reallocate the buffer if more memory 64 * was needed. 60 65 * 61 66 * 4) If (and only if) you have a char* buffer which … … 68 73 * The functions in this file used to be in stringh.c 69 74 * before V0.9.3 (2000-04-01). These have been largely 70 * rewritten with V0.9.6 (2000-11-01). 75 * rewritten with V0.9.6 (2000-11-01) and are now much 76 * more efficient. 71 77 * 72 78 * Note: Version numbering in this file relates to XWorkplace … … 145 151 * the XSTRING with. 146 152 * 153 * This does not create a copy of pszNew. Instead, 154 * pszNew is used as the member string in pxstr 155 * directly. 156 * 147 157 * Do not use this on an XSTRING which is already 148 158 * initialized. Use xstrset instead. 159 * 160 * Example: 161 * 162 + XSTRING str; 163 + xstrInitSet(&str, strdup("blah")); 149 164 * 150 165 *@@added V0.9.6 (2000-11-01) [umoeller] … … 173 188 * of an existing string. 174 189 * 190 * As opposed to xstrInitSet, this does create 191 * a copy of pcszSource. 192 * 175 193 * Do not use this on an XSTRING which is already 176 194 * initialized. Use xstrcpy instead. 195 * 196 * Example: 197 * 198 + XSTRING str; 199 + xstrInitCopy(&str, "blah"); 177 200 * 178 201 *@@added V0.9.6 (2000-11-01) [umoeller] … … 301 324 + xstrInit(&str, 0); 302 325 + xstrcpy(&str, "blah"); 326 * 327 * This sequence can be abbreviated using xstrInitCopy. 303 328 * 304 329 *@@changed V0.9.2 (2000-04-01) [umoeller]: renamed from strhxcpy … … 351 376 /* 352 377 *@@ xstrcat: 353 * appends pcszSource to pxstr, for which memory is allocated354 * asnecessary.378 * appends pcszSource to pxstr, for which memory is 379 * reallocated if necessary. 355 380 * 356 381 * If pxstr is empty, this behaves just like xstrcpy. … … 366 391 + xstrcat(&str, "blup"); 367 392 * 368 * would do the following: 369 * a) free the old value of str ("blah"); 370 * b) reallocate str; 371 * c) so that psz afterwards points to a new string containing 372 * "blahblup". 393 * After this, psz points to a new string containing 394 * "blahblup". 373 395 * 374 396 *@@changed V0.9.1 (99-12-20) [umoeller]: fixed memory leak … … 424 446 425 447 // 2) append source string: 426 strcpy(pxstr->psz + pxstr->ulLength, 427 pcszSource); 448 memcpy(pxstr->psz + pxstr->ulLength, 449 pcszSource, 450 ulSourceLength + 1); // null terminator 428 451 429 452 // in all cases, set new length 430 453 pxstr->ulLength += ulSourceLength; 431 454 ulrc = ulSourceLength; 432 } 455 456 } // end if (ulSourceLength) 433 457 // else no source specified or source is empty: 434 458 // do nothing … … 439 463 440 464 /* 465 *@@ xstrFindWord: 466 * searches for pstrFind in pxstr, starting at ulOfs. 467 * However, this only finds pstrFind if it's a "word", 468 * i.e. surrounded by one of the characters in the 469 * pcszBeginChars and pcszEndChars array. 470 * 471 * This is similar to strhFindWord, but this uses 472 * strhmemfind for fast searching, and it doesn't 473 * have to calculate the string lengths because these 474 * already in XSTRING. 475 * 476 * Returns 0 if no "word" was found, or the offset 477 * of the "word" in pxstr if found. 478 * 479 *@@added V0.9.6 (2000-11-12) [umoeller] 480 */ 481 482 PSZ xstrFindWord(const XSTRING *pxstr, // in: buffer to search ("haystack") 483 ULONG ulOfs, // in: where to begin search (0 = start) 484 const XSTRING *pstrFind, // in: word to find ("needle") 485 size_t *pShiftTable, // in: shift table (see strhmemfind) 486 PBOOL pfRepeatFind, // in: repeat find? (see strhmemfind) 487 const char *pcszBeginChars, // suggestion: "\x0d\x0a ()/\\-,." 488 const char *pcszEndChars) // suggestion: "\x0d\x0a ()/\\-,.:;" 489 { 490 PSZ pReturn = 0; 491 ULONG ulFoundLen = pstrFind->ulLength; 492 493 if ((pxstr->ulLength) && (ulFoundLen)) 494 { 495 const char *p = pxstr->psz + ulOfs; 496 497 do // while p 498 { 499 // p = strstr(p, pstrFind->psz); 500 p = (PSZ)strhmemfind(p, // in: haystack 501 pxstr->ulLength - (p - pxstr->psz), 502 // remaining length of haystack 503 pstrFind->psz, 504 ulFoundLen, 505 pShiftTable, 506 pfRepeatFind); 507 if (p) 508 { 509 // string found: 510 // check if that's a word 511 512 if (strhIsWord(pxstr->psz, 513 p, 514 ulFoundLen, 515 pcszBeginChars, 516 pcszEndChars)) 517 { 518 // valid end char: 519 pReturn = (PSZ)p; 520 break; 521 } 522 523 p += ulFoundLen; 524 } 525 } while (p); 526 527 } 528 return (pReturn); 529 } 530 531 /* 441 532 *@@ xstrrpl: 442 * replaces pstrSearch with pstrReplace in pxstr. 533 * replaces the first occurence of pstrSearch with 534 * pstrReplace in pxstr. 443 535 * 444 536 * Starting with V0.9.6, this operates entirely on 445 537 * XSTRING's for speed because we then know the string 446 538 * lengths already and can use memcpy instead of strcpy. 447 * This new version should be magnitudes faster. 539 * This new version should be magnitudes faster, 540 * especially with large string bufffers. 448 541 * 449 542 * None of the pointers can be NULL, but if pstrReplace … … 454 547 * (and pxstr was therefore not changed). 455 548 * 456 * If the string was found and (pulAfterOfs != NULL), 457 * *pulAfterOfs will be set to the first character 458 * after the new replacement string. This allows you 459 * to call this func again with the same strings to 460 * have several occurences replaced. 461 * 462 * Only the first occurence is replaced. To replace 463 * all occurences in a buffer, repeat calling this 464 * function until it returns 0. 549 * This starts the search at *pulOffset. If 550 * (*pulOffset == 0), this starts from the beginning 551 * of pxstr. 552 * If the string was found, *pulOffset will be set to the 553 * first character after the new replacement string. This 554 * allows you to call this func again with the same strings 555 * to have several occurences replaced (see the example below). 465 556 * 466 557 * There are two wrappers around this function which … … 476 567 * 477 568 + XSTRING str; 478 + ULONG ul Pos= 0;569 + ULONG ulOffset = 0; 479 570 + xstrInit(&str, 0); 480 571 + xstrcpy(&str, "Test phrase 1. Test phrase 2."); 481 572 + while (xstrrpl(&str, 482 + ulPos,573 + &ulPos, // in/out: offset 483 574 + "Test", // search 484 + "Dummy", // replace 485 + &ulPos)) 575 + "Dummy") // replace 486 576 + ; 487 577 * … … 493 583 *@@changed V0.9.2 (2000-04-01) [umoeller]: renamed from strhxrpl 494 584 *@@changed V0.9.6 (2000-11-01) [umoeller]: rewritten 585 *@@changed V0.9.6 (2000-11-12) [umoeller]: now using strhmemfind 495 586 */ 496 587 497 588 ULONG xstrrpl(PXSTRING pxstr, // in/out: string 498 ULONG ulOfs, // in: where to begin search (0 = start) 589 PULONG pulOfs, // in: where to begin search (0 = start); 590 // out: ofs of first char after replacement string 499 591 const XSTRING *pstrSearch, // in: search string; cannot be NULL 500 592 const XSTRING *pstrReplace, // in: replacement string; cannot be NULL 501 PULONG pulAfterOfs) // out: offset where found (ptr can be NULL) 502 { 503 ULONG ulrc = 0; 593 size_t *pShiftTable, // in: shift table (see strhmemfind) 594 PBOOL pfRepeatFind) // in: repeat find? (see strhmemfind) 595 { 596 ULONG ulrc = 0; // default: not found 504 597 505 598 if ((pxstr) && (pstrSearch) && (pstrReplace)) … … 508 601 509 602 // can we search this? 510 if ( ( ulOfs < pxstr->ulLength)603 if ( (*pulOfs < pxstr->ulLength) 511 604 && (cSearchLen) 512 605 ) 513 606 { 514 607 // yes: 515 PSZ pFound = strstr(pxstr->psz + ulOfs, 516 pstrSearch->psz); 517 608 /* PSZ pFound = strstr(pxstr->psz + *pulOfs, 609 pstrSearch->psz); */ 610 PSZ pFound = (PSZ)strhmemfind(pxstr->psz + *pulOfs, // in: haystack 611 pxstr->ulLength - *pulOfs, 612 pstrSearch->psz, 613 cSearchLen, 614 pShiftTable, 615 pfRepeatFind); 518 616 if (pFound) 519 617 { … … 569 667 + 1); // null terminator 570 668 669 // replace old buffer with new one 571 670 free(pxstr->psz); 572 671 pxstr->psz = pszNew; … … 627 726 // return new length 628 727 ulrc = cbNeeded - 1; 629 if (pulAfterOfs) 630 *pulAfterOfs = ulFoundOfs + cReplaceLen; 631 } 632 } 633 } 728 *pulOfs = ulFoundOfs + cReplaceLen; 729 } // end if (pFound) 730 } // end if ( (*pulOfs < pxstr->ulLength) ... 731 } // end if ((pxstr) && (pstrSearch) && (pstrReplace)) 634 732 635 733 return (ulrc); … … 638 736 /* 639 737 *@@ xstrcrpl: 640 * wrapper around xstrrpl which allows using C strings738 * wrapper around xstrrpl() which allows using C strings 641 739 * for the find and replace parameters. 642 740 * 741 * This creates two temporary XSTRING's for pcszSearch 742 * pcszReplace. As a result, this is slower than xstrrpl. 743 * If you search with the same strings several times, 744 * you'll be better off using xstrrpl() directly. 745 * 643 746 *@@added V0.9.6 (2000-11-01) [umoeller] 644 747 */ 645 748 646 749 ULONG xstrcrpl(PXSTRING pxstr, // in/out: string 647 ULONG ulOfs, // in: where to begin search (0 = start) 750 PULONG pulOfs, // in: where to begin search (0 = start); 751 // out: ofs of first char after replacement string 648 752 const char *pcszSearch, // in: search string; cannot be NULL 649 const char *pcszReplace, // in: replacement string; cannot be NULL 650 PULONG pulAfterOfs) // out: offset where found (ptr can be NULL) 651 { 652 ULONG ulrc = 0; 753 const char *pcszReplace) // in: replacement string; cannot be NULL 754 { 755 // ULONG ulrc = 0; 653 756 XSTRING xstrFind, 654 757 xstrReplace; 655 xstrInit(&xstrFind, 0); 656 xstrset(&xstrFind, (PSZ)pcszSearch); 657 xstrInit(&xstrReplace, 0); 658 xstrset(&xstrReplace, (PSZ)pcszReplace); 659 660 return (xstrrpl(pxstr, ulOfs, &xstrFind, &xstrReplace, pulAfterOfs)); 758 size_t ShiftTable[256]; 759 BOOL fRepeat = FALSE; 760 // initialize find/replace strings... note that the 761 // C strings are not free()'able, so we MUST NOT use xstrClear 762 // before leaving 763 xstrInitSet(&xstrFind, (PSZ)pcszSearch); 764 xstrInitSet(&xstrReplace, (PSZ)pcszReplace); 765 766 return (xstrrpl(pxstr, pulOfs, &xstrFind, &xstrReplace, ShiftTable, &fRepeat)); 661 767 } 662 768
Note:
See TracChangeset
for help on using the changeset viewer.