4 // PopupMenu Library - Linked Lists
6 // Copyright (C)2000 Henrik Isaksson <henrik@boing.nu>
7 // All Rights Reserved.
12 #include <exec/memory.h>
14 #include <proto/exec.h>
15 #include <clib/alib_protos.h>
18 // PM_InitList - allocate and initialize an Exec MinList structure.
20 PMDList
*PM_InitList(void)
22 PMDList
*newlist
=NULL
;
24 newlist
=(PMDList
*)AllocVec(sizeof(struct MinList
), MEMF_ANY
);
26 NewList((struct List
*)newlist
);
33 // PM_FreeList - free all nodes in a list and the list structure itself.
35 void PM_FreeList(PMDList
*list
)
40 worknode
= (PMGLN
*)(list
->mlh_Head
); /* First node */
41 while((nextnode
= (PMGLN
*)(worknode
->n
.mln_Succ
))) {
42 PM_FreeNode((PMNode
*)worknode
);
50 // PM_CopyList - copy a list.
52 PMDList
*PM_CopyList(PMDList
*list
)
54 PMDList
*newlist
=NULL
;
58 newlist
=PM_InitList();
61 worknode
= (PMGLN
*)(list
->mlh_Head
); /* First node */
62 while((nextnode
= (PMGLN
*)(worknode
->n
.mln_Succ
))) {
63 PMGLN
*copy
=(PMGLN
*)PM_CopyNode((PMNode
*)worknode
);
64 if(copy
) PM_AddToList(newlist
, (PMNode
*)copy
);
74 // PM_AddToList - add A to list l.
76 void PM_AddToList(PMDList
*l
, PMNode
*A
)
78 AddHead((struct List
*)l
, (struct Node
*)A
);
82 // PM_Unlink - remove A from list l.
84 void PM_Unlink(PMDList
*l
, PMNode
*A
)
86 Remove((struct Node
*)A
);
90 // PM_FreeNode - free a PMNode.
92 void PM_FreeNode(PMNode
*A
)
98 // PM_CopyNode - copy a PMNode.
100 PMNode
*PM_CopyNode(PMNode
*A
)
102 PMNode
*newnode
=NULL
;
105 newnode
=(PMNode
*)AllocVec(((PMGLN
*)A
)->Length
, MEMF_ANY
);
107 CopyMem(A
, newnode
, ((PMGLN
*)A
)->Length
);