aboutsummaryrefslogtreecommitdiff
path: root/src/list.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/list.h')
-rw-r--r--src/list.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/list.h b/src/list.h
new file mode 100644
index 0000000..c76c255
--- /dev/null
+++ b/src/list.h
@@ -0,0 +1,77 @@
+/*
+ * Ivy, C interface
+ *
+ * Copyright (C) 1997-2000
+ * Centre d'Études de la Navigation Aérienne
+ *
+ * Simple lists in C
+ *
+ * Authors: François-Régis Colin <fcolin@cena.dgac.fr>
+ *
+ * $Id: list.h,v 1.2 2007/06/07 14:59:13 saal Exp $
+ *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
+ */
+#if (__GNUC__ >= 3)
+#define TYPEOF(p) typeof (p)
+#else
+#define TYPEOF(p) void *
+#endif
+
+#define IVY_LIST_ITER( list, p, cond ) \
+ p = list; \
+ while ( p && (cond) ) p = p->next
+
+
+
+#define IVY_LIST_REMOVE( list, p ) \
+ { \
+ TYPEOF(p) toRemove; \
+ if ( list == p ) \
+ { \
+ list = p->next; \
+ free(p);\
+ } \
+ else \
+ {\
+ toRemove = p;\
+ IVY_LIST_ITER( list, p, ( p->next != toRemove ));\
+ if ( p )\
+ {\
+ /* somme tricky swapping to use a untyped variable */\
+ TYPEOF(p) suiv; \
+ TYPEOF(p) prec = p;\
+ p = toRemove;\
+ suiv = p->next;\
+ p = prec;\
+ p->next = suiv;\
+ free(toRemove);\
+ }\
+ } \
+ }
+
+#define IVY_LIST_ADD(list, p ) \
+ if ( p = (TYPEOF(p)) (malloc( sizeof( *p ))))\
+ { \
+ memset( p, 0 , sizeof( *p ));\
+ p->next = list; \
+ list = p; \
+ }
+
+#define IVY_LIST_EACH( list, p ) \
+ for ( p = list ; p ; p = p -> next )
+
+#define IVY_LIST_EACH_SAFE( list, p, next )\
+for ( p = list ; (next = p ? p->next: p ),p ; p = next )
+
+#define IVY_LIST_EMPTY( list ) \
+ { \
+ TYPEOF(list) p; \
+ while( list ) \
+ { \
+ p = list;\
+ list = list->next; \
+ free(p);\
+ } \
+ }