# HG changeset patch # User Tuomo Valkonen # Date 1109452173 -3600 # Node ID 55fcdff5bcea668a8da0406fb78501c699961327 # Parent 817f90f58aecb66b2ff12ab5f17bfef1f5f9af45 Added routines to take first/last elements of objlist and ptrlist. diff -r 817f90f58aec -r 55fcdff5bcea objlist.c --- a/objlist.c Sat Feb 26 21:58:19 2005 +0100 +++ b/objlist.c Sat Feb 26 22:09:33 2005 +0100 @@ -276,3 +276,49 @@ return TRUE; } + + +Obj *objlist_take_first(ObjList **objlist) +{ + ObjList *node; + Obj*obj; + + optimise(objlist); + + node=*objlist; + + if(node==NULL) + return NULL; + + obj=node->watch.obj; + + assert(obj!=NULL); + + free_node(objlist, node); + + return obj; +} + + +Obj *objlist_take_last(ObjList **objlist) +{ + ObjList *node; + Obj*obj; + + optimise(objlist); + + node=*objlist; + + if(node==NULL) + return NULL; + + node=node->prev; + + obj=node->watch.obj; + + assert(obj!=NULL); + + free_node(objlist, node); + + return obj; +} diff -r 817f90f58aec -r 55fcdff5bcea objlist.h --- a/objlist.h Sat Feb 26 21:58:19 2005 +0100 +++ b/objlist.h Sat Feb 26 22:09:33 2005 +0100 @@ -58,5 +58,7 @@ extern void objlist_iter_rev_init(ObjListIterTmp *state, ObjList *objlist); extern Obj *objlist_iter_rev(ObjListIterTmp *state); extern bool objlist_empty(ObjList *objlist); +extern Obj *objlist_take_first(ObjList **objlist); +extern Obj *objlist_take_last(ObjList **objlist); #endif /* LIBTU_OBJLIST_H */ diff -r 817f90f58aec -r 55fcdff5bcea ptrlist.c --- a/ptrlist.c Sat Feb 26 21:58:19 2005 +0100 +++ b/ptrlist.c Sat Feb 26 22:09:33 2005 +0100 @@ -165,3 +165,36 @@ return ptr; } + +void *ptrlist_take_first(PtrList **ptrlist) +{ + PtrList *node=*ptrlist; + void *ptr; + + if(node==NULL) + return NULL; + + ptr=node->ptr; + + free_node(ptrlist, node); + + return ptr; +} + + +void *ptrlist_take_last(PtrList **ptrlist) +{ + PtrList *node=*ptrlist; + void *ptr; + + if(node==NULL) + return NULL; + + node=node->prev; + + ptr=node->ptr; + + free_node(ptrlist, node); + + return ptr; +} diff -r 817f90f58aec -r 55fcdff5bcea ptrlist.h --- a/ptrlist.h Sat Feb 26 21:58:19 2005 +0100 +++ b/ptrlist.h Sat Feb 26 22:09:33 2005 +0100 @@ -56,5 +56,7 @@ extern void *ptrlist_iter(PtrListIterTmp *state); extern void ptrlist_iter_rev_init(PtrListIterTmp *state, PtrList *ptrlist); extern void *ptrlist_iter_rev(PtrListIterTmp *state); +extern void *ptrlist_take_first(PtrList **ptrlist); +extern void *ptrlist_take_last(PtrList **ptrlist); #endif /* LIBTU_PTRLIST_H */