X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=i3bar%2Finclude%2Futil.h;h=1f56361106dfc97670bc412bf5d6e2ad90fb6450;hb=f28c50b631cb9ac5b9ef832794d4a734c5fe5782;hp=6094932071ec299aed1af14f9fe29d8ec468e44a;hpb=8d09ed7bf53ebf39c8139146465c520e2edc0837;p=i3%2Fi3 diff --git a/i3bar/include/util.h b/i3bar/include/util.h index 60949320..1f563611 100644 --- a/i3bar/include/util.h +++ b/i3bar/include/util.h @@ -1,57 +1,70 @@ /* - * i3bar - an xcb-based status- and ws-bar for i3 + * vim:ts=4:sw=4:expandtab * - * © 2010-2011 Axel Wagner and contributors - * - * See file LICNSE for license information + * i3 - an improved dynamic tiling window manager + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) * */ -#ifndef UTIL_H_ -#define UTIL_H_ +#pragma once + +#include #include "queue.h" /* Get the maximum/minimum of x and y */ -#define MAX(x,y) ((x) > (y) ? (x) : (y)) -#define MIN(x,y) ((x) < (y) ? (x) : (y)) +#undef MAX +#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#undef MIN +#define MIN(x, y) ((x) < (y) ? (x) : (y)) + +#define STARTS_WITH(string, len, needle) (((len) >= strlen((needle))) && strncasecmp((string), (needle), strlen((needle))) == 0) /* Securely free p */ -#define FREE(p) do { \ - if (p != NULL) { \ - free(p); \ +#define FREE(p) \ + do { \ + free(p); \ p = NULL; \ - } \ -} while (0) - -/* Securely fee single-linked list */ -#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) + } while (0) +/* Securely free single-linked list */ +#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) + +/* Securely free tail queue */ +#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) + +#if defined(DLOG) +#undef DLOG #endif +/* Use cool logging macros */ +#define DLOG(fmt, ...) \ + do { \ + if (config.verbose) { \ + printf("[%s:%d] " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ + } \ + } while (0) -/* Securely fee tail-queues */ -#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) - -/* 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) +/* 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 +#define ELOG(fmt, ...) \ + do { \ + fprintf(stderr, "[%s:%d] ERROR: " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ + } while (0)