simplify yajl related code

Specifically, put the version dependent code in some macros, and put
that plus the `y' and `ystr' macros in a separate file, `yajl_utils.h'.
This commit is contained in:
Francesco Mazzoli
2012-11-03 11:17:28 +00:00
committed by Michael Stapelberg
parent dece12bf18
commit b67eedf71a
2 changed files with 48 additions and 86 deletions

31
include/yajl_utils.h Normal file
View File

@ -0,0 +1,31 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* yajl_utils.h
*
*/
#ifndef I3_YAJL_UTILS_H
#define I3_YAJL_UTILS_H
#include <yajl/yajl_gen.h>
#include <yajl/yajl_parse.h>
#include <yajl/yajl_version.h>
/* Shorter names for all those yajl_gen_* functions */
#define y(x, ...) yajl_gen_ ## x (gen, ##__VA_ARGS__)
#define ystr(str) yajl_gen_string(gen, (unsigned char*)str, strlen(str))
#if YAJL_MAJOR >= 2
#define ygenalloc() yajl_gen_alloc(NULL)
#define yalloc(callbacks, client) yajl_alloc(callbacks, NULL, client)
typedef size_t ylength;
#else
#define ygenalloc() yajl_gen_alloc(NULL, NULL);
#define yalloc(callbacks, client) yajl_alloc(callbacks, NULL, NULL, client)
typedef unsigned int ylength;
#endif
#endif