1 /******************************************************************************
3 * Copyright (C) 2002 Jason Evans <jasone@canonware.com>.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice(s), this list of conditions and the following disclaimer
11 * unmodified other than the allowable addition of one or more
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice(s), this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ******************************************************************************/
35 #define ql_head(a_type) \
40 #define ql_head_initializer(a_head) {NULL}
42 #define ql_elm(a_type) qr(a_type)
45 #define ql_new(a_head) do { \
46 (a_head)->qlh_first = NULL; \
49 #define ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field)
51 #define ql_first(a_head) ((a_head)->qlh_first)
53 #define ql_last(a_head, a_field) \
54 ((ql_first(a_head) != NULL) \
55 ? qr_prev(ql_first(a_head), a_field) : NULL)
57 #define ql_next(a_head, a_elm, a_field) \
58 ((ql_last(a_head, a_field) != (a_elm)) \
59 ? qr_next((a_elm), a_field) : NULL)
61 #define ql_prev(a_head, a_elm, a_field) \
62 ((ql_first(a_head) != (a_elm)) ? qr_prev((a_elm), a_field) \
65 #define ql_before_insert(a_head, a_qlelm, a_elm, a_field) do { \
66 qr_before_insert((a_qlelm), (a_elm), a_field); \
67 if (ql_first(a_head) == (a_qlelm)) { \
68 ql_first(a_head) = (a_elm); \
72 #define ql_after_insert(a_qlelm, a_elm, a_field) \
73 qr_after_insert((a_qlelm), (a_elm), a_field)
75 #define ql_head_insert(a_head, a_elm, a_field) do { \
76 if (ql_first(a_head) != NULL) { \
77 qr_before_insert(ql_first(a_head), (a_elm), a_field); \
79 ql_first(a_head) = (a_elm); \
82 #define ql_tail_insert(a_head, a_elm, a_field) do { \
83 if (ql_first(a_head) != NULL) { \
84 qr_before_insert(ql_first(a_head), (a_elm), a_field); \
86 ql_first(a_head) = qr_next((a_elm), a_field); \
89 #define ql_remove(a_head, a_elm, a_field) do { \
90 if (ql_first(a_head) == (a_elm)) { \
91 ql_first(a_head) = qr_next(ql_first(a_head), a_field); \
93 if (ql_first(a_head) != (a_elm)) { \
94 qr_remove((a_elm), a_field); \
96 ql_first(a_head) = NULL; \
100 #define ql_head_remove(a_head, a_type, a_field) do { \
101 a_type *t = ql_first(a_head); \
102 ql_remove((a_head), t, a_field); \
105 #define ql_tail_remove(a_head, a_type, a_field) do { \
106 a_type *t = ql_last(a_head, a_field); \
107 ql_remove((a_head), t, a_field); \
110 #define ql_foreach(a_var, a_head, a_field) \
111 qr_foreach((a_var), ql_first(a_head), a_field)
113 #define ql_reverse_foreach(a_var, a_head, a_field) \
114 qr_reverse_foreach((a_var), ql_first(a_head), a_field)