]>
Commit | Line | Data |
---|---|---|
54a0048b | 1 | /* List definitions. */ |
1a4d82fc | 2 | #define ql_head(a_type) \ |
970d7e83 LB |
3 | struct { \ |
4 | a_type *qlh_first; \ | |
5 | } | |
6 | ||
1a4d82fc | 7 | #define ql_head_initializer(a_head) {NULL} |
970d7e83 | 8 | |
1a4d82fc | 9 | #define ql_elm(a_type) qr(a_type) |
970d7e83 LB |
10 | |
11 | /* List functions. */ | |
1a4d82fc | 12 | #define ql_new(a_head) do { \ |
970d7e83 LB |
13 | (a_head)->qlh_first = NULL; \ |
14 | } while (0) | |
15 | ||
1a4d82fc | 16 | #define ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field) |
970d7e83 | 17 | |
1a4d82fc | 18 | #define ql_first(a_head) ((a_head)->qlh_first) |
970d7e83 | 19 | |
1a4d82fc | 20 | #define ql_last(a_head, a_field) \ |
970d7e83 LB |
21 | ((ql_first(a_head) != NULL) \ |
22 | ? qr_prev(ql_first(a_head), a_field) : NULL) | |
23 | ||
1a4d82fc | 24 | #define ql_next(a_head, a_elm, a_field) \ |
970d7e83 LB |
25 | ((ql_last(a_head, a_field) != (a_elm)) \ |
26 | ? qr_next((a_elm), a_field) : NULL) | |
27 | ||
1a4d82fc | 28 | #define ql_prev(a_head, a_elm, a_field) \ |
970d7e83 LB |
29 | ((ql_first(a_head) != (a_elm)) ? qr_prev((a_elm), a_field) \ |
30 | : NULL) | |
31 | ||
1a4d82fc | 32 | #define ql_before_insert(a_head, a_qlelm, a_elm, a_field) do { \ |
970d7e83 LB |
33 | qr_before_insert((a_qlelm), (a_elm), a_field); \ |
34 | if (ql_first(a_head) == (a_qlelm)) { \ | |
35 | ql_first(a_head) = (a_elm); \ | |
36 | } \ | |
37 | } while (0) | |
38 | ||
1a4d82fc | 39 | #define ql_after_insert(a_qlelm, a_elm, a_field) \ |
970d7e83 LB |
40 | qr_after_insert((a_qlelm), (a_elm), a_field) |
41 | ||
1a4d82fc | 42 | #define ql_head_insert(a_head, a_elm, a_field) do { \ |
970d7e83 LB |
43 | if (ql_first(a_head) != NULL) { \ |
44 | qr_before_insert(ql_first(a_head), (a_elm), a_field); \ | |
45 | } \ | |
46 | ql_first(a_head) = (a_elm); \ | |
47 | } while (0) | |
48 | ||
1a4d82fc | 49 | #define ql_tail_insert(a_head, a_elm, a_field) do { \ |
970d7e83 LB |
50 | if (ql_first(a_head) != NULL) { \ |
51 | qr_before_insert(ql_first(a_head), (a_elm), a_field); \ | |
52 | } \ | |
53 | ql_first(a_head) = qr_next((a_elm), a_field); \ | |
54 | } while (0) | |
55 | ||
1a4d82fc | 56 | #define ql_remove(a_head, a_elm, a_field) do { \ |
970d7e83 LB |
57 | if (ql_first(a_head) == (a_elm)) { \ |
58 | ql_first(a_head) = qr_next(ql_first(a_head), a_field); \ | |
59 | } \ | |
60 | if (ql_first(a_head) != (a_elm)) { \ | |
61 | qr_remove((a_elm), a_field); \ | |
62 | } else { \ | |
63 | ql_first(a_head) = NULL; \ | |
64 | } \ | |
65 | } while (0) | |
66 | ||
1a4d82fc | 67 | #define ql_head_remove(a_head, a_type, a_field) do { \ |
970d7e83 LB |
68 | a_type *t = ql_first(a_head); \ |
69 | ql_remove((a_head), t, a_field); \ | |
70 | } while (0) | |
71 | ||
1a4d82fc | 72 | #define ql_tail_remove(a_head, a_type, a_field) do { \ |
970d7e83 LB |
73 | a_type *t = ql_last(a_head, a_field); \ |
74 | ql_remove((a_head), t, a_field); \ | |
75 | } while (0) | |
76 | ||
1a4d82fc | 77 | #define ql_foreach(a_var, a_head, a_field) \ |
970d7e83 LB |
78 | qr_foreach((a_var), ql_first(a_head), a_field) |
79 | ||
1a4d82fc | 80 | #define ql_reverse_foreach(a_var, a_head, a_field) \ |
970d7e83 | 81 | qr_reverse_foreach((a_var), ql_first(a_head), a_field) |