X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Ftoolbox%2Fchain.c;h=59b4d6ba0c90f6f14ec6a2d1996c14c2676763a2;hb=d75b6037acf17c342166b9c9bd6e657dfdd12cd9;hp=7e50617d16559ba9e96b073f888d7047dd8c5d19;hpb=3a5f5900ebb2b3f0fc418b5a6a0d551db494fc12;p=cacao.git diff --git a/src/toolbox/chain.c b/src/toolbox/chain.c index 7e50617d1..59b4d6ba0 100644 --- a/src/toolbox/chain.c +++ b/src/toolbox/chain.c @@ -1,178 +1,220 @@ -/************************* toolbox/chain.c ************************************* +/* toolbox/chain.c - management of doubly linked lists with external linking - Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst + Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates, + R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner, + C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger, + Institut f. Computersprachen - TU Wien - See file COPYRIGHT for information on usage and disclaimer of warranties + This file is part of CACAO. - Not documented, see chain.h. + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. - Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. - Last Change: 1996/10/03 + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. + + Contact: cacao@complang.tuwien.ac.at + + Authors: Reinhard Grafl + + $Id: chain.c 1735 2004-12-07 14:33:27Z twisti $ + +*/ -*******************************************************************************/ #include #include #include -#include "memory.h" -#include "chain.h" - +#include "mm/memory.h" +#include "toolbox/chain.h" -chain *chain_new () +chain *chain_new() { chain *c; - c = NEW (chain); - c -> usedump = 0; - c -> first = NULL; - c -> last = NULL; - c -> active = NULL; + c = NEW(chain); + c->usedump = 0; + c->first = NULL; + c->last = NULL; + c->active = NULL; return c; } -chain *chain_dnew () + +chain *chain_dnew() { chain *c; - c = DNEW (chain); - c -> usedump = 1; - c -> first = NULL; - c -> last = NULL; - c -> active = NULL; + c = DNEW(chain); + c->usedump = 1; + c->first = NULL; + c->last = NULL; + c->active = NULL; return c; } -void chain_free (chain *c) +void chain_free(chain *c) { chainlink *l; - assert (! c->usedump); + assert(!c->usedump); l = c->first; while (l) { chainlink *nextl = l->next; - FREE (l, chainlink); + FREE(l, chainlink); l = nextl; - } + } - FREE (c, chain); + FREE(c, chain); } void chain_addafter(chain *c, void *element) { - chainlink *active,*newlink; + chainlink *active; + chainlink *newlink; active = c->active; - if (c -> usedump) newlink = DNEW (chainlink); - else newlink = NEW (chainlink); + if (c->usedump) { + newlink = DNEW(chainlink); - newlink -> element = element; + } else { + newlink = NEW(chainlink); + } + + newlink->element = element; if (active) { - newlink -> next = active -> next; - newlink -> prev = active; + newlink->next = active->next; + newlink->prev = active; - active -> next = newlink; - if (newlink -> next) newlink -> next -> prev = newlink; - else c -> last = newlink; - } - else { - newlink -> next = NULL; - newlink -> prev = NULL; + active->next = newlink; + if (newlink->next) { + newlink->next->prev = newlink; - c -> active = newlink; - c -> first = newlink; - c -> last = newlink; + } else { + c->last = newlink; } + + } else { + newlink->next = NULL; + newlink->prev = NULL; + + c->active = newlink; + c->first = newlink; + c->last = newlink; + } } void chain_addbefore(chain *c, void *element) { - chainlink *active,*newlink; + chainlink *active; + chainlink *newlink; active = c->active; - if (c -> usedump) newlink = DNEW (chainlink); - else newlink = NEW (chainlink); + if (c->usedump) { + newlink = DNEW(chainlink); + + } else { + newlink = NEW(chainlink); + } - newlink -> element = element; + newlink->element = element; if (active) { - newlink -> next = active; - newlink -> prev = active -> prev; + newlink->next = active; + newlink->prev = active->prev; - active -> prev = newlink; - if (newlink -> prev) newlink -> prev -> next = newlink; - else c -> first = newlink; - } - else { - newlink -> next = NULL; - newlink -> prev = NULL; + active->prev = newlink; + if (newlink->prev) { + newlink->prev->next = newlink; - c -> active = newlink; - c -> first = newlink; - c -> last = newlink; + } else { + c->first = newlink; } + + } else { + newlink->next = NULL; + newlink->prev = NULL; + + c->active = newlink; + c->first = newlink; + c->last = newlink; + } } -void chain_addlast (chain *c, void *e) + +void chain_addlast(chain *c, void *e) { - chain_last (c); - chain_addafter (c, e); + chain_last(c); + chain_addafter(c, e); } -void chain_addfirst (chain *c, void *e) + +void chain_addfirst(chain *c, void *e) { - chain_first (c); - chain_addbefore (c, e); + chain_first(c); + chain_addbefore(c, e); } -void chain_remove (chain *c) +void chain_remove(chain *c) { chainlink *active; - active = c -> active; - assert (active); + active = c->active; + assert(active); - if (active -> next) { - active -> next -> prev = active -> prev; - } - else { - c -> last = active -> prev; - } + if (active->next) { + active->next->prev = active->prev; + + } else { + c->last = active->prev; + } - if (active -> prev) { - active -> prev -> next = active -> next; - } - else { - c -> first = active -> next; - } + if (active->prev) { + active->prev->next = active->next; + + } else { + c->first = active->next; + } - if (active->prev) - c -> active = active->prev; - else - c -> active = active->next; + if (active->prev) { + c->active = active->prev; - if (! c -> usedump) FREE (active, chainlink); + } else { + c->active = active->next; + } + + if (!c->usedump) + FREE(active, chainlink); } -void *chain_remove_go_prev (chain *c) +void *chain_remove_go_prev(chain *c) { - chain_remove (c); - return chain_this (c); + chain_remove(c); + return chain_this(c); } @@ -181,40 +223,49 @@ void chain_removespecific(chain *c, void *e) { void *ce; - ce = chain_first (c); + ce = chain_first(c); while (ce) { - if (e == ce) { chain_remove (c); return; } - ce = chain_next (c); + if (e == ce) { + chain_remove(c); + return; } - + + ce = chain_next(c); + } } + void *chain_next(chain *c) { chainlink *active; - active = c -> active; - if (!active) return NULL; + active = c->active; + + if (!active) + return NULL; - if (active -> next) { - c -> active = active -> next; - return c -> active -> element; - } + if (active->next) { + c->active = active->next; + return c->active->element; + } return NULL; } + void *chain_prev(chain *c) { chainlink *active; - active = c -> active; - if (!active) return NULL; + active = c->active; + + if (!active) + return NULL; - if (active -> prev) { - c -> active = active -> prev; - return c -> active -> element; - } + if (active->prev) { + c->active = active->prev; + return c->active->element; + } return NULL; } @@ -222,22 +273,43 @@ void *chain_prev(chain *c) void *chain_this(chain *c) { - if (c -> active) return c -> active -> element; + if (c->active) + return c->active->element; + return NULL; } void *chain_first(chain *c) { - c -> active = c -> first; - if (c -> active) return c -> active -> element; + c->active = c->first; + + if (c -> active) + return c->active->element; + return NULL; } void *chain_last(chain *c) { - c -> active = c -> last; - if (c -> active) return c -> active -> element;; + c->active = c->last; + + if (c->active) + return c->active->element; + return NULL; } + +/* + * These are local overrides for various environment variables in Emacs. + * Please do not remove this and leave it at the end of the file, where + * Emacs will automagically detect them. + * --------------------------------------------------------------------- + * Local variables: + * mode: c + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + */