1 /* toolbox/chain.c - management of doubly linked lists with external linking
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Institut f. Computersprachen, TU Wien
5 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6 S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
9 This file is part of CACAO.
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2, or (at
14 your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Reinhard Grafl
30 $Id: chain.c 1621 2004-11-30 13:06:55Z twisti $
39 #include "mm/memory.h"
40 #include "toolbox/chain.h"
71 void chain_free(chain *c)
79 chainlink *nextl = l->next;
89 void chain_addafter(chain *c, void *element)
97 newlink = DNEW(chainlink);
100 newlink = NEW(chainlink);
103 newlink->element = element;
106 newlink->next = active->next;
107 newlink->prev = active;
109 active->next = newlink;
111 newlink->next->prev = newlink;
118 newlink->next = NULL;
119 newlink->prev = NULL;
128 void chain_addbefore(chain *c, void *element)
136 newlink = DNEW(chainlink);
139 newlink = NEW(chainlink);
142 newlink->element = element;
145 newlink->next = active;
146 newlink->prev = active->prev;
148 active->prev = newlink;
150 newlink->prev->next = newlink;
157 newlink->next = NULL;
158 newlink->prev = NULL;
167 void chain_addlast(chain *c, void *e)
170 chain_addafter(c, e);
174 void chain_addfirst(chain *c, void *e)
177 chain_addbefore(c, e);
181 void chain_remove(chain *c)
189 active->next->prev = active->prev;
192 c->last = active->prev;
196 active->prev->next = active->next;
199 c->first = active->next;
204 c->active = active->prev;
207 c->active = active->next;
211 FREE(active, chainlink);
215 void *chain_remove_go_prev(chain *c)
218 return chain_this(c);
223 void chain_removespecific(chain *c, void *e)
239 void *chain_next(chain *c)
249 c->active = active->next;
250 return c->active->element;
257 void *chain_prev(chain *c)
267 c->active = active->prev;
268 return c->active->element;
275 void *chain_this(chain *c)
278 return c->active->element;
284 void *chain_first(chain *c)
286 c->active = c->first;
289 return c->active->element;
294 void *chain_last(chain *c)
299 return c->active->element;
306 * These are local overrides for various environment variables in Emacs.
307 * Please do not remove this and leave it at the end of the file, where
308 * Emacs will automagically detect them.
309 * ---------------------------------------------------------------------
312 * indent-tabs-mode: t