ReactOS 0.4.15-dev-7674-gc0b4db1
dpa.c File Reference
#include <stdarg.h>
#include <limits.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "commctrl.h"
#include "objbase.h"
#include "comctl32.h"
#include "wine/debug.h"
Include dependency graph for dpa.c:

Go to the source code of this file.

Classes

struct  _DPA
 
struct  _STREAMDATA
 

Macros

#define COBJMACROS
 

Typedefs

typedef struct _DPA DPA
 
typedef struct _STREAMDATA STREAMDATA
 
typedef struct _STREAMDATAPSTREAMDATA
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (dpa)
 
HRESULT WINAPI DPA_LoadStream (HDPA *phDpa, PFNDPASTREAM loadProc, IStream *pStream, LPVOID pData)
 
HRESULT WINAPI DPA_SaveStream (HDPA hDpa, PFNDPASTREAM saveProc, IStream *pStream, LPVOID pData)
 
BOOL WINAPI DPA_Merge (HDPA hdpa1, HDPA hdpa2, DWORD dwFlags, PFNDPACOMPARE pfnCompare, PFNDPAMERGE pfnMerge, LPARAM lParam)
 
BOOL WINAPI DPA_Destroy (HDPA hdpa)
 
BOOL WINAPI DPA_Grow (HDPA hdpa, INT nGrow)
 
HDPA WINAPI DPA_Clone (const HDPA hdpa, HDPA hdpaNew)
 
LPVOID WINAPI DPA_GetPtr (HDPA hdpa, INT nIndex)
 
INT WINAPI DPA_GetPtrIndex (HDPA hdpa, LPCVOID p)
 
INT WINAPI DPA_InsertPtr (HDPA hdpa, INT i, LPVOID p)
 
BOOL WINAPI DPA_SetPtr (HDPA hdpa, INT i, LPVOID p)
 
LPVOID WINAPI DPA_DeletePtr (HDPA hdpa, INT i)
 
BOOL WINAPI DPA_DeleteAllPtrs (HDPA hdpa)
 
static VOID DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r, PFNDPACOMPARE pfnCompare, LPARAM lParam)
 
