]> git.sur5r.net Git - i3/i3/blob - i3bar/include/util.h
libi3: Implement Pango rendering
[i3/i3] / i3bar / include / util.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  */
8 #ifndef UTIL_H_
9 #define UTIL_H_
10
11 #include "queue.h"
12
13 /* Get the maximum/minimum of x and y */
14 #undef MAX
15 #define MAX(x,y) ((x) > (y) ? (x) : (y))
16 #undef MIN
17 #define MIN(x,y) ((x) < (y) ? (x) : (y))
18
19 /* Securely free p */
20 #define FREE(p) do { \
21     if (p != NULL) { \
22         free(p); \
23         p = NULL; \
24     } \
25 } while (0)
26
27 /* Securely fee single-linked list */
28 #define FREE_SLIST(l, type) do { \
29     type *walk = SLIST_FIRST(l); \
30     while (!SLIST_EMPTY(l)) { \
31         SLIST_REMOVE_HEAD(l, slist); \
32         FREE(walk); \
33         walk = SLIST_FIRST(l); \
34     } \
35 } while (0)
36
37 #endif
38
39 /* Securely fee tail-queues */
40 #define FREE_TAILQ(l, type) do { \
41     type *walk = TAILQ_FIRST(l); \
42     while (!TAILQ_EMPTY(l)) { \
43         TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \
44         FREE(walk); \
45         walk = TAILQ_FIRST(l); \
46     } \
47 } while (0)
48
49 /* Use cool logging-macros */
50 #define DLOG(fmt, ...) do { \
51     if (config.verbose) { \
52         printf("[%s:%d] " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
53     } \
54 } while(0)
55
56 /* We will include libi3.h which define its own version of ELOG.
57  * We want *our* version, so we undef the libi3 one. */
58 #if defined(ELOG)
59 #undef ELOG
60 #endif
61 #define ELOG(fmt, ...) do { \
62     fprintf(stderr, "[%s:%d] ERROR: " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
63 } while(0)