# The escaping is absurd, but we need to escape for shell, sed, make, define
GIT_VERSION:="$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1), branch $(shell [ -f .git/HEAD ] && sed 's/ref: refs\/heads\/\(.*\)/\\\\\\"\1\\\\\\"/g' .git/HEAD || echo 'unknown'))"
+# Fallback for libyajl 1 which did not include yajl_version.h. We need
+# YAJL_MAJOR from that file to decide which code path should be used.
+CFLAGS += -idirafter yajl-fallback
+
CFLAGS += -Wall
CFLAGS += -pipe
CFLAGS += -Iinclude
#include <stdio.h>
#include <i3/ipc.h>
#include <yajl/yajl_parse.h>
+#include <yajl/yajl_version.h>
#include "common.h"
* Parse an integer (current_workspace or the rect)
*
*/
+#if YAJL_MAJOR >= 2
+static int outputs_integer_cb(void *params_, long long val) {
+#else
static int outputs_integer_cb(void *params_, long val) {
+#endif
struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (!strcmp(params->cur_key, "current_workspace")) {
* Parse a string (name)
*
*/
+#if YAJL_MAJOR >= 2
+static int outputs_string_cb(void *params_, const unsigned char *val, size_t len) {
+#else
static int outputs_string_cb(void *params_, const unsigned char *val, unsigned int len) {
+#endif
struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (strcmp(params->cur_key, "name")) {
* Essentially we just save it in the parsing-state
*
*/
-static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, unsigned int keyLen) {
+#if YAJL_MAJOR >= 2
+static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
+#else
+static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, unsigned keyLen) {
+#endif
struct outputs_json_params *params = (struct outputs_json_params*) params_;
FREE(params->cur_key);
params.json = json;
yajl_handle handle;
- yajl_parser_config parse_conf = { 0, 0 };
yajl_status state;
+#if YAJL_MAJOR < 2
+ yajl_parser_config parse_conf = { 0, 0 };
handle = yajl_alloc(&outputs_callbacks, &parse_conf, NULL, (void*) ¶ms);
+#else
+ handle = yajl_alloc(&outputs_callbacks, NULL, (void*) ¶ms);
+#endif
state = yajl_parse(handle, (const unsigned char*) json, strlen(json));
case yajl_status_ok:
break;
case yajl_status_client_canceled:
+#if YAJL_MAJOR < 2
case yajl_status_insufficient_data:
+#endif
case yajl_status_error:
ELOG("Could not parse outputs-reply!\n");
exit(EXIT_FAILURE);
#include <stdio.h>
#include <errno.h>
#include <yajl/yajl_parse.h>
+#include <yajl/yajl_version.h>
#include "common.h"
* Parse an integer (num or the rect)
*
*/
+#if YAJL_MAJOR >= 2
+static int workspaces_integer_cb(void *params_, long long val) {
+#else
static int workspaces_integer_cb(void *params_, long val) {
+#endif
struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
if (!strcmp(params->cur_key, "num")) {
* Parse a string (name, output)
*
*/
+#if YAJL_MAJOR >= 2
+static int workspaces_string_cb(void *params_, const unsigned char *val, size_t len) {
+#else
static int workspaces_string_cb(void *params_, const unsigned char *val, unsigned int len) {
-
+#endif
struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
char *output_name;
* Essentially we just save it in the parsing-state
*
*/
+#if YAJL_MAJOR >= 2
+static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
+#else
static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, unsigned int keyLen) {
+#endif
struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
FREE(params->cur_key);
params.json = json;
yajl_handle handle;
- yajl_parser_config parse_conf = { 0, 0 };
yajl_status state;
+#if YAJL_MAJOR < 2
+ yajl_parser_config parse_conf = { 0, 0 };
handle = yajl_alloc(&workspaces_callbacks, &parse_conf, NULL, (void*) ¶ms);
+#else
+ handle = yajl_alloc(&workspaces_callbacks, NULL, (void*) ¶ms);
+#endif
state = yajl_parse(handle, (const unsigned char*) json, strlen(json));
case yajl_status_ok:
break;
case yajl_status_client_canceled:
+#if YAJL_MAJOR < 2
case yajl_status_insufficient_data:
+#endif
case yajl_status_error:
ELOG("Could not parse workspaces-reply!\n");
exit(EXIT_FAILURE);