X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;ds=sidebyside;f=util.h;fp=util.h;h=965ca4e485ddfab3489c54cb18a328eece7b818f;hb=d7d862c402564b4fe29f17e1a55cdbb2967aa6fd;hp=a572a0aabd01d9528b751777ccb241e1c0584536;hpb=c00388973ecb2af94cc7b74ef762f0b8d10741e6;p=wmpus diff --git a/util.h b/util.h index a572a0a..965ca4e 100644 --- a/util.h +++ b/util.h @@ -5,9 +5,13 @@ #define countof(x) (sizeof(x)/sizeof((x)[0])) -#define map_get(map, key) ({ \ +#define map_getg(map, test) ({ \ int i; \ - for (i = 0; i < countof(map) && \ - *((typeof(key)*)&map[i]) != key; i++); \ + for (i = 0; i < countof(map) && !(test); i++); \ i < countof(map) ? &map[i] : NULL ; \ }) + +#define map_get(m,k) map_getg(m,k==*((typeof(k)*)&m[i])) +#define map_getr(m,k) map_getg(m,k==*(((typeof(k)*)&m[i+1])-1)) +#define map_getk(m,k,a) map_getg(m,k==m[i].a) +