BOOL WINAPI DPA_Sort (HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
 
INT WINAPI DPA_Search (HDPA hdpa, LPVOID pFind, INT nStart, PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
 
HDPA WINAPI DPA_CreateEx (INT nGrow, HANDLE hHeap)
 
HDPA WINAPI DPA_Create (INT nGrow)
 
VOID WINAPI DPA_EnumCallback (HDPA hdpa, PFNDPAENUMCALLBACK enumProc, LPVOID lParam)
 
void WINAPI DPA_DestroyCallback (HDPA hdpa, PFNDPAENUMCALLBACK enumProc, LPVOID lParam)
 
ULONGLONG WINAPI DPA_GetSize (HDPA hdpa)
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 32 of file dpa.c.

Typedef Documentation

◆ DPA

typedef struct _DPA DPA

◆ PSTREAMDATA

◆ STREAMDATA

Function Documentation

◆ DPA_Clone()

HDPA WINAPI DPA_Clone ( const HDPA  hdpa,
HDPA  hdpaNew 
)

Definition at line 470 of file dpa.c.

471{
472 INT nNewItems, nSize;
473 HDPA hdpaTemp;
474
475 if (!hdpa)
476 return NULL;
477
478 TRACE("(%p %p)\n", hdpa, hdpaNew);
479
480 if (!hdpaNew) {
481 /* create a new DPA */
482 hdpaTemp = HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
483 sizeof(*hdpaTemp));
484 hdpaTemp->hHeap = hdpa->hHeap;
485 hdpaTemp->nGrow = hdpa->nGrow;
486 }
487 else
488 hdpaTemp = hdpaNew;
489
490 if (hdpaTemp->ptrs) {
491 /* remove old pointer array */
492 HeapFree (hdpaTemp->hHeap, 0, hdpaTemp->ptrs);
493 hdpaTemp->ptrs = NULL;
494 hdpaTemp->nItemCount = 0;
495 hdpaTemp->nMaxCount = 0;
496 }
497
498 /* create a new pointer array */
499 nNewItems = hdpaTemp->nGrow *
500 (((hdpa->nItemCount - 1) / hdpaTemp->nGrow) + 1);
501 nSize = nNewItems * sizeof(LPVOID);
502 hdpaTemp->ptrs = HeapAlloc (hdpaTemp->hHeap, HEAP_ZERO_MEMORY, nSize);
503 hdpaTemp->nMaxCount = nNewItems;
504
505 /* clone the pointer array */
506 hdpaTemp->nItemCount = hdpa->nItemCount;
507 memmove (hdpaTemp->ptrs, hdpa->ptrs,
508 hdpaTemp->nItemCount * sizeof(LPVOID));
509
510 return hdpaTemp;
511}
#define NULL
Definition: types.h:112
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define LPVOID
Definition: nt_native.h:45
#define TRACE(s)
Definition: solgame.cpp:4
Definition: dpa.c:49
HANDLE hHeap
Definition: dpa.c:52
INT nGrow
Definition: dpa.c:53
LPVOID * ptrs
Definition: dpa.c:51
INT nItemCount
Definition: dpa.c:50
INT nMaxCount
Definition: dpa.c:54
int32_t INT
Definition: typedefs.h:58
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2084

Referenced by init_functions().

◆ DPA_Create()

◆ DPA_CreateEx()

HDPA WINAPI DPA_CreateEx ( INT  nGrow,
HANDLE  hHeap 
)

Definition at line 909 of file dpa.c.

910{
911 HDPA hdpa;
912
913 TRACE("(%d %p)\n", nGrow, hHeap);
914
915 if (hHeap)
916 hdpa = HeapAlloc (hHeap, HEAP_ZERO_MEMORY, sizeof(*hdpa));
917 else
918 hdpa = Alloc (sizeof(*hdpa));
919
920 if (hdpa) {
921 hdpa->nGrow = max(8, nGrow);
922 hdpa->hHeap = hHeap ? hHeap : GetProcessHeap();
923 hdpa->nMaxCount = hdpa->nGrow * 2;
924 hdpa->ptrs = HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
925 hdpa->nMaxCount * sizeof(LPVOID));
926 }
927
928 TRACE("-- %p\n", hdpa);
929
930 return hdpa;
931}
PVOID Alloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: main.c:63
#define GetProcessHeap()
Definition: compat.h:736
#define max(a, b)
Definition: svc.c:63

Referenced by DPA_Create(), and init_functions().

◆ DPA_DeleteAllPtrs()

BOOL WINAPI DPA_DeleteAllPtrs ( HDPA  hdpa)

Definition at line 730 of file dpa.c.

731{
732 TRACE("(%p)\n", hdpa);
733
734 if (!hdpa)
735 return FALSE;
736
737 if (hdpa->ptrs && (!HeapFree (hdpa->hHeap, 0, hdpa->ptrs)))
738 return FALSE;
739
740 hdpa->nItemCount = 0;
741 hdpa->nMaxCount = hdpa->nGrow * 2;
742 hdpa->ptrs = HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
743 hdpa->nMaxCount * sizeof(LPVOID));
744
745 return TRUE;
746}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117

Referenced by CPointerArray< T, GrowthRate >::Clear(), init_functions(), and ranges_clear().

◆ DPA_DeletePtr()

LPVOID WINAPI DPA_DeletePtr ( HDPA  hdpa,
INT  i 
)

Definition at line 677 of file dpa.c.

678{
679 LPVOID *lpDest, *lpSrc, lpTemp = NULL;
680 INT nSize;
681
682 TRACE("(%p %d)\n", hdpa, i);
683
684 if ((!hdpa) || i < 0 || i >= hdpa->nItemCount)
685 return NULL;
686
687 lpTemp = hdpa->ptrs[i];
688
689 /* do we need to move ?*/
690 if (i < hdpa->nItemCount - 1) {
691 lpDest = hdpa->ptrs + i;
692 lpSrc = lpDest + 1;
693 nSize = (hdpa->nItemCount - i - 1) * sizeof(LPVOID);
694 TRACE("-- move dest=%p src=%p size=%x\n",
695 lpDest, lpSrc, nSize);
696 memmove (lpDest, lpSrc, nSize);
697 }
698
699 hdpa->nItemCount --;
700
701 /* free memory ?*/
702 if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
703 INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount);
704 nSize = nNewItems * sizeof(LPVOID);
705 lpDest = HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
706 hdpa->ptrs, nSize);
707 if (!lpDest)
708 return NULL;
709
710 hdpa->nMaxCount = nNewItems;
711 hdpa->ptrs = lpDest;
712 }
713
714 return lpTemp;
715}
#define HeapReAlloc
Definition: compat.h:734
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by DPA_Merge(), init_functions(), LISTVIEW_DeleteAllItems(), LISTVIEW_DeleteColumn(), LISTVIEW_DeleteItem(), LISTVIEW_InsertColumnT(), LISTVIEW_InsertItemT(), ranges_add(), ranges_del(), REBAR_DeleteBand(), REBAR_HandleUDDrag(), REBAR_MoveBand(), REBAR_MoveBandToRowOffset(), CPointerArray< T, GrowthRate >::RemoveAt(), SIC_IconAppend(), TAB_DeleteItem(), TAB_Destroy(), and TREEVIEW_FreeItem().

