Improvements to comments etc.
[AROS.git] / workbench / libs / popupmenu / pmdlist.c
blobbc0f53617d226f56b9c0cb368f556155dc312549
1 //
2 // pmdlist.c
3 //
4 // PopupMenu Library - Linked Lists
5 //
6 // Copyright (C)2000 Henrik Isaksson <henrik@boing.nu>
7 // All Rights Reserved.
8 //
10 #include "pmdlist.h"
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);
25 if(newlist) {
26 NewList((struct List *)newlist);
29 return newlist;
33 // PM_FreeList - free all nodes in a list and the list structure itself.
35 void PM_FreeList(PMDList *list)
37 PMGLN *worknode;
38 PMGLN *nextnode;
40 worknode = (PMGLN *)(list->mlh_Head); /* First node */
41 while((nextnode = (PMGLN *)(worknode->n.mln_Succ))) {
42 PM_FreeNode((PMNode *)worknode);
43 worknode = nextnode;
46 FreeVec(list);
50 // PM_CopyList - copy a list.
52 PMDList *PM_CopyList(PMDList *list)
54 PMDList *newlist=NULL;
55 PMGLN *worknode;
56 PMGLN *nextnode;
58 newlist=PM_InitList();
59 if(newlist) {
60 if(list) {
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);
65 worknode = nextnode;
70 return newlist;
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)
94 FreeVec(A);
98 // PM_CopyNode - copy a PMNode.
100 PMNode *PM_CopyNode(PMNode *A)
102 PMNode *newnode=NULL;
104 if(A) {
105 newnode=(PMNode *)AllocVec(((PMGLN *)A)->Length, MEMF_ANY);
106 if(newnode) {
107 CopyMem(A, newnode, ((PMGLN *)A)->Length);
111 return newnode;