X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=util.h;h=bc23ecd9a6005fce68d6007bec1b6cb016845039;hb=03298d834be19eed7eb1dd70c76a7f1f22a2e93b;hp=65b82f5ec6bfa68f703c7853d74c5df4ba7ed787;hpb=f223b1a30b6afe99f7d94980d11f3e42ce6b9c0a;p=wmpus diff --git a/util.h b/util.h index 65b82f5..bc23ecd 100644 --- a/util.h +++ b/util.h @@ -24,16 +24,16 @@ #define countof(x) (sizeof(x)/sizeof((x)[0])) /* Constant length map functions */ -#define map_getg(map, test) ({ \ - int i; \ - for (i = 0; i < countof(map) && !(test); i++); \ - i < countof(map) ? &map[i] : NULL ; \ +#define map_get(map, k, kv, v, def) ({ \ + typeof(def) val = def; \ + for (int i = 0; i < countof(map); i++) \ + if (map[i].k == kv) { \ + val = map[i].v; \ + break; \ + } \ + val; \ }) -#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) - /* Linked lists */ typedef struct list { struct list *prev; @@ -60,4 +60,6 @@ list_t *list_sort(list_t *list, int rev, int (*func)(void*,void*)); /* Misc */ int str2num(char *str, int def); +int warn(char *fmt, ...); + int error(char *fmt, ...);