◆ DPA_Destroy()

BOOL WINAPI DPA_Destroy ( HDPA  hdpa)

◆ DPA_DestroyCallback()

void WINAPI DPA_DestroyCallback ( HDPA  hdpa,
PFNDPAENUMCALLBACK  enumProc,
LPVOID  lParam 
)

Definition at line 1003 of file dpa.c.

1005{
1006 TRACE("(%p %p %p)\n", hdpa, enumProc, lParam);
1007
1008 DPA_EnumCallback (hdpa, enumProc, lParam);
1009 DPA_Destroy (hdpa);
1010}
LPARAM lParam
Definition: combotst.c:139
VOID WINAPI DPA_EnumCallback(HDPA hdpa, PFNDPAENUMCALLBACK enumProc, LPVOID lParam)
Definition: dpa.c:969
BOOL WINAPI DPA_Destroy(HDPA hdpa)
Definition: dpa.c:396

Referenced by CDefView::FillList(), init_functions(), SIC_Destroy(), and CPointerArray< T, GrowthRate >::~CPointerArray().

◆ DPA_EnumCallback()

VOID WINAPI DPA_EnumCallback ( HDPA  hdpa,
PFNDPAENUMCALLBACK  enumProc,
LPVOID  lParam 
)

Definition at line 969 of file dpa.c.

971{
972 INT i;
973
974 TRACE("(%p %p %p)\n", hdpa, enumProc, lParam);
975
976 if (!hdpa)
977 return;
978 if (hdpa->nItemCount <= 0)
979 return;
980
981 for (i = 0; i < hdpa->nItemCount; i++) {
982 if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
983 return;
984 }
985
986 return;
987}

Referenced by CPointerArray< T, GrowthRate >::Clear(), DPA_DestroyCallback(), init_functions(), InitShellServices(), ShutdownShellServices(), and TREEVIEW_SetFont().

◆ DPA_GetPtr()

LPVOID WINAPI DPA_GetPtr ( HDPA  hdpa,
INT  nIndex 
)

Definition at line 527 of file dpa.c.

528{
529 TRACE("(%p %d)\n", hdpa, nIndex);
530
531 if (!hdpa)
532 return NULL;
533 if (!hdpa->ptrs) {
534 WARN("no pointer array.\n");
535 return NULL;
536 }
537 if ((nIndex < 0) || (nIndex >= hdpa->nItemCount)) {
538 WARN("not enough pointers in array (%d vs %d).\n",nIndex,hdpa->nItemCount);
539 return NULL;
540 }
541
542 TRACE("-- %p\n", hdpa->ptrs[nIndex]);
543
544 return hdpa->ptrs[nIndex];
545}
#define WARN(fmt,...)
Definition: debug.h:112

◆ DPA_GetPtrIndex()

INT WINAPI DPA_GetPtrIndex ( HDPA  hdpa,
LPCVOID  p 
)

Definition at line 561 of file dpa.c.

562{
563 INT i;
564
565 if (!hdpa || !hdpa->ptrs)
566 return -1;
567
568 for (i = 0; i < hdpa->nItemCount; i++) {
569 if (hdpa->ptrs[i] == p)
570 return i;
571 }
572
573 return -1;
574}
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by CPointerArray< T, GrowthRate >::IndexOf(), init_functions(), LISTVIEW_CallBackCompareEx(), LISTVIEW_DeleteAllItems(), LISTVIEW_DeleteItem(), LISTVIEW_MapIdToIndex(), LISTVIEW_SortItems(), TREEVIEW_FreeItem(), TREEVIEW_GetItemIndex(), and TREEVIEW_VerifyItem().

