From f691927aa7e857ea834698cefef6f9c230b87f17 Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Mon, 3 Sep 2012 09:52:17 +0200 Subject: [PATCH] i3bar: Split JSON line logic to read_json_input --- i3bar/src/child.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/i3bar/src/child.c b/i3bar/src/child.c index 227a1435..9236de3f 100644 --- a/i3bar/src/child.c +++ b/i3bar/src/child.c @@ -203,6 +203,18 @@ static void read_flat_input(char *buffer, int length) { first->full_text = i3string_from_utf8(buffer); } +static void read_json_input(unsigned char *input, int length) { + yajl_status status = yajl_parse(parser, input, length); +#if YAJL_MAJOR >= 2 + if (status != yajl_status_ok) { +#else + if (status != yajl_status_ok && status != yajl_status_insufficient_data) { +#endif + fprintf(stderr, "[i3bar] Could not parse JSON input (code %d): %.*s\n", + status, length, input); + } +} + /* * Callbalk for stdin. We read a line from stdin and store the result * in statusline @@ -233,15 +245,7 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) { first_line = false; } if (!plaintext) { - yajl_status status = yajl_parse(parser, json_input, rec); -#if YAJL_MAJOR >= 2 - if (status != yajl_status_ok) { -#else - if (status != yajl_status_ok && status != yajl_status_insufficient_data) { -#endif - fprintf(stderr, "[i3bar] Could not parse JSON input (code %d): %.*s\n", - status, rec, json_input); - } + read_json_input(json_input, rec); } else { read_flat_input((char*)buffer, rec); } -- 2.39.5