From 49a8ef4fcbc8e76ca0f484e6b2d2d9eea70596b6 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Thu, 30 Apr 2009 05:52:10 +0200 Subject: too much stuff and it WORKS --- utils.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'utils.h') diff --git a/utils.h b/utils.h index 9a6d566..ad4ac9d 100644 --- a/utils.h +++ b/utils.h @@ -40,6 +40,26 @@ void fdlist_create(struct fdlist *list); void fdlist_add(struct fdlist *list, enum fdowner owner, int fd, short events); void fdlist_free(struct fdlist *list); -#define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) +struct collection { + void **list; + int capacity; +}; + +void collection_init(struct collection *col); +void collection_add(struct collection *col, void *element); +void collection_remove(struct collection *col, void *element); +int collection_count(struct collection *col); +void collection_free(struct collection *col); + +#define FOREACH(var, col) \ + do { \ + int _iter; \ + for(_iter=0; _iter<(col)->capacity; _iter++) { \ + if(!(col)->list[_iter]) continue; \ + var = (col)->list[_iter]; + +#define ENDFOREACH \ + } \ + } while(0); #endif -- cgit v1.1-32-gdbae