X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=util.h;h=bc23ecd9a6005fce68d6007bec1b6cb016845039;hb=5b87a56239c6bd1977e64965a5002010f2b53bc8;hp=ff68fb1f66858e5667698da039ff1f51cad711af;hpb=88e2a1773e458b1f79e2e743e3d5bdc659caf822;p=wmpus diff --git a/util.h b/util.h index ff68fb1..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; @@ -55,7 +55,11 @@ list_t *list_last(list_t *list); list_t *list_find(list_t *list, void *data); +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, ...);