]> git.sur5r.net Git - i3/i3/commitdiff
introduce the NODES_FOREACH and GREP_FIRST macros
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 14 May 2011 20:11:09 +0000 (22:11 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 14 May 2011 20:11:09 +0000 (22:11 +0200)
include/util.h

index 610e701e9e323c432654da13d2c05d397b42313c..df0e306557dac7e994c2e252a2c5299fbc2d4765 100644 (file)
 #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); \