◆ DPA_GetSize()

ULONGLONG WINAPI DPA_GetSize ( HDPA  hdpa)

Definition at line 1023 of file dpa.c.

1024{
1025 TRACE("(%p)\n", hdpa);
1026
1027 if (!hdpa) return 0;
1028
1029 return sizeof(DPA) + hdpa->nMaxCount*sizeof(PVOID);
1030}
struct _DPA DPA

◆ DPA_Grow()

BOOL WINAPI DPA_Grow ( HDPA  hdpa,
INT  nGrow 
)

Definition at line 423 of file dpa.c.

424{
425 INT items;
426 TRACE("(%p %d)\n", hdpa, nGrow);
427
428 if (!hdpa)
429 return FALSE;
430
431 nGrow = max( 8, nGrow );
432 items = nGrow * (((hdpa->nMaxCount - 1) / nGrow) + 1);
433 if (items > hdpa->nMaxCount)
434 {
435 void *ptr;
436
437 if (hdpa->ptrs)
438 ptr = HeapReAlloc( hdpa->hHeap, HEAP_ZERO_MEMORY, hdpa->ptrs, items * sizeof(LPVOID) );
439 else
440 ptr = HeapAlloc( hdpa->hHeap, HEAP_ZERO_MEMORY, items * sizeof(LPVOID) );
441 if (!ptr) return FALSE;
442 hdpa->nMaxCount = items;
443 hdpa->ptrs = ptr;
444 }
445 hdpa->nGrow = nGrow;
446
447 return TRUE;
448}
static PVOID ptr
Definition: dispmode.c:27
static TCHAR * items[]
Definition: page1.c:45

Referenced by DPA_LoadStream(), and init_functions().

◆ DPA_InsertPtr()

INT WINAPI DPA_InsertPtr ( HDPA  hdpa,
INT  i,
LPVOID  p 
)

Definition at line 591 of file dpa.c.

592{
593 TRACE("(%p %d %p)\n", hdpa, i, p);
594
595 if (!hdpa || i < 0) return -1;
596
597 /* append item if index is out of bounds */
598 i = min(hdpa->nItemCount, i);
599
600 /* create empty spot at the end */
601 if (!DPA_SetPtr(hdpa, hdpa->nItemCount, 0)) return -1;
602
603 if (i != hdpa->nItemCount - 1)
604 memmove (hdpa->ptrs + i + 1, hdpa->ptrs + i,
605 (hdpa->nItemCount - i - 1) * sizeof(LPVOID));
606
607 hdpa->ptrs[i] = p;
608 return i;
609}
BOOL WINAPI DPA_SetPtr(HDPA hdpa, INT i, LPVOID p)
Definition: dpa.c:626
#define min(a, b)
Definition: monoChain.cc:55

Referenced by CPointerArray< T, GrowthRate >::Append(), DPA_Merge(), CDefView::FillList(), init_functions(), CPointerArray< T, GrowthRate >::Insert(), LISTVIEW_InsertColumnT(), LISTVIEW_InsertItemT(), ranges_add(), ranges_del(), REBAR_HandleUDDrag(), REBAR_InsertBandT(), REBAR_MoveBand(), REBAR_MoveBandToRowOffset(), set_sub_item(), SIC_IconAppend(), TAB_InsertItemT(), TREEVIEW_AllocateItem(), and TREEVIEW_BuildChildDPA().

◆ DPA_LoadStream()

HRESULT WINAPI DPA_LoadStream ( HDPA phDpa,
PFNDPASTREAM  loadProc,
IStream pStream,
LPVOID  pData 
)

Definition at line 82 of file dpa.c.

