2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Desc: Help functions for aroslistclass.
9 #include <proto/exec.h>
10 #include <proto/utility.h>
11 #include <exec/memory.h>
12 #include "aroslist_intern.h"
14 #ifndef TURN_OFF_DEBUG
18 #include <aros/debug.h>
24 ULONG
CountItems(APTR
*array
)
26 /* D(bug("aroslist:CountItems(array=%p)\n", array)); */
29 for (i
= 0; *array
++; i
++) ;
31 /* ReturnInt("aroslist:CountItems", ULONG, i); */
39 struct ListEntry
**AllocEntries(ULONG numnewentries
,
43 struct ListEntry
*nodes
= NULL
;
45 D(bug("aroslist:AllocEntries(numnewentries=%d, data=%p)\n", numnewentries
, data
));
47 /* Allocate memory for ListEntrys.
48 We need the first node for keeping the list of these node-arrays for
53 nodes
= AllocVec(UB(&nodes
[numnewentries
]) - UB(&nodes
[0]), MEMF_ANY
);
56 struct ListEntry
**pointerarray
= NULL
;
58 /* Allocate memory for expanded pointerarray */
60 pointerarray
= AllocVec(UB(&pointerarray
[numnewentries
+ data
->ld_NumAllocated
])
61 - UB(&pointerarray
[0]),
65 /* Add the nodearray to the internal list of entry arrays */
66 AddLEHead(data
->ld_EntryTables
, nodes
);
68 data
->ld_NumAllocated
+= numnewentries
;
70 /* Skip the dummy node */
72 for (; numnewentries
--;)
74 AddLEHead(data
->ld_UnusedEntries
, nodes
);
78 ReturnPtr ("aroslist:AllocItems", struct ListEntry
**, pointerarray
);
79 } /* if (pointerarray) */
83 ReturnPtr ("aroslist:AllocItems", struct ListEntry
**, NULL
);
90 ULONG
InsertItems(APTR
*itemarray
,
91 struct ListEntry
**pointerarray
,
96 register struct ListEntry
**leptr
;
97 register struct ListEntry
*le
;
98 register ULONG numinserted
= 0;
101 leptr
= &pointerarray
[pos
];
108 le
= data
->ld_UnusedEntries
;
110 if (data
->ld_ConstructHook
)
112 le
->le_Item
= (APTR
)CallHookPkt(data
->ld_ConstructHook
,
118 le
->le_Item
= *itemarray
;
124 /* If constructhook succeeded, remove entry
125 * from list of unused entries.
127 RemLEHead(data
->ld_UnusedEntries
);
130 /* Point to new ListEntry in the pointerarray */
137 return (numinserted
);