2010-08-07 18:05:16 +02:00
|
|
|
/*
|
|
|
|
* i3bar - an xcb-based status- and ws-bar for i3
|
|
|
|
*
|
|
|
|
* © 2010 Axel Wagner and contributors
|
|
|
|
*
|
|
|
|
* See file LICNSE for license information
|
|
|
|
*
|
|
|
|
*/
|
2010-07-22 01:15:18 +02:00
|
|
|
#ifndef UTIL_H_
|
|
|
|
#define UTIL_H_
|
|
|
|
|
2010-07-30 03:11:54 +02:00
|
|
|
#include "queue.h"
|
|
|
|
|
2010-09-17 01:16:53 +02:00
|
|
|
/* Get the maximum/minimum of x and y */
|
|
|
|
#define MAX(x,y) ((x) > (y) ? (x) : (y))
|
|
|
|
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
|
|
|
|
2010-07-22 01:15:18 +02:00
|
|
|
/* Securely free p */
|
|
|
|
#define FREE(p) do { \
|
2010-08-03 21:20:11 +02:00
|
|
|
if (p != NULL) { \
|
|
|
|
free(p); \
|
|
|
|
p = NULL; \
|
|
|
|
} \
|
2010-07-22 01:15:18 +02:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* Securely fee single-linked list */
|
2010-07-30 03:11:54 +02:00
|
|
|
#define FREE_SLIST(l, type) do { \
|
2010-08-03 21:20:11 +02:00
|
|
|
type *walk = SLIST_FIRST(l); \
|
|
|
|
while (!SLIST_EMPTY(l)) { \
|
|
|
|
SLIST_REMOVE_HEAD(l, slist); \
|
|
|
|
FREE(walk); \
|
|
|
|
walk = SLIST_FIRST(l); \
|
|
|
|
} \
|
2010-07-22 01:15:18 +02:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#endif
|
2010-07-30 03:11:54 +02:00
|
|
|
|
|
|
|
/* Securely fee tail-queues */
|
|
|
|
#define FREE_TAILQ(l, type) do { \
|
2010-08-03 21:20:11 +02:00
|
|
|
type *walk = TAILQ_FIRST(l); \
|
|
|
|
while (!TAILQ_EMPTY(l)) { \
|
|
|
|
TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \
|
|
|
|
FREE(walk); \
|
|
|
|
walk = TAILQ_FIRST(l); \
|
|
|
|
} \
|
2010-07-30 03:11:54 +02:00
|
|
|
} while (0)
|
2010-09-17 06:49:28 +02:00
|
|
|
|
|
|
|
/* Use cool logging-macros */
|
|
|
|
#define DLOG(fmt, ...) do { \
|
|
|
|
if (config.verbose) { \
|
|
|
|
printf("[%s:%d] " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define ELOG(fmt, ...) do { \
|
|
|
|
fprintf(stderr, "[%s:%d] ERROR: " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
|
|
|
|
} while(0)
|