84{
85 HRESULT errCode;
86 LARGE_INTEGER position;
87 ULARGE_INTEGER initial_pos;
88 STREAMDATA streamData;
89 DPASTREAMINFO streamInfo;
90 ULONG ulRead;
91 HDPA hDpa;
92 PVOID *ptr;
93
94 TRACE ("phDpa=%p loadProc=%p pStream=%p pData=%p\n",
95 phDpa, loadProc, pStream, pData);
96
97 if (!phDpa || !loadProc || !pStream)
98 return E_INVALIDARG;
99
100 *phDpa = NULL;
101
102 position.QuadPart = 0;
103
104 errCode = IStream_Seek (pStream, position, STREAM_SEEK_CUR, &initial_pos);
105 if (errCode != S_OK)
106 return errCode;
107
108 memset(&streamData, 0, sizeof(STREAMDATA));
109 errCode = IStream_Read (pStream, &streamData, sizeof(STREAMDATA), &ulRead);
110 if (errCode != S_OK)
111 return errCode;
112
113 TRACE ("dwSize=%u dwData2=%u dwItems=%u\n",
114 streamData.dwSize, streamData.dwData2, streamData.dwItems);
115
116 if (ulRead < sizeof(STREAMDATA) ||
117 streamData.dwSize < sizeof(STREAMDATA) || streamData.dwData2 != 1) {
118 /* back to initial position */
119 position.QuadPart = initial_pos.QuadPart;
120 IStream_Seek (pStream, position, STREAM_SEEK_SET, NULL);
121 return E_FAIL;
122 }
123
124 if (streamData.dwItems > (UINT_MAX / 2 / sizeof(VOID*))) /* 536870911 */
125 return E_OUTOFMEMORY;
126
127 /* create the dpa */
128 hDpa = DPA_Create (streamData.dwItems);
129 if (!hDpa)
130 return E_OUTOFMEMORY;
131
132 if (!DPA_Grow (hDpa, streamData.dwItems)) {
133 DPA_Destroy (hDpa);
134 return E_OUTOFMEMORY;
135 }
136
137 /* load data from the stream into the dpa */
138 ptr = hDpa->ptrs;
139 for (streamInfo.iPos = 0; streamInfo.iPos < streamData.dwItems; streamInfo.iPos++) {
140 errCode = (loadProc)(&streamInfo, pStream, pData);
141 if (errCode != S_OK) {
142 errCode = S_FALSE;
143 break;
144 }
145
146 *ptr = streamInfo.pvItem;
147 ptr++;
148 }
149
150 /* set the number of items */
151 hDpa->nItemCount = streamInfo.iPos;
152
153 /* store the handle to the dpa */
154 *phDpa = hDpa;
155 TRACE ("new hDpa=%p, errorcode=%x\n", hDpa, errCode);
156
157 return errCode;
158}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
BOOL WINAPI DPA_Grow(HDPA hdpa, INT nGrow)
Definition: dpa.c:423
HDPA WINAPI DPA_Create(INT nGrow)
Definition: dpa.c:950
#define UINT_MAX
Definition: limits.h:41
#define S_OK
Definition: intsafe.h:52
#define memset(x, y, z)
Definition: compat.h:39
void * pvItem
Definition: commctrl.h:4885
DWORD dwItems
Definition: dpa.c:61
DWORD dwSize
Definition: dpa.c:59
DWORD dwData2
Definition: dpa.c:60
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
#define S_FALSE
Definition: winerror.h:2357

Referenced by init_functions().

◆ DPA_Merge()

BOOL WINAPI DPA_Merge ( HDPA  hdpa1,
HDPA  hdpa2,
DWORD  dwFlags,
PFNDPACOMPARE  pfnCompare,
PFNDPAMERGE  pfnMerge,
LPARAM  lParam 
)

Definition at line 265 of file dpa.c.

