1 /* 2 * linklist.h -- generic linked list 3 * 4 * Yet Another FTP Client 5 * Copyright (C) 1998-2001, Martin Hedenfalk <mhe@stacken.kth.se> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. See COPYING for more details. 11 */ 12 13 #ifndef _linklist_h_included 14 #define _linklist_h_included 15 16 #include <stdbool.h> 17 #include <stdint.h> 18 19 typedef int (*listfunc)(void *); 20 typedef void *(*listclonefunc)(void *); 21 22 /* should return < 0 if a < b, 0 if a == b, > 0 if a > b */ 23 typedef int (*listsortfunc)(const void *a, const void *b); 24 25 /* should return 0 (zero) if ITEM matches ARG */ 26 typedef int (*listsearchfunc)(const void *item, const void *arg); 27 28 typedef struct listitem listitem; 29 struct listitem { 30 void *data; 31 listitem *next, *prev; 32 }; 33 34 typedef struct list list; 35 struct list { 36 listitem* first; 37 listitem* last; 38 listfunc freefunc; 39 size_t numitem; 40 }; 41 42 list *list_new(listfunc freefunc); 43 void list_free(list *lp); 44 void list_clear(list *lp); 45 void list_delitem(list *lp, listitem *lip); 46 void list_removeitem(list *lp, listitem *lip); 47 void list_additem(list *lp, void *data); 48 size_t list_numitem(list *lp); 49 listitem *list_search(list *lp, listsearchfunc cmpfunc, const void *arg); 50 void list_sort(list *lp, listsortfunc cmp, bool reverse); 51 list *list_clone(list *lp, listclonefunc clonefunc); 52 int list_equal(list *a, list *b, listsortfunc cmpfunc); 53 54 #endif 55