4 // PopupMenu Library - Linked Lists
6 // Copyright (C)2000 Henrik Isaksson <henrik@boing.nu>
7 // All Rights Reserved.
15 #include <exec/memory.h>
17 #include <proto/exec.h>
18 #include <clib/alib_protos.h>
21 // PM_InitList - allocate and initialize an Exec MinList structure.
23 PMDList
*PM_InitList(void)
27 newlist
=(PMDList
*)AllocVec(sizeof(struct MinList
), MEMF_ANY
);
29 NewList((struct List
*)newlist
);
36 // PM_FreeList - free all nodes in a list and the list structure itself.
38 void PM_FreeList(PMDList
*list
)
43 worknode
= (PMGLN
*)(list
->mlh_Head
); /* First node */
44 while ((nextnode
= (PMGLN
*)(worknode
->n
.mln_Succ
))) {
45 PM_FreeNode((PMNode
*)worknode
);
53 // PM_CopyList - copy a list.
55 PMDList
*PM_CopyList(PMDList
*list
)
61 newlist
=PM_InitList();
64 worknode
= (PMGLN
*)(list
->mlh_Head
); /* First node */
65 while ((nextnode
= (PMGLN
*)(worknode
->n
.mln_Succ
))) {
66 PMGLN
*copy
=(PMGLN
*)PM_CopyNode((PMNode
*)worknode
);
67 if (copy
) PM_AddToList(newlist
, (PMNode
*)copy
);
77 // PM_AddToList - add A to list l.
79 void PM_AddToList(PMDList
*l
, PMNode
*A
)
81 AddHead((struct List
*)l
, (struct Node
*)A
);
85 // PM_Unlink - remove A from list l.
87 void PM_Unlink(PMDList
*l
, PMNode
*A
)
89 Remove((struct Node
*)A
);
93 // PM_FreeNode - free a PMNode.
95 void PM_FreeNode(PMNode
*A
)
101 // PM_CopyNode - copy a PMNode.
103 PMNode
*PM_CopyNode(PMNode
*A
)
105 PMNode
*newnode
=NULL
;
108 newnode
=(PMNode
*)AllocVec(((PMGLN
*)A
)->Length
, MEMF_ANY
);
110 CopyMem(A
, newnode
, ((PMGLN
*)A
)->Length
);