268{
269 INT nCount;
270 LPVOID *pWork1, *pWork2;
271 INT nResult, i;
272 INT nIndex;
273
274 TRACE("(%p %p %08x %p %p %08lx)\n",
275 hdpa1, hdpa2, dwFlags, pfnCompare, pfnMerge, lParam);
276
277 if (IsBadWritePtr (hdpa1, sizeof(*hdpa1)))
278 return FALSE;
279
280 if (IsBadWritePtr (hdpa2, sizeof(*hdpa2)))
281 return FALSE;
282
283 if (IsBadCodePtr ((FARPROC)pfnCompare))
284 return FALSE;
285
286 if (IsBadCodePtr ((FARPROC)pfnMerge))
287 return FALSE;
288
289 if (!(dwFlags & DPAM_SORTED)) {
290 TRACE("sorting dpa's.\n");
291 if (hdpa1->nItemCount > 0)
292 DPA_Sort (hdpa1, pfnCompare, lParam);
293 TRACE ("dpa 1 sorted.\n");
294 if (hdpa2->nItemCount > 0)
295 DPA_Sort (hdpa2, pfnCompare, lParam);
296 TRACE ("dpa 2 sorted.\n");
297 }
298
299 if (hdpa2->nItemCount < 1)
300 return TRUE;
301
302 TRACE("hdpa1->nItemCount=%d hdpa2->nItemCount=%d\n",
303 hdpa1->nItemCount, hdpa2->nItemCount);
304
305
306 nIndex = hdpa1->nItemCount - 1;
307 nCount = hdpa2->nItemCount - 1;
308
309 do
310 {
311 pWork1 = &hdpa1->ptrs[nIndex];
312 pWork2 = &hdpa2->ptrs[nCount];
313
314 if (nIndex < 0) {
315 if ((nCount >= 0) && (dwFlags & DPAM_UNION)) {
316 /* Now insert the remaining new items into DPA 1 */
317 TRACE("%d items to be inserted at start of DPA 1\n",
318 nCount+1);
319 for (i=nCount; i>=0; i--) {
320 PVOID ptr;
321
322 ptr = (pfnMerge)(DPAMM_INSERT, *pWork2, NULL, lParam);
323 if (!ptr)
324 return FALSE;
325 DPA_InsertPtr (hdpa1, 0, ptr);
326 pWork2--;
327 }
328 }
329 break;
330 }
331 nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
332 TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
333 nResult, nIndex, nCount);
334
335 if (nResult == 0)
336 {
337 PVOID ptr;
338
339 ptr = (pfnMerge)(DPAMM_MERGE, *pWork1, *pWork2, lParam);
340 if (!ptr)
341 return FALSE;
342
343 nCount--;
344 *pWork1 = ptr;
345 nIndex--;
346 }
347 else if (nResult > 0)
348 {
349 /* item in DPA 1 missing from DPA 2 */
351 {
352 /* Now delete the extra item in DPA1 */
353 PVOID ptr;
354
355 ptr = DPA_DeletePtr (hdpa1, nIndex);
356
357 (pfnMerge)(DPAMM_DELETE, ptr, NULL, lParam);
358 }
359 nIndex--;
360 }
361 else
362 {
363 /* new item in DPA 2 */
364 if (dwFlags & DPAM_UNION)
365 {
366 /* Now insert the new item in DPA 1 */
367 PVOID ptr;
368
369 ptr = (pfnMerge)(DPAMM_INSERT, *pWork2, NULL, lParam);
370 if (!ptr)
371 return FALSE;
372 DPA_InsertPtr (hdpa1, nIndex+1, ptr);
373 }
374 nCount--;
375 }
376
377 }
378 while (nCount >= 0);
379
380 return TRUE;
381}
BOOL WINAPI DPA_Sort(HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
Definition: dpa.c:813
LPVOID WINAPI DPA_DeletePtr(HDPA hdpa, INT i)
Definition: dpa.c:677
INT WINAPI DPA_InsertPtr(HDPA hdpa, INT i, LPVOID p)
Definition: dpa.c:591
int(* FARPROC)()
Definition: compat.h:36
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:883
BOOL NTAPI IsBadCodePtr(FARPROC lpfn)
Definition: except.c:872
#define DPAMM_INSERT
Definition: commctrl.h:4969
#define DPAM_UNION
Definition: commctrl.h:4964
#define DPAMM_DELETE
Definition: commctrl.h:4968
#define DPAM_SORTED
Definition: commctrl.h:4962
#define DPAM_INTERSECT
Definition: commctrl.h:4965
#define DPAMM_MERGE
Definition: commctrl.h:4967
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Referenced by init_functions().

◆ DPA_QuickSort()

static VOID DPA_QuickSort ( LPVOID lpPtrs,
INT  l,
INT  r,
PFNDPACOMPARE  pfnCompare,
LPARAM  lParam 
)
static

Definition at line 764 of file dpa.c.

766{
767 INT m;
768 LPVOID t;
769
770 TRACE("l=%i r=%i\n", l, r);
771
772 if (l==r) /* one element is always sorted */
773 return;
774 if (r<l) /* oops, got it in the wrong order */
775 {
776 DPA_QuickSort(lpPtrs, r, l, pfnCompare, lParam);
777 return;
778 }
779 m = (l+r)/2; /* divide by two */
780 DPA_QuickSort(lpPtrs, l, m, pfnCompare, lParam);
781 DPA_QuickSort(lpPtrs, m+1, r, pfnCompare, lParam);
782
783 /* join the two sides */
784 while( (l<=m) && (m<r) )
785 {
786 if(pfnCompare(lpPtrs[l],lpPtrs[m+1],lParam)>0)
787 {
788 t = lpPtrs[m+1];
789 memmove(&lpPtrs[l+1],&lpPtrs[l],(m-l+1)*sizeof(lpPtrs[l]));
790 lpPtrs[l] = t;
791
792 m++;
793 }
794 l++;
795 }
796}
r l[0]
Definition: byte_order.h:168
static VOID DPA_QuickSort(LPVOID *lpPtrs, INT l, INT r, PFNDPACOMPARE pfnCompare, LPARAM lParam)
Definition: dpa.c:764
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
const GLfloat * m
Definition: glext.h:10848

Referenced by DPA_QuickSort(), and DPA_Sort().

◆ DPA_SaveStream()

HRESULT WINAPI DPA_SaveStream ( HDPA  hDpa,
PFNDPASTREAM  saveProc,
IStream pStream,
LPVOID  pData 
)

Definition at line 179 of file dpa.c.

181{
182 LARGE_INTEGER position;
183 ULARGE_INTEGER initial_pos, curr_pos;
184 STREAMDATA streamData;
185 DPASTREAMINFO streamInfo;
186 HRESULT hr;
187 PVOID *ptr;
188
189 TRACE ("hDpa=%p saveProc=%p pStream=%p pData=%p\n",
190 hDpa, saveProc, pStream, pData);
191
192 if (!hDpa || !saveProc || !pStream) return E_INVALIDARG;
193
194 /* save initial position to write header after completion */
195 position.QuadPart = 0;
196 hr = IStream_Seek (pStream, position, STREAM_SEEK_CUR, &initial_pos);
197 if (hr != S_OK)
198 return hr;
199
200 /* write empty header */
201 streamData.dwSize = sizeof(streamData);
202 streamData.dwData2 = 1;
203 streamData.dwItems = 0;
204
205 hr = IStream_Write (pStream, &streamData, sizeof(streamData), NULL);
206 if (hr != S_OK) {
207 position.QuadPart = initial_pos.QuadPart;
208 IStream_Seek (pStream, position, STREAM_SEEK_SET, NULL);
209 return hr;
210 }
211
212 /* no items - we're done */
213 if (hDpa->nItemCount == 0) return S_OK;
214
215 ptr = hDpa->ptrs;
216 for (streamInfo.iPos = 0; streamInfo.iPos < hDpa->nItemCount; streamInfo.iPos++) {
217 streamInfo.pvItem = *ptr;
218 hr = (saveProc)(&streamInfo, pStream, pData);
219 if (hr != S_OK) {
220 hr = S_FALSE;
221 break;
222 }
223 ptr++;
224 }
225
226 /* write updated header */
227 position.QuadPart = 0;
228 IStream_Seek (pStream, position, STREAM_SEEK_CUR, &curr_pos);
229
230 streamData.dwSize = curr_pos.QuadPart - initial_pos.QuadPart;
231 streamData.dwData2 = 1;
232 streamData.dwItems = streamInfo.iPos;
233
234 position.QuadPart = initial_pos.QuadPart;
235 IStream_Seek (pStream, position, STREAM_SEEK_SET, NULL);
236 IStream_Write (pStream, &streamData, sizeof(streamData), NULL);
237
238 position.QuadPart = curr_pos.QuadPart;
239 IStream_Seek (pStream, position, STREAM_SEEK_SET, NULL);
240
241 return hr;
242}
HRESULT hr
Definition: shlfolder.c:183

Referenced by init_functions().

◆ DPA_Search()

INT WINAPI DPA_Search ( HDPA  hdpa,
LPVOID  pFind,
INT  nStart,
PFNDPACOMPARE  pfnCompare,
LPARAM  lParam,
UINT  uOptions 
)

Definition at line 845 of file dpa.c.

847{
848 if (!hdpa || !pfnCompare || !pFind)
849 return -1;
850
851 TRACE("(%p %p %d %p 0x%08lx 0x%08x)\n",
852 hdpa, pFind, nStart, pfnCompare, lParam, uOptions);
853
854 if (uOptions & DPAS_SORTED) {
855 /* array is sorted --> use binary search */
856 INT l, r, x, n;
857 LPVOID *lpPtr;
858
859 /* for binary search ignore start index */
860 l = 0;
861 r = hdpa->nItemCount - 1;
862 lpPtr = hdpa->ptrs;
863 while (r >= l) {
864 x = (l + r) / 2;
865 n = (pfnCompare)(pFind, lpPtr[x], lParam);
866 if (n == 0)
867 return x;
868 else if (n < 0)
869 r = x - 1;
870 else /* (n > 0) */
871 l = x + 1;
872 }
873 if (uOptions & (DPAS_INSERTBEFORE|DPAS_INSERTAFTER)) return l;
874 }
875 else {
876 /* array is not sorted --> use linear search */
877 LPVOID *lpPtr;
878 INT nIndex;
879
880 nIndex = (nStart == -1)? 0 : nStart;
881 lpPtr = hdpa->ptrs;
882 for (; nIndex < hdpa->nItemCount; nIndex++) {
883 if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0)
884 return nIndex;
885 }
886 }
887
888 return -1;
889}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble n
Definition: glext.h:7729
#define DPAS_INSERTBEFORE
Definition: commctrl.h:4863
#define DPAS_SORTED
Definition: commctrl.h:4862
#define DPAS_INSERTAFTER
Definition: commctrl.h:4864

