i3bar: be less strict about the {"version":1} JSON header

This commit is contained in:
Michael Stapelberg
2012-08-12 18:40:15 +02:00
parent dbe406641f
commit e53405c216
4 changed files with 140 additions and 7 deletions

View File

@ -192,19 +192,18 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
if (first_line) {
DLOG("Detecting input type based on buffer *%.*s*\n", rec, buffer);
/* Detect whether this is JSON or plain text. */
plaintext = (strncasecmp((char*)buffer, "{\"version\":", strlen("{\"version\":")) != 0);
unsigned int consumed = 0;
/* At the moment, we dont care for the version. This might change
* in the future, but for now, we just discard it. */
plaintext = (determine_json_version(buffer, buffer_len, &consumed) == -1);
if (plaintext) {
/* In case of plaintext, we just add a single block and change its
* full_text pointer later. */
struct status_block *new_block = scalloc(sizeof(struct status_block));
TAILQ_INSERT_TAIL(&statusline_head, new_block, blocks);
} else {
/* At the moment, we dont care for the version. This might change
* in the future, but for now, we just discard it. */
while (*json_input != '\n' && *json_input != '\0') {
json_input++;
rec--;
}
json_input += consumed;
rec -= consumed;
}
first_line = false;
}