aboutsummaryrefslogtreecommitdiffstats
path: root/libasn1parser/asn1p_list.h
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2004-06-03 03:38:44 +0000
committerLev Walkin <vlm@lionet.info>2004-06-03 03:38:44 +0000
commitf15320bf6b50a0c02636405561ac8323ae901abd (patch)
tree33461d45122896c6dde35f82f5c7d19b62004a6b /libasn1parser/asn1p_list.h
parent746cb60bbccf47019563665f4aec4b6c462c4163 (diff)
Initial revision
Diffstat (limited to 'libasn1parser/asn1p_list.h')
-rw-r--r--libasn1parser/asn1p_list.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/libasn1parser/asn1p_list.h b/libasn1parser/asn1p_list.h
new file mode 100644
index 00000000..1f808780
--- /dev/null
+++ b/libasn1parser/asn1p_list.h
@@ -0,0 +1,57 @@
+/*
+ * Singly linked tail queue support.
+ */
+#ifndef ASN1_PARSER_LIST_H
+#define ASN1_PARSER_LIST_H
+
+#define TQ_HEAD(type) \
+ struct { \
+ type *tq_head; \
+ type**tq_tail; \
+ }
+
+#define TQ_HEAD_COPY(to, from) \
+ do { (to)->tq_head = (from)->tq_head; \
+ (to)->tq_tail = (from)->tq_tail; } while(0)
+
+#define TQ_ENTRY(type) \
+ struct { \
+ type *tq_next; \
+ }
+
+#define TQ_FIRST(headp) ((headp)->tq_head)
+#define TQ_NEXT(el, field) ((el)->field.tq_next)
+
+#define TQ_INIT(head) do { \
+ TQ_FIRST((head)) = 0; \
+ (head)->tq_tail = &TQ_FIRST((head)); \
+ } while(0)
+
+#define TQ_FOR(var, head, field) \
+ for((var) = TQ_FIRST((head)); \
+ (var); (var) = TQ_NEXT((var), field))
+
+#define TQ_ADD(head, xel, field) do { \
+ typeof(xel) __el = xel; \
+ assert(TQ_NEXT((__el), field) == 0); \
+ *(head)->tq_tail = (__el); \
+ (head)->tq_tail = &TQ_NEXT((__el), field); \
+ } while(0)
+
+/*
+ * Remove the first element and return it.
+ */
+#define TQ_REMOVE(head, field) ({ \
+ typeof(TQ_FIRST((head))) __fel; \
+ __fel = TQ_FIRST((head)); \
+ if(__fel == 0 \
+ || (TQ_FIRST((head)) = TQ_NEXT(__fel, field)) \
+ == 0) { \
+ (head)->tq_tail = &TQ_FIRST((head)); \
+ } else { \
+ TQ_NEXT(__fel, field) = 0; \
+ } \
+ __fel; })
+
+
+#endif /* ASN1_PARSER_LIST_H */