Changeset 132 for trunk/src/helpers
- Timestamp:
- Jan 19, 2002, 11:50:39 AM (24 years ago)
- Location:
- trunk/src/helpers
- Files:
-
- 10 edited
-
comctl.c (modified) (5 diffs)
-
dialog.c (modified) (15 diffs)
-
dosh.c (modified) (4 diffs)
-
exeh.c (modified) (6 diffs)
-
linklist.c (modified) (16 diffs)
-
memdebug.c (modified) (1 diff)
-
stringh.c (modified) (3 diffs)
-
threads.c (modified) (1 diff)
-
winh.c (modified) (1 diff)
-
xstring.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/comctl.c
r123 r132 977 977 */ 978 978 979 PANIMATIONDATA CreateAnimationData(HWND hwndStatic, 979 PANIMATIONDATA CreateAnimationData(HAB hab, 980 HWND hwndStatic, 980 981 USHORT cAnimations) 981 982 { … … 996 997 WinSetWindowULong(hwndStatic, QWL_USER, (ULONG)pa); 997 998 998 pa->hab = WinQueryAnchorBlock(hwndStatic);999 pa->hab = hab; 999 1000 WinQueryWindowRect(hwndStatic, &pa->rclIcon); 1000 1001 pa->OldStaticProc = WinSubclassWindow(hwndStatic, ctl_fnwpBitmapStatic); … … 1046 1047 { 1047 1048 PANIMATIONDATA pa; 1048 1049 if (pa = CreateAnimationData(hwndStatic, 1050 usAnimCount)) 1049 HAB hab; 1050 if ( (hwndStatic) 1051 && (hab = WinQueryAnchorBlock(hwndStatic)) 1052 && (WinIsWindow(hab, hwndStatic)) 1053 && (pa = CreateAnimationData(hab, 1054 hwndStatic, 1055 usAnimCount)) 1056 ) 1051 1057 { 1052 1058 // switch static to icon mode 1053 1059 pa->ulFlags = ANF_ICON; 1060 return (pa); 1054 1061 } 1055 1062 1056 return ( pa);1063 return (NULL); 1057 1064 } 1058 1065 … … 1233 1240 { 1234 1241 PANIMATIONDATA pa; 1235 1236 if (pa = CreateAnimationData(hwndStatic, 1)) 1242 HAB hab; 1243 if ( (hwndStatic) 1244 && (hab = WinQueryAnchorBlock(hwndStatic)) 1245 && (WinIsWindow(hab, hwndStatic)) 1246 && (pa = CreateAnimationData(hab, hwndStatic, 1)) 1247 ) 1237 1248 { 1238 1249 // switch static to bitmap mode … … 1240 1251 if (fPreserveProportions) 1241 1252 pa->ulFlags |= ANF_PROPORTIONAL; 1253 return (pa); 1242 1254 } 1243 1255 1244 return (pa);1256 return NULL; 1245 1257 } 1246 1258 -
trunk/src/helpers/dialog.c
r123 r132 234 234 { 235 235 LONG lPointSize = 0; 236 const char *pcszFontThis = pControlDef->pcszFont;236 PCSZ pcszFontThis = pControlDef->pcszFont; 237 237 // can be NULL, 238 238 // or CTL_COMMON_FONT … … 1240 1240 1241 1241 APIRET Dlg1_ParseTables(PDLGPRIVATE pDlgData, 1242 P DLGHITEM paDlgItems, // in: definition array1242 PCDLGHITEM paDlgItems, // in: definition array 1243 1243 ULONG cDlgItems) // in: array item count (NOT array size) 1244 1244 { … … 1256 1256 ul++) 1257 1257 { 1258 P DLGHITEM pItemThis = &paDlgItems[ul];1258 PCDLGHITEM pItemThis = &paDlgItems[ul]; 1259 1259 1260 1260 switch (pItemThis->Type) … … 1584 1584 * it produces a static group control around the table. 1585 1585 * Useful for group boxes. pDef must point to a 1586 * _CONTROLDEF describing the control to be used for1586 * CONTROLDEF describing the control to be used for 1587 1587 * the group (usually a WC_STATIC with SS_GROUP style), 1588 1588 * whose size parameter is ignored. … … 1602 1602 * pDef must point to a CONTROLDEF structure. 1603 1603 * 1604 * Again, there is is NO information in 1605 * CONTROLDEF about a control's _position_. 1606 * Instead, the structure only contains the _size_ 1607 * of the control. All positions are computed by 1608 * this function, depending on the sizes of the 1609 * controls and their nesting within the various tables. 1610 * 1611 * If you specify SZL_AUTOSIZE, the size of the 1612 * control is even computed automatically. Presently, 1613 * this only works for statics with SS_TEXT, SS_ICON, 1614 * and SS_BITMAP. 1604 * Again, there is is NO information in CONTROLDEF 1605 * about a control's _position_. Instead, the structure 1606 * only contains the _size_ of the control. All 1607 * positions are computed by this function, depending 1608 * on the sizes of the controls and their nesting within 1609 * the various tables. 1610 * 1611 * If you specify SZL_AUTOSIZE with either cx or cy 1612 * or both, the size of the control is even computed 1613 * automatically. Presently, this only works for statics 1614 * with SS_TEXT, SS_ICON, and SS_BITMAP, push buttons, 1615 * and radio and check boxes. 1615 1616 * 1616 1617 * Unless separated with START_ROW items, subsequent … … 1621 1622 * an error: 1622 1623 * 1623 * -- The entire array must be enclosed in a table1624 * (the "root" table).1625 * 1626 * -- After START_TABLE or START_GROUP_TABLE, there must1627 * always be a START_ROW first.1624 * -- The entire array must be enclosed in a table 1625 * (the "root" table). 1626 * 1627 * -- After START_TABLE or START_GROUP_TABLE, there must 1628 * always be a START_ROW first. 1628 1629 * 1629 1630 * To create a dialog, set up arrays like the following: … … 1686 1687 + º ³ ³ ³ ³ º 1687 1688 + º ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ º 1689 + º ³ ³ º 1688 1690 + º ³ Static below cnr (3) ³ º 1689 1691 + º ³ ³ º 1690 1692 + º ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ º 1693 + º º 1691 1694 + º ÚÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ º 1692 1695 + º ³ OK (4) ³ ³ Cancel (5) ³ º … … 1756 1759 ULONG flCreateFlags, // in: standard FCF_* frame flags 1757 1760 PFNWP pfnwpDialogProc, 1758 const char *pcszDlgTitle,1759 P DLGHITEM paDlgItems, // in: definition array1761 PCSZ pcszDlgTitle, 1762 PCDLGHITEM paDlgItems, // in: definition array 1760 1763 ULONG cDlgItems, // in: array item count (NOT array size) 1761 1764 PVOID pCreateParams, // in: for mp2 of WM_INITDLG 1762 const char *pcszControlsFont) // in: font for ctls with CTL_COMMON_FONT1765 PCSZ pcszControlsFont) // in: font for ctls with CTL_COMMON_FONT 1763 1766 { 1764 1767 APIRET arc = NO_ERROR; … … 1840 1843 */ 1841 1844 1842 Dlg2_CalcSizes(pDlgData, 1843 &szlClient); 1844 1845 WinSubclassWindow(hwndDlg, pfnwpDialogProc); 1846 1847 /* 1848 * 4) compute size of dialog client from total 1849 * size of all controls 1850 */ 1851 1852 // calculate the frame size from the client size 1853 rclClient.xLeft = 10; 1854 rclClient.yBottom = 10; 1855 rclClient.xRight = szlClient.cx + 2 * SPACING; 1856 rclClient.yTop = szlClient.cy + 2 * SPACING; 1857 WinCalcFrameRect(hwndDlg, 1858 &rclClient, 1859 FALSE); // frame from client 1860 1861 WinSetWindowPos(hwndDlg, 1862 0, 1863 10, 1864 10, 1865 rclClient.xRight, 1866 rclClient.yTop, 1867 SWP_MOVE | SWP_SIZE | SWP_NOADJUST); 1868 1869 arc = Dlg3_PositionAndCreate(pDlgData, 1870 &szlClient, 1871 &hwndFocusItem); 1872 1873 /* 1874 * 7) WM_INITDLG, set focus 1875 * 1876 */ 1877 1878 if (!WinSendMsg(pDlgData->hwndDlg, 1879 WM_INITDLG, 1880 (MPARAM)hwndFocusItem, 1881 (MPARAM)pCreateParams)) 1845 if (!(arc = Dlg2_CalcSizes(pDlgData, 1846 &szlClient))) 1882 1847 { 1883 // if WM_INITDLG returns FALSE, this means 1884 // the dlg proc has not changed the focus; 1885 // we must then set the focus here 1886 WinSetFocus(HWND_DESKTOP, hwndFocusItem); 1848 WinSubclassWindow(hwndDlg, pfnwpDialogProc); 1849 1850 /* 1851 * 4) compute size of dialog client from total 1852 * size of all controls 1853 */ 1854 1855 // calculate the frame size from the client size 1856 rclClient.xLeft = 10; 1857 rclClient.yBottom = 10; 1858 rclClient.xRight = szlClient.cx + 2 * SPACING; 1859 rclClient.yTop = szlClient.cy + 2 * SPACING; 1860 WinCalcFrameRect(hwndDlg, 1861 &rclClient, 1862 FALSE); // frame from client 1863 1864 WinSetWindowPos(hwndDlg, 1865 0, 1866 10, 1867 10, 1868 rclClient.xRight, 1869 rclClient.yTop, 1870 SWP_MOVE | SWP_SIZE | SWP_NOADJUST); 1871 1872 arc = Dlg3_PositionAndCreate(pDlgData, 1873 &szlClient, 1874 &hwndFocusItem); 1875 1876 /* 1877 * 7) WM_INITDLG, set focus 1878 * 1879 */ 1880 1881 if (!WinSendMsg(pDlgData->hwndDlg, 1882 WM_INITDLG, 1883 (MPARAM)hwndFocusItem, 1884 (MPARAM)pCreateParams)) 1885 { 1886 // if WM_INITDLG returns FALSE, this means 1887 // the dlg proc has not changed the focus; 1888 // we must then set the focus here 1889 WinSetFocus(HWND_DESKTOP, hwndFocusItem); 1890 } 1887 1891 } 1888 1892 } … … 1953 1957 1954 1958 APIRET dlghFormatDlg(HWND hwndDlg, // in: dialog frame to work on 1955 P DLGHITEM paDlgItems, // in: definition array1959 PCDLGHITEM paDlgItems, // in: definition array 1956 1960 ULONG cDlgItems, // in: array item count (NOT array size) 1957 const char *pcszControlsFont, // in: font for ctls with CTL_COMMON_FONT1961 PCSZ pcszControlsFont, // in: font for ctls with CTL_COMMON_FONT 1958 1962 ULONG flFlags) // in: DFFL_* flags 1959 1963 { … … 2209 2213 2210 2214 APIRET dlghAppendToArray(PDLGARRAY pArray, // in: dialog array created by dlghCreateArray 2211 DLGHITEM *paItems, // in: subarray to be appended2215 PCDLGHITEM paItems, // in: subarray to be appended 2212 2216 ULONG cItems) // in: subarray item count (NOT array size) 2213 2217 { … … 2250 2254 HWND hwndOwner, 2251 2255 HPOINTER hptrIcon, 2252 const char *pcszTitle,2253 const char *pcszMessage,2256 PCSZ pcszTitle, 2257 PCSZ pcszMessage, 2254 2258 ULONG flFlags, 2255 const char *pcszFont,2259 PCSZ pcszFont, 2256 2260 const MSGBOXSTRINGS *pStrings, 2257 2261 PULONG pulAlarmFlag) // out: alarm sound to be played … … 2334 2338 *p2 = NULL; 2335 2339 2336 Icon.pcszText = ( const char *)hptrIcon;2340 Icon.pcszText = (PCSZ)hptrIcon; 2337 2341 InfoText.pcszText = pcszMessage; 2338 2342 … … 2545 2549 ULONG dlghMessageBox(HWND hwndOwner, // in: owner for msg box 2546 2550 HPOINTER hptrIcon, // in: icon to display 2547 const char *pcszTitle, // in: title2548 const char *pcszMessage, // in: message2551 PCSZ pcszTitle, // in: title 2552 PCSZ pcszMessage, // in: message 2549 2553 ULONG flFlags, // in: standard message box flags 2550 const char *pcszFont, // in: font (e.g. "9.WarpSans")2554 PCSZ pcszFont, // in: font (e.g. "9.WarpSans") 2551 2555 const MSGBOXSTRINGS *pStrings) // in: strings array 2552 2556 { … … 2616 2620 2617 2621 PSZ dlghTextEntryBox(HWND hwndOwner, 2618 const char *pcszTitle, // in: dlg title2619 const char *pcszDescription, // in: descriptive text above entry field2620 const char *pcszDefault, // in: default text for entry field or NULL2621 const char *pcszOK, // in: "OK" string2622 const char *pcszCancel, // in: "Cancel" string2622 PCSZ pcszTitle, // in: dlg title 2623 PCSZ pcszDescription, // in: descriptive text above entry field 2624 PCSZ pcszDefault, // in: default text for entry field or NULL 2625 PCSZ pcszOK, // in: "OK" string 2626 PCSZ pcszCancel, // in: "Cancel" string 2623 2627 ULONG ulMaxLen, // in: maximum length for entry 2624 2628 ULONG fl, // in: TEBF_* flags 2625 const char *pcszFont) // in: font (e.g. "9.WarpSans")2629 PCSZ pcszFont) // in: font (e.g. "9.WarpSans") 2626 2630 { 2627 2631 CONTROLDEF -
trunk/src/helpers/dosh.c
r131 r132 2382 2382 pszContent[cbRead] = '\0'; 2383 2383 *ppszContent = pszContent; 2384 if (pcbRead) 2385 *pcbRead = cbRead + 1; 2384 2386 } 2385 2387 } … … 2978 2980 2979 2981 /* 2982 *@@ doshQueryProcAddr: 2983 * attempts to resolve the given procedure from 2984 * the given module name. Saves you from querying 2985 * the module handle and all that. 2986 * 2987 * This is intended for resolving undocumented 2988 * APIs from OS/2 system DLls such as PMMERGE 2989 * and DOSCALLS. It is assumed that the specified 2990 * module is already loaded. 2991 * 2992 * Returns: 2993 * 2994 * -- NO_ERROR 2995 * 2996 * -- ERROR_INVALID_NAME 2997 * 2998 * -- ERROR_INVALID_ORDINAL 2999 * 3000 * plus the error codes of DosLoadModule. 3001 * 3002 *@@added V0.9.16 (2002-01-13) [umoeller] 3003 */ 3004 3005 APIRET doshQueryProcAddr(PCSZ pcszModuleName, // in: module name (e.g. "PMMERGE") 3006 ULONG ulOrdinal, // in: proc ordinal 3007 PFN *ppfn) // out: proc address 3008 { 3009 HMODULE hmod; 3010 APIRET arc; 3011 if (!(arc = DosQueryModuleHandle((PSZ)pcszModuleName, 3012 &hmod))) 3013 { 3014 if ((arc = DosQueryProcAddr(hmod, 3015 ulOrdinal, 3016 NULL, 3017 ppfn))) 3018 { 3019 // the CP programming guide and reference says use 3020 // DosLoadModule if DosQueryProcAddr fails with this error 3021 if (arc == ERROR_INVALID_HANDLE) 3022 { 3023 if (!(arc = DosLoadModule(NULL, 3024 0, 3025 (PSZ)pcszModuleName, 3026 &hmod))) 3027 { 3028 arc = DosQueryProcAddr(hmod, 3029 ulOrdinal, 3030 NULL, 3031 ppfn); 3032 } 3033 } 3034 } 3035 } 3036 3037 return (arc); 3038 } 3039 3040 /* 2980 3041 *@@ doshResolveImports: 2981 3042 * this function loads the module called pszModuleName … … 2990 3051 */ 2991 3052 2992 APIRET doshResolveImports(P SZ pszModuleName, // in: DLL to load3053 APIRET doshResolveImports(PCSZ pcszModuleName, // in: DLL to load 2993 3054 HMODULE *phmod, // out: module handle 2994 P RESOLVEFUNCTION paResolves, // in/out: function resolves3055 PCRESOLVEFUNCTION paResolves, // in/out: function resolves 2995 3056 ULONG cResolves) // in: array item count (not array size!) 2996 3057 { … … 3000 3061 if (!(arc = DosLoadModule(szName, 3001 3062 sizeof(szName), 3002 pszModuleName,3063 (PSZ)pcszModuleName, 3003 3064 phmod))) 3004 3065 { -
trunk/src/helpers/exeh.c
r131 r132 329 329 // go read in the complete header then 330 330 // (doshReadAt has this in the cache) 331 if (!(pExec->pNEHeader = malloc(cbRead)))331 if (!(pExec->pNEHeader = (PNEHEADER)malloc(cbRead))) 332 332 arc = ERROR_NOT_ENOUGH_MEMORY; 333 333 else if (!(arc = doshReadAt(pFile, … … 361 361 // go read in the complete header then 362 362 // (doshReadAt has this in the cache) 363 if (!(pExec->pLXHeader = malloc(cbRead)))363 if (!(pExec->pLXHeader = (PLXHEADER)malloc(cbRead))) 364 364 arc = ERROR_NOT_ENOUGH_MEMORY; 365 365 else if (!(arc = doshReadAt(pFile, … … 389 389 // plus an extended header, so check 390 390 // what we've got 391 if (!(pExec->pPEHeader = malloc(sizeof(PEHEADER))))391 if (!(pExec->pPEHeader = (PPEHEADER)malloc(sizeof(PEHEADER)))) 392 392 arc = ERROR_NOT_ENOUGH_MEMORY; 393 393 else … … 2742 2742 // 4096 bytes for each page that is read in 2743 2743 // plus 4 extra bytes to terminate for decompression 2744 if (!(pabCompressed = malloc(ulPageSize + 4)))2744 if (!(pabCompressed = (PBYTE)malloc(ulPageSize + 4))) 2745 2745 arc = ERROR_NOT_ENOUGH_MEMORY; 2746 2746 // 4096 * cPages for the data that is composed from that … … 2793 2793 { 2794 2794 // allocate a new buffer for caller 2795 if (!(*ppbResData = malloc(pRsEntry->cb)))2795 if (!(*ppbResData = (PBYTE)malloc(pRsEntry->cb))) 2796 2796 arc = ERROR_NOT_ENOUGH_MEMORY; 2797 2797 else … … 3052 3052 ULONG cb = pSegThis->ns_cbseg; // resource size 3053 3053 PBYTE pb; 3054 if (!(*ppbResData = malloc(cb)))3054 if (!(*ppbResData = (PBYTE)malloc(cb))) 3055 3055 arc = ERROR_NOT_ENOUGH_MEMORY; 3056 3056 else -
trunk/src/helpers/linklist.c
r113 r132 292 292 // item pointers upon destruction? 293 293 { 294 PLINKLIST pNewList = (PLINKLIST)malloc(sizeof(LINKLIST));295 if (pNewList )294 PLINKLIST pNewList; 295 if (pNewList = (PLINKLIST)malloc(sizeof(LINKLIST))) 296 296 lstInit(pNewList, fItemsFreeable); 297 297 return (pNewList); … … 444 444 PLISTNODE pNode = NULL; 445 445 446 if (pList) 447 if (pList->ulMagic == LINKLISTMAGIC) 448 if (pList->pFirst) 449 { 450 unsigned long ulCount = 0; 451 pNode = pList->pFirst; 452 for (ulCount = 0; 453 ((pNode) && (ulCount < ulIndex)); 454 ulCount++) 455 { 456 if (pNode->pNext) 457 pNode = pNode->pNext; 458 else 459 pNode = NULL; // exit 460 } 461 } 446 if ( (pList) 447 && (pList->ulMagic == LINKLISTMAGIC) 448 && (pList->pFirst) 449 ) 450 { 451 unsigned long ulCount = 0; 452 pNode = pList->pFirst; 453 for (ulCount = 0; 454 ((pNode) && (ulCount < ulIndex)); 455 ulCount++) 456 { 457 if (pNode->pNext) 458 pNode = pNode->pNext; 459 else 460 pNode = NULL; // exit 461 } 462 } 462 463 463 464 return (pNode); … … 480 481 pNodeFound = 0; 481 482 482 if (pList) 483 if ( (pList->ulMagic == LINKLISTMAGIC) 484 && (pItemData) 485 ) 486 { 487 pNode = pList->pFirst; 488 while (pNode) 483 if ( (pList) 484 && (pList->ulMagic == LINKLISTMAGIC) 485 && (pItemData) 486 ) 487 { 488 pNode = pList->pFirst; 489 while (pNode) 490 { 491 if (pNode->pItemData == pItemData) 489 492 { 490 if (pNode->pItemData == pItemData) 491 { 492 pNodeFound = pNode; 493 break; 494 } 495 496 pNode = pNode->pNext; 493 pNodeFound = pNode; 494 break; 497 495 } 498 } 496 497 pNode = pNode->pNext; 498 } 499 } 499 500 500 501 return (pNodeFound); … … 518 519 unsigned long ulIndex) 519 520 { 520 PLISTNODE pNode = lstNodeFromIndex(pList, ulIndex);521 if (pNode )521 PLISTNODE pNode; 522 if (pNode = lstNodeFromIndex(pList, ulIndex)) 522 523 return (pNode->pItemData); 523 524 else … … 580 581 const char *function) 581 582 { 582 PLISTNODE pNewNode = 0; 583 584 if (pList) 585 if (pList->ulMagic == LINKLISTMAGIC) 586 { 587 if (pNewNode = (PLISTNODE)memdMalloc(sizeof(LISTNODE), file, line, function)) 588 { 589 memset(pNewNode, 0, sizeof(LISTNODE)); 590 pNewNode->pItemData = pNewItemData; 591 592 if (pList->pLast) 593 { 594 // list is not empty: append to tail 595 596 // 1) make last item point to new node 597 pList->pLast->pNext = pNewNode; 598 // 2) make new node point to last item 599 pNewNode->pPrevious = pList->pLast; 600 // 3) store new node as new last item 601 pList->pLast = pNewNode; 602 603 pList->ulCount++; 604 } 605 else 606 { 607 // list is empty: insert as first 608 pList->pFirst 609 = pList->pLast 610 = pNewNode; 611 612 pList->ulCount = 1; 613 } 614 } 615 } 583 PLISTNODE pNewNode = NULL; 584 585 if ( (pList) 586 && (pList->ulMagic == LINKLISTMAGIC) 587 && (pNewNode = (PLISTNODE)memdMalloc(sizeof(LISTNODE), file, line, function)) 588 ) 589 { 590 memset(pNewNode, 0, sizeof(LISTNODE)); 591 pNewNode->pItemData = pNewItemData; 592 593 if (pList->pLast) 594 { 595 // list is not empty: append to tail 596 597 // 1) make last item point to new node 598 pList->pLast->pNext = pNewNode; 599 // 2) make new node point to last item 600 pNewNode->pPrevious = pList->pLast; 601 // 3) store new node as new last item 602 pList->pLast = pNewNode; 603 604 pList->ulCount++; 605 } 606 else 607 { 608 // list is empty: insert as first 609 pList->pFirst 610 = pList->pLast 611 = pNewNode; 612 613 pList->ulCount = 1; 614 } 615 } 616 616 617 617 return (pNewNode); … … 635 635 void* pNewItemData) // in: data to store in list node 636 636 { 637 PLISTNODE pNewNode = 0; 638 639 if (pList) 640 if (pList->ulMagic == LINKLISTMAGIC) 641 { 642 if (pNewNode = (PLISTNODE)malloc(sizeof(LISTNODE))) 643 { 644 memset(pNewNode, 0, sizeof(LISTNODE)); 645 pNewNode->pItemData = pNewItemData; 646 647 if (pList->pLast) 648 { 649 // list is not empty: append to tail 650 651 // 1) make last item point to new node 652 pList->pLast->pNext = pNewNode; 653 // 2) make new node point to last item 654 pNewNode->pPrevious = pList->pLast; 655 // 3) store new node as new last item 656 pList->pLast = pNewNode; 657 658 pList->ulCount++; 659 } 660 else 661 { 662 // list is empty: insert as first 663 pList->pFirst 664 = pList->pLast 665 = pNewNode; 666 667 pList->ulCount = 1; 668 } 669 } 670 } 637 PLISTNODE pNewNode = NULL; 638 639 if ( (pList) 640 && (pList->ulMagic == LINKLISTMAGIC) 641 && (pNewNode = (PLISTNODE)malloc(sizeof(LISTNODE))) 642 ) 643 { 644 memset(pNewNode, 0, sizeof(LISTNODE)); 645 pNewNode->pItemData = pNewItemData; 646 647 if (pList->pLast) 648 { 649 // list is not empty: append to tail 650 651 // 1) make last item point to new node 652 pList->pLast->pNext = pNewNode; 653 // 2) make new node point to last item 654 pNewNode->pPrevious = pList->pLast; 655 // 3) store new node as new last item 656 pList->pLast = pNewNode; 657 658 pList->ulCount++; 659 } 660 else 661 { 662 // list is empty: insert as first 663 pList->pFirst 664 = pList->pLast 665 = pNewNode; 666 667 pList->ulCount = 1; 668 } 669 } 671 670 672 671 return (pNewNode); … … 703 702 unsigned long ulIndex) 704 703 { 705 PLISTNODE pNewNode = 0; 706 707 if (pList) 708 if (pList->ulMagic == LINKLISTMAGIC) 709 { 710 if (pNewNode = (PLISTNODE)malloc(sizeof(LISTNODE))) 704 PLISTNODE pNewNode = NULL; 705 706 if ( (pList) 707 && (pList->ulMagic == LINKLISTMAGIC) 708 && (pNewNode = (PLISTNODE)malloc(sizeof(LISTNODE))) 709 ) 710 { 711 memset(pNewNode, 0, sizeof(LISTNODE)); 712 pNewNode->pItemData = pNewItemData; 713 714 if (ulIndex == 0) 715 { 716 // insert at beginning: 717 if (pList->pFirst) 718 pList->pFirst->pPrevious = pNewNode; 719 720 pNewNode->pNext = pList->pFirst; 721 pNewNode->pPrevious = NULL; 722 723 pList->pFirst = pNewNode; 724 725 if (!pList->pLast) 726 // the list was empty: 727 pList->pLast = pNewNode; // V0.9.14 (2001-07-14) [umoeller] 728 729 (pList->ulCount)++; 730 } 731 else 732 { 733 // insert at a later position: 734 PLISTNODE pNodeInsertAfter = lstNodeFromIndex( 735 pList, 736 (ulIndex-1)); 737 738 if (pNodeInsertAfter) 711 739 { 712 memset(pNewNode, 0, sizeof(LISTNODE)); 713 pNewNode->pItemData = pNewItemData; 714 715 if (ulIndex == 0) 716 { 717 // insert at beginning: 718 if (pList->pFirst) 719 pList->pFirst->pPrevious = pNewNode; 720 721 pNewNode->pNext = pList->pFirst; 722 pNewNode->pPrevious = NULL; 723 724 pList->pFirst = pNewNode; 725 726 if (!pList->pLast) 727 // the list was empty: 728 pList->pLast = pNewNode; // V0.9.14 (2001-07-14) [umoeller] 729 730 (pList->ulCount)++; 731 } 732 else 733 { 734 // insert at a later position: 735 PLISTNODE pNodeInsertAfter = lstNodeFromIndex( 736 pList, 737 (ulIndex-1)); 738 739 if (pNodeInsertAfter) 740 { 741 // 1) set pointers for new node 742 pNewNode->pPrevious = pNodeInsertAfter; 743 pNewNode->pNext = pNodeInsertAfter->pNext; 744 745 // 2) adjust next item 746 // so that it points to the new node 747 if (pNodeInsertAfter->pNext) 748 pNodeInsertAfter->pNext->pPrevious = pNewNode; 749 750 // 3) adjust previous item 751 // so that it points to the new node 752 pNodeInsertAfter->pNext = pNewNode; 753 754 // 4) adjust last item, if necessary 755 if (pList->pLast == pNodeInsertAfter) 756 pList->pLast = pNewNode; 757 758 (pList->ulCount)++; 759 } 760 else 761 { 762 // item index too large: append instead 763 free(pNewNode); 764 pNewNode = lstAppendItem(pList, pNewItemData); 765 } 766 } 740 // 1) set pointers for new node 741 pNewNode->pPrevious = pNodeInsertAfter; 742 pNewNode->pNext = pNodeInsertAfter->pNext; 743 744 // 2) adjust next item 745 // so that it points to the new node 746 if (pNodeInsertAfter->pNext) 747 pNodeInsertAfter->pNext->pPrevious = pNewNode; 748 749 // 3) adjust previous item 750 // so that it points to the new node 751 pNodeInsertAfter->pNext = pNewNode; 752 753 // 4) adjust last item, if necessary 754 if (pList->pLast == pNodeInsertAfter) 755 pList->pLast = pNewNode; 756 757 (pList->ulCount)++; 767 758 } 768 } 759 else 760 { 761 // item index too large: append instead 762 free(pNewNode); 763 pNewNode = lstAppendItem(pList, pNewItemData); 764 } 765 } 766 } 769 767 770 768 return (pNewNode); … … 797 795 BOOL fFound = FALSE; 798 796 799 if ( pList)800 if ((pList->ulMagic == LINKLISTMAGIC)801 && (pRemoveNode)802 )803 {804 if (pList->pFirst == pRemoveNode)805 // item to be removed is first: adjust first806 pList->pFirst = pRemoveNode->pNext; // can be NULL807 if (pList->pLast == pRemoveNode)808 // item to be removed is last: adjust last809 pList->pLast = pRemoveNode->pPrevious; // can be NULL810 811 if (pRemoveNode->pPrevious)812 // adjust previous item813 pRemoveNode->pPrevious->pNext = pRemoveNode->pNext;814 815 if (pRemoveNode->pNext)816 // adjust next item817 pRemoveNode->pNext->pPrevious = pRemoveNode->pPrevious;818 819 // decrease list count820 pList->ulCount--;821 822 // free node data823 if (pList->fItemsFreeable)824 if (pRemoveNode->pItemData)825 free(pRemoveNode->pItemData);826 // free node827 free(pRemoveNode);828 829 fFound = TRUE;830 }797 if ( (pList) 798 && (pList->ulMagic == LINKLISTMAGIC) 799 && (pRemoveNode) 800 ) 801 { 802 if (pList->pFirst == pRemoveNode) 803 // item to be removed is first: adjust first 804 pList->pFirst = pRemoveNode->pNext; // can be NULL 805 if (pList->pLast == pRemoveNode) 806 // item to be removed is last: adjust last 807 pList->pLast = pRemoveNode->pPrevious; // can be NULL 808 809 if (pRemoveNode->pPrevious) 810 // adjust previous item 811 pRemoveNode->pPrevious->pNext = pRemoveNode->pNext; 812 813 if (pRemoveNode->pNext) 814 // adjust next item 815 pRemoveNode->pNext->pPrevious = pRemoveNode->pPrevious; 816 817 // decrease list count 818 pList->ulCount--; 819 820 // free node data 821 if (pList->fItemsFreeable) 822 if (pRemoveNode->pItemData) 823 free(pRemoveNode->pItemData); 824 // free node 825 free(pRemoveNode); 826 827 fFound = TRUE; 828 } 831 829 832 830 return (fFound); … … 852 850 BOOL lstRemoveItem(PLINKLIST pList, void* pRemoveItem) 853 851 { 854 BOOL brc = FALSE; 855 856 PLISTNODE pNode = lstNodeFromItem(pList, pRemoveItem); 857 858 if (pNode) 859 brc = lstRemoveNode(pList, pNode); 860 861 return (brc); 852 PLISTNODE pNode; 853 854 if (pNode = lstNodeFromItem(pList, pRemoveItem)) 855 return (lstRemoveNode(pList, pNode)); 856 857 return (FALSE); 862 858 } 863 859 … … 875 871 PLISTNODE pNode2) 876 872 { 877 BOOL brc = FALSE;878 879 873 if ( (pNode1) && (pNode2) ) 880 874 { … … 883 877 pNode2->pItemData = pTemp; 884 878 885 brc = TRUE;879 return (TRUE); 886 880 } 887 881 888 return ( brc);882 return (FALSE); 889 883 } 890 884 … … 907 901 { 908 902 long ll = lLeft, 909 lr = lRight -1,903 lr = lRight - 1, 910 904 lPivot = lRight; 911 905 … … 919 913 { 920 914 // compare left item data to pivot item data 921 while ( (*pfnSort)(pNodeLeft->pItemData,922 pNodePivot->pItemData,923 pStorage)915 while ( pfnSort(pNodeLeft->pItemData, 916 pNodePivot->pItemData, 917 pStorage) 924 918 < 0 ) 925 919 { … … 930 924 931 925 // compare right item to pivot 932 while ( ( (*pfnSort)(pNodeRight->pItemData,933 pNodePivot->pItemData,934 pStorage)926 while ( ( pfnSort(pNodeRight->pItemData, 927 pNodePivot->pItemData, 928 pStorage) 935 929 >= 0 ) 936 930 && (lr > ll) … … 953 947 954 948 // recurse! 955 lstQuickSort2(pList, pfnSort, pStorage, lLeft, ll-1); 956 lstQuickSort2(pList, pfnSort, pStorage, ll+1, lRight); 949 lstQuickSort2(pList, pfnSort, pStorage, 950 lLeft, 951 ll - 1); 952 lstQuickSort2(pList, pfnSort, pStorage, 953 ll + 1, 954 lRight); 957 955 } 958 956 } … … 994 992 BOOL brc = FALSE; 995 993 996 if ( pList)997 if ((pList->ulMagic == LINKLISTMAGIC)998 && (pfnSort)999 )1000 {1001 long lRight = lstCountItems(pList)-1;1002 1003 lstQuickSort2(pList, pfnSort, pStorage,1004 0, // lLeft1005 lRight);1006 brc = TRUE;1007 }994 if ( (pList) 995 && (pList->ulMagic == LINKLISTMAGIC) 996 && (pfnSort) 997 ) 998 { 999 long lRight = lstCountItems(pList) - 1; 1000 1001 lstQuickSort2(pList, pfnSort, pStorage, 1002 0, // lLeft 1003 lRight); 1004 brc = TRUE; 1005 } 1008 1006 1009 1007 return (brc); -
trunk/src/helpers/memdebug.c
r123 r132 753 753 // before each output line 754 754 { 755 PSZ psz = strhCreateDump(pb, ulSize, ulIndent);756 if (psz )755 PSZ psz; 756 if (psz = strhCreateDump(pb, ulSize, ulIndent)) 757 757 { 758 _Pmpf(("\n%s", psz));758 // _Pmpf(("\n%s", psz)); 759 759 free(psz); 760 760 } -
trunk/src/helpers/stringh.c
r127 r132 347 347 *@@ strhncpy0: 348 348 * like strncpy, but always appends a 0 character. 349 * 350 *@@changed V0.9.16 (2002-01-09) [umoeller]: fixed crash on null pszSource 349 351 */ 350 352 … … 354 356 { 355 357 ULONG ul = 0; 356 PSZ pTarget = pszTarget, 357 pSource = (PSZ)pszSource; 358 359 for (ul = 0; ul < cbSource; ul++) 360 if (*pSource) 361 *pTarget++ = *pSource++; 362 else 363 break; 358 PSZ pTarget = pszTarget, 359 pSource; 360 361 if (pSource = (PSZ)pszSource) // V0.9.16 (2002-01-09) [umoeller] 362 { 363 for (ul = 0; ul < cbSource; ul++) 364 if (*pSource) 365 *pTarget++ = *pSource++; 366 else 367 break; 368 } 369 364 370 *pTarget = 0; 365 371 … … 529 535 if (pszBuf) 530 536 { 531 PSZ pOpen = strchr(pszBuf, cOpen);532 if (pOpen )537 PSZ pOpen; 538 if (pOpen = strchr(pszBuf, cOpen)) 533 539 { 534 540 // opening char found: -
trunk/src/helpers/threads.c
r123 r132 501 501 PLISTNODE pNode; 502 502 *pcThreads = lstCountItems(&G_llThreadInfos); 503 pArray = (PTHREADINFO)malloc(*pcThreads * sizeof(THREADINFO)); 504 pThis = pArray; 505 506 pNode = lstQueryFirstNode(&G_llThreadInfos); 507 while (pNode) 503 if (pArray = (PTHREADINFO)malloc(*pcThreads * sizeof(THREADINFO))) 508 504 { 509 memcpy(pThis, 510 (PTHREADINFO)pNode->pItemData, 511 sizeof(THREADINFO)); 512 pThis++; 513 pNode = pNode->pNext; 505 pThis = pArray; 506 507 pNode = lstQueryFirstNode(&G_llThreadInfos); 508 while (pNode) 509 { 510 memcpy(pThis, 511 (PTHREADINFO)pNode->pItemData, 512 sizeof(THREADINFO)); 513 pThis++; 514 pNode = pNode->pNext; 515 } 514 516 } 515 517 -
trunk/src/helpers/winh.c
r129 r132 4510 4510 HWND hwndStatusBar = winhCreateStatusBar(hwndFrame, 4511 4511 hwndFrame, 4512 NULL,4512 "", 4513 4513 "9.WarpSans", 4514 4514 CLR_BLACK); -
trunk/src/helpers/xstring.c
r129 r132 129 129 void XWPENTRY xstrInitDebug(PXSTRING pxstr, 130 130 ULONG ulPreAllocate, 131 const char *file,131 PCSZ file, 132 132 unsigned long line, 133 const char *function)133 PCSZ function) 134 134 { 135 135 memset(pxstr, 0, sizeof(XSTRING)); … … 194 194 195 195 /* 196 *@@ xstrInitSet :196 *@@ xstrInitSet2: 197 197 * this can be used instead of xstrInit if you 198 198 * have a free()'able string you want to initialize … … 212 212 + xstrInitSet(&str, strdup("blah")); 213 213 * 214 *@@added V0.9. 6 (2000-11-01) [umoeller]215 * @@changed V0.9.9 (2001-03-09) [umoeller]: added ulDelta216 */ 217 218 void xstrInitSet(PXSTRING pxstr,219 PSZ pszNew)214 *@@added V0.9.16 (2002-01-13) [umoeller] 215 */ 216 217 void xstrInitSet2(PXSTRING pxstr, 218 PSZ pszNew, 219 ULONG ulNewLength) 220 220 { 221 221 if (!pszNew) … … 223 223 else 224 224 { 225 if (!ulNewLength) 226 ulNewLength = strlen(pszNew); 225 227 pxstr->psz = pszNew; 226 pxstr->ulLength = strlen(pszNew); 227 pxstr->cbAllocated = pxstr->ulLength + 1; 228 pxstr->ulDelta = pxstr->ulLength * 10 / 100; 229 } 228 pxstr->ulLength = ulNewLength; 229 pxstr->cbAllocated = ulNewLength + 1; 230 pxstr->ulDelta = ulNewLength * 10 / 100; 231 } 232 } 233 234 /* 235 *@@ xstrInitSet: 236 * shortcut to xstrInitSet2 to retain compatibility. 237 * 238 *@@added V0.9.6 (2000-11-01) [umoeller] 239 *@@changed V0.9.9 (2001-03-09) [umoeller]: added ulDelta 240 */ 241 242 void xstrInitSet(PXSTRING pxstr, 243 PSZ pszNew) 244 { 245 xstrInitSet2(pxstr, pszNew, 0); 230 246 } 231 247 … … 239 255 240 256 void XWPENTRY xstrInitCopyDebug(PXSTRING pxstr, 241 const char *pcszSource,257 PCSZ pcszSource, 242 258 ULONG ulExtraAllocate, 243 const char *file,259 PCSZ file, 244 260 unsigned long line, 245 const char *function)261 PCSZ function) 246 262 { 247 263 if (pxstr) … … 301 317 302 318 void xstrInitCopy(PXSTRING pxstr, 303 const char *pcszSource,319 PCSZ pcszSource, 304 320 ULONG ulExtraAllocate) // in: if > 0, extra memory to allocate 305 321 { … … 497 513 498 514 /* 499 *@@ xstrset :515 *@@ xstrset2: 500 516 * sets the specified XSTRING to a new string 501 517 * without copying it. … … 511 527 * is true if pszNew comes from strdup(). 512 528 * 513 *@@added V0.9.6 (2000-11-01) [umoeller] 514 *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL target crash 515 */ 516 517 ULONG xstrset(PXSTRING pxstr, // in/out: string 518 PSZ pszNew) // in: heap PSZ to use 529 * With this function, you can pass in the 530 * length of the string in ulNewLength. 531 * Otherwise use xstrset. 532 * 533 *@@added V0.9.16 (2002-01-13) [umoeller] 534 */ 535 536 ULONG xstrset2(PXSTRING pxstr, // in/out: string 537 PSZ pszNew, // in: heap PSZ to use 538 ULONG ulNewLength) // in: length of string or 0 to run strlen here 519 539 { 520 540 if (!pxstr) … … 525 545 if (pszNew) 526 546 { 527 pxstr->ulLength = strlen(pszNew); 528 pxstr->cbAllocated = pxstr->ulLength + 1; 529 530 pxstr->ulDelta = pxstr->cbAllocated * 10 / 100; 547 if (!ulNewLength) 548 ulNewLength = strlen(pszNew); 549 pxstr->ulLength = ulNewLength; 550 pxstr->cbAllocated = ulNewLength + 1; 551 552 pxstr->ulDelta = ulNewLength * 10 / 100; 531 553 } 532 554 // else null string: cbAllocated and ulLength are 0 already 533 555 534 556 return (pxstr->ulLength); 557 } 558 559 /* 560 *@@ xstrset: 561 * shortcut for xstrset2 for retaining compatibility. 562 * 563 *@@added V0.9.6 (2000-11-01) [umoeller] 564 *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL target crash 565 */ 566 567 ULONG xstrset(PXSTRING pxstr, // in/out: string 568 PSZ pszNew) // in: heap PSZ to use 569 { 570 return (xstrset2(pxstr, pszNew, 0)); 535 571 } 536 572 … … 583 619 584 620 ULONG xstrcpy(PXSTRING pxstr, // in/out: string 585 const char *pcszSource, // in: source, can be NULL621 PCSZ pcszSource, // in: source, can be NULL 586 622 ULONG ulSourceLength) // in: length of pcszSource or 0 587 623 { … … 694 730 695 731 ULONG xstrcat(PXSTRING pxstr, // in/out: string 696 const char *pcszSource, // in: source, can be NULL732 PCSZ pcszSource, // in: source, can be NULL 697 733 ULONG ulSourceLength) // in: length of pcszSource or 0 698 734 { … … 863 899 ULONG ulFirstReplOfs, // in: ofs of first char to replace 864 900 ULONG cReplLen, // in: no. of chars to replace 865 const char *pcszReplaceWith, // in: string to replace chars with901 PCSZ pcszReplaceWith, // in: string to replace chars with 866 902 ULONG cReplaceWithLen) // in: length of replacement string 867 903 // (this MUST be specified; if 0, chars are removed only) … … 1014 1050 size_t *pShiftTable, // in: shift table (see strhmemfind) 1015 1051 PBOOL pfRepeatFind, // in: repeat find? (see strhmemfind) 1016 const char *pcszBeginChars, // suggestion: "\x0d\x0a ()/\\-,."1017 const char *pcszEndChars) // suggestion: "\x0d\x0a ()/\\-,.:;"1052 PCSZ pcszBeginChars, // suggestion: "\x0d\x0a ()/\\-,." 1053 PCSZ pcszEndChars) // suggestion: "\x0d\x0a ()/\\-,.:;" 1018 1054 { 1019 1055 PSZ pReturn = 0; … … 1025 1061 if ((pxstr->ulLength) && (ulFoundLen)) 1026 1062 { 1027 const char *p = pxstr->psz + ulOfs;1063 PCSZ p = pxstr->psz + ulOfs; 1028 1064 1029 1065 do // while p … … 1152 1188 // yes: 1153 1189 ULONG ulOfs = *pulOfs; 1154 const char *pFound1155 = ( const char *)strhmemfind(pxstr->psz + ulOfs, // in: haystack1190 PCSZ pFound 1191 = (PCSZ)strhmemfind(pxstr->psz + ulOfs, // in: haystack 1156 1192 pxstr->ulLength - ulOfs, 1157 1193 pstrSearch->psz, … … 1199 1235 PULONG pulOfs, // in: where to begin search (0 = start); 1200 1236 // out: ofs of first char after replacement string 1201 const char *pcszSearch, // in: search string; cannot be NULL1202 const char *pcszReplace) // in: replacement string; cannot be NULL1237 PCSZ pcszSearch, // in: search string; cannot be NULL 1238 PCSZ pcszReplace) // in: replacement string; cannot be NULL 1203 1239 { 1204 1240 XSTRING xstrFind, … … 1292 1328 1293 1329 ULONG xstrEncode(PXSTRING pxstr, // in/out: string to convert 1294 const char *pcszEncode) // in: characters to encode (e.g. "%,();=")1330 PCSZ pcszEncode) // in: characters to encode (e.g. "%,();=") 1295 1331 { 1296 1332 ULONG ulrc = 0,
Note:
See TracChangeset
for help on using the changeset viewer.
