changeset: 2426:331694a2e8d1
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sun Dec 28 16:20:13 2008 -0500
files: cmd/wmii/fns.h cmd/wmii/mouse.c
description:
Black magic to make break work with foreach_*
diff -r a6d491229802 -r 331694a2e8d1 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Wed Dec 24 00:24:23 2008 -0500
+++ b/cmd/wmii/fns.h Sun Dec 28 16:20:13 2008 -0500
@@ -13,23 +13,30 @@
# pragma varargck type "r" void
#endif
+#define _cond(cond, n) __alive++ == n && cond
+#define _cont(cont) (void)(__alive--, cont)
+
#define with(type, var) \
- for(type *var=(void*)-1; var == (void*)-1; var=nil)
+ for(type var=(type)-1; (var == (type)-1) && ((var=0) || true);)
+
+/* Grotesque, but worth it. */
#define foreach_area(v, s, a) \
- with(Area, __anext) \
- for(s=0; s <= nscreens; s++) \
- for((a)=(s < nscreens ? (v)->areas[s] : v->floating), __anext=(a)->next; (a); (void)(((a)=__anext) && (__anext=(a)->next)))
+ with(int, __alive) \
+ with(Area*, __anext) \
+ for(s=0; _cond(s <= nscreens, 0); _cont(s++)) \
+ for((a)=(s < nscreens ? (v)->areas[s] : v->floating), __anext=(a)->next; _cond(a, 1); _cont(((a)=__anext) && (__anext=(a)->next)))
#define foreach_column(v, s, a) \
- with(Area, __anext) \
- for(s=0; s < nscreens; s++) \
- for((a)=(v)->areas[s], __anext=(a)->next; (a); (void)(((a)=__anext) && (__anext=(a)->next)))
+ with(int, __alive) \
+ with(Area*, __anext) \
+ for(s=0; _cond(s < nscreens, 0); _cont(s++)) \
+ for((a)=(v)->areas[s], __anext=(a)->next; _cond(a, 1); _cont(((a)=__anext) && (__anext=(a)->next)))
#define foreach_frame(v, s, a, f) \
- with(Frame, __fnext) \
+ with(Frame*, __fnext) \
foreach_area(v, s, a) \
- for((void)(((f)=(a)->frame) && (__fnext=(f)->anext)); (f); (void)(((f)=__fnext) && (__fnext=(f)->anext)))
+ for((void)(((f)=(a)->frame) && (__fnext=(f)->anext)); _cond(f, 2); _cont(((f)=__fnext) && (__fnext=(f)->anext)))
#define btassert(arg, cond) \
(cond ? fprint(1, __FILE__":%d: failed assertion: " #cond "\n", __LINE__), backtrace(arg), true : false)
diff -r a6d491229802 -r 331694a2e8d1 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Wed Dec 24 00:24:23 2008 -0500
+++ b/cmd/wmii/mouse.c Sun Dec 28 16:20:13 2008 -0500
@@ -221,10 +221,9 @@
d = divs;
foreach_column(v, s, a) {
if(a == f->area)
- goto found;
+ break;
d = d->next;
}
-found:
if(align&East)
d = d->next;
Received on Sun Dec 28 2008 - 21:21:57 UTC
This archive was generated by hypermail 2.2.0 : Sun Dec 28 2008 - 21:24:04 UTC