<commit_before>#define _POSIX_C_SOURCE 200809L
#include <json-c/json.h>
#include <linux/input-event-codes.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wlr/util/log.h>
#include "swaybar/config.h"
#include "swaybar/status_line.h"

static void i3bar_block_free(struct i3bar_block *block) {
	if (!block) {
		return;
	}
	free(block->full_text);
	free(block->short_text);
	free(block->align);
	free(block->name);
	free(block->instance);
	free(block->color);
	free(block);
}

void i3bar_block_unref(struct i3bar_block *block) {
	if (--block->ref_count == 0) {
		i3bar_block_free(block);
	}
}

static bool i3bar_parse_json(struct status_line *status, const char *text) {
	struct i3bar_block *block, *tmp;
	wl_list_for_each_safe(block, tmp, &status->blocks, link) {
		wl_list_remove(&block->link);
		i3bar_block_unref(block);
	}
	json_object *results = json_tokener_parse(text);
	if (!results) {
		status_error(status, "[failed to parse i3bar json]");
		return false;
	}
	wlr_log(WLR_DEBUG, "Got i3bar json: '%s'", text);
	for (size_t i = 0; i < json_object_array_length(results); ++i) {
		json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
		json_object *name, *instance, *separator, *separator_block_width;
		json_object *background, *border, *border_top, *border_bottom;
		json_object *border_left, *border_right, *markup;
		json_object *json = json_object_array_get_idx(results, i);
		if (!json) {<commit_msg>bar: remove i3bar_block_free in favour of i3bar_block_unref<commit_after>#define _POSIX_C_SOURCE 200809L
#include <json-c/json.h>
#include <linux/input-event-codes.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wlr/util/log.h>
#include "swaybar/config.h"
#include "swaybar/status_line.h"

void i3bar_block_unref(struct i3bar_block *block) {
	if (block == NULL) {
		return;
	}

	if (--block->ref_count == 0) {
		free(block->full_text);
		free(block->short_text);
		free(block->align);
		free(block->name);
		free(block->instance);
		free(block->color);
		free(block);
	}
}

static bool i3bar_parse_json(struct status_line *status, const char *text) {
	struct i3bar_block *block, *tmp;
	wl_list_for_each_safe(block, tmp, &status->blocks, link) {
		wl_list_remove(&block->link);
		i3bar_block_unref(block);
	}
	json_object *results = json_tokener_parse(text);
	if (!results) {
		status_error(status, "[failed to parse i3bar json]");
		return false;
	}
	wlr_log(WLR_DEBUG, "Got i3bar json: '%s'", text);
	for (size_t i = 0; i < json_object_array_length(results); ++i) {
		json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
		json_object *name, *instance, *separator, *separator_block_width;
		json_object *background, *border, *border_top, *border_bottom;
		json_object *border_left, *border_right, *markup;
		json_object *json = json_object_array_get_idx(results, i);
		if (!json) {
{'fraction_non_alphanumeric': 0.1512313562261533, 'fraction_numerical': 0.012140131807145335, 'mean_word_length': 5.899521531100478, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4177576', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1132, 'n_words': 227}