X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=util.h;h=965ca4e485ddfab3489c54cb18a328eece7b818f;hb=d7d862c402564b4fe29f17e1a55cdbb2967aa6fd;hp=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391;hpb=58936d6ab733acf784cf8b1a8f6839b7a75bfe7a;p=wmpus diff --git a/util.h b/util.h index e69de29..965ca4e 100644 --- a/util.h +++ b/util.h @@ -0,0 +1,17 @@ +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define MIN(a,b) ((a) < (b) ? (a) : (b)) + +#define new0(type) (calloc(1, sizeof(type))) + +#define countof(x) (sizeof(x)/sizeof((x)[0])) + +#define map_getg(map, test) ({ \ + int 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) +