introduce the NODES_FOREACH and GREP_FIRST macros

next
Michael Stapelberg 2011-05-14 22:11:09 +02:00
parent 443753bea6
commit 0e2d58347c
1 changed files with 15 additions and 0 deletions

View File

@ -25,6 +25,21 @@
#define FOR_TABLE(workspace) \
for (int cols = 0; cols < (workspace)->cols; cols++) \
for (int rows = 0; rows < (workspace)->rows; rows++)
#define NODES_FOREACH(head) \
for (Con *child = (Con*)-1; (child == (Con*)-1) && ((child = 0), true);) \
TAILQ_FOREACH(child, &((head)->nodes_head), nodes)
/* greps the ->nodes of the given head and returns the first node that matches the given condition */
#define GREP_FIRST(dest, head, condition) \
NODES_FOREACH(head) { \
if (!(condition)) \
continue; \
\
(dest) = child; \
break; \
}
#define FREE(pointer) do { \
if (pointer != NULL) { \
free(pointer); \