Referenced by init_functions(), LISTVIEW_MapIdToIndex(), ranges_add(), ranges_contain(), ranges_del(), ranges_shift(), CPointerArray< T, GrowthRate >::Search(), SIC_GetIconIndex(), and SIC_IconAppend().

◆ DPA_SetPtr()

BOOL WINAPI DPA_SetPtr ( HDPA  hdpa,
INT  i,
LPVOID  p 
)

Definition at line 626 of file dpa.c.

627{
628 LPVOID *lpTemp;
629
630 TRACE("(%p %d %p)\n", hdpa, i, p);
631
632 if (!hdpa || i < 0)
633 return FALSE;
634
635 if (hdpa->nItemCount <= i) {
636 /* within the old array */
637 if (hdpa->nMaxCount <= i) {
638 /* resize the block of memory */
639 INT nNewItems =
640 hdpa->nGrow * ((((i+1) - 1) / hdpa->nGrow) + 1);
641 INT nSize = nNewItems * sizeof(LPVOID);
642
643 if (hdpa->ptrs)
644 lpTemp = HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, hdpa->ptrs, nSize);
645 else
646 lpTemp = HeapAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY, nSize);
647
648 if (!lpTemp)
649 return FALSE;
650
651 hdpa->nMaxCount = nNewItems;
652 hdpa->ptrs = lpTemp;
653 }
654 hdpa->nItemCount = i+1;
655 }
656
657 /* put the new entry in */
658 hdpa->ptrs[i] = p;
659
660 return TRUE;
661}

Referenced by DPA_InsertPtr(), init_functions(), LISTVIEW_InsertItemT(), LISTVIEW_MoveIconTo(), ranges_clone(), and CPointerArray< T, GrowthRate >::Set().

◆ DPA_Sort()

BOOL WINAPI DPA_Sort ( HDPA  hdpa,
PFNDPACOMPARE  pfnCompare,
LPARAM  lParam 
)

Definition at line 813 of file dpa.c.

814{
815 if (!hdpa || !pfnCompare)
816 return FALSE;
817
818 TRACE("(%p %p 0x%lx)\n", hdpa, pfnCompare, lParam);
819
820 if ((hdpa->nItemCount > 1) && (hdpa->ptrs))
821 DPA_QuickSort (hdpa->ptrs, 0, hdpa->nItemCount - 1,
822 pfnCompare, lParam);
823
824 return TRUE;
825}

Referenced by DPA_Merge(), CMenuSFToolbar::FillToolbar(), init_functions(), LISTVIEW_SortItems(), CPointerArray< T, GrowthRate >::Sort(), and TREEVIEW_Sort().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( dpa  )