Declared more function parameters as socklen_t for better POSIX
[AROS.git] / tools / MetaMake / list.c
blob7ccb711b776e2b4b706608447545d1ff05f7ad72
1 /* MetaMake - A Make extension
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
4 This file is part of MetaMake.
6 MetaMake is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 MetaMake is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* This file contains the code for the list functions */
23 #include "config.h"
25 #include <stddef.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <assert.h>
29 #ifdef HAVE_STRING_H
30 # include <string.h>
31 #else
32 # include <strings.h>
33 #endif
35 #include "mem.h"
36 #include "list.h"
38 void
39 AssignList (struct List * dest, struct List * src)
41 NewList (dest);
43 if (src->first->next != NULL)
45 src->first->prev = (struct Node *)&dest->first;
46 dest->first = src->first;
47 src->prelast->next = (struct Node *)&dest->last;
48 dest->prelast = src->prelast;
52 void *
53 FindNode (const struct List * l, const char * name)
55 struct Node * n;
57 ForeachNode (l, n)
59 if (!strcmp (n->name, name))
60 return n;
63 return NULL;
66 void
67 printlist (struct List * l)
69 struct Node * n;
71 ForeachNode (l,n)
73 printf (" \"%s\"\n", n->name);
77 void
78 freelist (struct List * l)
80 struct Node * node, * next;
82 ForeachNodeSafe(l,node,next)
84 Remove (node);
86 cfree (node->name);
87 free (node);
91 struct Node *
92 newnode (const char * name)
94 struct Node * n;
96 assert (name);
98 n = new (struct Node);
100 n->name = xstrdup (name);
102 return n;
105 void *
106 newnodesize (const char * name, size_t size)
108 struct Node * n;
110 assert (name);
112 n = (struct Node *)xmalloc (size);
113 memset (n, 0, size);
115 n->name = xstrdup (name);
117 return (void *)n;
120 struct Node *
121 addnodeonce (struct List * l, const char * name)
123 struct Node * n;
125 n = FindNode (l, name);
127 if (!n)
129 n = newnode (name);
130 AddTail(l,n);
133 return n;
136 void *
137 addnodeoncesize (struct List * l, const char * name, size_t size)
139 void * n;
141 n = FindNode (l, name);
143 if (!n)
145 n = newnodesize (name, size);
146 AddTail(l,n);
149 return n;