2010-08-07 12:05:16 -04:00
|
|
|
/*
|
2011-10-25 16:19:38 -04:00
|
|
|
* vim:ts=4:sw=4:expandtab
|
2010-08-07 12:05:16 -04:00
|
|
|
*
|
2011-10-25 16:19:38 -04:00
|
|
|
* i3 - an improved dynamic tiling window manager
|
2015-04-03 20:17:56 -04:00
|
|
|
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
|
2010-08-07 12:05:16 -04:00
|
|
|
*
|
|
|
|
*/
|
2013-12-28 21:11:50 -05:00
|
|
|
#pragma once
|
2010-07-21 19:15:18 -04:00
|
|
|
|
2010-07-29 21:11:54 -04:00
|
|
|
#include "queue.h"
|
|
|
|
|
2010-09-16 19:16:53 -04:00
|
|
|
/* Get the maximum/minimum of x and y */
|
2012-08-05 15:36:49 -04:00
|
|
|
#undef MAX
|
2014-06-19 05:20:32 -04:00
|
|
|
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
2012-08-05 15:36:49 -04:00
|
|
|
#undef MIN
|
2014-06-19 05:20:32 -04:00
|
|
|
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
2010-09-16 19:16:53 -04:00
|
|
|
|
2015-12-29 12:01:51 -05:00
|
|
|
#define STARTS_WITH(string, len, needle) (((len) >= strlen((needle))) && strncasecmp((string), (needle), strlen((needle))) == 0)
|
2012-09-03 04:43:29 -04:00
|
|
|
|
2010-07-21 19:15:18 -04:00
|
|
|
/* Securely free p */
|
2014-06-19 05:20:32 -04:00
|
|
|
#define FREE(p) \
|
|
|
|
do { \
|
|
|
|
if (p != NULL) { \
|
|
|
|
free(p); \
|
|
|
|
p = NULL; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2010-07-21 19:15:18 -04:00
|
|
|
|
2015-03-24 08:41:16 -04:00
|
|
|
/* Securely free single-linked list */
|
2014-06-19 05:20:32 -04:00
|
|
|
#define FREE_SLIST(l, type) \
|
|
|
|
do { \
|
|
|
|
type *walk = SLIST_FIRST(l); \
|
|
|
|
while (!SLIST_EMPTY(l)) { \
|
|
|
|
SLIST_REMOVE_HEAD(l, slist); \
|
|
|
|
FREE(walk); \
|
|
|
|
walk = SLIST_FIRST(l); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2010-07-21 19:15:18 -04:00
|
|
|
|
2015-03-24 08:41:16 -04:00
|
|
|
/* Securely free tail queue */
|
2014-06-19 05:20:32 -04:00
|
|
|
#define FREE_TAILQ(l, type) \
|
|
|
|
do { \
|
|
|
|
type *walk = TAILQ_FIRST(l); \
|
|
|
|
while (!TAILQ_EMPTY(l)) { \
|
|
|
|
TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \
|
|
|
|
FREE(walk); \
|
|
|
|
walk = TAILQ_FIRST(l); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2010-09-17 00:49:28 -04:00
|
|
|
|
2013-12-24 04:35:56 -05:00
|
|
|
#if defined(DLOG)
|
|
|
|
#undef DLOG
|
|
|
|
#endif
|
2015-03-23 15:56:49 -04:00
|
|
|
/* Use cool logging macros */
|
2014-06-19 05:20:32 -04:00
|
|
|
#define DLOG(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (config.verbose) { \
|
|
|
|
printf("[%s:%d] " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2010-09-17 00:49:28 -04:00
|
|
|
|
2012-08-10 09:39:50 -04:00
|
|
|
/* We will include libi3.h which define its own version of ELOG.
|
|
|
|
* We want *our* version, so we undef the libi3 one. */
|
|
|
|
#if defined(ELOG)
|
|
|
|
#undef ELOG
|
|
|
|
#endif
|
2014-06-19 05:20:32 -04:00
|
|
|
#define ELOG(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
fprintf(stderr, "[%s:%d] ERROR: " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|