2 Copyright 2004-2007, The AROS Development Team. All rights reserved.
3 This file is part of the Wanderer Preferences program, which is distributed
4 under the terms of version 2 of the GNU General Public License.
6 $Id: entryelements.c 26862 2007-09-27 01:02:45Z weissms $
9 #include <proto/exec.h>
10 #include <proto/utility.h>
11 #include <proto/dos.h>
13 #include <clib/alib_protos.h>
17 #define HAVE_ELEMENTFUNCS
18 #include "entryelements.h"
20 ULONG
EntryElementCount(struct List
*entry_List
)
23 struct EntryElement__Entry
*current_Node
= NULL
;
25 ForeachNode(entry_List
, current_Node
)
32 BOOL
EntryElementRegister(struct List
*entry_List
, ULONG entry_ID
, char *entry_Name
)
34 struct EntryElement__Entry
*current_Node
= NULL
;
35 IPTR element_NameLen
= strlen(entry_Name
) ;
37 //If the element already exists fail ..
38 ForeachNode(entry_List
, current_Node
)
40 if ((current_Node
->EE_E_ID
== (IPTR
)entry_ID
) ||
41 (strcmp(current_Node
->EE_E_Name
, entry_Name
) == 0))
45 current_Node
= AllocVec(sizeof(struct EntryElement__Entry
), MEMF_PUBLIC
|MEMF_CLEAR
);
46 current_Node
->EE_E_Name
= AllocVec(element_NameLen
+ 1, MEMF_PUBLIC
|MEMF_CLEAR
);
47 strncpy(current_Node
->EE_E_Name
, entry_Name
, element_NameLen
);
49 current_Node
->EE_E_ID
= (IPTR
)entry_ID
;
50 AddTail(entry_List
, (struct Node
*)current_Node
);
55 void EntryElementRemove(struct List
*entry_List
, ULONG entry_ID
)
57 struct EntryElement__Entry
*current_Node
= NULL
;
59 ForeachNode(entry_List
, current_Node
)
61 if (current_Node
->EE_E_ID
== (IPTR
)entry_ID
)
63 #warning "todo: remove the elements node and free its storage"
68 IPTR
EntryElementFindNode(struct List
*entry_List
, ULONG entry_ID
)
70 struct EntryElement__Entry
*current_Node
= NULL
;
72 ForeachNode(entry_List
, current_Node
)
74 if (current_Node
->EE_E_ID
== (IPTR
)entry_ID
)
75 return (IPTR
)current_Node
;
80 IPTR
EntryElementFindNamedNode(struct List
*entry_List
, char * entry_Name
)
82 struct EntryElement__Entry
*current_Node
= NULL
;
84 ForeachNode(entry_List
, current_Node
)
86 if (strcmp(current_Node
->EE_E_Name
, entry_Name
) == 0)
87 return (IPTR
)current_Node
;
92 IPTR
GetEntryElementName(IPTR entry
)
94 return (IPTR
)(((struct EntryElement__Entry
*)entry
)->EE_E_Name
);
97 IPTR
GetEntryElementID(IPTR entry
)
99 return ((struct EntryElement__Entry
*)entry
)->EE_E_ID
;