nouveau.hidd: disable warnings about not initialized variables
[AROS.git] / workbench / classes / gadgets / aroslist / helpfuncs.c
blob6170839e42700c5ffedc633db0aabb45d35dc6c6
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Help functions for aroslistclass.
6 Lang: english
7 */
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
15 #define DEBUG 1
16 #endif
18 #include <aros/debug.h>
20 /**************/
21 /* CountItems */
22 /**************/
24 ULONG CountItems(APTR *array)
26 /* D(bug("aroslist:CountItems(array=%p)\n", array)); */
28 register ULONG i;
29 for (i = 0; *array ++; i ++) ;
31 /* ReturnInt("aroslist:CountItems", ULONG, i); */
32 return (i);
35 /****************/
36 /* AllocEntries */
37 /****************/
39 struct ListEntry **AllocEntries(ULONG numnewentries,
40 struct ListData *data
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
49 later deallocation */
51 numnewentries ++;
53 nodes = AllocVec(UB(&nodes[numnewentries]) - UB(&nodes[0]), MEMF_ANY);
54 if (nodes)
56 struct ListEntry **pointerarray = NULL;
58 /* Allocate memory for expanded pointerarray */
59 numnewentries --;
60 pointerarray = AllocVec(UB(&pointerarray[numnewentries + data->ld_NumAllocated])
61 - UB(&pointerarray[0]),
62 MEMF_ANY);
63 if (pointerarray)
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 */
71 nodes ++;
72 for (; numnewentries --;)
74 AddLEHead(data->ld_UnusedEntries, nodes);
75 nodes ++;
78 ReturnPtr ("aroslist:AllocItems", struct ListEntry **, pointerarray);
79 } /* if (pointerarray) */
80 FreeVec(nodes);
82 } /* if (nodes) */
83 ReturnPtr ("aroslist:AllocItems", struct ListEntry **, NULL);
86 /***************/
87 /* InsertItems */
88 /***************/
90 ULONG InsertItems(APTR *itemarray,
91 struct ListEntry **pointerarray,
92 LONG pos,
93 struct ListData *data
96 register struct ListEntry **leptr;
97 register struct ListEntry *le;
98 register ULONG numinserted = 0;
101 leptr = &pointerarray[pos];
105 while(*itemarray)
108 le = data->ld_UnusedEntries;
110 if (data->ld_ConstructHook)
112 le->le_Item = (APTR)CallHookPkt(data->ld_ConstructHook,
113 data->ld_Pool,
114 *itemarray);
116 else
118 le->le_Item = *itemarray;
120 itemarray ++;
122 if (le->le_Item)
124 /* If constructhook succeeded, remove entry
125 * from list of unused entries.
127 RemLEHead(data->ld_UnusedEntries);
128 le->le_Flags = 0;
130 /* Point to new ListEntry in the pointerarray */
131 *leptr ++ = le;
133 numinserted ++;
137 return (numinserted);