Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / libraries / popupmenu / pmdlist.c
blob50b8714322d5a3c5e8c7dd372baa5ab7481f87bf
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 //
9 // $Date$
10 // $Revision$
13 #include "pmdlist.h"
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)
25 PMDList *newlist;
27 newlist=(PMDList *)AllocVec(sizeof(struct MinList), MEMF_ANY);
28 if (newlist) {
29 NewList((struct List *)newlist);
32 return newlist;
36 // PM_FreeList - free all nodes in a list and the list structure itself.
38 void PM_FreeList(PMDList *list)
40 PMGLN *worknode;
41 PMGLN *nextnode;
43 worknode = (PMGLN *)(list->mlh_Head); /* First node */
44 while ((nextnode = (PMGLN *)(worknode->n.mln_Succ))) {
45 PM_FreeNode((PMNode *)worknode);
46 worknode = nextnode;
49 FreeVec(list);
53 // PM_CopyList - copy a list.
55 PMDList *PM_CopyList(PMDList *list)
57 PMDList *newlist;
58 PMGLN *worknode;
59 PMGLN *nextnode;
61 newlist=PM_InitList();
62 if (newlist) {
63 if (list) {
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);
68 worknode = nextnode;
73 return newlist;
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)
97 FreeVec(A);
101 // PM_CopyNode - copy a PMNode.
103 PMNode *PM_CopyNode(PMNode *A)
105 PMNode *newnode=NULL;
107 if (A) {
108 newnode=(PMNode *)AllocVec(((PMGLN *)A)->Length, MEMF_ANY);
109 if (newnode) {
110 CopyMem(A, newnode, ((PMGLN *)A)->Length);
114 return newnode;