46 |
/* |
/* |
47 |
* Generalized list structure |
* Generalized list structure |
48 |
*/ |
*/ |
49 |
typedef struct list_t LIST; |
typedef struct rw_list RWLIST; |
50 |
#define LIST(type) \ |
#define RWLIST(type) \ |
51 |
type *next;\ |
type *next;\ |
52 |
type *prev |
type *prev |
53 |
|
|
54 |
struct list_t { |
struct rw_list { |
55 |
LIST(LIST); |
RWLIST(RWLIST); |
56 |
}; |
}; |
57 |
|
|
58 |
/* |
/* |
61 |
typedef struct object_t OBJECT ; |
typedef struct object_t OBJECT ; |
62 |
|
|
63 |
#define OBJ(type) \ |
#define OBJ(type) \ |
64 |
LIST(type);\ |
RWLIST(type);\ |
65 |
type *alloc |
type *alloc |
66 |
|
|
67 |
struct object_t { |
struct object_t { |
1751 |
/* **************************************************************************** |
/* **************************************************************************** |
1752 |
* Generalized list functions |
* Generalized list functions |
1753 |
*/ |
*/ |
1754 |
static LIST *_list_insert(LIST **first, LIST **last, LIST *prev, |
static RWLIST *_list_insert(RWLIST **first, RWLIST **last, RWLIST *prev, |
1755 |
LIST *obj, int before); |
RWLIST *obj, int before); |
1756 |
static LIST *_list_remove(LIST **first, LIST **last, LIST *obj); |
static RWLIST *_list_remove(RWLIST **first, RWLIST **last, RWLIST *obj); |
1757 |
static LIST *_list_append(LIST **first, LIST **last, LIST *obj); |
static RWLIST *_list_append(RWLIST **first, RWLIST **last, RWLIST *obj); |
1758 |
|
|
1759 |
#define list_insert(first, last, prev, obj, before) \ |
#define list_insert(first, last, prev, obj, before) \ |
1760 |
_list_insert((LIST**)first,(LIST**)last,(LIST*)prev,(LIST*)obj, before) |
_list_insert((RWLIST**)first,(RWLIST**)last,(RWLIST*)prev,(RWLIST*)obj, before) |
1761 |
#define list_remove(first, last, obj) \ |
#define list_remove(first, last, obj) \ |
1762 |
_list_remove((LIST**)first,(LIST**)last,(LIST *)obj) |
_list_remove((RWLIST**)first,(RWLIST**)last,(RWLIST *)obj) |
1763 |
#define list_append(first, last, obj) \ |
#define list_append(first, last, obj) \ |
1764 |
_list_append((LIST**)first, (LIST**)last, (LIST*)obj) |
_list_append((RWLIST**)first, (RWLIST**)last, (RWLIST*)obj) |
1765 |
|
|
1766 |
LIST * |
RWLIST * |
1767 |
_list_append(first, last, obj) |
_list_append(first, last, obj) |
1768 |
LIST **first, **last, *obj; |
RWLIST **first, **last, *obj; |
1769 |
{ |
{ |
1770 |
return list_insert(first, last, *last, obj, 0); |
return list_insert(first, last, *last, obj, 0); |
1771 |
} |
} |
1772 |
|
|
1773 |
LIST * |
RWLIST * |
1774 |
_list_insert(first, last, prev, obj, before) |
_list_insert(first, last, prev, obj, before) |
1775 |
LIST **first, **last, *prev, *obj; |
RWLIST **first, **last, *prev, *obj; |
1776 |
int before; |
int before; |
1777 |
{ |
{ |
1778 |
LIST *next; |
RWLIST *next; |
1779 |
|
|
1780 |
/* |
/* |
1781 |
* No first element: initialize whole list |
* No first element: initialize whole list |
1815 |
return obj; |
return obj; |
1816 |
} |
} |
1817 |
|
|
1818 |
LIST * |
RWLIST * |
1819 |
_list_remove(first, last, obj) |
_list_remove(first, last, obj) |
1820 |
LIST **first, **last, *obj; |
RWLIST **first, **last, *obj; |
1821 |
{ |
{ |
1822 |
LIST *temp; |
RWLIST *temp; |
1823 |
|
|
1824 |
if (temp = obj->prev) |
if (temp = obj->prev) |
1825 |
temp->next = obj->next; |
temp->next = obj->next; |