1 /**************************************************************************** 2 Copyright (C) 1987-2015 by Jeffery P. Hansen 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along 15 with this program; if not, write to the Free Software Foundation, Inc., 16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 ****************************************************************************/ 18 19 #ifndef __list_h 20 #define __list_h 21 22 typedef struct listelem ListElem; 23 typedef struct list List; 24 25 typedef int elemcmp_f(const void*,const void*); 26 27 struct listelem { 28 ListElem *next,*prev; 29 void *obj; 30 }; 31 32 struct list { 33 int num; 34 ListElem *first,*last; 35 }; 36 37 List *new_List(); 38 39 void delete_List(List*); 40 41 List *copy_List(List*); 42 43 void List_init(List*); 44 45 void List_flush(List*); 46 47 void List_sort(List*L,elemcmp_f*); 48 49 void List_append(List*L,List*A); 50 51 void List_addToHead(List*,void*); 52 53 void List_addToTail(List*,void*); 54 55 void *List_popHead(List*); 56 void *List_popTail(List*); 57 void *List_remove(List*,ListElem*); 58 void *List_nth(List*,int); 59 60 #define List_uninit(L) List_flush(L) 61 #define List_first(L) (L)->first 62 #define List_last(L) (L)->last 63 #define List_numElems(L) (L)->num 64 #define List_next(L,E) (E)->next 65 #define List_prev(L,E) (E)->prev 66 67 #define ListElem_obj(E) (E)->obj 68 69 void *List_find(List *L,const void *obj,elemcmp_f*); 70 71 #endif 72