wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit bf9847dde708440e8dad6a633eab89c733853936
parent 4d037de26c233b6f1dc526d3dbc2cf6bd4f904ee
Author: Kris Maglione <jg@suckless.org>
Date:   Sun, 28 Dec 2008 16:20:13 -0500

Black magic to make break work with foreach_*

Diffstat:
cmd/wmii/fns.h | 25++++++++++++++++---------
cmd/wmii/mouse.c | 3+--
2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h @@ -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 --git a/cmd/wmii/mouse.c b/cmd/wmii/mouse.c @@ -221,10 +221,9 @@ mouse_resizecolframe(Frame *f, Align align) { d = divs; foreach_column(v, s, a) { if(a == f->area) - goto found; + break; d = d->next; } -found: if(align&East) d = d->next;