From: Michael Stapelberg Date: Sat, 14 May 2011 20:11:09 +0000 (+0200) Subject: introduce the NODES_FOREACH and GREP_FIRST macros X-Git-Tag: tree-pr3~26 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0e2d58347c0290cb4dbed92e3b47dbabd0005318;p=i3%2Fi3 introduce the NODES_FOREACH and GREP_FIRST macros --- diff --git a/include/util.h b/include/util.h index 610e701e..df0e3065 100644 --- a/include/util.h +++ b/include/util.h @@ -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); \