+/*
+ * The start of a new array is the start of a new status line, so we clear all
+ * previous entries.
+ *
+ */
+static int stdin_start_array(void *context) {
+ struct status_block *first;
+ while (!TAILQ_EMPTY(&statusline_head)) {
+ first = TAILQ_FIRST(&statusline_head);
+ FREE(first->full_text);
+ FREE(first->color);
+ TAILQ_REMOVE(&statusline_head, first, blocks);
+ free(first);
+ }
+ return 1;
+}
+
+/*
+ * The start of a map is the start of a single block of the status line.
+ *
+ */
+static int stdin_start_map(void *context) {
+ parser_ctx *ctx = context;
+ memset(&(ctx->block), '\0', sizeof(struct status_block));
+ return 1;
+}
+
+static int stdin_map_key(void *context, const unsigned char *key, size_t len) {
+ parser_ctx *ctx = context;
+ FREE(ctx->last_map_key);
+ sasprintf(&(ctx->last_map_key), "%.*s", len, key);
+ return 1;
+}
+
+static int stdin_string(void *context, const unsigned char *val, size_t len) {
+ parser_ctx *ctx = context;
+ if (strcasecmp(ctx->last_map_key, "full_text") == 0) {
+ sasprintf(&(ctx->block.full_text), "%.*s", len, val);
+ }
+ if (strcasecmp(ctx->last_map_key, "color") == 0) {
+ sasprintf(&(ctx->block.color), "%.*s", len, val);
+ }
+ return 1;
+}
+
+static int stdin_end_map(void *context) {
+ parser_ctx *ctx = context;
+ struct status_block *new_block = smalloc(sizeof(struct status_block));
+ memcpy(new_block, &(ctx->block), sizeof(struct status_block));
+ TAILQ_INSERT_TAIL(&statusline_head, new_block, blocks);
+ return 1;
+}
+
+static int stdin_end_array(void *context) {
+ DLOG("dumping statusline:\n");
+ struct status_block *current;
+ TAILQ_FOREACH(current, &statusline_head, blocks) {
+ DLOG("full_text = %s\n", current->full_text);
+ DLOG("color = %s\n", current->color);
+ }
+ DLOG("end of dump\n");
+ return 1;
+}
+