[go: up one dir, main page]

Menu

[r456]: / tags / 0.6.4 / src / list.h  Maximize  Restore  History

Download this file

100 lines (78 with data), 2.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* $Id$
* -------------------------------------------------------
* Copyright (C) 2002-2005 Tommi Saviranta <wnd@iki.fi>
* -------------------------------------------------------
* 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 of the License, or
* (at your option) any later version.
*
* 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.
*/
#ifndef LIST_H_
#define LIST_H_
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* ifdef HAVE_CONFIG_H */
typedef struct _list_type list_type;
struct _list_type
{
void *data; /* Payload. */
list_type *prev; /* Link to previous item. */
list_type *next; /* Link to next item. */
list_type *last; /* Link to last item. */
};
#define LIST_CLEAR(_list_) \
{ \
list_type *__list__0; \
__list__0 = _list_; \
while (__list__0 != NULL) { \
__list__0 = list_delete(__list__0, __list__0); \
} \
_list_ = NULL; \
}
/*
* Following macros can be used to walk thru the list even when elements
* will be removed during it.
*
* Example:
* LLIST_WALK_H(nicknames.nicks.head, char *);
* xfree(data);
* LLIST_WALK_F;
*
* Using these macros, "node" points to current node and "data" to node->data.
*/
#define LIST_WALK_H(firstitem, datatype) { \
datatype data; \
list_type *node; \
list_type *nextnode; \
node = (firstitem); \
while (node != NULL) { \
nextnode = node->next; \
data = (datatype) node->data;
#define LLIST_WALK_F \
node = nextnode; \
} }
#define LLIST_WALK_CONTINUE \
node = nextnode; \
continue;
/* Setting nextnode to NULL is just a pre-caution. */
#define LLIST_WALK_BREAK \
nextnode = NULL; \
break;
list_type *list_add_head(list_type *list, void *data);
list_type *list_add_tail(list_type *list, void *data);
list_type *list_delete(list_type *list, list_type *node);
list_type *list_find(list_type *list, void *data);
list_type *list_move_first_to(list_type *list, list_type *dest);
list_type *list_insert_at(list_type *list, list_type *dest, void *data);
/*
list_type *list_move_to(list_type *list, list_type *src, list_type *dest);
*/
#ifdef DUMPSTATUS
const char *list_dump(list_type *list);
#endif /* DUMPSTATUS */
#endif /* ifndef LIST_H_ */