Remove yajl major version conditionals
Yajl version ≥ 2 is required. fixes #1156
This commit is contained in:
committed by
Michael Stapelberg
parent
22b4215d92
commit
13db562551
@ -161,11 +161,7 @@ static int stdin_start_map(void *context) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if YAJL_MAJOR >= 2
|
||||
static int stdin_map_key(void *context, const unsigned char *key, size_t len) {
|
||||
#else
|
||||
static int stdin_map_key(void *context, const unsigned char *key, unsigned int len) {
|
||||
#endif
|
||||
parser_ctx *ctx = context;
|
||||
FREE(ctx->last_map_key);
|
||||
sasprintf(&(ctx->last_map_key), "%.*s", len, key);
|
||||
@ -183,11 +179,7 @@ static int stdin_boolean(void *context, int val) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if YAJL_MAJOR >= 2
|
||||
static int stdin_string(void *context, const unsigned char *val, size_t len) {
|
||||
#else
|
||||
static int stdin_string(void *context, const unsigned char *val, unsigned int len) {
|
||||
#endif
|
||||
parser_ctx *ctx = context;
|
||||
if (strcasecmp(ctx->last_map_key, "full_text") == 0) {
|
||||
ctx->block.full_text = i3string_from_utf8_with_length((const char *)val, len);
|
||||
@ -223,11 +215,7 @@ static int stdin_string(void *context, const unsigned char *val, unsigned int le
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if YAJL_MAJOR >= 2
|
||||
static int stdin_integer(void *context, long long val) {
|
||||
#else
|
||||
static int stdin_integer(void *context, long val) {
|
||||
#endif
|
||||
parser_ctx *ctx = context;
|
||||
if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
|
||||
ctx->block.min_width = (uint32_t)val;
|
||||
@ -321,11 +309,7 @@ static void read_flat_input(char *buffer, int length) {
|
||||
static bool read_json_input(unsigned char *input, int length) {
|
||||
yajl_status status = yajl_parse(parser, input, length);
|
||||
bool has_urgent = false;
|
||||
#if YAJL_MAJOR >= 2
|
||||
if (status != yajl_status_ok) {
|
||||
#else
|
||||
if (status != yajl_status_ok && status != yajl_status_insufficient_data) {
|
||||
#endif
|
||||
char *message = (char *)yajl_get_error(parser, 0, input, length);
|
||||
|
||||
/* strip the newline yajl adds to the error message */
|
||||
@ -429,11 +413,8 @@ void child_sig_cb(struct ev_loop *loop, ev_child *watcher, int revents) {
|
||||
void child_write_output(void) {
|
||||
if (child.click_events) {
|
||||
const unsigned char *output;
|
||||
#if YAJL_MAJOR < 2
|
||||
unsigned int size;
|
||||
#else
|
||||
size_t size;
|
||||
#endif
|
||||
|
||||
yajl_gen_get_buf(gen, &output, &size);
|
||||
write(child_stdin, output, size);
|
||||
write(child_stdin, "\n", 1);
|
||||
@ -465,17 +446,9 @@ void start_child(char *command) {
|
||||
.yajl_start_array = stdin_start_array,
|
||||
.yajl_end_array = stdin_end_array,
|
||||
};
|
||||
#if YAJL_MAJOR < 2
|
||||
yajl_parser_config parse_conf = { 0, 0 };
|
||||
|
||||
parser = yajl_alloc(&callbacks, &parse_conf, NULL, (void*)&parser_context);
|
||||
|
||||
gen = yajl_gen_alloc(NULL, NULL);
|
||||
#else
|
||||
parser = yajl_alloc(&callbacks, NULL, &parser_context);
|
||||
|
||||
gen = yajl_gen_alloc(NULL);
|
||||
#endif
|
||||
|
||||
int pipe_in[2]; /* pipe we read from */
|
||||
int pipe_out[2]; /* pipe we write to */
|
||||
|
@ -27,11 +27,7 @@ static char *cur_key;
|
||||
* Essentially we just save it in cur_key.
|
||||
*
|
||||
*/
|
||||
#if YAJL_MAJOR >= 2
|
||||
static int config_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
|
||||
#else
|
||||
static int config_map_key_cb(void *params_, const unsigned char *keyVal, unsigned keyLen) {
|
||||
#endif
|
||||
FREE(cur_key);
|
||||
|
||||
cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
|
||||
@ -61,11 +57,7 @@ static int config_null_cb(void *params_) {
|
||||
* Parse a string
|
||||
*
|
||||
*/
|
||||
#if YAJL_MAJOR >= 2
|
||||
static int config_string_cb(void *params_, const unsigned char *val, size_t _len) {
|
||||
#else
|
||||
static int config_string_cb(void *params_, const unsigned char *val, unsigned int _len) {
|
||||
#endif
|
||||
int len = (int)_len;
|
||||
/* The id and socket_path are ignored, we already know them. */
|
||||
if (!strcmp(cur_key, "id") || !strcmp(cur_key, "socket_path"))
|
||||
@ -225,13 +217,7 @@ static yajl_callbacks outputs_callbacks = {
|
||||
void parse_config_json(char *json) {
|
||||
yajl_handle handle;
|
||||
yajl_status state;
|
||||
#if YAJL_MAJOR < 2
|
||||
yajl_parser_config parse_conf = { 0, 0 };
|
||||
|
||||
handle = yajl_alloc(&outputs_callbacks, &parse_conf, NULL, NULL);
|
||||
#else
|
||||
handle = yajl_alloc(&outputs_callbacks, NULL, NULL);
|
||||
#endif
|
||||
|
||||
state = yajl_parse(handle, (const unsigned char*) json, strlen(json));
|
||||
|
||||
@ -240,9 +226,6 @@ void parse_config_json(char *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 config-reply!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -27,11 +27,7 @@ struct mode_json_params {
|
||||
* Parse a string (change)
|
||||
*
|
||||
*/
|
||||
#if YAJL_MAJOR >= 2
|
||||
static int mode_string_cb(void *params_, const unsigned char *val, size_t len) {
|
||||
#else
|
||||
static int mode_string_cb(void *params_, const unsigned char *val, unsigned int len) {
|
||||
#endif
|
||||
struct mode_json_params *params = (struct mode_json_params*) params_;
|
||||
|
||||
if (!strcmp(params->cur_key, "change")) {
|
||||
@ -56,11 +52,7 @@ static int mode_string_cb(void *params_, const unsigned char *val, unsigned int
|
||||
* Essentially we just save it in the parsing-state
|
||||
*
|
||||
*/
|
||||
#if YAJL_MAJOR >= 2
|
||||
static int mode_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
|
||||
#else
|
||||
static int mode_map_key_cb(void *params_, const unsigned char *keyVal, unsigned int keyLen) {
|
||||
#endif
|
||||
struct mode_json_params *params = (struct mode_json_params*) params_;
|
||||
FREE(params->cur_key);
|
||||
|
||||
@ -95,13 +87,7 @@ void parse_mode_json(char *json) {
|
||||
yajl_handle handle;
|
||||
yajl_status state;
|
||||
|
||||
#if YAJL_MAJOR < 2
|
||||
yajl_parser_config parse_conf = { 0, 0 };
|
||||
|
||||
handle = yajl_alloc(&mode_callbacks, &parse_conf, NULL, (void*) ¶ms);
|
||||
#else
|
||||
handle = yajl_alloc(&mode_callbacks, NULL, (void*) ¶ms);
|
||||
#endif
|
||||
|
||||
state = yajl_parse(handle, (const unsigned char*) json, strlen(json));
|
||||
|
||||
@ -110,9 +96,6 @@ void parse_mode_json(char *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 mode-event!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -64,11 +64,7 @@ static int outputs_boolean_cb(void *params_, int val) {
|
||||
* 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")) {
|
||||
@ -108,11 +104,7 @@ static int outputs_integer_cb(void *params_, long val) {
|
||||
* 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, "current_workspace")) {
|
||||
@ -232,11 +224,7 @@ static int outputs_end_map_cb(void *params_) {
|
||||
* Essentially we just save it in the parsing-state
|
||||
*
|
||||
*/
|
||||
#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);
|
||||
|
||||
@ -281,13 +269,7 @@ void parse_outputs_json(char *json) {
|
||||
|
||||
yajl_handle handle;
|
||||
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));
|
||||
|
||||
@ -296,9 +278,6 @@ void parse_outputs_json(char *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);
|
||||
|
@ -35,11 +35,7 @@ static enum {
|
||||
NO_KEY
|
||||
} current_key;
|
||||
|
||||
#if YAJL_MAJOR >= 2
|
||||
static int header_integer(void *ctx, long long val) {
|
||||
#else
|
||||
static int header_integer(void *ctx, long val) {
|
||||
#endif
|
||||
i3bar_child *child = ctx;
|
||||
|
||||
switch (current_key) {
|
||||
@ -76,11 +72,7 @@ static int header_boolean(void *ctx, int val) {
|
||||
#define CHECK_KEY(name) (stringlen == strlen(name) && \
|
||||
STARTS_WITH((const char*)stringval, stringlen, name))
|
||||
|
||||
#if YAJL_MAJOR >= 2
|
||||
static int header_map_key(void *ctx, const unsigned char *stringval, size_t stringlen) {
|
||||
#else
|
||||
static int header_map_key(void *ctx, const unsigned char *stringval, unsigned int stringlen) {
|
||||
#endif
|
||||
if (CHECK_KEY("version")) {
|
||||
current_key = KEY_VERSION;
|
||||
} else if (CHECK_KEY("stop_signal")) {
|
||||
@ -118,16 +110,10 @@ void parse_json_header(i3bar_child *child, const unsigned char *buffer, int leng
|
||||
|
||||
current_key = NO_KEY;
|
||||
|
||||
#if YAJL_MAJOR >= 2
|
||||
yajl_handle handle = yajl_alloc(&version_callbacks, NULL, child);
|
||||
/* Allow trailing garbage. yajl 1 always behaves that way anyways, but for
|
||||
* yajl 2, we need to be explicit. */
|
||||
yajl_config(handle, yajl_allow_trailing_garbage, 1);
|
||||
#else
|
||||
yajl_parser_config parse_conf = { 0, 0 };
|
||||
|
||||
yajl_handle handle = yajl_alloc(&version_callbacks, &parse_conf, NULL, child);
|
||||
#endif
|
||||
|
||||
yajl_status state = yajl_parse(handle, buffer, length);
|
||||
if (state != yajl_status_ok) {
|
||||
|
@ -58,11 +58,7 @@ static int workspaces_boolean_cb(void *params_, int val) {
|
||||
* 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")) {
|
||||
@ -103,11 +99,7 @@ static int workspaces_integer_cb(void *params_, long val) {
|
||||
* 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;
|
||||
@ -182,11 +174,7 @@ static int workspaces_start_map_cb(void *params_) {
|
||||
* 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);
|
||||
|
||||
@ -223,13 +211,7 @@ void parse_workspaces_json(char *json) {
|
||||
|
||||
yajl_handle handle;
|
||||
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));
|
||||
|
||||
@ -238,9 +220,6 @@ void parse_workspaces_json(char *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);
|
||||
|
Reference in New Issue
Block a user